\r
import java.lang.reflect.Constructor;\r
import java.lang.reflect.InvocationTargetException;\r
-import java.util.Collection;\r
import java.util.HashMap;\r
import java.util.HashSet;\r
import java.util.LinkedHashSet;\r
import org.simantics.db.common.utils.ListUtils;\r
import org.simantics.db.common.utils.NameUtils;\r
import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
import org.simantics.message.ILogger;\r
import org.simantics.xml.sax.ontology.XMLResource;\r
\r
public class XMLWriter {\r
\r
private ReadGraph graph;\r
- private Map<String, XMLWriter> subWriters = new HashMap<String, XMLWriter>();\r
+ private Map<Resource, XMLWriter> subWriters = new HashMap<Resource, XMLWriter>();\r
private Map<Class<? extends XMLElementWriter>, XMLElementWriter> namedWriters = new HashMap<Class<? extends XMLElementWriter>, XMLElementWriter>();\r
private Map<Resource,XMLElementWriter> writers = new HashMap<>();\r
private String schemaURI;\r
+ private String ontologyURI;\r
+ private Resource ontology;\r
\r
private ILogger logger;\r
\r
return graph;\r
}\r
\r
- public void setGraph(ReadGraph graph) {\r
+ public void setGraph(ReadGraph graph) throws DatabaseException {\r
this.graph = graph;\r
for (XMLWriter p : subWriters.values())\r
p.setGraph(graph);\r
+ if (ontologyURI != null)\r
+ this.ontology = graph.getResource(ontologyURI);\r
}\r
\r
public String getSchemaURI() {\r
this.schemaURI = schemaURI;\r
}\r
\r
+ public String getOntologyURI() {\r
+ return ontologyURI;\r
+ }\r
+ \r
+ public void setOntologyURI(String ontologyURI) {\r
+ this.ontologyURI = ontologyURI;\r
+ }\r
+ \r
+ public Resource getOntology() {\r
+ return ontology;\r
+ }\r
+ \r
public void add(XMLElementWriter writer) throws DatabaseException {\r
Resource type = writer.getType(graph);\r
if (type != null)\r
}\r
\r
public void add(XMLWriter writer) {\r
- subWriters.put(writer.getSchemaURI(), writer);\r
+ subWriters.put(writer.getOntology(), writer);\r
}\r
\r
public void write(Resource root, XMLStreamWriter writer) throws DatabaseException, XMLStreamException {\r
if (graph.hasValue(instance.instance))\r
elementWriter.characters(graph, instance, writer);\r
// get all child elements\r
- Collection<Statement> childElements = graph.getStatements(instance.instance, XML.hasElement);\r
+ Set<Statement> childElements = new HashSet<>();\r
+ childElements.addAll(graph.getStatements(instance.instance, XML.hasElement));\r
+ childElements.addAll(graph.getStatements(instance.instance, XML.hasComplexType));\r
// load elements, assign writers\r
Map<Resource,WriterElement> elementMap = new HashMap<>();\r
for (Statement s : childElements) {\r
if (processed.contains(r)) // badly generated writer could report elements several times. \r
continue;\r
WriterElement child = elementMap.get(r);\r
+ if (child == null)\r
+ throw new DatabaseException("Trying to export unregonized resource " +NameUtils.getSafeName(graph, r) + " " + r);\r
write(child, writer);\r
processed.add(r);\r
}\r
if (processed.contains(stm.getObject()))\r
continue;\r
WriterElement child = elementMap.get(stm.getObject());\r
+ if (child == null)\r
+ throw new DatabaseException("Trying to export unregonized resource " +NameUtils.getSafeName(graph, stm.getObject()) + " " + stm.getObject());\r
write(child, writer);\r
}\r
\r
childWriter = this.writers.get(childWriterClass);\r
if (childWriter == null) {\r
try {\r
- Constructor<? extends XMLElementWriter> c = childWriterClass.getConstructor(ReadGraph.class);\r
+ Constructor<? extends XMLElementWriter> c = null;\r
+ try {\r
+ c = childWriterClass.getConstructor(ReadGraph.class);\r
+ childWriter = c.newInstance(graph);\r
+ } catch (NoSuchMethodException e) {\r
+ c = childWriterClass.getConstructor();\r
+ childWriter = c.newInstance();\r
+ }\r
//childWriter = childWriterClass.newInstance();\r
- childWriter = c.newInstance(graph);\r
+ \r
namedWriters.put(childWriterClass, childWriter);\r
} catch (IllegalAccessException|InstantiationException|NoSuchMethodException|SecurityException|InvocationTargetException e) {\r
String err = "Error processing " + childWriterClass.getName() + " : element writers must have accessible constructor with ReadGraph parameter";\r
- logger.log(new Status(IStatus.ERROR, XMLParser.PLUGIN_ID, err));\r
+ logger.log(new Status(IStatus.ERROR, XMLParser.PLUGIN_ID, err, e));\r
} \r
}\r
}\r
childWriter = writers.get(type);\r
}\r
if (childWriter == null) {\r
- throw new DatabaseException("Cannot locate writer for " + NameUtils.getSafeName(graph, child.instance) + ", " + child.instance);\r
+ Resource type = graph.getSingleType(child.instance);\r
+ Resource ontology = getOntology(type);\r
+ if (ontology != null) {\r
+ XMLWriter xmlWriter = subWriters.get(ontology);\r
+ if (xmlWriter != null) {\r
+ childWriter = xmlWriter.writers.get(type);\r
+ }\r
+ }\r
+ if (childWriter == null)\r
+ throw new DatabaseException("Cannot locate writer for " + NameUtils.getSafeName(graph, child.instance) + ", " + child.instance);\r
}\r
child.writer = childWriter;\r
\r
}\r
+ \r
+ private Resource getOntology(Resource type) throws DatabaseException {\r
+ Layer0 L0 = Layer0.getInstance(graph);\r
+ Resource r = type;\r
+ while (true) {\r
+ r = graph.getPossibleObject(r, L0.PartOf);\r
+ if (r != null && graph.isInstanceOf(r, L0.Ontology))\r
+ break;\r
+ }\r
+ return r;\r
+ }\r
\r
}\r
import javax.xml.namespace.QName;\r
\r
import org.simantics.utils.datastructures.BijectionMap;\r
-import org.simantics.xml.sax.SchemaConversionBase.RefType;\r
import org.simantics.xml.sax.configuration.AttributeComposition;\r
import org.simantics.xml.sax.configuration.Configuration;\r
import org.simantics.xml.sax.configuration.IDProvider;\r
import org.w3._2001.xmlschema.LocalComplexType;\r
import org.w3._2001.xmlschema.LocalSimpleType;\r
import org.w3._2001.xmlschema.NamedAttributeGroup;\r
-import org.w3._2001.xmlschema.OpenAttrs;\r
import org.w3._2001.xmlschema.Restriction;\r
import org.w3._2001.xmlschema.Schema;\r
import org.w3._2001.xmlschema.SimpleType;\r
\r
\r
\r
- public void createParser(Schema schema,String className, SchemaConverter converter) throws IOException {\r
+ public void createParser(Schema schema,String ontologyUri, String className, SchemaConverter converter) throws IOException {\r
this.schema = schema;\r
this.ontologyClassName = className;\r
this.converter = converter;\r
mainWriter.println(" public " + name + parserClassPostfix+"(Session session) throws DatabaseException {");\r
if (schema.getTargetNamespace() != null)\r
mainWriter.println(" setSchemaURI(\""+schema.getTargetNamespace()+"\");");\r
+ mainWriter.println(" setOntologyURI(\""+ontologyUri+"\");");\r
mainWriter.println(" session.syncRequest(new ReadRequest() {");\r
mainWriter.println(" @Override");\r
mainWriter.println(" public void run(ReadGraph graph) throws DatabaseException {");\r
return "org.simantics.xml.sax.base.XMLElementNamedChildWriterBase";\r
}\r
\r
+ @Override\r
+ protected void handleSimpleType(SchemaObject parent, SchemaObject simpleTypeObj) {\r
+ }\r
\r
@Override\r
protected void handleComplexType(SchemaObject complexTypeObj) {\r
ComplexType topLevelComplexType = complexTypeObj.getComplexType();\r
\r
- String name = getName(complexTypeObj);//topLevelComplexType.getName();\r
+ String name = getName(complexTypeObj);\r
\r
String className = name;//"_"+name;\r
\r
throw new RuntimeException(e);\r
}\r
writers.put(complexTypeObj, fw);\r
- \r
- boolean isList = false;\r
\r
- String baseClass = "org.simantics.xml.sax.base.XMLElementNamedChildWriterBase";\r
+ String baseClass = getBaseClass();\r
\r
boolean inherited = false;\r
\r
QName type = getComplexTypeBase(topLevelComplexType);\r
if (type != null && !type.getNamespaceURI().equals("http://www.w3.org/2001/XMLSchema")) {\r
- baseClass = getName(complexTypeName.get(type.getLocalPart()));\r
- inherited = true;\r
+ SchemaObject obj = complexTypeName.get(type.getLocalPart());\r
+// if (obj == null)\r
+// obj = simpleTypeName.get(type.getLocalPart());\r
+ if (obj != null) {\r
+ baseClass = getName(obj);\r
+ inherited = true;\r
+ }\r
}\r
\r
provider = getIDProvider(topLevelComplexType);\r
- List<IDReference> references = getIDReferences(topLevelComplexType);\r
- UnrecognizedChildElement unknownChildElement = getUnknown(topLevelComplexType);\r
+// List<IDReference> references = getIDReferences(topLevelComplexType);\r
+// UnrecognizedChildElement unknownChildElement = getUnknown(topLevelComplexType);\r
\r
// List<String> intrerfaces = new ArrayList<String>();\r
// if (references.size() > 0)\r
// intrerfaces.add("org.simantics.xml.sax.base.UnrecognizedElementParser");\r
\r
createClassHeader(fw.writer);\r
- writeClass(fw.writer,false, null, className, baseClass, Collections.EMPTY_LIST);\r
+ writeClass(fw.writer,false, topLevelComplexType.getName(), className, baseClass, Collections.EMPTY_LIST);\r
\r
// writeIDProvider(fw.writer);\r
\r
}\r
\r
\r
- @Override\r
- protected void handleSimpleType(SchemaObject parent, SchemaObject simpleType) {\r
-\r
- }\r
+ \r
\r
\r
\r
import java.io.PrintWriter;\r
import java.io.StringWriter;\r
import java.util.ArrayList;\r
-import java.util.HashMap;\r
import java.util.List;\r
import java.util.Map;\r
\r
import javax.xml.namespace.QName;\r
\r
import org.simantics.utils.datastructures.BijectionMap;\r
-import org.simantics.xml.sax.SchemaConversionBase.RefType;\r
import org.simantics.xml.sax.configuration.AttributeComposition;\r
import org.simantics.xml.sax.configuration.Configuration;\r
import org.simantics.xml.sax.configuration.IDProvider;\r
import org.simantics.xml.sax.configuration.IDReference;\r
-import org.simantics.xml.sax.configuration.Rename;\r
import org.simantics.xml.sax.configuration.UnrecognizedChildElement;\r
import org.w3._2001.xmlschema.Annotated;\r
import org.w3._2001.xmlschema.Attribute;\r
import org.w3._2001.xmlschema.AttributeGroup;\r
-import org.w3._2001.xmlschema.AttributeGroupRef;\r
import org.w3._2001.xmlschema.ComplexType;\r
import org.w3._2001.xmlschema.Element;\r
import org.w3._2001.xmlschema.LocalComplexType;\r
import org.w3._2001.xmlschema.LocalSimpleType;\r
import org.w3._2001.xmlschema.NamedAttributeGroup;\r
-import org.w3._2001.xmlschema.OpenAttrs;\r
import org.w3._2001.xmlschema.Restriction;\r
import org.w3._2001.xmlschema.Schema;\r
import org.w3._2001.xmlschema.SimpleType;\r
super(configuration);\r
}\r
\r
- public void createParser(Schema schema,String className, SchemaConverter converter) throws IOException {\r
+ public void createParser(Schema schema,String ontologyUri, String className, SchemaConverter converter) throws IOException {\r
this.schema = schema;\r
this.ontologyClassName = className;\r
this.converter = converter;\r
}\r
\r
protected void handle(TopLevelAttribute topLevelAttribute) {\r
-\r
}\r
\r
+ @Override\r
+ protected void handleSimpleType(SchemaObject parent, SchemaObject simpleTypeObj) {\r
+ }\r
\r
@Override\r
protected void handleComplexType(SchemaObject complexTypeObj) {\r
ComplexType topLevelComplexType = complexTypeObj.getComplexType();\r
\r
- String name = getName(complexTypeObj);//topLevelComplexType.getName();\r
+ String name = getName(complexTypeObj);\r
+ \r
+// if (topLevelComplexType.getName().equals("Reference"))\r
+// System.out.println();\r
\r
String className = name;//"_"+name;\r
\r
throw new RuntimeException(e);\r
}\r
writers.put(complexTypeObj, fw);\r
- \r
- boolean isList = false;\r
\r
- String baseClass = "org.simantics.xml.sax.base.XMLElementNamedChildParserBase";\r
+ String baseClass = getBaseClass();\r
\r
boolean inherited = false;\r
\r
QName type = getComplexTypeBase(topLevelComplexType);\r
if (type != null && !type.getNamespaceURI().equals("http://www.w3.org/2001/XMLSchema")) {\r
- baseClass = getName(complexTypeName.get(type.getLocalPart()));\r
- inherited = true;\r
+ SchemaObject obj = complexTypeName.get(type.getLocalPart());\r
+ if (obj != null) {\r
+ baseClass = getName(obj);\r
+ inherited = true;\r
+ }\r
}\r
\r
provider = getIDProvider(topLevelComplexType);\r
if (unknownChildElement != null)\r
intrerfaces.add("org.simantics.xml.sax.base.UnrecognizedElementParser");\r
\r
- createClassHeader(fw.writer, isList);\r
+ createClassHeader(fw.writer, false);\r
writeClass(fw.writer,false, null, className, baseClass, intrerfaces);\r
\r
writeIDProvider(fw.writer);\r
fw.writer.println(" public Resource create(WriteGraph graph, ParserElement element) throws DatabaseException{");\r
fw.writer.println(" Layer0 L0 = Layer0.getInstance(graph);");\r
fw.writer.println(" "+getOntologyImport());\r
- if (!isList) {\r
fw.writer.println(" Resource res = graph.newResource();");\r
fw.writer.println(" graph.claim(res, L0.InstanceOf, "+ontShort+name+");");\r
- } else {\r
- fw.writer.println(" Resource res = ListUtils.create(graph, "+ontShort+name+", Collections.EMPTY_LIST);");\r
- }\r
fw.writer.println(" return res;");\r
fw.writer.println(" }");\r
fw.writer.println();\r
}\r
\r
\r
- @Override\r
- protected void handleSimpleType(SchemaObject parent, SchemaObject simpleType) {\r
-\r
- }\r
+ \r
\r
\r
IDProvider provider;\r
public static String getAttributeGroupPrefix() {\r
return "AttributeGroups_";\r
}\r
- \r
-// @Override\r
-// protected void handle(SchemaObject parent, SchemaElement indicator, SchemaElement element) {\r
-// Element localElement = element.getElement();\r
-// if (localElement.getName() != null) {\r
-// SchemaObject eObj = elements.get(localElement);\r
-// String refName = localElement.getName();\r
-// QName refType = localElement.getType();\r
-// if (refType != null)\r
-// handleIndicator(parent, indicator, element, false, refName, refType);\r
-// else {\r
-// handleElement(eObj);\r
-// handleIndicator(parent, indicator, element, false, refName, localElement);\r
-// }\r
-// } else if (localElement.getRef() != null) {\r
-// QName refType = localElement.getRef();\r
-// handleIndicator(parent, indicator,element, true, refType.getLocalPart(), refType);\r
-// }\r
-// }\r
- \r
+ \r
@Override\r
protected void handle(SchemaObject parent, SchemaElement indicator, List<SchemaElement> elements) {\r
if (indicator.getType() == SchemaElement.ElementType.SEQUENCE || (indicator.getType() == SchemaElement.ElementType.CHOICE && indicator.getRestriction().many())) {\r
}\r
}\r
\r
- protected void writeClass(PrintWriter writer,boolean abst, String name, String className, String baseClass, List<String> interfaces) {\r
+ protected void writeClass(PrintWriter writer,boolean abst, String elementId, String className, String baseClass, List<String> interfaces) {\r
writer.println("@SuppressWarnings(\"unused\")");\r
writer.print("public " +(abst ? "abstract " : "") + "class " + className + " extends "+baseClass);\r
if (interfaces.size() > 0) {\r
writer.println();\r
writer.println(" @Override");\r
writer.println(" public java.lang.String getElementId() {");\r
- if (name != null)\r
- writer.println(" return \""+name+"\";");\r
+ if (elementId != null)\r
+ writer.println(" return \""+elementId+"\";");\r
else // complex types cannot be parsed directly with name/id reference.\r
writer.println(" return null;");\r
writer.println(" }");\r
import org.w3._2001.xmlschema.LocalComplexType;\r
import org.w3._2001.xmlschema.LocalSimpleType;\r
import org.w3._2001.xmlschema.NamedAttributeGroup;\r
-import org.w3._2001.xmlschema.OpenAttrs;\r
import org.w3._2001.xmlschema.Restriction;\r
import org.w3._2001.xmlschema.Schema;\r
import org.w3._2001.xmlschema.SimpleType;\r
String commentTag = "//";\r
\r
Schema schema;\r
- String ontologyName;\r
+ String ontologyUri;\r
String className;\r
\r
SchemaConverter converter;\r
public void createOntology(Schema schema, String ontologyName, String className, SchemaConverter converter) throws FileNotFoundException {\r
this.schema = schema;\r
this.converter = converter;\r
- this.ontologyName = ontologyName;\r
+ this.ontologyUri = ontologyName;\r
this.className = className;\r
\r
// for (OpenAttrs attrs : schema.getIncludeOrImportOrRedefine()) {\r
}\r
\r
protected void handle(Schema schema) {\r
- String parts[] = ontologyName.split("/");\r
+ String parts[] = ontologyUri.split("/");\r
String name = parts[parts.length-1];\r
ontRoot = name.substring(0, Math.min(3, name.length())).toUpperCase();\r
- String version = schema.getVersion();\r
- if (version == null)\r
- version = "1.0";\r
\r
- \r
for (String s : converter.getHeader()) {\r
writer.println(commentTag + " " + s); \r
}\r
writer.println("L0 = <http://www.simantics.org/Layer0-1.1>");\r
writer.println("XML = <http://www.simantics.org/XML-1.0>");\r
writer.println();\r
- writer.println(ontRoot + " = <" + ontologyName +"-"+ version+"> : L0.Ontology");\r
+ writer.println(ontRoot + " = <" + ontologyUri +"> : L0.Ontology");\r
writer.println(" @L0.new");\r
writer.println(" L0.HasResourceClass \"" + className +"\"");\r
writer.println();\r
writer.println();\r
\r
ontRoot += ".";\r
- // TODO : these could be created in separate base ontology.\r
-// writer.println(commentTag + " Built-in types");\r
-// writer.println();\r
-// writer.println(ontRoot+"XML : L0.Library");\r
-// writer.println(ontRoot+"XML.hasAttribute <R L0.HasProperty");\r
-// writer.println(ontRoot+"XML.hasID <R "+ontRoot+"XML.hasAttribute : L0.FunctionalRelation");\r
-// writer.println(" --> L0.String");\r
-// writer.println(ontRoot+"XML.ComplexType <T L0.Entity");\r
-// writer.println(ontRoot+"XML.hasComplexType <R L0.IsComposedOf");\r
-// writer.println(ontRoot+"XML.AttributeGroup <T L0.Entity");\r
-// writer.println(ontRoot+"XML.Element <T L0.Entity");\r
-// writer.println(ontRoot+"XML.hasElement <R L0.IsComposedOf");\r
-// writer.println(ontRoot+"XML.ElementList <T L0.List");\r
-// writer.println(ontRoot+"XML.hasElementList <R L0.IsComposedOf");\r
-// writer.println(ontRoot+"XML.hasOriginalElementList <R " + ontRoot+"XML.hasElementList");\r
-// writer.println(ontRoot+"XML.hasReference <R L0.IsRelatedTo");\r
-// writer.println(ontRoot+"XML.hasExternalReference <R L0.IsRelatedTo");\r
-// writer.println(" L0.InverseOf " + ontRoot+"XML.externalReferenceOf <R L0.IsRelatedTo");\r
-// writer.println();\r
writer.println(ontRoot+"ComplexTypes : L0.Library");\r
writer.println(ontRoot+"AttributeGroups : L0.Library");\r
writer.println();\r
return ontType;\r
else if (isComplexTypeRef(qtype.getLocalPart()))\r
return ontRoot+getComplexTypePrefix()+qtype.getLocalPart();\r
+ else if (isSimpleTypeRef(qtype.getLocalPart()))\r
+ return ontRoot+qtype.getLocalPart();\r
else if (isElementRef(qtype.getLocalPart()))\r
return ontRoot+qtype.getLocalPart();\r
else if (qtype.getPrefix() != null && qtype.getPrefix().length() > 0) {\r
\r
\r
@Override\r
- //protected void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement element, boolean reference, String refName, QName refType) {\r
protected void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement element, String refName, RefType refType) {\r
if (refType != refType.Element) {\r
QName referenceType = null;\r
@Override\r
protected void handleComplexType(SchemaObject topLevelComplexType) {\r
String name = getName(topLevelComplexType);\r
- if (name.contains("Pcurve"))\r
- System.out.println();\r
-// if (parent != null)\r
-// name = parent +"_"+name;\r
+// if (topLevelComplexType.getName().equals("Reference"))\r
+// System.out.println();\r
\r
String relationName = ontRoot+getName(topLevelComplexType,"has");//ontRoot+"has"+name;\r
\r
import org.w3._2001.xmlschema.OpenAttrs;\r
import org.w3._2001.xmlschema.Restriction;\r
import org.w3._2001.xmlschema.Schema;\r
+import org.w3._2001.xmlschema.SimpleContent;\r
import org.w3._2001.xmlschema.SimpleType;\r
import org.w3._2001.xmlschema.TopLevelAttribute;\r
import org.w3._2001.xmlschema.TopLevelComplexType;\r
throw new RuntimeException("Groups not supported");\r
}\r
}\r
+ if (ct.getSimpleContent() != null) {\r
+ SimpleContent cc = ct.getSimpleContent();\r
+ ExtensionType extensionType = cc.getExtension();\r
+ if (extensionType != null) {\r
+ if (extensionType.getChoice() != null) {\r
+ preload(object,extensionType.getChoice(), stack);\r
+ }\r
+ if (extensionType.getSequence()!= null) {\r
+ preload(object,extensionType.getSequence(), stack);\r
+ }\r
+ if (extensionType.getAll()!= null) {\r
+ preload(object,extensionType.getAll(), stack);\r
+ }\r
+ if (extensionType.getGroup() != null)\r
+ throw new RuntimeException("Groups not supported");\r
+ }\r
+ }\r
} else if (object.getType() == ObjectType.ELEMENT) {\r
Element e = object.getElement();\r
if (e instanceof TopLevelElement)\r
return type;\r
}\r
}\r
+// SimpleContent simpleContent = complexType.getSimpleContent();\r
+// if (simpleContent != null) {\r
+// ExtensionType extensionType = simpleContent.getExtension();\r
+// if (extensionType != null) {\r
+// QName type = extensionType.getBase();\r
+// return type;\r
+// }\r
+// }\r
return null;\r
}\r
\r
handleAttributes(complexType, extensionType.getAttributeOrAttributeGroup());\r
}\r
}\r
+ SimpleContent simpleContent = complexType.getComplexType().getSimpleContent();\r
+ if (simpleContent != null) {\r
+ ExtensionType extensionType = simpleContent.getExtension();\r
+ if (extensionType != null) {\r
+ handleAttributes(complexType, extensionType.getAttributeOrAttributeGroup());\r
+ }\r
+ }\r
}\r
\r
\r
}\r
}\r
}\r
+// SimpleContent simpleContent = complexType.getSimpleContent();\r
+// if (simpleContent != null) {\r
+// ExtensionType extensionType = simpleContent.getExtension();\r
+// }\r
}\r
}\r
\r
\r
\r
protected boolean isElementRef(String ref) {\r
-// for (OpenAttrs attrs : schema.getSimpleTypeOrComplexTypeOrGroup()) {\r
-// if (attrs instanceof TopLevelElement) {\r
-// TopLevelElement element = (TopLevelElement)attrs;\r
-// if (ref.equals(element.getName()))\r
-// return true;\r
-// }\r
-// }\r
-// return false;\r
return elementName.containsKey(ref);\r
}\r
\r
protected boolean isComplexTypeRef(String ref) {\r
-// for (OpenAttrs attrs : schema.getSimpleTypeOrComplexTypeOrGroup()) {\r
-// if (attrs instanceof TopLevelComplexType) {\r
-// TopLevelComplexType element = (TopLevelComplexType)attrs;\r
-// if (ref.equals(element.getName()))\r
-// return true;\r
-// }\r
-// }\r
-// return false;\r
return complexTypeName.containsKey(ref);\r
- \r
+ }\r
+ \r
+ protected boolean isSimpleTypeRef(String ref) {\r
+ return simpleTypeName.containsKey(ref);\r
}\r
\r
protected NamedAttributeGroup getAttributeGroup(String name) {\r
header[3] = "Date " + new Date().toString();\r
\r
\r
- String ontologyName = schema.getTargetNamespace();\r
- if (ontologyName == null) {\r
- ontologyName = getSchemaFile().getName();\r
+ String ontologyUri = schema.getTargetNamespace();\r
+ if (ontologyUri == null) {\r
+ ontologyUri = getSchemaFile().getName();\r
\r
- int index = ontologyName.lastIndexOf(".");\r
+ int index = ontologyUri.lastIndexOf(".");\r
if (index > 0)\r
- ontologyName = ontologyName.substring(0, index);\r
+ ontologyUri = ontologyUri.substring(0, index);\r
} \r
- if (!ontologyName.startsWith("http"))\r
- ontologyName = "http://" + ontologyName;\r
- String parts[] = ontologyName.split("/");\r
+ ontologyUri = ontologyUri.replaceAll(" ", "_");\r
+ String parts[] = ontologyUri.split("/");\r
String name = parts[parts.length-1];\r
- //String ontRoot = name.substring(0, Math.min(3, name.length())).toUpperCase();\r
+ name = name.replaceAll("\\.", "_");\r
+ if (!ontologyUri.startsWith("http://"))\r
+ ontologyUri = "http://" + ontologyUri.replaceAll("/", "_");\r
+ else\r
+ ontologyUri = "http://" + ontologyUri.substring("http://".length()).replaceAll("/", "_");\r
+ \r
+ String version = schema.getVersion();\r
+ if (version == null)\r
+ version = "1.0";\r
+ ontologyUri +="-"+ version;\r
\r
\r
- name = name.replaceAll("\\.", "_");\r
- name = name.replaceAll(" ", "_");\r
String className = getPluginName() + "." + name;\r
\r
if (createPGraph) {\r
OntologyGenerator ontologyGenerator = new OntologyGenerator(configuration);\r
- ontologyGenerator.createOntology(schema, ontologyName, className, this);\r
+ ontologyGenerator.createOntology(schema, ontologyUri, className, this);\r
}\r
if (createImporter) {\r
ImporterGenerator importerGenerator = new ImporterGenerator(configuration);\r
- importerGenerator.createParser(schema, className, this);\r
+ importerGenerator.createParser(schema, ontologyUri, className, this);\r
}\r
if (createExporter) {\r
ExporterGenerator exporterGenerator = new ExporterGenerator(configuration);\r
- exporterGenerator.createParser(schema, className, this);\r
+ exporterGenerator.createParser(schema, ontologyUri,className, this);\r
}\r
}\r
\r