Search in sources :

Example 1 with ISchemaIncludeGenerator

use of com.twinsoft.convertigo.beans.core.ISchemaIncludeGenerator in project convertigo by convertigo.

the class XmlSchemaBuilder method preBuildSchema.

private void preBuildSchema() throws EngineException {
    try {
        schema.setElementFormDefault(new XmlSchemaForm(project.getSchemaElementForm().name()));
        schema.setAttributeFormDefault(new XmlSchemaForm(project.getSchemaElementForm().name()));
        ConvertigoError.addXmlSchemaObjects(schema);
        EngineStatistics.addXmlSchemaObjects(schema);
        // static and read-only generation : references, transactions, sequences declaration
        new WalkHelper() {

            @Override
            protected void walk(DatabaseObject databaseObject) throws Exception {
                if (databaseObject instanceof ISchemaGenerator) {
                    // generate itself and add to the caller list
                    if (databaseObject instanceof ISchemaImportGenerator) {
                        // Import case
                        if (databaseObject instanceof ProjectSchemaReference) {
                        // done further in buildSchema
                        } else {
                            XmlSchemaImport schemaImport = ((ISchemaImportGenerator) databaseObject).getXmlSchemaObject(collection, schema);
                            if (schemaImport != null) {
                                SchemaMeta.setXmlSchemaObject(schema, databaseObject, schemaImport);
                                XmlSchemaUtils.add(schema, schemaImport);
                            }
                        }
                    } else if (databaseObject instanceof ISchemaIncludeGenerator) {
                        // Include case
                        if (databaseObject instanceof Transaction) {
                            XmlSchemaInclude schemaInclude = ((ISchemaIncludeGenerator) databaseObject).getXmlSchemaObject(collection, schema);
                            addSchemaIncludeObjects(databaseObject, schemaInclude.getSchema());
                        } else {
                            XmlSchemaInclude schemaInclude = ((ISchemaIncludeGenerator) databaseObject).getXmlSchemaObject(collection, schema);
                            SchemaMeta.setXmlSchemaObject(schema, databaseObject, schemaInclude);
                            XmlSchemaUtils.add(schema, schemaInclude);
                        }
                    } else if (databaseObject instanceof Sequence) {
                        // Sequence case
                        XmlSchemaElement element = ((Sequence) databaseObject).getXmlSchemaObject(collection, schema);
                        SchemaMeta.setXmlSchemaObject(schema, databaseObject, element);
                        XmlSchemaUtils.add(schema, element);
                    }
                } else {
                    // doesn't generate schema, just deep walk
                    super.walk(databaseObject);
                }
            }

            @Override
            protected boolean before(DatabaseObject databaseObject, Class<? extends DatabaseObject> dboClass) {
                // just walk references, transactions, sequences declaration
                return Step.class.isAssignableFrom(dboClass) || Transaction.class.isAssignableFrom(dboClass) || Sequence.class.isAssignableFrom(dboClass) || Reference.class.isAssignableFrom(dboClass) || Connector.class.isAssignableFrom(dboClass);
            }

            protected void addSchemaIncludeObjects(DatabaseObject databaseObject, XmlSchema xmlSchema) {
                if (xmlSchema != null) {
                    XmlSchemaObjectCollection c = xmlSchema.getItems();
                    Iterator<XmlSchemaObject> it = GenericUtils.cast(c.getIterator());
                    while (it.hasNext()) {
                        XmlSchemaObject xmlSchemaObject = it.next();
                        SchemaMeta.getReferencedDatabaseObjects(xmlSchemaObject).add(databaseObject);
                        if (xmlSchemaObject instanceof XmlSchemaImport) {
                        // ignore
                        } else if (xmlSchemaObject instanceof XmlSchemaInclude) {
                            XmlSchemaInclude schemaInclude = (XmlSchemaInclude) xmlSchemaObject;
                            addSchemaIncludeObjects(databaseObject, schemaInclude.getSchema());
                        } else if (xmlSchemaObject instanceof XmlSchemaAttribute) {
                            XmlSchemaAttribute attribute = (XmlSchemaAttribute) xmlSchemaObject;
                            if (schema.getAttributes().getItem(attribute.getQName()) == null) {
                                schema.getAttributes().add(attribute.getQName(), attribute);
                                schema.getItems().add(attribute);
                            }
                        } else if (xmlSchemaObject instanceof XmlSchemaAttributeGroup) {
                            XmlSchemaAttributeGroup attributeGroup = (XmlSchemaAttributeGroup) xmlSchemaObject;
                            if (schema.getAttributeGroups().getItem(attributeGroup.getName()) == null) {
                                schema.getAttributeGroups().add(attributeGroup.getName(), attributeGroup);
                                schema.getItems().add(attributeGroup);
                            }
                        } else if (xmlSchemaObject instanceof XmlSchemaGroup) {
                            XmlSchemaGroup group = (XmlSchemaGroup) xmlSchemaObject;
                            if (schema.getGroups().getItem(group.getName()) == null) {
                                schema.getGroups().add(group.getName(), group);
                                schema.getItems().add(group);
                            }
                        } else if (xmlSchemaObject instanceof XmlSchemaElement) {
                            XmlSchemaElement element = (XmlSchemaElement) xmlSchemaObject;
                            if (collection.getElementByQName(element.getQName()) == null && schema.getElementByName(element.getQName()) == null) {
                                schema.getElements().add(element.getQName(), element);
                                schema.getItems().add(element);
                            }
                        } else if (xmlSchemaObject instanceof XmlSchemaType) {
                            XmlSchemaType schemaType = (XmlSchemaType) xmlSchemaObject;
                            if (collection.getTypeByQName(schemaType.getQName()) == null && schema.getTypeByName(schemaType.getQName()) == null) {
                                schema.addType(schemaType);
                                schema.getItems().add(schemaType);
                            }
                        } else {
                            schema.getItems().add(xmlSchemaObject);
                        }
                    }
                }
            }
        }.init(project);
    } catch (Exception e) {
        throw new EngineException("preBuildSchema failed", e);
    }
}
Also used : ProjectSchemaReference(com.twinsoft.convertigo.beans.references.ProjectSchemaReference) WalkHelper(com.twinsoft.convertigo.engine.helpers.WalkHelper) Step(com.twinsoft.convertigo.beans.core.Step) RequestableStep(com.twinsoft.convertigo.beans.core.RequestableStep) SequenceStep(com.twinsoft.convertigo.beans.steps.SequenceStep) XMLCopyStep(com.twinsoft.convertigo.beans.steps.XMLCopyStep) TransactionStep(com.twinsoft.convertigo.beans.steps.TransactionStep) XmlSchemaObject(org.apache.ws.commons.schema.XmlSchemaObject) Iterator(java.util.Iterator) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) XmlSchemaImport(org.apache.ws.commons.schema.XmlSchemaImport) XmlSchemaObjectCollection(org.apache.ws.commons.schema.XmlSchemaObjectCollection) ISchemaIncludeGenerator(com.twinsoft.convertigo.beans.core.ISchemaIncludeGenerator) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) Reference(com.twinsoft.convertigo.beans.core.Reference) ProjectSchemaReference(com.twinsoft.convertigo.beans.references.ProjectSchemaReference) XmlSchemaAttributeGroup(org.apache.ws.commons.schema.XmlSchemaAttributeGroup) XmlSchemaForm(org.apache.ws.commons.schema.XmlSchemaForm) XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) Sequence(com.twinsoft.convertigo.beans.core.Sequence) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType) XmlSchemaAttribute(org.apache.ws.commons.schema.XmlSchemaAttribute) XmlSchemaGroup(org.apache.ws.commons.schema.XmlSchemaGroup) Transaction(com.twinsoft.convertigo.beans.core.Transaction) XmlSchema(org.apache.ws.commons.schema.XmlSchema) ISchemaImportGenerator(com.twinsoft.convertigo.beans.core.ISchemaImportGenerator) XmlSchemaInclude(org.apache.ws.commons.schema.XmlSchemaInclude) ISchemaGenerator(com.twinsoft.convertigo.beans.core.ISchemaGenerator)

Aggregations

DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)1 ISchemaGenerator (com.twinsoft.convertigo.beans.core.ISchemaGenerator)1 ISchemaImportGenerator (com.twinsoft.convertigo.beans.core.ISchemaImportGenerator)1 ISchemaIncludeGenerator (com.twinsoft.convertigo.beans.core.ISchemaIncludeGenerator)1 Reference (com.twinsoft.convertigo.beans.core.Reference)1 RequestableStep (com.twinsoft.convertigo.beans.core.RequestableStep)1 Sequence (com.twinsoft.convertigo.beans.core.Sequence)1 Step (com.twinsoft.convertigo.beans.core.Step)1 Transaction (com.twinsoft.convertigo.beans.core.Transaction)1 ProjectSchemaReference (com.twinsoft.convertigo.beans.references.ProjectSchemaReference)1 SequenceStep (com.twinsoft.convertigo.beans.steps.SequenceStep)1 TransactionStep (com.twinsoft.convertigo.beans.steps.TransactionStep)1 XMLCopyStep (com.twinsoft.convertigo.beans.steps.XMLCopyStep)1 WalkHelper (com.twinsoft.convertigo.engine.helpers.WalkHelper)1 Iterator (java.util.Iterator)1 XmlSchema (org.apache.ws.commons.schema.XmlSchema)1 XmlSchemaAttribute (org.apache.ws.commons.schema.XmlSchemaAttribute)1 XmlSchemaAttributeGroup (org.apache.ws.commons.schema.XmlSchemaAttributeGroup)1 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)1 XmlSchemaForm (org.apache.ws.commons.schema.XmlSchemaForm)1