Package org.xmlpull.infoset

Examples of org.xmlpull.infoset.XmlElement


   */
  public XmlElement toXML() {
    // This must be before graph.toXML() to set WSDL ID to each node.
    Map<String, WsdlDefinitions> wsdls = getWSDLs();

    XmlElement workflowElement = XMLUtil.BUILDER.newFragment(NS_XWF,
        WORKFLOW_TAG);

    // Version
    workflowElement.setAttributeValue(NS_XWF, VERSION_ATTRIBUTE,
        XBayaVersion.VERSION);

    // Date
    // TODO add modification time
    // XmlElement modifiedTimeElement = graphElement.addElement(
    // XgraphSchema.NS, "modifiedTime");
    // modifiedTimeElement.addChild(new GregorianCalendar().toString());

    // Graph
    workflowElement.addElement(this.graph.toXML());

    // WSDLs
    XmlElement wsdlsElement = workflowElement.addElement(NS_XWF, WSDLS_TAG);
    for (String id : wsdls.keySet()) {
      WsdlDefinitions wsdl = wsdls.get(id);
      XmlElement wsdlElement = wsdlsElement.addElement(NS_XWF, WSDL_TAG);
      wsdlElement.setAttributeValue(NS_XWF, ID_ATTRIBUTE, id);
      wsdlElement.setText(XMLUtil.xmlElementToString(wsdl.xml()));
    }

    // Image
    if (this.image != null) {
      try {
        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        ImageIO.write(this.image, XBayaConstants.PNG_FORMAT_NAME,
            outStream);
        byte[] bytes = outStream.toByteArray();
        byte[] base64 = Base64.encodeBase64Chunked(bytes);

        XmlElement imageElement = workflowElement.addElement(NS_XWF,
            IMAGE_TAG);
        imageElement.setText(new String(base64));
      } catch (IOException e) {
        // No image
        logger.caught(e);
      }
    }

    // BPEL
    if (this.gpelProcess != null) {
      XmlElement bpelElement = workflowElement.addElement(NS_XWF,
          BPEL_TAG);
      bpelElement.setText(this.gpelProcess.xmlStringPretty());
    }

    // Workflow WSDL
    if (this.workflowWSDL != null) {
      XmlElement workflowWSDLElement = workflowElement.addElement(NS_XWF,
          WORKFLOW_WSDL_TAG);
      workflowWSDLElement.setText(this.workflowWSDL.xmlStringPretty());
    }

    return workflowElement;
  }
View Full Code Here


  /**
   * @see java.lang.Object#clone()
   */
  @Override
  public Workflow clone() {
    XmlElement originalXML = toXML();
    XmlElement newXML = XMLUtil.deepClone(originalXML);
    try {
      Workflow newWorkflow = new Workflow(newXML);
      return newWorkflow;
    } catch (GraphException e) {
      // This should not happen.
View Full Code Here

   * @throws ComponentException
   */
  private void parse(XmlElement workflowElement) throws GraphException,
      ComponentException {
    // Graph
    XmlElement graphElement = workflowElement
        .element(GraphSchema.GRAPH_TAG);
    this.graph = WSGraphFactory.createGraph(graphElement);

    XmlElement wsdlsElement = workflowElement.element(WSDLS_TAG);
    for (XmlElement wsdlElement : wsdlsElement.elements(null, WSDL_TAG)) {
      String wsdlText = wsdlElement.requiredText();
      WsdlDefinitions wsdl = WSDLUtil.stringToWSDL(wsdlText);
      String id = wsdlElement.attributeValue(NS_XWF, ID_ATTRIBUTE);
      if (id == null || id.length() == 0) {
        // xwf up to 2.2.6_2 doesn't have ID.
        id = WSDLUtil.getWSDLQName(wsdl).toString();
      }
      addWSDL(id, wsdl);
    }

    bindComponents();

    // Image
    XmlElement imageElement = workflowElement.element(IMAGE_TAG);
    if (imageElement != null) {
      String base64 = imageElement.requiredText();
      byte[] bytes = Base64.decodeBase64(base64.getBytes());
      try {
        this.image = ImageIO.read(new ByteArrayInputStream(bytes));
      } catch (IOException e) {
        // This should not happen and it's OK that image is broken. We
        // can reproduce it anytime.
        logger.caught(e);
      }
    }

    XmlElement bpelElement = workflowElement.element(BPEL_TAG);
    if (bpelElement != null) {
      try {
        String bpelString = bpelElement.requiredText();
        XmlNamespace gpelNS = XmlInfosetBuilder.newInstance()
            .newNamespace(BPELScript.GPEL, BPELScript.GPELNS);
        GpelConstants.GPEL_NS = gpelNS;
        this.gpelProcess = new GpelProcess(
            XMLUtil.stringToXmlElement(bpelString));
      } catch (RuntimeException e) {
        String error = "Failed to parse the BPEL document.";
        throw new GraphException(error, e);
      }
    }

    XmlElement workflowWSDLElement = workflowElement
        .element(WORKFLOW_WSDL_TAG);
    if (workflowWSDLElement != null) {
      try {
        String wsdlText = workflowWSDLElement.requiredText();
        this.workflowWSDL = new WsdlDefinitions(
            XMLUtil.stringToXmlElement(wsdlText));
      } catch (RuntimeException e) {
        String error = "Failed to parse the workflow WSDL.";
        throw new GraphException(error, e);
View Full Code Here

            }

            // check if it's WSComponent or WorkflowComponent
            WsdlPortType portType = wsdl.getPortType(portTypeQName
                    .getLocalPart());
            XmlElement templateIDElement = portType.xml().element(
                    WorkflowComponent.GPEL_NAMESPACE,
                    WorkflowComponent.WORKFLOW_TEMPLATE_ID_TAG);
            WSComponent component;
            if (templateIDElement == null) {
                component = new WSComponent(wsdl, portTypeQName, operationName);
View Full Code Here

     * Parses XML
     *
     * @param portElement
     */
    protected void parse(XmlElement portElement) {
        XmlElement idElement = portElement.element(GraphSchema.PORT_ID_TAG);
        this.id = idElement.requiredText();

        XmlElement nameElement = portElement.element(GraphSchema.PORT_NAME_TAG);
        if (nameElement != null) {
            // TODO control ports might have name?
            this.name = nameElement.requiredText();
        }

        XmlElement nodeElement = portElement.element(GraphSchema.PORT_NODE_TAG);
        this.nodeID = nodeElement.requiredText();
    }
View Full Code Here

        return element;
    }

    private XmlElement addParameter(Node node, SystemDataPort port,
            XmlElement sequence, XmlElement schema) {
        XmlElement element = sequence.addElement(WSConstants.ELEMENT_TAG);
        element.setAttributeValue(WSConstants.NAME_ATTRIBUTE, node.getID());

        //
        // type
        //
        QName type = port.getType();
        WSComponentPort componentPort = port.getWSComponentPort();
        WsdlDefinitions wsdl = null;
        if (componentPort != null) {
            wsdl = componentPort.getComponent().getWSDL();
            type = declareTypeIfNecessary(wsdl, type);
        }
        int arrayDimension = port.getArrayDimension();
        if (arrayDimension == 1) {
            String typeName = declareArrayType(schema, type, wsdl);
            type = new QName(this.typesNamespace.getName(), typeName);
        } else if (arrayDimension > 1) {
            // TODO
            throw new XBayaRuntimeException(
                    "multi-dimentional arrays are not supported yet.");
        }

        if (WSConstants.XSD_ANY_TYPE.equals(type) && componentPort != null) {
            XmlElement elementElement = componentPort.getElement();
            if (elementElement == null) {
                // Types are not defined anywhare. Leave it as xsd:any.
                setTypeAttribute(element, type);
            } else {
                // Copy the embedded type defition.
                XmlElement clonedElementElement = XMLUtil
                        .deepClone(elementElement);
                String typeString = clonedElementElement
                        .attributeValue(WSConstants.TYPE_ATTRIBUTE);
                if (typeString == null) {
                    for (Object child : clonedElementElement.children()) {
                        if (child instanceof XmlElement) {
                            ((XmlElement) child).setParent(null);
                        }
                        element.addChild(child);
                    }
View Full Code Here

            return new QName(WSConstants.XSD_NS_URI, paramType.getLocalPart(),
                    WSConstants.XSD_NS_PREFIX);
        }

        // check if this type already exists in the workflow WSDL.
        XmlElement typeDefinition = WSDLUtil.getTypeDefinition(
                this.definitions, paramType);
       
       
       
       
       
       
        if (typeDefinition == null) {
         
          //now lets check whether there is an import in the service wsdl schema
            //that would import this type,
            //if so we would be done by just importing that schema
         
          typeDefinition = WSDLUtil.findTypeDefinitionInImports(serviceWSDL, paramType);
          if(typeDefinition != null){
            XmlElement importEle = WSDLUtil.getImportContainingTypeDefinition(serviceWSDL, paramType);
            addImportIfNecessary(importEle);
            String prefix = declareNamespaceIfNecessary(paramType.getPrefix(),
                        paramType.getNamespaceURI(), false);
            return new QName(paramType.getNamespaceURI(), paramType.getLocalPart(), prefix);
          }
         
         
         
         
            // copy the type defition and use it.

            // Need to copy the whole schema because it might have different
            // targetNamespace.
            XmlElement newSchema = WSDLUtil.getSchema(serviceWSDL, paramType);
            if (newSchema == null) {
                // This should have been caught in WSComponent
                throw new XBayaRuntimeException(
                        "could not find definition for type " + paramType
                                + " in " + WSDLUtil.getWSDLQName(serviceWSDL));
View Full Code Here

                    .getLocalPart(), namespace.getPrefix());
        }
    }

  private void addImportIfNecessary(XmlElement importEle) {
    XmlElement schema = this.definitions.getTypes().element(WSConstants.SCHEMA_TAG);
    Iterable<XmlElement> imports = schema.elements(null, WSConstants.IMPORT_TAG);
    for (XmlElement importElement : imports) {
      if(importElement.attributeValue("namespace").equals(importEle.attributeValue("namespace")) &&
          importElement.attributeValue("schemaLocation").equals(importEle.attributeValue("schemaLocation"))){
        return;
      }
    }
    schema.addChild(0, importEle);
  }
View Full Code Here

    /**
     * @return the XML representation of this Port
     */
    protected XmlElement toXML() {
        XmlElement portElement = XMLUtil.BUILDER.newFragment(GraphSchema.NS,
                GraphSchema.PORT_TAG);

        XmlElement idElement = portElement.addElement(GraphSchema.NS,
                GraphSchema.PORT_ID_TAG);
        idElement.addChild(getID());

        if (this.name != null) {
            // TODO control ports might have name?
            XmlElement nameElement = portElement.addElement(GraphSchema.NS,
                    GraphSchema.PORT_NAME_TAG);
            nameElement.addChild(this.name);
        }

        XmlElement nodeElement = portElement.addElement(GraphSchema.NS,
                GraphSchema.PORT_NODE_TAG);
        nodeElement.addChild(this.node.getID());

        return portElement;
    }
View Full Code Here

    schema.addChild(0, importEle);
  }

    private String declareArrayType(XmlElement schema, QName valueType,
            WsdlDefinitions serviceWSDL) {
        XmlElement complexType = schema
                .addElement(WSConstants.COMPLEX_TYPE_TAG);
        String typeName = valueType.getLocalPart() + "ArrayType";
        // TODO check if this typeName is already used.
        complexType.setAttributeValue(WSConstants.NAME_ATTRIBUTE, typeName);
        XmlElement sequence = complexType.addElement(WSConstants.SEQUENCE_TAG);
        XmlElement element = sequence.addElement(WSConstants.ELEMENT_TAG);
        element.setAttributeValue(WSConstants.MIN_OCCURS_ATTRIBUTE, "0");
        element.setAttributeValue(WSConstants.MAX_OCCURS_ATTRIBUTE,
                WSConstants.UNBOUNDED_VALUE);
        element.setAttributeValue(WSConstants.NAME_ATTRIBUTE, "value");
        valueType = declareTypeIfNecessary(serviceWSDL, valueType);
        element.setAttributeValue(WSConstants.TYPE_ATTRIBUTE, valueType
                .getPrefix()
                + ":" + valueType.getLocalPart());
        return typeName;
    }
View Full Code Here

TOP

Related Classes of org.xmlpull.infoset.XmlElement

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.