private XmlSchemaAttributeGroup handleAttributeGroup(XmlSchema schema, Element groupEl, Element schemaEl) { XmlSchemaAttributeGroup attrGroup = new XmlSchemaAttributeGroup(); if (groupEl.hasAttribute("name")) attrGroup.name = new QName(schema.getTargetNamespace(), groupEl .getAttribute("name")); if (groupEl.hasAttribute("id")) attrGroup.id = groupEl.getAttribute("id"); for (Element el = XDOMUtil.getFirstChildElementNS(groupEl, XmlSchema.SCHEMA_NS); el != null; el = XDOMUtil .getNextSiblingElementNS(el, XmlSchema.SCHEMA_NS)) { if (el.getLocalName().equals("attribute")) { XmlSchemaAttribute attr = handleAttribute(schema, el, schemaEl); attrGroup.attributes.add(attr); } else if (el.getLocalName().equals("attributeGroup")) { XmlSchemaAttributeGroupRef attrGroupRef = handleAttributeGroupRef(el); attrGroup.attributes.add(attrGroupRef); } else if (el.getLocalName().equals("anyAttribute")) { attrGroup.anyAttribute = handleAnyAttribute(schema, el, schemaEl); } else if (el.getLocalName().equals("annotation")) { XmlSchemaAnnotation ann = handleAnnotation(el); attrGroup.setAnnotation(ann); } } return attrGroup; }
choice.items.add(seq); } else if (el.getLocalName().equals("element")) { XmlSchemaElement element = handleElement(schema, el, schemaEl, false); choice.items.add(element); } else if (el.getLocalName().equals("group")) { XmlSchemaGroupRef group = handleGroupRef(schema, el, schemaEl); choice.items.add(group); } else if (el.getLocalName().equals("choice")) { XmlSchemaChoice choiceItem = handleChoice(schema, el, schemaEl); choice.items.add(choiceItem); } else if (el.getLocalName().equals("any")) { XmlSchemaAny any = handleAny(schema, el, schemaEl); choice.items.add(any); } else if (el.getLocalName().equals("annotation")) { XmlSchemaAnnotation annotation = handleAnnotation(el);
private XmlSchemaAttributeGroup handleAttributeGroup(XmlSchema schema, Element groupEl, Element schemaEl) { XmlSchemaAttributeGroup attrGroup = new XmlSchemaAttributeGroup(); if (groupEl.hasAttribute("name")) attrGroup.name = new QName(schema.getTargetNamespace(), groupEl .getAttribute("name")); if (groupEl.hasAttribute("id")) attrGroup.id = groupEl.getAttribute("id"); for (Element el = XDOMUtil.getFirstChildElementNS(groupEl, XmlSchema.SCHEMA_NS); el != null; el = XDOMUtil .getNextSiblingElementNS(el, XmlSchema.SCHEMA_NS)) { if (el.getLocalName().equals("attribute")) { XmlSchemaAttribute attr = handleAttribute(schema, el, schemaEl); attrGroup.attributes.add(attr); } else if (el.getLocalName().equals("attributeGroup")) { XmlSchemaAttributeGroupRef attrGroupRef = handleAttributeGroupRef(el); attrGroup.attributes.add(attrGroupRef); } else if (el.getLocalName().equals("anyAttribute")) { attrGroup.anyAttribute = handleAnyAttribute(schema, el, schemaEl); } else if (el.getLocalName().equals("annotation")) { XmlSchemaAnnotation ann = handleAnnotation(el); attrGroup.setAnnotation(ann); } } return attrGroup; }
private XmlSchemaSimpleContentExtension handleSimpleContentExtension( XmlSchema schema, Element extEl, Element schemaEl) { XmlSchemaSimpleContentExtension ext = new XmlSchemaSimpleContentExtension(); if (extEl.hasAttribute("base")) { String name = extEl.getAttribute("base"); ext.baseTypeName = getRefQName(name, extEl); } for (Element el = XDOMUtil.getFirstChildElementNS(extEl, XmlSchema.SCHEMA_NS); el != null; el = XDOMUtil .getNextSiblingElementNS(el, XmlSchema.SCHEMA_NS)) { if (el.getLocalName().equals("attribute")) { XmlSchemaAttribute attr = handleAttribute(schema, el, schemaEl); ext.attributes.add(attr); } else if (el.getLocalName().equals("attributeGroup")) { XmlSchemaAttributeGroupRef attrGroup = handleAttributeGroupRef(el); ext.attributes.add(attrGroup); } else if (el.getLocalName().equals("anyAttribute")) { ext.anyAttribute = handleAnyAttribute(schema, el, schemaEl); } else if (el.getLocalName().equals("annotation")) { XmlSchemaAnnotation ann = handleAnnotation(el); ext.setAnnotation(ann); } } return ext; }
private XmlSchemaSimpleContentExtension handleSimpleContentExtension( XmlSchema schema, Element extEl, Element schemaEl) { XmlSchemaSimpleContentExtension ext = new XmlSchemaSimpleContentExtension(); if (extEl.hasAttribute("base")) { String name = extEl.getAttribute("base"); ext.baseTypeName = getRefQName(name, extEl); } for (Element el = XDOMUtil.getFirstChildElementNS(extEl, XmlSchema.SCHEMA_NS); el != null; el = XDOMUtil .getNextSiblingElementNS(el, XmlSchema.SCHEMA_NS)) { if (el.getLocalName().equals("attribute")) { XmlSchemaAttribute attr = handleAttribute(schema, el, schemaEl); ext.attributes.add(attr); } else if (el.getLocalName().equals("attributeGroup")) { XmlSchemaAttributeGroupRef attrGroup = handleAttributeGroupRef(el); ext.attributes.add(attrGroup); } else if (el.getLocalName().equals("anyAttribute")) { ext.anyAttribute = handleAnyAttribute(schema, el, schemaEl); } else if (el.getLocalName().equals("annotation")) { XmlSchemaAnnotation ann = handleAnnotation(el); ext.setAnnotation(ann); } } return ext; }
private XmlSchemaComplexContentExtension handleComplexContentExtension( XmlSchema schema, Element extEl, Element schemaEl) { XmlSchemaComplexContentExtension ext = new XmlSchemaComplexContentExtension(); if (extEl.hasAttribute("base")) { String name = extEl.getAttribute("base"); ext.baseTypeName = getRefQName(name, extEl); } for (Element el = XDOMUtil.getFirstChildElementNS(extEl, XmlSchema.SCHEMA_NS); el != null; el = XDOMUtil .getNextSiblingElementNS(el, XmlSchema.SCHEMA_NS)) { if (el.getLocalName().equals("sequence")) { ext.particle = handleSequence(schema, el, schemaEl); } else if (el.getLocalName().equals("choice")) { ext.particle = handleChoice(schema, el, schemaEl); } else if (el.getLocalName().equals("all")) { ext.particle = handleAll(schema, el, schemaEl); } else if (el.getLocalName().equals("attribute")) { ext.attributes.add(handleAttribute(schema, el, schemaEl)); } else if (el.getLocalName().equals("attributeGroup")) { ext.attributes.add(handleAttributeGroupRef(el)); } else if (el.getLocalName().equals("group")) { ext.particle = handleGroupRef(schema, el, schemaEl); } else if (el.getLocalName().equals("anyAttribute")) { ext.anyAttribute = handleAnyAttribute(schema, el, schemaEl); } else if (el.getLocalName().equals("annotation")) { ext.setAnnotation(handleAnnotation(el)); } } return ext; }
} else if (el.getLocalName().equals("attribute")) { restriction.attributes .add(handleAttribute(schema, el, schemaEl)); } else if (el.getLocalName().equals("attributeGroup")) { restriction.attributes.add(handleAttributeGroupRef(el)); } else if (el.getLocalName().equals("group")) { restriction.particle = handleGroupRef(schema, el, schemaEl);
private XmlSchemaComplexContentExtension handleComplexContentExtension( XmlSchema schema, Element extEl, Element schemaEl) { XmlSchemaComplexContentExtension ext = new XmlSchemaComplexContentExtension(); if (extEl.hasAttribute("base")) { String name = extEl.getAttribute("base"); ext.baseTypeName = getRefQName(name, extEl); } for (Element el = XDOMUtil.getFirstChildElementNS(extEl, XmlSchema.SCHEMA_NS); el != null; el = XDOMUtil .getNextSiblingElementNS(el, XmlSchema.SCHEMA_NS)) { if (el.getLocalName().equals("sequence")) { ext.particle = handleSequence(schema, el, schemaEl); } else if (el.getLocalName().equals("choice")) { ext.particle = handleChoice(schema, el, schemaEl); } else if (el.getLocalName().equals("all")) { ext.particle = handleAll(schema, el, schemaEl); } else if (el.getLocalName().equals("attribute")) { ext.attributes.add(handleAttribute(schema, el, schemaEl)); } else if (el.getLocalName().equals("attributeGroup")) { ext.attributes.add(handleAttributeGroupRef(el)); } else if (el.getLocalName().equals("group")) { ext.particle = handleGroupRef(schema, el, schemaEl); } else if (el.getLocalName().equals("anyAttribute")) { ext.anyAttribute = handleAnyAttribute(schema, el, schemaEl); } else if (el.getLocalName().equals("annotation")) { ext.setAnnotation(handleAnnotation(el)); } } return ext; }
XmlSchemaAttribute attr = handleAttribute(schema, el, schemaEl); ext.attributes.add(attr); } else if (el.getLocalName().equals("attributeGroup")) { XmlSchemaAttributeGroupRef attrGroup = handleAttributeGroupRef(el); ext.attributes.add(attrGroup); } else if (el.getLocalName().equals("anyAttribute")) { ext.anyAttribute =
/** * Resolves schema imports by adding an schema import section to the host schema. * @param hostSchema The host schema * @param refNamespace The external schema reference */ private static void resolveSchemaImports(XmlSchema hostSchema, String refNamespace) { if (!hostSchema.getTargetNamespace().equals(refNamespace)) { XmlSchemaImport schemaImport = new XmlSchemaImport(); schemaImport.setNamespace(refNamespace); if (!containsSchemaImport(hostSchema, schemaImport)) { hostSchema.getItems().add(schemaImport); } } }
private XmlSchemaAll handleAll(XmlSchema schema, Element allEl, Element schemaEl) { XmlSchemaAll all = new XmlSchemaAll(); //handle min and max occurences all.minOccurs = getMinOccurs(allEl); all.maxOccurs = getMaxOccurs(allEl); for (Element el = XDOMUtil.getFirstChildElementNS(allEl, XmlSchema.SCHEMA_NS); el != null; el = XDOMUtil.getNextSiblingElementNS(el, XmlSchema.SCHEMA_NS)) { if (el.getLocalName().equals("element")) { XmlSchemaElement element = handleElement(schema, el, schemaEl, false); all.items.add(element); } else if (el.getLocalName().equals("annotation")) { XmlSchemaAnnotation annotation = handleAnnotation(el); all.setAnnotation(annotation); } } return all; }
/** * Creates XML schema complex type with the given namespace and the name. * @param cparams The common parameters used in the schema generator * @param namespace The namespace of the complex type * @param name The name of the complex type * @param global Signal if the newly created type is global or not * @return The newly create XML schema complex type */ private static XmlSchemaComplexType createComplexType(CommonParams cparams, String namespace, String name, boolean global) { XmlSchema schema = retrieveSchema(cparams, namespace); XmlSchemaComplexType type = new XmlSchemaComplexType(schema); Map<QName, XmlSchemaComplexType> typeMap = cparams.getTypeMap(); if (global) { QName qname = new QName(namespace, name); if (typeMap.containsKey(qname)) { int suffix = 1; // start with 2, if T is there, the next one would be T2 while (typeMap.containsKey(new QName(namespace, name + (++suffix)))); name = name + suffix; qname = new QName(namespace, name); } type.setName(name); cparams.getTypeMap().put(qname, type); schema.getItems().add(type); schema.getSchemaTypes().add(qname, type); } return type; }
private XmlSchemaAll handleAll(XmlSchema schema, Element allEl, Element schemaEl) { XmlSchemaAll all = new XmlSchemaAll(); //handle min and max occurences all.minOccurs = getMinOccurs(allEl); all.maxOccurs = getMaxOccurs(allEl); for (Element el = XDOMUtil.getFirstChildElementNS(allEl, XmlSchema.SCHEMA_NS); el != null; el = XDOMUtil .getNextSiblingElementNS(el, XmlSchema.SCHEMA_NS)) { if (el.getLocalName().equals("element")) { XmlSchemaElement element = handleElement(schema, el, schemaEl, false); all.items.add(element); } else if (el.getLocalName().equals("annotation")) { XmlSchemaAnnotation annotation = handleAnnotation(el); all.setAnnotation(annotation); } } return all; }
private XmlSchemaAll handleAll(XmlSchema schema, Element allEl, Element schemaEl) { XmlSchemaAll all = new XmlSchemaAll(); //handle min and max occurences all.minOccurs = getMinOccurs(allEl); all.maxOccurs = getMaxOccurs(allEl); for (Element el = XDOMUtil.getFirstChildElementNS(allEl, XmlSchema.SCHEMA_NS); el != null; el = XDOMUtil .getNextSiblingElementNS(el, XmlSchema.SCHEMA_NS)) { if (el.getLocalName().equals("element")) { XmlSchemaElement element = handleElement(schema, el, schemaEl, false); all.items.add(element); } else if (el.getLocalName().equals("annotation")) { XmlSchemaAnnotation annotation = handleAnnotation(el); all.setAnnotation(annotation); } } return all; }
private static XmlSchemaObjectCollection getSchemaObjectsFromComplexType(XmlSchemaComplexType schemaComplexType) { XmlSchemaObjectCollection collection = new XmlSchemaObjectCollection(); XmlSchemaSequence sequence = (XmlSchemaSequence) schemaComplexType.getParticle(); if (sequence != null) { XmlSchemaObjectCollection seqItems = sequence.getItems(); int c = seqItems.getCount(); for (int i = 0; i < c; i++) { // add elements collection.add(seqItems.getItem(i)); } } XmlSchemaObjectCollection attrItems = schemaComplexType.getAttributes(); int c = attrItems.getCount(); for (int i = 0; i < c; i++) { // add attributes collection.add(attrItems.getItem(i)); } return collection; }
/** * Adds the given parameter to the complex type. * @param complexType The complex type which the attribute will be added to * @param name The name of the attribute * @param xsdType The type of the attribute */ @SuppressWarnings("unchecked") private static void addAttributeToComplexType(XmlSchemaComplexType complexType, String name, QName xsdType) { XmlSchemaAttribute attr = new XmlSchemaAttribute(); attr.setName(name); attr.setSchemaTypeName(xsdType); attr.setUse(new XmlSchemaUse("optional")); XmlSchemaAttribute tmpAttr; for (Iterator<XmlSchemaAttribute> itr = complexType.getAttributes().getIterator(); itr.hasNext();) { tmpAttr = itr.next(); if (tmpAttr.getName().equals(attr.getName())) { /* current attribute is already set, nothing more to do */ return; } } complexType.getAttributes().add(attr); }
private void inlineIncludes(XmlSchema schema, Set<XmlSchema> processedIncludes, Set<XmlSchema> processedImports) { processedIncludes.add(schema); XmlSchemaObjectCollection schemaItems = schema.getItems(); for (int i = 0; i < schemaItems.getCount(); i++) { XmlSchemaObject schemaObject = schemaItems.getItem(i); if (schemaObject instanceof XmlSchemaInclude) { XmlSchema includedSchema = ((XmlSchemaInclude) schemaObject).getSchema(); if (!processedIncludes.contains(includedSchema)) { inlineIncludes(includedSchema, processedIncludes, processedImports); findImports(includedSchema, processedImports, processedIncludes); XmlSchemaObjectCollection includeItems = includedSchema.getItems(); for (int j = 0; j < includeItems.getCount(); j++) { XmlSchemaObject includedItem = includeItems.getItem(j); schemaItems.add(includedItem); } } // remove the <include/> schemaItems.removeAt(i); i--; } } }
/** * Creates the default data services response element, and stores it in the schema. * @param cparams The common parameters used in the schema generator */ private static void createAndStoreDataServiceResponseElement(CommonParams cparams) { XmlSchemaElement element = createElement(cparams, DBConstants.WSO2_DS_NAMESPACE, DBConstants.DATA_SERVICE_RESPONSE_WRAPPER_ELEMENT, true); XmlSchemaComplexType type = createComplexType(cparams, DBConstants.WSO2_DS_NAMESPACE, DBConstants.DATA_SERVICE_RESPONSE_WRAPPER_ELEMENT, false); element.setType(type); XmlSchemaAny anyEl = new XmlSchemaAny(); anyEl.setMinOccurs(0); XmlSchemaSequence seq = new XmlSchemaSequence(); seq.getItems().add(anyEl); type.setParticle(seq); }
/** * Create a nex XML schema element. * <p/> * We use the source URI to mark these injected elements. * * @param typeQName the element type * @param elementQName the element name * @param schema the XML schema */ public static void addXmlSchemaElement(final QName typeQName, final QName elementQName, final XmlSchema schema) { XmlSchemaElement el = new XmlSchemaElement(); el.setQName(elementQName); el.setName(elementQName.getLocalPart()); el.setSchemaTypeName(typeQName); el.setSchemaType(schema.getTypeByName(typeQName)); el.setSourceURI(XsdConstants.INJECTED_ELEMENT); schema.getElements().add(elementQName, el); schema.getItems().add(el); }