View Javadoc
1 /* 2 * $Header: /cvsroot/ebxmlrr/jaxr/src/com/sun/xml/registry/ebxml/infomodel/UserImpl.java,v 1.20 2003/08/13 04:22:07 farrukh_najmi Exp $ 3 * 4 * 5 */ 6 7 package com.sun.xml.registry.ebxml.infomodel; 8 9 import javax.xml.registry.*; 10 import javax.xml.registry.infomodel.*; 11 import java.net.*; 12 import java.util.*; 13 import java.io.*; 14 15 import org.oasis.ebxml.registry.bindings.rim.EmailAddressType; 16 import org.oasis.ebxml.registry.bindings.rim.TelephoneNumberType; 17 import org.oasis.ebxml.registry.bindings.rim.UserType; 18 19 import com.sun.xml.registry.ebxml.LifeCycleManagerImpl; 20 21 /*** 22 * Class Declaration for Class1 23 * @author <a href="mailto:Farrukh.Najmi@Sun.COM">Farrukh S. Najmi</a> 24 */ 25 public class UserImpl extends RegistryObjectImpl implements User 26 { 27 private PersonName personName = null; 28 private ArrayList addresses = new ArrayList(); 29 private ArrayList emails = new ArrayList(); 30 private ArrayList phones = new ArrayList(); 31 private URL url = null; 32 private String type = null; 33 private RegistryObjectRef orgRef = null; 34 35 public UserImpl(LifeCycleManagerImpl lcm) throws JAXRException { 36 super(lcm); 37 personName = lcm.createPersonName("", "", ""); 38 } 39 40 public UserImpl(LifeCycleManagerImpl lcm, UserType ebUser) 41 throws JAXRException 42 { 43 super(lcm, ebUser); 44 personName = new PersonNameImpl(lcm, ebUser.getPersonName()); 45 46 PostalAddressImpl address = new PostalAddressImpl(lcm, ebUser.getAddress()); 47 addresses.add(address); 48 49 TelephoneNumberType[] tels = ebUser.getTelephoneNumber(); 50 for (int i = 0; i < tels.length; i++) { 51 phones.add(new TelephoneNumberImpl(lcm, tels[i])); 52 } 53 54 EmailAddressType[] ebEmails = ebUser.getEmailAddress(); 55 for (int i = 0; i < ebEmails.length; i++) { 56 emails.add(new EmailAddressImpl(lcm, ebEmails[i])); 57 } 58 59 Object orgObj = ebUser.getOrganization(); 60 if (orgObj != null) { 61 orgRef = new RegistryObjectRef(lcm, orgObj); 62 } 63 64 try { 65 url = new URL(ebUser.getUrl()); 66 } catch (MalformedURLException x) { 67 // XXX If the URL is malformed, then act like we have no URL, 68 // instead of throwing a JAXRException. Is this the right 69 // thing to do?? 70 } 71 } 72 73 public String toXML() throws JAXRException { 74 org.oasis.ebxml.registry.bindings.rim.RegistryObjectType ebObj = toBindingObject(); 75 StringWriter sw = new StringWriter(); 76 try { 77 ebObj.marshal(sw); 78 } catch (org.exolab.castor.xml.MarshalException x) { 79 throw new JAXRException(x); 80 } catch (org.exolab.castor.xml.ValidationException x) { 81 throw new JAXRException(x); 82 } 83 return sw.toString(); 84 } 85 86 public PersonName getPersonName() throws JAXRException { 87 return personName; 88 } 89 90 public void setPersonName(PersonName par1) throws JAXRException { 91 personName = par1; 92 setModified(true); 93 } 94 95 public Collection getPostalAddresses() throws JAXRException { 96 return addresses; 97 } 98 99 public void setPostalAddresses(Collection par1) throws JAXRException { 100 addresses.clear(); 101 addresses.addAll(par1); 102 setModified(true); 103 } 104 105 public URL getUrl() throws JAXRException { 106 return url; 107 } 108 109 public void setUrl(URL par1) throws JAXRException { 110 url = par1; 111 setModified(true); 112 } 113 114 //Add to JAXR2.0?? 115 public void addTelephoneNumber(TelephoneNumber _phone) throws JAXRException { 116 getTelephoneNumbers().add(_phone); 117 setModified(true); 118 } 119 120 //Add to JAXR2.0?? 121 public void addTelephoneNumbers(Collection telephoneNumbers) throws JAXRException { 122 Iterator iter = telephoneNumbers.iterator(); 123 while (iter.hasNext()) { 124 TelephoneNumber phone = (TelephoneNumber)iter.next(); 125 addTelephoneNumber(phone); 126 } 127 setModified(true); 128 } 129 130 //Add to JAXR2.0?? 131 public void removeTelephoneNumber(TelephoneNumber _phone) throws JAXRException { 132 if (phones != null) { 133 getTelephoneNumbers().remove(_phone); 134 setModified(true); 135 } 136 } 137 138 //Add to JAXR2.0?? 139 public void removeTelephoneNumbers(Collection _phones) throws JAXRException { 140 if (phones != null) { 141 getTelephoneNumbers().removeAll(_phones); 142 setModified(true); 143 } 144 } 145 146 //??Add to JAXR 2.0. Apply same pattern to all Collection attributes in RIM. 147 public void removeAllTelephoneNumbers() throws JAXRException { 148 if (phones != null) { 149 removeTelephoneNumbers(phones); 150 setModified(true); 151 } 152 } 153 154 //Add to JAXR2.0?? 155 public void setTelephoneNumbers(Collection _phones) throws JAXRException { 156 removeAllTelephoneNumbers(); 157 158 addTelephoneNumbers(_phones); 159 setModified(true); 160 } 161 162 //Add to JAXR2.0?? 163 public Collection getTelephoneNumbers() throws JAXRException { 164 if (phones == null) { 165 phones = new ArrayList(); 166 } 167 return phones; 168 } 169 170 //Deprecate in JAXR 2.0?? 171 public Collection getTelephoneNumbers(String phoneType) throws JAXRException { 172 return getTelephoneNumbers(); 173 //return (Collection)(phones.clone()); 174 } 175 176 public Collection getEmailAddresses() throws JAXRException { 177 return (Collection)(emails.clone()); 178 } 179 180 public void setEmailAddresses(Collection par1) throws JAXRException { 181 emails.clear(); 182 emails.addAll(par1); 183 setModified(true); 184 } 185 186 public String getType() throws JAXRException { 187 return type; 188 } 189 190 public void setType(String par1) throws JAXRException { 191 type = par1; 192 setModified(true); 193 } 194 195 public Organization getOrganization() throws JAXRException { 196 if (orgRef != null) { 197 return (Organization)orgRef.getRegistryObject("Organization"); 198 } 199 return null; 200 } 201 202 /*** 203 * This method takes this JAXR infomodel object and returns an 204 * equivalent binding object for it. Note it does the reverse of one 205 * of the constructors above. 206 */ 207 public org.oasis.ebxml.registry.bindings.rim.User toBindingObject() throws JAXRException { 208 org.oasis.ebxml.registry.bindings.rim.User ebUser = 209 new org.oasis.ebxml.registry.bindings.rim.User(); 210 211 setBindingObject(ebUser); 212 213 return ebUser; 214 } 215 216 protected void setBindingObject(org.oasis.ebxml.registry.bindings.rim.UserType ebUser) throws JAXRException { 217 super.setBindingObject(ebUser); 218 219 org.oasis.ebxml.registry.bindings.rim.PersonName ebPersonName = 220 ((PersonNameImpl)personName).toBindingObject(); 221 ebUser.setPersonName(ebPersonName); 222 223 boolean compatibilityMode = Boolean.valueOf(com.sun.xml.registry.ebxml.util.ProviderProperties.getInstance().getProperty("jaxr-ebxml.tck.compatibilityMode", "false")).booleanValue(); 224 225 //In compatibilityMode must have all required fields filled in by provider 226 //since JAXR 1.0 TCK assumes these are optional due to UDDI bias. Fix in TCK later?? 227 if (compatibilityMode) { 228 if (addresses.size() == 0) { 229 PostalAddress address = lcm.createPostalAddress( 230 "streetNumber", 231 "street", 232 "city", 233 "stateOrProvince", 234 "country", 235 "postalCode", 236 "type" 237 ); 238 239 ArrayList _addresses = new ArrayList(); 240 _addresses.add(address); 241 setPostalAddresses(_addresses); 242 } 243 244 if (phones.size() == 0) { 245 TelephoneNumber phone = lcm.createTelephoneNumber(); 246 247 ArrayList _phones = new ArrayList(); 248 _phones.add(phone); 249 setTelephoneNumbers(_phones); 250 } 251 252 if (emails.size() == 0) { 253 EmailAddress email = lcm.createEmailAddress("dummy@nowhere.com"); 254 255 ArrayList _emails = new ArrayList(); 256 _emails.add(email); 257 setTelephoneNumbers(_emails); 258 } 259 } 260 261 Iterator iter = getPostalAddresses().iterator(); 262 while (iter.hasNext()) { 263 PostalAddressImpl addr = (PostalAddressImpl)iter.next(); 264 265 org.oasis.ebxml.registry.bindings.rim.Address ebAddress = 266 new org.oasis.ebxml.registry.bindings.rim.Address(); 267 addr.setBindingObject(ebAddress); 268 ebUser.setAddress(ebAddress); 269 //??ebXML only allows one address for a User 270 break; 271 } 272 273 iter = getEmailAddresses().iterator(); 274 while (iter.hasNext()) { 275 EmailAddressImpl email = (EmailAddressImpl)iter.next(); 276 org.oasis.ebxml.registry.bindings.rim.EmailAddress ebEmail = email.toBindingObject(); 277 ebUser.addEmailAddress(ebEmail); 278 } 279 280 iter = getTelephoneNumbers(null).iterator(); 281 while (iter.hasNext()) { 282 TelephoneNumberImpl phone = (TelephoneNumberImpl)iter.next(); 283 org.oasis.ebxml.registry.bindings.rim.TelephoneNumber ebPhone = phone.toBindingObject(); 284 ebUser.addTelephoneNumber(ebPhone); 285 } 286 287 if (url != null) { 288 ebUser.setUrl(url.toString()); 289 } 290 291 } 292 293 /*** 294 * Used by LifeCycleManagerImpl.saveObjects 295 * 296 */ 297 public HashSet getRegistryObjectRefs() { 298 HashSet refs = new HashSet(); 299 300 //refs.addAll(super.getRegistryObjectRefs()); 301 302 if (orgRef != null) { 303 refs.add(orgRef); 304 } 305 306 return refs; 307 } 308 309 public InternationalString getName() throws JAXRException { 310 InternationalString name = null; 311 if ((this.name == null) || ((this.name.getValue() == null) || (this.name.getValue().length() == 0))) { 312 String nameStr = ""; 313 if (personName.getLastName() != null) { 314 nameStr += personName.getLastName(); 315 } 316 if (personName.getFirstName() != null) { 317 nameStr += ", " + personName.getFirstName(); 318 } 319 if (personName.getMiddleName() != null) { 320 nameStr += " " + personName.getMiddleName(); 321 } 322 name = lcm.createInternationalString(nameStr); 323 } 324 else { 325 name = this.name; 326 } 327 return name; 328 } 329 330 331 }

This page was automatically generated by Maven