KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > wfxml > WfXmlFactoryBindingImpl


1 /**
2  * WfXmlFactoryBindingImpl.java
3  *
4  * This file was auto-generated from WSDL
5  * by the Apache Axis 1.2RC2 Nov 16, 2004 (12:19:44 EST) WSDL2Java emitter.
6  */

7
8 package org.enhydra.shark.wfxml;
9
10 import java.io.ByteArrayInputStream JavaDoc;
11 import java.io.StringWriter JavaDoc;
12 import java.rmi.RemoteException JavaDoc;
13
14 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
15 import javax.xml.soap.SOAPException JavaDoc;
16 import javax.xml.transform.Transformer JavaDoc;
17 import javax.xml.transform.TransformerFactory JavaDoc;
18 import javax.xml.transform.dom.DOMSource JavaDoc;
19 import javax.xml.transform.stream.StreamResult JavaDoc;
20
21 import org.apache.axis.message.MessageElement;
22 import org.apache.axis.types.URI;
23 import org.enhydra.shark.Shark;
24 import org.enhydra.shark.asap.AsapBindingUtilitiesImpl;
25 import org.enhydra.shark.asap.AsapFactoryBindingImpl;
26 import org.enhydra.shark.asap.types.*;
27 import org.enhydra.shark.asap.types.holders.ResponseHolder;
28 import org.enhydra.shark.wfxml.types.*;
29 import org.enhydra.shark.wfxml.types.holders.GetDefinitionRsHolder;
30 import org.enhydra.shark.wfxml.types.holders.SetDefinitionRsHolder;
31 import org.w3c.dom.*;
32 import org.w3c.dom.CharacterData JavaDoc;
33
34 /**
35  * Wf-XML factory implementation
36  *
37  * @author V.Puskas, S.Bojanic
38  * @version 0.21
39  */

40 public class WfXmlFactoryBindingImpl extends AsapFactoryBindingImpl implements
41                                     org.enhydra.shark.wfxml.FactoryPortType {
42
43    public void getDefinition(Request rqHead,
44                              GetDefinitionRq rqBody,
45                              ResponseHolder rsHead,
46                              GetDefinitionRsHolder rsBody) throws java.rmi.RemoteException JavaDoc {
47       URI rqReceiverKey = AsapBindingUtilitiesImpl.turnHeads(rqHead,
48                                                              rsHead);
49       rsBody.value = new GetDefinitionRs();
50
51       try {
52          byte[] a = Shark.getInstance()
53             .getAdminInterface()
54             .getPackageAdministration()
55             .getPackageContent(SharkServiceImpl.getAdminMiscUtilities()
56                .getProcessMgrPkgId(AsapBindingUtilitiesImpl.parseFactoryReceiverKey(rqReceiverKey)));
57
58          Document b = DocumentBuilderFactory.newInstance()
59             .newDocumentBuilder()
60             .parse(new ByteArrayInputStream JavaDoc(a));
61          MessageElement main = convertToMessageElement(b.getFirstChild());
62          rsBody.value.set_any(new MessageElement[] {
63             main
64          });
65
66       } catch (Exception JavaDoc ex) {
67          ex.printStackTrace();
68          throw new RemoteException JavaDoc(ex.getMessage());
69       }
70    }
71
72    private MessageElement convertToMessageElement(Node node) throws SOAPException JavaDoc {
73       if (Node.TEXT_NODE == node.getNodeType()) { return new MessageElement((CharacterData JavaDoc) node); }
74       MessageElement ret = new MessageElement(node.getNodeName(),
75                                               "xpdl",
76                                               "http://www.wfmc.org/2002/XPDL1.0");
77       NamedNodeMap atts = node.getAttributes();
78       if (null != atts) {
79          for (int i = 0; i < atts.getLength(); ++i) {
80             Node att = atts.item(i);
81             ret.addAttribute("", att.getNodeName(), att.getNodeValue());
82          }
83       }
84       NodeList children = node.getChildNodes();
85       if (null != children) {
86          for (int i = 0; i < children.getLength(); ++i) {
87             MessageElement r = convertToMessageElement(children.item(i));
88             if (null != r) {
89                ret.addChild(r);
90             }
91          }
92       }
93       return ret;
94    }
95
96    public void setDefinition(Request rqHead,
97                              SetDefinitionRq rqBody,
98                              ResponseHolder rsHead,
99                              SetDefinitionRsHolder rsBody) throws java.rmi.RemoteException JavaDoc {
100       URI rqReceiverKey = AsapBindingUtilitiesImpl.turnHeads(rqHead,
101                                                              rsHead);
102       rsBody.value = new SetDefinitionRs(rqBody.getDefinition().get_any());
103
104       if (!"XPDL".equals(rqBody.getProcessLanguage())) { throw new RemoteException JavaDoc("Allowed value for process language is XPDL only!"); }
105       MessageElement m = rqBody.getDefinition().get_any()[0];
106       String JavaDoc pkgId = m.getAttribute("Id");
107       try {
108          System.err.println("NAmiruSVI"
109                             + AsapBindingUtilitiesImpl.parseFactoryReceiverKey(rqReceiverKey));
110          System.err.println("NAmiruSVI" + pkgId);
111          if (!AsapBindingUtilitiesImpl.parseFactoryReceiverKey(rqReceiverKey)
112             .startsWith(pkgId)) { throw new RemoteException JavaDoc("Package Ids don't match, cannot continue."); }
113          String JavaDoc relPath = "wfxml/"+ System.currentTimeMillis() +".xpdl";
114          Document document = m.getAsDocument();
115
116          DOMSource JavaDoc source = new DOMSource JavaDoc(document);
117          StringWriter JavaDoc sw = new StringWriter JavaDoc();
118          StreamResult JavaDoc result = new StreamResult JavaDoc(sw);
119          Transformer JavaDoc transformer = TransformerFactory.newInstance()
120             .newTransformer();
121          transformer.transform(source, result);
122          byte[] bytes = sw.toString().getBytes("UTF8");
123          try {
124             SharkServiceImpl.getRepositoryMgr().deletePackage(relPath);
125          } catch (Exception JavaDoc _) {}
126          SharkServiceImpl.getRepositoryMgr().uploadPackage(bytes, relPath);
127          if (SharkServiceImpl.getPackageAdministration()
128             .isPackageOpened(pkgId)) {
129             SharkServiceImpl.getPackageAdministration()
130                .updatePackage(pkgId, relPath);
131          } else {
132             SharkServiceImpl.getPackageAdministration().openPackage(relPath);
133          }
134       } catch (Exception JavaDoc ex) {
135          ex.printStackTrace();
136          throw new RemoteException JavaDoc(ex.getMessage());
137       }
138    }
139 }
140
141
Popular Tags