Java源码示例:javax.wsdl.extensions.schema.Schema

示例1
/**
 * 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;
}
 
示例2
/**
 * Build a list of schema target name spaces which are element form qualified.
 *
 * @return All target name spaces for schemas defined in the WSDL which are element form qualified.
 */
private List<String> getElementFormQualifiedNamespaces() {

  List<String> namespaces = new ArrayList<>();
  List<ExtensibilityElement> schemas = getSchemas();

  for ( ExtensibilityElement schema : schemas ) {
    Element schemaElement = ( (Schema) schema ).getElement();

    if ( schemaElement.hasAttribute( WsdlUtils.ELEMENT_FORM_DEFAULT_ATTR ) ) {
      String v = schemaElement.getAttribute( WsdlUtils.ELEMENT_FORM_DEFAULT_ATTR );
      if ( WsdlUtils.ELEMENT_FORM_QUALIFIED.equalsIgnoreCase( v ) ) {
        namespaces.add( schemaElement.getAttribute( WsdlUtils.TARGET_NAMESPACE_ATTR ) );
      }
    }
  }
  return namespaces;
}
 
示例3
/**
 * Get the schema with the specified target namespace.
 *
 * @param targetNamespace target namespace of the schema to get.
 * @return null if not found.
 */
private Schema getSchema( String targetNamespace ) {

  if ( _types == null ) {
    return null;
  }

  List<ExtensibilityElement> schemas = WsdlUtils.findExtensibilityElements( (ElementExtensible) _types, "schema" );

  for ( ExtensibilityElement e : schemas ) {
    Element schemaRoot = ( (Schema) e ).getElement();
    String tns = schemaRoot.getAttribute( "targetNamespace" );
    if ( targetNamespace.equals( tns ) ) {
      return (Schema) e;
    }
  }
  return null;
}
 
示例4
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;
}
 
示例5
/**
 * 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;
}
 
示例6
/**
 * Build a list of schema target name spaces which are element form qualified.
 *
 * @return All target name spaces for schemas defined in the WSDL which are element form qualified.
 */
private List<String> getElementFormQualifiedNamespaces() {

  List<String> namespaces = new ArrayList<String>();
  List<ExtensibilityElement> schemas = getSchemas();

  for ( ExtensibilityElement schema : schemas ) {
    Element schemaElement = ( (Schema) schema ).getElement();

    if ( schemaElement.hasAttribute( WsdlUtils.ELEMENT_FORM_DEFAULT_ATTR ) ) {
      String v = schemaElement.getAttribute( WsdlUtils.ELEMENT_FORM_DEFAULT_ATTR );
      if ( WsdlUtils.ELEMENT_FORM_QUALIFIED.equalsIgnoreCase( v ) ) {
        namespaces.add( schemaElement.getAttribute( WsdlUtils.TARGET_NAMESPACE_ATTR ) );
      }
    }
  }
  return namespaces;
}
 
示例7
/**
 * Get the schema with the specified target namespace.
 *
 * @param targetNamespace
 *          target namespace of the schema to get.
 * @return null if not found.
 */
private Schema getSchema( String targetNamespace ) {

  if ( _types == null ) {
    return null;
  }

  List<ExtensibilityElement> schemas = WsdlUtils.findExtensibilityElements( _types, "schema" );

  for ( ExtensibilityElement e : schemas ) {
    Element schemaRoot = ( (Schema) e ).getElement();
    String tns = schemaRoot.getAttribute( "targetNamespace" );
    if ( targetNamespace.equals( tns ) ) {
      return (Schema) e;
    }
  }
  return null;
}
 
示例8
/**
 * 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;
}
 
示例9
/**
 * Create a new instance, parse the WSDL file for named complex types.
 *
 * @param wsdlTypes Name space resolver.
 */
protected WsdlComplexTypes( WsdlTypes wsdlTypes ) {

  List<ExtensibilityElement> schemas = wsdlTypes.getSchemas();
  for ( ExtensibilityElement schema : schemas ) {
    Element schemaRoot = ( (Schema) schema ).getElement();

    List<Element> types = DomUtils.getChildElementsByName( schemaRoot, WsdlUtils.COMPLEX_TYPE_NAME );
    for ( Element t : types ) {
      String schemaTypeName = t.getAttribute( WsdlUtils.NAME_ATTR );
      _complexTypes.put( schemaTypeName, new ComplexType( t, wsdlTypes ) );
    }
  }
}
 
示例10
public void setSchemaDocIntoWSDLTypes( Document doc ) {
	try {

		Types wsdl_types = localDef.createTypes();
		Schema typesExt = (Schema) extensionRegistry.createExtension( Types.class,
			new QName( NameSpacesEnum.XML_SCH.getNameSpaceURI(), "schema" ) );
		typesExt.setElement( (Element) doc.getFirstChild() );
		wsdl_types.addExtensibilityElement( typesExt );
		localDef.setTypes( wsdl_types );

	} catch( Exception ex ) {
		System.err.println( ex.getMessage() );
	}
}
 
示例11
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;
    }
  }
}
 
示例12
public void addWSDLSchemaImport(Definition def, String tns, File file) throws Exception {
    // REVISIT, check if the wsdl schema already exists.
    Types types = def.getTypes();
    if (types == null) {
        types = def.createTypes();
        def.setTypes(types);
    }
    Schema wsdlSchema = (Schema)def.getExtensionRegistry()
        .createExtension(Types.class, new QName(Constants.URI_2001_SCHEMA_XSD, "schema"));

    addWSDLSchemaImport(wsdlSchema, tns, file);
    types.addExtensibilityElement(wsdlSchema);
}
 
示例13
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);
    }
}
 
示例14
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);
            }
        }
    }
}
 
示例15
private void fixSchema(Schema sc, String pfx) throws ParserConfigurationException {
    Document doc = DOMUtils.getEmptyDocument();
    Element el = doc.createElementNS(sc.getElementType().getNamespaceURI(),
                        pfx + ":" + sc.getElementType().getLocalPart());
    sc.setElement(el);
    Map<String, List<String>> mp = CastUtils.cast(sc.getImports());
    for (Map.Entry<String, List<String>> ent : mp.entrySet()) {
        Element imp = doc.createElementNS(sc.getElementType().getNamespaceURI(),
                                          pfx + ":import");
        el.appendChild(imp);
        imp.setAttribute("namespace", ent.getKey());
    }
}
 
示例16
/**
 * When the imported schema location has been resolved through catalog, we need to:
 * 1) get a valid relative location to use for recursion into the imported schema
 * 2) add an entry to the doneSchemas map using such a valid relative location, as that's
 *    what will be used later for import links
 *
 * The valid relative location for the imported schema is computed by first obtaining the
 * relative uri that maps the importing schema resolved location into the imported schema
 * resolved location, then such value is resolved on top of the valid relative location
 * that's saved in the doneSchemas map for the importing schema.
 *
 * @param doneSchemas
 * @param resolvedSchemaLocation
 * @param currentSchema
 * @param schemaReference
 * @return
 */
private String getAndSaveRelativeSchemaLocationIfCatalogResolved(Map<String, SchemaReference> doneSchemas,
                                                                 String resolvedSchemaLocation,
                                                                 Schema currentSchema,
                                                                 SchemaReference schemaReference) {
    String path = null;
    for (Map.Entry<String, SchemaReference> entry : doneSchemas.entrySet()) {
        Schema rs = entry.getValue().getReferencedSchema();
        String k = entry.getKey();
        String rsURI = rs.getDocumentBaseURI();
        if (currentSchema.equals(rs) && !rsURI.equals(k)) {
            try {
                String p = URIParserUtil.relativize(rsURI, resolvedSchemaLocation);
                if (p != null) {
                    path = new URI(k).resolve(p).toString();
                    break;
                }
            } catch (URISyntaxException e) {
                // ignore
            }
        }
    }
    if (path != null) {
        doneSchemas.put(path, schemaReference);
    }
    return path;
}
 
示例17
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);
}
 
示例18
private void getSchemaList(Definition def) {
    Types typesElement = def.getTypes();
    if (typesElement != null) {
        Iterator<?> ite = typesElement.getExtensibilityElements().iterator();
        while (ite.hasNext()) {
            Object obj = ite.next();
            if (obj instanceof Schema) {
                Schema schema = (Schema)obj;
                addSchema(schema.getDocumentBaseURI(), schema);
            }
        }
    }
}
 
示例19
public void marshall(@SuppressWarnings("rawtypes") Class parentType,
                     QName elementType, ExtensibilityElement extension, PrintWriter pw,
                     Definition def, ExtensionRegistry extReg) throws WSDLException {
    try {
        writeXml(((Schema)extension).getElement(), pw);
    } catch (XMLStreamException e) {
        throw new WSDLException("", "Could not write schema.", e);
    }
}
 
示例20
@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()
                 );
}
 
示例21
protected static void addNamespaces(Schema schema, Map<String, String> namespaces) {
	for (Map.Entry<String,String> e : namespaces.entrySet()) {
		String key = e.getKey().length() == 0 ? "xmlns" : ("xmlns:" + e.getKey());
		if (schema.getElement().getAttribute(key).length() == 0) {
			schema.getElement().setAttribute(key, e.getValue());
		}
	}
}
 
示例22
/**
 * 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;
}
 
示例23
/**
 * Create a new instance, parse the WSDL file for named complex types.
 *
 * @param wsdlTypes
 *          Name space resolver.
 */
protected WsdlComplexTypes( WsdlTypes wsdlTypes ) {

  List<ExtensibilityElement> schemas = wsdlTypes.getSchemas();
  for ( ExtensibilityElement schema : schemas ) {
    Element schemaRoot = ( (Schema) schema ).getElement();

    List<Element> types = DomUtils.getChildElementsByName( schemaRoot, WsdlUtils.COMPLEX_TYPE_NAME );
    for ( Element t : types ) {
      String schemaTypeName = t.getAttribute( WsdlUtils.NAME_ATTR );
      _complexTypes.put( schemaTypeName, new ComplexType( t, wsdlTypes ) );
    }
  }
}
 
示例24
protected S2JJAXBModel compileModel(Types types, SchemaCompiler compiler, org.w3c.dom.Element rootTypes) {
  Schema schema = (Schema) types.getExtensibilityElements().get(0);
  compiler.parseSchema(schema.getDocumentBaseURI() + "#types1", rootTypes);
  S2JJAXBModel intermediateModel = compiler.bind();
  return intermediateModel;
}
 
示例25
protected S2JJAXBModel compileModel(Types types, SchemaCompiler compiler, Element rootTypes) {
  Schema schema = (Schema) types.getExtensibilityElements().get(0);
  compiler.parseSchema(schema.getDocumentBaseURI() + "#types1", rootTypes);
  S2JJAXBModel intermediateModel = compiler.bind();
  return intermediateModel;
}
 
示例26
protected S2JJAXBModel compileModel(Types types, SchemaCompiler compiler, org.w3c.dom.Element rootTypes) {
    Schema schema = (Schema) types.getExtensibilityElements().get(0);
    compiler.parseSchema(schema.getDocumentBaseURI() + "#types1", rootTypes);
    S2JJAXBModel intermediateModel = compiler.bind();
    return intermediateModel;
}
 
示例27
protected S2JJAXBModel compileModel(Types types, SchemaCompiler compiler, Element rootTypes) {
    Schema schema = (Schema) types.getExtensibilityElements().get(0);
    compiler.parseSchema(schema.getDocumentBaseURI() + "#types1", rootTypes);
    S2JJAXBModel intermediateModel = compiler.bind();
    return intermediateModel;
}
 
示例28
private void init(Types types) {
    Collection<Schema> schemas = WSDLUtils.findExtensibilityElements(types.getExtensibilityElements(), Schema.class);
    for (Schema schema : schemas) {
        createXmlSchema(schema.getElement(), schema.getDocumentBaseURI());
    }
}
 
示例29
public static String getSchemaString(Schema schema) throws Exception {
	Element element = schema.getElement();
	return getElementString(element);
}
 
示例30
public static void writeSchema(Schema schema, OutputStream outputStream) throws Exception {
	FileUtils.createFile(getSchemaString(schema), outputStream);
}