1 6 7 package org.enhydra.shark.wfxml; 8 9 import java.io.StringWriter ; 10 import java.net.URLEncoder ; 11 import java.rmi.RemoteException ; 12 import java.util.Arrays ; 13 import java.util.Iterator ; 14 15 import javax.xml.transform.Transformer ; 16 import javax.xml.transform.TransformerFactory ; 17 import javax.xml.transform.dom.DOMSource ; 18 import javax.xml.transform.stream.StreamResult ; 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 ; 32 33 39 public class WfXmlRegistryBindingImpl implements 40 org.enhydra.shark.wfxml.RegistryPortType { 41 public void getProperties(Request rqHead, 42 String rqBody, 43 ResponseHolder rsHead, 44 GetPropertiesRsHolder rsBody) throws java.rmi.RemoteException { 45 URI rqReceiverKey = AsapBindingUtilitiesImpl.turnHeads(rqHead, 46 rsHead); 47 rsBody.value = new GetPropertiesRs(); 48 49 Iterator it =MessageContext.getCurrentContext().getRequestMessage().getMimeHeaders().getAllHeaders(); 50 System.err.println("##:--"); 52 while (it.hasNext()) { 53 System.err.println("##:"+((javax.xml.soap.MimeHeader )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 { 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 { 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 ex) { 101 ex.printStackTrace(); 102 throw new RemoteException (ex.getMessage()); 103 } 104 } 105 106 public void newDefinition(Request rqHead, 107 NewDefinitionRq rqBody, 108 ResponseHolder rsHead, 109 NewDefinitionRsHolder rsBody) throws java.rmi.RemoteException { 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 ("Allowed value for process language is XPDL only!"); } 115 try { 116 MessageElement m = rqBody.getDefinition().get_any()[0]; 117 String pkgId = m.getAttribute("Id"); 118 String relPath = "wfxml/"+ System.currentTimeMillis() +".xpdl"; 119 Document document = m.getAsDocument(); 120 DOMSource source = new DOMSource (document); 122 StringWriter sw = new StringWriter (); 123 StreamResult result = new StreamResult (sw); 124 Transformer transformer = TransformerFactory.newInstance() 125 .newTransformer(); 126 transformer.transform(source, result); 127 byte[] bytes = sw.toString().getBytes("UTF8"); 128 SharkServiceImpl.getRepositoryMgr().uploadPackage(bytes, relPath); 141 SharkServiceImpl.getPackageAdministration().openPackage(relPath); 142 } catch (Exception ex) { 143 ex.printStackTrace(); 144 throw new RemoteException (ex.getMessage()); 145 } 146 } 147 148 private static URI createFactoryKey(String string) throws Exception { 149 URI factoryURI = new URI(new SharkWebServiceLocator().getwfxmlFactoryBindingAddress()); 150 AsapBindingUtilitiesImpl.imprintURI(factoryURI); 152 factoryURI.setQueryString(SharkServiceImpl.QSPN_PROCESS_MANAGER 153 + URLEncoder.encode(string, "UTF-8")); 154 return factoryURI; 155 } 156 } | Popular Tags |