Refine search
public void addXmlSchemaImport(XmlSchema rootSchema, XmlSchema schema, File file) { // Make sure we haven't already imported the schema. String importNamespace = schema.getTargetNamespace(); boolean included = false; for (XmlSchemaExternal ext : rootSchema.getExternals()) { if (ext instanceof XmlSchemaImport) { XmlSchemaImport imp = (XmlSchemaImport)ext; if (imp.getNamespace().equals(importNamespace)) { included = true; break; } } } if (!included) { XmlSchemaImport importSchema = new XmlSchemaImport(rootSchema); if (!ignoreImports) { importSchema.setSchemaLocation(file.toURI().toString()); } importSchema.setNamespace(schema.getTargetNamespace()); } if (!importedSchemas.containsKey(file)) { importedSchemas.put(file, schema); } }
private static XmlSchemaType findSchemaType(XmlSchema xmlSchema, QName typeName) { XmlSchemaType schemaType = xmlSchema.getTypeByName(typeName); // Endpoint reference types will give a null schemaType // here, so we need to // go through the list of imports to find the definition for // an Endpoint // reference type. if (schemaType == null) { for (XmlSchemaExternal ext : xmlSchema.getExternals()) { if (ext instanceof XmlSchemaImport) { XmlSchemaImport xmlImport = (XmlSchemaImport)ext; if (xmlImport.getNamespace().equals(typeName.getNamespaceURI())) { XmlSchema importSchema = xmlImport.getSchema(); schemaType = importSchema.getTypeByName(typeName); } else { schemaType = findSchemaType(ext.getSchema(), typeName); if (schemaType != null) { return schemaType; } } } } if (schemaType != null) { return schemaType; } } return schemaType; }
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 findImports(XmlSchema schema, Set<XmlSchema> processedImports, Set<XmlSchema> processedIncludes) { processedImports.add(schema); List<XmlSchemaExternal> externals = schema.getExternals(); for (XmlSchemaExternal external : externals) { if (external instanceof XmlSchemaImport) { XmlSchemaImport schemaImport = (XmlSchemaImport) external; XmlSchema importedSchema = schemaImport.getSchema(); if (!"http://www.w3.org/XML/1998/namespace".equals(schemaImport.getNamespace()) && importedSchema != null && !processedImports.contains(importedSchema)) { inlineIncludes(importedSchema, processedIncludes, processedImports); findImports(importedSchema, processedImports, processedIncludes); xmlSchemas.add(importedSchema); } // remove the schemaLocation external.setSchemaLocation(null); } } }
if (xmlSchema.getTypeByName(simpleTypeName) == null) { XmlSchemaComplexType xmlSchemaComplexType = new XmlSchemaComplexType(xmlSchema, false); XmlSchemaSequence xmlSchemaSequence = new XmlSchemaSequence(); xmlSchema.getItems().add(xmlSchemaComplexType); xmlSchema.getSchemaTypes().put( new QName(xmlSchema.getTargetNamespace(), simpleTypeName), xmlSchemaComplexType); if (typeTable.getComplexSchemaType(propertyName) != null && !((NamespaceMap) xmlSchema.getNamespaceContext()).values(). contains(typeTable.getComplexSchemaType(propertyName).getNamespaceURI())) { XmlSchemaImport importElement = new XmlSchemaImport(xmlSchema); importElement.setNamespace( typeTable.getComplexSchemaType(propertyName).getNamespaceURI()); xmlSchema.getItems().add(importElement);
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()); } }
if (Constants.URI_2001_SCHEMA_XSD.equals(schema.getTargetNamespace())) { return; String ns = schema.getTargetNamespace(); if (ns == null) { ns = URLProcessor.DEFAULT_PACKAGE; if (!loadedSchemaMap.containsKey(schema.getTargetNamespace())) { loadedSchemaMap.put(schema.getTargetNamespace(), schema); XmlSchema schema1 = schemaImport.getSchema(); if (schema1 != null) { compile(schema1, isPartofGroup); } else if (schemaImport.getNamespace().equals(Constants.NS_URI_XML)) { schemaImport.setSchema(schema1); compile(schema1, isPartofGroup); } else if (!schemaImport.getNamespace().equals(Constants.URI_2001_SCHEMA_XSD)) { log.warn("No schemaLocation for import of " + schemaImport.getNamespace() + "; compilation may fail");
nsMap = (NamespaceMap)schema.getNamespaceContext(); } catch (ClassCastException ex) { nsMap = new NamespaceMap(); nsMap.add("xs", Constants.URI_2001_SCHEMA_XSD); schema.setNamespaceContext(nsMap); } else { nsMap.add("xs", Constants.URI_2001_SCHEMA_XSD); nsMap.add("tns", schema.getTargetNamespace()); org.w3c.dom.Element el = schema.getAllSchemas()[0].getDocumentElement(); XmlSchemaImport xmlSchemaImport = (XmlSchemaImport)ext; SchemaImport schemaimport = wsdlSchema.createImport(); schemaimport.setNamespaceURI(xmlSchemaImport.getNamespace()); if (xmlSchemaImport.getSchemaLocation() != null && !ignoreImports) { schemaimport.setSchemaLocationURI(xmlSchemaImport.getSchemaLocation());
private void addWSAddressingImport(XmlSchema s) { boolean alreadyImported = false; for (XmlSchemaExternal ext : s.getExternals()) { if (ext instanceof XmlSchemaImport) { XmlSchemaImport schemaImport = (XmlSchemaImport)ext; if (schemaImport.getNamespace().equals(ReferenceConstants.WSADDRESSING_NAMESPACE)) { alreadyImported = true; break; XmlSchemaImport wsaImport = new XmlSchemaImport(s); wsaImport.setNamespace(ReferenceConstants.WSADDRESSING_NAMESPACE); wsaImport.setSchemaLocation(ReferenceConstants.WSADDRESSING_LOCATION); NamespaceMap nsMap = (NamespaceMap)s.getNamespaceContext(); if (nsMap == null) { nsMap = new NamespaceMap(); nsMap.add(ReferenceConstants.WSADDRESSING_PREFIX, ReferenceConstants.WSADDRESSING_NAMESPACE); s.setNamespaceContext(nsMap); } else { nsMap.add(ReferenceConstants.WSADDRESSING_PREFIX,
schema.getNamespaceContext() != null){ outStream.write(separator); String baseURI = schema.getSourceURI(); outStream.write(baseURI.getBytes()); outStream.write(separator); schema.write(outStream); for (Iterator<?> i = schema.getIncludes().getIterator(); i.hasNext();) { ext = ((XmlSchemaImport)obj).getSchema();
schemaImpl.setElementType(WSDLConstants.QNAME_SCHEMA); schemaImpl.setElement(schemaInfo.getElement()); for (XmlSchemaExternal ext : schemaInfo.getSchema().getExternals()) { if (ext.getSchema() == null) { continue; imp.setNamespaceURI(((XmlSchemaImport)ext).getNamespace()); imp.setSchemaLocationURI(((XmlSchemaImport)ext).getSchemaLocation()); schemaImpl2.setDocumentBaseURI(ext.getSchema().getSourceURI()); try { schemaImpl2.setElement(ext.getSchema().getSchemaDocument().getDocumentElement()); } catch (XmlSchemaSerializerException e) {
XmlSchema schema = schemas[i]; if (schema.getTargetNamespace() == null){ fromSchema = schema; } else if (schema.getTargetNamespace().equals(toNamespace)){ toSchema = schema; resultSchema.add(schema); } else if (schema.getTargetNamespace().equals("http://www.w3.org/2001/XMLSchema")){ ((XmlSchemaImport)obj).getNamespace().equals(toNamespace)){
private boolean isExistImport(XmlSchema schema, String ns) { boolean isExist = false; for (XmlSchemaExternal ext : schema.getExternals()) { if (ext instanceof XmlSchemaImport) { XmlSchemaImport xsImport = (XmlSchemaImport)ext; if (xsImport.getNamespace().equals(ns)) { isExist = true; break; } } } return isExist; }
private static XmlSchemaType getSchemaType(XmlSchema schema, QName typeName) { XmlSchemaType xmlSchemaType = null; if (schema != null) { xmlSchemaType = schema.getTypeByName(typeName); if (xmlSchemaType == null) { // try to find in an import or an include) { for (XmlSchemaObject object : schema.getExternals()) { if (object instanceof XmlSchemaImport) { XmlSchema schema1 = ((XmlSchemaImport) object).getSchema(); xmlSchemaType = getSchemaType(schema1, typeName); } if (object instanceof XmlSchemaInclude) { XmlSchema schema1 = ((XmlSchemaInclude) object).getSchema(); xmlSchemaType = getSchemaType(schema1, typeName); } if (xmlSchemaType != null) { break; } } } } return xmlSchemaType; }
private static <T extends XmlSchemaObject> T getXmlSchemaObject(XmlSchema schema, QName name, Class<T> type) { if (schema != null) { XmlSchemaObject object = null; if (type == XmlSchemaElement.class) { object = schema.getElementByName(name); } else if (type == XmlSchemaType.class) { object = schema.getTypeByName(name); } if (object != null) { return type.cast(object); } for (Iterator<?> i = schema.getIncludes().getIterator(); i.hasNext();) { XmlSchemaObject obj = (XmlSchemaObject)i.next(); XmlSchema ext = null; if (obj instanceof XmlSchemaInclude) { ext = ((XmlSchemaInclude)obj).getSchema(); } if (obj instanceof XmlSchemaImport) { ext = ((XmlSchemaImport)obj).getSchema(); } object = getXmlSchemaObject(ext, name, type); if (object != null) { return type.cast(object); } } } return null; }
private XmlSchemaElement getSchemaElement(XmlSchema schema) { XmlSchemaElement xmlSchemaElement = null; if (schema != null) { xmlSchemaElement = schema.getElementByName(this.elementQname); if (xmlSchemaElement == null) { // try to find in an import or an include for (XmlSchemaObject external : schema.getExternals()) { if (external instanceof XmlSchemaImport) { XmlSchema schema1 = ((XmlSchemaImport) external).getSchema(); xmlSchemaElement = getSchemaElement(schema1); } if (external instanceof XmlSchemaInclude) { XmlSchema schema1 = ((XmlSchemaInclude) external).getSchema(); xmlSchemaElement = getSchemaElement(schema1); } if (xmlSchemaElement != null) { break; } } } } return xmlSchemaElement; }
Element schemaEl) { XmlSchemaImport schemaImport = new XmlSchemaImport(); schemaImport.setAnnotation(importAnnotation); if ((schemaImport.schemaLocation != null) && (!schemaImport.schemaLocation.equals(""))) { if (schema.getSourceURI() != null) { schemaImport.schema = resolveXmlSchema(uri, schemaImport.schemaLocation, schema.getSourceURI(), validator); } else {
/** * Checks if the specified schema import is existent. * @param schema The target schema to be checked * @param schemaImport The schema import * @return true if the schema import is there in the given schema */ private static boolean containsSchemaImport(XmlSchema schema, XmlSchemaImport schemaImport) { XmlSchemaObjectCollection list = schema.getItems(); int c = list.getCount(); XmlSchemaObject obj; for (int i = 0; i < c; i++) { obj = list.getItem(i); if (obj instanceof XmlSchemaImport) { if (((XmlSchemaImport) obj).getNamespace().equals(schemaImport.getNamespace())) { return true; } } } return false; }
private void findImports(XmlSchema schema, Set<XmlSchema> processedImports, Set<XmlSchema> processedIncludes) { processedImports.add(schema); XmlSchemaObjectCollection includes = schema.getIncludes(); for (int i = 0; i < includes.getCount(); i++) { XmlSchemaExternal external = (XmlSchemaExternal) includes.getItem(i); if (external instanceof XmlSchemaImport) { XmlSchemaImport schemaImport = (XmlSchemaImport) external; XmlSchema importedSchema = schemaImport.getSchema(); if (!"http://www.w3.org/XML/1998/namespace".equals(schemaImport.getNamespace()) && importedSchema != null && !processedImports.contains(importedSchema)) { inlineIncludes(importedSchema, processedIncludes, processedImports); findImports(importedSchema, processedImports, processedIncludes); xmlSchemas.add(importedSchema); } // remove the schemaLocation external.setSchemaLocation(null); } } }
/** * Get a schema from an import * * @param includeOrImport * @return return the schema object. */ private XmlSchema getSchema(Object includeOrImport) { XmlSchema schema; if (includeOrImport instanceof XmlSchemaImport) { schema = ((XmlSchemaImport) includeOrImport).getSchema(); } else if (includeOrImport instanceof XmlSchemaInclude) { schema = ((XmlSchemaInclude) includeOrImport).getSchema(); } else { // skip ? schema = null; } return schema; }