blob: fa08bfb22b83be346f7dfd139ea1471839d1af98 [file] [log] [blame]
// GraphPropertyFileSpecification.java
package org.eclipse.stem.internal.data.specifications;
/*******************************************************************************
* Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018
* IBM Corporation, BfR, and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* Contributors:
* IBM Corporation - initial API and implementation and new features
* Bundesinstitut für Risikobewertung - Pajek Graph interface, new Veterinary Models
*******************************************************************************/
import java.util.Map;
import java.util.StringTokenizer;
import org.eclipse.stem.core.graph.Graph;
import org.eclipse.stem.core.graph.GraphFactory;
import org.eclipse.stem.core.graph.GraphPackage;
import org.eclipse.stem.internal.data.generatedplugin.DublinCore;
/**
* This class represents a {@link Graph} that is specified by a properties file.
*/
abstract public class GraphPropertyFileSpecification extends
IdentifiablePropertyFileSpecification {
/**
* These are the properties that define the {@link Graph}.
*/
protected Map<String, String> graphProperties = null;
protected GraphPropertyFileSpecification() {
// nothing
}
/**
* @return the {@link Graph}
*/
public Graph getGraph() {
return (Graph) getIdentifiable();
} // getGraph
@Override
protected Graph createIdentifiableInstance() {
final Graph retValue = GraphFactory.eINSTANCE.createGraph();
dublinCore.setFormat(GraphPackage.eNS_URI);
return retValue;
} // createIdentifiableInstance
@Override
protected String getSerializationFileNameExtension() {
return GraphPackage.eNAME;
} // getRecordType
/**
* @param type
* the type of elements in the Graph (e.g., "Edge", "Label",
* "Node")
* @param subject
* the thing the type represents (e.g., "area", "population",
* "region")
* @return the String to put in the {@link DublinCore#getSubject()} string
*/
public static String createDublinCoreSubjectString(final String type,
final String subject) {
final StringBuilder sb = new StringBuilder(type);
sb.append(":");
sb.append(subject);
return sb.toString();
} // createDublinCoreSubjectString
/**
* @param dcSubjectString
* a String created by
* {@link #createDublinCoreSubjectString(String, String)}
* @return the type and subject extracted from the String
*/
public static String[] parseDublinCoreSubjectString(final String dcSubjectString) {
final StringTokenizer st = new StringTokenizer(dcSubjectString, ":");
final String type = st.nextToken();
final String subject = st.nextToken();
return new String[] { type, subject };
} // parseDublinCoreSubjectString
} // GraphPropertyFileSpecification