private boolean isReferenceSchemaTypeDefined(QName objectReferenceName, XmlSchema refSchema) { List<XmlSchemaObject> schemaObjects = refSchema.getItems(); for (XmlSchemaObject schemaObj : schemaObjects) { if (schemaObj instanceof XmlSchemaElement) { XmlSchemaElement el = (XmlSchemaElement)schemaObj; if (el.getName().equals(objectReferenceName.getLocalPart())) { return true; } } } return false; }
/** * Process each element in the input Schema. * <p/> * Use root elements (as opposed to named complex types) to drive the * process because we need to reconstruct a hierarchy of complex types. * Elements give us the roots to start from. * */ public void visit() throws XsdMappingException { if (_log.isDebugEnabled()) { _log.debug("visit XML Schema started"); } processCollectionElements(_schema.getItems(), 1); if (_log.isDebugEnabled()) { _log.debug("visit XML Schema ended"); } }
@Override public void write(StringBuilder sb) { for (XmlSchema xs : coll.getXmlSchemas()) { if (xs.getItems().isEmpty() || Constants.URI_2001_SCHEMA_XSD.equals(xs.getTargetNamespace())) { continue; } StringWriter writer = new StringWriter(); xs.write(writer); sb.append(writer.toString()); } } }
@Override public void write(StringBuilder sb) { for (XmlSchema xs : coll.getXmlSchemas()) { if (xs.getItems().isEmpty() || Constants.URI_2001_SCHEMA_XSD.equals(xs.getTargetNamespace())) { continue; } StringWriter writer = new StringWriter(); xs.write(writer); sb.append(writer.toString()); } } }
public void write(StringBuilder sb) { for (XmlSchema xs : coll.getXmlSchemas()) { if (xs.getItems().isEmpty() || WSDLConstants.NS_SCHEMA_XSD.equals(xs.getTargetNamespace())) { continue; } StringWriter writer = new StringWriter(); xs.write(writer); sb.append(writer.toString()); } } }
private void addImport(XmlSchema schema, String ns) { if (!ns.equals(schema.getTargetNamespace()) && !ns.equals(WSDLConstants.NS_SCHEMA_XSD) && !isExistImport(schema, ns)) { XmlSchemaImport is = new XmlSchemaImport(schema); is.setNamespace(ns); if (this.schemaLocationMapping.get(ns) != null) { is.setSchemaLocation(this.schemaLocationMapping.get(ns)); } if (!schema.getItems().contains(is)) { schema.getItems().add(is); } } }
private void addImport(XmlSchema schema, String ns) { if (!ns.equals(schema.getTargetNamespace()) && !ns.equals(WSDLConstants.NS_SCHEMA_XSD) && !isExistImport(schema, ns)) { XmlSchemaImport is = new XmlSchemaImport(schema); is.setNamespace(ns); if (this.schemaLocationMapping.get(ns) != null) { is.setSchemaLocation(this.schemaLocationMapping.get(ns)); } if (!schema.getItems().contains(is)) { schema.getItems().add(is); } } }
private void addImport(XmlSchema schema, String ns) { if (!ns.equals(schema.getTargetNamespace()) && !ns.equals(WSDLConstants.NS_SCHEMA_XSD) && !isExistImport(schema, ns)) { XmlSchemaImport is = new XmlSchemaImport(schema); is.setNamespace(ns); if (this.schemaLocationMapping.get(ns) != null) { is.setSchemaLocation(this.schemaLocationMapping.get(ns)); } if (!schema.getItems().contains(is)) { schema.getItems().add(is); } } }
public void fixUpMovedTypeReferences(String fromNamespace, String toNamespace, XmlSchemaObject fixUpObj, List<XmlSchema> relatedSchema){ if (!(fixUpObj instanceof XmlSchemaComplexType)){ return; } for (XmlSchema schema : relatedSchema){ int importRemoveIndex = -1; for (int i = 0; i < schema.getItems().getCount(); i++){ XmlSchemaObject obj = schema.getItems().getItem(i); processXMLSchemaObject(toNamespace, obj, fixUpObj); // remove FROM imports if (obj instanceof XmlSchemaImport && ((XmlSchemaImport)obj).getNamespace().equals(fromNamespace)){ importRemoveIndex = i; } } if (importRemoveIndex >= 0){ schema.getItems().removeAt(importRemoveIndex); } } }
protected void addImport(XmlSchema xmlSchema, QName schemaTypeName) { NamespacePrefixList map = xmlSchema.getNamespaceContext(); if (map == null || ((map instanceof NamespaceMap) && ((NamespaceMap) map).values() == null) || schemaTypeName == null) { return; } if (map instanceof NamespaceMap && !((NamespaceMap) map).values(). contains(schemaTypeName.getNamespaceURI())) { XmlSchemaImport importElement = new XmlSchemaImport(xmlSchema); importElement.setNamespace(schemaTypeName.getNamespaceURI()); if (!xmlSchema.getItems().contains(importElement)) { xmlSchema.getItems().add(importElement); } ((NamespaceMap) xmlSchema.getNamespaceContext()). put(generatePrefix(), schemaTypeName.getNamespaceURI()); } }
protected void addImport(XmlSchema xmlSchema, QName schemaTypeName) { NamespacePrefixList map = xmlSchema.getNamespaceContext(); if (map == null || ((map instanceof NamespaceMap) && ((NamespaceMap) map).values() == null) || schemaTypeName == null) { return; } if (map instanceof NamespaceMap && !((NamespaceMap) map).values(). contains(schemaTypeName.getNamespaceURI())) { XmlSchemaImport importElement = new XmlSchemaImport(xmlSchema); importElement.setNamespace(schemaTypeName.getNamespaceURI()); if (!xmlSchema.getItems().contains(importElement)) { xmlSchema.getItems().add(importElement); } ((NamespaceMap) xmlSchema.getNamespaceContext()). put(generatePrefix(), schemaTypeName.getNamespaceURI()); } }
private void generateComplexTypeforException() { XmlSchemaSequence sequence = new XmlSchemaSequence(); XmlSchema xmlSchema = getXmlSchema(schemaTargetNameSpace); QName elementName = new QName(schemaTargetNameSpace, "Exception", schema_namespace_prefix); XmlSchemaComplexType complexType = new XmlSchemaComplexType(xmlSchema, false); complexType.setName("Exception"); xmlSchema.getItems().add(complexType); xmlSchema.getSchemaTypes().put(elementName, complexType); typeTable.addComplexSchema(Exception.class.getName(), elementName); QName schemaTypeName = new QName(Java2WSDLConstants.URI_2001_SCHEMA_XSD, "string"); addContentToMethodSchemaType(sequence, schemaTypeName, "Message", false); complexType.setParticle(sequence); }
private void generateComplexTypeforException() { XmlSchemaSequence sequence = new XmlSchemaSequence(); XmlSchema xmlSchema = getXmlSchema(schemaTargetNameSpace); QName elementName = new QName(schemaTargetNameSpace, "Exception", schema_namespace_prefix); XmlSchemaComplexType complexType = new XmlSchemaComplexType(xmlSchema, false); complexType.setName("Exception"); xmlSchema.getItems().add(complexType); xmlSchema.getSchemaTypes().put(elementName, complexType); typeTable.addComplexSchema(Exception.class.getName(), elementName); QName schemaTypeName = new QName(Java2WSDLConstants.URI_2001_SCHEMA_XSD, "string"); addContentToMethodSchemaType(sequence, schemaTypeName, "Message", false); complexType.setParticle(sequence); }
protected XmlSchemaComplexType getComplexTypeForElement(XmlSchema xmlSchema, QName name) { for (XmlSchemaObject object : xmlSchema.getItems()) { if (object instanceof XmlSchemaElement && ((XmlSchemaElement) object).getQName().equals(name)) { XmlSchemaComplexType xmlSchemaComplexType = (XmlSchemaComplexType) ((XmlSchemaElement) object).getSchemaType(); if ((xmlSchemaComplexType == null) && (((XmlSchemaElement) object).getSchemaTypeName() != null)) { xmlSchemaComplexType = (XmlSchemaComplexType) xmlSchema.getTypeByName(((XmlSchemaElement) object).getSchemaTypeName()); } return xmlSchemaComplexType; } } return null; }
protected XmlSchemaComplexType getComplexTypeForElement(XmlSchema xmlSchema, QName name) { for (XmlSchemaObject object : xmlSchema.getItems()) { if (object instanceof XmlSchemaElement && ((XmlSchemaElement) object).getQName().equals(name)) { XmlSchemaComplexType xmlSchemaComplexType = (XmlSchemaComplexType) ((XmlSchemaElement) object).getSchemaType(); if ((xmlSchemaComplexType == null) && (((XmlSchemaElement) object).getSchemaTypeName() != null)) { xmlSchemaComplexType = (XmlSchemaComplexType) xmlSchema.getTypeByName(((XmlSchemaElement) object).getSchemaTypeName()); } return xmlSchemaComplexType; } } return null; }
protected void generateSchemaForSingleElement(QName schemaTypeName, String paraName, boolean isArray) throws Exception { XmlSchemaElement elt1 = new XmlSchemaElement(getXmlSchema(schemaTargetNameSpace), false); elt1.setName(paraName); elt1.setSchemaTypeName(schemaTypeName); elt1.setNillable(true); QName elementName = new QName(schemaTargetNameSpace, paraName, schema_namespace_prefix); XmlSchema xmlSchema = getXmlSchema(schemaTargetNameSpace); xmlSchema.getElements().put(elementName, elt1); xmlSchema.getItems().add(elt1); typeTable.addComplexSchema(paraName, elementName); }
/** * 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); } } }
protected void generateSchemaForSingleElement(QName schemaTypeName, String paraName, boolean isArray) throws Exception { XmlSchemaElement elt1 = new XmlSchemaElement(getXmlSchema(schemaTargetNameSpace), false); elt1.setName(paraName); elt1.setSchemaTypeName(schemaTypeName); elt1.setNillable(true); QName elementName = new QName(schemaTargetNameSpace, paraName, schema_namespace_prefix); XmlSchema xmlSchema = getXmlSchema(schemaTargetNameSpace); xmlSchema.getElements().put(elementName, elt1); xmlSchema.getItems().add(elt1); typeTable.addComplexSchema(paraName, elementName); }
/** * Generate schema construct for given type * * @param localPartName */ private XmlSchemaComplexType createSchemaTypeForMethodPart(String localPartName) { XmlSchema xmlSchema = getXmlSchema(schemaTargetNameSpace); QName elementName = new QName(this.schemaTargetNameSpace, localPartName, this.schema_namespace_prefix); XmlSchemaComplexType complexType = getComplexTypeForElement(xmlSchema, elementName); if (complexType == null) { complexType = new XmlSchemaComplexType(xmlSchema, false); XmlSchemaElement globalElement = new XmlSchemaElement(xmlSchema, false); globalElement.setSchemaType(complexType); globalElement.setName(localPartName); xmlSchema.getItems().add(globalElement); xmlSchema.getElements().put(elementName, globalElement); } typeTable.addComplexSchema(localPartName, elementName); return complexType; }
/** * 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); }