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 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 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; }
/** * Is there an import for a particular namespace in a schema? * @param schema * @param namespaceUri */ public static boolean schemaImportsNamespace(XmlSchema schema, String namespaceUri) { List<XmlSchemaExternal> externals = schema.getExternals(); for (XmlSchemaExternal what : externals) { if (what instanceof XmlSchemaImport) { XmlSchemaImport imp = (XmlSchemaImport)what; // already there. if (namespaceUri.equals(imp.getNamespace())) { return true; } } } return false; }
/** * Is there an import for a particular namespace in a schema? * @param schema * @param namespaceUri */ public static boolean schemaImportsNamespace(XmlSchema schema, String namespaceUri) { List<XmlSchemaExternal> externals = schema.getExternals(); for (XmlSchemaExternal what : externals) { if (what instanceof XmlSchemaImport) { XmlSchemaImport imp = (XmlSchemaImport)what; // already there. if (namespaceUri.equals(imp.getNamespace())) { return true; } } } return false; }
/** * Is there an import for a particular namespace in a schema? * @param schema * @param namespaceUri */ public static boolean schemaImportsNamespace(XmlSchema schema, String namespaceUri) { List<XmlSchemaExternal> externals = schema.getExternals(); for (XmlSchemaExternal what : externals) { if (what instanceof XmlSchemaImport) { XmlSchemaImport imp = (XmlSchemaImport)what; // already there. if (namespaceUri.equals(imp.getNamespace())) { return true; } } } return false; }
/** * Is there an import for a particular namespace in a schema? * @param schema * @param namespaceUri * @return */ public static boolean schemaImportsNamespace(XmlSchema schema, String namespaceUri) { List<XmlSchemaExternal> externals = schema.getExternals(); for (XmlSchemaExternal what : externals) { if (what instanceof XmlSchemaImport) { XmlSchemaImport imp = (XmlSchemaImport)what; // already there. if (namespaceUri.equals(imp.getNamespace())) { return true; } } } return false; }
/** * Is there an import for a particular namespace in a schema? * @param schema * @param namespaceUri */ public static boolean schemaImportsNamespace(XmlSchema schema, String namespaceUri) { List<XmlSchemaExternal> externals = schema.getExternals(); for (XmlSchemaExternal what : externals) { if (what instanceof XmlSchemaImport) { XmlSchemaImport imp = (XmlSchemaImport)what; // already there. if (namespaceUri.equals(imp.getNamespace())) { return true; } } } return false; }
/** * 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); 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); } } }
/** * Assist in managing the required <import namespace='uri'> for imports of peer schemas. * @param schema * @param namespaceUri */ public static void addImportIfNeeded(XmlSchema schema, String namespaceUri) { // no need to import nothing or the XSD schema, or the schema we are fixing. if ("".equals(namespaceUri) || Constants.URI_2001_SCHEMA_XSD.equals(namespaceUri) || schema.getTargetNamespace().equals(namespaceUri)) { return; } List<XmlSchemaExternal> externals = schema.getExternals(); for (XmlSchemaExternal what : externals) { if (what instanceof XmlSchemaImport) { XmlSchemaImport imp = (XmlSchemaImport)what; // already there. if (namespaceUri.equals(imp.getNamespace())) { return; } } } XmlSchemaImport imp = new XmlSchemaImport(schema); imp.setNamespace(namespaceUri); }
/** * Assist in managing the required <import namespace='uri'> for imports of peer schemas. * @param schema * @param namespaceUri */ public static void addImportIfNeeded(XmlSchema schema, String namespaceUri) { // no need to import nothing or the XSD schema, or the schema we are fixing. if ("".equals(namespaceUri) || XmlSchemaConstants.XSD_NAMESPACE_URI.equals(namespaceUri) || schema.getTargetNamespace().equals(namespaceUri)) { return; } List<XmlSchemaExternal> externals = schema.getExternals(); for (XmlSchemaExternal what : externals) { if (what instanceof XmlSchemaImport) { XmlSchemaImport imp = (XmlSchemaImport)what; // already there. if (namespaceUri.equals(imp.getNamespace())) { return; } } } XmlSchemaImport imp = new XmlSchemaImport(schema); imp.setNamespace(namespaceUri); }
/** * Assist in managing the required <import namespace='uri'> for imports of peer schemas. * @param schema * @param namespaceUri */ public static void addImportIfNeeded(XmlSchema schema, String namespaceUri) { // no need to import nothing or the XSD schema, or the schema we are fixing. if ("".equals(namespaceUri) || Constants.URI_2001_SCHEMA_XSD.equals(namespaceUri) || schema.getTargetNamespace().equals(namespaceUri)) { return; } List<XmlSchemaExternal> externals = schema.getExternals(); for (XmlSchemaExternal what : externals) { if (what instanceof XmlSchemaImport) { XmlSchemaImport imp = (XmlSchemaImport)what; // already there. if (namespaceUri.equals(imp.getNamespace())) { return; } } } XmlSchemaImport imp = new XmlSchemaImport(schema); imp.setNamespace(namespaceUri); }
/** * Assist in managing the required <import namespace='uri'> for imports of peer schemas. * @param schema * @param namespaceUri */ public static void addImportIfNeeded(XmlSchema schema, String namespaceUri) { // no need to import nothing or the XSD schema, or the schema we are fixing. if ("".equals(namespaceUri) || XmlSchemaConstants.XSD_NAMESPACE_URI.equals(namespaceUri) || schema.getTargetNamespace().equals(namespaceUri)) { return; } List<XmlSchemaExternal> externals = schema.getExternals(); for (XmlSchemaExternal what : externals) { if (what instanceof XmlSchemaImport) { XmlSchemaImport imp = (XmlSchemaImport)what; // already there. if (namespaceUri.equals(imp.getNamespace())) { return; } } } XmlSchemaImport imp = new XmlSchemaImport(schema); imp.setNamespace(namespaceUri); }
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); } } }
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 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); } } }
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; }
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); } } }
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); } } }