public XmlSchema getSchemaForElement(QName name) { for (XmlSchema schema : schemaCollection.getXmlSchemas()) { if (name.getNamespaceURI().equals(schema.getTargetNamespace())) { if (schema.getElementByName(name.getLocalPart()) != null) { return schema; } else if (schema.getElementByName(name) != null) { return schema; } } } return null; }
@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()); } } }
private void addSchema(Map<String, EmbeddedSchema> sources, XmlSchema schema, Element element) throws XMLStreamException { String schemaSystemId = schema.getSourceURI(); if (null == schemaSystemId) { schemaSystemId = schema.getTargetNamespace(); } EmbeddedSchema embeddedSchema = new EmbeddedSchema(schemaSystemId, element); sources.put(schema.getTargetNamespace(), embeddedSchema); }
/** * Search this schema for a type by qname. * @param name * @return the type. */ public XmlSchemaType getTypeByName(String name) { QName nameToSearchFor = new QName(this.getTargetNamespace(),name); return getTypeByName(nameToSearchFor, false, null); }
public XmlSchemaElement getElementByQName(QName qname) { String uri = qname.getNamespaceURI(); if (schema != null && schema.getTargetNamespace() != null && schema.getTargetNamespace().equals(uri)) { return schema.getElementByName(qname); } return null; }
private XmlSchemaGroup handleGroup(XmlSchema schema, Element groupEl, Element schemaEl) { XmlSchemaGroup group = new XmlSchemaGroup(); group.name = new QName(schema.getTargetNamespace(), groupEl .getAttribute("name")); for (Element el = XDOMUtil.getFirstChildElementNS(groupEl, XmlSchema.SCHEMA_NS); el != null; el = XDOMUtil .getNextSiblingElementNS(el, XmlSchema.SCHEMA_NS)) { if (el.getLocalName().equals("all")) { group.particle = handleAll(schema, el, schemaEl); } else if (el.getLocalName().equals("sequence")) { group.particle = handleSequence(schema, el, schemaEl); } else if (el.getLocalName().equals("choice")) { group.particle = handleChoice(schema, el, schemaEl); } else if (el.getLocalName().equals("annotation")) { XmlSchemaAnnotation groupAnnotation = handleAnnotation(el); group.setAnnotation(groupAnnotation); } } return group; }
protected QName checkPrefix(QName schematypeName) { QName name = schematypeName; if ((name != null) && (name.getPrefix() == null || name.getPrefix().isEmpty())) { if (StringUtils.isEmpty(name.getNamespaceURI())) { return name; } String prefix = def.getPrefix(name.getNamespaceURI()); if (prefix == null) { prefix = xmlSchemaList.getSchemaByTargetNamespace(name.getNamespaceURI()) .getNamespaceContext().getPrefix(name.getNamespaceURI()); } if (prefix != null) { return new QName(name.getNamespaceURI(), name.getLocalPart(), prefix); } return null; } return name; }
protected void checkForElement(ServiceInfo serviceInfo, MessagePartInfo mpi) { SchemaInfo si = getOrCreateSchema(serviceInfo, mpi.getElementQName().getNamespaceURI(), getQualifyWrapperSchema()); XmlSchemaElement e = si.getSchema().getElementByName(mpi.getElementQName().getLocalPart()); if (e != null) { mpi.setXmlSchema(e); return; } XmlSchema schema = si.getSchema(); si.setElement(null); //cached element is now invalid XmlSchemaElement el = new XmlSchemaElement(schema, true); el.setName(mpi.getElementQName().getLocalPart()); el.setNillable(true); XmlSchemaType tp = (XmlSchemaType)mpi.getXmlSchema(); if (tp == null) { throw new ServiceConstructionException(new Message("INTRACTABLE_PART", LOG, mpi.getName(), mpi.getMessageInfo().getName())); } el.setSchemaTypeName(tp.getQName()); mpi.setXmlSchema(el); }
/** * By convention, an element that is named in its schema's TNS can have a 'name' but * no QName. This can get inconvenient for consumers who want to think about qualified names. * Unfortunately, XmlSchema elements, unlike types, don't store a reference to their containing * schema. * @param element * @param schema */ public static QName getElementQualifiedName(XmlSchemaElement element, XmlSchema schema) { if (element.getQName() != null) { return element.getQName(); } else if (element.getName() != null) { return new QName(schema.getTargetNamespace(), element.getName()); } else { return null; } }
public XmlSchemaType getSchemaType(QName name) throws Exception { XmlSchemaType type = null; for (XmlSchema xmlSchema : xmlSchemaList.getXmlSchemas()) { String nspace = name.getNamespaceURI(); if (nspace == null) { nspace = xmlSchema.getTargetNamespace(); } //QName tname = createQName(nspace, name.getLocalPart(), "xsd"); QName tname = createQName(nspace, name.getLocalPart(), ""); type = findSchemaType(tname); if (type != null) { break; } } return type; }
include.schemaLocation = includeEl.getAttribute("schemaLocation"); if (schema.getSourceURI() != null) { include.schema = resolveXmlSchema(schema.logicalTargetNamespace, include.schemaLocation, schema.getSourceURI(), validator); } else { include.schema = resolveXmlSchema(schema.logicalTargetNamespace,
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); }
XPathExpression xpe = p.compile(d.getDocumentElement().getAttribute("node")); for (XmlSchema schema : schemas.getXmlSchemas()) { if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(schema.getTargetNamespace())) { continue; NodeList nodes = (NodeList)xpe.evaluate(src, XPathConstants.NODESET); if (nodes.getLength() > 0) { String key = schema.getSourceURI(); binding = convertToTmpInputSource(d.getDocumentElement(), key); opts.addBindFile(binding);
private void createBridgeXsElement(MessagePartInfo part, QName qn, QName typeName) { XmlSchemaElement el = null; SchemaInfo schemaInfo = serviceInfo.getSchema(qn.getNamespaceURI()); if (schemaInfo != null) { el = schemaInfo.getElementByQName(qn); if (el == null) { createXsElement(schemaInfo.getSchema(), part, typeName, schemaInfo); } else if (!typeName.equals(el.getSchemaTypeName())) { throw new Fault(new Message("CANNOT_CREATE_ELEMENT", LOG, qn, typeName, el.getSchemaTypeName())); } return; } XmlSchema schema = schemas.newXmlSchemaInCollection(qn.getNamespaceURI()); if (qualifiedSchemas) { schema.setElementFormDefault(XmlSchemaForm.QUALIFIED); } schemaInfo = new SchemaInfo(qn.getNamespaceURI(), qualifiedSchemas, false); schemaInfo.setSchema(schema); el = createXsElement(schema, part, typeName, schemaInfo); NamespaceMap nsMap = new NamespaceMap(); nsMap.add(WSDLConstants.CONVENTIONAL_TNS_PREFIX, schema.getTargetNamespace()); nsMap.add(WSDLConstants.NP_SCHEMA_XSD, WSDLConstants.NS_SCHEMA_XSD); schema.setNamespaceContext(nsMap); serviceInfo.addSchema(schemaInfo); }
/** * Since both an Array and a List can have the same type definition, double check that there isn't already * a defined type already. * * @param root * @return */ private boolean hasDefinedArray(XmlSchema root) { return root.getTypeByName(getSchemaType().getLocalPart()) != null; }
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 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; }
return element; if (getSchema() == null) { throw new RuntimeException("No XmlSchema in SchemaInfo"); XmlSchema sch = getSchema(); synchronized (sch) { XmlSchema schAgain = getSchema(); if (schAgain.getNamespaceContext() == null) { NamespaceMap nsMap = new NamespaceMap(); nsMap.add("xsd", Constants.URI_2001_SCHEMA_XSD); nsMap.add("tns", schAgain.getTargetNamespace()); schAgain.setNamespaceContext(nsMap); serializedSchema = schAgain.getSchemaDocument(); } catch (XmlSchemaSerializerException e) { throw new RuntimeException("Error serializing Xml Schema", e); if (element.getPrefix() == null && !Constants.URI_2001_SCHEMA_XSD.equals(element.getAttributeNS(Constants.XMLNS_ATTRIBUTE_NS_URI, Constants.XMLNS_ATTRIBUTE))) { Attr attr = element.getOwnerDocument() .createAttributeNS(Constants.XMLNS_ATTRIBUTE_NS_URI, Constants.XMLNS_ATTRIBUTE); attr.setValue(Constants.URI_2001_SCHEMA_XSD);
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()); } }
public static boolean isElementFormQualified(XmlSchema schema, QName type) { if (type != null) { String uri = type.getNamespaceURI(); if (uri.equals(schema.getTargetNamespace())) { return schema.getElementFormDefault() == XmlSchemaForm.QUALIFIED; } for (XmlSchemaExternal extSchema : schema.getExternals()) { return isElementFormQualified(extSchema.getSchema(), type); } } return false; }