org.apache.ws.commons.schema.XmlSchemaCollection Java Examples

The following examples show how to use org.apache.ws.commons.schema.XmlSchemaCollection. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SchemaAddinsTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testAegisTypeSchema() throws Exception {
    AegisContext context = new AegisContext();
    context.initialize();
    XmlSchemaCollection collection = new XmlSchemaCollection();
    context.addTypesSchemaDocument(collection);
    XmlSchema[] schemas = collection.getXmlSchemas();
    XmlSchema typeSchema = null;
    for (XmlSchema schema : schemas) {
        if (AegisContext.UTILITY_TYPES_SCHEMA_NS.equals(schema.getTargetNamespace())) {
            typeSchema = schema;
            break;
        }
    }
    assertNotNull(typeSchema);

    assertNotSame(0, typeSchema.getItems().size());
    XmlSchemaSerializer serializer = new XmlSchemaSerializer();
    Document[] docs = serializer.serializeSchema(typeSchema, false);
    testUtilities.assertValid("/xsd:schema/xsd:simpleType[@name='char']", docs[0]);



}
 
Example #2
Source File: AbstractXmlSchemaExtractorTest.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setupClass() throws XmlSchemaSerializer.XmlSchemaSerializerException {
    if (sourceSchemas == null) {
        final InputSource inputSource = new InputSource(AbstractXmlSchemaExtractorTest.class
            .getResourceAsStream(TEST_SCHEMA));
        final XmlSchemaCollection schemaCollection = new XmlSchemaCollection();
        schemaCollection.read(inputSource);
        sourceSchemas = new SchemaCollection(schemaCollection);

        sourceSchemaNodes = new HashMap<>();
        for (XmlSchema schema : sourceSchemas.getXmlSchemas()) {
            final NodeList childNodes = schema.getSchemaDocument().getDocumentElement().getChildNodes();
            List<Element> elements = new ArrayList<>();
            for (int i = 0; i < childNodes.getLength(); i++) {
                final Node node = childNodes.item(i);
                if (node instanceof Element) {
                    elements.add((Element) node);
                }
            }
            sourceSchemaNodes.put(schema.getTargetNamespace(), elements);
        }
    }
}
 
Example #3
Source File: ScopedNameVisitor.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected static void populateAliasSchemaType(CorbaType corbaType,
                                              WSDLASTVisitor wsdlVisitor,
                                              VisitorTypeHolder holder) {
    XmlSchemaCollection schemas = wsdlVisitor.getSchemas();
    TypeMappingType typeMap = wsdlVisitor.getTypeMap();
    holder.setCorbaType(corbaType);
    Alias alias = (Alias) corbaType;
    //loop through alias base types, till you get a non-alias corba type
    CorbaType type = findCorbaType(typeMap, alias.getBasetype());
    while ((type != null) && (type instanceof Alias)) {
        alias = (Alias) type;
        type = findCorbaType(typeMap, alias.getBasetype());
    }
    QName tname;
    if (type == null) {
        //it must be a primitive type
        tname = xmlSchemaPrimitiveMap.get(alias.getBasetype());
    } else {
        tname = type.getType();
    }
    XmlSchemaType stype = schemas.getTypeByQName(tname);
    if (stype == null) {
        XmlSchema xmlSchema = wsdlVisitor.getManager().getXmlSchema(tname.getNamespaceURI());
        if (xmlSchema != null) {
            stype = xmlSchema.getTypeByName(tname);
        } else {
            stype = wsdlVisitor.getSchema().getTypeByName(tname);
        }
    }
    holder.setSchemaType(stype);
}
 
Example #4
Source File: ServiceWSDLBuilderTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testSchemas() throws Exception {
    setupWSDL(WSDL_PATH);
    Types types = newDef.getTypes();
    assertNotNull(types);
    Collection<ExtensibilityElement> schemas =
        CastUtils.cast(types.getExtensibilityElements(), ExtensibilityElement.class);
    assertEquals(1, schemas.size());
    XmlSchemaCollection schemaCollection = new XmlSchemaCollection();
    Element schemaElem = ((Schema)schemas.iterator().next()).getElement();
    XmlSchema newSchema = schemaCollection.read(schemaElem);
    assertEquals("http://apache.org/hello_world_soap_http/types",
                 newSchema.getTargetNamespace()
                 );
}
 
Example #5
Source File: SchemaJavascriptBuilder.java    From cxf with Apache License 2.0 5 votes vote down vote up
public String generateCodeForSchemaCollection(XmlSchemaCollection collection) {
    StringBuilder accumulatedCode = new StringBuilder();
    for (XmlSchema schema : collection.getXmlSchemas()) {
        if (!Constants.URI_2001_SCHEMA_XSD.equals(schema.getTargetNamespace())) {
            accumulatedCode.append(generateCodeForSchema(schema));
        }
    }
    return accumulatedCode.toString();
}
 
Example #6
Source File: SchemaCollection.java    From cxf with Apache License 2.0 5 votes vote down vote up
public SchemaCollection(XmlSchemaCollection col) {
    schemaCollection = col;
    if (schemaCollection.getNamespaceContext() == null) {
        // an empty prefix map avoids extra checks for null.
        schemaCollection.setNamespaceContext(new NamespaceMap());
    }
}
 
Example #7
Source File: SchemaCollection.java    From cxf with Apache License 2.0 5 votes vote down vote up
public boolean equals(Object obj) {
    if (obj instanceof SchemaCollection) {
        return schemaCollection.equals(((SchemaCollection)obj).schemaCollection);
    } else if (obj instanceof XmlSchemaCollection) {
        return schemaCollection.equals(obj);
    }
    return false;
}
 
Example #8
Source File: FixedPtConstVisitor.java    From cxf with Apache License 2.0 5 votes vote down vote up
public FixedPtConstVisitor(Scope scopeRef,
                           Definition defn,
                           XmlSchema schemaRef,
                           XmlSchemaCollection xmlSchemas) {
    scope = scopeRef;
    schemas = xmlSchemas;
}
 
Example #9
Source File: ParamDeferredAction.java    From cxf with Apache License 2.0 5 votes vote down vote up
public ParamDeferredAction(XmlSchemaElement elem,
                           Scope ts,
                           XmlSchema xmlSchema,
                           XmlSchemaCollection xmlSchemas,
                           WSDLSchemaManager man,
                           ModuleToNSMapper map) {
    element = elem;
    schema = xmlSchema;
    schemas = xmlSchemas;
    typeScope = ts;
    manager = man;
    mapper = map;
}
 
Example #10
Source File: PrimitiveTypesVisitor.java    From cxf with Apache License 2.0 5 votes vote down vote up
public PrimitiveTypesVisitor(Scope scopeRef,
                             Definition defn,
                             XmlSchema schemaRef,
                             XmlSchemaCollection xmlSchemas) {
    scope = scopeRef;
    schemas = xmlSchemas;
}
 
Example #11
Source File: Stax2ValidationUtilsTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    XmlSchemaCollection schemaCol = new XmlSchemaCollection();

    InputStream io = getClass().getClassLoader().getResourceAsStream(schemaPath);
    String sysId = getClass().getClassLoader().getResource(schemaPath).toString();
    schemaCol.setBaseUri(getTestBaseURI());
    schemaCol.read(new StreamSource(io, sysId));
    serviceInfo.addSchema(schemaInfo);
    schemaInfo.setSchema(schemaCol.getXmlSchema(sysId)[0]);
    expect(endpoint.get(anyObject())).andReturn(null);
    expect(endpoint.containsKey(anyObject())).andReturn(false);
    expect(endpoint.put(anyString(), anyObject())).andReturn(null);
    replay(endpoint);
}
 
Example #12
Source File: WSDLASTVisitor.java    From cxf with Apache License 2.0 5 votes vote down vote up
public WSDLASTVisitor(String tns, String schemans, String corbatypemaptns, String pragmaPrefix)
    throws WSDLException, JAXBException {

    manager = new WSDLSchemaManager();

    definition = manager.createWSDLDefinition(tns);

    inheritScopeMap = new TreeMap<>();

    targetNamespace = tns;
    schemas = new XmlSchemaCollection();
    scopedNames = new ScopeNameCollection();
    deferredActions = new DeferredActionCollection();

    if (schemans == null) {
        schemans = tns;
    }
    schema = manager.createXmlSchemaForDefinition(definition, schemans, schemas);
    declaredWSAImport = false;

    typeMap = manager.createCorbaTypeMap(definition, corbatypemaptns);

    // idl:sequence<octet> maps to xsd:base64Binary by default
    sequenceOctetType = schemas.getTypeByQName(Constants.XSD_BASE64);

    // treat bounded corba:string/corba:wstring as unbounded if set to true
    setBoundedStringOverride(false);

    moduleToNSMapper = new ModuleToNSMapper();
    this.setPragmaPrefix(pragmaPrefix);
}
 
Example #13
Source File: ScopedNameVisitor.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected static boolean findNonSchemaType(String name,
                                           WSDLASTVisitor wsdlVisitor,
                                           VisitorTypeHolder holder) {
    boolean result = false;
    TypeMappingType typeMap = wsdlVisitor.getTypeMap();
    XmlSchemaCollection schemas = wsdlVisitor.getSchemas();

    QName qname = new QName(typeMap.getTargetNamespace(), name);
    CorbaType corbaType = findCorbaType(typeMap, qname);
    if (corbaType != null) {
        if (corbaType instanceof Alias) {
            result = true;
            if (holder != null) {
                populateAliasSchemaType(corbaType, wsdlVisitor, holder);
            }
        } else if (((corbaType instanceof Sequence) || (corbaType instanceof Anonsequence))
                   && ((corbaType.getType().equals(Constants.XSD_BASE64)))) {
            //special case of sequence of octets
            result = true;
            if (holder != null) {
                holder.setCorbaType(corbaType);
                holder.setSchemaType(schemas.getTypeByQName(corbaType.getType()));
            }
        }
    }
    return result;
}
 
Example #14
Source File: TypesVisitorBase.java    From cxf with Apache License 2.0 5 votes vote down vote up
public TypesVisitorBase(XmlSchemaCollection xmlSchemas,
                        XmlSchema xmlSchema,
                        TypeMappingType typeMapRef) {
    schemas = xmlSchemas;
    schema = xmlSchema;
    typeMap = typeMapRef;
}
 
Example #15
Source File: SchemaInfoBuilderTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
private XmlSchemaInfo loadSchemaInfo(String fileName) throws Exception {
    InputStream in = getClass().getClassLoader().getResourceAsStream(fileName);
    XmlSchemaCollection xmlSchemaCollection = new XmlSchemaCollection();
    xmlSchemaCollection.read(new InputStreamReader(in), null);
    CommonsSchemaInfoBuilder schemaInfoBuilder = new CommonsSchemaInfoBuilder(xmlSchemaCollection);
    XmlSchemaInfo schemaInfo = schemaInfoBuilder.createSchemaInfo();
    return schemaInfo;
}
 
Example #16
Source File: DidSchemaParser.java    From secure-data-service with Apache License 2.0 5 votes vote down vote up
private XmlSchema parseXmlSchema(final InputStream is, final String baseXsdPath) {
    try {
        XmlSchemaCollection schemaCollection = new XmlSchemaCollection();
        schemaCollection.setSchemaResolver(new URIResolver() {
            @Override
            public InputSource resolveEntity(String targetNamespace, String schemaLocation, String baseUri) {
                if (resourceLoader != null) {
                    Resource resource = resourceLoader.getResource(baseXsdPath + "/" + schemaLocation);
                    if (resource.exists()) {
                        try {
                            return new InputSource(resource.getInputStream());
                        } catch (IOException e) {
                            throw new RuntimeException("Exception occurred", e);
                        }
                    }
                }
                return new InputSource(Thread.currentThread().getContextClassLoader()
                        .getResourceAsStream(baseXsdPath + "/" + schemaLocation));
            }
        });
        return schemaCollection.read(new InputSource(is), null);
    } catch (Exception exception) {
        throw new RuntimeException(exception);
    } finally {
        try {
            is.close();
        } catch (IOException ioException) {
            LOG.error("ioExecption in closing input file ", ioException);
        }
    }
}
 
Example #17
Source File: Xsd2CobolTypesModelBuilderTest.java    From legstar-core2 with GNU Affero General Public License v3.0 5 votes vote down vote up
private String build(String schemaName) throws Exception {
    File xsdFile = new File(TEST_XSD_FOLDER, schemaName + ".xsd");

    Reader reader = new InputStreamReader(new FileInputStream(xsdFile),
            LEGSTAR_XSD_FILE_ENCODING);

    XmlSchemaCollection schemaCol = new XmlSchemaCollection();
    XmlSchema xsd = schemaCol.read(new StreamSource(reader));
    Xsd2CobolTypesModelBuilder builder = new Xsd2CobolTypesModelBuilder();
    Map < String, Xsd2CobolTypesModelBuilder.RootCompositeType > model = builder.build(xsd);
    assertEquals(1, model.size());
    return model.toString();
}
 
Example #18
Source File: AbstractXsdEmitterTester.java    From legstar-core2 with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * @return an empty XML schema for testing
 */
public XmlSchema getXmlSchema() {
    XmlSchema xsd = new XmlSchema("http://legstar.com/test",
            new XmlSchemaCollection());
    xsd.setElementFormDefault(XmlSchemaForm.QUALIFIED);
    return xsd;
}
 
Example #19
Source File: Cob2Xsd.java    From legstar-core2 with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Create an empty XML Schema.
 * <p/>
 * If no targetNamespace, make sure there is no default namespace otherwise
 * our complex types would be considered part of that default namespace
 * (usually XML Schema namespace).
 * 
 * @param encoding the character set used to encode this XML Schema
 * @param targetNamespace the target namespace to use (null for no namespace)
 * @return a new empty XML schema using the model
 */
protected XmlSchema createXmlSchema(final String encoding, final String targetNamespace) {
    XmlSchema xsd = new XmlSchema(targetNamespace,
            new XmlSchemaCollection());
    if (targetNamespace != null) {
        xsd.setElementFormDefault(XmlSchemaForm.QUALIFIED);
    }
    xsd.setAttributeFormDefault(null);
    xsd.setInputEncoding(encoding);
    if (targetNamespace == null) {
        NamespaceMap prefixmap = new NamespaceMap();
        NamespacePrefixList npl = xsd.getNamespaceContext();
        if (npl == null) {
            prefixmap.add("xsd", XMLConstants.W3C_XML_SCHEMA_NS_URI);
        } else {
            for (int i = 0; i < npl.getDeclaredPrefixes().length; i++) {
                String prefix = npl.getDeclaredPrefixes()[i];
                String namespace = npl.getNamespaceURI(prefix);
                if (namespace.equals(XMLConstants.W3C_XML_SCHEMA_NS_URI)) {
                    if (prefix.equals("")) {
                        prefix = "xsd";
                    }
                }
                prefixmap.add(prefix, namespace);
            }
        }
        xsd.setNamespaceContext(prefixmap);
    }
    return xsd;
}
 
Example #20
Source File: XsdToNeutralSchemaRepo.java    From secure-data-service with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("PMD.DoNotThrowExceptionInFinally")   // seems necessary to report issue while closing input stream
private XmlSchema parseXmlSchema(final InputStream is) {
    try {
        XmlSchemaCollection schemaCollection = new XmlSchemaCollection();
        schemaCollection.setSchemaResolver(new URIResolver() {
            @Override
            public InputSource resolveEntity(String targetNamespace, String schemaLocation, String baseUri) {
                if (resourceLoader != null) {
                    Resource resource = resourceLoader.getResource(getXsdPath() + "/" + schemaLocation);
                    if (resource.exists()) {
                        try {
                            return new InputSource(resource.getInputStream());
                        } catch (IOException e) {
                            throw new RuntimeException("Exception occurred", e);
                        }
                    }
                }
                return new InputSource(Thread.currentThread().getContextClassLoader()
                        .getResourceAsStream(getXsdPath() + "/" + schemaLocation));
            }
        });
        return schemaCollection.read(new InputSource(is), null);
    } catch (Exception exception) {
        throw new RuntimeException(exception);
    } finally {
        try {
            is.close();
        } catch (IOException ioException) {
            throw new RuntimeException(ioException);
        }
    }
}
 
Example #21
Source File: SmooksGenerator.java    From secure-data-service with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("PMD.DoNotThrowExceptionInFinally")    // smooks support soon to be removed
private XmlSchema parseXmlSchema(final InputStream is, final String baseXsdPath) {
    try {
        XmlSchemaCollection schemaCollection = new XmlSchemaCollection();
        // schemaCollection.setBaseUri(baseUri);
        schemaCollection.setSchemaResolver(new URIResolver() {
            @Override
            public InputSource resolveEntity(String targetNamespace, String schemaLocation, String baseUri) {
                if (resourceLoader != null) {
                    Resource resource = resourceLoader.getResource(baseXsdPath + "/" + schemaLocation);
                    if (resource.exists()) {
                        try {
                            return new InputSource(resource.getInputStream());
                        } catch (IOException e) {
                            throw new RuntimeException("Exception occurred", e);
                        }
                    }
                }
                return new InputSource(Thread.currentThread().getContextClassLoader()
                        .getResourceAsStream(baseXsdPath + "/" + schemaLocation));
            }
        });
        return schemaCollection.read(new InputSource(is), null);
    } catch (Exception exception) {
        throw new RuntimeException(exception);
    } finally {
        try {
            is.close();
        } catch (IOException ioException) {
            throw new RuntimeException(ioException);
        }
    }
}
 
Example #22
Source File: SequenceDeferredAction.java    From cxf with Apache License 2.0 4 votes vote down vote up
public SequenceDeferredAction(XmlSchemaCollection xmlSchemas,
                              XmlSchema xmlSchema) {
    schemas = xmlSchemas;
    schema = xmlSchema;
}
 
Example #23
Source File: CommonsSchemaLoader.java    From tomee with Apache License 2.0 4 votes vote down vote up
public XmlSchemaCollection loadSchema() throws OpenEJBException {
    Definition definition = readWsdl(wsdlUri);
    addImportsFromDefinition(definition);
    return xmlSchemaCollection;
}
 
Example #24
Source File: CommonsSchemaInfoBuilder.java    From tomee with Apache License 2.0 4 votes vote down vote up
public CommonsSchemaInfoBuilder(XmlSchemaCollection xmlSchemaCollection) {
    if (xmlSchemaCollection == null) throw new NullPointerException("schemaTypeSystem is null");
    this.xmlSchemaCollection = xmlSchemaCollection;
}
 
Example #25
Source File: XsdReader.java    From secure-data-service with Apache License 2.0 4 votes vote down vote up
private static final XmlSchema readSchema(final InputStream istream, final URIResolver schemaResolver) {
    final XmlSchemaCollection schemaCollection = new XmlSchemaCollection();
    schemaCollection.setSchemaResolver(schemaResolver);
    return schemaCollection.read(new InputSource(istream), null);
}
 
Example #26
Source File: SchemaCollection.java    From cxf with Apache License 2.0 4 votes vote down vote up
public XmlSchemaCollection getXmlSchemaCollection() {
    return schemaCollection;
}
 
Example #27
Source File: SchemaCollection.java    From cxf with Apache License 2.0 4 votes vote down vote up
public SchemaCollection() {
    this(new XmlSchemaCollection());
}
 
Example #28
Source File: XercesSchemaValidationUtils.java    From cxf with Apache License 2.0 4 votes vote down vote up
void tryToParseSchemas(XmlSchemaCollection collection, DOMErrorHandler handler)
    throws Exception {

    final List<DOMLSInput> inputs = new ArrayList<>();
    final Map<String, LSInput> resolverMap = new HashMap<>();

    for (XmlSchema schema : collection.getXmlSchemas()) {
        if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(schema.getTargetNamespace())) {
            continue;
        }
        Document document = new XmlSchemaSerializer().serializeSchema(schema, false)[0];
        DOMLSInput input = new DOMLSInput(document, schema.getTargetNamespace());
        resolverMap.put(schema.getTargetNamespace(), input);
        inputs.add(input);
    }

    try {

        Object schemaLoader = findMethod(impl, "createXSLoader").invoke(impl, new Object[1]);
        DOMConfiguration config = (DOMConfiguration)findMethod(schemaLoader, "getConfig").invoke(schemaLoader);

        config.setParameter("validate", Boolean.TRUE);
        config.setParameter("error-handler", handler);
        config.setParameter("resource-resolver", new LSResourceResolver() {
            public LSInput resolveResource(String type, String namespaceURI, String publicId,
                                           String systemId, String baseURI) {
                return resolverMap.get(namespaceURI);
            }
        });


        Method m = findMethod(schemaLoader, "loadInputList");
        String name = m.getParameterTypes()[0].getName() + "Impl";
        name = name.replace("xs.LS", "impl.xs.util.LS");
        Class<?> c = Class.forName(name);
        Object inputList = c.getConstructor(LSInput[].class, Integer.TYPE)
            .newInstance(inputs.toArray(new LSInput[0]), inputs.size());
        m.invoke(schemaLoader, inputList);
    } catch (InvocationTargetException e) {
        throw (Exception)e.getTargetException();
    }
}
 
Example #29
Source File: AegisContext.java    From cxf with Apache License 2.0 4 votes vote down vote up
public XmlSchema addXmimeSchemaDocument(XmlSchemaCollection collection) {
    return collection.read(getXmimeSchemaDocument(), null);
}
 
Example #30
Source File: AegisContext.java    From cxf with Apache License 2.0 4 votes vote down vote up
public XmlSchema addTypesSchemaDocument(XmlSchemaCollection collection) {
    return collection.read(getAegisTypesSchemaDocument(), null);
}