Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package de.uniks.networkparser.xml;
/*
NetworkParser
The MIT License
Copyright (c) 2010-2016 Stefan Lindel https://github.com/fujaba/NetworkParser/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
import java.util.ArrayList;
import java.util.Collection;
import de.uniks.networkparser.EntityUtil;
import de.uniks.networkparser.IdMap;
import de.uniks.networkparser.MapEntity;
import de.uniks.networkparser.buffer.CharacterBuffer;
import de.uniks.networkparser.buffer.Tokener;
import de.uniks.networkparser.graph.Association;
import de.uniks.networkparser.graph.AssociationTypes;
import de.uniks.networkparser.graph.Attribute;
import de.uniks.networkparser.graph.Cardinality;
import de.uniks.networkparser.graph.Clazz;
import de.uniks.networkparser.graph.ClazzType;
import de.uniks.networkparser.graph.DataType;
import de.uniks.networkparser.graph.GraphList;
import de.uniks.networkparser.graph.GraphModel;
import de.uniks.networkparser.graph.Literal;
import de.uniks.networkparser.graph.util.AssociationSet;
import de.uniks.networkparser.interfaces.Entity;
import de.uniks.networkparser.interfaces.EntityList;
import de.uniks.networkparser.interfaces.SendableEntityCreator;
import de.uniks.networkparser.interfaces.SendableEntityCreatorIndexId;
import de.uniks.networkparser.list.SimpleKeyValueList;
import de.uniks.networkparser.list.SimpleList;
import de.uniks.networkparser.list.SimpleSet;
public class EMFTokener extends Tokener{
public static final String ECORE = "ecore";
public static final String EPACKAGE = "ecore:EPackage";
public static final String EAttribute = "eAttributes";
public static final String ECLASS = "eClassifiers";
public static final String EREFERENCE = "eReferences";
public static final String ETYPE = "eType";
public static final String EDATATYPE ="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//";
public static final String TYPE_ECLASS = "ecore:EClass";
public static final String TYPE_EAttribute = "ecore:EAttribute";
public static final String TYPE_EReferences = "ecore:EReference";
public static final String TYPE_ESUPERTYPE = "eSuperTypes";
public static final String TYPE_EEnum = "ecore:EEnum";
public static final String EOpposite = "eOpposite";
public static final String ATTRIBUTE_URL = "http://www.eclipse.org/emf/2002/Ecore#//";
public static final String UPPERBOUND = "upperBound";
public static final String XSI_TYPE = "xsi:type";
public static final String XMI_ID = "xmi:id";
public static final String NAME = "name";
/**
* Skip the Current Entity to >.
*/
protected void skipEntity() {
skipTo('>', false);
// Skip >
nextClean(false);
}
public String skipHeader() {
boolean skip=false;
CharacterBuffer tag;
do {
tag = this.getString(2);
if(tag == null) {
break;
}
if(tag.equals("")) {
skipEntity();
skip = true;
} else if(tag.equals(") {
for (Object childValue : (Collection>) propertyValue) {
XMLEntity child = new XMLEntity();
parent.withChild(child);
child.setType(propertyName);
String typetag = childValue.getClass().getName().replaceAll("\\.", ":");
child.put(XSI_TYPE, typetag);
encodeChildren(childValue, child, map);
}
} else {
XMLEntity child = new XMLEntity();
parent.withChild(child);
child.setType(propertyName);
String typetag = propertyValue.getClass().getName().replaceAll("\\.", ":");
child.put(XSI_TYPE, typetag);
encodeChildren(propertyValue, child, map);
}
}
}
/**
* Decode a Element from EMF
*
* @param map decoding runtime values
* @param root The Root Element of Returnvalue
* @return decoded Object
*/
public Object decode(MapEntity map, Object root) {
skipHeader();
XMLEntity xmlEntity = new XMLEntity();
xmlEntity.withValue(this.buffer);
if(EPACKAGE.equals(xmlEntity.getTag())) {
if(root instanceof GraphList) {
return decoding(xmlEntity, (GraphList)root);
}
return decoding(xmlEntity, null);
}
// build root entity
String tag = xmlEntity.getTag();
String[] splitTag = tag.split("\\:");
if(splitTag.length<2) {
return null;
}
if(ECORE.equalsIgnoreCase(splitTag[0]) || root instanceof GraphModel) {
GraphModel model;
if(root == null || root instanceof GraphModel == false) {
model = new GraphList();
} else {
model = (GraphModel) root;
}
return decodingClassModel(xmlEntity, model);
}
Object rootObject = null;
SendableEntityCreator rootFactory;
if(root == null) {
String className = splitTag[1];
rootFactory = getCreator(className, false, null);
if (rootFactory != null) {
rootObject = rootFactory.getSendableInstance(false);
} else {
// just use an ArrayList
rootObject = new ArrayList