You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by we...@apache.org on 2004/02/04 22:16:31 UTC
cvs commit: jakarta-jetspeed-2/services/registry/src/java/org/apache/jetspeed/om/preference/impl AbstractPreference.java
weaver 2004/02/04 13:16:31
Modified: services/registry/src/java/org/apache/jetspeed/om/preference/impl
AbstractPreference.java
Log:
AbstractPortletPrefernce:
- refactored equals() method
- support for non-OJB colections
- clone support
Revision Changes Path
1.2 +63 -18 jakarta-jetspeed-2/services/registry/src/java/org/apache/jetspeed/om/preference/impl/AbstractPreference.java
Index: AbstractPreference.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/services/registry/src/java/org/apache/jetspeed/om/preference/impl/AbstractPreference.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractPreference.java 12 Jan 2004 06:19:51 -0000 1.1
+++ AbstractPreference.java 4 Feb 2004 21:16:31 -0000 1.2
@@ -63,13 +63,14 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.jetspeed.om.common.MutableDescription;
-import org.apache.jetspeed.om.common.MutableDescriptionSet;
+
import org.apache.jetspeed.om.common.preference.PreferenceComposite;
import org.apache.jetspeed.om.impl.DescriptionImpl;
import org.apache.jetspeed.om.impl.DescriptionSetImpl;
+import org.apache.jetspeed.registry.JetspeedPortletRegistry;
import org.apache.jetspeed.util.HashCodeBuilder;
import org.apache.pluto.om.common.Description;
-import org.apache.pluto.om.common.Preference;
+
/**
* <p>
@@ -82,23 +83,28 @@
* @version $ $
*
*/
-public abstract class AbstractPreference implements PreferenceComposite
+public abstract class AbstractPreference implements PreferenceComposite, Cloneable
{
+ protected String ojbConcreteClass = AbstractPreference.class.getName();
+
private static final Log log = LogFactory.getLog(AbstractPreference.class);
protected String name;
protected boolean readOnly;
-
+
protected int id;
+ protected long parentId;
+
/** a collection of <code>PreferenceValueObjects</code>
* that can be persisted in a unique fashion.
*/
protected List values;
/** Localized Descriptions */
- protected MutableDescriptionSet descriptions;
+ protected Collection descriptions;
+ protected DescriptionSetImpl descCollWrapper = new DescriptionSetImpl(DescriptionImpl.TYPE_PREFERENCE);
/** The type of preference this is either the portlet default or user defined */
protected String type;
@@ -197,13 +203,8 @@
public void setDescription(String description)
{
// TODO: Is this still needed as we are using localized text???
- //this.description = description;
- if (descriptions == null)
- {
- descriptions = new DescriptionSetImpl(MutableDescription.TYPE_PREFERENCE);
- }
-
- descriptions.addDescription(new DescriptionImpl(Locale.getDefault(), description, MutableDescription.TYPE_PREFERENCE));
+ // addDescription(Jetspeed.getDefaultLocale(), description);
+ addDescription(Locale.getDefault(), description);
}
/**
@@ -219,10 +220,13 @@
*/
public boolean equals(Object obj)
{
- if (obj != null && obj instanceof Preference)
+ if (obj != null && obj.getClass().equals(getClass()))
{
- Preference pref = (Preference) obj;
- return pref.getName().equals(this.getName());
+ AbstractPreference pref = (AbstractPreference) obj;
+ boolean sameParent = (pref.parentId == parentId);
+ boolean sameName = (name != null && pref.getName() != null && name.equals(pref.getName()));
+ return sameParent && sameName;
+
}
return false;
@@ -245,9 +249,23 @@
{
if (descriptions == null)
{
- descriptions = new DescriptionSetImpl(MutableDescription.TYPE_PREFERENCE);
+ descriptions = new ArrayList();
+ }
+ descCollWrapper.setInnerCollection(descriptions);
+ try
+ {
+ MutableDescription descObj =
+ (MutableDescription) JetspeedPortletRegistry.getNewObjectInstance(MutableDescription.TYPE_PREFERENCE, true);
+ descObj.setLocale(locale);
+ descObj.setDescription(description);
+ descCollWrapper.addDescription(descObj);
+ }
+ catch (Exception e)
+ {
+ String msg = "Unable to instantiate Description implementor, " + e.toString();
+ log.error(msg, e);
+ throw new IllegalStateException(msg);
}
- descriptions.addDescription(new DescriptionImpl(locale, description, MutableDescription.TYPE_PREFERENCE));
}
/**
@@ -257,7 +275,8 @@
{
if (descriptions != null)
{
- return descriptions.get(locale);
+ descCollWrapper.setInnerCollection(descriptions);
+ return descCollWrapper.get(locale);
}
return null;
}
@@ -376,6 +395,32 @@
return null;
+ }
+
+ /**
+ * @see java.lang.Object#clone()
+ */
+ public Object clone()
+ {
+ try
+ {
+ AbstractPreference clone = (AbstractPreference) getClass().newInstance();
+ clone.name = name;
+ clone.ojbConcreteClass= getClass().getName();
+ clone.id = id;
+ clone.descriptions = descriptions;
+ clone.descCollWrapper = descCollWrapper;
+ clone.parentId = parentId;
+ clone.readOnly = readOnly;
+ clone.type = type;
+ clone.values = values;
+ return clone;
+ }
+ catch (Exception e)
+ {
+ throw new IllegalStateException("Unable to clone this preference: "+e.toString());
+ }
+
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org