Exemplo n.º 1
0
  public Element refineSchemaTarget(Element target) {
    // look for existing xs:annotation
    Element annotation = DOMUtils.getFirstChildElement(target, Constants.NS_XSD, "annotation");
    if (annotation == null)
      // none exists. need to make one
      annotation = insertXMLSchemaElement(target, "annotation");

    // then look for appinfo
    Element appinfo = DOMUtils.getFirstChildElement(annotation, Constants.NS_XSD, "appinfo");
    if (appinfo == null)
      // none exists. need to make one
      appinfo = insertXMLSchemaElement(annotation, "appinfo");

    return appinfo;
  }
  public Element refineTarget(Element target) {
    // look for existing xs:annotation
    Element annotation =
        DOMUtils.getFirstChildElement(target, WellKnownNamespace.XML_SCHEMA, "annotation");
    if (annotation == null)
      // none exists. need to make one
      annotation = insertXMLSchemaElement(target, "annotation");

    // then look for appinfo
    Element appinfo =
        DOMUtils.getFirstChildElement(annotation, WellKnownNamespace.XML_SCHEMA, "appinfo");
    if (appinfo == null)
      // none exists. need to make one
      appinfo = insertXMLSchemaElement(annotation, "appinfo");

    return appinfo;
  }
Exemplo n.º 3
0
 public Element refineWSDLTarget(Element target) {
   // look for existing xs:annotation
   Element JAXWSBindings =
       DOMUtils.getFirstChildElement(target, JAXWSBindingsConstants.NS_JAXWS_BINDINGS, "bindings");
   if (JAXWSBindings == null)
     // none exists. need to make one
     JAXWSBindings = insertJAXWSBindingsElement(target, "bindings");
   return JAXWSBindings;
 }
Exemplo n.º 4
0
  /**
   * Determines the target node of the "bindings" element by using the inherited target node, then
   * put the result into the "result" map.
   */
  private void buildTargetNodeMap(
      Element bindings, Node inheritedTarget, Map<Element, Node> result) {
    // start by the inherited target
    Node target = inheritedTarget;

    validate(bindings); // validate this node

    // look for @wsdlLocation
    if (isTopLevelBinding(bindings)) {
      String wsdlLocation;
      if (bindings.getAttributeNode("wsdlLocation") != null) {
        wsdlLocation = bindings.getAttribute("wsdlLocation");

        try {
          // absolutize this URI.
          // TODO: use the URI class
          // TODO: honor xml:base
          wsdlLocation =
              new URL(new URL(forest.getSystemId(bindings.getOwnerDocument())), wsdlLocation)
                  .toExternalForm();
        } catch (MalformedURLException e) {
          wsdlLocation = JAXWSUtils.absolutize(JAXWSUtils.getFileOrURLName(wsdlLocation));
        }
      } else {
        // the node does not have
        wsdlLocation = forest.getFirstRootDocument();
      }
      target = forest.get(wsdlLocation);

      if (target == null) {
        reportError(
            bindings,
            WsdlMessages.INTERNALIZER_INCORRECT_SCHEMA_REFERENCE(
                wsdlLocation, EditDistance.findNearest(wsdlLocation, forest.listSystemIDs())));
        return; // abort processing this <JAXWS:bindings>
      }
    }

    // if the target node is xs:schema, declare the jaxb version on it as latter on it will be
    // required by the inlined schema bindings

    Element element = DOMUtil.getFirstElementChild(target);
    if (element != null
        && element.getNamespaceURI().equals(Constants.NS_WSDL)
        && element.getLocalName().equals("definitions")) {
      // get all schema elements
      Element type = DOMUtils.getFirstChildElement(element, Constants.NS_WSDL, "types");
      if (type != null) {
        for (Element schemaElement : DOMUtils.getChildElements(type, Constants.NS_XSD, "schema")) {
          if (!schemaElement.hasAttributeNS(Constants.NS_XMLNS, "jaxb")) {
            schemaElement.setAttributeNS(
                Constants.NS_XMLNS, "xmlns:jaxb", JAXWSBindingsConstants.NS_JAXB_BINDINGS);
          }

          // add jaxb:bindings version info. Lets put it to 1.0, may need to change latter
          if (!schemaElement.hasAttributeNS(JAXWSBindingsConstants.NS_JAXB_BINDINGS, "version")) {
            schemaElement.setAttributeNS(
                JAXWSBindingsConstants.NS_JAXB_BINDINGS,
                "jaxb:version",
                JAXWSBindingsConstants.JAXB_BINDING_VERSION);
          }
        }
      }
    }

    boolean hasNode = true;
    if ((isJAXWSBindings(bindings) || isJAXBBindings(bindings))
        && bindings.getAttributeNode("node") != null) {
      target =
          evaluateXPathNode(
              bindings, target, bindings.getAttribute("node"), new NamespaceContextImpl(bindings));
    } else if (isJAXWSBindings(bindings)
        && (bindings.getAttributeNode("node") == null)
        && !isTopLevelBinding(bindings)) {
      hasNode = false;
    } else if (isGlobalBinding(bindings)
        && !isWSDLDefinition(target)
        && isTopLevelBinding(bindings.getParentNode())) {
      target = getWSDLDefintionNode(bindings, target);
    }

    // if target is null it means the xpath evaluation has some problem,
    // just return
    if (target == null) return;

    // update the result map
    if (hasNode) result.put(bindings, target);

    // look for child <JAXWS:bindings> and process them recursively
    Element[] children = getChildElements(bindings);
    for (Element child : children) buildTargetNodeMap(child, target, result);
  }