1 16 package org.apache.juddi.handler; 17 18 import java.util.Vector ; 19 20 import org.apache.juddi.IRegistry; 21 import org.apache.juddi.datatype.BusinessKey; 22 import org.apache.juddi.datatype.RegistryObject; 23 import org.apache.juddi.datatype.response.RelatedBusinessInfo; 24 import org.apache.juddi.datatype.response.RelatedBusinessInfos; 25 import org.apache.juddi.datatype.response.RelatedBusinessesList; 26 import org.apache.juddi.util.xml.XMLUtils; 27 import org.w3c.dom.Element ; 28 29 33 public class RelatedBusinessesListHandler extends AbstractHandler 34 { 35 public static final String TAG_NAME = "relatedBusinessList"; 36 37 private HandlerMaker maker = null; 38 39 protected RelatedBusinessesListHandler(HandlerMaker maker) 40 { 41 this.maker = maker; 42 } 43 44 public RegistryObject unmarshal(Element element) 45 { 46 RelatedBusinessesList obj = new RelatedBusinessesList(); 47 Vector nodeList = null; 48 AbstractHandler handler = null; 49 50 54 obj.setGeneric(element.getAttribute("generic")); 56 obj.setOperator(element.getAttribute("operator")); 57 58 62 String truncValue = element.getAttribute("truncated"); 63 if (truncValue != null) 64 obj.setTruncated(truncValue.equalsIgnoreCase("true")); 65 66 69 nodeList = XMLUtils.getChildElementsByTagName(element,BusinessKeyHandler.TAG_NAME); 71 if (nodeList.size() > 0) 72 { 73 handler = maker.lookup(BusinessKeyHandler.TAG_NAME); 74 obj.setBusinessKey((BusinessKey)handler.unmarshal((Element )nodeList.elementAt(0))); 75 } 76 77 nodeList = XMLUtils.getChildElementsByTagName(element,RelatedBusinessInfosHandler.TAG_NAME); 78 if (nodeList.size() > 0) 79 { 80 handler = maker.lookup(RelatedBusinessInfosHandler.TAG_NAME); 81 obj.setRelatedBusinessInfos((RelatedBusinessInfos)handler.unmarshal((Element )nodeList.elementAt(0))); 82 } 83 84 return obj; 85 } 86 87 public void marshal(RegistryObject object,Element parent) 88 { 89 RelatedBusinessesList list = (RelatedBusinessesList)object; 90 Element element = parent.getOwnerDocument().createElementNS(null,TAG_NAME); 91 AbstractHandler handler = null; 92 93 String generic = list.getGeneric(); 94 if ((generic != null) && (generic.trim().length() > 0)) 95 { 96 element.setAttribute("generic",generic); 97 98 if (generic.equals(IRegistry.UDDI_V1_GENERIC)) 99 element.setAttribute("xmlns",IRegistry.UDDI_V1_NAMESPACE); 100 else if (generic.equals(IRegistry.UDDI_V2_GENERIC)) 101 element.setAttribute("xmlns",IRegistry.UDDI_V2_NAMESPACE); 102 else if (generic.equals(IRegistry.UDDI_V3_GENERIC)) 103 element.setAttribute("xmlns",IRegistry.UDDI_V3_NAMESPACE); 104 } 105 else { 107 element.setAttribute("generic",IRegistry.UDDI_V2_GENERIC); 108 element.setAttribute("xmlns",IRegistry.UDDI_V2_NAMESPACE); 109 } 110 111 String operator = list.getOperator(); 112 if (operator != null) 113 element.setAttribute("operator",operator); 114 else 115 element.setAttribute("operator",""); 116 117 boolean truncated = list.isTruncated(); 118 if (truncated) 119 element.setAttribute("truncated","true"); 120 121 BusinessKey key = list.getBusinessKey(); 122 if (key != null) 123 { 124 handler = maker.lookup(BusinessKeyHandler.TAG_NAME); 125 handler.marshal(key,element); 126 } 127 128 RelatedBusinessInfos infos = list.getRelatedBusinessInfos(); 129 if (infos != null) 130 { 131 handler = maker.lookup(RelatedBusinessInfosHandler.TAG_NAME); 132 handler.marshal(infos,element); 133 } 134 135 parent.appendChild(element); 136 } 137 138 139 140 141 142 143 144 public static void main(String args[]) 145 throws Exception 146 { 147 HandlerMaker maker = HandlerMaker.getInstance(); 148 AbstractHandler handler = maker.lookup(RelatedBusinessesListHandler.TAG_NAME); 149 150 Element parent = XMLUtils.newRootElement(); 151 Element child = null; 152 153 RelatedBusinessesList list = new RelatedBusinessesList(); 154 list.setGeneric("2.0"); 155 list.setOperator("jUDDI.org"); 156 list.setTruncated(true); 157 list.setBusinessKey(new BusinessKey("f9f0c35f-06ab-4bec-9c7d-b1469e73f0eb")); 158 list.addRelatedBusinessInfo(new RelatedBusinessInfo("abc")); 159 list.addRelatedBusinessInfo(new RelatedBusinessInfo("xyz")); 160 161 System.out.println(); 162 163 RegistryObject regObject = list; 164 handler.marshal(regObject,parent); 165 child = (Element )parent.getFirstChild(); 166 parent.removeChild(child); 167 XMLUtils.writeXML(child,System.out); 168 169 System.out.println(); 170 171 regObject = handler.unmarshal(child); 172 handler.marshal(regObject,parent); 173 child = (Element )parent.getFirstChild(); 174 parent.removeChild(child); 175 XMLUtils.writeXML(child,System.out); 176 } 177 } | Popular Tags |