Package javax.wsdl.extensions.schema

Examples of javax.wsdl.extensions.schema.SchemaReference


                        .getWSDLFactory().newWSDLWriter();
                    def.setExtensionRegistry(bus.getExtension(WSDLManager.class).getExtensionRegistry());
                    doc = wsdlWriter.getDocument(def);
                }
            } else {
                SchemaReference si = smp.get(xsd);
                if (si == null) {
                    String xsd2 = resolveWithCatalogs(OASISCatalogManager.getCatalogManager(bus),
                                                       xsd,
                                                       base);
                    if (xsd2 != null) {
                        si = smp.get(xsd2);
                    }
                }
                if (si == null) {
                    throw new WSDLQueryException(new Message("SCHEMA_NOT_FOUND", LOG, wsdl), null);
                }
               
                String uri = si.getReferencedSchema().getDocumentBaseURI();
                uri = resolveWithCatalogs(OASISCatalogManager.getCatalogManager(bus),
                                          uri,
                                          si.getReferencedSchema().getDocumentBaseURI());
                if (uri == null) {
                    uri = si.getReferencedSchema().getDocumentBaseURI();
                }
                ResourceManagerWSDLLocator rml = new ResourceManagerWSDLLocator(uri,
                                                                                bus);
               
                InputSource src = rml.getBaseInputSource();
View Full Code Here


                        .getWSDLFactory().newWSDLWriter();
                    def.setExtensionRegistry(bus.getExtension(WSDLManager.class).getExtensionRegistry());
                    doc = wsdlWriter.getDocument(def);
                }
            } else {
                SchemaReference si = smp.get(xsd);
                if (si == null) {
                    String xsd2 = resolveWithCatalogs(OASISCatalogManager.getCatalogManager(bus),
                                                       xsd,
                                                       base);
                    si = smp.get(xsd2);
                }
               
                String uri = si.getReferencedSchema().getDocumentBaseURI();
                uri = resolveWithCatalogs(OASISCatalogManager.getCatalogManager(bus),
                                          uri,
                                          si.getReferencedSchema().getDocumentBaseURI());
                if (uri == null) {
                    uri = si.getReferencedSchema().getDocumentBaseURI();
                }
                ResourceManagerWSDLLocator rml = new ResourceManagerWSDLLocator(uri,
                                                                                bus);
               
                InputSource src = rml.getBaseInputSource();
View Full Code Here

        * if the user chooses not to register a suitable deserializer then the
        * UnknownDeserializer will be used, returning an UnknownExtensibilityElement.
        */

    Schema schema = null;
    SchemaReference schemaRef = null;
    try
    {

      QName elementType = QNameUtils.newQName(el);

      ExtensionDeserializer exDS =
          extReg.queryDeserializer(parentType, elementType);

      //Now unmarshall the DOM element.
      ExtensibilityElement ee =
          exDS.unmarshall(parentType, elementType, el, def, extReg);

      if (ee instanceof Schema)
      {
        schema = (Schema) ee;
      }
      else
      {
        //Unknown extensibility element, so don't do any more schema parsing on it.
        return ee;
      }


      //Keep track of parsed schemas to avoid duplicating Schema objects
      //through duplicate or circular references (eg: A imports B imports A).
      if (schema.getDocumentBaseURI() != null)
      {
        this.allSchemas.put(schema.getDocumentBaseURI(), schema);
      }

      //At this point, any SchemaReference objects held by the schema will not
      //yet point to their referenced schemas, so we must now retrieve these
      //schemas and set the schema references.

      //First, combine the schema references for imports, includes and redefines
      //into a single list

      ArrayList allSchemaRefs = new ArrayList();

      Collection ic = schema.getImports().values();
      Iterator importsIterator = ic.iterator();
      while(importsIterator.hasNext())
      {
        allSchemaRefs.addAll( (Collection) importsIterator.next() );
      }

      allSchemaRefs.addAll(schema.getIncludes());
      allSchemaRefs.addAll(schema.getRedefines());

      //Then, retrieve the schema referred to by each schema reference. If the
      //schema has been read in previously, use the existing schema object.
      //Otherwise unmarshall the DOM element into a new schema object.

      ListIterator schemaRefIterator = allSchemaRefs.listIterator();

      while(schemaRefIterator.hasNext())
      {
        try
        {
          schemaRef = (SchemaReference) schemaRefIterator.next();

          if (schemaRef.getSchemaLocationURI() == null)
          {
            //cannot get the referenced schema, so ignore this schema reference
            continue;
          }

          if (verbose)
          {
            System.out.println("Retrieving schema at '" +
                schemaRef.getSchemaLocationURI() +
                (schema.getDocumentBaseURI() == null
                    ? "'."
                    : "', relative to '" +
                    schema.getDocumentBaseURI() + "'."));
          }


          InputStream inputStream = null;
          InputSource inputSource = null;

          //This is the child schema referred to by the schemaReference
          Schema referencedSchema = null;

          //This is the child schema's location obtained from the WSDLLocator or the URL
          String location = null;

          if (loc != null)
          {
            //Try to get the referenced schema using the wsdl locator
            inputSource = loc.getImportInputSource(
                schema.getDocumentBaseURI(), schemaRef.getSchemaLocationURI());

            if (inputSource == null)
            {
              throw new WSDLException(WSDLException.OTHER_ERROR,
                  "Unable to locate with a locator "
                      + "the schema referenced at '"
                      + schemaRef.getSchemaLocationURI()
                      + "' relative to document base '"
                      + schema.getDocumentBaseURI() + "'");
            }
            location = loc.getLatestImportURI();

            //if a schema from this location has been read previously, use it.
            referencedSchema = (Schema) this.allSchemas.get(location);
          }
          else
          {
            // We don't have a wsdl locator, so try to retrieve the schema by its URL
            String contextURI = schema.getDocumentBaseURI();
            URL contextURL = (contextURI != null) ? StringUtils.getURL(null, contextURI) : null;
            URL url = StringUtils.getURL(contextURL, schemaRef.getSchemaLocationURI());
            location = url.toExternalForm();

            //if a schema from this location has been retrieved previously, use it.
            referencedSchema = (Schema) this.allSchemas.get(location);

            if (referencedSchema == null)
            {
              // We haven't read this schema in before so do it now
              inputStream = StringUtils.getContentAsInputStream(url);

              if (inputStream != null)
              {
                inputSource = new InputSource(inputStream);
              }

              if (inputSource == null)
              {
                throw new WSDLException(WSDLException.OTHER_ERROR,
                    "Unable to locate with a url "
                        + "the document referenced at '"
                        + schemaRef.getSchemaLocationURI()
                        + "'"
                        + (contextURI == null ? "." : ", relative to '"
                        + contextURI + "'."));
              }
            }

          } //end if loc

          // If we have not previously read the schema, get its DOM element now.
          if (referencedSchema == null)
          {
            inputSource.setSystemId(location);
            Document doc = getDocument(inputSource, location);

            if (inputStream != null)
            {
              inputStream.close();
            }

            Element documentElement = doc.getDocumentElement();

            // If it's a schema doc process it, otherwise the schema reference remains null

            QName docElementQName = QNameUtils.newQName(documentElement);

            if (SchemaConstants.XSD_QNAME_LIST.contains(docElementQName))
            {
              //We now need to call parseSchema recursively to parse the referenced
              //schema. The document base URI of the referenced schema will be set to
              //the document base URI of the current schema plus the schemaLocation in
              //the schemaRef. We cannot explicitly pass in a new document base URI
              //to the schema deserializer, so instead we will create a dummy
              //Definition and set its documentBaseURI to the new document base URI.
              //We can leave the other definition fields empty because we know
              //that the SchemaDeserializer.unmarshall method uses the definition
              //parameter only to get its documentBaseURI. If the unmarshall method
              //implementation changes (ie: its use of definition changes) we may need
              //to rethink this approach.

              WSDLFactory factory = getWSDLFactory();
              Definition dummyDef = factory.newDefinition();

              dummyDef.setDocumentBaseURI(location);

              //By this point, we know we have a SchemaDeserializer registered
              //so we can safely cast the ExtensibilityElement to a Schema.
              referencedSchema = (Schema) parseSchema( parentType,
                  documentElement,
                  dummyDef,
                  extReg);
            }

          } //end if referencedSchema

          schemaRef.setReferencedSchema(referencedSchema);
        }
        catch (WSDLException e)
        {
          throw e;
        }
        catch (RuntimeException e)
        {
          throw e;
        }
        catch (Exception e)
        {
          throw new WSDLException(WSDLException.OTHER_ERROR,
              "An error occurred trying to resolve schema referenced at '"
                  + schemaRef.getSchemaLocationURI()
                  + "'"
                  + (schema.getDocumentBaseURI() == null ? "." : ", relative to '"
                  + schema.getDocumentBaseURI() + "'."),
              e);
        }
View Full Code Here

                        .getWSDLFactory().newWSDLWriter();
                    def.setExtensionRegistry(bus.getExtension(WSDLManager.class).getExtensionRegistry());
                    doc = wsdlWriter.getDocument(def);
                }
            } else {
                SchemaReference si = smp.get(xsd);
                if (si == null) {
                    String xsd2 = resolveWithCatalogs(OASISCatalogManager.getCatalogManager(bus),
                                                       xsd,
                                                       base);
                    if (xsd2 != null) {
                        si = smp.get(xsd2);
                    }
                }
                if (si == null) {
                    throw new WSDLQueryException(new Message("SCHEMA_NOT_FOUND", LOG, wsdl), null);
                }
               
                String uri = si.getReferencedSchema().getDocumentBaseURI();
                uri = resolveWithCatalogs(OASISCatalogManager.getCatalogManager(bus),
                                          uri,
                                          si.getReferencedSchema().getDocumentBaseURI());
                if (uri == null) {
                    uri = si.getReferencedSchema().getDocumentBaseURI();
                }
                ResourceManagerWSDLLocator rml = new ResourceManagerWSDLLocator(uri,
                                                                                bus);
               
                InputSource src = rml.getBaseInputSource();
View Full Code Here

            rootElement = writer.getDocument(def).getDocumentElement();
           
            updateWSDLImports(rootElement, base, wsdlKey);
            updateSchemaImports(rootElement, base, wsdlKey);
        } else {
            SchemaReference si = schemaMap.get(xsdKey);
           
            if (si == null) {
                throw new FileNotFoundException("Schema not found: " + xsdKey);
            }
           
            rootElement = si.getReferencedSchema().getElement();
           
            updateSchemaImports(rootElement, base, xsdKey);
        }
               
        writeTo(rootElement, os);
View Full Code Here

                key = new URI(".").resolve(loc).toString();
            }
        } catch (URISyntaxException e) {
           //ignore
        }
        SchemaReference ref = smp.get(URLDecoder.decode(key, "utf-8"));
        if (ref != null) {
            return base + "?xsd=" + key.replace(" ", "%20");
        }
        return null;
    }
View Full Code Here

    protected Document readXSDDocument(Bus bus,
                                       String xsd,
                                       Map<String, SchemaReference> smp,
                                       String base) throws XMLStreamException {
        Document doc = null;
        SchemaReference si = lookupSchemaReference(bus, xsd, smp, base);

        String uri = si.getReferencedSchema().getDocumentBaseURI();
        uri = resolveWithCatalogs(OASISCatalogManager.getCatalogManager(bus),
            uri, si.getReferencedSchema().getDocumentBaseURI());
        if (uri == null) {
            uri = si.getReferencedSchema().getDocumentBaseURI();
        }
        ResourceManagerWSDLLocator rml = new ResourceManagerWSDLLocator(uri, bus);

        InputSource src = rml.getBaseInputSource();
        if (src.getByteStream() != null || src.getCharacterStream() != null) {
            doc = StaxUtils.read(src);
        } else { // last resort lets try for the referenced schema itself.
            // its not thread safe if we use the same document
            doc = StaxUtils.read(
                new DOMSource(si.getReferencedSchema().getElement().getOwnerDocument()));
        }

        return doc;
    }
View Full Code Here

     */
    private SchemaReference lookupSchemaReference(Bus bus,
                                                  String xsd,
                                                  Map<String, SchemaReference> smp,
                                                  String base) {
        SchemaReference si = smp.get(xsd);
        if (si == null) {
            String xsd2 = resolveWithCatalogs(OASISCatalogManager.getCatalogManager(bus),
                xsd, base);
            if (xsd2 != null) {
                si = smp.get(xsd2);
View Full Code Here

                        .getWSDLFactory().newWSDLWriter();
                    def.setExtensionRegistry(bus.getExtension(WSDLManager.class).getExtensionRegistry());
                    doc = wsdlWriter.getDocument(def);
                }
            } else {
                SchemaReference si = smp.get(xsd);
                if (si == null) {
                    String xsd2 = resolveWithCatalogs(OASISCatalogManager.getCatalogManager(bus),
                                                       xsd,
                                                       base);
                    if (xsd2 != null) {
                        si = smp.get(xsd2);
                    }
                }
                if (si == null) {
                    throw new WSDLQueryException(new Message("SCHEMA_NOT_FOUND", LOG, wsdl), null);
                }
               
                String uri = si.getReferencedSchema().getDocumentBaseURI();
                uri = resolveWithCatalogs(OASISCatalogManager.getCatalogManager(bus),
                                          uri,
                                          si.getReferencedSchema().getDocumentBaseURI());
                if (uri == null) {
                    uri = si.getReferencedSchema().getDocumentBaseURI();
                }
                ResourceManagerWSDLLocator rml = new ResourceManagerWSDLLocator(uri,
                                                                                bus);
               
                InputSource src = rml.getBaseInputSource();
View Full Code Here

/*      */
/*      */   protected ExtensibilityElement parseSchema(Class parentType, Element el, Definition def, ExtensionRegistry extReg)
/*      */     throws WSDLException
/*      */   {
/*  687 */     Schema schema = null;
/*  688 */     SchemaReference schemaRef = null;
/*      */     try
/*      */     {
/*  692 */       QName elementType = QNameUtils.newQName(el);
/*      */
/*  694 */       ExtensionDeserializer exDS = extReg.queryDeserializer(parentType, elementType);
/*      */
/*  698 */       ExtensibilityElement ee = exDS.unmarshall(parentType, elementType, el, def, extReg);
/*      */
/*  701 */       if ((ee instanceof Schema))
/*      */       {
/*  703 */         schema = (Schema)ee;
/*      */       }
/*      */       else
/*      */       {
/*  708 */         return ee;
/*      */       }
/*      */
/*  714 */       if (schema.getDocumentBaseURI() != null)
/*      */       {
/*  716 */         this.allSchemas.put(schema.getDocumentBaseURI(), schema);
/*      */       }
/*      */
/*  726 */       ArrayList allSchemaRefs = new ArrayList();
/*      */
/*  728 */       Collection ic = schema.getImports().values();
/*  729 */       Iterator importsIterator = ic.iterator();
/*  730 */       while (importsIterator.hasNext())
/*      */       {
/*  732 */         allSchemaRefs.addAll((Collection)importsIterator.next());
/*      */       }
/*      */
/*  735 */       allSchemaRefs.addAll(schema.getIncludes());
/*  736 */       allSchemaRefs.addAll(schema.getRedefines());
/*      */
/*  742 */       ListIterator schemaRefIterator = allSchemaRefs.listIterator();
/*      */
/*  744 */       while (schemaRefIterator.hasNext())
/*      */       {
/*      */         try
/*      */         {
/*  748 */           schemaRef = (SchemaReference)schemaRefIterator.next();
/*      */
/*  750 */           if (schemaRef.getSchemaLocationURI() == null)
/*      */           {
/*      */             continue;
/*      */           }
/*      */
/*  756 */           if (this.verbose)
/*      */           {
/*  758 */             System.out.println("Retrieving schema at '" + schemaRef.getSchemaLocationURI() + (schema.getDocumentBaseURI() == null ? "'." : new StringBuilder().append("', relative to '").append(schema.getDocumentBaseURI()).append("'.").toString()));
/*      */           }
/*      */
/*  767 */           InputStream inputStream = null;
/*  768 */           InputSource inputSource = null;
/*      */
/*  771 */           Schema referencedSchema = null;
/*      */
/*  774 */           String location = null;
/*      */
/*  776 */           if (this.loc != null)
/*      */           {
/*  779 */             inputSource = this.loc.getImportInputSource(schema.getDocumentBaseURI(), schemaRef.getSchemaLocationURI());
/*      */
/*  782 */             if (inputSource == null)
/*      */             {
/*  784 */               throw new WSDLException("OTHER_ERROR", "Unable to locate with a locator the schema referenced at '" + schemaRef.getSchemaLocationURI() + "' relative to document base '" + schema.getDocumentBaseURI() + "'");
/*      */             }
/*      */
/*  791 */             location = this.loc.getLatestImportURI();
/*      */
/*  794 */             referencedSchema = (Schema)this.allSchemas.get(location);
/*      */           }
/*      */           else
/*      */           {
/*  799 */             String contextURI = schema.getDocumentBaseURI();
/*  800 */             URL contextURL = contextURI != null ? StringUtils.getURL(null, contextURI) : null;
/*  801 */             URL url = StringUtils.getURL(contextURL, schemaRef.getSchemaLocationURI());
/*  802 */             location = url.toExternalForm();
/*      */
/*  805 */             referencedSchema = (Schema)this.allSchemas.get(location);
/*      */
/*  807 */             if (referencedSchema == null)
/*      */             {
/*  810 */               inputStream = StringUtils.getContentAsInputStream(url);
/*      */
/*  812 */               if (inputStream != null)
/*      */               {
/*  814 */                 inputSource = new InputSource(inputStream);
/*      */               }
/*      */
/*  817 */               if (inputSource == null)
/*      */               {
/*  819 */                 throw new WSDLException("OTHER_ERROR", "Unable to locate with a url the document referenced at '" + schemaRef.getSchemaLocationURI() + "'" + (contextURI == null ? "." : new StringBuilder().append(", relative to '").append(contextURI).append("'.").toString()));
/*      */               }
/*      */
/*      */             }
/*      */
/*      */           }
/*      */
/*  832 */           if (referencedSchema == null)
/*      */           {
/*  834 */             inputSource.setSystemId(location);
/*  835 */             Document doc = getDocument(inputSource, location);
/*      */
/*  837 */             if (inputStream != null)
/*      */             {
/*  839 */               inputStream.close();
/*      */             }
/*      */
/*  842 */             Element documentElement = doc.getDocumentElement();
/*      */
/*  846 */             QName docElementQName = QNameUtils.newQName(documentElement);
/*      */
/*  848 */             if (SchemaConstants.XSD_QNAME_LIST.contains(docElementQName))
/*      */             {
/*  862 */               WSDLFactory factory = getWSDLFactory();
/*  863 */               Definition dummyDef = factory.newDefinition();
/*      */
/*  865 */               dummyDef.setDocumentBaseURI(location);
/*      */
/*  869 */               referencedSchema = (Schema)parseSchema(parentType, documentElement, dummyDef, extReg);
/*      */             }
/*      */
/*      */           }
/*      */
/*  877 */           schemaRef.setReferencedSchema(referencedSchema);
/*      */         }
/*      */         catch (WSDLException e)
/*      */         {
/*  881 */           throw e;
/*      */         }
/*      */         catch (RuntimeException e)
/*      */         {
/*  885 */           throw e;
/*      */         }
/*      */         catch (Exception e)
/*      */         {
/*  889 */           throw new WSDLException("OTHER_ERROR", "An error occurred trying to resolve schema referenced at '" + schemaRef.getSchemaLocationURI() + "'" + (schema.getDocumentBaseURI() == null ? "." : new StringBuilder().append(", relative to '").append(schema.getDocumentBaseURI()).append("'.").toString()), e);
/*      */         }
/*      */
/*      */       }
/*      */
/*  900 */       return schema;
View Full Code Here

TOP

Related Classes of javax.wsdl.extensions.schema.SchemaReference

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.