1 16 package org.apache.juddi.handler; 17 18 import java.util.Vector ; 19 20 import org.apache.juddi.datatype.BusinessKey; 21 import org.apache.juddi.datatype.Description; 22 import org.apache.juddi.datatype.KeyedReference; 23 import org.apache.juddi.datatype.Name; 24 import org.apache.juddi.datatype.RegistryObject; 25 import org.apache.juddi.datatype.SharedRelationships; 26 import org.apache.juddi.datatype.response.RelatedBusinessInfo; 27 import org.apache.juddi.util.xml.XMLUtils; 28 import org.w3c.dom.Element ; 29 30 33 public class RelatedBusinessInfoHandler extends AbstractHandler 34 { 35 public static final String TAG_NAME = "relatedBusinessInfo"; 36 37 private HandlerMaker maker = null; 38 39 protected RelatedBusinessInfoHandler(HandlerMaker maker) 40 { 41 this.maker = maker; 42 } 43 44 public RegistryObject unmarshal(Element element) 45 { 46 RelatedBusinessInfo obj = new RelatedBusinessInfo(); 47 Vector nodeList = null; 48 AbstractHandler handler = null; 49 50 53 56 nodeList = XMLUtils.getChildElementsByTagName(element,BusinessKeyHandler.TAG_NAME); 58 if (nodeList.size() > 0) 59 { 60 handler = maker.lookup(BusinessKeyHandler.TAG_NAME); 61 obj.setBusinessKey((BusinessKey)handler.unmarshal((Element )nodeList.elementAt(0))); 62 } 63 64 nodeList = XMLUtils.getChildElementsByTagName(element,NameHandler.TAG_NAME); 65 for (int i=0; i<nodeList.size(); i++) 66 { 67 handler = maker.lookup(NameHandler.TAG_NAME); 68 Name name = (Name )handler.unmarshal((Element )nodeList.elementAt(i)); 69 if (name != null) 70 obj.addName(name); 71 } 72 73 nodeList = XMLUtils.getChildElementsByTagName(element,DescriptionHandler.TAG_NAME); 74 for (int i=0; i<nodeList.size(); i++) 75 { 76 handler = maker.lookup(DescriptionHandler.TAG_NAME); 77 Description descr = (Description)handler.unmarshal((Element )nodeList.elementAt(i)); 78 if (descr != null) 79 obj.addDescription(descr); 80 } 81 82 nodeList = XMLUtils.getChildElementsByTagName(element,SharedRelationshipsHandler.TAG_NAME); 83 if (nodeList.size() > 0) 84 { 85 handler = maker.lookup(SharedRelationshipsHandler.TAG_NAME); 86 obj.setSharedRelationships((SharedRelationships)handler.unmarshal((Element )nodeList.elementAt(0))); 87 } 88 89 return obj; 90 } 91 92 95 public void marshal(RegistryObject object,Element parent) 96 { 97 RelatedBusinessInfo info = (RelatedBusinessInfo)object; 98 Element element = parent.getOwnerDocument().createElementNS(null,TAG_NAME); 99 AbstractHandler handler = null; 100 101 String businessKey = info.getBusinessKey(); 102 if (businessKey != null) 103 { 104 handler = maker.lookup(BusinessKeyHandler.TAG_NAME); 105 handler.marshal(new BusinessKey(businessKey),element); 106 } 107 108 Vector nameVector = info.getNameVector(); 109 if ((nameVector!=null) && (nameVector.size() > 0)) 110 { 111 handler = maker.lookup(NameHandler.TAG_NAME); 112 for (int i=0; i < nameVector.size(); i++) 113 handler.marshal((org.apache.juddi.datatype.Name)nameVector.elementAt(i),element); 114 } 115 116 Vector descVector = info.getDescriptionVector(); 117 if ((descVector!=null) && (descVector.size() > 0)) 118 { 119 handler = maker.lookup(DescriptionHandler.TAG_NAME); 120 for (int i=0; i < descVector.size(); i++) 121 handler.marshal((Description)descVector.elementAt(i),element); 122 } 123 124 SharedRelationships relationships = info.getSharedRelationships(); 125 if (relationships != null) 126 { 127 handler = maker.lookup(SharedRelationshipsHandler.TAG_NAME); 128 handler.marshal(relationships,element); 129 } 130 131 parent.appendChild(element); 132 } 133 134 135 136 137 138 139 140 public static void main(String args[]) 141 throws Exception 142 { 143 HandlerMaker maker = HandlerMaker.getInstance(); 144 AbstractHandler handler = maker.lookup(RelatedBusinessInfoHandler.TAG_NAME); 145 Element parent = XMLUtils.newRootElement(); 146 Element child = null; 147 148 RelatedBusinessInfo info = new RelatedBusinessInfo(); 149 info.setBusinessKey(""); 150 info.setBusinessKey("6c0ac186-d36b-4b81-bd27-066a5fe0fc1f"); 151 info.addName(new Name("businessNm")); 152 info.addName(new Name("businessNm2","en")); 153 info.addDescription(new Description("business whatever")); 154 info.addDescription(new Description("business whatever too","fr")); 155 info.addKeyedReference(new KeyedReference("idBagKeyName","idBagkeyValue")); 156 info.addKeyedReference(new KeyedReference("uuid:f78a135a-4769-4e79-8604-54d440314bc0","idBagKeyName2","idBagkeyValue2")); 157 158 System.out.println(); 159 160 RegistryObject regObject = info; 161 handler.marshal(regObject,parent); 162 child = (Element )parent.getFirstChild(); 163 parent.removeChild(child); 164 XMLUtils.writeXML(child,System.out); 165 166 System.out.println(); 167 168 regObject = handler.unmarshal(child); 169 handler.marshal(regObject,parent); 170 child = (Element )parent.getFirstChild(); 171 parent.removeChild(child); 172 XMLUtils.writeXML(child,System.out); 173 } 174 } | Popular Tags |