1 4 5 package com.sun.j2ee.blueprints.attachmentservice; 6 7 import java.net.*; 8 import java.rmi.*; 9 import java.util.*; 10 11 import javax.ejb.*; 12 import javax.xml.soap.*; 13 import javax.xml.transform.*; 14 import javax.xml.rpc.handler.*; 15 import javax.xml.transform.dom.*; 16 17 import org.w3c.dom.*; 18 import org.w3c.dom.Node ; 19 20 public class AttachmentPurchaseOrderServiceBean implements SessionBean { 21 22 private SessionContext sc; 23 private TransformerFactory transfactory; 24 25 public AttachmentPurchaseOrderServiceBean() {} 26 27 33 public java.net.URI submitPO(Source xmlsrc) throws InvalidPOException, RemoteException{ 34 URI uri = null; 35 String id = null; 36 try { 37 Transformer transformer = transfactory.newTransformer(); 38 DOMResult result = new DOMResult(); 39 transformer.transform(xmlsrc, result); 40 Document doc = (Document)result.getNode(); 41 Element root = doc.getDocumentElement(); 42 NodeList list = root.getElementsByTagName("poId"); 43 for (int loop = 0; loop < list.getLength(); loop++) { 44 Node node = list.item(loop); 45 if (node != null) { 46 Node child = node.getFirstChild(); 47 if ((child != null) && child.getNodeValue() != null) id = child.getNodeValue(); 48 } 49 } 50 MessageContext mc = sc.getMessageContext(); 51 AttachmentPart att = MessageFactory.newInstance().createMessage().createAttachmentPart(); 52 att.setContentId(" < "+ id + " >"); 53 att.setContent("<submitPO response/>","text/plain"); 54 ArrayList arrList = new ArrayList(); 55 arrList.add(att); 56 mc.setProperty("com.sun.xml.rpc.attachment.SetAttachmentContext", arrList); 58 uri = new java.net.URI ("cid:" + id); 59 } catch (Exception e) { 60 throw new EJBException("AttachmentPOService Having Problems:"+e.getMessage(), e); 61 } 62 if(id.equals("100")) 64 throw new InvalidPOException("Invalid ID for the purchase order!!! " + 65 "For demo purposes, we throw " + 66 "an application defined exception for the ID value of 100."); 67 return uri; 68 } 69 70 public void ejbCreate() throws CreateException { 72 transfactory = TransformerFactory.newInstance(); 73 } 74 75 public void setSessionContext(SessionContext sc) { 76 this.sc = sc; 77 } 78 79 public void ejbRemove() { 80 transfactory=null; 81 } 82 83 public void ejbActivate() {} 84 85 public void ejbPassivate() {} 86 } 87 88 89 90 | Popular Tags |