Author: geirm
Date: Thu Feb 10 07:06:49 2005
New Revision: 153228
URL: http://svn.apache.org/viewcvs?view=rev&rev=153228
Log:
first cut at solving the mythical primary contact problem
The spec isn't quite clear about this, so trying to be as
clear and defensive as possible.
Modified:
webservices/scout/trunk/modules/scout/src/java/org/apache/ws/scout/registry/infomodel/OrganizationImpl.java
Modified:
webservices/scout/trunk/modules/scout/src/java/org/apache/ws/scout/registry/infomodel/OrganizationImpl.java
URL:
http://svn.apache.org/viewcvs/webservices/scout/trunk/modules/scout/src/java/org/apache/ws/scout/registry/infomodel/OrganizationImpl.java?view=diff&r1=153227&r2=153228
==============================================================================
---
webservices/scout/trunk/modules/scout/src/java/org/apache/ws/scout/registry/infomodel/OrganizationImpl.java
(original)
+++
webservices/scout/trunk/modules/scout/src/java/org/apache/ws/scout/registry/infomodel/OrganizationImpl.java
Thu Feb 10 07:06:49 2005
@@ -16,7 +16,6 @@
package org.apache.ws.scout.registry.infomodel;
-import javax.xml.registry.InvalidRequestException;
import javax.xml.registry.JAXRException;
import javax.xml.registry.LifeCycleManager;
import javax.xml.registry.UnsupportedCapabilityException;
@@ -35,7 +34,8 @@
* * Implements JAXR Interface.
* For futher details, look into the JAXR API Javadoc.
*
- * @author Anil Saldhana <[EMAIL PROTECTED]>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Anil Saldhana</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
*/
public class OrganizationImpl extends RegistryObjectImpl implements
Organization
{
@@ -52,6 +52,9 @@
public User getPrimaryContact() throws JAXRException
{
//TODO: How do we fix this? Run JAXRQueryTest and you will hit this
problem.
+ //
+ // gmj : I think I fixed w/ primary contact hack...
+ //
//if (primaryContact == null) {
// throw new IllegalStateException("primaryContact is null and the
spec says we cannot return a null value");
//}
@@ -64,25 +67,47 @@
{
throw new IllegalArgumentException("primaryContact must not be
null");
}
- users.add(user);
+
+ /*
+ * first check to see if user already exists in user set
+ */
+
primaryContact = user;
- ((UserImpl) user).setOrganization(this);
+
+ if (!users.contains(user)) {
+ addUser(user);
+ }
}
public void addUser(User user) throws JAXRException
{
+ doPrimaryContactHack(user);
+
users.add(user);
((UserImpl) user).setOrganization(this);
}
+ /**
+ *
+ * to solve the getPrimaryContactProblem(), if we have no defined
+ * primaryContact, we'll designate the first user as such
+ *
+ * @param user
+ */
+ private void doPrimaryContactHack(User user) {
+
+ if (primaryContact == null && users.size() == 0) {
+ primaryContact = user;
+ }
+ }
+
public void addUsers(Collection collection) throws JAXRException
{
// do this by hand to ensure all members are actually instances of User
for (Iterator iterator = collection.iterator(); iterator.hasNext();)
{
User user = (User) iterator.next();
- users.add(user);
- ((UserImpl) user).setOrganization(this);
+ addUser(user);
}
}
@@ -93,20 +118,35 @@
public void removeUser(User user) throws JAXRException
{
- if (primaryContact.equals(user))
- {
- throw new InvalidRequestException("Cannot remove primaryContact");
+ if (user != null) {
+ users.remove(user);
+ }
+
+ /*
+ * more primaryContact hakiness - nothing says that you can't
+ * remove the user that is the PC...
+ */
+
+ if (!users.contains(primaryContact)) {
+ primaryContact = null;
}
- users.remove(user);
}
public void removeUsers(Collection collection) throws JAXRException
{
- if (collection.contains(primaryContact))
- {
- throw new InvalidRequestException("Cannot remove primaryContact");
+ if (collection != null) {
+ users.removeAll(collection);
}
- users.removeAll(collection);
+
+ /*
+ * more primaryContact hakiness - nothing says that you can't
+ * remove the user that is the PC...
+ */
+
+ if (!users.contains(primaryContact)) {
+ primaryContact = null;
+ }
+
}
public Collection getTelephoneNumbers(String phoneType) throws
JAXRException
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]