taylor 01/07/17 09:41:14 Modified: src/java/org/apache/jetspeed/om/profile BasePSMLDocument.java BaseProfile.java BaseProfileLocator.java Profile.java ProfileLocator.java Log: - added compare functions provided by Atul Dambalker for profile locators Revision Changes Path 1.3 +2 -1 jakarta-jetspeed/src/java/org/apache/jetspeed/om/profile/BasePSMLDocument.java Index: BasePSMLDocument.java =================================================================== RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/om/profile/BasePSMLDocument.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- BasePSMLDocument.java 2001/06/25 10:48:59 1.2 +++ BasePSMLDocument.java 2001/07/17 16:40:59 1.3 @@ -64,7 +64,7 @@ * document. * * @author <a href="mailto:[EMAIL PROTECTED]">Raphaël Luta</a> - * @version $Id: BasePSMLDocument.java,v 1.2 2001/06/25 10:48:59 raphael Exp $ + * @version $Id: BasePSMLDocument.java,v 1.3 2001/07/17 16:40:59 taylor Exp $ */ public class BasePSMLDocument implements PSMLDocument { @@ -96,6 +96,7 @@ */ public BasePSMLDocument( String name, Portlets portlets ) { + this.name = name; this.portlets = portlets; } 1.8 +23 -21 jakarta-jetspeed/src/java/org/apache/jetspeed/om/profile/BaseProfile.java Index: BaseProfile.java =================================================================== RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/om/profile/BaseProfile.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- BaseProfile.java 2001/07/09 07:37:12 1.7 +++ BaseProfile.java 2001/07/17 16:41:01 1.8 @@ -64,32 +64,24 @@ Provides base functionality within a Registry. @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a> -@version $Id: BaseProfile.java,v 1.7 2001/07/09 07:37:12 taylor Exp $ +@version $Id: BaseProfile.java,v 1.8 2001/07/17 16:41:01 taylor Exp $ */ public class BaseProfile extends BaseProfileLocator implements Profile { - private String url; + private PSMLDocument document = null; - private PSMLDocument doc = null; - public BaseProfile() {} - - /** - * Gets the URL for this profile, a path and resource name - * @deprecated - @return The URL of the profile - */ - public String getURL() - { - return this.url; - } - public void setURL(String url) + /** + * @see Object#clone + * @return an instance copy of this object + */ + public Object clone() throws java.lang.CloneNotSupportedException { - this.url = url; + return super.clone(); } /** @@ -111,13 +103,23 @@ { synchronized (this) { - if ((this.doc == null) || (this.doc.getPortlets() == null)) + if ((this.document == null) || (this.document.getPortlets() == null)) { - this.doc = PsmlManager.getDocument(getURL()); + this.document = PsmlManager.getDocument(this); } } - return this.doc; + return this.document; + } + + /* + * Sets the psml document attached to this profile + * + * @param The PSML document for this profile. + */ + public void setDocument(PSMLDocument document) + { + this.document = document; } /** @@ -127,9 +129,9 @@ */ public void store() throws ProfileException { - if (doc!=null) + if (document != null) { - PsmlManager.saveDocument(doc); + PsmlManager.saveDocument(document); } } 1.2 +228 -11 jakarta-jetspeed/src/java/org/apache/jetspeed/om/profile/BaseProfileLocator.java Index: BaseProfileLocator.java =================================================================== RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/om/profile/BaseProfileLocator.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- BaseProfileLocator.java 2001/07/09 07:37:12 1.1 +++ BaseProfileLocator.java 2001/07/17 16:41:03 1.2 @@ -54,7 +54,14 @@ package org.apache.jetspeed.om.profile; +import org.apache.turbine.util.Log; +import org.apache.turbine.om.security.User; +import org.apache.turbine.om.security.Role; +import org.apache.turbine.om.security.Group; +import org.apache.turbine.util.security.UnknownEntityException; +import org.apache.jetspeed.services.JetspeedSecurity; + /** * Interface definition for a Profile Locator. * Locators are used by the profiler to describe the parameters used to locate @@ -62,19 +69,30 @@ * * * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a> - * @version $Id: BaseProfileLocator.java,v 1.1 2001/07/09 07:37:12 taylor Exp $ + * @author <a href="mailto:[EMAIL PROTECTED]">Atul Dambalkar</a> + * @version $Id: BaseProfileLocator.java,v 1.2 2001/07/17 16:41:03 taylor Exp $ */ -public class BaseProfileLocator implements ProfileLocator +public class BaseProfileLocator implements ProfileLocator, Cloneable { // instance state private String name; private String mediaType; private String language; private String country; - private String user; - private String role; - private String group; + private User user = null; + private Role role = null; + private Group group = null; + private boolean anonymous = false; + + /** + * @see Object#clone + * @return an instance copy of this object + */ + public Object clone() throws java.lang.CloneNotSupportedException + { + return super.clone(); + } /* * Gets the resource name parameter for this profile. @@ -97,6 +115,38 @@ } /* + * Gets the anonymous user flag for this profile. + * + * @param The user parameter for this profile. + */ + public boolean getAnonymous() + { + return this.anonymous; + } + + + /* + * Sets the user parameter as the anonymous user + * + * @param anonymous True indicates this is an anonymous user. + */ + public void setAnonymous(boolean anonymous) + { + try + { + this.setUser( JetspeedSecurity.getAnonymousUser() ); + } + catch (UnknownEntityException e) + { + Log.error("Could not get Anonymous user"); + } + finally + { + this.anonymous = anonymous; + } + } + + /* * Gets the media type parameter for this profile. * Media types are values such as html, wml, xml ... * @@ -171,7 +221,7 @@ * * @return The user parameter for this profile. */ - public String getUser() + public User getUser() { return user; } @@ -181,7 +231,7 @@ * * @param The user parameter for this profile. */ - public void setUser(String user) + public void setUser(User user) { this.user = user; } @@ -191,7 +241,7 @@ * * @return The role parameter for this profile. */ - public String getRole() + public Role getRole() { return role; } @@ -201,7 +251,7 @@ * * @param The role parameter for this profile. */ - public void setRole( String role ) + public void setRole( Role role ) { this.role = role; } @@ -211,7 +261,7 @@ * * @return The group parameter for this profile. */ - public String getGroup() + public Group getGroup() { return group; } @@ -221,9 +271,176 @@ * * @param The group parameter for this profile. */ - public void setGroup( String group ) + public void setGroup( Group group ) { this.group = group; } + + /* + * Comparision Functions. Contributed by Atul Dambalkar + */ + + /** + * Define equality criteria for ProfileLocator objects. + * @param obj ProfileLocator object to be compared with. + */ + public boolean equals(Object obj) + { + synchronized (obj) + { + if ( ! ( obj instanceof ProfileLocator ) ) + { + return false; + } + + ProfileLocator locator = (ProfileLocator)obj; + + String name = locator.getName(); + String mediaType = locator.getMediaType(); + String language = locator.getLanguage(); + String country = locator.getCountry(); + Group group = locator.getGroup(); + Role role = locator.getRole(); + + return nameEquals(name) + && mediaTypeEquals(mediaType) + && languageEquals(language) + && countryEquals(country) + && userEquals(locator) + && groupEquals(group) + && roleEquals(role); + } + } + + /** + * Check equality for given User object with this ProfileLocator's User + * object. + */ + private boolean userEquals(ProfileLocator locator) + { + User user = locator.getUser(); + // if either of reference is null return false. + if (exclusiveOr(this.user, user)) + { + return false; + } + // check if both are non-nulls + if (assert(this.user) && assert(user)) + { + return stringEquals(this.user.getUserName(), user.getUserName()); + } + // can be anonymous user + return this.anonymous == locator.getAnonymous(); + } + + /** + * Check equality for given Group object with this ProfileLocator's Group + * object. + */ + private boolean groupEquals(Group group) + { + // if either of reference is null return false. + if (exclusiveOr(this.group, group)) + { + return false; + } + // check if both are non-nulls + if (assert(this.group) && assert(group)) + { + return stringEquals( this.group.getName(), group.getName()); + } + // both are null + return true; + } + + /** + * Check equality for given Role object with this ProfileLocator's Role + * object. + */ + private boolean roleEquals(Role role) + { + // if either of reference is null return false. + if (exclusiveOr(this.role, role)) + { + return false; + } + // check if both are non-nulls + if (assert(this.role) && assert(role)) + { + return stringEquals(this.role.getName(), role.getName()); + } + // both are null + return true; + } + + /** + * Check equality for language object with this ProfileLocator's language + * object. + */ + private boolean languageEquals(String language) + { + return stringEquals(this.language, language); + } + + /** + * Check equality for country object with this ProfileLocator's country + * object. + */ + private boolean countryEquals(String country) + { + return stringEquals(this.country, country); + } + + /** + * Check equality for name object with this ProfileLocator's name + * object. + */ + private boolean nameEquals(String name) + { + return stringEquals(this.name, name); + } + + /** + * Check equality for name object with this ProfileLocator's name + * object. + */ + private boolean mediaTypeEquals(String mediaType) + { + return stringEquals(this.mediaType, mediaType); + } + + /** + * Assert the two String objects and then check the equality. + */ + private boolean stringEquals(String str1, String str2) + { + if (exclusiveOr(str1, str2)) + { + return false; + } + if (assert(str1) && assert(str2)) + { + return str1.equals(str2); + } + // both are null + return true; + } + + /** + * Assert the given object. + */ + private boolean assert(Object object) + { + return object != null; + } + + /** + * Exclusive or the two objects fro their references null-ability. + */ + private boolean exclusiveOr(Object obj1, Object obj2) + { + return (assert(obj1) && !assert(obj2)) + || (!assert(obj1) && assert(obj2)); + } } 1.7 +10 -6 jakarta-jetspeed/src/java/org/apache/jetspeed/om/profile/Profile.java Index: Profile.java =================================================================== RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/om/profile/Profile.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- Profile.java 2001/07/09 07:37:12 1.6 +++ Profile.java 2001/07/17 16:41:04 1.7 @@ -62,7 +62,7 @@ Represents a profile, the interface to a PSML resource. @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a> -@version $Id: Profile.java,v 1.6 2001/07/09 07:37:12 taylor Exp $ +@version $Id: Profile.java,v 1.7 2001/07/17 16:41:04 taylor Exp $ */ public interface Profile extends ProfileLocator @@ -83,13 +83,11 @@ public PSMLDocument getDocument(); /* - * Gets the URL for this profile, a fully qualified local path and resource name + * Sets the psml document attached to this profile * - * @deprecated Will be removed with refactoring of profiler service. - * @return The URL of the profile + * @param The PSML document for this profile. */ - public String getURL(); - public void setURL(String url); + public void setDocument(PSMLDocument document); /* * stores the resource by merging and rewriting the psml file @@ -97,5 +95,11 @@ * @throws ProfileException if an error occurs storing the profile */ public void store() throws ProfileException; + + /** + * @see Object#clone + * @return an instance copy of this object + */ + Object clone() throws java.lang.CloneNotSupportedException; } 1.2 +37 -14 jakarta-jetspeed/src/java/org/apache/jetspeed/om/profile/ProfileLocator.java Index: ProfileLocator.java =================================================================== RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/om/profile/ProfileLocator.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ProfileLocator.java 2001/07/09 07:37:13 1.1 +++ ProfileLocator.java 2001/07/17 16:41:06 1.2 @@ -54,6 +54,9 @@ package org.apache.jetspeed.om.profile; +import org.apache.turbine.om.security.User; +import org.apache.turbine.om.security.Role; +import org.apache.turbine.om.security.Group; /** * Interface definition for a Profile Locator. @@ -62,7 +65,7 @@ * * * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a> - * @version $Id: ProfileLocator.java,v 1.1 2001/07/09 07:37:13 taylor Exp $ + * @version $Id: ProfileLocator.java,v 1.2 2001/07/17 16:41:06 taylor Exp $ */ public interface ProfileLocator @@ -77,7 +80,7 @@ /* * Sets the resource name parameter for this profile. * - * @param The resource name parameter for this profile. + * @param name The resource name parameter for this profile. */ void setName(String name); @@ -93,7 +96,7 @@ * Sets the media type parameter for this profile. * Media types are values such as html, wml, xml ... * - * @param The media type parameter for this profile. + * @param mediaType The media type parameter for this profile. */ void setMediaType(String mediaType); @@ -111,7 +114,7 @@ * Language values are ISO-639 standard language abbreviations * en, fr, de, ... * - * @param The language parameter for this profile. + * @param language The language parameter for this profile. */ void setLanguage(String language); @@ -129,7 +132,7 @@ * Country code values are ISO-3166 standard country code abbreviations. * GB, US, FR, CA, DE, ... * - * @param The country code parameter for this profile. + * @param country The country code parameter for this profile. */ void setCountry(String country); @@ -138,41 +141,61 @@ * * @return The user parameter for this profile. */ - String getUser(); + User getUser(); /* * Sets the user parameter for this profile. * - * @param The user parameter for this profile. + * @param user The user parameter for this profile. */ - void setUser(String user); + void setUser(User user); /* + * Gets the anonymous user flag for this profile. + * + * @return True if this profile is anonymous. + */ + boolean getAnonymous(); + + /* + * Sets the user parameter as the anonymous user + * + * @param anonymous True indicates this is an anonymous user. + */ + void setAnonymous(boolean anonymous); + + /* * Gets the role parameter for this profile. * * @return The role parameter for this profile. */ - String getRole(); + Role getRole(); /* * Sets the role parameter for this profile. * - * @param The role parameter for this profile. + * @param role The role parameter for this profile. */ - void setRole( String role ); + void setRole( Role role ); /* * Gets the group parameter for this profile. * * @return The group parameter for this profile. */ - String getGroup(); + Group getGroup(); /* * Sets the group parameter for this profile. * - * @param The group parameter for this profile. + * @param group The group parameter for this profile. */ - void setGroup( String group ); + void setGroup( Group group ); + + /** + * @see Object#clone + * @return an instance copy of this object + */ + Object clone() throws java.lang.CloneNotSupportedException; } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]