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.CategoryBag; 22 import org.apache.juddi.datatype.Description; 23 import org.apache.juddi.datatype.IdentifierBag; 24 import org.apache.juddi.datatype.KeyedReference; 25 import org.apache.juddi.datatype.OverviewDoc; 26 import org.apache.juddi.datatype.RegistryObject; 27 import org.apache.juddi.datatype.response.TModelDetail; 28 import org.apache.juddi.datatype.tmodel.TModel; 29 import org.apache.juddi.util.xml.XMLUtils; 30 import org.w3c.dom.Element ; 31 32 38 public class TModelDetailHandler extends AbstractHandler 39 { 40 public static final String TAG_NAME = "tModelDetail"; 41 42 private HandlerMaker maker = null; 43 44 protected TModelDetailHandler(HandlerMaker maker) 45 { 46 this.maker = maker; 47 } 48 49 public RegistryObject unmarshal(Element element) 50 { 51 TModelDetail obj = new TModelDetail(); 52 Vector nodeList = null; 53 AbstractHandler handler = null; 54 55 59 obj.setGeneric(element.getAttribute("generic")); 61 obj.setOperator(element.getAttribute("operator")); 62 63 67 String truncValue = element.getAttribute("truncated"); 68 if (truncValue != null) 69 obj.setTruncated(truncValue.equalsIgnoreCase("true")); 70 71 74 nodeList = XMLUtils.getChildElementsByTagName(element,TModelHandler.TAG_NAME); 76 for (int i=0; i<nodeList.size(); i++) 77 { 78 handler = maker.lookup(TModelHandler.TAG_NAME); 79 obj.addTModel((TModel)handler.unmarshal((Element )nodeList.elementAt(i))); 80 } 81 82 return obj; 83 } 84 85 public void marshal(RegistryObject object,Element parent) 86 { 87 TModelDetail detail = (TModelDetail)object; 88 Element element = parent.getOwnerDocument().createElementNS(null,TAG_NAME); 89 AbstractHandler handler = null; 90 91 String generic = detail.getGeneric(); 92 if ((generic != null) && (generic.trim().length() > 0)) 93 { 94 element.setAttribute("generic",generic); 95 96 if (generic.equals(IRegistry.UDDI_V1_GENERIC)) 97 element.setAttribute("xmlns",IRegistry.UDDI_V1_NAMESPACE); 98 else if (generic.equals(IRegistry.UDDI_V2_GENERIC)) 99 element.setAttribute("xmlns",IRegistry.UDDI_V2_NAMESPACE); 100 else if (generic.equals(IRegistry.UDDI_V3_GENERIC)) 101 element.setAttribute("xmlns",IRegistry.UDDI_V3_NAMESPACE); 102 } 103 else { 105 element.setAttribute("generic",IRegistry.UDDI_V2_GENERIC); 106 element.setAttribute("xmlns",IRegistry.UDDI_V2_NAMESPACE); 107 } 108 109 String operator = detail.getOperator(); 110 if (operator != null) 111 element.setAttribute("operator",operator); 112 else 113 element.setAttribute("operator",""); 114 115 boolean truncated = detail.isTruncated(); 116 if (truncated) 117 element.setAttribute("truncated","true"); 118 119 Vector vector = detail.getTModelVector(); 120 if ((vector!=null) && (vector.size() > 0)) 121 { 122 handler = maker.lookup(TModelHandler.TAG_NAME); 123 for (int i=0; i < vector.size(); i++) 124 handler.marshal((TModel)vector.elementAt(i),element); 125 } 126 127 parent.appendChild(element); 128 } 129 130 131 132 133 134 135 136 public static void main(String args[]) 137 throws Exception 138 { 139 HandlerMaker maker = HandlerMaker.getInstance(); 140 AbstractHandler handler = maker.lookup(TModelDetailHandler.TAG_NAME); 141 142 Element parent = XMLUtils.newRootElement(); 143 Element child = null; 144 145 OverviewDoc overDoc = new OverviewDoc(); 146 overDoc.setOverviewURL("http://www.sviens.com/service.html"); 147 overDoc.addDescription(new Description("over-doc Descr")); 148 overDoc.addDescription(new Description("over-doc Descr Two","en")); 149 150 CategoryBag catBag = new CategoryBag(); 151 catBag.addKeyedReference(new KeyedReference("catBagKeyName","catBagKeyValue")); 152 catBag.addKeyedReference(new KeyedReference("uuid:dfddb58c-4853-4a71-865c-f84509017cc7","catBagKeyName2","catBagKeyValue2")); 153 154 IdentifierBag idBag = new IdentifierBag(); 155 idBag.addKeyedReference(new KeyedReference("idBagKeyName","idBagkeyValue")); 156 idBag.addKeyedReference(new KeyedReference("uuid:f78a135a-4769-4e79-8604-54d440314bc0","idBagKeyName2","idBagkeyValue2")); 157 158 TModel tModel = new TModel(); 159 tModel.setTModelKey("uuid:269855db-62eb-4862-8e5a-1b06f2753038"); 160 tModel.setOperator("jUDDI"); 161 tModel.setAuthorizedName("Steve Viens"); 162 tModel.setName("jUDDI TModel"); 163 tModel.addDescription(new Description("tModel whatever")); 164 tModel.addDescription(new Description("tModel whatever too","fr")); 165 tModel.setCategoryBag(catBag); 166 tModel.setIdentifierBag(idBag); 167 tModel.setOverviewDoc(overDoc); 168 169 TModelDetail detail = new TModelDetail(); 170 detail.setGeneric("2.0"); 171 detail.setOperator("jUDDI.org"); 172 detail.setTruncated(true); 173 detail.addTModel(tModel); 174 detail.addTModel(tModel); 175 176 System.out.println(); 177 178 RegistryObject regObject = detail; 179 handler.marshal(regObject,parent); 180 child = (Element )parent.getFirstChild(); 181 parent.removeChild(child); 182 XMLUtils.writeXML(child,System.out); 183 184 System.out.println(); 185 186 regObject = handler.unmarshal(child); 187 handler.marshal(regObject,parent); 188 child = (Element )parent.getFirstChild(); 189 parent.removeChild(child); 190 XMLUtils.writeXML(child,System.out); 191 } 192 } | Popular Tags |