1 16 package org.apache.juddi.handler; 17 18 import java.util.Vector ; 19 20 import org.apache.juddi.datatype.RegistryObject; 21 import org.apache.juddi.datatype.business.BusinessEntity; 22 import org.apache.juddi.datatype.request.ValidateValues; 23 import org.apache.juddi.datatype.service.BusinessService; 24 import org.apache.juddi.datatype.tmodel.TModel; 25 import org.apache.juddi.util.xml.XMLUtils; 26 import org.w3c.dom.Element ; 27 28 31 public class ValidateValuesHandler extends AbstractHandler 32 { 33 public static final String TAG_NAME = "validate_values"; 34 35 private HandlerMaker maker = null; 36 37 protected ValidateValuesHandler(HandlerMaker maker) 38 { 39 this.maker = maker; 40 } 41 42 public RegistryObject unmarshal(Element element) 43 { 44 ValidateValues obj = new ValidateValues(); 45 Vector nodeList = null; 46 AbstractHandler handler = null; 47 48 String generic = element.getAttribute("generic"); 50 if ((generic != null && (generic.trim().length() > 0))) 51 obj.setGeneric(generic); 52 53 56 nodeList = XMLUtils.getChildElementsByTagName(element,BusinessEntityHandler.TAG_NAME); 58 for (int i=0; i<nodeList.size(); i++) 59 { 60 handler = maker.lookup(BusinessEntityHandler.TAG_NAME); 61 obj.addBusinessEntity((BusinessEntity)handler.unmarshal((Element )nodeList.elementAt(i))); 62 } 63 64 nodeList = XMLUtils.getChildElementsByTagName(element,BusinessServiceHandler.TAG_NAME); 65 for (int i=0; i<nodeList.size(); i++) 66 { 67 handler = maker.lookup(BusinessServiceHandler.TAG_NAME); 68 obj.addBusinessService((BusinessService)handler.unmarshal((Element )nodeList.elementAt(i))); 69 } 70 71 nodeList = XMLUtils.getChildElementsByTagName(element,TModelHandler.TAG_NAME); 72 for (int i=0; i<nodeList.size(); i++) 73 { 74 handler = maker.lookup(TModelHandler.TAG_NAME); 75 obj.addTModel((TModel)handler.unmarshal((Element )nodeList.elementAt(i))); 76 } 77 78 return obj; 79 } 80 81 public void marshal(RegistryObject object,Element parent) 82 { 83 ValidateValues request = (ValidateValues)object; 84 Element element = parent.getOwnerDocument().createElementNS(null,TAG_NAME); 85 AbstractHandler handler = null; 86 87 String generic = request.getGeneric(); 88 if (generic != null) 89 element.setAttribute("generic",generic); 90 91 Vector businessVector = request.getBusinessEntityVector(); 92 if ((businessVector!=null) && (businessVector.size() > 0)) 93 { 94 handler = maker.lookup(BusinessEntityHandler.TAG_NAME); 95 for (int i=0; i < businessVector.size(); i++) 96 handler.marshal((BusinessEntity)businessVector.elementAt(i),element); 97 } 98 99 Vector serviceVector = request.getBusinessServiceVector(); 100 if ((serviceVector!=null) && (serviceVector.size() > 0)) 101 { 102 handler = maker.lookup(BusinessServiceHandler.TAG_NAME); 103 for (int i=0; i < serviceVector.size(); i++) 104 handler.marshal((BusinessService)serviceVector.elementAt(i),element); 105 } 106 107 Vector tModelVector = request.getTModelVector(); 108 if ((tModelVector!=null) && (tModelVector.size() > 0)) 109 { 110 handler = maker.lookup(TModelHandler.TAG_NAME); 111 for (int i=0; i < tModelVector.size(); i++) 112 handler.marshal((TModel)tModelVector.elementAt(i),element); 113 } 114 115 parent.appendChild(element); 116 } 117 118 119 120 121 122 123 124 public static void main(String args[]) 125 throws Exception 126 { 127 HandlerMaker maker = HandlerMaker.getInstance(); 128 AbstractHandler handler = maker.lookup(ValidateValuesHandler.TAG_NAME); 129 Element parent = XMLUtils.newRootElement(); 130 Element child = null; 131 132 BusinessEntity business = new BusinessEntity(); 133 BusinessService service = new BusinessService(); 134 TModel tModel = new TModel(); 135 136 ValidateValues request = new ValidateValues(); 137 request.addBusinessEntity(business); 138 request.addBusinessService(service); 139 request.addTModel(tModel); 140 141 System.out.println(); 142 143 RegistryObject regObject = request; 144 handler.marshal(regObject,parent); 145 child = (Element )parent.getFirstChild(); 146 parent.removeChild(child); 147 XMLUtils.writeXML(child,System.out); 148 149 System.out.println(); 150 151 regObject = handler.unmarshal(child); 152 handler.marshal(regObject,parent); 153 child = (Element )parent.getFirstChild(); 154 parent.removeChild(child); 155 XMLUtils.writeXML(child,System.out); 156 157 System.out.println(); 158 } 159 } | Popular Tags |