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

The following examples show how to use javax.wsdl.extensions.schema.Schema#getElement() . 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: WsdlTypes.java    From hop with Apache License 2.0 6 votes vote down vote up
/**
 * Find a named <complexType> or <simpleType> in the types section of the WSDL.
 *
 * @param typeName Name of the type to find.
 * @return null if type not found.
 */
protected Element findNamedType( QName typeName ) {

  Schema s = getSchema( typeName.getNamespaceURI() );
  if ( s == null ) {
    return null;
  }

  Element schemaRoot = s.getElement();

  // get all simple and complex types defined at the top-level.
  //
  List<Element> types = DomUtils.getChildElementsByName( schemaRoot, WsdlUtils.COMPLEX_TYPE_NAME );
  types.addAll( DomUtils.getChildElementsByName( schemaRoot, WsdlUtils.SIMPLE_TYPE_NAME ) );

  Element namedType = null;
  for ( Element t : types ) {
    String schemaTypeName = t.getAttribute( WsdlUtils.NAME_ATTR );
    if ( typeName.getLocalPart().equals( schemaTypeName ) ) {
      namedType = t;
      break;
    }
  }
  return namedType;
}
 
Example 2
Source File: SchemaWriterImpl.java    From cxf with Apache License 2.0 6 votes vote down vote up
public Element getElement(Definition wsdlDef) throws WSDLException {
    Types types = wsdlDef.getTypes();
    if (types != null) {
        List<ExtensibilityElement> l = CastUtils.cast(types.getExtensibilityElements());
        if (l == null) {
            return null;
        }

        for (ExtensibilityElement e : l) {
            if (e instanceof Schema) {
                Schema sc = (Schema)e;
                return sc.getElement();
            }
        }
    }
    return null;
}
 
Example 3
Source File: WsdlTypes.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
/**
 * Find a named &lt;complexType&gt; or &lt;simpleType&gt; in the types section of the WSDL.
 *
 * @param typeName
 *          Name of the type to find.
 * @return null if type not found.
 */
protected Element findNamedType( QName typeName ) {

  Schema s = getSchema( typeName.getNamespaceURI() );
  if ( s == null ) {
    return null;
  }

  Element schemaRoot = s.getElement();

  // get all simple and complex types defined at the top-level.
  //
  List<Element> types = DomUtils.getChildElementsByName( schemaRoot, WsdlUtils.COMPLEX_TYPE_NAME );
  types.addAll( DomUtils.getChildElementsByName( schemaRoot, WsdlUtils.SIMPLE_TYPE_NAME ) );

  Element namedType = null;
  for ( Element t : types ) {
    String schemaTypeName = t.getAttribute( WsdlUtils.NAME_ATTR );
    if ( typeName.getLocalPart().equals( schemaTypeName ) ) {
      namedType = t;
      break;
    }
  }
  return namedType;
}
 
Example 4
Source File: WsdlTypes.java    From hop with Apache License 2.0 5 votes vote down vote up
/**
 * Find a named &lt;element&gt; in the types section of the WSDL.
 *
 * @param elementName Name of element to find.
 * @return The element node.
 * @throws HopTransformException If schema or element in schema can't be found for the given element name
 */
protected Element findNamedElement( QName elementName ) throws HopTransformException {

  Element namedElement = null;
  Schema s = getSchema( elementName.getNamespaceURI() );
  if ( s == null ) {
    throw new HopTransformException( BaseMessages
      .getString( PKG, "Wsdl.Error.MissingSchemaException", elementName ) );
  }

  Element schemaRoot = s.getElement();
  List<Element> elements = DomUtils.getChildElementsByName( schemaRoot, WsdlUtils.ELEMENT_NAME );

  for ( Element e : elements ) {
    String schemaElementName = e.getAttribute( WsdlUtils.NAME_ATTR );
    if ( elementName.getLocalPart().equals( schemaElementName ) ) {
      namedElement = e;
      break;
    }
  }

  if ( namedElement == null ) {
    throw new HopTransformException( BaseMessages.getString(
      PKG, "Wsdl.Error.ElementMissingException", elementName ) );
  }
  return namedElement;
}
 
Example 5
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 6
Source File: WsdlTypes.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Find a named &lt;element&gt; in the types section of the WSDL.
 *
 * @param elementName
 *          Name of element to find.
 * @return The element node.
 * @throws KettleStepException
 *           If schema or element in schema can't be found for the given element name
 */
protected Element findNamedElement( QName elementName ) throws KettleStepException {

  Element namedElement = null;
  Schema s = getSchema( elementName.getNamespaceURI() );
  if ( s == null ) {
    throw new KettleStepException( BaseMessages
      .getString( PKG, "Wsdl.Error.MissingSchemaException", elementName ) );
  }

  Element schemaRoot = s.getElement();
  List<Element> elements = DomUtils.getChildElementsByName( schemaRoot, WsdlUtils.ELEMENT_NAME );

  for ( Element e : elements ) {
    String schemaElementName = e.getAttribute( WsdlUtils.NAME_ATTR );
    if ( elementName.getLocalPart().equals( schemaElementName ) ) {
      namedElement = e;
      break;
    }
  }

  if ( namedElement == null ) {
    throw new KettleStepException( BaseMessages.getString(
      PKG, "Wsdl.Error.ElementMissingException", elementName ) );
  }
  return namedElement;
}
 
Example 7
Source File: XMLUtil.java    From developer-studio with Apache License 2.0 4 votes vote down vote up
public static String getSchemaString(Schema schema) throws Exception {
	Element element = schema.getElement();
	return getElementString(element);
}
 
Example 8
Source File: WSDL11SOAPOperationExtractor.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
/**
 * Initiallize SOAP to REST Operations
 *
 * @return true if extracting operations was successful
 */
private boolean initModels() {
    wsdlDefinition = getWSDLDefinition();
    boolean canProcess = true;
    targetNamespace = wsdlDefinition.getTargetNamespace();
    Types types = wsdlDefinition.getTypes();
    if (types != null) {
        typeList = types.getExtensibilityElements();
    }
    if (typeList != null) {
        for (Object ext : typeList) {
            if (ext instanceof Schema) {
                Schema schema = (Schema) ext;
                Map importedSchemas = schema.getImports();
                Element schemaElement = schema.getElement();
                NodeList schemaNodes = schemaElement.getChildNodes();
                schemaNodeList.addAll(SOAPOperationBindingUtils.list(schemaNodes));
                //gets types from imported schemas from the parent wsdl. Nested schemas will not be imported.
                if (importedSchemas != null) {
                    for (Object importedSchemaObj : importedSchemas.keySet()) {
                        String schemaUrl = (String) importedSchemaObj;
                        if (importedSchemas.get(schemaUrl) != null) {
                            Vector vector = (Vector) importedSchemas.get(schemaUrl);
                            for (Object schemaVector : vector) {
                                if (schemaVector instanceof SchemaImport) {
                                    Schema referencedSchema = ((SchemaImport) schemaVector)
                                            .getReferencedSchema();
                                    if (referencedSchema != null && referencedSchema.getElement() != null) {
                                        if (referencedSchema.getElement().hasChildNodes()) {
                                            schemaNodeList.addAll(SOAPOperationBindingUtils
                                                    .list(referencedSchema.getElement().getChildNodes()));
                                        } else {
                                            log.warn("The referenced schema : " + schemaUrl
                                                    + " doesn't have any defined types");
                                        }
                                    } else {
                                        boolean isInlineSchema = false;
                                        for (Object aSchema : typeList) {
                                            if (schemaUrl.equalsIgnoreCase(
                                                    ((Schema) aSchema).getElement()
                                                            .getAttribute(TARGET_NAMESPACE_ATTRIBUTE))) {
                                                isInlineSchema = true;
                                                break;
                                            }
                                        }
                                        if (isInlineSchema) {
                                            log.debug(schemaUrl + " is already defined inline. Hence continue.");
                                        } else {
                                            log.warn("Cannot access referenced schema for the schema defined at: " + schemaUrl);
                                        }
                                    }
                                }
                            }
                        }
                    }
                } else {
                    log.info("No any imported schemas found in the given wsdl.");
                }

                if (log.isDebugEnabled()) {
                    Gson gson = new GsonBuilder().setExclusionStrategies(new SwaggerFieldsExcludeStrategy())
                            .create();
                    log.debug("swagger definition model map from the wsdl: " + gson.toJson(parameterModelMap));
                }
                if (schemaNodeList == null) {
                    log.warn("No schemas found in the type element for target namespace:" + schema
                            .getDocumentBaseURI());
                }
            }
        }
        if (schemaNodeList != null) {
            for (Node node : schemaNodeList) {
                WSDLParamDefinition wsdlParamDefinition = new WSDLParamDefinition();
                ModelImpl model = new ModelImpl();
                Property currentProperty = null;
                traverseTypeElement(node, null, model, currentProperty);
                if (StringUtils.isNotBlank(model.getName())) {
                    parameterModelMap.put(model.getName(), model);
                }
                if (wsdlParamDefinition.getDefinitionName() != null) {
                    wsdlParamDefinitions.add(wsdlParamDefinition);
                }
            }
        } else {
            log.info("No schema is defined in the wsdl document");
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("Successfully initialized an instance of " + this.getClass().getSimpleName()
                + " with a single WSDL.");
    }
    return canProcess;
}
 
Example 9
Source File: SchemaUtil.java    From cxf with Apache License 2.0 4 votes vote down vote up
private void addSchema(String docBaseURI, Schema schema) {
    //String docBaseURI = schema.getDocumentBaseURI();
    Element schemaEle = schema.getElement();
    if (schemaList.get(docBaseURI) == null) {
        schemaList.put(docBaseURI, schemaEle);
    } else if (schemaList.get(docBaseURI) != null && schemaList.containsValue(schemaEle)) {
        // do nothing
    } else {
        String tns = schema.getDocumentBaseURI() + "#"
                     + schema.getElement().getAttribute("targetNamespace");
        if (schemaList.get(tns) == null) {
            schemaList.put(tns, schema.getElement());
        }
    }

    Map<String, List<?>> imports = CastUtils.cast(schema.getImports());
    if (imports != null && !imports.isEmpty()) {
        for (Map.Entry<String, List<?>> entry : imports.entrySet()) {
            String importNamespace = entry.getKey();
            List<SchemaImport> schemaImports = CastUtils.cast(entry.getValue());

            for (SchemaImport schemaImport : schemaImports) {
                Schema tempImport = schemaImport.getReferencedSchema();
                String key = schemaImport.getSchemaLocationURI();
                if (importNamespace == null && tempImport != null) {
                    importNamespace = tempImport.getDocumentBaseURI();
                }

                if (tempImport != null && !catalogResolved.containsKey(key)) {
                    key = tempImport.getDocumentBaseURI();
                }

                if (tempImport != null
                    && !isSchemaParsed(key, importNamespace)
                    && !schemaList.containsValue(tempImport.getElement())) {
                    addSchema(key, tempImport);
                }
            }

        }
    }
}