View Javadoc
1 /* 2 * ==================================================================== 3 * 4 * This code is subject to the freebxml License, Version 1.1 5 * 6 * Copyright (c) 2003 freebxml.org. All rights reserved. 7 * 8 * $Header: /cvsroot/ebxmlrr/jaxr/src/com/sun/xml/registry/ebxml/infomodel/OrganizationImpl.java,v 1.32 2003/08/02 21:14:06 farrukh_najmi Exp $ 9 * ==================================================================== 10 */ 11 package com.sun.xml.registry.ebxml.infomodel; 12 13 import java.util.ArrayList; 14 import java.util.Collection; 15 import java.util.HashSet; 16 import javax.xml.registry.JAXRException; 17 import javax.xml.registry.infomodel.Organization; 18 import javax.xml.registry.infomodel.TelephoneNumber; 19 import javax.xml.registry.infomodel.User; 20 21 /*** 22 * Class Declaration for Class1 23 * @author <a href="mailto:Farrukh.Najmi@Sun.COM">Farrukh S. Najmi</a> 24 */ 25 public class OrganizationImpl extends RegistryObjectImpl implements Organization { 26 private RegistryObjectRef parentRef = null; 27 private PostalAddressImpl address = null; 28 private RegistryObjectRef primaryContactRef = null; 29 private HashSet users = new HashSet(); 30 31 private ArrayList phones = new ArrayList(); 32 private ArrayList services = new ArrayList(); 33 private HashSet childOrgs = new HashSet(); 34 35 public OrganizationImpl(com.sun.xml.registry.ebxml.LifeCycleManagerImpl lcm) throws JAXRException { 36 super(lcm); 37 38 address = new PostalAddressImpl(lcm); 39 40 //Automatically assign primary contact to be the caller 41 User user =((com.sun.xml.registry.ebxml.QueryManagerImpl)( lcm.getRegistryService().getBusinessQueryManager())).getCallersUser(); 42 setPrimaryContact(user); 43 } 44 45 public OrganizationImpl(com.sun.xml.registry.ebxml.LifeCycleManagerImpl lcm, org.oasis.ebxml.registry.bindings.rim.OrganizationType ebOrg) throws JAXRException { 46 super(lcm, ebOrg); 47 48 address = new PostalAddressImpl(lcm, ebOrg.getAddress()); 49 50 org.oasis.ebxml.registry.bindings.rim.TelephoneNumberType[] tels = ebOrg.getTelephoneNumber(); 51 for (int i = 0; i < tels.length; i++) { 52 addTelephoneNumber(new TelephoneNumberImpl(lcm, tels[i])); 53 } 54 55 Object ebParentRef = ebOrg.getParent(); 56 if (ebParentRef != null) { 57 parentRef = new RegistryObjectRef(lcm, ebParentRef); 58 } 59 60 Object ebPrimaryContactRef = ebOrg.getPrimaryContact(); 61 if (ebPrimaryContactRef != null) { 62 primaryContactRef = new RegistryObjectRef(lcm, ebPrimaryContactRef); 63 } 64 else { 65 throw new JAXRException("primaryContact cannot be null in an Organization"); 66 } 67 } 68 69 public String toXML() throws JAXRException { 70 org.oasis.ebxml.registry.bindings.rim.RegistryObjectType ebObj = toBindingObject(); 71 java.io.StringWriter sw = new java.io.StringWriter(); 72 try { 73 ebObj.marshal(sw); 74 } catch (org.exolab.castor.xml.MarshalException x) { 75 throw new JAXRException(x); 76 } catch (org.exolab.castor.xml.ValidationException x) { 77 throw new JAXRException(x); 78 } 79 return sw.toString(); 80 } 81 82 public javax.xml.registry.infomodel.PostalAddress getPostalAddress() throws JAXRException { 83 return address; 84 } 85 86 public void setPostalAddress(javax.xml.registry.infomodel.PostalAddress par1) throws JAXRException { 87 // XXX Code assumes that par1 will always be a PostalAddressImpl 88 address = (PostalAddressImpl)par1; 89 setModified(true); 90 } 91 92 public User getPrimaryContact() throws JAXRException { 93 javax.xml.registry.infomodel.RegistryObject primaryContact = null; 94 if (primaryContactRef != null) { 95 primaryContact = primaryContactRef.getRegistryObject("User"); 96 } 97 98 return (User)primaryContact; 99 } 100 101 public void setPrimaryContact(User primaryContact) throws JAXRException { 102 primaryContactRef = new RegistryObjectRef(lcm, primaryContact); 103 setModified(true); 104 105 /* 106 if (!(users.contains(primaryContactRef))) { 107 users.add(primaryContactRef); 108 } 109 */ 110 } 111 112 public void addUser(User par1) throws JAXRException { 113 users.add(par1); 114 setModified(true); 115 } 116 117 public void addUsers(Collection par1) throws JAXRException { 118 users.addAll(par1); 119 setModified(true); 120 } 121 122 public void removeUser(User par1) throws JAXRException { 123 users.remove(par1); 124 setModified(true); 125 } 126 127 public void removeUsers(Collection par1) throws JAXRException { 128 users.removeAll(par1); 129 setModified(true); 130 } 131 132 public Collection getUsers() throws JAXRException { 133 return (HashSet)(users.clone()); 134 } 135 136 //Add to JAXR2.0?? 137 public void addTelephoneNumber(TelephoneNumber _phone) throws JAXRException { 138 getTelephoneNumbers().add(_phone); 139 setModified(true); 140 } 141 142 //Add to JAXR2.0?? 143 public void addTelephoneNumbers(Collection telephoneNumbers) throws JAXRException { 144 java.util.Iterator iter = telephoneNumbers.iterator(); 145 while (iter.hasNext()) { 146 TelephoneNumber phone = (TelephoneNumber)iter.next(); 147 addTelephoneNumber(phone); 148 } 149 setModified(true); 150 } 151 152 //Add to JAXR2.0?? 153 public void removeTelephoneNumber(TelephoneNumber _phone) throws JAXRException { 154 if (phones != null) { 155 getTelephoneNumbers().remove(_phone); 156 setModified(true); 157 } 158 } 159 160 //Add to JAXR2.0?? 161 public void removeTelephoneNumbers(Collection _phones) throws JAXRException { 162 if (phones != null) { 163 getTelephoneNumbers().removeAll(_phones); 164 setModified(true); 165 } 166 } 167 168 //??Add to JAXR 2.0. Apply same pattern to all Collection attributes in RIM. 169 public void removeAllTelephoneNumbers() throws JAXRException { 170 if (phones != null) { 171 removeTelephoneNumbers(phones); 172 setModified(true); 173 } 174 } 175 176 //Add to JAXR2.0?? 177 public void setTelephoneNumbers(Collection _phones) throws JAXRException { 178 removeAllTelephoneNumbers(); 179 180 addTelephoneNumbers(_phones); 181 setModified(true); 182 } 183 184 //Add to JAXR2.0?? 185 public Collection getTelephoneNumbers() throws JAXRException { 186 if (phones == null) { 187 phones = new ArrayList(); 188 } 189 return phones; 190 } 191 192 //Deprecate in JAXR 2.0?? 193 public Collection getTelephoneNumbers(String phoneType) throws JAXRException { 194 return getTelephoneNumbers(); 195 //return (Collection)(phones.clone()); 196 } 197 198 public void addService(javax.xml.registry.infomodel.Service par1) throws JAXRException { 199 services.add(par1); 200 setModified(true); 201 } 202 203 public void addServices(Collection par1) throws JAXRException { 204 services.addAll(par1); 205 setModified(true); 206 } 207 208 public void removeService(javax.xml.registry.infomodel.Service par1) throws JAXRException { 209 services.remove(par1); 210 setModified(true); 211 } 212 213 public void removeServices(Collection par1) throws JAXRException { 214 services.removeAll(par1); 215 setModified(true); 216 } 217 218 public Collection getServices() throws JAXRException { 219 return (Collection)(services.clone()); 220 } 221 222 public void addChildOrganization(Organization par1) throws JAXRException { 223 childOrgs.add(par1); 224 setModified(true); 225 } 226 227 public void addChildOrganizations(Collection par1) throws JAXRException { 228 childOrgs.addAll(par1); 229 setModified(true); 230 } 231 232 public void removeChildOrganization(Organization par1) throws JAXRException { 233 childOrgs.remove(par1); 234 setModified(true); 235 } 236 237 public void removeChildOrganizations(Collection par1) throws JAXRException { 238 childOrgs.removeAll(par1); 239 setModified(true); 240 } 241 242 public int getChildOrganizationCount() throws JAXRException { 243 return childOrgs.size(); 244 } 245 246 public Collection getChildOrganizations() throws JAXRException { 247 return (Collection)(childOrgs.clone()); 248 } 249 250 public Collection getDescendantOrganizations() throws JAXRException { 251 ArrayList descendants = new ArrayList(childOrgs); 252 java.util.Iterator iter = childOrgs.iterator(); 253 254 while (iter.hasNext()) { 255 Organization child = (Organization) iter.next(); 256 257 if (child.getChildOrganizationCount() > 0) { 258 descendants.addAll(child.getDescendantOrganizations()); 259 } 260 } 261 return descendants; 262 } 263 264 public Organization getParentOrganization() throws JAXRException { 265 Organization parent = null; 266 267 if (parentRef != null) { 268 javax.xml.registry.infomodel.RegistryObject parentObj = parentRef.getRegistryObject("Organization"); 269 if (parentObj instanceof Organization) { 270 parent = (Organization)parentObj; 271 } 272 } 273 274 return parent; 275 } 276 277 public Organization getRootOrganization() throws JAXRException { 278 Organization root = this; 279 280 while (root.getParentOrganization() != null) { 281 root = root.getParentOrganization(); 282 } 283 284 return root; 285 } 286 287 public void getComposedObjects(HashSet composedObjects) throws JAXRException { 288 super.getComposedObjects(composedObjects); 289 composedObjects.addAll(childOrgs); 290 } 291 292 293 /*** 294 * This method takes this JAXR infomodel object and returns an 295 * equivalent binding object for it. Note it does the reverse of one 296 * of the constructors above. 297 */ 298 public org.oasis.ebxml.registry.bindings.rim.Organization toBindingObject() throws JAXRException { 299 org.oasis.ebxml.registry.bindings.rim.Organization ebOrg = 300 new org.oasis.ebxml.registry.bindings.rim.Organization(); 301 302 setBindingObject(ebOrg); 303 304 return ebOrg; 305 } 306 307 protected void setBindingObject(org.oasis.ebxml.registry.bindings.rim.OrganizationType ebOrg) throws JAXRException { 308 super.setBindingObject(ebOrg); 309 310 if (parentRef != null) { 311 org.oasis.ebxml.registry.bindings.rim.ObjectRef ebParentRef = 312 new org.oasis.ebxml.registry.bindings.rim.ObjectRef(); 313 ebParentRef.setId(parentRef.getId()); 314 ebOrg.setParent(ebParentRef); 315 } 316 317 boolean compatibilityMode = Boolean.valueOf(com.sun.xml.registry.ebxml.util.ProviderProperties.getInstance().getProperty("jaxr-ebxml.tck.compatibilityMode", "false")).booleanValue(); 318 319 //In compatibilityMode must have all required fields filled in by provider 320 //since JAXR 1.0 TCK assumes these are optional due to UDDI bias. Fix in TCK later?? 321 if (compatibilityMode) { 322 if (address == null) { 323 javax.xml.registry.infomodel.PostalAddress _address = lcm.createPostalAddress( 324 "streetNumber", 325 "street", 326 "city", 327 "stateOrProvince", 328 "country", 329 "postalCode", 330 "type" 331 ); 332 333 setPostalAddress(_address); 334 } 335 336 if (phones.size() == 0) { 337 TelephoneNumber phone = lcm.createTelephoneNumber(); 338 339 ArrayList _phones = new ArrayList(); 340 _phones.add(phone); 341 setTelephoneNumbers(_phones); 342 } 343 344 } 345 346 347 org.oasis.ebxml.registry.bindings.rim.Address ebAddress = 348 new org.oasis.ebxml.registry.bindings.rim.Address(); 349 350 if (address != null) { 351 address.setBindingObject(ebAddress); 352 ebOrg.setAddress(ebAddress); 353 } else { 354 throw new javax.xml.registry.InvalidRequestException("Organization is missing required address attribute"); 355 } 356 357 if (primaryContactRef != null) { 358 org.oasis.ebxml.registry.bindings.rim.ObjectRef ebPrimaryContactRef = 359 new org.oasis.ebxml.registry.bindings.rim.ObjectRef(); 360 ebPrimaryContactRef.setId(primaryContactRef.getId()); 361 ebOrg.setPrimaryContact(ebPrimaryContactRef); 362 } 363 else { 364 throw new javax.xml.registry.InvalidRequestException("Organization is missing required primaryContact attribute"); 365 } 366 367 java.util.Iterator iter = getTelephoneNumbers().iterator(); 368 while (iter.hasNext()) { 369 TelephoneNumberImpl phone = (TelephoneNumberImpl)iter.next(); 370 org.oasis.ebxml.registry.bindings.rim.TelephoneNumber ebPhone = 371 phone.toBindingObject(); 372 ebOrg.addTelephoneNumber(ebPhone); 373 } 374 375 /* 376 iter = getServices().iterator(); 377 while (iter.hasNext()) { 378 ServiceImpl service = (ServiceImpl)iter.next(); 379 org.oasis.ebxml.registry.bindings.rim.Service ebService = 380 service.toBindingObject(); 381 ebOrg.addService(ebService); 382 } 383 */ 384 } 385 386 /*** 387 * Used by LifeCycleManagerImpl.saveObjects 388 * 389 */ 390 public HashSet getRegistryObjectRefs() { 391 HashSet refs = new HashSet(); 392 393 //refs.addAll(super.getRegistryObjectRefs()); 394 395 if (parentRef != null) { 396 refs.add(parentRef); 397 } 398 399 if (primaryContactRef != null) { 400 refs.add(primaryContactRef); 401 } 402 403 return refs; 404 } 405 406 public void setModified(boolean modified) { 407 super.setModified(modified); 408 409 if (modified == true) { 410 int i=0; 411 } 412 else { 413 int j=0; 414 } 415 416 } 417 }

This page was automatically generated by Maven