Пример #1
0
  /**
   * This method creates a WSDL document containing the partner link types.
   *
   * @param model The global protocol model
   * @param role The role of the process
   * @param localcm The local protocol model
   * @param bpelProcess The BPEL process
   * @param journal The feedback handler
   * @return The WSDL document containing the partner link types
   * @throws Exception Failed to generate the partner link types
   */
  public static org.w3c.dom.Document generatePartnerLinkTypes(
      ProtocolModel model,
      Role role,
      ProtocolModel localcm,
      TProcess bpelProcess,
      FeedbackHandler journal)
      throws Exception {
    org.w3c.dom.Document doc =
        javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
    org.w3c.dom.Element defn = doc.createElement(WSDL_DEFINITIONS);
    doc.appendChild(defn);

    defn.setAttribute(XMLNS_PLNK, PLNKTYPE_NS);
    defn.setAttribute(XMLNS_WSDL, WSDL_NS);

    defn.setAttribute(NAME_LABEL, localcm.getProtocol().getName());

    defn.setAttribute(TARGET_NAMESPACE_LABEL, bpelProcess.getTargetNamespace());

    ContractGenerator cg = ContractGeneratorFactory.getContractGenerator();

    // Add import to associated wsdl
    String wsdlName = WSDLGeneratorUtil.getWSDLFileName(role, localcm.getProtocol().getName(), "");

    org.w3c.dom.Element imp = doc.createElement(WSDL_IMPORT);

    imp.setAttribute("namespace", bpelProcess.getTargetNamespace());
    imp.setAttribute("location", wsdlName);

    defn.appendChild(imp);

    // Add imports for associated roles
    java.util.ListIterator<Role> roles = localcm.getProtocol().getRoles().listIterator();

    while (roles.hasNext()) {
      Role r = roles.next();

      // Check if role is a client parameter - if so,
      // don't include an import for it
      if (localcm.getProtocol().getParameterDefinition(r.getName()) != null) {
        continue;
      }

      Contract contract = null;

      if (cg != null) {
        contract = cg.generate(model.getProtocol(), null, r, journal);
      }

      if (contract != null) {
        boolean gen = false;

        java.util.Iterator<Interface> iter = contract.getInterfaces().iterator();

        while (gen == false && iter.hasNext()) {
          Interface intf = iter.next();

          if (intf.getMessageExchangePatterns().size() > 0) {
            gen = true;
          }
        }

        if (gen) {
          wsdlName = WSDLGeneratorUtil.getWSDLFileName(r, localcm.getProtocol().getName(), "");

          imp = doc.createElement(WSDL_IMPORT);

          imp.setAttribute("namespace", contract.getNamespace());
          imp.setAttribute("location", wsdlName);

          defn.appendChild(imp);
        }
      }
    }

    // Create partner link types
    java.util.Map<String, String> nsMap = new java.util.HashMap<String, String>();

    for (TPartnerLink pl : bpelProcess.getPartnerLinks().getPartnerLink()) {
      org.w3c.dom.Element plt = doc.createElement(PLNK_PARTNER_LINK_TYPE);

      plt.setAttribute(NAME_LABEL, pl.getPartnerLinkType().getLocalPart());

      if (pl.getPartnerRole() != null && pl.getPartnerRole().trim().length() > 0) {
        org.w3c.dom.Element plRole = doc.createElement(PLNK_ROLE);

        plt.appendChild(plRole);

        plRole.setAttribute(NAME_LABEL, pl.getPartnerRole());

        Role useRole = null;

        for (int i = 0; useRole == null && i < localcm.getProtocol().getRoles().size(); i++) {
          if (pl.getPartnerRole().startsWith(localcm.getProtocol().getRoles().get(i).getName())) {
            useRole = localcm.getProtocol().getRoles().get(i);
          }
        }

        Contract contract = null;

        if (cg != null && useRole != null) {
          contract = cg.generate(model.getProtocol(), null, useRole, journal);
        }

        if (contract != null) {
          Interface intf = null;

          if (pl.getMyRole() != null) {
            intf = contract.getInterface(pl.getMyRole());
          }

          if (intf == null && contract.getInterfaces().size() > 0) {
            intf = contract.getInterfaces().iterator().next();
          }

          if (intf != null) {
            String prefix = null;
            String portType = intf.getName();

            if (intf.getNamespace() != null) {
              prefix = XMLUtils.getPrefixForNamespace(intf.getNamespace(), nsMap);

              portType = prefix + ":" + portType;
            }

            plRole.setAttribute(PORT_TYPE_LABEL, portType);
          }
        }
      }

      if (pl.getMyRole() != null && pl.getMyRole().trim().length() > 0) {
        org.w3c.dom.Element plRole = doc.createElement(PLNK_ROLE);

        plt.appendChild(plRole);

        plRole.setAttribute(NAME_LABEL, pl.getMyRole());

        Contract contract = null;

        if (cg != null) {
          String linkName = pl.getPartnerLinkType().getLocalPart();

          int pos = linkName.indexOf("To");

          if (pos != -1) {
            java.util.Set<Role> clientRoles = new java.util.HashSet<Role>();

            clientRoles.add(new Role(linkName.substring(0, pos)));

            contract = cg.generate(model.getProtocol(), clientRoles, role, journal);
          } else {
            contract = cg.generate(model.getProtocol(), null, role, journal);
          }
        }

        if (contract != null) {
          Interface intf = null;

          if (pl.getMyRole() != null) {
            intf = contract.getInterface(pl.getMyRole());
          }

          if (intf == null && contract.getInterfaces().size() > 0) {
            intf = contract.getInterfaces().iterator().next();
          }

          if (intf != null) {
            String prefix = null;
            String portType = intf.getName();

            if (intf.getNamespace() != null) {
              prefix = XMLUtils.getPrefixForNamespace(intf.getNamespace(), nsMap);

              portType = prefix + ":" + portType;
            }

            plRole.setAttribute(PORT_TYPE_LABEL, portType);
          }
        }
      }

      defn.appendChild(plt);
    }

    // Create remaining namespace/prefix mappings
    java.util.Iterator<String> iter = nsMap.keySet().iterator();
    while (iter.hasNext()) {
      String ns = iter.next();
      String prefix = nsMap.get(ns);

      defn.setAttribute(XMLNS_PREFIX + prefix, ns);
    }

    return (doc);
  }
Пример #2
0
  /**
   * This method generates the BPEL deployment descriptor.
   *
   * @param model The global protocol model
   * @param role The role being generated
   * @param localcm The local protocol model
   * @param bpelProcess The BPEL process
   * @param wsdls The list of relevant WSDL definitions
   * @param partnerLinkTypes The partner link types for this role
   * @param journal The feedback handler
   * @return The deployment descriptor
   * @throws Exception Failed to generate the BPEL deployment descriptor
   */
  public static org.w3c.dom.Document generateDeploymentDescriptor(
      ProtocolModel model,
      Role role,
      ProtocolModel localcm,
      TProcess bpelProcess,
      java.util.Collection<javax.wsdl.Definition> wsdls,
      org.w3c.dom.Element partnerLinkTypes,
      FeedbackHandler journal)
      throws Exception {

    org.w3c.dom.Document doc =
        javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();

    org.w3c.dom.Element defn = doc.createElementNS(APACHE_ODE_NAMESPACE, DEPLOY_LABEL);
    doc.appendChild(defn);

    java.util.Map<String, String> nsMap = new java.util.HashMap<String, String>();

    // Create process element
    org.w3c.dom.Element proc = doc.createElement(PROCESS_LABEL);
    defn.appendChild(proc);

    String name = bpelProcess.getName();

    if (bpelProcess.getTargetNamespace() != null) {
      String prefix = XMLUtils.getPrefixForNamespace(bpelProcess.getTargetNamespace(), nsMap);

      name = prefix + ":" + name;
    }

    proc.setAttribute(NAME_LABEL, name);

    org.w3c.dom.Element active = doc.createElement(ACTIVE_LABEL);
    proc.appendChild(active);

    org.w3c.dom.Text activeText = doc.createTextNode(Boolean.TRUE.toString());
    active.appendChild(activeText);

    org.w3c.dom.Element processEvents = doc.createElement(PROCESS_EVENTS_LABEL);
    processEvents.setAttribute("generate", "all");
    proc.appendChild(processEvents);

    // TODO: Need more info - possibly Contract should have interfaces based on
    // the relationship between two roles, as this may provide the necessary
    // information - but this requires the ability to have multiple interfaces
    // per role, which some other parts of the BPEL generation would currently
    // not handle.

    // Work through partner links for now
    for (TPartnerLink pl : bpelProcess.getPartnerLinks().getPartnerLink()) {
      if (pl.getMyRole() != null && pl.getMyRole().trim().length() > 0) {
        org.w3c.dom.Element provide = doc.createElement(PROVIDE_LABEL);

        provide.setAttribute(PARTNER_LINK_LABEL, XMLUtils.getLocalname(pl.getName()));

        org.w3c.dom.Element service = doc.createElement(SERVICE_LABEL);

        // Find service for partner link
        initializeService(service, bpelProcess, pl, wsdls, partnerLinkTypes, nsMap);

        provide.appendChild(service);

        proc.appendChild(provide);
      }
    }

    for (TPartnerLink pl : bpelProcess.getPartnerLinks().getPartnerLink()) {
      if (pl.getPartnerRole() != null && pl.getPartnerRole().trim().length() > 0) {
        org.w3c.dom.Element invoke = doc.createElement(INVOKE_LABEL);

        invoke.setAttribute(PARTNER_LINK_LABEL, XMLUtils.getLocalname(pl.getName()));
        invoke.setAttribute(USE_PEER2_PEER, Boolean.FALSE.toString());

        org.w3c.dom.Element service = doc.createElement(SERVICE_LABEL);

        // Find service for partner link
        initializeService(service, bpelProcess, pl, wsdls, partnerLinkTypes, nsMap);

        invoke.appendChild(service);

        proc.appendChild(invoke);
      }
    }

    // Create remaining namespace/prefix mappings
    java.util.Iterator<String> iter = nsMap.keySet().iterator();
    while (iter.hasNext()) {
      String ns = iter.next();
      String prefix = nsMap.get(ns);

      defn.setAttribute(XMLNS_PREFIX + prefix, ns);
    }

    return (doc);
  }