1 9 10 package org.uddi4j.datatype.service; 11 12 import java.util.Vector ; 13 14 import org.uddi4j.UDDIElement; 15 import org.uddi4j.UDDIException; 16 import org.uddi4j.datatype.Description; 17 import org.uddi4j.datatype.Name; 18 import org.uddi4j.datatype.binding.BindingTemplates; 19 import org.uddi4j.util.CategoryBag; 20 import org.w3c.dom.Element ; 21 import org.w3c.dom.NodeList ; 22 23 46 public class BusinessService extends UDDIElement { 47 public static final String UDDI_TAG = "businessService"; 48 49 protected Element base = null; 50 51 String serviceKey = null; 52 String businessKey = null; 53 BindingTemplates bindingTemplates = null; 54 CategoryBag categoryBag = null; 55 Vector description = new Vector (); 57 Vector nameVector = new Vector (); 58 59 65 public BusinessService() { 66 } 67 68 79 public BusinessService(String serviceKey, 80 String name, 81 BindingTemplates bindingTemplates) { 82 this.serviceKey = serviceKey; 83 nameVector.addElement(new Name(name)); 84 this.bindingTemplates = bindingTemplates; 85 } 86 87 92 public BusinessService(String serviceKey) { 93 this.serviceKey = serviceKey; 94 } 95 96 106 public BusinessService(Element base) throws UDDIException { 107 super(base); 109 serviceKey = base.getAttribute("serviceKey"); 110 businessKey = getAttr(base,"businessKey"); 111 NodeList nl = null; 112 nl = getChildElementsByTagName(base, Name.UDDI_TAG); 113 for (int i=0; i < nl.getLength(); i++) { 114 nameVector.addElement(new Name((Element)nl.item(i))); 115 } 116 nl = getChildElementsByTagName(base, BindingTemplates.UDDI_TAG); 117 if (nl.getLength() > 0) { 118 bindingTemplates = new BindingTemplates((Element)nl.item(0)); 119 } 120 nl = getChildElementsByTagName(base, CategoryBag.UDDI_TAG); 121 if (nl.getLength() > 0) { 122 categoryBag = new CategoryBag((Element)nl.item(0)); 123 } 124 nl = getChildElementsByTagName(base, Description.UDDI_TAG); 125 for (int i=0; i < nl.getLength(); i++) { 126 description.addElement(new Description((Element)nl.item(i))); 127 } 128 } 129 130 private String getAttr(Element base, String attrname) 131 { 132 if(base.getAttributeNode(attrname)!=null && base.getAttributeNode(attrname).getSpecified() ) 133 { 134 return base.getAttribute(attrname); 135 } 136 return null; 137 } 138 139 public void setServiceKey(String s) { 140 serviceKey = s; 141 } 142 143 public void setBusinessKey(String s) { 144 businessKey = s; 145 } 146 147 152 public void setName(Name s) { 153 setDefaultName(s); 154 } 155 156 161 public void setName(String s) { 162 setDefaultNameString(s, null); 163 } 164 165 169 public void setDefaultName(Name name) { 170 if (nameVector.size() > 0) { 171 nameVector.setElementAt(name,0); 172 } else { 173 nameVector.addElement(name); 174 } 175 } 176 177 181 public void setDefaultNameString(String value, String lang) { 182 Name name = new Name(value, lang); 183 if (nameVector.size() > 0) { 184 nameVector.setElementAt(name,0); 185 } else { 186 nameVector.addElement(name); 187 } 188 } 189 190 193 public void setNameVector(Vector s) { 194 nameVector = s; 195 } 196 197 public void setBindingTemplates(BindingTemplates s) { 198 bindingTemplates = s; 199 } 200 201 public void setCategoryBag(CategoryBag s) { 202 categoryBag = s; 203 } 204 205 210 public void setDescriptionVector(Vector s) { 211 description = s; 212 } 213 214 219 public void setDefaultDescriptionString(String s) { 220 if (description.size() > 0) { 221 description.setElementAt(new Description(s), 0); 222 } else { 223 description.addElement(new Description(s)); 224 } 225 } 226 227 public String getServiceKey() { 228 return serviceKey; 229 } 230 231 232 public String getBusinessKey() { 233 return businessKey; 234 } 235 236 241 public Name getName() { 242 return getDefaultName(); 243 } 244 245 250 public String getNameString() { 251 return getDefaultNameString(); 252 } 253 254 public Name getDefaultName() { 255 if (nameVector.size() > 0) { 256 return (Name) nameVector.elementAt(0); 257 } else { 258 return null; 259 } 260 } 261 262 public String getDefaultNameString() { 263 if ((nameVector).size() > 0) { 264 return ((Name)nameVector.elementAt(0)).getText(); 265 } else { 266 return null; 267 } 268 } 269 270 275 public Vector getNameVector() { 276 return nameVector ; 277 } 278 279 280 public BindingTemplates getBindingTemplates() { 281 return bindingTemplates; 282 } 283 284 285 public CategoryBag getCategoryBag() { 286 return categoryBag; 287 } 288 289 290 295 public Vector getDescriptionVector() { 296 return description; 297 } 298 299 304 public String getDefaultDescriptionString() { 305 if ((description).size() > 0) { 306 Description t = (Description)description.elementAt(0); 307 return t.getText(); 308 } else { 309 return null; 310 } 311 } 312 313 322 public void saveToXML(Element parent) { 323 base = parent.getOwnerDocument().createElement(UDDI_TAG); 324 if (serviceKey!=null) { 326 base.setAttribute("serviceKey", serviceKey); 327 } 328 if (businessKey!=null) { 329 base.setAttribute("businessKey", businessKey); 330 } 331 if (nameVector!=null) { 332 for (int i=0; i < nameVector.size(); i++) { 333 ((Name)(nameVector.elementAt(i))).saveToXML(base); 334 } 335 } 336 if (description!=null) { 337 for (int i=0; i < description.size(); i++) { 338 ((Description)(description.elementAt(i))).saveToXML(base); 339 } 340 } 341 if (bindingTemplates!=null) { 342 bindingTemplates.saveToXML(base); 343 } 344 if (categoryBag!=null) { 345 categoryBag.saveToXML(base); 346 } 347 parent.appendChild(base); 348 } 349 } 350 | Popular Tags |