svn commit: r678081 [2/3] - in /portals/jetspeed-2/portal/branches/JS2-869: components/jetspeed-portal/src/main/java/org/apache/jetspeed/util/descriptor/ components/jetspeed-registry/src/main/java/JETSPEED-INF/ojb/ components/jetspeed-registry/src/main...

View: New views
1 Messages — Rating Filter:   Alert me  

svn commit: r678081 [2/3] - in /portals/jetspeed-2/portal/branches/JS2-869: components/jetspeed-portal/src/main/java/org/apache/jetspeed/util/descriptor/ components/jetspeed-registry/src/main/java/JETSPEED-INF/ojb/ components/jetspeed-registry/src/main...

by Ate Douma-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Modified: portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/main/java/org/apache/jetspeed/om/portlet/impl/PortletDefinitionImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/main/java/org/apache/jetspeed/om/portlet/impl/PortletDefinitionImpl.java?rev=678081&r1=678080&r2=678081&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/main/java/org/apache/jetspeed/om/portlet/impl/PortletDefinitionImpl.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/main/java/org/apache/jetspeed/om/portlet/impl/PortletDefinitionImpl.java Fri Jul 18 17:17:27 2008
@@ -25,11 +25,11 @@
 import java.util.List;
 import java.util.Locale;
 import java.util.StringTokenizer;
-import java.util.prefs.BackingStoreException;
-import java.util.prefs.Preferences;
 
 import javax.portlet.PreferencesValidator;
 
+import org.apache.jetspeed.Jetspeed;
+import org.apache.jetspeed.components.portletpreferences.PortletPreferencesProvider;
 import org.apache.jetspeed.components.portletregistry.PortletRegistry;
 import org.apache.jetspeed.components.portletregistry.RegistryException;
 import org.apache.jetspeed.factory.PortletFactory;
@@ -54,8 +54,6 @@
 import org.apache.jetspeed.om.impl.PortletParameterSetImpl;
 import org.apache.jetspeed.om.impl.SecurityRoleRefImpl;
 import org.apache.jetspeed.om.impl.SecurityRoleRefSetImpl;
-import org.apache.jetspeed.om.preference.impl.PrefsPreference;
-import org.apache.jetspeed.om.preference.impl.PrefsPreferenceSetImpl;
 import org.apache.jetspeed.util.HashCodeBuilder;
 import org.apache.jetspeed.util.JetspeedLongObjectID;
 import org.apache.pluto.om.common.Description;
@@ -86,14 +84,9 @@
  */
 public class PortletDefinitionImpl implements PortletDefinitionComposite, PreferencesValidatorFactory, Serializable, Support
 {
-    /**
-     * This is a static instance of the PortletREgistry that can be used by
-     * all instances of the PortletDefinitionImpl to support the
-     * PortletDefintionCtrl.store() method.
-     *
-     */
-    protected static PortletRegistry registry;
-    protected static PortletFactory  portletFactory;
+    private static PortletRegistry registry;
+    private static PortletFactory  portletFactory;
+    private static PortletPreferencesProvider portletPreferencesProvider;
     
     private Long id;
     private JetspeedLongObjectID oid;
@@ -130,7 +123,7 @@
 
     /** Metadata property */
     private Collection metadataFields = null;
-    private PrefsPreferenceSetImpl preferenceSet;
+    private PreferenceSetComposite preferenceSet;
 
     private String jetspeedSecurityConstraint = null;
     
@@ -218,28 +211,16 @@
      */
     public PreferenceSet getPreferenceSet()
     {
-        try
+        if (preferenceSet == null)
         {
-            if (preferenceSet == null)
+          
+            if(app == null)
             {
-              
-                if(app == null)
-                {
-                    throw new IllegalStateException("Portlet Application must be defined before preferences can be accessed");
-                }
-                
-                Preferences prefNode = PrefsPreference.createPrefenceNode(this);
-                preferenceSet = new PrefsPreferenceSetImpl(prefNode, this);
+                throw new IllegalStateException("Portlet Application must be defined before preferences can be accessed");
             }
+            retrievePortletPreferencesProvider();
+            preferenceSet = portletPreferencesProvider.getPreferenceSet(this);
         }
-        catch (BackingStoreException e)
-        {
-            String msg = "Preference backing store failed: " + e.toString();
-            IllegalStateException ise = new IllegalStateException(msg);
-            ise.initCause(e);
-            throw ise;
-        }
-
         return preferenceSet;
     }
 
@@ -248,7 +229,7 @@
      */
     public void setPreferenceSet( PreferenceSet preferences )
     {
-        this.preferenceSet = (PrefsPreferenceSetImpl) preferences;
+        this.preferenceSet = (PreferenceSetComposite) preferences;
     }
 
     /**
@@ -290,11 +271,8 @@
      */
     public ClassLoader getPortletClassLoader()
     {
-        if ( portletFactory != null )
-        {
-            return portletFactory.getPortletApplicationClassLoader(app);
-        }
-        return null;
+        retrievePortletFactory();
+        return portletFactory.getPortletApplicationClassLoader(app);
     }
 
     /**
@@ -503,7 +481,7 @@
      */
     public PreferenceComposite addPreference( String name, String[] values )
     {
-        return (PreferenceComposite) ((PrefsPreferenceSetImpl) getPreferenceSet()).add(name, Arrays.asList(values));
+        return (PreferenceComposite) ((PreferenceSetComposite) getPreferenceSet()).add(name, Arrays.asList(values));
     }
 
     public void setPortletIdentifier( String portletIdentifier )
@@ -723,7 +701,7 @@
         }
         return DNListWrapper;
     }
-
+    
     /**
      * <p>
      * store will attempt to perform an atomic persistence call against this
@@ -735,22 +713,24 @@
      */
     public void store() throws IOException
     {
-        if(registry != null)
+        retrievePortletRegistry();
+        try
         {
-            try
-            {
-                registry.savePortletDefinition(this);
-            }
-            catch (RegistryException e)
-            {
-                IOException ioe = new IOException("Failed to store portlet definition: "+e.getMessage());
-                ioe.initCause(e);
-            }
+            registry.savePortletDefinition(this);
         }
-        else
+        catch (RegistryException e)
         {
-            throw new IllegalStateException("The portlet registry for PortletDefinitionImpl has not been set.  "+
-                                             "Please invoke PortletDefinitionImpl.setPortletRegistry before invoking the store() method.");
+            IOException ioe = new IOException("Failed to store portlet definition: "+e.getMessage());
+            ioe.initCause(e);
+        }
+    }
+
+    public void storeChildren()
+    {
+        if (preferenceSet != null)
+        {
+            retrievePortletPreferencesProvider();
+            portletPreferencesProvider.savePreferenceSet(this, preferenceSet);
         }
     }
 
@@ -794,7 +774,9 @@
 
         PreferenceComposite newPref = (PreferenceComposite) ((PreferenceSetComposite) getPreferenceSet()).add(
                 preference.getName(), list);
+        newPref.setReadOnly(Boolean.toString(preference.isReadOnly()));
 
+        // TODO: remove? (not really used/implemented in Jetspeed)
         Iterator descItr = newPref.getDescriptions();
         while (descItr.hasNext())
         {
@@ -932,23 +914,10 @@
         }
     }
     
-    public static void setPortletRegistry(PortletRegistry registry)
-    {
-        PortletDefinitionImpl.registry = registry;
-    }
-
-    public static void setPortletFactory(PortletFactory portletFactory)
-    {
-        PortletDefinitionImpl.portletFactory = portletFactory;
-    }
-
     public PreferencesValidator getPreferencesValidator()
     {
-        if ( portletFactory != null )
-        {
-            return portletFactory.getPreferencesValidator(this);
-        }
-        return null;
+        retrievePortletFactory();
+        return portletFactory.getPreferencesValidator(this);
     }
 
     /* (non-Javadoc)
@@ -966,4 +935,28 @@
     {
         this.jetspeedSecurityConstraint = constraint;
     }
+
+    private void retrievePortletRegistry()
+    {
+        if (registry == null)
+        {
+            registry = (PortletRegistry)Jetspeed.getComponentManager().getComponent("portletRegistry");
+        }
+    }
+
+    private void retrievePortletFactory()
+    {
+        if (portletFactory == null)
+        {
+            portletFactory = (PortletFactory)Jetspeed.getComponentManager().getComponent("portletFactory");
+        }
+    }
+
+    private void retrievePortletPreferencesProvider()
+    {
+        if (portletPreferencesProvider == null)
+        {
+            portletPreferencesProvider = (PortletPreferencesProvider)Jetspeed.getComponentManager().getComponent("portletPreferencesProvider");
+        }
+    }
 }

Added: portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/main/java/org/apache/jetspeed/om/preference/impl/PreferenceImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/main/java/org/apache/jetspeed/om/preference/impl/PreferenceImpl.java?rev=678081&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/main/java/org/apache/jetspeed/om/preference/impl/PreferenceImpl.java (added)
+++ portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/main/java/org/apache/jetspeed/om/preference/impl/PreferenceImpl.java Fri Jul 18 17:17:27 2008
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jetspeed.om.preference.impl;
+
+import java.io.Serializable;
+
+/**
+ * @version $Id$
+ *
+ */
+public class PreferenceImpl implements Serializable
+{
+    private long id;
+    private String applicationName;
+    private String portletName;
+    private String name;
+    
+    public long getId()
+    {
+        return id;
+    }
+    public void setId(long id)
+    {
+        this.id = id;
+    }
+    public String getApplicationName()
+    {
+        return applicationName;
+    }
+    public void setApplicationName(String applicationName)
+    {
+        this.applicationName = applicationName;
+    }
+    public String getPortletName()
+    {
+        return portletName;
+    }
+    public void setPortletName(String portletName)
+    {
+        this.portletName = portletName;
+    }
+    public String getName()
+    {
+        return name;
+    }
+    public void setName(String name)
+    {
+        this.name = name;
+    }
+    
+    public int hashCode()
+    {
+        return applicationName.hashCode()+portletName.hashCode()+name.hashCode();
+    }
+
+    public boolean equals(Object object)
+    {
+        if (this == object)
+        {
+            return true;
+        }
+        if ((object instanceof PreferenceImpl))
+        {
+            PreferenceImpl other = (PreferenceImpl)object;            
+            return applicationName.equals(other.applicationName) && portletName.equals(other.applicationName) && name.equals(other.name);
+        }
+        return false;
+    }
+}

Propchange: portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/main/java/org/apache/jetspeed/om/preference/impl/PreferenceImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/main/java/org/apache/jetspeed/om/preference/impl/PreferenceImpl.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/main/java/org/apache/jetspeed/om/preference/impl/PreferenceImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/main/java/org/apache/jetspeed/om/preference/impl/PreferenceSetImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/main/java/org/apache/jetspeed/om/preference/impl/PreferenceSetImpl.java?rev=678081&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/main/java/org/apache/jetspeed/om/preference/impl/PreferenceSetImpl.java (added)
+++ portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/main/java/org/apache/jetspeed/om/preference/impl/PreferenceSetImpl.java Fri Jul 18 17:17:27 2008
@@ -0,0 +1,257 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jetspeed.om.preference.impl;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+
+import javax.portlet.PreferencesValidator;
+
+import org.apache.jetspeed.cache.DistributedCacheObject;
+import org.apache.jetspeed.om.common.preference.PreferenceComposite;
+import org.apache.jetspeed.om.common.preference.PreferenceSetComposite;
+import org.apache.jetspeed.om.common.preference.PreferencesValidatorFactory;
+import org.apache.pluto.om.common.Description;
+import org.apache.pluto.om.common.Preference;
+
+/**
+ * @version $Id$
+ *
+ */
+public class PreferenceSetImpl implements PreferenceSetComposite, DistributedCacheObject
+{
+    /** The serial uid. */
+    private static final long serialVersionUID = -1254944161724683301L;
+
+    public static class PreferenceImpl implements Preference,PreferenceComposite, Serializable
+    {
+        /** The serial uid. */
+        private static final long serialVersionUID = 6942546526156122157L;
+        
+        private long id;
+        private String name;
+        private boolean readOnly;
+        private List<String> values;
+        
+        private PreferenceImpl(long id, String name, List<String> values)
+        {
+            this.id = id;
+            this.name = name;
+            if (values == null)
+            {
+                this.values = new ArrayList<String>();
+            }
+            else
+            {
+                if (values.size() == Short.MAX_VALUE)
+                {
+                    throw new UnsupportedOperationException("Too many values");
+                }
+                this.values = new ArrayList<String>(values);
+            }
+        }
+        
+        public PreferenceImpl(PreferenceImpl other)
+        {
+            this.id = other.id;
+            this.name = other.name;
+            this.readOnly = other.readOnly;
+            this.values = new ArrayList<String>(other.values);
+        }
+        
+        public long getId()
+        {
+            return id;
+        }
+        
+        public String getName()
+        {
+            return name;
+        }
+
+        public Iterator<String> getValues()
+        {
+            return values.iterator();
+        }
+
+        public boolean isReadOnly()
+        {
+            return readOnly;
+        }
+
+        public boolean isValueSet()
+        {
+            return !values.isEmpty();
+        }
+
+        public void addDescription(Locale locale, String Description)
+        {
+            // TODO: remove? (not really used/implemented in Jetspeed)
+        }
+
+        public void addValue(String value)
+        {
+            if (values.size() == Short.MAX_VALUE)
+            {
+                throw new UnsupportedOperationException("Too many values");
+            }
+            values.add(value);
+        }
+
+        public Description getDescription(Locale locale)
+        {
+            // TODO: remove? (not really used/implemented in Jetspeed)
+            return null;
+        }
+
+        public Iterator getDescriptions()
+        {
+            // TODO: remove? (not really used/implemented in Jetspeed)
+            return Collections.EMPTY_LIST.iterator();
+        }
+
+        public List<String> getValuesList()
+        {
+            return new ArrayList<String>(values);
+        }
+
+        public void setName(String name)
+        {
+            this.name = name;
+        }
+
+        public void setReadOnly(String value)
+        {
+            readOnly = Boolean.parseBoolean(value);
+        }
+
+        public void setValues(List values)
+        {
+            if (values != null && values.size() == Short.MAX_VALUE)
+            {
+                throw new UnsupportedOperationException("Too many values");
+            }
+            
+            this.values.clear();
+            if (values != null && !values.isEmpty())
+            {
+                this.values.addAll(values);
+            }
+        }
+        
+        public boolean equals(PreferenceImpl other)
+        {
+            if (other == null && name.equals(other.name) && readOnly == other.readOnly && values.size() == other.values.size() )
+            {
+                String a;
+                String b;
+                for (int i = 0, size = values.size(); i < size; i++)
+                {
+                    a = values.get(i);
+                    b = other.values.get(i);
+                    if ((a == null && b != null) || (a != null && !a.equals(b)))
+                    {
+                        return false;
+                    }
+                }
+            }
+            return false;
+        }
+    }
+    
+    private PreferencesValidatorFactory validatorFactory;
+    private HashMap<String,PreferenceImpl> prefs;
+    
+    public PreferenceSetImpl()
+    {
+        prefs = new HashMap<String,PreferenceImpl>();
+    }
+    
+    public PreferenceSetImpl(PreferencesValidatorFactory validatorFactory)
+    {
+        this();
+        this.validatorFactory = validatorFactory;
+    }
+    
+    public PreferenceSetImpl(PreferenceSetImpl src)
+    {
+        prefs = new HashMap<String,PreferenceImpl>(src.prefs.size());
+        for (Map.Entry<String,PreferenceImpl> entry: src.prefs.entrySet())
+        {
+            prefs.put(entry.getKey(), new PreferenceImpl(entry.getValue()));
+        }
+    }
+    
+    public Set<String> getNames()
+    {
+        return prefs.keySet();
+    }
+
+    public int size()
+    {
+        return prefs.size();
+    }
+
+    public PreferenceImpl get(String name)
+    {
+        return prefs.get(name);
+    }
+
+    public PreferencesValidator getPreferencesValidator()
+    {
+        return validatorFactory != null ? validatorFactory.getPreferencesValidator() : null;
+    }
+
+    public Iterator iterator()
+    {
+        return prefs.values().iterator();
+    }
+
+    public PreferenceImpl add(String name, List values)
+    {
+        return add(-1, name, values);
+    }
+
+    PreferenceImpl add(long id, String name, List values)
+    {
+        PreferenceImpl pref = new PreferenceImpl(id, name, values);
+        prefs.put(name, pref);
+        return pref;
+    }
+
+    public PreferenceImpl remove(String name)
+    {
+        return prefs.remove(name);
+    }
+
+    public void remove(Preference pref)
+    {
+        prefs.remove(pref.getName());
+    }
+
+    public void notifyChange(int action)
+    {
+    }
+}

Propchange: portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/main/java/org/apache/jetspeed/om/preference/impl/PreferenceSetImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/main/java/org/apache/jetspeed/om/preference/impl/PreferenceSetImpl.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/main/java/org/apache/jetspeed/om/preference/impl/PreferenceSetImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/main/java/org/apache/jetspeed/om/preference/impl/PreferenceValueImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/main/java/org/apache/jetspeed/om/preference/impl/PreferenceValueImpl.java?rev=678081&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/main/java/org/apache/jetspeed/om/preference/impl/PreferenceValueImpl.java (added)
+++ portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/main/java/org/apache/jetspeed/om/preference/impl/PreferenceValueImpl.java Fri Jul 18 17:17:27 2008
@@ -0,0 +1,146 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jetspeed.om.preference.impl;
+
+import java.io.Serializable;
+
+import org.apache.ojb.broker.PersistenceBroker;
+import org.apache.ojb.broker.PersistenceBrokerAware;
+import org.apache.ojb.broker.PersistenceBrokerException;
+
+/**
+ * @version $Id$
+ *
+ */
+public class PreferenceValueImpl implements Serializable, PersistenceBrokerAware
+{
+    private long prefId;
+    private short index;
+    private String userName;
+    private Long entityOid;
+    private String entityId;
+    private boolean readOnly;
+    private boolean nullValue;
+    private String value;
+    
+    public long getPrefId()
+    {
+        return prefId;
+    }
+    public void setPrefId(long prefId)
+    {
+        this.prefId = prefId;
+    }
+    public short getIndex()
+    {
+        return index;
+    }
+    public void setIndex(short index)
+    {
+        this.index = index;
+    }
+    public String getUserName()
+    {
+        return userName;
+    }
+    public void setUserName(String userName)
+    {
+        this.userName = userName;
+    }
+    public Long getEntityOid()
+    {
+        return entityOid;
+    }
+    public void setEntityOid(Long entityOid)
+    {
+        this.entityOid = entityOid;
+    }
+    public String getEntityId()
+    {
+        return entityId;
+    }
+    public void setEntityId(String entityId)
+    {
+        this.entityId = entityId;
+    }
+    public boolean isReadOnly()
+    {
+        return readOnly;
+    }
+    public void setReadOnly(boolean readOnly)
+    {
+        this.readOnly = readOnly;
+    }
+    public String getValue()
+    {
+        return value;
+    }
+    public void setValue(String value)
+    {
+        this.value = value;
+        nullValue = value == null;
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.ojb.broker.PersistenceBrokerAware#afterDelete(org.apache.ojb.broker.PersistenceBroker)
+     */
+    public void afterDelete(PersistenceBroker arg0) throws PersistenceBrokerException
+    {
+    }
+    /* (non-Javadoc)
+     * @see org.apache.ojb.broker.PersistenceBrokerAware#afterInsert(org.apache.ojb.broker.PersistenceBroker)
+     */
+    public void afterInsert(PersistenceBroker arg0) throws PersistenceBrokerException
+    {
+    }
+    /* (non-Javadoc)
+     * @see org.apache.ojb.broker.PersistenceBrokerAware#afterLookup(org.apache.ojb.broker.PersistenceBroker)
+     */
+    public void afterLookup(PersistenceBroker arg0) throws PersistenceBrokerException
+    {
+        if (!nullValue && value == null)
+        {
+            value = "";
+        }
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.ojb.broker.PersistenceBrokerAware#afterUpdate(org.apache.ojb.broker.PersistenceBroker)
+     */
+    public void afterUpdate(PersistenceBroker arg0) throws PersistenceBrokerException
+    {
+    }
+    /* (non-Javadoc)
+     * @see org.apache.ojb.broker.PersistenceBrokerAware#beforeDelete(org.apache.ojb.broker.PersistenceBroker)
+     */
+    public void beforeDelete(PersistenceBroker arg0) throws PersistenceBrokerException
+    {
+    }
+    /* (non-Javadoc)
+     * @see org.apache.ojb.broker.PersistenceBrokerAware#beforeInsert(org.apache.ojb.broker.PersistenceBroker)
+     */
+    public void beforeInsert(PersistenceBroker arg0) throws PersistenceBrokerException
+    {
+    }
+    /* (non-Javadoc)
+     * @see org.apache.ojb.broker.PersistenceBrokerAware#beforeUpdate(org.apache.ojb.broker.PersistenceBroker)
+     */
+    public void beforeUpdate(PersistenceBroker arg0) throws PersistenceBrokerException
+    {
+    }
+}

Propchange: portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/main/java/org/apache/jetspeed/om/preference/impl/PreferenceValueImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/main/java/org/apache/jetspeed/om/preference/impl/PreferenceValueImpl.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/main/java/org/apache/jetspeed/om/preference/impl/PreferenceValueImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/main/java/org/apache/jetspeed/serializer/JetspeedRegistrySerializer.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/main/java/org/apache/jetspeed/serializer/JetspeedRegistrySerializer.java?rev=678081&r1=678080&r2=678081&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/main/java/org/apache/jetspeed/serializer/JetspeedRegistrySerializer.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/main/java/org/apache/jetspeed/serializer/JetspeedRegistrySerializer.java Fri Jul 18 17:17:27 2008
@@ -16,20 +16,19 @@
  */
 package org.apache.jetspeed.serializer;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.Map;
-import java.util.Vector;
-import java.util.prefs.Preferences;
 
 import org.apache.commons.logging.Log;
 import org.apache.jetspeed.components.portletentity.PortletEntityAccessComponent;
+import org.apache.jetspeed.components.portletpreferences.PortletPreferencesProvider;
 import org.apache.jetspeed.components.portletregistry.PortletRegistry;
 import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
 import org.apache.jetspeed.om.common.portlet.MutablePortletEntity;
 import org.apache.jetspeed.om.common.portlet.PortletApplication;
-import org.apache.jetspeed.om.preference.impl.PrefsPreference;
-import org.apache.jetspeed.om.preference.impl.PrefsPreferenceSetImpl;
+import org.apache.jetspeed.om.common.preference.PreferenceSetComposite;
 import org.apache.jetspeed.search.SearchEngine;
 import org.apache.jetspeed.serializer.objects.JSApplication;
 import org.apache.jetspeed.serializer.objects.JSApplications;
@@ -37,6 +36,7 @@
 import org.apache.jetspeed.serializer.objects.JSEntity;
 import org.apache.jetspeed.serializer.objects.JSEntityPreference;
 import org.apache.jetspeed.serializer.objects.JSEntityPreferences;
+import org.apache.jetspeed.serializer.objects.JSNVPElement;
 import org.apache.jetspeed.serializer.objects.JSNVPElements;
 import org.apache.jetspeed.serializer.objects.JSPortlet;
 import org.apache.jetspeed.serializer.objects.JSPortlets;
@@ -56,6 +56,7 @@
     protected PortletEntityAccessComponent entityAccess;
 
     protected PortletRegistry registry;
+    protected PortletPreferencesProvider prefsProvider;
     protected SearchEngine searchEngine;
 
     
@@ -64,11 +65,12 @@
      * @param entityAccess
      * @param searchEngine
      */
-    public JetspeedRegistrySerializer(PortletRegistry registry, PortletEntityAccessComponent entityAccess,
+    public JetspeedRegistrySerializer(PortletRegistry registry, PortletEntityAccessComponent entityAccess, PortletPreferencesProvider prefsProvider,
             SearchEngine searchEngine)
     {
         this.registry = registry;
         this.entityAccess = entityAccess;
+        this.prefsProvider = prefsProvider;
         this.searchEngine = searchEngine;
     }
 
@@ -213,23 +215,40 @@
             if ((preferences == null) || (preferences.size() == 0))
                 return;
 
-            // since I do have preferences let us make sure we have a root node
-
-            String rootForEntity = MutablePortletEntity.PORTLET_ENTITY_ROOT + "/" + portletEntity.getId();
             try
             {
-                Preferences.userRoot().node(rootForEntity); // will create it if it
-                // doesn't exist
 
                 Iterator it = preferences.iterator();
                 while (it.hasNext())
                 {
                     JSEntityPreference preference = (JSEntityPreference) it.next();
-
-                    // do we have preferences for this one?
-                    importPreferenceNode(preference, portletEntity, settings, log);
+                    
+                    String userName = preference.getName();
+                    PreferenceSetComposite preferenceSet = prefsProvider.getPreferenceSet(portletEntity, userName);
+                    for (Object name : preferenceSet.getNames())
+                    {
+                        preferenceSet.remove((String)name);
+                    }
+                    String name = null;
+                    ArrayList<String> values = null;
+                    for ( JSNVPElement element : preference.getPreferences().getValues() )
+                    {
+                        if (!element.getKey().equals(name))
+                        {
+                            if (name != null)
+                            {
+                                preferenceSet.add(name, values);
+                            }
+                            values = new ArrayList<String>();
+                        }
+                        values.add(element.getValue());
+                    }
+                    if (name != null)
+                    {
+                        preferenceSet.add(name, values);
+                    }
+                    prefsProvider.savePreferenceSet(portletEntity, userName, preferenceSet);
                 }
-
             }
             catch (Exception e)
             {
@@ -239,51 +258,6 @@
         }
     }
 
-    private void importPreferenceNode(JSEntityPreference preference, MutablePortletEntity entity, Map settings, Log log)
-    {
-
-        String child = preference.getName();
-
-        String prefNodePath = MutablePortletEntity.PORTLET_ENTITY_ROOT + "/" + entity.getId() + "/" + child + "/"
-                + PrefsPreference.PORTLET_PREFERENCES_ROOT;
-        Preferences prefNode = Preferences.userRoot().node(prefNodePath);
-
-        if (prefNode == null)
-            return;
-
-        JSNVPElements prefList = preference.getPreferences();
-        try
-        {
-            PrefsPreferenceSetImpl preferenceSet = new PrefsPreferenceSetImpl(prefNode);
-
-            Iterator it = prefList.getMyMap().keySet().iterator();
-
-            while (it.hasNext())
-            {
-                String key = (String) it.next();
-                String value = (String) prefList.getMyMap().get(key);
-                Preference p = preferenceSet.get(key);
-                if ((p == null) || isSettingSet(settings, JetspeedSerializer.KEY_OVERWRITE_EXISTING))
-                {
-
-                    Vector v = new Vector();
-                    v.add(value);
-                    preferenceSet.add(key, v);
-                    log.debug("Entity " + entity.getId() + " updated with preference " + key + "=" + value);
-                }
-            }
-            preferenceSet.flush();
-            return;
-        }
-        catch (Exception e)
-        {
-            log.error(e);
-            return;
-
-        }
-
-    }
-
     private void exportEntities(JSSnapshot snapshot, Map settings, Log log) throws SerializerException
     {
         Collection col = registry.getPortletApplications();
@@ -417,83 +391,40 @@
         
         if (isSettingSet(settings, JetspeedSerializer.KEY_PROCESS_USER_PREFERENCES))
         {
-            String rootForEntity = MutablePortletEntity.PORTLET_ENTITY_ROOT + "/" + entity.getId();
-            try
-            {
-                if (Preferences.userRoot().nodeExists(rootForEntity))
+            JSEntityPreferences entityPreferences = new JSEntityPreferences();
+            Iterator<String> userNames = prefsProvider.getUserNames(entity);
+            while (userNames.hasNext())
+            {
+                String userName = userNames.next();
+                PreferenceSetComposite preferenceSet = prefsProvider.getPreferenceSet(entity, userNames.next());
+                JSEntityPreference userPreference = new JSEntityPreference();
+                userPreference.setName(userName);
+                Iterator<Preference> preferences = preferenceSet.iterator();
+                JSNVPElements v = new JSNVPElements();
+                while (preferences.hasNext())
                 {
-                    Preferences prefNode = Preferences.userRoot().node(rootForEntity);
-                    String[] children = prefNode.childrenNames();
-                    if ((children != null) && (children.length > 0))
+                    Preference p = preferences.next();
+                    Iterator<String> values = p.getValues();
+                    while (values.hasNext())
                     {
-                        JSEntityPreferences preferences = new JSEntityPreferences();
-
-                        for (int i = 0; i < children.length; i++)
-                        {
-                            JSEntityPreference preference = exportPreferenceNode(entity, children[i], settings, log);
-                            if (preference != null)
-                            {
-                                preferences.add(preference);
-                            }
-                        }
-                        if (!preferences.isEmpty())
-                        {
-                            log.debug("processed preferences for entity=" + entity.getId());
-                            jsEntity.setEntityPreferences(preferences);
-                        }
+                        JSNVPElement element = new JSNVPElement();
+                        element.setKey(p.getName());
+                        element.setValue(values.next());
+                        v.add(element);
                     }
                 }
-            }
-            catch (Exception e)
-            {
-                log.error(e);
-                jsEntity = null;
-            }
-        }
-        return jsEntity;
-    }
-
-    JSEntityPreference exportPreferenceNode(MutablePortletEntity entity, String child, Map settings, Log log)
-    {
-        String prefNodePath = MutablePortletEntity.PORTLET_ENTITY_ROOT + "/" + entity.getId() + "/" + child + "/"
-                + PrefsPreference.PORTLET_PREFERENCES_ROOT;
-        Preferences prefNode = Preferences.userRoot().node(prefNodePath);
-
-        if (prefNode == null)
-            return null;
-        JSEntityPreference preference = new JSEntityPreference();
-        preference.setName(child);
-
-        try
-        {
-            PrefsPreferenceSetImpl preferenceSet = new PrefsPreferenceSetImpl(prefNode);
-            if (preferenceSet.size() == 0)
-                return null;
-            Iterator it = preferenceSet.iterator();
-            JSNVPElements v = new JSNVPElements();
-
-            while (it.hasNext())
-            {
-                Preference pref = (Preference) it.next();
-                String name = pref.getName();
-                Iterator ii = pref.getValues();
-                while (ii.hasNext())
+                if (v.size() > 0)
                 {
-                    Object o = ii.next();
-                    v.add(name, o.toString());
+                    userPreference.setPreferences(v);
+                    entityPreferences.add(userPreference);
+                }
+                if (!entityPreferences.isEmpty())
+                {
+                    log.debug("processed preferences for entity=" + entity.getId());
+                    jsEntity.setEntityPreferences(entityPreferences);
                 }
             }
-            if (v.size() > 0)
-            {
-                preference.setPreferences(v);
-                return preference;
-            }
-            return null;
-        }
-        catch (Exception e)
-        {
-            log.error(e);
-            return null;
         }
+        return jsEntity;
     }
 }

Modified: portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/test/java/org/apache/jetspeed/components/portletentity/TestPortletEntityDAO.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/test/java/org/apache/jetspeed/components/portletentity/TestPortletEntityDAO.java?rev=678081&r1=678080&r2=678081&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/test/java/org/apache/jetspeed/components/portletentity/TestPortletEntityDAO.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/test/java/org/apache/jetspeed/components/portletentity/TestPortletEntityDAO.java Fri Jul 18 17:17:27 2008
@@ -1,290 +1,323 @@
-/*
+/*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
  * this work for additional information regarding copyright ownership.
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.jetspeed.components.portletentity;
-
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Locale;
-import java.util.prefs.Preferences;
-
-import org.apache.jetspeed.components.portletregistry.PortletRegistry;
-import org.apache.jetspeed.components.util.DatasourceEnabledSpringTestCase;
-import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
-import org.apache.jetspeed.om.common.portlet.MutablePortletEntity;
-import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite;
-import org.apache.jetspeed.om.common.preference.PreferenceComposite;
-import org.apache.jetspeed.om.common.preference.PreferenceSetComposite;
-import org.apache.jetspeed.om.page.ContentFragment;
-import org.apache.jetspeed.om.page.Fragment;
-import org.apache.jetspeed.om.portlet.impl.PortletApplicationDefinitionImpl;
-import org.apache.jetspeed.om.portlet.impl.PortletDefinitionImpl;
-import org.apache.jetspeed.om.servlet.impl.WebApplicationDefinitionImpl;
-import org.apache.jetspeed.util.JetspeedObjectID;
-import org.apache.pluto.om.portlet.PortletApplicationDefinition;
-import org.apache.pluto.om.portlet.PortletDefinitionList;
-import org.jmock.Mock;
-import org.jmock.core.matcher.InvokeAtLeastOnceMatcher;
-import org.jmock.core.stub.ReturnStub;
-
-/**
- * <p>
- * TestPortletEntityDAO
- * </p>
- *
- * @author <a href="mailto:weaver@...">Scott T. Weaver</a>
- * @version $Id: TestPortletEntityDAO.java,v 1.3 2005/05/24 14:43:19 ate Exp $
- */
-public class TestPortletEntityDAO extends DatasourceEnabledSpringTestCase
-{
-    private static final String TEST_APP = "EntityTestApp";
-
-    private static final String TEST_PORTLET = "EntityTestPortlet";
-
-    private static final String TEST_ENTITY = "user5/entity-9";
-
-    private PersistenceBrokerPortletEntityAccess entityAccess = null;
-
-    private PortletRegistry registry;
-
-    protected void setUp() throws Exception
-    {
-        super.setUp();
-        this.registry = (PortletRegistry) scm.getComponent("portletRegistry");
-        this.entityAccess = (PersistenceBrokerPortletEntityAccess) scm.getComponent("portletEntityAccessImpl");
-
-        teardownTestData();
-        setupTestData();
-    }
-
-    protected void tearDown() throws Exception
-    {
-        teardownTestData();
-        super.tearDown();
-    }
-
-    public void test1() throws Exception
-    {
-        assertNotNull(this.entityAccess);
-        assertNotNull(this.registry);
-    }
-
-    public void testEntities() throws Exception
-    {
-        PortletApplicationDefinition pa = registry.getPortletApplication(TEST_APP);
-        assertNotNull("Portlet Application", pa);
-        System.out.println("pa = " + pa.getId());
-        PortletDefinitionList portlets = pa.getPortletDefinitionList(); // .get(JetspeedObjectID.createFromString(TEST_PORTLET));
-        Iterator pi = portlets.iterator();
-        PortletDefinitionComposite pd = null;
-        while (pi.hasNext())
-        {
-            pd = (PortletDefinitionComposite) pi.next();
-            assertTrue("Portlet Def not found", pd.getName().equals("EntityTestPortlet"));
-        }
-        assertNotNull("Portlet Def is null", pd);
-
-        Mock mockf1 = new Mock(Fragment.class);
-        mockf1.expects(new InvokeAtLeastOnceMatcher()).method("getName").will(new ReturnStub(pd.getUniqueName()));
-        mockf1.expects(new InvokeAtLeastOnceMatcher()).method("getId").will(new ReturnStub(TEST_ENTITY));
-        ContentFragment f1 = new ContentFragmentTestImpl((Fragment) mockf1.proxy(), new HashMap());
-
-        MutablePortletEntity entity = entityAccess
-                .generateEntityFromFragment(new ContentFragmentTestImpl(f1, new HashMap()));
-        PreferenceSetComposite prefs = (PreferenceSetComposite) entity.getPreferenceSet();
-        prefs.remove("pref1");
-        assertNotNull(prefs);
-        assertNull(prefs.get("pref1"));
-
-        // test adding a pref
-        prefs.add("pref1", Arrays.asList(new String[]
-        { "1" }));
-        assertNotNull(prefs.get("pref1"));
-
-        // Remove should return the deleted pref
-        assertNotNull(prefs.remove("pref1"));
-
-        // Should be gone
-        assertNull(prefs.get("pref1"));
-
-        // Add it back so we can test tole back
-        prefs.add("pref1", Arrays.asList(new String[]
-        { "1" }));
-
-        entityAccess.storePortletEntity(entity);
-
-        prefs = (PreferenceSetComposite) entity.getPreferenceSet();
-
-        assertNotNull(prefs.get("pref1"));
-
-        PreferenceComposite pref = (PreferenceComposite) prefs.get("pref1");
-
-        assertEquals("1", pref.getValueAt(0));
-
-        pref.setValueAt(0, "2");
-
-        assertEquals("2", pref.getValueAt(0));
-
-        prefs.add("pref2", Arrays.asList(new String[]
-        { "2", "3" }));
-
-        entity.store();
-
-        PreferenceComposite pref2 = (PreferenceComposite) prefs.get("pref2");
-
-        assertNotNull(pref2);
-
-        Iterator prefsValues = pref2.getValues();
-        int count = 0;
-        while (prefsValues.hasNext())
-        {
-            prefsValues.next();
-            count++;
-        }
-
-        assertEquals(2, count);
-
-        pref2.addValue("4");
-        prefsValues = pref2.getValues();
-        count = 0;
-        while (prefsValues.hasNext())
-        {
-            assertEquals(String.valueOf(count + 2), prefsValues.next());
-            count++;
-        }
-        assertEquals(3, count);
-
-        // testing preferences null values assignments fix, issue JS2-607
-        pref2.setValueAt(0, null);        
-        assertNull("pref2.value[0] should be null", pref2.getValueAt(0));        
-        String[] values = pref2.getValueArray();
-        assertEquals(3, values.length);
-        assertNull("pref2.value[0] should be null", values[0]);
-        assertEquals("3", values[1]);
-        pref2.setValues(new String[]{"2",null,"3"});
-        assertNull("pref2.value[1] should be null", pref2.getValueAt(1));
-        values = pref2.getValueArray();
-        assertEquals(3, values.length);
-        assertEquals("2", values[0]);
-        assertNull("pref2.value[1] should be null", values[1]);
-        assertEquals("3", values[2]);
-        assertTrue(pref2.isValueSet());
-        pref2.setValues((String[])null);
-        assertFalse(pref2.isValueSet());
-        assertTrue(pref2.getValueArray().length == 0);
-        pref2.setValues(new String[]{});
-        assertFalse(pref2.isValueSet());
-        assertTrue(pref2.getValueArray().length == 0);
-
-        MutablePortletEntity entity2 = entityAccess.getPortletEntityForFragment(f1);
-        assertTrue("entity id ", entity2.getId().toString().equals(TEST_ENTITY));
-        assertNotNull("entity's portlet ", entity2.getPortletDefinition());
-        mockf1.verify();
-
-        Mock mockf2 = new Mock(Fragment.class);
-        mockf2.expects(new InvokeAtLeastOnceMatcher()).method("getName").will(new ReturnStub(pd.getUniqueName()));
-        ContentFragment f2 = new ContentFragmentTestImpl((Fragment) mockf2.proxy(), new HashMap());
-
-        MutablePortletEntity entity5 = entityAccess.newPortletEntityInstance(pd);
-
-        System.out.println("before storing entity: " + entity5.getId());
-
-        entityAccess.storePortletEntity(entity5);
-        System.out.println("store done: " + entity5.getId());
-        mockf2.expects(new InvokeAtLeastOnceMatcher()).method("getId").will(new ReturnStub(entity5.getId().toString()));
-
-        MutablePortletEntity entity6 = entityAccess.getPortletEntityForFragment(f2);
-        assertNotNull(entity6);
-        System.out.println("reget : " + entity6.getId());
-
-        entityAccess.removePortletEntity(entity6);
-
-    }
-
-    private void teardownTestData() throws Exception
-    {
-
-        JetspeedObjectID objId = JetspeedObjectID.createFromString(TEST_ENTITY);
-        MutablePortletEntity entity = entityAccess.getPortletEntity(objId);
-        System.out.println("entity == " + entity);
-
-        if (entity != null)
-        {
-            entityAccess.removePortletEntity(entity);
-        }
-
-        PortletApplicationDefinition pa = registry.getPortletApplication(TEST_APP);
-        System.out.println("pa == " + pa);
-        if (pa != null)
-        {
-            registry.removeApplication(pa);
-        }
-
-        if (Preferences.systemRoot().nodeExists(MutablePortletApplication.PREFS_ROOT))
-        {
-            Preferences.systemRoot().node(MutablePortletApplication.PREFS_ROOT).removeNode();
-        }
-
-        if (Preferences.userRoot().nodeExists(PortletDefinitionComposite.PORTLETS_PREFS_ROOT))
-        {
-            Preferences.userRoot().node(PortletDefinitionComposite.PORTLETS_PREFS_ROOT).removeNode();
-        }
-
-        if (Preferences.userRoot().nodeExists(MutablePortletEntity.PORTLET_ENTITY_ROOT))
-        {
-            Preferences.userRoot().node(MutablePortletEntity.PORTLET_ENTITY_ROOT).removeNode();
-        }
-
-    }
-
-    private void setupTestData() throws Exception
-    {
-
-        PortletApplicationDefinitionImpl app = new PortletApplicationDefinitionImpl();
-        app.setName(TEST_APP);
-        app.setApplicationIdentifier(TEST_APP);
-
-        WebApplicationDefinitionImpl webApp = new WebApplicationDefinitionImpl();
-        webApp.setContextRoot("/app1");
-        webApp.addDescription(Locale.FRENCH, "Description: Le fromage est dans mon pantalon!");
-        webApp.addDisplayName(Locale.FRENCH, "Display Name: Le fromage est dans mon pantalon!");
-
-        PortletDefinitionComposite portlet = new PortletDefinitionImpl();
-        portlet.setClassName("org.apache.Portlet");
-        portlet.setName(TEST_PORTLET);
-        portlet.addDescription(Locale.getDefault(), "Portlet description.");
-        portlet.addDisplayName(Locale.getDefault(), "Portlet display Name.");
-
-        portlet.addInitParameter("testparam", "test value", "This is a test portlet parameter", Locale.getDefault());
-
-        app.addPortletDefinition(portlet);
-
-        app.setWebApplicationDefinition(webApp);
-
-        PreferenceSetComposite prefSet = (PreferenceSetComposite) portlet.getPreferenceSet();
-        prefSet.add("pref1", Arrays.asList(new String[]
-        { "1" }));
-
-        registry.registerPortletApplication(app);
-    }
-
-    protected String[] getConfigurations()
-    {
-        return new String[]
-        { "transaction.xml", "registry-test.xml", "prefs.xml", "cache.xml" };
-    }
-}
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.components.portletentity;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.prefs.Preferences;
+
+import org.apache.jetspeed.Jetspeed;
+import org.apache.jetspeed.components.portletregistry.PortletRegistry;
+import org.apache.jetspeed.components.util.DatasourceEnabledSpringTestCase;
+import org.apache.jetspeed.engine.MockJetspeedEngine;
+import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
+import org.apache.jetspeed.om.common.portlet.MutablePortletEntity;
+import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite;
+import org.apache.jetspeed.om.common.preference.PreferenceComposite;
+import org.apache.jetspeed.om.common.preference.PreferenceSetComposite;
+import org.apache.jetspeed.om.page.ContentFragment;
+import org.apache.jetspeed.om.page.Fragment;
+import org.apache.jetspeed.om.portlet.impl.PortletApplicationDefinitionImpl;
+import org.apache.jetspeed.om.portlet.impl.PortletDefinitionImpl;
+import org.apache.jetspeed.om.servlet.impl.WebApplicationDefinitionImpl;
+import org.apache.jetspeed.util.JetspeedObjectID;
+import org.apache.pluto.om.portlet.PortletApplicationDefinition;
+import org.apache.pluto.om.portlet.PortletDefinitionList;
+import org.jmock.Mock;
+import org.jmock.core.matcher.InvokeAtLeastOnceMatcher;
+import org.jmock.core.stub.ReturnStub;
+
+/**
+ * <p>
+ * TestPortletEntityDAO
+ * </p>
+ *
+ * @author <a href="mailto:weaver@...">Scott T. Weaver</a>
+ * @version $Id: TestPortletEntityDAO.java,v 1.3 2005/05/24 14:43:19 ate Exp $
+ */
+public class TestPortletEntityDAO extends DatasourceEnabledSpringTestCase
+{
+    private static final String TEST_APP = "EntityTestApp";
+
+    private static final String TEST_PORTLET = "EntityTestPortlet";
+
+    private static final String TEST_ENTITY = "user5/entity-9";
+
+    private static MockJetspeedEngine mockEngine = new MockJetspeedEngine();
+
+    private PersistenceBrokerPortletEntityAccess entityAccess = null;
+
+    private PortletRegistry registry;
+    
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+        mockEngine.setComponentManager(scm);
+        Jetspeed.setEngine(mockEngine);
+        this.registry = (PortletRegistry) scm.getComponent("portletRegistry");
+        this.entityAccess = (PersistenceBrokerPortletEntityAccess) scm.getComponent("portletEntityAccessImpl");
+
+        teardownTestData();
+        setupTestData();
+    }
+
+    protected void tearDown() throws Exception
+    {
+        teardownTestData();
+        Jetspeed.setEngine(null);
+        super.tearDown();
+    }
+
+    public void test1() throws Exception
+    {
+        assertNotNull(this.entityAccess);
+        assertNotNull(this.registry);
+    }
+
+    public void testEntities() throws Exception
+    {
+        PortletApplicationDefinition pa = registry.getPortletApplication(TEST_APP);
+        assertNotNull("Portlet Application", pa);
+        System.out.println("pa = " + pa.getId());
+        PortletDefinitionList portlets = pa.getPortletDefinitionList(); // .get(JetspeedObjectID.createFromString(TEST_PORTLET));
+        Iterator pi = portlets.iterator();
+        PortletDefinitionComposite pd = null;
+        while (pi.hasNext())
+        {
+            pd = (PortletDefinitionComposite) pi.next();
+            assertTrue("Portlet Def not found", pd.getName().equals("EntityTestPortlet"));
+        }
+        assertNotNull("Portlet Def is null", pd);
+
+        Mock mockf1 = new Mock(Fragment.class);
+        mockf1.expects(new InvokeAtLeastOnceMatcher()).method("getName").will(new ReturnStub(pd.getUniqueName()));
+        mockf1.expects(new InvokeAtLeastOnceMatcher()).method("getId").will(new ReturnStub(TEST_ENTITY));
+        ContentFragment f1 = new ContentFragmentTestImpl((Fragment) mockf1.proxy(), new HashMap());
+
+        MutablePortletEntity entity = entityAccess
+                .generateEntityFromFragment(new ContentFragmentTestImpl(f1, new HashMap()));
+        PreferenceSetComposite prefs = (PreferenceSetComposite) entity.getPreferenceSet();
+        prefs.remove("pref1");
+        assertNotNull(prefs);
+        assertNull(prefs.get("pref1"));
+
+        // test adding a pref
+        prefs.add("pref1", Arrays.asList(new String[]
+        { "1" }));
+        assertNotNull(prefs.get("pref1"));
+
+        // Remove should return the deleted pref
+        assertNotNull(prefs.remove("pref1"));
+
+        // Should be gone
+        assertNull(prefs.get("pref1"));
+
+        // Add it back so we can test tole back
+        prefs.add("pref1", Arrays.asList(new String[]
+        { "1" }));
+
+        entityAccess.storePortletEntity(entity);
+
+        prefs = (PreferenceSetComposite) entity.getPreferenceSet();
+
+        assertNotNull(prefs.get("pref1"));
+        
+        PreferenceComposite pref = (PreferenceComposite) prefs.get("pref1");
+        
+        List<String> prefValues = pref.getValuesList();
+        
+        assertEquals("1", prefValues.size());
+              
+        prefValues.set(0, "2");
+        pref.setValues(prefValues);
+
+        prefValues = pref.getValuesList();
+        assertEquals("2", prefValues.get(0));
+
+        prefValues.add("3");
+        prefs.add("pref2", prefValues);
+
+        entity.store();
+
+        prefs = (PreferenceSetComposite)entity.getPreferenceSet();
+        PreferenceComposite pref2 = (PreferenceComposite) prefs.get("pref2");
+
+        assertNotNull(pref2);
+
+        prefValues = pref2.getValuesList();
+        assertEquals(2, prefValues.size());
+
+        pref2.addValue("4");
+        prefValues = pref2.getValuesList();
+        assertEquals(3, prefValues.size());
+        assertEquals("2", prefValues.get(0));
+        assertEquals("3", prefValues.get(1));
+        assertEquals("4", prefValues.get(2));
+
+        // testing preferences null values assignments fix, issue JS2-607
+        prefValues.set(0,null);
+        pref2.setValues(prefValues);
+        entity.store();
+        
+        prefs = (PreferenceSetComposite)entity.getPreferenceSet();
+        pref2 = (PreferenceComposite) prefs.get("pref2");
+        
+        prefValues = pref2.getValuesList();
+        assertNull("pref2.value[0] should be null", prefValues.get(0));
+        
+        assertEquals(3, prefValues.size());
+        assertEquals("3", prefValues.get(1));
+        prefValues.set(0, "2");
+        prefValues.set(1, null);
+        prefValues.set(2, "3");
+        pref2.setValues(prefValues);
+        
+        entity.store();
+
+        prefs = (PreferenceSetComposite)entity.getPreferenceSet();
+        pref2 = (PreferenceComposite) prefs.get("pref2");
+        
+        prefValues = pref2.getValuesList();
+        assertNull("pref2.value[1] should be null", prefValues.get(1));
+        
+        assertTrue(pref2.isValueSet());
+        pref2.setValues(null);        
+        assertFalse(pref2.isValueSet());
+        
+        entity.store();
+
+        prefs = (PreferenceSetComposite)entity.getPreferenceSet();
+        pref2 = (PreferenceComposite) prefs.get("pref2");
+
+        assertFalse(pref2.isValueSet());
+        prefValues = pref2.getValuesList();
+        
+        assertTrue(prefValues.size() == 0);
+        
+        pref2.setValues(prefValues);
+        assertFalse(pref2.isValueSet());
+
+        entity.store();
+
+        prefs = (PreferenceSetComposite)entity.getPreferenceSet();
+        pref2 = (PreferenceComposite) prefs.get("pref2");
+
+        assertFalse(pref2.isValueSet());
+        prefValues = pref2.getValuesList();
+        
+        assertTrue(prefValues.size() == 0);
+        
+        MutablePortletEntity entity2 = entityAccess.getPortletEntityForFragment(f1);
+        assertTrue("entity id ", entity2.getId().toString().equals(TEST_ENTITY));
+        assertNotNull("entity's portlet ", entity2.getPortletDefinition());
+        mockf1.verify();
+
+        Mock mockf2 = new Mock(Fragment.class);
+        mockf2.expects(new InvokeAtLeastOnceMatcher()).method("getName").will(new ReturnStub(pd.getUniqueName()));
+        ContentFragment f2 = new ContentFragmentTestImpl((Fragment) mockf2.proxy(), new HashMap());
+
+        MutablePortletEntity entity5 = entityAccess.newPortletEntityInstance(pd);
+
+        System.out.println("before storing entity: " + entity5.getId());
+
+        entityAccess.storePortletEntity(entity5);
+        System.out.println("store done: " + entity5.getId());
+        mockf2.expects(new InvokeAtLeastOnceMatcher()).method("getId").will(new ReturnStub(entity5.getId().toString()));
+
+        MutablePortletEntity entity6 = entityAccess.getPortletEntityForFragment(f2);
+        assertNotNull(entity6);
+        System.out.println("reget : " + entity6.getId());
+
+        entityAccess.removePortletEntity(entity6);
+    }
+
+    private void teardownTestData() throws Exception
+    {
+
+        JetspeedObjectID objId = JetspeedObjectID.createFromString(TEST_ENTITY);
+        MutablePortletEntity entity = entityAccess.getPortletEntity(objId);
+        System.out.println("entity == " + entity);
+
+        if (entity != null)
+        {
+            entityAccess.removePortletEntity(entity);
+        }
+
+        PortletApplicationDefinition pa = registry.getPortletApplication(TEST_APP);
+        System.out.println("pa == " + pa);
+        if (pa != null)
+        {
+            registry.removeApplication(pa);
+        }
+
+        if (Preferences.systemRoot().nodeExists(MutablePortletApplication.PREFS_ROOT))
+        {
+            Preferences.systemRoot().node(MutablePortletApplication.PREFS_ROOT).removeNode();
+        }
+
+        if (Preferences.userRoot().nodeExists(PortletDefinitionComposite.PORTLETS_PREFS_ROOT))
+        {
+            Preferences.userRoot().node(PortletDefinitionComposite.PORTLETS_PREFS_ROOT).removeNode();
+        }
+
+        if (Preferences.userRoot().nodeExists(MutablePortletEntity.PORTLET_ENTITY_ROOT))
+        {
+            Preferences.userRoot().node(MutablePortletEntity.PORTLET_ENTITY_ROOT).removeNode();
+        }
+
+    }
+
+    private void setupTestData() throws Exception
+    {
+
+        PortletApplicationDefinitionImpl app = new PortletApplicationDefinitionImpl();
+        app.setName(TEST_APP);
+        app.setApplicationIdentifier(TEST_APP);
+
+        WebApplicationDefinitionImpl webApp = new WebApplicationDefinitionImpl();
+        webApp.setContextRoot("/app1");
+        webApp.addDescription(Locale.FRENCH, "Description: Le fromage est dans mon pantalon!");
+        webApp.addDisplayName(Locale.FRENCH, "Display Name: Le fromage est dans mon pantalon!");
+
+        PortletDefinitionComposite portlet = new PortletDefinitionImpl();
+        portlet.setClassName("org.apache.Portlet");
+        portlet.setName(TEST_PORTLET);
+        portlet.addDescription(Locale.getDefault(), "Portlet description.");
+        portlet.addDisplayName(Locale.getDefault(), "Portlet display Name.");
+
+        portlet.addInitParameter("testparam", "test value", "This is a test portlet parameter", Locale.getDefault());
+
+        app.addPortletDefinition(portlet);
+
+        app.setWebApplicationDefinition(webApp);
+
+        PreferenceSetComposite prefSet = (PreferenceSetComposite) portlet.getPreferenceSet();
+        prefSet.add("pref1", Arrays.asList(new String[]
+        { "1" }));
+
+        registry.registerPortletApplication(app);
+    }
+
+    protected String[] getConfigurations()
+    {
+        return new String[]
+        { "transaction.xml", "registry-test.xml", "prefs.xml", "cache.xml" };
+    }
+}

Modified: portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/test/java/org/apache/jetspeed/components/portletregistry/AbstractRegistryTest.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/test/java/org/apache/jetspeed/components/portletregistry/AbstractRegistryTest.java?rev=678081&r1=678080&r2=678081&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/test/java/org/apache/jetspeed/components/portletregistry/AbstractRegistryTest.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/test/java/org/apache/jetspeed/components/portletregistry/AbstractRegistryTest.java Fri Jul 18 17:17:27 2008
@@ -20,7 +20,9 @@
 import java.util.Iterator;
 import java.util.Locale;
 
+import org.apache.jetspeed.Jetspeed;
 import org.apache.jetspeed.components.util.DatasourceEnabledSpringTestCase;
+import org.apache.jetspeed.engine.MockJetspeedEngine;
 import org.apache.jetspeed.om.common.DublinCore;
 import org.apache.jetspeed.om.common.GenericMetadata;
 import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
@@ -55,7 +57,9 @@
 
     public static final String APP_1_NAME = "RegistryTestPortlet";
 
-    protected PortletRegistry registry;
+    private static MockJetspeedEngine mockEngine = new MockJetspeedEngine();
+
+   protected PortletRegistry registry;
 
     private static int testPasses = 0;
 
@@ -70,10 +74,18 @@
     protected void setUp() throws Exception
     {
         super.setUp();
+        mockEngine.setComponentManager(scm);
+        Jetspeed.setEngine(mockEngine);
         this.registry = (PortletRegistry) scm.getComponent("portletRegistry");
 
         testPasses++;
     }
+    
+    protected void tearDown() throws Exception
+    {
+        Jetspeed.setEngine(null);
+        super.tearDown();
+    }
 
     protected void validateDublinCore(GenericMetadata metadata)
     {

Modified: portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/test/java/org/apache/jetspeed/components/portletregistry/TestPortletRegistryDAO.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/test/java/org/apache/jetspeed/components/portletregistry/TestPortletRegistryDAO.java?rev=678081&r1=678080&r2=678081&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/test/java/org/apache/jetspeed/components/portletregistry/TestPortletRegistryDAO.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/test/java/org/apache/jetspeed/components/portletregistry/TestPortletRegistryDAO.java Fri Jul 18 17:17:27 2008
@@ -193,8 +193,6 @@
         { "value 1", "value 2" }));
         pc.addDescription(JetspeedLocale.getDefaultLocale(), "Preference Description");
 
-        assertNotNull(pc.getValueAt(0));
-
         portlet.addLanguage(portletRegistry.createLanguage(Locale.getDefault(), "Portlet 1", "Portlet 1",
                 "This is Portlet 1", null));
 

Modified: portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/test/java/org/apache/jetspeed/components/portletregistry/TestRegistryCache.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/test/java/org/apache/jetspeed/components/portletregistry/TestRegistryCache.java?rev=678081&r1=678080&r2=678081&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/test/java/org/apache/jetspeed/components/portletregistry/TestRegistryCache.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/test/java/org/apache/jetspeed/components/portletregistry/TestRegistryCache.java Fri Jul 18 17:17:27 2008
@@ -142,8 +142,6 @@
         { "value 1", "value 2" }));
         pc.addDescription(JetspeedLocale.getDefaultLocale(), "Preference Description");
 
-        assertNotNull(pc.getValueAt(0));
-
         portlet.addLanguage(portletRegistry.createLanguage(Locale.getDefault(), "Portlet 1", "Portlet 1",
                 "This is Portlet 1", null));
 

Modified: portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/test/java/org/apache/jetspeed/components/portletregistry/direct/TestRegistryDirectAll.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/test/java/org/apache/jetspeed/components/portletregistry/direct/TestRegistryDirectAll.java?rev=678081&r1=678080&r2=678081&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/test/java/org/apache/jetspeed/components/portletregistry/direct/TestRegistryDirectAll.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/test/java/org/apache/jetspeed/components/portletregistry/direct/TestRegistryDirectAll.java Fri Jul 18 17:17:27 2008
@@ -120,8 +120,6 @@
                 "value 1", "value 2"}));
         pc.addDescription(JetspeedLocale.getDefaultLocale(), "Preference Description");
 
-        assertNotNull(pc.getValueAt(0));
-
         portlet.addLanguage(registry.createLanguage(Locale.getDefault(), "Portlet 1", "Portlet 1", "This is Portlet 1",
                 null));
 

Modified: portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/test/java/org/apache/jetspeed/components/portletregistry/direct/TestRegistryDirectPart1a.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/test/java/org/apache/jetspeed/components/portletregistry/direct/TestRegistryDirectPart1a.java?rev=678081&r1=678080&r2=678081&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/test/java/org/apache/jetspeed/components/portletregistry/direct/TestRegistryDirectPart1a.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/test/java/org/apache/jetspeed/components/portletregistry/direct/TestRegistryDirectPart1a.java Fri Jul 18 17:17:27 2008
@@ -117,8 +117,6 @@
                 "value 1", "value 2"}));
         pc.addDescription(JetspeedLocale.getDefaultLocale(), "Preference Description");
 
-        assertNotNull(pc.getValueAt(0));
-
         portlet.addLanguage(registry.createLanguage(Locale.getDefault(), "Portlet 1", "Portlet 1", "This is Portlet 1",
                 null));
 

Added: portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/test/java/org/apache/jetspeed/engine/MockJetspeedEngine.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/test/java/org/apache/jetspeed/engine/MockJetspeedEngine.java?rev=678081&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/test/java/org/apache/jetspeed/engine/MockJetspeedEngine.java (added)
+++ portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-registry/src/test/java/org/apache/jetspeed/engine/MockJetspeedEngine.java Fri Jul 18 17:17:27 2008
@@ -0,0 +1,99 @@
+/*
+ * Lic