Java Code Examples for javax.wsdl.Definition#addNamespace()

The following examples show how to use javax.wsdl.Definition#addNamespace() . 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 6 votes vote down vote up
public void addWSDLDefinitionImport(Definition rootDefn, Definition defn, String prefix, File file) {
    if (rootDefn.getImports().get(defn.getTargetNamespace()) == null && !".wsdl".equals(file.getName())) {
        // Only import if not already done to prevent multiple imports of the same file
        // in the WSDL. Also watch out for empty fileNames, which by this point in the
        // code would show up as ".wsdl".
        Import importDefn = rootDefn.createImport();
        if (!ignoreImports) {
            importDefn.setLocationURI(file.toURI().toString());
        }
        importDefn.setNamespaceURI(defn.getTargetNamespace());
        rootDefn.addImport(importDefn);
    }
    if (!rootDefn.getNamespaces().values().contains(defn.getTargetNamespace())) {
        rootDefn.addNamespace(prefix, defn.getTargetNamespace());
    }
    if (!importedDefns.containsKey(file)) {
        importedDefns.put(file, defn);
    }

}
 
Example 2
Source File: ModelService.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
public Document toWSDL(String locationURI) throws WSDLException {
    WSDLFactory factory = WSDLFactory.newInstance();
    Definition def = factory.newDefinition();
    def.setTargetNamespace(TNS);
    def.addNamespace("xsd", XSD);
    def.addNamespace("tns", TNS);
    def.addNamespace("soap", "http://schemas.xmlsoap.org/wsdl/soap/");
    this.getWSDL(def, locationURI);
    return factory.newWSDLWriter().getDocument(def);
}
 
Example 3
Source File: BaseNodeAdapter.java    From tesb-studio-se with Apache License 2.0 5 votes vote down vote up
private void setNamespacePrefixes(Definition definition) {
      if (definition == null || definition.getNamespaces() == null) {
          return;
      }

      Collection namespaces = definition.getNamespaces().values();
      if (namespaces == null) {
          return;
      }

      if (!namespaces.contains("http://schemas.xmlsoap.org/wsdl/http/")) {
          definition.addNamespace("http", "http://schemas.xmlsoap.org/wsdl/http/");
      }
      if (!namespaces.contains("http://schemas.xmlsoap.org/wsdl/mime/")) {
          definition.addNamespace("mime", "http://schemas.xmlsoap.org/wsdl/mime/");
      }
      if (!namespaces.contains("http://schemas.xmlsoap.org/wsdl/soap/")) {
          definition.addNamespace("soap", "http://schemas.xmlsoap.org/wsdl/soap/");
}
      if (!namespaces.contains("http://schemas.xmlsoap.org/wsdl/soap/")) {
          definition.addNamespace("soap", "http://schemas.xmlsoap.org/wsdl/soap/");
      }
      if (!namespaces.contains("http://schemas.xmlsoap.org/wsdl/soap12/")) {
          definition.addNamespace("soap12", "http://schemas.xmlsoap.org/wsdl/soap12/");
      }
      if (!namespaces.contains("http://schemas.xmlsoap.org/wsdl/")) {
          definition.addNamespace("wsdl", "http://schemas.xmlsoap.org/wsdl/");
      }
  }
 
Example 4
Source File: XTeeWsdlDefinition.java    From j-road with Apache License 2.0 5 votes vote down vote up
private void addXRoadExtensions(Definition definition) throws WSDLException {
  definition.addNamespace(XROAD_PREFIX, XROAD_NAMESPACE);

  Message message = definition.createMessage();
  message.setQName(new QName(definition.getTargetNamespace(), XROAD_HEADER));

  addXroadHeaderPart(definition, message, XTeeHeader.CLIENT);
  addXroadHeaderPart(definition, message, XTeeHeader.SERVICE);
  addXroadHeaderPart(definition, message, XTeeHeader.ID);
  addXroadHeaderPart(definition, message, XTeeHeader.USER_ID);
  addXroadHeaderPart(definition, message, XTeeHeader.PROTOCOL_VERSION);

  message.setUndefined(false);
  definition.addMessage(message);

  // Add XRoad schema import to the first schema
  for (Object ex : definition.getTypes().getExtensibilityElements()) {
    if (ex instanceof Schema) {
      Schema schema = (Schema) ex;
      Element xRoadImport =
          schema.getElement().getOwnerDocument().createElement(schema.getElement().getPrefix() == null
                                                                                                       ? "import"
                                                                                                       : schema.getElement().getPrefix()
                                                                                                           + ":import");
      xRoadImport.setAttribute("namespace", XROAD_NAMESPACE);
      xRoadImport.setAttribute("schemaLocation", XROAD_NAMESPACE);
      schema.getElement().insertBefore(xRoadImport, schema.getElement().getFirstChild());
      break;
    }
  }
}
 
Example 5
Source File: WSDLSchemaManager.java    From cxf with Apache License 2.0 5 votes vote down vote up
public Definition createWSDLDefinition(String tns) throws WSDLException, JAXBException {
    WSDLManager wm = BusFactory.getThreadDefaultBus().getExtension(WSDLManager.class);
    WSDLFactory wsdlFactory = wm.getWSDLFactory();
    Definition wsdlDefinition = wsdlFactory.newDefinition();
    wsdlDefinition.setExtensionRegistry(wm.getExtensionRegistry());
    wsdlDefinition.setTargetNamespace(tns);
    wsdlDefinition.addNamespace("wsdl", "http://schemas.xmlsoap.org/wsdl/");
    wsdlDefinition.addNamespace(WSDLConstants.NP_SCHEMA_XSD, WSDLConstants.NS_SCHEMA_XSD);
    wsdlDefinition.addNamespace(WSDLConstants.SOAP11_PREFIX, WSDLConstants.NS_SOAP11);
    wsdlDefinition.addNamespace("tns", tns);
    wsdlDefinition.addNamespace(CorbaConstants.NP_WSDL_CORBA, CorbaConstants.NU_WSDL_CORBA);
    defns.put(tns, wsdlDefinition);
    return wsdlDefinition;
}
 
Example 6
Source File: WSDLASTVisitor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Definition getPhysicalDefinition(Definition logicalDef, boolean schemaOnly)
    throws WSDLException, JAXBException {

    Definition def = null;
    if (schemaOnly) {
        def = logicalDef;
    } else {
        def = manager.createWSDLDefinition(targetNamespace);
    }

    Collection<String> namespaces = CastUtils.cast(definition.getNamespaces().values());
    for (String namespace : namespaces) {
        String prefix = definition.getPrefix(namespace);
        def.addNamespace(prefix, namespace);
    }
    Collection<Binding> bindings = CastUtils.cast(definition.getAllBindings().values());
    for (Binding binding : bindings) {
        def.addBinding(binding);
    }
    Collection<Service> services = CastUtils.cast(definition.getAllServices().values());
    for (Service service : services) {
        def.addService(service);
    }
    Collection<ExtensibilityElement> extns = CastUtils.cast(definition.getExtensibilityElements());
    for (ExtensibilityElement ext : extns) {
        def.addExtensibilityElement(ext);
    }

    def.setExtensionRegistry(definition.getExtensionRegistry());

    return def;
}
 
Example 7
Source File: WSDLCorbaWriterImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void fixTypes(Definition wsdlDef) throws ParserConfigurationException {
    Types t = wsdlDef.getTypes();
    if (t == null) {
        return;
    }
    List<ExtensibilityElement> l = CastUtils.cast(t.getExtensibilityElements());
    if (l == null) {
        return;
    }

    for (ExtensibilityElement e : l) {
        if (e instanceof Schema) {
            Schema sc = (Schema)e;
            String pfx = wsdlDef.getPrefix(sc.getElementType().getNamespaceURI());
            if (StringUtils.isEmpty(pfx)) {
                pfx = "xsd";
                String ns = wsdlDef.getNamespace(pfx);
                int count = 1;
                while (!StringUtils.isEmpty(ns)) {
                    pfx = "xsd" + count++;
                    ns = wsdlDef.getNamespace(pfx);
                }
                wsdlDef.addNamespace(pfx, sc.getElementType().getNamespaceURI());
            }
            if (sc.getElement() == null) {
                fixSchema(sc, pfx);
            }
        }
    }
}
 
Example 8
Source File: SOAPBindingUtil.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static void addSOAPNamespace(Definition definition, boolean isSOAP12) {
    Map<?, ?> namespaces = definition.getNamespaces();
    if (isSOAP12
        && !namespaces.values().contains(WSDLConstants.NS_SOAP12)) {
        definition.addNamespace("soap12", WSDLConstants.NS_SOAP12);
    } else if (!namespaces.values().contains(WSDLConstants.NS_SOAP11)) {
        definition.addNamespace("soap", WSDLConstants.NS_SOAP11);
    }
}
 
Example 9
Source File: SOAPBindingUtil.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static void addSOAPNamespace(Definition definition, boolean isSOAP12) {
    Map<?, ?> namespaces = definition.getNamespaces();
    if (isSOAP12
        && !namespaces.values().contains(WSDLConstants.NS_SOAP12)) {
        definition.addNamespace("soap12", WSDLConstants.NS_SOAP12);
    } else if (!namespaces.values().contains(WSDLConstants.NS_SOAP11)) {
        definition.addNamespace("soap", WSDLConstants.NS_SOAP11);
    }
}
 
Example 10
Source File: WSDLSchemaManager.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void addWSDLDefinitionNamespace(Definition defn, String prefix, String ns) {
    if (!defn.getNamespaces().values().contains(ns)) {
        defn.addNamespace(prefix, ns);
    }
}
 
Example 11
Source File: WSDLASTVisitor.java    From cxf with Apache License 2.0 4 votes vote down vote up
private Definition getLogicalDefinition(String schemaFilename, Writer schemaWriter)
    throws WSDLException, JAXBException, Exception {
    Definition def = manager.createWSDLDefinition(targetNamespace);

    // checks for -T option.
    if (schemaFilename != null) {
        writeSchemaDefinition(definition, schemaWriter);
        manager.addWSDLSchemaImport(def, schema.getTargetNamespace(), schemaFilename);
    } else {
        // checks for -n option
        if (importSchemaFilename == null) {
            Types types = definition.getTypes();
            def.setTypes(types);
        } else {
            manager.addWSDLSchemaImport(def, schema.getTargetNamespace(), importSchemaFilename);
        }
    }

    Collection<PortType> portTypes = CastUtils.cast(definition.getAllPortTypes().values());
    for (PortType port : portTypes) {
        def.addPortType(port);
    }

    Collection<Message> messages = CastUtils.cast(definition.getMessages().values());
    for (Message msg : messages) {
        def.addMessage(msg);
    }

    Collection<String> namespaces = CastUtils.cast(definition.getNamespaces().values());
    for (String namespace : namespaces) {
        String prefix = definition.getPrefix(namespace);
        if (!"corba".equals(prefix)) {
            def.addNamespace(prefix, namespace);
        } else {
            def.removeNamespace(prefix);
        }
    }

    Collection<Import> imports = CastUtils.cast(definition.getImports().values());
    for (Import importType : imports) {
        def.addImport(importType);
    }

    def.setDocumentationElement(definition.getDocumentationElement());
    def.setDocumentBaseURI(definition.getDocumentBaseURI());

    return def;
}
 
Example 12
Source File: IDLToWSDLProcessor.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void parseIDL(AST idlTree) throws Exception {
    if (env.isVerbose()) {
        System.out.println(idlTree.toStringTree());
    }

    // target namespace
    String tns = (String) env.get(ToolCorbaConstants.CFG_TNS);
    if (tns == null) {
        tns = CorbaConstants.WSDL_NS_URI + idl;
    }
    // XmlSchema namespace
    String schemans = (String) env.get(ToolCorbaConstants.CFG_SCHEMA_NAMESPACE);

    // corba typemap namespace
    String corbatypemaptns = (String) env.get(ToolCorbaConstants.CFG_CORBATYPEMAP_NAMESPACE);

    outputDir = ".";

    try {
        WSDLASTVisitor visitor = new WSDLASTVisitor(tns, schemans, corbatypemaptns,
                                                    preprocessor.getPragmaPrefix());
        visitor.getManager().setIgnoreImports(ignoreImports);
        if (env.optionSet(ToolConstants.CFG_OUTPUTDIR)) {
            outputDir = (String) env.get(ToolConstants.CFG_OUTPUTDIR);
        }
        visitor.setOutputDir(outputDir);
        Definition def = visitor.getDefinition();
        if (env.optionSet(ToolCorbaConstants.CFG_SEQUENCE_OCTET_TYPE)) {
            visitor.setSequenceOctetType((String) env.get(ToolCorbaConstants.CFG_SEQUENCE_OCTET_TYPE));
        }
        if (env.optionSet(ToolCorbaConstants.CFG_SCHEMA_NAMESPACE)) {
            //visitor.getDefinition()
            def.addNamespace(ToolCorbaConstants.CFG_SCHEMA_NAMESPACE_PREFIX,
                              (String) env.get(ToolCorbaConstants.CFG_SCHEMA_NAMESPACE));
        }
        if (env.optionSet(ToolCorbaConstants.CFG_BOUNDEDSTRINGS)) {
            visitor.setBoundedStringOverride(true);
        }

        if (env.optionSet(ToolCorbaConstants.CFG_MODULETONS)) {
            String mapping = (String) env.get(ToolCorbaConstants.CFG_MODULETONS);
            //parse the mapping & set a map of module to namespace mapping in the visitor
            visitor.setModuleToNSMapping(getModuleToNSMapping(mapping));
        }

        if (env.optionSet(ToolCorbaConstants.CFG_QUALIFIED)) {
            visitor.setQualified(true);
        }

        if (env.optionSet(ToolCorbaConstants.CFG_POLYMORPHIC_FACTORIES)) {
            visitor.setSupportPolymorphicFactories(true);
        }

        if (env.optionSet(ToolCorbaConstants.CFG_SCHEMA)) {
            visitor.setSchemaGenerated(true);
            // generate default namespace for schema if -T is used alone.
            if (env.get(ToolCorbaConstants.CFG_SCHEMA_NAMESPACE) == null) {
                visitor.updateSchemaNamespace(def.getTargetNamespace() + "-types");
                def.addNamespace(ToolCorbaConstants.CFG_SCHEMA_NAMESPACE_PREFIX, def.getTargetNamespace()
                                                                                 + "-types");
            }
        }

        if (env.optionSet(ToolCorbaConstants.CFG_EXCLUDEMODULES)) {
            String modules = (String) env.get(ToolCorbaConstants.CFG_EXCLUDEMODULES);
            //parse the mapping & set a map of module to namespace mapping in the visitor
            visitor.setExcludedModules(getExcludedModules(modules));
        }
        visitor.visit(idlTree);

        cleanUpTypeMap(visitor.getTypeMap());

        Binding[] bindings = visitor.getCorbaBindings();
        generateCORBAService(def, bindings, visitor.getModuleToNSMapper().isDefaultMapping());
        writeDefinitions(visitor);
    } catch (Exception ex) {
        throw new ToolException(ex.getMessage(), ex);
    }
}
 
Example 13
Source File: ServiceWSDLBuilder.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected void addNamespace(String prefix, String namespaceURI, Definition def) {
    ns2prefix.put(namespaceURI, prefix);
    def.addNamespace(prefix, namespaceURI);
}