1 7 8 package org.enhydra.shark.wfxml; 9 10 import java.io.ByteArrayInputStream ; 11 import java.io.StringWriter ; 12 import java.rmi.RemoteException ; 13 14 import javax.xml.parsers.DocumentBuilderFactory ; 15 import javax.xml.soap.SOAPException ; 16 import javax.xml.transform.Transformer ; 17 import javax.xml.transform.TransformerFactory ; 18 import javax.xml.transform.dom.DOMSource ; 19 import javax.xml.transform.stream.StreamResult ; 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 ; 33 34 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 { 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 (a)); 61 MessageElement main = convertToMessageElement(b.getFirstChild()); 62 rsBody.value.set_any(new MessageElement[] { 63 main 64 }); 65 66 } catch (Exception ex) { 67 ex.printStackTrace(); 68 throw new RemoteException (ex.getMessage()); 69 } 70 } 71 72 private MessageElement convertToMessageElement(Node node) throws SOAPException { 73 if (Node.TEXT_NODE == node.getNodeType()) { return new MessageElement((CharacterData ) 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 { 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 ("Allowed value for process language is XPDL only!"); } 105 MessageElement m = rqBody.getDefinition().get_any()[0]; 106 String 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 ("Package Ids don't match, cannot continue."); } 113 String relPath = "wfxml/"+ System.currentTimeMillis() +".xpdl"; 114 Document document = m.getAsDocument(); 115 116 DOMSource source = new DOMSource (document); 117 StringWriter sw = new StringWriter (); 118 StreamResult result = new StreamResult (sw); 119 Transformer 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 _) {} 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 ex) { 135 ex.printStackTrace(); 136 throw new RemoteException (ex.getMessage()); 137 } 138 } 139 } 140 141 | Popular Tags |