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 at...@apache.org on 2008/04/15 00:02:16 UTC
svn commit: r648024 [1/2] - in
/portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE: ./
components/cm/ components/cm/src/java/org/apache/jetspeed/cache/impl/
components/cm/src/test/org/apache/jetspeed/cache/
components/portal/src/java/org/apa...
Author: ate
Date: Mon Apr 14 15:02:13 2008
New Revision: 648024
URL: http://svn.apache.org/viewvc?rev=648024&view=rev
Log:
backport of JS2-800
See: http://issues.apache.org/jira/browse/JS2-800
Added:
portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/cm/src/java/org/apache/jetspeed/cache/impl/EhPortletWindowCache.java (with props)
portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/cm/src/test/org/apache/jetspeed/cache/TestPortletWindowCache.java (with props)
portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/portal/src/test/org/apache/jetspeed/HashMapWindowCache.java (with props)
portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/jetspeed-api/src/java/org/apache/jetspeed/cache/PortletWindowCache.java (with props)
Modified:
portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/.classpath
portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/cm/pom.xml
portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/cm/src/java/org/apache/jetspeed/cache/impl/EhCacheDistributedImpl.java
portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/cm/src/java/org/apache/jetspeed/cache/impl/EhCacheImpl.java
portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/cm/src/java/org/apache/jetspeed/cache/impl/EhDecorationContentCacheImpl.java
portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/cm/src/java/org/apache/jetspeed/cache/impl/EhPortletContentCacheImpl.java
portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/portal/src/java/org/apache/jetspeed/aggregator/impl/PortletTrackingManagerImpl.java
portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/portal/src/java/org/apache/jetspeed/container/window/impl/PortletWindowAccessorImpl.java
portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/portal/src/test/org/apache/jetspeed/AbstractPortalContainerTestCase.java
portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/portal/src/test/org/apache/jetspeed/window/TestWindows.java
portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/core-build.xml
portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/etc/db-ojb/ehcache.xml
portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/etc/editors/m2.classpath
portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/jetspeed-api/src/java/org/apache/jetspeed/container/window/PortletWindowAccessor.java
portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/pom.xml
portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/src/webapp/WEB-INF/assembly/cache.xml
portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/src/webapp/WEB-INF/assembly/jetspeed-spring.xml
Modified: portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/.classpath
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/.classpath?rev=648024&r1=648023&r2=648024&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/.classpath (original)
+++ portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/.classpath Mon Apr 14 15:02:13 2008
@@ -81,7 +81,7 @@
<classpathentry kind="var" path="MAVEN_REPO/commons-dbcp/jars/commons-dbcp-1.2.2.jar"/>
<classpathentry kind="var" path="MAVEN_REPO/commons-configuration/jars/commons-configuration-1.1.jar"/>
<classpathentry exported="true" kind="var" path="MAVEN_REPO/mockrunner/jars/mockrunner-0.3.8.jar"/>
- <classpathentry kind="var" path="MAVEN_REPO/jmock/jars/jmock-1.0.1.jar"/>
+ <classpathentry kind="var" path="MAVEN_REPO/jmock/jars/jmock-1.2.0.jar"/>
<classpathentry kind="var" path="MAVEN_REPO/saxpath/jars/saxpath-1.0-FCS.jar"/>
<classpathentry kind="var" path="MAVEN_REPO/jaxen/jars/jaxen-1.0-FCS-full.jar"/>
<classpathentry kind="var" path="MAVEN_REPO/aopalliance/jars/aopalliance-1.0.jar"/>
@@ -96,7 +96,7 @@
<classpathentry kind="var" path="MAVEN_REPO/myfaces/jars/myfaces-api-1.1.5.jar"/>
<classpathentry kind="var" path="MAVEN_REPO/myfaces/jars/myfaces-impl-1.1.5.jar"/>
<classpathentry kind="var" path="MAVEN_REPO/myfaces/jars/tomahawk-1.1.5.jar"/>
- <classpathentry kind="var" path="MAVEN_REPO/cglib/jars/cglib-2.1_3.jar"/>
+ <classpathentry kind="var" path="MAVEN_REPO/cglib/jars/cglib-nodep-2.1_3.jar"/>
<classpathentry kind="var" path="MAVEN_REPO/org.springframework/jars/spring-2.0.5.jar"/>
<classpathentry kind="var" path="MAVEN_REPO/org.springframework/jars/spring-mock-2.0.5.jar"/>
<classpathentry kind="var" path="MAVEN_REPO/org.springframework/jars/spring-portlet-2.0.5.jar"/>
@@ -118,6 +118,7 @@
<classpathentry kind="var" path="MAVEN_REPO/commons-betwixt/jars/commons-betwixt-20061115.jar"/>
<classpathentry kind="var" path="MAVEN_REPO/ant/jars/ant-1.6.5.jar"/>
<classpathentry kind="var" path="MAVEN_REPO/ehcache/jars/ehcache-1.2.4.jar"/>
+ <classpathentry kind="var" path="MAVEN_REPO/jmock/jars/jmock-cglib-1.1.0.jar"/>
<classpathentry kind="var" path="MAVEN_REPO/portlet-api/jars/portlet-api-1.0.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Modified: portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/cm/pom.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/cm/pom.xml?rev=648024&r1=648023&r2=648024&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/cm/pom.xml (original)
+++ portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/cm/pom.xml Mon Apr 14 15:02:13 2008
@@ -124,7 +124,7 @@
<!-- Runtime Dependencies -->
<dependency>
<groupId>cglib</groupId>
- <artifactId>cglib</artifactId>
+ <artifactId>cglib-nodep</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
Modified: portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/cm/src/java/org/apache/jetspeed/cache/impl/EhCacheDistributedImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/cm/src/java/org/apache/jetspeed/cache/impl/EhCacheDistributedImpl.java?rev=648024&r1=648023&r2=648024&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/cm/src/java/org/apache/jetspeed/cache/impl/EhCacheDistributedImpl.java (original)
+++ portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/cm/src/java/org/apache/jetspeed/cache/impl/EhCacheDistributedImpl.java Mon Apr 14 15:02:13 2008
@@ -41,7 +41,7 @@
private Map refList = Collections.synchronizedMap(new HashMap());
- public EhCacheDistributedImpl(Cache ehcache)
+ public EhCacheDistributedImpl(Ehcache ehcache)
{
super(ehcache);
RegisteredEventListeners listeners = ehcache
Modified: portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/cm/src/java/org/apache/jetspeed/cache/impl/EhCacheImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/cm/src/java/org/apache/jetspeed/cache/impl/EhCacheImpl.java?rev=648024&r1=648023&r2=648024&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/cm/src/java/org/apache/jetspeed/cache/impl/EhCacheImpl.java (original)
+++ portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/cm/src/java/org/apache/jetspeed/cache/impl/EhCacheImpl.java Mon Apr 14 15:02:13 2008
@@ -20,7 +20,7 @@
import java.util.ArrayList;
import java.util.List;
-import net.sf.ehcache.Cache;
+import net.sf.ehcache.Ehcache;
import net.sf.ehcache.Element;
import org.apache.jetspeed.cache.CacheElement;
@@ -31,11 +31,11 @@
public class EhCacheImpl implements JetspeedCache
{
- protected Cache ehcache;
+ protected Ehcache ehcache;
protected List localListeners = new ArrayList();
protected List remoteListeners = new ArrayList();
- public EhCacheImpl(Cache ehcache)
+ public EhCacheImpl(Ehcache ehcache)
{
this.ehcache = ehcache;
}
@@ -73,8 +73,8 @@
public CacheElement createElement(Object key, Object content)
{
- if (!((key instanceof Serializable) && (content instanceof Serializable)))
- return null;
+ if (!((key instanceof Serializable) || !(content instanceof Serializable)))
+ throw new IllegalArgumentException("The cache key and the object to cache must be serializable."); //return null;
return new EhCacheElementImpl((Serializable)key, (Serializable)content);
}
Modified: portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/cm/src/java/org/apache/jetspeed/cache/impl/EhDecorationContentCacheImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/cm/src/java/org/apache/jetspeed/cache/impl/EhDecorationContentCacheImpl.java?rev=648024&r1=648023&r2=648024&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/cm/src/java/org/apache/jetspeed/cache/impl/EhDecorationContentCacheImpl.java (original)
+++ portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/cm/src/java/org/apache/jetspeed/cache/impl/EhDecorationContentCacheImpl.java Mon Apr 14 15:02:13 2008
@@ -24,6 +24,7 @@
import java.util.StringTokenizer;
import net.sf.ehcache.Cache;
+import net.sf.ehcache.Ehcache;
import net.sf.ehcache.Element;
import org.apache.jetspeed.cache.CacheElement;
@@ -33,10 +34,9 @@
import org.apache.jetspeed.cache.JetspeedCache;
import org.apache.jetspeed.cache.JetspeedCacheEventListener;
import org.apache.jetspeed.cache.JetspeedContentCache;
-import org.apache.jetspeed.cache.impl.JetspeedContentCacheKey;
import org.apache.jetspeed.decoration.Theme;
-import org.apache.jetspeed.request.RequestContext;
import org.apache.jetspeed.om.page.ContentPage;
+import org.apache.jetspeed.request.RequestContext;
/**
* Wrapper around actual cache implementation
@@ -50,7 +50,7 @@
JetspeedCache preferenceCache = null;
ContentCacheKeyGenerator keyGenerator = null;
- public EhDecorationContentCacheImpl(Cache ehcache, JetspeedCache preferenceCache, ContentCacheKeyGenerator keyGenerator)
+ public EhDecorationContentCacheImpl(Ehcache ehcache, JetspeedCache preferenceCache, ContentCacheKeyGenerator keyGenerator)
{
this(ehcache);
this.preferenceCache = preferenceCache;
@@ -58,14 +58,14 @@
preferenceCache.addEventListener(this,false); //only listen to remote events
}
- public EhDecorationContentCacheImpl(Cache ehcache, JetspeedCache preferenceCache)
+ public EhDecorationContentCacheImpl(Ehcache ehcache, JetspeedCache preferenceCache)
{
this(ehcache);
this.preferenceCache = preferenceCache;
preferenceCache.addEventListener(this,false); //only listen to remote events
}
- public EhDecorationContentCacheImpl(Cache ehcache)
+ public EhDecorationContentCacheImpl(Ehcache ehcache)
{
super(ehcache);
}
Modified: portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/cm/src/java/org/apache/jetspeed/cache/impl/EhPortletContentCacheImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/cm/src/java/org/apache/jetspeed/cache/impl/EhPortletContentCacheImpl.java?rev=648024&r1=648023&r2=648024&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/cm/src/java/org/apache/jetspeed/cache/impl/EhPortletContentCacheImpl.java (original)
+++ portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/cm/src/java/org/apache/jetspeed/cache/impl/EhPortletContentCacheImpl.java Mon Apr 14 15:02:13 2008
@@ -23,7 +23,7 @@
import java.util.Map;
import java.util.StringTokenizer;
-import net.sf.ehcache.Cache;
+import net.sf.ehcache.Ehcache;
import net.sf.ehcache.Element;
import org.apache.jetspeed.cache.CacheElement;
@@ -48,7 +48,7 @@
JetspeedCache preferenceCache = null;
ContentCacheKeyGenerator keyGenerator = null;
- public EhPortletContentCacheImpl(Cache ehcache, JetspeedCache preferenceCache, ContentCacheKeyGenerator keyGenerator)
+ public EhPortletContentCacheImpl(Ehcache ehcache, JetspeedCache preferenceCache, ContentCacheKeyGenerator keyGenerator)
{
this(ehcache);
this.preferenceCache = preferenceCache;
@@ -56,19 +56,19 @@
preferenceCache.addEventListener(this,false); //only listen to remote events
}
- public EhPortletContentCacheImpl(Cache ehcache, JetspeedCache preferenceCache)
+ public EhPortletContentCacheImpl(Ehcache ehcache, JetspeedCache preferenceCache)
{
this(ehcache);
this.preferenceCache = preferenceCache;
preferenceCache.addEventListener(this,false); //only listen to remote events
}
- public EhPortletContentCacheImpl(Cache ehcache)
+ public EhPortletContentCacheImpl(Ehcache ehcache)
{
super(ehcache);
}
- public EhPortletContentCacheImpl(Cache ehcache, ContentCacheKeyGenerator keyGenerator)
+ public EhPortletContentCacheImpl(Ehcache ehcache, ContentCacheKeyGenerator keyGenerator)
{
this(ehcache);
this.keyGenerator = keyGenerator;
Added: portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/cm/src/java/org/apache/jetspeed/cache/impl/EhPortletWindowCache.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/cm/src/java/org/apache/jetspeed/cache/impl/EhPortletWindowCache.java?rev=648024&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/cm/src/java/org/apache/jetspeed/cache/impl/EhPortletWindowCache.java (added)
+++ portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/cm/src/java/org/apache/jetspeed/cache/impl/EhPortletWindowCache.java Mon Apr 14 15:02:13 2008
@@ -0,0 +1,140 @@
+/*
+* 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.cache.impl;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import net.sf.ehcache.Ehcache;
+
+import org.apache.jetspeed.cache.CacheElement;
+import org.apache.jetspeed.cache.PortletWindowCache;
+import org.apache.pluto.om.entity.PortletEntity;
+import org.apache.pluto.om.window.PortletWindow;
+
+/**
+ * <p>
+ * EhPortletWindowCache
+ * </p>
+ * <p>
+ * Implementation of {@link PortletWindowCache} that is backed
+ * <a href="http://ehcache.sourceforge.net/">Ehcache</a>.
+ * </p>
+ * @author <a href="mailto:scott.t.weaver@gmail.com">Scott T. Weaver</a>
+ *
+ */
+public class EhPortletWindowCache extends EhCacheImpl implements PortletWindowCache {
+
+ /** Allows us to track {@link PortletWindow}s in cache by {@link PortletEntity#getId()}*/
+ private Map portletEntityIdToEntityid;
+
+
+ public EhPortletWindowCache(Ehcache ehcache)
+ {
+ super(ehcache);
+ portletEntityIdToEntityid = new HashMap();
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.jetspeed.cache.impl.PortletWindowCache#getPortletWindow(java.lang.String)
+ */
+ public PortletWindow getPortletWindow(String windowId)
+ {
+ assert windowId != null;
+ CacheElement cacheElement = get(windowId);
+ if(cacheElement != null)
+ {
+ return (PortletWindow) cacheElement.getContent();
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.jetspeed.cache.impl.PortletWindowCache#getPortletWindowByEntityId(java.lang.String)
+ */
+ public PortletWindow getPortletWindowByEntityId(String portletEntityId)
+ {
+ assert portletEntityId != null;
+ if(portletEntityIdToEntityid.containsKey(portletEntityId))
+ {
+ return (PortletWindow) getPortletWindow((String) portletEntityIdToEntityid.get(portletEntityId));
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.jetspeed.cache.impl.PortletWindowCache#putPortletWindow(org.apache.pluto.om.window.PortletWindow)
+ */
+ public void putPortletWindow(PortletWindow window)
+ {
+ assert window != null;
+ String windowId = window.getId().toString();
+ portletEntityIdToEntityid.put(window.getPortletEntity().getId().toString(), windowId);
+ put(createElement(windowId, window));
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.jetspeed.cache.impl.PortletWindowCache#removePortletWindow(java.lang.String)
+ */
+ public void removePortletWindow(String portletWindowId)
+ {
+ assert portletWindowId != null;
+ PortletWindow window = getPortletWindow(portletWindowId);
+ if(window != null)
+ {
+ portletEntityIdToEntityid.remove(window.getPortletEntity().getId().toString());
+ removeQuiet(portletWindowId);
+ }
+ }
+
+ public void removePortletWindowByPortletEntityId(String portletEntityId)
+ {
+ assert portletEntityId != null;
+ PortletWindow portletWindow = getPortletWindowByEntityId(portletEntityId);
+ if(portletWindow != null)
+ {
+ portletEntityIdToEntityid.remove(portletEntityId);
+ removeQuiet(portletWindow.getId().toString());
+ }
+ }
+
+ public Set getAllPortletWindows()
+ {
+ Iterator keys = ehcache.getKeys().iterator();
+ Set windows = new HashSet();
+ while(keys.hasNext())
+ {
+ String key = (String) keys.next();
+ PortletWindow window = getPortletWindow(key);
+ if(window != null)
+ {
+ windows.add(window);
+ }
+ }
+ return windows;
+ }
+
+}
Propchange: portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/cm/src/java/org/apache/jetspeed/cache/impl/EhPortletWindowCache.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/cm/src/java/org/apache/jetspeed/cache/impl/EhPortletWindowCache.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/cm/src/java/org/apache/jetspeed/cache/impl/EhPortletWindowCache.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/cm/src/test/org/apache/jetspeed/cache/TestPortletWindowCache.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/cm/src/test/org/apache/jetspeed/cache/TestPortletWindowCache.java?rev=648024&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/cm/src/test/org/apache/jetspeed/cache/TestPortletWindowCache.java (added)
+++ portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/cm/src/test/org/apache/jetspeed/cache/TestPortletWindowCache.java Mon Apr 14 15:02:13 2008
@@ -0,0 +1,222 @@
+/*
+ * 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.cache;
+
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
+
+import net.sf.ehcache.Ehcache;
+import net.sf.ehcache.Element;
+
+import org.apache.jetspeed.cache.impl.EhCacheImpl;
+import org.apache.jetspeed.cache.impl.EhPortletWindowCache;
+import org.apache.pluto.om.common.ObjectID;
+import org.apache.pluto.om.entity.PortletEntity;
+import org.apache.pluto.om.window.PortletWindow;
+import org.jmock.Mock;
+import org.jmock.cglib.MockObjectTestCase;
+import org.jmock.core.stub.VoidStub;
+
+
+
+/**
+ *
+ * Tests for {@link EhPortletWindowCache}.
+ *
+ * @author <a href="mailto:scott.t.weaver@gmail.com">Scott T. Weaver</a>
+ *
+ */
+public class TestPortletWindowCache extends MockObjectTestCase
+{
+ private static final String WINDOW_ID = "window1";
+ private static final String ENTITY_ID = "entity1";
+
+
+ private Mock cacheMock;
+ private Mock windowMock;
+ private Mock entityMock;
+ private Mock oidMock;
+ private Mock entityOidMock;
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ cacheMock = mock(Ehcache.class);
+ windowMock = mock(SerializablePortletWindow.class);
+ entityMock = mock(PortletEntity.class);
+ oidMock = mock(ObjectID.class);
+ entityOidMock = (Mock) mock(ObjectID.class);
+ }
+
+ public void testSimplePutAndGet()
+ {
+
+ PortletWindow window = (PortletWindow) windowMock.proxy();
+ Element element = new Element(WINDOW_ID, window);
+ ObjectID oid = (ObjectID) oidMock.proxy();
+ ObjectID entityOid = (ObjectID) entityOidMock.proxy();
+ entityOidMock.expects(atLeastOnce()).method("toString").will(returnValue(ENTITY_ID));
+ oidMock.expects(atLeastOnce()).method("toString").will(returnValue(WINDOW_ID));
+ windowMock.expects(once()).method("getId").withNoArguments().will(returnValue(oid));
+ windowMock.expects(once()).method("getPortletEntity").withNoArguments().will(returnValue(entityMock.proxy()));
+ entityMock.expects(once()).method("getId").withNoArguments().will(returnValue(entityOid));
+ cacheMock.expects(once()).method("put").with(eq(element));
+ cacheMock.expects(atLeastOnce()).method("get").with(eq(WINDOW_ID)).will(returnValue(element));
+
+
+ Ehcache cache = (Ehcache) cacheMock.proxy();
+ PortletWindowCache windowCache = new EhPortletWindowCache(cache);
+ windowCache.putPortletWindow(window);
+
+ assertNotNull(windowCache.getPortletWindow(WINDOW_ID));
+ assertEquals(windowCache.getPortletWindow(WINDOW_ID), window);
+
+ verify();
+ }
+
+ public void testGetByPortletEntity()
+ {
+
+ SerializablePortletWindow window = (SerializablePortletWindow) windowMock.proxy();
+ Element element = new Element(WINDOW_ID, window);
+
+ ObjectID oid = (ObjectID) oidMock.proxy();
+ oidMock.expects(atLeastOnce()).method("toString").will(returnValue(WINDOW_ID));
+ ObjectID entityOid = (ObjectID) entityOidMock.proxy();
+ entityOidMock.expects(atLeastOnce()).method("toString").will(returnValue(ENTITY_ID));
+ cacheMock.expects(once()).method("put").with(eq(element));
+ cacheMock.expects(once()).method("get").with(eq(WINDOW_ID)).will(returnValue(element));
+ windowMock.expects(once()).method("getId").withNoArguments().will(returnValue(oid));
+ windowMock.expects(once()).method("getPortletEntity").withNoArguments().will(returnValue(entityMock.proxy()));
+ entityMock.expects(once()).method("getId").withNoArguments().will(returnValue(entityOid));
+
+ Ehcache cache = (Ehcache) cacheMock.proxy();
+ PortletWindowCache windowCache = new EhPortletWindowCache(cache);
+ windowCache.putPortletWindow(window);
+
+ PortletWindow fromCache = windowCache.getPortletWindowByEntityId(ENTITY_ID);
+ assertNotNull(fromCache);
+
+ verify();
+ }
+
+ public void testRemove()
+ {
+ SerializablePortletWindow window = (SerializablePortletWindow) windowMock.proxy();
+ Element element = new Element(WINDOW_ID, window);
+
+ ObjectID oid = (ObjectID) oidMock.proxy();
+ oidMock.expects(atLeastOnce()).method("toString").will(returnValue(WINDOW_ID));
+
+ ObjectID entityOid = (ObjectID)entityOidMock.proxy();
+ entityOidMock.expects(atLeastOnce()).method("toString").will(returnValue(ENTITY_ID));
+
+ cacheMock.expects(once()).method("put").with(eq(element));
+ cacheMock.expects(exactly(2)).method("get").with(eq(WINDOW_ID)).will(returnValue(element));
+ windowMock.expects(once()).method("getId").withNoArguments().will(returnValue(oid));
+ windowMock.expects(exactly(2)).method("getPortletEntity").withNoArguments().will(returnValue(entityMock.proxy()));
+ entityMock.expects(exactly(2)).method("getId").withNoArguments().will(returnValue(entityOid));
+
+
+ cacheMock.expects(once()).method("removeQuiet").with(eq(WINDOW_ID)).will(returnValue(true));
+
+
+ Ehcache cache = (Ehcache) cacheMock.proxy();
+ PortletWindowCache windowCache = new EhPortletWindowCache(cache);
+ windowCache.putPortletWindow(window);
+
+ windowCache.removePortletWindow(WINDOW_ID);
+ assertNull(windowCache.getPortletWindowByEntityId(ENTITY_ID));
+
+ verify();
+ }
+
+ public void testRemoveByEntityId()
+ {
+ SerializablePortletWindow window = (SerializablePortletWindow) windowMock.proxy();
+ Element element = new Element(WINDOW_ID, window);
+
+ ObjectID oid = (ObjectID) oidMock.proxy();
+ oidMock.expects(atLeastOnce()).method("toString").will(returnValue(WINDOW_ID));
+
+ ObjectID entityOid = (ObjectID) entityOidMock.proxy();
+ entityOidMock.expects(atLeastOnce()).method("toString").will(returnValue(ENTITY_ID));
+
+ cacheMock.expects(once()).method("put").with(eq(element));
+ cacheMock.expects(exactly(3)).method("get").with(eq(WINDOW_ID)).will(onConsecutiveCalls(returnValue(element), returnValue(element), new VoidStub()));
+ windowMock.expects(exactly(2)).method("getId").withNoArguments().will(returnValue(oid));
+ windowMock.expects(once()).method("getPortletEntity").withNoArguments().will(returnValue(entityMock.proxy()));
+ entityMock.expects(once()).method("getId").withNoArguments().will(returnValue(entityOid));
+
+
+ cacheMock.expects(atLeastOnce()).method("removeQuiet").with(eq(WINDOW_ID)).will(returnValue(true));
+
+
+ Ehcache cache = (Ehcache) cacheMock.proxy();
+ PortletWindowCache windowCache = new EhPortletWindowCache(cache);
+ windowCache.putPortletWindow(window);
+
+ windowCache.removePortletWindowByPortletEntityId(ENTITY_ID);
+ assertNull(windowCache.getPortletWindow(WINDOW_ID));
+
+ verify();
+ }
+
+ public void testGetAllPortletWindows()
+ {
+ PortletWindow window = (PortletWindow) windowMock.proxy();
+ PortletWindow window2 = (PortletWindow) mock(SerializablePortletWindow.class).proxy();
+ PortletWindow window3 = (PortletWindow) mock(SerializablePortletWindow.class).proxy();
+
+ List keys = Arrays.asList(new String[] {WINDOW_ID, "window2", "window3"});
+
+ cacheMock.expects(once()).method("getKeys").withNoArguments().will(returnValue(keys));
+ cacheMock.expects(once()).method("get").with(eq(WINDOW_ID)).will(returnValue(new Element(WINDOW_ID, window)));
+ cacheMock.expects(once()).method("get").with(eq("window2")).will(returnValue(new Element("window2", window2)));
+ cacheMock.expects(once()).method("get").with(eq("window3")).will(returnValue(new Element("window3", window3)));
+
+ PortletWindowCache windowCache = new EhPortletWindowCache((Ehcache) cacheMock.proxy());
+
+ Set allPortletWindows = windowCache.getAllPortletWindows();
+ assertNotNull(allPortletWindows);
+ assertEquals(3, allPortletWindows.size());
+ }
+
+ public void testUnexpected()
+ {
+// PortletWindowCache windowCache = new EhPortletWindowCache((Ehcache) cacheMock.proxy());
+// cacheMock.proxy();
+// windowCache.getPortletWindow(null);
+// verify();
+ }
+
+ /**
+ * We need this class to test the cache as the {@link EhCacheImpl} object only
+ * allows {@link Serializable} objects to be cached.
+ *
+ * @author <a href="mailto:scott.t.weaver@gmail.com">Scott T. Weaver</a>
+ *
+ */
+ private interface SerializablePortletWindow extends PortletWindow, Serializable
+ {
+
+ }
+
+
+}
Propchange: portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/cm/src/test/org/apache/jetspeed/cache/TestPortletWindowCache.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/cm/src/test/org/apache/jetspeed/cache/TestPortletWindowCache.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/cm/src/test/org/apache/jetspeed/cache/TestPortletWindowCache.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/portal/src/java/org/apache/jetspeed/aggregator/impl/PortletTrackingManagerImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/portal/src/java/org/apache/jetspeed/aggregator/impl/PortletTrackingManagerImpl.java?rev=648024&r1=648023&r2=648024&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/portal/src/java/org/apache/jetspeed/aggregator/impl/PortletTrackingManagerImpl.java (original)
+++ portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/portal/src/java/org/apache/jetspeed/aggregator/impl/PortletTrackingManagerImpl.java Mon Apr 14 15:02:13 2008
@@ -131,8 +131,7 @@
Iterator windows = this.windowAccessor.getPortletWindows().iterator();
while (windows.hasNext())
{
- Map.Entry entry = (Map.Entry)windows.next();
- PortletWindow window = (PortletWindow)entry.getValue();
+ PortletWindow window = (PortletWindow)windows.next();
PortletDefinitionComposite pd = (PortletDefinitionComposite)window.getPortletEntity().getPortletDefinition();
for (int ix = 0; ix < fullPortletNames.size(); ix++)
{
@@ -150,8 +149,7 @@
Iterator windows = this.windowAccessor.getPortletWindows().iterator();
while (windows.hasNext())
{
- Map.Entry entry = (Map.Entry)windows.next();
- PortletWindow window = (PortletWindow)entry.getValue();
+ PortletWindow window = (PortletWindow)windows.next();
PortletDefinitionComposite pd = (PortletDefinitionComposite)window.getPortletEntity().getPortletDefinition();
if (pd.getUniqueName().equals(fullPortletName) && isOutOfService(window))
{
@@ -167,8 +165,7 @@
Iterator windows = this.windowAccessor.getPortletWindows().iterator();
while (windows.hasNext())
{
- Map.Entry entry = (Map.Entry)windows.next();
- PortletWindow window = (PortletWindow)entry.getValue();
+ PortletWindow window = (PortletWindow)windows.next();
if (isOutOfService(window))
{
outs.add(window);
Modified: portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/portal/src/java/org/apache/jetspeed/container/window/impl/PortletWindowAccessorImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/portal/src/java/org/apache/jetspeed/container/window/impl/PortletWindowAccessorImpl.java?rev=648024&r1=648023&r2=648024&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/portal/src/java/org/apache/jetspeed/container/window/impl/PortletWindowAccessorImpl.java (original)
+++ portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/portal/src/java/org/apache/jetspeed/container/window/impl/PortletWindowAccessorImpl.java Mon Apr 14 15:02:13 2008
@@ -1,389 +1,429 @@
-/*
+/*
* 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.container.window.impl;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.jetspeed.components.portletentity.PortletEntityAccessComponent;
-import org.apache.jetspeed.components.portletentity.PortletEntityNotGeneratedException;
-import org.apache.jetspeed.components.portletentity.PortletEntityNotStoredException;
-import org.apache.jetspeed.components.portletregistry.PortletRegistry;
-import org.apache.jetspeed.components.portletregistry.RegistryEventListener;
-import org.apache.jetspeed.container.window.FailedToCreateWindowException;
-import org.apache.jetspeed.container.window.FailedToRetrievePortletWindow;
-import org.apache.jetspeed.container.window.PortletWindowAccessor;
-import org.apache.jetspeed.factory.PortletFactory;
-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.common.portlet.PortletDefinitionComposite;
-import org.apache.jetspeed.om.page.ContentFragment;
-import org.apache.jetspeed.om.window.impl.PortletWindowImpl;
-import org.apache.jetspeed.util.ArgUtil;
-import org.apache.pluto.om.entity.PortletEntity;
-import org.apache.pluto.om.window.PortletWindow;
-import org.apache.pluto.om.window.PortletWindowCtrl;
-
-/**
- * Portlet Window Accessor Implementation
- *
- * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
- * @version $Id: PortletWindowAccessorImpl.java,v 1.12 2005/04/29 14:01:57 weaver Exp $
- */
-public class PortletWindowAccessorImpl implements PortletWindowAccessor, RegistryEventListener
-{
- protected final static Log log = LogFactory.getLog(PortletWindowAccessorImpl.class);
-
- private Map windows = Collections.synchronizedMap(new HashMap());
- private PortletEntityAccessComponent entityAccessor;
- private PortletFactory portletFactory;
- private boolean validateWindows = false;
-
-
- public PortletWindowAccessorImpl(PortletEntityAccessComponent entityAccessor, PortletFactory portletFactory, boolean validateWindows)
- {
- this.entityAccessor = entityAccessor;
- this.portletFactory = portletFactory;
- this.validateWindows = validateWindows;
- }
-
- public PortletWindowAccessorImpl(PortletEntityAccessComponent entityAccessor,
- PortletFactory portletFactory,
- PortletRegistry registry,
- boolean validateWindows)
- {
- this.entityAccessor = entityAccessor;
- this.portletFactory = portletFactory;
- this.validateWindows = validateWindows;
- registry.addRegistryListener(this);
- }
-
- public PortletWindow createPortletWindow(PortletEntity entity, String windowId)
- {
- if(entity == null)
- {
- throw new IllegalArgumentException("cratePortletWindow requires a non-null PortletEntity");
- }
-
- PortletWindow found = getWindowFromCache(windowId);
- if (found != null)
- {
- // remove from cache if invalid entity
- checkPortletWindowEntity(found);
- ((PortletWindowCtrl)found).setPortletEntity(entity);
- return found;
- }
-
- PortletWindowImpl window = new PortletWindowImpl(windowId);
- window.setPortletEntity(entity);
- if ( isValidPortletEntity(entity))
- {
- windows.put(windowId, window);
- }
- return window;
- }
-
- public PortletWindow createPortletWindow(String windowId)
- {
- PortletWindow found = getWindowFromCache(windowId);
- if (found != null)
- {
- // remove from cache if invalid entity
- checkPortletWindowEntity(found);
- return found;
- }
- PortletWindowImpl window = new PortletWindowImpl(windowId);
- return window;
- }
-
- public PortletWindow getPortletWindow(String windowId)
- {
- PortletWindow window = getWindowFromCache(windowId);
- if (window != null)
- {
- // remove from cache if invalid entity
- checkPortletWindowEntity(window);
- }
- return window;
- }
-
- public PortletWindow getPortletWindow(ContentFragment fragment) throws FailedToRetrievePortletWindow, PortletEntityNotStoredException
- {
- ArgUtil.assertNotNull(ContentFragment.class, fragment, this, "getPortletWindow(Fragment fragment)");
- PortletWindow portletWindow = getWindowFromCache(fragment);
- if (portletWindow == null || !checkPortletWindowEntity(portletWindow))
- {
- try
- {
- return createPortletWindow(fragment);
- }
- catch (FailedToCreateWindowException e)
- {
- throw new FailedToRetrievePortletWindow(e.toString(), e);
- }
- }
- else
- {
- if (validateWindows)
- {
- validateWindow(fragment, portletWindow);
- }
- }
-
- return portletWindow;
- }
-
- /**
- * <p>
- * validateWindow
- * </p>
- *
- * @param fragment
- * @param portletWindow
- * @throws PortletEntityNotStoredException
- * @throws InconsistentWindowStateException
- */
- protected void validateWindow( ContentFragment fragment, PortletWindow portletWindow ) throws FailedToRetrievePortletWindow, PortletEntityNotStoredException
- {
- // make sure the window has the most up-to-date portlet entity
- PortletEntity portletEntity = entityAccessor.getPortletEntityForFragment(fragment);
- if(portletEntity != null)
- {
- ((PortletWindowCtrl) portletWindow).setPortletEntity(portletEntity);
- // if not a valid entity, remove window from cache
- checkPortletWindowEntity(portletWindow);
- }
- else
- {
- removeWindow(portletWindow);
- throw new FailedToRetrievePortletWindow("No PortletEntity exists for for id "+fragment.getId()+" removing window from cache.");
- }
- }
-
- public PortletWindow getPortletWindow(ContentFragment fragment, String principal) throws FailedToRetrievePortletWindow, FailedToCreateWindowException, PortletEntityNotStoredException
- {
- ArgUtil.assertNotNull(ContentFragment.class, fragment, this, "getPortletWindow(Fragment fragment, String principal)");
- ArgUtil.assertNotNull(String.class, principal, this, "getPortletWindow(Fragment fragment, String principal)");
- PortletWindow portletWindow = getWindowFromCache(fragment);
- if (portletWindow == null)
- {
- return createPortletWindow(fragment, principal);
- }
- else
- {
- // make sure the window has the most up-to-date portlet entity
- validateWindow(fragment, portletWindow);
- }
- return portletWindow;
- }
-
- private PortletWindow createPortletWindow(ContentFragment fragment) throws FailedToCreateWindowException, PortletEntityNotStoredException
- {
- return createPortletWindow(fragment, null);
- }
-
- private PortletWindow createPortletWindow(ContentFragment fragment, String principal) throws FailedToCreateWindowException, PortletEntityNotStoredException
- {
- PortletWindow portletWindow = new PortletWindowImpl(fragment.getId());
- boolean temporaryWindow = false;
-
- MutablePortletEntity portletEntity = entityAccessor.getPortletEntityForFragment(fragment, principal);
- if (portletEntity == null)
- {
- log.info("No portlet entity defined for fragment ID "+fragment.getId()+" attempting to auto-generate...");
- try
- {
- portletEntity = entityAccessor.generateEntityFromFragment(fragment, principal);
- // not portlet definition most likely means that the portlet has not been deployed so dont worry about storing off the entity
- if(isValidPortletEntity(portletEntity))
- {
- entityAccessor.storePortletEntity(portletEntity);
- }
- else
- {
- // don't cache the incomplete window
- temporaryWindow = true;
- }
- }
- catch (PortletEntityNotGeneratedException e)
- {
- throw new FailedToCreateWindowException("Error generating new PortletEntity: "+e.toString(), e);
- }
- catch (PortletEntityNotStoredException e)
- {
- throw new FailedToCreateWindowException("Error storing new PortletEntity: "+e.toString(), e);
- }
-
- if(portletEntity == null)
- {
- throw new FailedToCreateWindowException("Unable to generate portlet entity.");
- }
-
- }
- ((PortletWindowCtrl) portletWindow).setPortletEntity(portletEntity);
-
- if ( !temporaryWindow )
- {
- windows.put(fragment.getId(), portletWindow);
- }
-
- return portletWindow;
- }
-
-
- public void removeWindows(PortletEntity portletEntity)
- {
- List tmpWindows = new ArrayList(windows.entrySet());
- for(int i = 0; i < tmpWindows.size(); i++)
- {
- PortletWindow window = (PortletWindow)((Map.Entry)tmpWindows.get(i)).getValue();
- if (portletEntity.getId().equals(window.getPortletEntity().getId()))
- {
- removeWindow(window);
- }
- }
- tmpWindows.clear();
-
- }
-
- public void removeWindow(PortletWindow window)
- {
- windows.remove(window.getId().toString());
- }
-
- private PortletWindow getWindowFromCache(ContentFragment fragment)
- {
- return (PortletWindow)windows.get(fragment.getId());
- }
-
- private PortletWindow getWindowFromCache(String id)
- {
- return (PortletWindow)windows.get(id);
- }
-
- private boolean checkPortletWindowEntity(PortletWindow window)
- {
- if (!isValidPortletEntity(window.getPortletEntity()))
- {
- removeWindow(window);
- return false;
- }
- return true;
- }
-
- private boolean isValidPortletEntity(PortletEntity pe)
- {
- return pe != null
- && pe.getPortletDefinition() != null
- && pe.getPortletDefinition().getPortletApplicationDefinition() != null
- && portletFactory.isPortletApplicationRegistered((PortletApplication) pe.getPortletDefinition()
- .getPortletApplicationDefinition());
- }
-
- public Set getPortletWindows()
- {
- return this.windows.entrySet();
- }
-
- protected void removeForPortletDefinition(PortletDefinitionComposite def)
- {
- List tmpWindows = new ArrayList(windows.entrySet());
- for (int i = 0; i < tmpWindows.size(); i++)
- {
- PortletWindow window = (PortletWindow)((Map.Entry)tmpWindows.get(i)).getValue();
- PortletDefinitionComposite windowDef = (PortletDefinitionComposite)window.getPortletEntity().getPortletDefinition();
- if(def != null && windowDef != null && def.getUniqueName() != null && def.getUniqueName().equals(windowDef.getUniqueName()))
- {
- removeWindow(window);
- }
- }
- tmpWindows.clear();
- if (def != null)
- portletFactory.updatePortletConfig(def);
- }
-
- protected void removeForPortletApplication(MutablePortletApplication app)
- {
- List tmpWindows = new ArrayList(windows.entrySet());
- for (int i = 0; i < tmpWindows.size(); i++)
- {
- PortletWindow window = (PortletWindow)((Map.Entry)tmpWindows.get(i)).getValue();
- PortletDefinitionComposite pd = (PortletDefinitionComposite)window.getPortletEntity().getPortletDefinition();
- if (pd != null)
- {
- MutablePortletApplication windowApp = (MutablePortletApplication)pd.getPortletApplicationDefinition();
- if (app.getName().equals(windowApp.getName()))
- {
- removeWindow(window);
- }
- }
- }
- tmpWindows.clear();
- }
-
- public void applicationRemoved(MutablePortletApplication app)
- {
- if (app == null)
- {
- //System.out.println("@@@ receiving APP REMOVED message with NULL");
- return;
- }
- //System.out.println("@@@ receiving APP REMOVED message: " + app.getName());
- removeForPortletApplication(app);
- }
-
-
- public void applicationUpdated(MutablePortletApplication app)
- {
- if (app == null)
- {
- //System.out.println("@@@ receiving APP UPDATED message with NULL");
- return;
- }
- //System.out.println("@@@ receiving APP UPDATED message: " + app.getName());
- removeForPortletApplication(app);
- }
-
- public void portletRemoved(PortletDefinitionComposite def)
- {
- if (def == null)
- {
- //System.out.println("@@@ receiving DEF REMOVED message with NULL");
- return;
- }
- //System.out.println("@@@ receiving DEF REMOVED message: " + def.getName());
- removeForPortletDefinition(def);
- }
-
- public void portletUpdated(PortletDefinitionComposite def)
- {
- if (def == null)
- {
- //System.out.println("@@@ receiving DEF UPDATED message with NULL");
- return;
- }
- //System.out.println("@@@ receiving DEF UPDATED message: " + def.getName());
- removeForPortletDefinition(def);
- }
-}
+ * 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.container.window.impl;
+
+import java.util.Iterator;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jetspeed.cache.PortletWindowCache;
+import org.apache.jetspeed.components.portletentity.PortletEntityAccessComponent;
+import org.apache.jetspeed.components.portletentity.PortletEntityNotGeneratedException;
+import org.apache.jetspeed.components.portletentity.PortletEntityNotStoredException;
+import org.apache.jetspeed.components.portletregistry.PortletRegistry;
+import org.apache.jetspeed.components.portletregistry.RegistryEventListener;
+import org.apache.jetspeed.container.window.FailedToCreateWindowException;
+import org.apache.jetspeed.container.window.FailedToRetrievePortletWindow;
+import org.apache.jetspeed.container.window.PortletWindowAccessor;
+import org.apache.jetspeed.factory.PortletFactory;
+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.common.portlet.PortletDefinitionComposite;
+import org.apache.jetspeed.om.page.ContentFragment;
+import org.apache.jetspeed.om.window.impl.PortletWindowImpl;
+import org.apache.jetspeed.util.ArgUtil;
+import org.apache.pluto.om.entity.PortletEntity;
+import org.apache.pluto.om.window.PortletWindow;
+import org.apache.pluto.om.window.PortletWindowCtrl;
+
+/**
+ * Portlet Window Accessor Implementation
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: PortletWindowAccessorImpl.java,v 1.12 2005/04/29 14:01:57 weaver Exp $
+ */
+public class PortletWindowAccessorImpl implements PortletWindowAccessor, RegistryEventListener
+{
+ protected final static Log log = LogFactory.getLog(PortletWindowAccessorImpl.class);
+
+ //private Map windows = Collections.synchronizedMap(new HashMap());
+ private PortletEntityAccessComponent entityAccessor;
+ private PortletFactory portletFactory;
+ private boolean validateWindows = false;
+ private PortletWindowCache portletWindowCache;
+
+
+
+ public PortletWindowAccessorImpl(PortletEntityAccessComponent entityAccessor, PortletFactory portletFactory, PortletWindowCache portletWindowCache, boolean validateWindows)
+ {
+ this.entityAccessor = entityAccessor;
+ this.portletFactory = portletFactory;
+ this.validateWindows = validateWindows;
+ this.portletWindowCache = portletWindowCache;
+
+ }
+
+ public PortletWindowAccessorImpl(PortletEntityAccessComponent entityAccessor,
+ PortletFactory portletFactory,
+ PortletRegistry registry,
+ PortletWindowCache portletWindowCache,
+ boolean validateWindows)
+ {
+ this.entityAccessor = entityAccessor;
+ this.portletFactory = portletFactory;
+ this.validateWindows = validateWindows;
+ this.portletWindowCache = portletWindowCache;
+ registry.addRegistryListener(this);
+ }
+
+ public PortletWindow createPortletWindow(PortletEntity entity, String windowId)
+ {
+ if(entity == null)
+ {
+ throw new IllegalArgumentException("cratePortletWindow requires a non-null PortletEntity");
+ }
+
+ PortletWindow found = getWindowFromCache(windowId);
+ if (found != null)
+ {
+ // remove from cache if invalid entity
+ checkPortletWindowEntity(found);
+ ((PortletWindowCtrl)found).setPortletEntity(entity);
+ return found;
+ }
+
+ PortletWindowImpl window = new PortletWindowImpl(windowId);
+ window.setPortletEntity(entity);
+ if ( isValidPortletEntity(entity))
+ {
+ // windows.put(windowId, window);
+ portletWindowCache.putPortletWindow(window);
+ }
+ return window;
+ }
+
+ public PortletWindow createPortletWindow(String windowId)
+ {
+ PortletWindow found = getWindowFromCache(windowId);
+ if (found != null)
+ {
+ // remove from cache if invalid entity
+ checkPortletWindowEntity(found);
+ return found;
+ }
+ PortletWindowImpl window = new PortletWindowImpl(windowId);
+ return window;
+ }
+
+ public PortletWindow getPortletWindow(String windowId)
+ {
+ PortletWindow window = getWindowFromCache(windowId);
+ if (window != null)
+ {
+ // remove from cache if invalid entity
+ checkPortletWindowEntity(window);
+ }
+ return window;
+ }
+
+ public PortletWindow getPortletWindow(ContentFragment fragment) throws FailedToRetrievePortletWindow, PortletEntityNotStoredException
+ {
+ ArgUtil.assertNotNull(ContentFragment.class, fragment, this, "getPortletWindow(Fragment fragment)");
+ PortletWindow portletWindow = getWindowFromCache(fragment);
+ if (portletWindow == null || !checkPortletWindowEntity(portletWindow))
+ {
+ try
+ {
+ return createPortletWindow(fragment);
+ }
+ catch (FailedToCreateWindowException e)
+ {
+ throw new FailedToRetrievePortletWindow(e.toString(), e);
+ }
+ }
+ else
+ {
+ if (validateWindows)
+ {
+ validateWindow(fragment, portletWindow);
+ }
+ }
+
+ return portletWindow;
+ }
+
+ /**
+ * <p>
+ * validateWindow
+ * </p>
+ *
+ * @param fragment
+ * @param portletWindow
+ * @throws PortletEntityNotStoredException
+ * @throws InconsistentWindowStateException
+ */
+ protected void validateWindow( ContentFragment fragment, PortletWindow portletWindow ) throws FailedToRetrievePortletWindow, PortletEntityNotStoredException
+ {
+ // make sure the window has the most up-to-date portlet entity
+ PortletEntity portletEntity = entityAccessor.getPortletEntityForFragment(fragment);
+ if(portletEntity != null)
+ {
+ ((PortletWindowCtrl) portletWindow).setPortletEntity(portletEntity);
+ // if not a valid entity, remove window from cache
+ checkPortletWindowEntity(portletWindow);
+ }
+ else
+ {
+ removeWindow(portletWindow);
+ throw new FailedToRetrievePortletWindow("No PortletEntity exists for for id "+fragment.getId()+" removing window from cache.");
+ }
+ }
+
+ public PortletWindow getPortletWindow(ContentFragment fragment, String principal) throws FailedToRetrievePortletWindow, FailedToCreateWindowException, PortletEntityNotStoredException
+ {
+ ArgUtil.assertNotNull(ContentFragment.class, fragment, this, "getPortletWindow(Fragment fragment, String principal)");
+ ArgUtil.assertNotNull(String.class, principal, this, "getPortletWindow(Fragment fragment, String principal)");
+ PortletWindow portletWindow = getWindowFromCache(fragment);
+ if (portletWindow == null)
+ {
+ return createPortletWindow(fragment, principal);
+ }
+ else
+ {
+ // make sure the window has the most up-to-date portlet entity
+ validateWindow(fragment, portletWindow);
+ }
+ return portletWindow;
+ }
+
+ private PortletWindow createPortletWindow(ContentFragment fragment) throws FailedToCreateWindowException, PortletEntityNotStoredException
+ {
+ return createPortletWindow(fragment, null);
+ }
+
+ private PortletWindow createPortletWindow(ContentFragment fragment, String principal) throws FailedToCreateWindowException, PortletEntityNotStoredException
+ {
+ PortletWindow portletWindow = new PortletWindowImpl(fragment.getId());
+ boolean temporaryWindow = false;
+
+ MutablePortletEntity portletEntity = entityAccessor.getPortletEntityForFragment(fragment, principal);
+ if (portletEntity == null)
+ {
+ log.info("No portlet entity defined for fragment ID "+fragment.getId()+" attempting to auto-generate...");
+ try
+ {
+ portletEntity = entityAccessor.generateEntityFromFragment(fragment, principal);
+ // not portlet definition most likely means that the portlet has not been deployed so dont worry about storing off the entity
+ if(isValidPortletEntity(portletEntity))
+ {
+ entityAccessor.storePortletEntity(portletEntity);
+ }
+ else
+ {
+ // don't cache the incomplete window
+ temporaryWindow = true;
+ }
+ }
+ catch (PortletEntityNotGeneratedException e)
+ {
+ throw new FailedToCreateWindowException("Error generating new PortletEntity: "+e.toString(), e);
+ }
+ catch (PortletEntityNotStoredException e)
+ {
+ throw new FailedToCreateWindowException("Error storing new PortletEntity: "+e.toString(), e);
+ }
+
+ if(portletEntity == null)
+ {
+ throw new FailedToCreateWindowException("Unable to generate portlet entity.");
+ }
+
+ }
+ ((PortletWindowCtrl) portletWindow).setPortletEntity(portletEntity);
+
+ if ( !temporaryWindow )
+ {
+ portletWindowCache.putPortletWindow(portletWindow);
+ }
+
+ return portletWindow;
+ }
+
+
+ public void removeWindows(PortletEntity portletEntity)
+ {
+// List tmpWindows = new ArrayList(windows.entrySet());
+// for(int i = 0; i < tmpWindows.size(); i++)
+// {
+// PortletWindow window = (PortletWindow)((Map.Entry)tmpWindows.get(i)).getValue();
+// if (portletEntity.getId().equals(window.getPortletEntity().getId()))
+// {
+// removeWindow(window);
+// }
+// }
+// tmpWindows.clear();
+//
+ portletWindowCache.removePortletWindowByPortletEntityId(portletEntity.getId().toString());
+
+ }
+
+ public void removeWindow(PortletWindow window)
+ {
+ // windows.remove(window.getId().toString());
+ portletWindowCache.removePortletWindow(window.getId().toString());
+ }
+
+ private PortletWindow getWindowFromCache(ContentFragment fragment)
+ {
+ return portletWindowCache.getPortletWindow(fragment.getId());
+ }
+
+ private PortletWindow getWindowFromCache(String id)
+ {
+ return portletWindowCache.getPortletWindow(id);
+ }
+
+ private boolean checkPortletWindowEntity(PortletWindow window)
+ {
+ if (!isValidPortletEntity(window.getPortletEntity()))
+ {
+ removeWindow(window);
+ return false;
+ }
+ return true;
+ }
+
+ private boolean isValidPortletEntity(PortletEntity pe)
+ {
+ return pe != null
+ && pe.getPortletDefinition() != null
+ && pe.getPortletDefinition().getPortletApplicationDefinition() != null
+ && portletFactory.isPortletApplicationRegistered((PortletApplication) pe.getPortletDefinition()
+ .getPortletApplicationDefinition());
+ }
+
+ public Set getPortletWindows()
+ {
+ return portletWindowCache.getAllPortletWindows();
+ }
+
+ protected void removeForPortletDefinition(PortletDefinitionComposite def)
+ {
+// List tmpWindows = new ArrayList(windows.entrySet());
+// for (int i = 0; i < tmpWindows.size(); i++)
+// {
+// PortletWindow window = (PortletWindow)((Map.Entry)tmpWindows.get(i)).getValue();
+// PortletDefinitionComposite windowDef = (PortletDefinitionComposite)window.getPortletEntity().getPortletDefinition();
+// if(def != null && windowDef != null && def.getUniqueName() != null && def.getUniqueName().equals(windowDef.getUniqueName()))
+// {
+// removeWindow(window);
+// }
+// }
+// tmpWindows.clear();
+// if (def != null)
+// portletFactory.updatePortletConfig(def);
+
+
+ Iterator windows = getPortletWindows().iterator();
+ while(windows.hasNext())
+ {
+ PortletWindow window = (PortletWindow) windows.next();
+ PortletDefinitionComposite windowDef = (PortletDefinitionComposite)window.getPortletEntity().getPortletDefinition();
+ if(def != null && windowDef != null && def.getUniqueName() != null && def.getUniqueName().equals(windowDef.getUniqueName()))
+ {
+ removeWindow(window);
+ }
+ }
+
+ if (def != null)
+ portletFactory.updatePortletConfig(def);
+ }
+
+ protected void removeForPortletApplication(MutablePortletApplication app)
+ {
+// List tmpWindows = new ArrayList(windows.entrySet());
+// for (int i = 0; i < tmpWindows.size(); i++)
+// {
+// PortletWindow window = (PortletWindow)((Map.Entry)tmpWindows.get(i)).getValue();
+// PortletDefinitionComposite pd = (PortletDefinitionComposite)window.getPortletEntity().getPortletDefinition();
+// if (pd != null)
+// {
+// MutablePortletApplication windowApp = (MutablePortletApplication)pd.getPortletApplicationDefinition();
+// if (app.getName().equals(windowApp.getName()))
+// {
+// removeWindow(window);
+// }
+// }
+// }
+// tmpWindows.clear();
+
+ Iterator windows = getPortletWindows().iterator();
+ while(windows.hasNext())
+ {
+ PortletWindow window = (PortletWindow) windows.next();
+ PortletDefinitionComposite pd = (PortletDefinitionComposite)window.getPortletEntity().getPortletDefinition();
+ if (pd != null)
+ {
+ MutablePortletApplication windowApp = (MutablePortletApplication)pd.getPortletApplicationDefinition();
+ if (app.getName().equals(windowApp.getName()))
+ {
+ removeWindow(window);
+ }
+ }
+ }
+
+
+
+ }
+
+ public void applicationRemoved(MutablePortletApplication app)
+ {
+ if (app == null)
+ {
+ //System.out.println("@@@ receiving APP REMOVED message with NULL");
+ return;
+ }
+ //System.out.println("@@@ receiving APP REMOVED message: " + app.getName());
+ removeForPortletApplication(app);
+ }
+
+
+ public void applicationUpdated(MutablePortletApplication app)
+ {
+ if (app == null)
+ {
+ //System.out.println("@@@ receiving APP UPDATED message with NULL");
+ return;
+ }
+ //System.out.println("@@@ receiving APP UPDATED message: " + app.getName());
+ removeForPortletApplication(app);
+ }
+
+ public void portletRemoved(PortletDefinitionComposite def)
+ {
+ if (def == null)
+ {
+ //System.out.println("@@@ receiving DEF REMOVED message with NULL");
+ return;
+ }
+ //System.out.println("@@@ receiving DEF REMOVED message: " + def.getName());
+ removeForPortletDefinition(def);
+ }
+
+ public void portletUpdated(PortletDefinitionComposite def)
+ {
+ if (def == null)
+ {
+ //System.out.println("@@@ receiving DEF UPDATED message with NULL");
+ return;
+ }
+ //System.out.println("@@@ receiving DEF UPDATED message: " + def.getName());
+ removeForPortletDefinition(def);
+ }
+}
Modified: portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/portal/src/test/org/apache/jetspeed/AbstractPortalContainerTestCase.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/portal/src/test/org/apache/jetspeed/AbstractPortalContainerTestCase.java?rev=648024&r1=648023&r2=648024&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/portal/src/test/org/apache/jetspeed/AbstractPortalContainerTestCase.java (original)
+++ portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/portal/src/test/org/apache/jetspeed/AbstractPortalContainerTestCase.java Mon Apr 14 15:02:13 2008
@@ -22,20 +22,26 @@
import org.apache.pluto.PortletContainer;
/**
- * @author <a href="mailto:sweaver@einnovation.com">Scott T. Weaver</a>
- *
+ * @author <a href="mailto:scott.t.weaver@gmail.com">Scott T. Weaver</a>
+ *
*/
public class AbstractPortalContainerTestCase extends AbstractRequestContextTestCase
{
protected PortletWindowAccessor windowAccessor;
+
protected PortletContainer portletContainer;
-
- /* (non-Javadoc)
+
+ /*
+ * (non-Javadoc)
+ *
* @see junit.framework.TestCase#setUp()
*/
protected void setUp() throws Exception
{
super.setUp();
- windowAccessor = new PortletWindowAccessorImpl(entityAccess,PortletFactoryMock.instance,true);
+ windowAccessor = new PortletWindowAccessorImpl(entityAccess,
+ PortletFactoryMock.instance,
+ new HashMapWindowCache(),
+ true);
}
}
Added: portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/portal/src/test/org/apache/jetspeed/HashMapWindowCache.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/portal/src/test/org/apache/jetspeed/HashMapWindowCache.java?rev=648024&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/portal/src/test/org/apache/jetspeed/HashMapWindowCache.java (added)
+++ portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/portal/src/test/org/apache/jetspeed/HashMapWindowCache.java Mon Apr 14 15:02:13 2008
@@ -0,0 +1,100 @@
+/*
+ * 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;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import org.apache.jetspeed.cache.PortletWindowCache;
+import org.apache.pluto.om.window.PortletWindow;
+
+/**
+ * This implementation of {@link PortletWindowCache} is to be used ONLY for testing purposes.
+ *
+ * @author <a href="mailto:scott.t.weaver@gmail.com">Scott T. Weaver</a>
+ *
+ */
+public class HashMapWindowCache implements PortletWindowCache
+{
+
+
+ private Map portletEntityToWindow = new HashMap();
+ private Map windows = new HashMap();
+
+ public Set getAllPortletWindows()
+ {
+ Set windowSet = new HashSet();
+
+ Iterator itr = windows.entrySet().iterator();
+ while(itr.hasNext())
+ {
+ Map.Entry entry = (Entry) itr.next();
+ windowSet.add((PortletWindow)entry.getValue());
+ }
+
+ return windowSet;
+ }
+
+ public PortletWindow getPortletWindow(String windowId)
+ {
+ return (PortletWindow) windows.get(windowId);
+ }
+
+ public PortletWindow getPortletWindowByEntityId(String portletEntityId)
+ {
+ if(portletEntityToWindow.containsKey(portletEntityId))
+ {
+ return (PortletWindow) windows.get((String) portletEntityToWindow.get(portletEntityId));
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public void putPortletWindow(PortletWindow window)
+ {
+ windows.put(window.getId().toString(), window);
+ portletEntityToWindow.put(window.getPortletEntity().getId().toString(), window.getId().toString());
+
+ }
+
+ public void removePortletWindow(String windowId)
+ {
+ PortletWindow window = (PortletWindow) windows.get(windowId);
+ if(window != null)
+ {
+ windows.remove(windowId);
+ portletEntityToWindow.remove(window.getPortletEntity().getId().toString());
+ }
+
+ }
+
+ public void removePortletWindowByPortletEntityId(String portletEntityId)
+ {
+ PortletWindow window = getPortletWindowByEntityId(portletEntityId);
+ if(window != null)
+ {
+ removePortletWindow(window.getId().toString());
+ }
+
+ }
+}
\ No newline at end of file
Propchange: portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/portal/src/test/org/apache/jetspeed/HashMapWindowCache.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/portal/src/test/org/apache/jetspeed/HashMapWindowCache.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/portal/src/test/org/apache/jetspeed/HashMapWindowCache.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/portal/src/test/org/apache/jetspeed/window/TestWindows.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/portal/src/test/org/apache/jetspeed/window/TestWindows.java?rev=648024&r1=648023&r2=648024&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/portal/src/test/org/apache/jetspeed/window/TestWindows.java (original)
+++ portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/portal/src/test/org/apache/jetspeed/window/TestWindows.java Mon Apr 14 15:02:13 2008
@@ -25,6 +25,7 @@
import junit.framework.TestCase;
import junit.framework.TestSuite;
+import org.apache.jetspeed.HashMapWindowCache;
import org.apache.jetspeed.PortletFactoryMock;
import org.apache.jetspeed.components.portletentity.PortletEntityAccessComponent;
import org.apache.jetspeed.container.window.PortletWindowAccessor;
@@ -33,6 +34,7 @@
import org.apache.jetspeed.om.page.ContentFragment;
import org.apache.jetspeed.om.page.Fragment;
import org.apache.jetspeed.om.page.ContentFragmentImpl;
+import org.apache.jetspeed.util.JetspeedObjectID;
import org.apache.pluto.om.window.PortletWindow;
import org.apache.pluto.om.window.PortletWindowList;
import org.apache.pluto.om.window.PortletWindowListCtrl;
@@ -77,7 +79,7 @@
fragMock = new Mock(Fragment.class);
entityMock = new Mock(MutablePortletEntity.class);
windowListMock = new Mock(CompositeWindowList.class);
- windowAccess = new PortletWindowAccessorImpl((PortletEntityAccessComponent) entityAccessMock.proxy(), PortletFactoryMock.instance,true);
+ windowAccess = new PortletWindowAccessorImpl((PortletEntityAccessComponent) entityAccessMock.proxy(), PortletFactoryMock.instance, new HashMapWindowCache(),true);
}
public void testWindowAccess() throws Exception
@@ -92,6 +94,8 @@
.will(new ReturnStub("frag1"));
entityMock.expects(new InvokeAtLeastOnceMatcher()).method("getPortletWindowList").withNoArguments().will(
new ReturnStub(windowList));
+ entityMock.expects(new InvokeAtLeastOnceMatcher()).method("getId").withNoArguments().will(
+ new ReturnStub(new JetspeedObjectID("entity1")));
windowListMock.expects(new InvokeCountMatcher(4)).method("add").withAnyArguments().will(
new ListAppendStub(windows));
Modified: portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/core-build.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/core-build.xml?rev=648024&r1=648023&r2=648024&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/core-build.xml (original)
+++ portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/core-build.xml Mon Apr 14 15:02:13 2008
@@ -90,7 +90,8 @@
</properties>
</dependency>
<dependency>
- <id>cglib</id>
+ <id>cglib-nodep</id>
+ <groupId>cglib</groupId>
<version>2.1_3</version>
<properties>
<war.bundle>true</war.bundle>
@@ -223,11 +224,19 @@
<!-- Unit testing -->
<dependency>
<id>jmock</id>
- <version>1.0.1</version>
+ <version>1.2.0</version>
<properties>
<war.bundle>false</war.bundle>
</properties>
</dependency>
+ <dependency>
+ <id>jmock-cglib</id>
+ <groupId>jmock</groupId>
+ <version>1.1.0</version>
+ <properties>
+ <war.bundle>false</war.bundle>
+ </properties>
+ </dependency>
<dependency>
<id>mockrunner</id>
<version>0.3.8</version>
Modified: portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/etc/db-ojb/ehcache.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/etc/db-ojb/ehcache.xml?rev=648024&r1=648023&r2=648024&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/etc/db-ojb/ehcache.xml (original)
+++ portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/etc/db-ojb/ehcache.xml Mon Apr 14 15:02:13 2008
@@ -491,4 +491,13 @@
memoryStoreEvictionPolicy="LFU"
/>
+ <cache name="portletWindowCache"
+ maxElementsInMemory="200"
+ maxElementsOnDisk="1000"
+ eternal="false"
+ overflowToDisk="false"
+ timeToIdleSeconds="28800"
+ timeToLiveSeconds="28800"
+ memoryStoreEvictionPolicy="LFU"/>
+
</ehcache>
Modified: portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/etc/editors/m2.classpath
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/etc/editors/m2.classpath?rev=648024&r1=648023&r2=648024&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/etc/editors/m2.classpath (original)
+++ portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/etc/editors/m2.classpath Mon Apr 14 15:02:13 2008
@@ -80,7 +80,7 @@
<classpathentry kind="var" path="M2_REPO/commons-dbcp/commons-dbcp/1.2.2/commons-dbcp-1.2.2.jar"/>
<classpathentry kind="var" path="M2_REPO/commons-configuration/commons-configuration/1.1/commons-configuration-1.1.jar"/>
<classpathentry kind="var" path="M2_REPO/mockrunner/mockrunner/0.2.7/mockrunner-0.3.8.jar"/>
- <classpathentry kind="var" path="M2_REPO/jmock/jmock/1.0.1/mock-1.0.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/jmock/jmock/1.2.0/mock-1.2.0.jar"/>
<classpathentry kind="var" path="M2_REPO/saxpath/saxpath/1.0-FCS/saxpath-1.0-FCS.jar"/>
<classpathentry kind="var" path="M2_REPO/jaxen/jaxen/1.0-FCS/jaxen-1.0-FCS.jar"/>
<classpathentry kind="var" path="M2_REPO/aopalliance/aopalliance/1.0/aopalliance-1.0.jar"/>
@@ -92,7 +92,7 @@
<classpathentry kind="var" path="M2_REPO/commons-codec/commons-codec/1.3/commons-codec-1.3.jar"/>
<classpathentry kind="var" path="M2_REPO/rome/rome/0.8/rome-0.8.jar"/>
<classpathentry kind="var" path="M2_REPO/taglibs/standard/1.1.2/standard-1.1.2.jar"/>
- <classpathentry kind="var" path="M2_REPO/cglib/cglib-full/2.0.2/cglib-2.1_3.jar"/>
+ <classpathentry kind="var" path="M2_REPO/cglib/cglib-nodep/2.1_3/cglib-nodep-2.1_3.jar"/>
<classpathentry kind="var" path="M2_REPO/org/springframework/spring/2.0.5/spring-2.0.5.jar"/>
<classpathentry kind="var" path="M2_REPO/org/springframework/spring-mock/2.0.5/spring-mock-2.0.5.jar"/>
<classpathentry kind="var" path="M2_REPO/org/springframework/spring-portlet/2.0.5/spring-portlet-2.0.5.jar"/>
@@ -114,6 +114,7 @@
<classpathentry kind="var" path="M2_REPO/ant/ant/1.6.5/ant-1.6.5.jar"/>
<classpathentry kind="var" path="M2_REPO/ehcache/ehcache/1.2.4/ehcache-1.2.4.jar"/>
<classpathentry kind="var" path="M2_REPO/portlet-api/portlet-api/1.0/portlet-api-1.0.jar"/>
+ <classpathentry kind="var" path="M2_REPO/jmock/jmock-cglib/1.2.0/jmock-cglib-1.2.0.jar"/>
<classpathentry kind="var" path="M2_REPO/myfaces/myfaces-api/1.1.0/myfaces-api-1.1.4.jar"/>
<classpathentry kind="var" path="M2_REPO/myfaces/myfaces-impl/1.1.0/myfaces-impl-1.1.4.jar"/>
<classpathentry kind="var" path="M2_REPO/myfaces/tomahawk/1.1.0/tomahawk-1.1.4.jar"/>
Added: portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/jetspeed-api/src/java/org/apache/jetspeed/cache/PortletWindowCache.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/jetspeed-api/src/java/org/apache/jetspeed/cache/PortletWindowCache.java?rev=648024&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/jetspeed-api/src/java/org/apache/jetspeed/cache/PortletWindowCache.java (added)
+++ portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/jetspeed-api/src/java/org/apache/jetspeed/cache/PortletWindowCache.java Mon Apr 14 15:02:13 2008
@@ -0,0 +1,88 @@
+/*
+ * 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.cache;
+
+import java.util.List;
+import java.util.Set;
+
+import org.apache.pluto.om.entity.PortletEntity;
+import org.apache.pluto.om.window.PortletWindow;
+
+/**
+ * {@link org.apache.jetspeed.cache.impl.PortletWindowCache} is an abstraction of a caching mechanism for use
+ * within {@link org.apache.jetspeed.container.window.impl.PortletWindowAccessorImpl}.
+ *
+ * @author <a href="mailto:scott.t.weaver@gmail.com">Scott T. Weaver</a>
+ * @see PortletWindowAccessorImpl
+ * @see EhPortletWindowCache
+ *
+ */
+public interface PortletWindowCache
+{
+ /**
+ * Gets a {@link PortletWindow} from the cache.
+ *
+ * @param windowId Id of the window to get from the cache.
+ * @return {@link PortletWindow} whose <code>id</code> to
+ * {@link PortletWindow#getId()} or <code>null</code> if no window exists that matches
+ * <code>windowId</code>.
+ */
+ PortletWindow getPortletWindow(String windowId);
+
+ /**
+ * Gets a {@link PortletWindow} from the cache whose {@link PortletEntity}'s ({@link PortletWindow#getPortletEntity()})
+ * equals <code>portletEntityId</code>.
+ *
+ * @param portletEntityId id of {@link PortletEntity} whose window want want to retrieve from cache.
+ * @return {@link PortletWindow} whose {@link PortletEntity}'s id equals <code>portletEntityId</code>
+ * or <code>null</code> if no windows exists in the cache that match said criteria.
+ */
+ PortletWindow getPortletWindowByEntityId(String portletEntityId);
+
+ /**
+ * Stores a {@link PortletWindow} in the cache using the {@link PortletWindow#getId()#toString()}
+ * as the key for the cache.
+ *
+ * @param window {@link PortletWindow} to put into the cache.
+ */
+ void putPortletWindow(PortletWindow window);
+
+ /**
+ * Removes a {@link PortletWindow} from cache using the <code>windowId</code>
+ * as the cache key.
+ *
+ * @param windowId Id of the {@link PortletWindow} we want to remove from the cache.
+ */
+ void removePortletWindow(String windowId);
+
+ /**
+ * Removes a {@link PortletWindow} from the cache whose {@link PortletEntity}'s id
+ * matches <code>portletEntityId</code>.
+ *
+ * @param portletEntityId id of the {@link PortletEntity} whose parent {@link PortletWindow}
+ * is to be removed from the cache.
+ */
+ void removePortletWindowByPortletEntityId(String portletEntityId);
+
+ /**
+ *
+ * @return {@link List} of all the {@link PortletWindow}s in the cache. If no cache
+ * entries exist an empty list is returned. Never returns <code>null</code>.
+ */
+ Set getAllPortletWindows();
+
+}
\ No newline at end of file
Propchange: portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/jetspeed-api/src/java/org/apache/jetspeed/cache/PortletWindowCache.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/jetspeed-api/src/java/org/apache/jetspeed/cache/PortletWindowCache.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/jetspeed-api/src/java/org/apache/jetspeed/cache/PortletWindowCache.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org