import java.io.StringWriter;\r
import java.util.ArrayList;\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.Inheritance;\r
import org.simantics.xml.sax.SchemaConversionBase.InheritanceType;\r
import org.simantics.xml.sax.SchemaConversionBase.RefType;\r
+import org.simantics.xml.sax.SchemaConversionBase.TypeEntry;\r
import org.simantics.xml.sax.SchemaObject.ObjectType;\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.UnrecognizedChildElement;\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.NamedGroup;\r
import org.w3._2001.xmlschema.Restriction;\r
-import org.w3._2001.xmlschema.Schema;\r
import org.w3._2001.xmlschema.SimpleType;\r
-import org.w3._2001.xmlschema.TopLevelAttribute;\r
\r
public class ImporterGenerator extends JavaGenerator{\r
\r
- public ImporterGenerator(Configuration configuration) {\r
- super(configuration);\r
+ public ImporterGenerator(SchemaConverter converter, SchemaConversionBase base) {\r
+ super(converter, base);\r
}\r
\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
+ public void createParser() throws IOException {\r
\r
- \r
- String packageParts[] = className.split("\\.");\r
- String name = packageParts[packageParts.length-1];\r
- \r
- \r
- ontShort = name.substring(0, 3).toUpperCase();\r
- ontShort +=".";\r
String parserPackagePostfix = "_elem";\r
String importerClassPostfix = "Importer";\r
String parserClassPostfix = "Parser";\r
if (!importParserDir.exists())\r
importParserDir.mkdirs();\r
\r
- handle(schema);\r
+ base.handle(this);\r
// Create Importer class\r
File importerFile = new File(converter.getParserDir().getAbsolutePath()+"/"+name+importerClassPostfix+".java");\r
PrintWriter mainWriter = createFile(importerFile);\r
mainWriter.flush();\r
mainWriter.close();\r
}\r
-\r
- protected void handle(TopLevelAttribute topLevelAttribute) {\r
+ \r
+ @Override\r
+ public void handleSimpleType(SchemaObject parent, SchemaObject simpleTypeObj) {\r
}\r
\r
@Override\r
- protected void handleSimpleType(SchemaObject parent, SchemaObject simpleTypeObj) {\r
+ public void handle(SchemaObject parent, NamedGroup attribute) {\r
+ // TODO Auto-generated method stub\r
}\r
\r
@Override\r
- protected void handleComplexType(SchemaObject complexTypeObj) {\r
+ public void handleComplexType(SchemaObject complexTypeObj) {\r
ComplexType topLevelComplexType = complexTypeObj.getComplexType();\r
\r
String name = getName(complexTypeObj);\r
}\r
writers.put(complexTypeObj, fw);\r
\r
- Inheritance inheritance = getInheritance(complexTypeObj);\r
+ Inheritance inheritance = this.base.getInheritance(complexTypeObj);\r
\r
- provider = getIDProvider(topLevelComplexType);\r
- List<IDReference> references = getIDReferences(topLevelComplexType);\r
- UnrecognizedChildElement unknownChildElement = getUnknown(topLevelComplexType);\r
+ provider = this.base.getIDProvider(topLevelComplexType);\r
+ List<IDReference> references = this.base.getIDReferences(topLevelComplexType);\r
+ UnrecognizedChildElement unknownChildElement = this.base.getUnknown(topLevelComplexType);\r
\r
List<String> intrerfaces = new ArrayList<String>();\r
if (references.size() > 0)\r
fw.writer.println(" public " + className + "() {");\r
fw.writer.println(" super();");\r
\r
- handleComplexTypeExtension(complexTypeObj);\r
+ this.base.handleComplexTypeExtension(complexTypeObj);\r
\r
fw.writer.println(" }");\r
\r
}\r
fw.writer.println(" "+getOntologyImport());\r
\r
- handleComplexTypeAttributes(complexTypeObj);\r
- handleExtensionAttributes(complexTypeObj);\r
+ this.base.handleComplexTypeAttributes(complexTypeObj);\r
+ this.base.handleExtensionAttributes(complexTypeObj);\r
\r
fw.writer.println(" }");\r
\r
}\r
\r
@Override\r
- protected void createReferenceIndicator(SchemaObject parent, RefType referenceType, String refName, String objectName, String primaryClassName, String secondaryClassName, boolean useElementList, boolean useOriginalList) {\r
+ public void createReferenceIndicator(SchemaObject parent, RefType referenceType, String refName, String objectName, String primaryClassName, String secondaryClassName, boolean useElementList, boolean useOriginalList) {\r
FileWriter fw = getWriter(parent);\r
if (referenceType == RefType.Type) {\r
// create internal class for handling the element and child attachment\r
fw.delayedWriter.println(" }");\r
}\r
\r
+ @Override\r
protected void createPrimitiveIndicator(SchemaObject parent, String refName, String binding) {\r
FileWriter fw = getWriter(parent);\r
fw.writer.println(" addParser(\""+ refName +"\", "+getName(parent) +"_" +refName+".class);");\r
fw.delayedWriter2.println(" }");\r
}\r
\r
+ @Override\r
protected void createElementIndicator(SchemaObject parent, boolean useElementList, String refName, String className, boolean useOriginalList) {\r
FileWriter fw = getWriter(parent);\r
//if (!reference)\r
}\r
\r
@Override\r
- protected void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement any) { \r
+ public void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement any) { \r
// generates overriding method that allows parsing any element\r
FileWriter fw = getWriter(parent);\r
fw.delayedWriter2.println(" @Override");\r
}\r
\r
@Override \r
- protected void handle(SchemaObject parent, Attribute attribute) {\r
+ public void handle(SchemaObject parent, Attribute attribute) {\r
+ if (parent == null)\r
+ return;\r
String name = attribute.getName();\r
QName primitiveType = attribute.getType();\r
SimpleType simpleType = attribute.getSimpleType();\r
attrName = ref.getLocalPart();\r
relationName = ontShort+getName(parent)+"_has"+ref.getLocalPart();\r
\r
- Attribute referred = getRefAttribute(ref);\r
+ Attribute referred = this.base.getRefAttribute(ref);\r
if (referred != null) {\r
primitiveType = referred.getType();\r
simpleType = referred.getSimpleType();\r
if (primitiveType != null) {\r
\r
//String binding = getBindingFromPrimitiveType(primitiveType);\r
- TypeEntry binding = getTypeEntry(primitiveType);\r
+ TypeEntry binding = this.base.getTypeEntry(primitiveType);\r
\r
if (binding != null) {\r
writeAttribute(fw, attrName, relationName, binding, isReference);\r
return;\r
} else {\r
if (simpleType == null) {\r
- SchemaObject simpleTypeObj = simpleTypeName.get(primitiveType.getLocalPart());\r
+ SchemaObject simpleTypeObj = this.base.simpleTypeName.get(primitiveType.getLocalPart());\r
if (simpleTypeObj != null)\r
simpleType = simpleTypeObj.getSimpleType();\r
} \r
if (simpleType != null) {\r
org.w3._2001.xmlschema.List list = simpleType.getList();\r
if (list != null) {\r
- TypeEntry binding = getTypeEntry(new QName(SCHEMA_NS, "string"));\r
+ TypeEntry binding = this.base.getTypeEntry(new QName(SchemaConversionBase.SCHEMA_NS, "string"));\r
writeAttribute(fw, attrName, relationName, binding, isReference);\r
} else {\r
Restriction restriction = simpleType.getRestriction();\r
\r
\r
//String binding = getBindingFromPrimitiveType(base);\r
- TypeEntry binding = getTypeEntry(base);\r
+ TypeEntry binding = this.base.getTypeEntry(base);\r
writeAttribute(fw, attrName, relationName, binding, isReference);\r
}\r
} else {\r
//throw new RuntimeException("Cannot resolve type for Attribute " + attrName + " -> " + primitiveType.getLocalPart());\r
fw.writer.println(" //FIXME: Cannot resolve type for Attribute " + attrName + " Using default type String");\r
//writeAttribute(fw, attrName, relationName, "STRING", isReference);\r
- writeAttribute(fw, attrName, relationName, getTypeEntry("string"), isReference);\r
+ writeAttribute(fw, attrName, relationName, this.base.getTypeEntry("string"), isReference);\r
}\r
}\r
\r
- //private void writeAttribute(FileWriter fw, String attrName, String relationName, String binding, boolean isReference) {\r
private void writeAttribute(FileWriter fw, String attrName, String relationName, TypeEntry binding, boolean isReference) {\r
fw.writer.println(" {");\r
fw.writer.println(" Attribute a = element.getAttribute(\"" +attrName+"\");");\r
}\r
\r
@Override\r
- protected void handleAttributes(SchemaObject simpleTypeObj) {\r
+ public void handleAttributes(SchemaObject simpleTypeObj) {\r
SchemaObject parent = simpleTypeObj.getParent();\r
FileWriter fw = getWriter(parent);\r
\r
\r
\r
//String binding = getBindingFromPrimitiveType(base);\r
- TypeEntry binding = getTypeEntry(base);\r
+ TypeEntry binding = this.base.getTypeEntry(base);\r
fw.writer.println(" @Override");\r
fw.writer.println(" public void configure(WriteGraph graph, ParserElement element, java.lang.String value) throws DatabaseException {");\r
//fw.writer.println(" graph.claimValue(element.getData(),"+getValueGetter(binding)+", Bindings."+binding+");");\r
}\r
\r
@Override\r
- protected void handle(SchemaObject parent, AttributeGroup attribute) {\r
+ public void handle(SchemaObject parent, AttributeGroup attribute) {\r
if (parent != null) {\r
FileWriter fw = getWriter(parent);\r
- NamedAttributeGroup group = getAttributeGroup(attribute.getRef().getLocalPart());\r
+ NamedAttributeGroup group = this.base.getAttributeGroup(attribute.getRef().getLocalPart());\r
fw.writer.println(commentTag+" AttributeGroup " + group.getName());\r
SchemaObject obj = new SchemaObject(parent,attribute);\r
for (Annotated annotated : group.getAttributeOrAttributeGroup()) {\r
}\r
\r
@Override\r
- protected void handleAttributeComposition(SchemaObject parent, AttributeComposition composition, BijectionMap<org.simantics.xml.sax.configuration.Attribute, Annotated> attributes) {\r
+ public void handleAttributeComposition(SchemaObject parent, AttributeComposition composition, BijectionMap<org.simantics.xml.sax.configuration.Attribute, Annotated> attributes) {\r
FileWriter fw = getWriter(parent);\r
- QName type = new QName(CONVERSION_NS, composition.getType());\r
- String arrayBinding = getBindingFromPrimitiveType(type);\r
- String javaType = getJavaTypeFromPrimitiveType(type);\r
+ QName type = new QName(SchemaConversionBase.CONVERSION_NS, composition.getType());\r
+ String arrayBinding = this.base.getBindingFromPrimitiveType(type);\r
+ String javaType = this.base.getJavaTypeFromPrimitiveType(type);\r
String name = composition.getName();\r
\r
String relationName;\r
for (org.simantics.xml.sax.configuration.Attribute a : composition.getAttribute()) {\r
Attribute attribute = ((Attribute)attributes.getRight(a));\r
//QName atype = getBaseType(attribute);\r
- QName atype = getPrimitiveType(attribute);\r
+ QName atype = this.base.getPrimitiveType(attribute);\r
String defaultValue = attribute.getDefault();\r
if (defaultValue == null)\r
- defaultValue = getDefaultValue(atype);\r
+ defaultValue = this.base.getDefaultValue(atype);\r
\r
//String binding = getBindingFromPrimitiveType(atype);\r
- TypeEntry binding = getTypeEntry(atype);\r
+ TypeEntry binding = this.base.getTypeEntry(atype);\r
if (i > 0)\r
fw.writer.print(",");\r
if (defaultValue != null)\r
\r
}\r
\r
- protected String getDefaultValue(QName atype) {\r
- Map<String,TypeEntry> types = typeMap.get(atype.getNamespaceURI());\r
- if (types == null)\r
- return null;\r
- TypeEntry entry = types.get(atype.getLocalPart());\r
- if (entry == null)\r
- return null;\r
- return entry.defaultValue;\r
- }\r
+ \r
\r
\r
\r
\r
IDProvider provider;\r
@Override\r
- protected void handleElement(SchemaObject elementObj) {\r
+ public void handleElement(SchemaObject elementObj) {\r
Element element = elementObj.getElement();\r
\r
String name = getName(elementObj);//topLevelElement.getName();\r
writers.put(elementObj, fw);\r
boolean isList = false;\r
\r
- Inheritance inheritance = getInheritance(elementObj); \r
+ Inheritance inheritance = this.base.getInheritance(elementObj); \r
\r
- provider = getIDProvider(element);\r
- List<IDReference> references = getIDReferences(element);\r
- UnrecognizedChildElement unknownChildElement = getUnknown(element);\r
+ provider = this.base.getIDProvider(element);\r
+ List<IDReference> references = this.base.getIDReferences(element);\r
+ UnrecognizedChildElement unknownChildElement = this.base.getUnknown(element);\r
\r
List<String> intrerfaces = new ArrayList<String>();\r
if (references.size() > 0)\r
LocalSimpleType simpleType = element.getSimpleType();\r
\r
if (complexType != null) {\r
- SchemaObject obj = complexTypes.get(complexType);\r
- handleElementComplexTypeAttributes(obj);\r
+ SchemaObject obj = this.base.complexTypes.get(complexType);\r
+ this.base.handleElementComplexTypeAttributes(obj);\r
} \r
fw.writer.println(" }");\r
\r
fw.writer.println(" super();");\r
\r
if (complexType != null) {\r
- SchemaObject obj = complexTypes.get(complexType);\r
- handleComplexTypeExtension(obj);\r
+ SchemaObject obj = this.base.complexTypes.get(complexType);\r
+ this.base.handleComplexTypeExtension(obj);\r
} else if (simpleType != null) {\r
\r
}\r
}\r
\r
@Override\r
- protected String getBaseClass(ObjectType type) {\r
+ public String getBaseClass(ObjectType type) {\r
return "org.simantics.xml.sax.base.XMLElementNamedChildParserBase";\r
}\r
\r