Java Code Examples for javax.wsdl.extensions.schema.Schema#createImport()

The following examples show how to use javax.wsdl.extensions.schema.Schema#createImport() . 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: WSDLSchemaManager.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void addWSDLSchemaImport(Schema wsdlSchema, String tns, File file) {
    if (!wsdlSchema.getImports().containsKey(tns)) {
        SchemaImport schemaimport = wsdlSchema.createImport();
        schemaimport.setNamespaceURI(tns);
        if (file != null && !ignoreImports) {
            schemaimport.setSchemaLocationURI(file.toURI().toString());
        }
        wsdlSchema.addImport(schemaimport);
    }
}
 
Example 2
Source File: ServiceWSDLBuilder.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void addSchemaImport(Schema schema, SchemaInfo schemaInfo, Schema referencedSchema) {
    SchemaImport imp = schema.createImport();
    imp.setId(schemaInfo.getSystemId());
    imp.setNamespaceURI(schemaInfo.getNamespaceURI());
    imp.setSchemaLocationURI(referencedSchema.getDocumentBaseURI());
    imp.setReferencedSchema(referencedSchema);
    schema.addImport(imp);
}
 
Example 3
Source File: IDLToWSDLProcessor.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void addTypeMapSchemaImports(Definition def, WSDLASTVisitor visitor) {
    List<CorbaType> types = visitor.getTypeMap().getStructOrExceptionOrUnion();
    ModuleToNSMapper mapper = visitor.getModuleToNSMapper();
    WSDLSchemaManager manager = visitor.getManager();
    Collection<String> namespaces = CastUtils.cast(def.getNamespaces().values());
    Set<Map.Entry<String, String>> userModuleMappings = mapper.getUserMapping().entrySet();

    if (types != null) {
        for (int i = 0; i < types.size(); i++) {
            CorbaType type = types.get(i);
            QName schemaType = type.getType();
            if (schemaType != null) {
                String typeNamespace = schemaType.getNamespaceURI();
                try {
                    // WS-Addressing namespace is a special case.  We need to import the schema from
                    // a remote location.
                    if (!namespaces.contains(typeNamespace)
                        && typeNamespace.equals(ReferenceConstants.WSADDRESSING_NAMESPACE)) {

                        // build up the ws-addressing schema import
                        Schema wsdlSchema =
                            (Schema)def.getExtensionRegistry().createExtension(Types.class,
                                                 new QName(Constants.URI_2001_SCHEMA_XSD, "schema"));
                        SchemaImport schemaimport = wsdlSchema.createImport();
                        schemaimport.setNamespaceURI(ReferenceConstants.WSADDRESSING_NAMESPACE);
                        schemaimport.setSchemaLocationURI(ReferenceConstants.WSADDRESSING_LOCATION);
                        wsdlSchema.addImport(schemaimport);

                        // add the import and the prefix to the definition
                        def.getTypes().addExtensibilityElement(wsdlSchema);
                        CastUtils.cast(def.getNamespaces(), String.class, String.class)
                            .put(ReferenceConstants.WSADDRESSING_PREFIX, typeNamespace);
                    } else if (!namespaces.contains(typeNamespace)) {
                        String prefix = getModulePrefixForNamespace(userModuleMappings, mapper,
                                                                    typeNamespace);
                        //prefix = mapper.mapNSToPrefix(typeNamespace);
                        XmlSchema schema = manager.getXmlSchema(typeNamespace);
                        // TODO: REVISIT - Is this the only way we can create the file name for the
                        // imported schema?
                        String importFile = visitor.getOutputDir()
                            + System.getProperty("file.separator")
                            + prefix + ".xsd";
                        manager.addWSDLSchemaImport(def, typeNamespace, importFile);
                        manager.getImportedXmlSchemas().put(new File(importFile), schema);
                        CastUtils.cast(def.getNamespaces(), String.class, String.class)
                            .put(prefix, typeNamespace);
                    }
                } catch (Exception ex) {
                    throw new ToolException("Unable to add schema import for namespace"
                                            + typeNamespace);
                }
            }
        }
    }
}