Esempio 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;
  }
Esempio n. 2
0
  /** Moves JAXWS customizations under their respective target nodes. */
  private void move(Element bindings, Map<Element, Node> targetNodes) {
    Node target = targetNodes.get(bindings);
    if (target == null)
      // this must be the result of an error on the external binding.
      // recover from the error by ignoring this node
      return;

    Element[] children = DOMUtils.getChildElements(bindings);

    for (Element item : children) {
      if ("bindings".equals(item.getLocalName())) {
        // process child <jaxws:bindings> recursively
        move(item, targetNodes);
      } else if (isGlobalBinding(item)) {
        target = targetNodes.get(item);
        moveUnder(item, (Element) target);
      } else {
        if (!(target instanceof Element)) {
          return; // abort
        }
        // move this node under the target
        moveUnder(item, (Element) target);
      }
    }
  }
  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;
  }
Esempio n. 4
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;
 }
Esempio n. 5
0
  // meat of the processing
  public boolean run(Outline model, Options opt, ErrorHandler errorHandler) {
    for (ClassOutline co : model.getClasses()) {
      CPluginCustomization c = co.target.getCustomizations().find(Const.NS, "code");
      if (c == null) continue; // no customization --- nothing to inject here

      c.markAsAcknowledged();
      // TODO: ideally you should validate this DOM element to make sure
      // that there's no typo/etc. JAXP 1.3 can do this very easily.
      String codeFragment = DOMUtils.getElementText(c.element);

      // inject the specified code fragment into the implementation class.
      co.implClass.direct(codeFragment);
    }

    return true;
  }
Esempio n. 6
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);
  }