1 16 package org.apache.juddi.handler; 17 18 import java.util.Vector ; 19 20 import org.apache.juddi.datatype.Description; 21 import org.apache.juddi.datatype.Name; 22 import org.apache.juddi.datatype.RegistryObject; 23 import org.apache.juddi.datatype.response.BusinessInfo; 24 import org.apache.juddi.datatype.response.ServiceInfos; 25 import org.apache.juddi.util.xml.XMLUtils; 26 import org.w3c.dom.Element ; 27 28 34 public class BusinessInfoHandler extends AbstractHandler 35 { 36 public static final String TAG_NAME = "businessInfo"; 37 38 private HandlerMaker maker = null; 39 40 protected BusinessInfoHandler(HandlerMaker maker) 41 { 42 this.maker = maker; 43 } 44 45 public RegistryObject unmarshal(Element element) 46 { 47 BusinessInfo obj = new BusinessInfo(); 48 Vector nodeList = null; 49 AbstractHandler handler = null; 50 51 obj.setBusinessKey(element.getAttribute("businessKey")); 53 54 57 nodeList = XMLUtils.getChildElementsByTagName(element,NameHandler.TAG_NAME); 59 for (int i=0; i<nodeList.size(); i++) 60 { 61 handler = maker.lookup(NameHandler.TAG_NAME); 62 Name name = (Name )handler.unmarshal((Element )nodeList.elementAt(i)); 63 if (name != null) 64 obj.addName(name); 65 } 66 67 nodeList = XMLUtils.getChildElementsByTagName(element,DescriptionHandler.TAG_NAME); 68 for (int i=0; i<nodeList.size(); i++) 69 { 70 handler = maker.lookup(DescriptionHandler.TAG_NAME); 71 Description descr = (Description)handler.unmarshal((Element )nodeList.elementAt(i)); 72 if (descr != null) 73 obj.addDescription(descr); 74 } 75 76 nodeList = XMLUtils.getChildElementsByTagName(element,ServiceInfosHandler.TAG_NAME); 77 if (nodeList.size() > 0) 78 { 79 handler = maker.lookup(ServiceInfosHandler.TAG_NAME); 80 obj.setServiceInfos((ServiceInfos)handler.unmarshal((Element )nodeList.elementAt(0))); 81 } 82 83 return obj; 84 } 85 86 public void marshal(RegistryObject object,Element parent) 87 { 88 BusinessInfo info = (BusinessInfo)object; 89 Element element = parent.getOwnerDocument().createElementNS(null,TAG_NAME); 90 AbstractHandler handler = null; 91 92 String businessKey = info.getBusinessKey(); 93 if (businessKey != null) 94 element.setAttribute("businessKey",businessKey); 95 96 Vector nameVector = info.getNameVector(); 97 if ((nameVector!=null) && (nameVector.size() > 0)) 98 { 99 handler = maker.lookup(NameHandler.TAG_NAME); 100 for (int i=0; i < nameVector.size(); i++) 101 handler.marshal((org.apache.juddi.datatype.Name)nameVector.elementAt(i),element); 102 } 103 104 Vector descVector = info.getDescriptionVector(); 105 if ((descVector!=null) && (descVector.size() > 0)) 106 { 107 handler = maker.lookup(DescriptionHandler.TAG_NAME); 108 for (int i=0; i < descVector.size(); i++) 109 handler.marshal((Description)descVector.elementAt(i),element); 110 } 111 112 ServiceInfos infos = info.getServiceInfos(); 113 if (infos != null) 114 { 115 handler = maker.lookup(ServiceInfosHandler.TAG_NAME); 116 handler.marshal(infos,element); 117 } 118 119 parent.appendChild(element); 120 } 121 122 123 124 125 126 127 128 public static void main(String args[]) 129 throws Exception 130 { 131 } 132 } | Popular Tags |