KickJava   Java API By Example, From Geeks To Geeks.

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


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

6
7 package org.enhydra.shark.wfxml;
8
9 import java.io.StringWriter JavaDoc;
10 import java.net.URLEncoder JavaDoc;
11 import java.rmi.RemoteException JavaDoc;
12 import java.util.Arrays JavaDoc;
13 import java.util.Iterator JavaDoc;
14
15 import javax.xml.transform.Transformer JavaDoc;
16 import javax.xml.transform.TransformerFactory JavaDoc;
17 import javax.xml.transform.dom.DOMSource JavaDoc;
18 import javax.xml.transform.stream.StreamResult JavaDoc;
19
20 import org.apache.axis.MessageContext;
21 import org.apache.axis.message.MessageElement;
22 import org.apache.axis.types.URI;
23 import org.enhydra.shark.api.client.wfmodel.WfProcessMgr;
24 import org.enhydra.shark.asap.AsapBindingUtilitiesImpl;
25 import org.enhydra.shark.asap.types.*;
26 import org.enhydra.shark.asap.types.holders.ResponseHolder;
27 import org.enhydra.shark.wfxml.types.*;
28 import org.enhydra.shark.wfxml.types.GetPropertiesRs;
29 import org.enhydra.shark.wfxml.types.SetPropertiesRq;
30 import org.enhydra.shark.wfxml.types.holders.*;
31 import org.w3c.dom.Document JavaDoc;
32
33 /**
34  * Wf-XML registry service implementation
35  *
36  * @author V.Puskas, S.Bojanic
37  * @version 0.11
38  */

39 public class WfXmlRegistryBindingImpl implements
40                                      org.enhydra.shark.wfxml.RegistryPortType {
41    public void getProperties(Request rqHead,
42                              String JavaDoc rqBody,
43                              ResponseHolder rsHead,
44                              GetPropertiesRsHolder rsBody) throws java.rmi.RemoteException JavaDoc {
45       URI rqReceiverKey = AsapBindingUtilitiesImpl.turnHeads(rqHead,
46                                                              rsHead);
47       rsBody.value = new GetPropertiesRs();
48       
49       Iterator JavaDoc it =MessageContext.getCurrentContext().getRequestMessage().getMimeHeaders().getAllHeaders();
50          //MessageContext.getCurrentContext().getPropertyNames();
51
System.err.println("##:--");
52       while (it.hasNext()) {
53          System.err.println("##:"+((javax.xml.soap.MimeHeader JavaDoc)it.next()).getName());
54       }
55       System.err.println("##:--");
56       System.err.println(Arrays.asList(MessageContext.getCurrentContext().getRequestMessage().getMimeHeaders().getHeader("User-Agent")));
57       rsBody.value.setRegistryPropertiesGroup(new RegistryPropertiesGroup());
58       rsBody.value.getRegistryPropertiesGroup()
59          .setKey(rqHead.getReceiverKey());
60       rsBody.value.getRegistryPropertiesGroup().setName("Enhydra Shark");
61    }
62
63    public void setProperties(Request rqHead,
64                              SetPropertiesRq rqBody,
65                              ResponseHolder rsHead,
66                              SetPropertiesRsHolder rsBody) throws java.rmi.RemoteException JavaDoc {
67       URI rqReceiverKey = AsapBindingUtilitiesImpl.turnHeads(rqHead,
68                                                              rsHead);
69       rsBody.value = new org.enhydra.shark.wfxml.types.SetPropertiesRs();
70
71       rsBody.value.setRegistryPropertiesGroup(new RegistryPropertiesGroup());
72       rsBody.value.getRegistryPropertiesGroup()
73          .setKey(rqHead.getReceiverKey());
74       rsBody.value.getRegistryPropertiesGroup().setName("Enhydra Shark");
75    }
76
77    public void listDefinitions(Request rqHead,
78                                ListDefinitionsRq rqBody,
79                                ResponseHolder rsHead,
80                                ListDefinitionsRsHolder rsBody) throws java.rmi.RemoteException JavaDoc {
81       URI rqReceiverKey = AsapBindingUtilitiesImpl.turnHeads(rqHead,
82                                                              rsHead);
83       rsBody.value = new ListDefinitionsRs();
84
85       try {
86          WfProcessMgr p[] = SharkServiceImpl.getExecAdmin()
87             .get_iterator_processmgr()
88             .get_next_n_sequence(0);
89          DefinitionInfo[] di = new DefinitionInfo[p.length];
90          for (int i = 0; i < p.length; ++i) {
91             di[i] = new DefinitionInfo(createFactoryKey(p[i].name()),
92                                        SharkServiceImpl.getAdminMiscUtilities()
93                                           .getProcessMgrProcDefName(p[i].name()),
94                                        p[i].description(),
95                                        p[i].version(),
96                                        String.valueOf(p[i].process_mgr_state()
97                                           .value()));
98          }
99          rsBody.value.setDefinitionInfo(di);
100       } catch (Exception JavaDoc ex) {
101          ex.printStackTrace();
102          throw new RemoteException JavaDoc(ex.getMessage());
103       }
104    }
105
106    public void newDefinition(Request rqHead,
107                              NewDefinitionRq rqBody,
108                              ResponseHolder rsHead,
109                              NewDefinitionRsHolder rsBody) throws java.rmi.RemoteException JavaDoc {
110       URI rqReceiverKey = AsapBindingUtilitiesImpl.turnHeads(rqHead,
111                                                              rsHead);
112       rsBody.value = new NewDefinitionRs(rqBody.getDefinition().get_any());
113
114       if (!"XPDL".equals(rqBody.getProcessLanguage())) { throw new RemoteException JavaDoc("Allowed value for process language is XPDL only!"); }
115       try {
116          MessageElement m = rqBody.getDefinition().get_any()[0];
117          String JavaDoc pkgId = m.getAttribute("Id");
118          String JavaDoc relPath = "wfxml/"+ System.currentTimeMillis() +".xpdl";
119          Document JavaDoc document = m.getAsDocument();
120          // Use a Transformer for output
121
DOMSource JavaDoc source = new DOMSource JavaDoc(document);
122          StringWriter JavaDoc sw = new StringWriter JavaDoc();
123          StreamResult JavaDoc result = new StreamResult JavaDoc(sw);
124          Transformer JavaDoc transformer = TransformerFactory.newInstance()
125             .newTransformer();
126          transformer.transform(source, result);
127          byte[] bytes = sw.toString().getBytes("UTF8");
128          // try {
129
// SharkServiceImpl.getRepositoryMgr().deletePackage(relPath);
130
// } catch (Exception _) {}
131
// SharkServiceImpl.getRepositoryMgr().uploadPackage(bytes,
132
// relPath);
133
// if (SharkServiceImpl.getPackageAdministration()
134
// .isPackageOpened(pkgId)) {
135
// SharkServiceImpl.getPackageAdministration()
136
// .updatePackage(pkgId, relPath);
137
// } else {
138
// SharkServiceImpl.getPackageAdministration().openPackage(relPath);
139
// }
140
SharkServiceImpl.getRepositoryMgr().uploadPackage(bytes, relPath);
141          SharkServiceImpl.getPackageAdministration().openPackage(relPath);
142       } catch (Exception JavaDoc ex) {
143          ex.printStackTrace();
144          throw new RemoteException JavaDoc(ex.getMessage());
145       }
146    }
147
148    private static URI createFactoryKey(String JavaDoc string) throws Exception JavaDoc {
149       URI factoryURI = new URI(new SharkWebServiceLocator().getwfxmlFactoryBindingAddress());
150       //factoryURI.setHost(SharkServiceImpl.getMyAddress());
151
AsapBindingUtilitiesImpl.imprintURI(factoryURI);
152       factoryURI.setQueryString(SharkServiceImpl.QSPN_PROCESS_MANAGER
153                                    + URLEncoder.encode(string, "UTF-8"));
154       return factoryURI;
155    }
156 }
Popular Tags