You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pluto-scm@portals.apache.org by ms...@apache.org on 2016/01/21 16:12:25 UTC
[2/3] portals-pluto git commit: Worked on portlet session scoped bean
management.
Worked on portlet session scoped bean management.
Project: http://git-wip-us.apache.org/repos/asf/portals-pluto/repo
Commit: http://git-wip-us.apache.org/repos/asf/portals-pluto/commit/1fc34d12
Tree: http://git-wip-us.apache.org/repos/asf/portals-pluto/tree/1fc34d12
Diff: http://git-wip-us.apache.org/repos/asf/portals-pluto/diff/1fc34d12
Branch: refs/heads/V3Prototype
Commit: 1fc34d12ecf1af7733016f33da72b441e5f21c58
Parents: a5004de
Author: Scott Nicklous <ms...@apache.org>
Authored: Wed Jan 20 16:36:50 2016 +0100
Committer: Scott Nicklous <ms...@apache.org>
Committed: Wed Jan 20 16:36:50 2016 +0100
----------------------------------------------------------------------
.../samples/AppSessionRandomNumberBean.java | 56 +++++
.../samples/ApplicationRandomNumberBean.java | 52 +++++
.../portals/samples/HelloWorldRender.java | 29 ++-
.../samples/PortletSessionRandomNumberBean.java | 55 +++++
.../samples/RequestRandomNumberBean.java | 52 +++++
.../container/bean/processor/ConfigSummary.java | 21 +-
.../processor/PortletAnnotationRecognizer.java | 34 ++-
.../bean/processor/PortletInvoker.java | 2 +-
.../PortletRequestScopedAnnotatedType.java | 149 +++++++++++++
.../processor/PortletSessionBeanHolder.java | 212 ++++++-------------
.../PortletSessionScopedAnnotatedType.java | 18 +-
.../processor/PortletSessionScopedBeanMap.java | 185 ++++++++++++++++
.../processor/PortletSessionScopedConfig.java | 2 +-
.../processor/fixtures/SessionScopedApp2.java | 37 ++++
.../tests/PortletSessionAppScopeTest.java | 24 +--
.../tests/PortletSessionScopedTest.java | 18 +-
16 files changed, 765 insertions(+), 181 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/1fc34d12/PortletV3AnnotatedDemo/src/main/java/org/apache/portals/samples/AppSessionRandomNumberBean.java
----------------------------------------------------------------------
diff --git a/PortletV3AnnotatedDemo/src/main/java/org/apache/portals/samples/AppSessionRandomNumberBean.java b/PortletV3AnnotatedDemo/src/main/java/org/apache/portals/samples/AppSessionRandomNumberBean.java
new file mode 100644
index 0000000..f15f642
--- /dev/null
+++ b/PortletV3AnnotatedDemo/src/main/java/org/apache/portals/samples/AppSessionRandomNumberBean.java
@@ -0,0 +1,56 @@
+/* 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.portals.samples;
+
+import java.io.Serializable;
+
+import javax.portlet.PortletSession;
+import javax.portlet.annotations.PortletSessionScoped;
+
+/**
+ * Provides a random number generated once per request.
+ * @author Scott Nicklous
+ *
+ */
+@PortletSessionScoped(PortletSession.APPLICATION_SCOPE)
+public class AppSessionRandomNumberBean implements Serializable {
+ private static final long serialVersionUID = -5412855426733207637L;
+
+ private int randomNumber;
+
+ public AppSessionRandomNumberBean() {
+ randomNumber = ((int)(Math.random() * 1000)) - 500;
+ }
+
+ /**
+ * @return the randomNumber
+ */
+ public int getRandomNumber() {
+ return randomNumber;
+ }
+
+ /**
+ * @param randomNumber the randomNumber to set
+ */
+ public void setRandomNumber(int randomNumber) {
+ this.randomNumber = randomNumber;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/1fc34d12/PortletV3AnnotatedDemo/src/main/java/org/apache/portals/samples/ApplicationRandomNumberBean.java
----------------------------------------------------------------------
diff --git a/PortletV3AnnotatedDemo/src/main/java/org/apache/portals/samples/ApplicationRandomNumberBean.java b/PortletV3AnnotatedDemo/src/main/java/org/apache/portals/samples/ApplicationRandomNumberBean.java
new file mode 100644
index 0000000..d478ff4
--- /dev/null
+++ b/PortletV3AnnotatedDemo/src/main/java/org/apache/portals/samples/ApplicationRandomNumberBean.java
@@ -0,0 +1,52 @@
+/* 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.portals.samples;
+
+import javax.enterprise.context.ApplicationScoped;
+
+/**
+ * Provides a random number generated once per request.
+ * @author Scott Nicklous
+ *
+ */
+@ApplicationScoped
+public class ApplicationRandomNumberBean {
+
+ private int randomNumber;
+
+ public ApplicationRandomNumberBean() {
+ randomNumber = ((int)(Math.random() * 1000)) - 500;
+ }
+
+ /**
+ * @return the randomNumber
+ */
+ public int getRandomNumber() {
+ return randomNumber;
+ }
+
+ /**
+ * @param randomNumber the randomNumber to set
+ */
+ public void setRandomNumber(int randomNumber) {
+ this.randomNumber = randomNumber;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/1fc34d12/PortletV3AnnotatedDemo/src/main/java/org/apache/portals/samples/HelloWorldRender.java
----------------------------------------------------------------------
diff --git a/PortletV3AnnotatedDemo/src/main/java/org/apache/portals/samples/HelloWorldRender.java b/PortletV3AnnotatedDemo/src/main/java/org/apache/portals/samples/HelloWorldRender.java
index b835d00..c8cd7a0 100644
--- a/PortletV3AnnotatedDemo/src/main/java/org/apache/portals/samples/HelloWorldRender.java
+++ b/PortletV3AnnotatedDemo/src/main/java/org/apache/portals/samples/HelloWorldRender.java
@@ -32,6 +32,18 @@ public class HelloWorldRender {
// entered through the form.
@Inject
private NameBean nameBean;
+
+ @Inject
+ private RequestRandomNumberBean reqrn;
+
+ @Inject
+ private PortletSessionRandomNumberBean pltsessrn;
+
+ @Inject
+ private AppSessionRandomNumberBean appsessrn;
+
+ @Inject
+ private ApplicationRandomNumberBean apprn;
/**
* Bean portlet render method for "BeanHelloWorld" portlet.
@@ -44,15 +56,24 @@ public class HelloWorldRender {
StringBuilder txt = new StringBuilder(128);
- txt.append("<h3>Hello ");
-
+ txt.append("<h3>Hello \n");
// Get the name from the bean. If it hasn't been set, just greet the world.
if (nameBean.getName() != null) {
txt.append(nameBean.getName());
} else {
- txt.append("World");
+ txt.append("World\n");
}
- txt.append("!!</h3>");
+ txt.append("!!</h3>\n");
+
+ txt.append("<table><tr><td align='left'>\n");
+ txt.append("Application Scoped number:</td><td>").append(apprn.getRandomNumber());
+ txt.append("</td></tr><tr><td>\n");
+ txt.append("Portlet session scoped (Application) number:</td><td>").append(appsessrn.getRandomNumber());
+ txt.append("</td></tr><tr><td>\n");
+ txt.append("Portlet session scoped (Portlet) number:</td><td>").append(pltsessrn.getRandomNumber());
+ txt.append("</td></tr><tr><td>\n");
+ txt.append("Request number:</td><td>").append(reqrn.getRandomNumber());
+ txt.append("</td></tr></table>\n");
return txt.toString();
}
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/1fc34d12/PortletV3AnnotatedDemo/src/main/java/org/apache/portals/samples/PortletSessionRandomNumberBean.java
----------------------------------------------------------------------
diff --git a/PortletV3AnnotatedDemo/src/main/java/org/apache/portals/samples/PortletSessionRandomNumberBean.java b/PortletV3AnnotatedDemo/src/main/java/org/apache/portals/samples/PortletSessionRandomNumberBean.java
new file mode 100644
index 0000000..5272b1e
--- /dev/null
+++ b/PortletV3AnnotatedDemo/src/main/java/org/apache/portals/samples/PortletSessionRandomNumberBean.java
@@ -0,0 +1,55 @@
+/* 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.portals.samples;
+
+import java.io.Serializable;
+
+import javax.portlet.annotations.PortletSessionScoped;
+
+/**
+ * Provides a random number generated once per request.
+ * @author Scott Nicklous
+ *
+ */
+@PortletSessionScoped
+public class PortletSessionRandomNumberBean implements Serializable{
+ private static final long serialVersionUID = -7072838091228517612L;
+
+ private int randomNumber;
+
+ public PortletSessionRandomNumberBean() {
+ randomNumber = ((int)(Math.random() * 1000)) - 500;
+ }
+
+ /**
+ * @return the randomNumber
+ */
+ public int getRandomNumber() {
+ return randomNumber;
+ }
+
+ /**
+ * @param randomNumber the randomNumber to set
+ */
+ public void setRandomNumber(int randomNumber) {
+ this.randomNumber = randomNumber;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/1fc34d12/PortletV3AnnotatedDemo/src/main/java/org/apache/portals/samples/RequestRandomNumberBean.java
----------------------------------------------------------------------
diff --git a/PortletV3AnnotatedDemo/src/main/java/org/apache/portals/samples/RequestRandomNumberBean.java b/PortletV3AnnotatedDemo/src/main/java/org/apache/portals/samples/RequestRandomNumberBean.java
new file mode 100644
index 0000000..6ad9f05
--- /dev/null
+++ b/PortletV3AnnotatedDemo/src/main/java/org/apache/portals/samples/RequestRandomNumberBean.java
@@ -0,0 +1,52 @@
+/* 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.portals.samples;
+
+import javax.enterprise.context.RequestScoped;
+
+/**
+ * Provides a random number generated once per request.
+ * @author Scott Nicklous
+ *
+ */
+@RequestScoped
+public class RequestRandomNumberBean {
+
+ private int randomNumber;
+
+ public RequestRandomNumberBean() {
+ randomNumber = ((int)(Math.random() * 1000)) - 500;
+ }
+
+ /**
+ * @return the randomNumber
+ */
+ public int getRandomNumber() {
+ return randomNumber;
+ }
+
+ /**
+ * @param randomNumber the randomNumber to set
+ */
+ public void setRandomNumber(int randomNumber) {
+ this.randomNumber = randomNumber;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/1fc34d12/pluto-container/src/main/java/org/apache/pluto/container/bean/processor/ConfigSummary.java
----------------------------------------------------------------------
diff --git a/pluto-container/src/main/java/org/apache/pluto/container/bean/processor/ConfigSummary.java b/pluto-container/src/main/java/org/apache/pluto/container/bean/processor/ConfigSummary.java
index ebbb309..2978262 100644
--- a/pluto-container/src/main/java/org/apache/pluto/container/bean/processor/ConfigSummary.java
+++ b/pluto-container/src/main/java/org/apache/pluto/container/bean/processor/ConfigSummary.java
@@ -36,6 +36,9 @@ public class ConfigSummary {
// List of PortletSessionScoped beans with APPLICATION_SCOPE
List<PortletSessionScopedAnnotatedType> appScopedTypes = new ArrayList<PortletSessionScopedAnnotatedType>();
+
+ // List of RequestScoped beans
+ List<PortletRequestScopedAnnotatedType> reqScopedTypes = new ArrayList<PortletRequestScopedAnnotatedType>();
// Per-class error messages for portlet session scoped bean deployment problems
private final Map<Class<?>, String> badSessionBeans = new HashMap<Class<?>, String>();
@@ -43,7 +46,7 @@ public class ConfigSummary {
// Per-class error messages for portlet state scoped bean deployment problems
private final Map<Class<?>, String> badStateBeans = new HashMap<Class<?>, String>();
- // Per-portlet error messages for deployment problems
+ // Per-portlet error messages for deployment problems. Key is the portlet name.
private final Map<String, List<String>> errors = new TreeMap<String, List<String>>();
/**
@@ -163,4 +166,20 @@ public class ConfigSummary {
return appScopedTypes;
}
+ /**
+ * Returns list of all request scoped beans
+ * @return the reqScopedTypes
+ */
+ public List<PortletRequestScopedAnnotatedType> getReqScopedTypes() {
+ return reqScopedTypes;
+ }
+
+ /**
+ * Adds a request scoped bean to the summary list
+ * @param reqScopedTypes the reqScopedTypes to set
+ */
+ public void addReqScopedType(PortletRequestScopedAnnotatedType type) {
+ reqScopedTypes.add(type);
+ }
+
}
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/1fc34d12/pluto-container/src/main/java/org/apache/pluto/container/bean/processor/PortletAnnotationRecognizer.java
----------------------------------------------------------------------
diff --git a/pluto-container/src/main/java/org/apache/pluto/container/bean/processor/PortletAnnotationRecognizer.java b/pluto-container/src/main/java/org/apache/pluto/container/bean/processor/PortletAnnotationRecognizer.java
index 074aa5f..7026200 100644
--- a/pluto-container/src/main/java/org/apache/pluto/container/bean/processor/PortletAnnotationRecognizer.java
+++ b/pluto-container/src/main/java/org/apache/pluto/container/bean/processor/PortletAnnotationRecognizer.java
@@ -37,6 +37,8 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.context.SessionScoped;
import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.inject.spi.BeanManager;
import javax.portlet.PortletException;
@@ -69,9 +71,11 @@ public class PortletAnnotationRecognizer extends AnnotationRecognizer {
static {
classAnnotations.add(PortletStateScoped.class);
classAnnotations.add(PortletSessionScoped.class);
+ classAnnotations.add(SessionScoped.class);
+ classAnnotations.add(RequestScoped.class);
}
- // Maps the annotation class to a list of method descriptions. A given annnotation
+ // Maps the annotation class to a list of method descriptions. A given annotation
// may support multiple method signatures, each of which has its own method description.
private final static Map<Class<? extends Annotation>, List<MethodDescription>> descriptions =
new HashMap<Class<? extends Annotation>, List<MethodDescription>>();
@@ -237,15 +241,29 @@ public class PortletAnnotationRecognizer extends AnnotationRecognizer {
LOG.debug(txt.toString());
summary.addSessionBeanErrorString(theClass, txt.toString());
} else {
- if (pss.value() == PortletSession.APPLICATION_SCOPE) {
- PortletSessionScopedAnnotatedType at = new PortletSessionScopedAnnotatedType((AnnotatedType<PortletSessionScoped>)aType);
- summary.addAppScopedType(at);
- return at;
- } else {
- sessionScopedConfig.addAnnotation(theClass, pss);
- }
+ sessionScopedConfig.addAnnotation(theClass, pss);
}
+ } else if (anno instanceof RequestScoped) {
+
+ // Wrap the request scoped bean to make it a portlet request scoped bean, add it to
+ // the summary, and return it so it gets processed by CDI
+
+ PortletRequestScopedAnnotatedType at = new PortletRequestScopedAnnotatedType((AnnotatedType<RequestScoped>)aType);
+ summary.addReqScopedType(at);
+ return at;
+
+ } else if (anno instanceof SessionScoped) {
+
+ // Wrap the session scoped bean to make it a portlet session scoped bean with application
+ // scope, add it to the summary, and return it so it gets processed by CDI
+
+ PortletSessionScopedAnnotatedType at = new PortletSessionScopedAnnotatedType((AnnotatedType<SessionScoped>)aType);
+ PortletSessionScoped pss = at.getAnnotation(PortletSessionScoped.class);
+ sessionScopedConfig.addAnnotation(theClass, pss);
+ summary.addAppScopedType(at);
+ return at;
+
} else {
// Any other annotation that lands here indicates a programming error
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/1fc34d12/pluto-container/src/main/java/org/apache/pluto/container/bean/processor/PortletInvoker.java
----------------------------------------------------------------------
diff --git a/pluto-container/src/main/java/org/apache/pluto/container/bean/processor/PortletInvoker.java b/pluto-container/src/main/java/org/apache/pluto/container/bean/processor/PortletInvoker.java
index 2e1a960..33853a9 100644
--- a/pluto-container/src/main/java/org/apache/pluto/container/bean/processor/PortletInvoker.java
+++ b/pluto-container/src/main/java/org/apache/pluto/container/bean/processor/PortletInvoker.java
@@ -117,7 +117,7 @@ public class PortletInvoker implements Portlet, ResourceServingPortlet, EventPor
PortletRequestScopedBeanHolder.setBeanHolder();
// Set the portlet session bean holder for the thread & session
- PortletSessionBeanHolder.setBeanHolder(req.getPortletSession());
+ PortletSessionBeanHolder.setBeanHolder(req, acb.getSessionScopedConfig());
// Set the portlet state scoped bean holder
PortletStateScopedBeanHolder.setBeanHolder(req, acb.getStateScopedConfig());
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/1fc34d12/pluto-container/src/main/java/org/apache/pluto/container/bean/processor/PortletRequestScopedAnnotatedType.java
----------------------------------------------------------------------
diff --git a/pluto-container/src/main/java/org/apache/pluto/container/bean/processor/PortletRequestScopedAnnotatedType.java b/pluto-container/src/main/java/org/apache/pluto/container/bean/processor/PortletRequestScopedAnnotatedType.java
new file mode 100644
index 0000000..8af9e7f
--- /dev/null
+++ b/pluto-container/src/main/java/org/apache/pluto/container/bean/processor/PortletRequestScopedAnnotatedType.java
@@ -0,0 +1,149 @@
+/* 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.pluto.container.bean.processor;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.inject.spi.AnnotatedConstructor;
+import javax.enterprise.inject.spi.AnnotatedField;
+import javax.enterprise.inject.spi.AnnotatedMethod;
+import javax.enterprise.inject.spi.AnnotatedType;
+import javax.portlet.annotations.PortletRequestScoped;
+
+/**
+ * A wrapper for a RequestScoped annotated type
+ * that replaces the <code>{@literal @}RequestScoped</code> annotation with
+ * <code>{@literal @}PortletRequestScoped</code> in order to assure that the bean
+ * is scoped to the portlet request rather than to the underlying servlet request.
+ *
+ * @author Scott
+ *
+ */
+public class PortletRequestScopedAnnotatedType implements AnnotatedType<RequestScoped> {
+
+ // to obtain annotation instances
+ @RequestScoped
+ @PortletRequestScoped
+ private class Dummy {}
+
+ // the wrapped type.
+ private final AnnotatedType<RequestScoped> aType;
+
+ // The set of annotations
+ private final Set<Annotation> annos = new HashSet<Annotation>();
+
+ /**
+ * Construct the wrapper.
+ */
+ public PortletRequestScopedAnnotatedType(AnnotatedType<RequestScoped> type) {
+ aType = type;
+ annos.addAll(type.getAnnotations());
+ annos.remove(Dummy.class.getAnnotation(RequestScoped.class));
+ annos.add(Dummy.class.getAnnotation(PortletRequestScoped.class));
+ }
+
+ /* (non-Javadoc)
+ * @see javax.enterprise.inject.spi.Annotated#getAnnotation(java.lang.Class)
+ */
+ @SuppressWarnings({"unchecked"})
+ @Override
+ public <U extends Annotation> U getAnnotation(Class<U> type) {
+ for (Annotation a : annos) {
+ if (type.equals(a.annotationType())) {
+ return (U) a;
+ }
+ }
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.enterprise.inject.spi.Annotated#getAnnotations()
+ */
+ @Override
+ public Set<Annotation> getAnnotations() {
+ return new HashSet<Annotation>(annos);
+ }
+
+ /* (non-Javadoc)
+ * @see javax.enterprise.inject.spi.Annotated#getBaseType()
+ */
+ @Override
+ public Type getBaseType() {
+ return aType.getBaseType();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.enterprise.inject.spi.Annotated#getTypeClosure()
+ */
+ @Override
+ public Set<Type> getTypeClosure() {
+ return aType.getTypeClosure();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.enterprise.inject.spi.Annotated#isAnnotationPresent(java.lang.Class)
+ */
+ @Override
+ public boolean isAnnotationPresent(Class<? extends Annotation> type) {
+ for (Annotation a : annos) {
+ if (type.equals(a.annotationType())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.enterprise.inject.spi.AnnotatedType#getConstructors()
+ */
+ @Override
+ public Set<AnnotatedConstructor<RequestScoped>> getConstructors() {
+ return aType.getConstructors();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.enterprise.inject.spi.AnnotatedType#getFields()
+ */
+ @Override
+ public Set<AnnotatedField<? super RequestScoped>> getFields() {
+ return aType.getFields();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.enterprise.inject.spi.AnnotatedType#getJavaClass()
+ */
+ @Override
+ public Class<RequestScoped> getJavaClass() {
+ return aType.getJavaClass();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.enterprise.inject.spi.AnnotatedType#getMethods()
+ */
+ @Override
+ public Set<AnnotatedMethod<? super RequestScoped>> getMethods() {
+ return aType.getMethods();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/1fc34d12/pluto-container/src/main/java/org/apache/pluto/container/bean/processor/PortletSessionBeanHolder.java
----------------------------------------------------------------------
diff --git a/pluto-container/src/main/java/org/apache/pluto/container/bean/processor/PortletSessionBeanHolder.java b/pluto-container/src/main/java/org/apache/pluto/container/bean/processor/PortletSessionBeanHolder.java
index 8491fa8..665e221 100644
--- a/pluto-container/src/main/java/org/apache/pluto/container/bean/processor/PortletSessionBeanHolder.java
+++ b/pluto-container/src/main/java/org/apache/pluto/container/bean/processor/PortletSessionBeanHolder.java
@@ -16,19 +16,14 @@
* under the License.
*/
-
package org.apache.pluto.container.bean.processor;
import java.io.Serializable;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
import javax.enterprise.context.spi.Contextual;
import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.inject.spi.Bean;
+import javax.portlet.PortletRequest;
import javax.portlet.PortletSession;
-import javax.servlet.http.HttpSessionBindingEvent;
-import javax.servlet.http.HttpSessionBindingListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -37,67 +32,74 @@ import org.slf4j.LoggerFactory;
* This is a container for PortletSessionScoped CDI beans.
*
* @author nick
- *
+ *
*/
-public class PortletSessionBeanHolder implements HttpSessionBindingListener, Serializable {
- private static final Logger LOG = LoggerFactory.getLogger(PortletSessionBeanHolder.class);
- private static final boolean isDebug = LOG.isDebugEnabled();
-
-
- private static final long serialVersionUID = 4713451590109713169L;
- private static final String ATTRIBNAME = "portletSessionBeanHolder";
-
- private class BeanInstance<T> implements Serializable {
- private static final long serialVersionUID = -2094530892049932082L;
- CreationalContext<T> crco;
- T instance;
- }
-
- // Each instance of the bean holder gets its own map
- private Map<Contextual<?>, BeanInstance<?>> beans =
- new ConcurrentHashMap<Contextual<?>, BeanInstance<?>>();
-
+public class PortletSessionBeanHolder implements Serializable {
+ private static final Logger LOG = LoggerFactory
+ .getLogger(PortletSessionBeanHolder.class);
+ private static final boolean isDebug = LOG.isDebugEnabled();
+
+ private static final long serialVersionUID = 4713451590109713169L;
+ private static final String ATTRIBNAME = "portletSessionBeanHolder";
+
// The ThreadLocal manages the holders so that there is one holder per thread.
- private static final ThreadLocal<PortletSessionBeanHolder> holders =
- new ThreadLocal<PortletSessionBeanHolder>();
-
+ private static final ThreadLocal<PortletSessionBeanHolder> holders = new ThreadLocal<PortletSessionBeanHolder>();
+
+ // ========== Instance vars
+
+ private final PortletSessionScopedBeanMap beans;
+ private final PortletSessionScopedConfig config;
+ private final String windowId;
+
/**
- * private constructor
+ * private constructor ... constructed once per thread
*/
- private PortletSessionBeanHolder() {
+ private PortletSessionBeanHolder(PortletSessionScopedBeanMap beans, String windowId,
+ PortletSessionScopedConfig config) {
+ this.beans = beans;
+ this.windowId = windowId;
+ this.config = config;
}
/**
- * Sets the portlet session bean holder in a ThreadLocal object for the given
- * portlet session. If no bean holder exists in the session, a new one is created.
+ * Sets the portlet session bean holder in a ThreadLocal object for the given portlet session. If no bean holder
+ * exists in the session, a new one is created.
*
- * @param ps The portlet session.
- * @return The portlet session bean holder
+ * @param ps
+ * The portlet session.
+ * @return The portlet session bean holder
*/
- public static void setBeanHolder(PortletSession ps) {
-
+ public static void setBeanHolder(PortletRequest req, PortletSessionScopedConfig config) {
+
+ PortletSession ps = req.getPortletSession();
+ String windowId = req.getWindowID();
+
if (isDebug) {
StringBuilder txt = new StringBuilder(80);
txt.append("Setting portlet session bean holder.");
- txt.append(" ThreadId=").append(Thread.currentThread().getId());
- txt.append(", PortletSession=").append(ps.getId());
+ txt.append(" ThreadId: ").append(Thread.currentThread().getId());
+ txt.append(", PortletSession: ").append(ps.getId());
+ txt.append(", WindowId: ").append(windowId);
LOG.debug(txt.toString());
}
-
- PortletSessionBeanHolder holder = (PortletSessionBeanHolder) ps.getAttribute(ATTRIBNAME);
- if (holder == null) {
- holder = new PortletSessionBeanHolder();
- ps.setAttribute(ATTRIBNAME, holder);
+
+ PortletSessionScopedBeanMap map = (PortletSessionScopedBeanMap) ps.getAttribute(ATTRIBNAME,
+ PortletSession.APPLICATION_SCOPE);
+ if (map == null) {
+ map = new PortletSessionScopedBeanMap();
+ ps.setAttribute(ATTRIBNAME, map, PortletSession.APPLICATION_SCOPE);
if (isDebug) {
StringBuilder txt = new StringBuilder(80);
- txt.append("Created new portlet session holder.");
+ txt.append("Created new portlet session bean map.");
LOG.debug(txt.toString());
}
}
+
+ PortletSessionBeanHolder holder = new PortletSessionBeanHolder(map, windowId, config);
holders.set(holder);
}
-
+
/**
* Removes the bean holder for the current session.
*/
@@ -111,7 +113,7 @@ public class PortletSessionBeanHolder implements HttpSessionBindingListener, Ser
LOG.debug(txt.toString());
}
}
-
+
/**
* Returns the portlet session bean holder that was set for the thread.
*
@@ -120,115 +122,37 @@ public class PortletSessionBeanHolder implements HttpSessionBindingListener, Ser
public static PortletSessionBeanHolder getBeanHolder() {
return holders.get();
}
-
- /**
- * Returns an instance for the contextual type, or null if none available.
- *
- * @param bean Contextual type (Bean) for which an instance is desired
- * @return The instance, or null if none exists
- */
- @SuppressWarnings("unchecked")
- public <T> T getBean(Contextual<T> bean) {
- BeanInstance<?> bi = beans.get(bean);
-
- if (isDebug) {
- StringBuilder txt = new StringBuilder(80);
- txt.append("Getting bean: ");
- if (bean instanceof Bean<?>) {
- Bean<?> b = (Bean<?>) bean;
- txt.append(b.getBeanClass().getSimpleName());
- }
- if (bi == null) {
- txt.append(", instance is null.");
- }
- LOG.debug(txt.toString());
- }
- return (bi == null) ? null : (T) bi.instance;
- }
-
/**
- * Adds a bean instance with associated creational context to the store for the
- * given contextual object (bean).
+ * Returns an instance for the contextual type, or null if none available.
*
- * @param bean The bean type
- * @param crco The creational context
- * @param instance The bean instance
- */
- public <T> void putBeanInstance(Contextual<T> bean, CreationalContext<T> crco, T instance) {
- BeanInstance<T> bi = new BeanInstance<T>();
- bi.crco = crco;
- bi.instance = instance;
- beans.put(bean, bi);
-
- if (isDebug) {
- StringBuilder txt = new StringBuilder(80);
- txt.append("Added bean: ");
- if (bean instanceof Bean<?>) {
- Bean<?> b = (Bean<?>) bean;
- txt.append(b.getBeanClass().getSimpleName());
- }
- LOG.debug(txt.toString());
- }
- }
-
- /**
- * Removes & destroys the given bean
* @param bean
+ * Contextual type (Bean) for which an instance is desired
+ * @return The instance, or null if none exists
*/
- @SuppressWarnings("unchecked")
- protected <T> void remove(Contextual<T> bean) {
- BeanInstance<?> bi = beans.get(bean);
-
- if (isDebug) {
- StringBuilder txt = new StringBuilder(80);
- txt.append("Removing bean: ");
- if (bean instanceof Bean<?>) {
- Bean<?> b = (Bean<?>) bean;
- txt.append(b.getBeanClass().getSimpleName());
- }
- if (bi == null) {
- txt.append(", instance is null.");
- }
- LOG.debug(txt.toString());
- }
-
- if (bi != null) {
- beans.remove(bean);
- bi.crco.release();
- bean.destroy((T)bi.instance, (CreationalContext<T>)bi.crco);
- }
- }
-
- /**
- * Remove & destroy all beans
- */
- protected void removeAll() {
- for (Contextual<?> bean : beans.keySet()) {
- remove(bean);
+ public <T> T getBean(Contextual<T> bean) {
+ String id = null;
+ if (config.isPortletScoped(bean)) {
+ id = windowId;
}
+ return beans.getBeanInstance(id, bean);
}
/**
- * Session binding listener method - binding to session
- *
- * @param arg0
- */
- @Override
- public void valueBound(HttpSessionBindingEvent arg0) {
- }
-
- /**
- * Session binding listener method - unbinding from session.
- * This occurs only when the session times out or is destroyed (in our case).
+ * Adds a bean instance with associated creational context to the store for the given contextual object (bean).
*
- * @param arg0
+ * @param bean
+ * The bean type
+ * @param crco
+ * The creational context
+ * @param instance
+ * The bean instance
*/
- @Override
- public void valueUnbound(HttpSessionBindingEvent evt) {
- if (isDebug) {
- LOG.debug("PortletSessionBeanHolder unbound from session. ID=" + evt.getName());
+ public <T> void putBeanInstance(Contextual<T> bean, CreationalContext<T> crco, T instance) {
+ String id = null;
+ if (config.isPortletScoped(bean)) {
+ id = windowId;
}
- removeAll();
+ beans.putBeanInstance(id, bean, crco, instance);
}
}
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/1fc34d12/pluto-container/src/main/java/org/apache/pluto/container/bean/processor/PortletSessionScopedAnnotatedType.java
----------------------------------------------------------------------
diff --git a/pluto-container/src/main/java/org/apache/pluto/container/bean/processor/PortletSessionScopedAnnotatedType.java b/pluto-container/src/main/java/org/apache/pluto/container/bean/processor/PortletSessionScopedAnnotatedType.java
index 21fe4d4..5cfdd19 100644
--- a/pluto-container/src/main/java/org/apache/pluto/container/bean/processor/PortletSessionScopedAnnotatedType.java
+++ b/pluto-container/src/main/java/org/apache/pluto/container/bean/processor/PortletSessionScopedAnnotatedType.java
@@ -42,7 +42,7 @@ import javax.portlet.annotations.PortletSessionScoped;
* @author Scott
*
*/
-public class PortletSessionScopedAnnotatedType implements AnnotatedType<PortletSessionScoped> {
+public class PortletSessionScopedAnnotatedType implements AnnotatedType<SessionScoped> {
// to obtain annotation instances
@SessionScoped
@@ -50,7 +50,7 @@ public class PortletSessionScopedAnnotatedType implements AnnotatedType<PortletS
private class Dummy {}
// the wrapped type.
- private final AnnotatedType<PortletSessionScoped> aType;
+ private final AnnotatedType<SessionScoped> aType;
// The set of annotations
private final Set<Annotation> annos = new HashSet<Annotation>();
@@ -58,11 +58,11 @@ public class PortletSessionScopedAnnotatedType implements AnnotatedType<PortletS
/**
* Construct the wrapper.
*/
- public PortletSessionScopedAnnotatedType(AnnotatedType<PortletSessionScoped> type) {
+ public PortletSessionScopedAnnotatedType(AnnotatedType<SessionScoped> type) {
aType = type;
annos.addAll(type.getAnnotations());
- annos.remove(Dummy.class.getAnnotation(PortletSessionScoped.class));
- annos.add(Dummy.class.getAnnotation(SessionScoped.class));
+ annos.remove(Dummy.class.getAnnotation(SessionScoped.class));
+ annos.add(Dummy.class.getAnnotation(PortletSessionScoped.class));
}
/* (non-Javadoc)
@@ -120,7 +120,7 @@ public class PortletSessionScopedAnnotatedType implements AnnotatedType<PortletS
* @see javax.enterprise.inject.spi.AnnotatedType#getConstructors()
*/
@Override
- public Set<AnnotatedConstructor<PortletSessionScoped>> getConstructors() {
+ public Set<AnnotatedConstructor<SessionScoped>> getConstructors() {
return aType.getConstructors();
}
@@ -128,7 +128,7 @@ public class PortletSessionScopedAnnotatedType implements AnnotatedType<PortletS
* @see javax.enterprise.inject.spi.AnnotatedType#getFields()
*/
@Override
- public Set<AnnotatedField<? super PortletSessionScoped>> getFields() {
+ public Set<AnnotatedField<? super SessionScoped>> getFields() {
return aType.getFields();
}
@@ -136,7 +136,7 @@ public class PortletSessionScopedAnnotatedType implements AnnotatedType<PortletS
* @see javax.enterprise.inject.spi.AnnotatedType#getJavaClass()
*/
@Override
- public Class<PortletSessionScoped> getJavaClass() {
+ public Class<SessionScoped> getJavaClass() {
return aType.getJavaClass();
}
@@ -144,7 +144,7 @@ public class PortletSessionScopedAnnotatedType implements AnnotatedType<PortletS
* @see javax.enterprise.inject.spi.AnnotatedType#getMethods()
*/
@Override
- public Set<AnnotatedMethod<? super PortletSessionScoped>> getMethods() {
+ public Set<AnnotatedMethod<? super SessionScoped>> getMethods() {
return aType.getMethods();
}
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/1fc34d12/pluto-container/src/main/java/org/apache/pluto/container/bean/processor/PortletSessionScopedBeanMap.java
----------------------------------------------------------------------
diff --git a/pluto-container/src/main/java/org/apache/pluto/container/bean/processor/PortletSessionScopedBeanMap.java b/pluto-container/src/main/java/org/apache/pluto/container/bean/processor/PortletSessionScopedBeanMap.java
new file mode 100644
index 0000000..0f264d3
--- /dev/null
+++ b/pluto-container/src/main/java/org/apache/pluto/container/bean/processor/PortletSessionScopedBeanMap.java
@@ -0,0 +1,185 @@
+/* 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.pluto.container.bean.processor;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.enterprise.context.spi.Contextual;
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.Bean;
+import javax.servlet.http.HttpSessionBindingEvent;
+import javax.servlet.http.HttpSessionBindingListener;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * Map for portlet session scoped beans that allows for two keys: the window ID, and the
+ * contextual object whose instance is to be obtained. This map is stored in the portlet
+ * session with application scope and contains PortletSessionScoped beans of both portlet
+ * scope and application scope.
+ *
+ * @author Scott Nicklous
+ *
+ */
+public class PortletSessionScopedBeanMap implements HttpSessionBindingListener, Serializable {
+ private static final long serialVersionUID = -4770245090803443972L;
+
+ private static final Logger LOG = LoggerFactory.getLogger(PortletSessionScopedBeanMap.class);
+ private static final boolean isDebug = LOG.isDebugEnabled();
+
+ // Used in the bean map to designate application scoped beans.
+ private static final String WINDOW_ID_APPLICATION = "application";
+
+
+ private class BeanInstance<T> implements Serializable {
+ private static final long serialVersionUID = -2094530892049932082L;
+ CreationalContext<T> crco;
+ T instance;
+ }
+
+ // Map of window ID to map of contextuals to instances
+ private final Map<String, Map<Contextual<?>, BeanInstance<?>>> beans =
+ new HashMap<String, Map<Contextual<?>, BeanInstance<?>>>();
+
+
+ /**
+ * Adds a bean instance with associated creational context to the store for the
+ * given contextual object (bean).
+ *
+ * @param id The window ID
+ * @param bean The bean type
+ * @param crco The creational context
+ * @param instance The bean instance
+ */
+ public <T> void putBeanInstance(String id, Contextual<T> bean, CreationalContext<T> crco, T instance) {
+
+ BeanInstance<T> bi = new BeanInstance<T>();
+ bi.crco = crco;
+ bi.instance = instance;
+
+ if (id == null) {
+ id = WINDOW_ID_APPLICATION;
+ }
+
+ synchronized (beans) {
+ Map<Contextual<?>, BeanInstance<?>> beanMap = beans.get(id);
+ if (beanMap == null) {
+ beanMap = new HashMap<Contextual<?>, BeanInstance<?>>();
+ beans.put(id, beanMap);
+ LOG.debug("Added new bean map.");
+ }
+ beanMap.put(bean, bi);
+ }
+
+ if (isDebug) {
+ StringBuilder txt = new StringBuilder(80);
+ txt.append("Added bean: ");
+ if (bean instanceof Bean<?>) {
+ Bean<?> b = (Bean<?>) bean;
+ txt.append(b.getBeanClass().getSimpleName());
+ }
+ txt.append(", window ID: ").append(id);
+ LOG.debug(txt.toString());
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T> T getBeanInstance(String id, Contextual<T> bean) {
+ T instance = null;
+
+ if (id == null) {
+ id = WINDOW_ID_APPLICATION;
+ }
+
+ synchronized(beans) {
+ Map<Contextual<?>, BeanInstance<?>> beanMap = beans.get(id);
+ if (beanMap != null) {
+ instance = (T) beanMap.get(bean).instance;
+ }
+ }
+ LOG.debug("Window ID: " + id + ", instance: " + instance);
+ return instance;
+ }
+
+ /**
+ * Removes & destroys the given bean from the given bean map
+ * @param bean
+ */
+ @SuppressWarnings("unchecked")
+ private <T> void remove(String id, Map<Contextual<?>, BeanInstance<?>> beanMap, Contextual<T> bean) {
+ BeanInstance<?> bi = beanMap.get(bean);
+
+ if (isDebug) {
+ StringBuilder txt = new StringBuilder(80);
+ txt.append("Removing bean: ");
+ if (bean instanceof Bean<?>) {
+ Bean<?> b = (Bean<?>) bean;
+ txt.append(b.getBeanClass().getSimpleName());
+ }
+ txt.append(", window ID: ").append(id);
+ if (bi == null) {
+ txt.append(", instance is null.");
+ }
+ LOG.debug(txt.toString());
+ }
+
+ if (bi != null) {
+ beans.remove(bean);
+ bi.crco.release();
+ bean.destroy((T)bi.instance, (CreationalContext<T>)bi.crco);
+ }
+ }
+
+ /**
+ * Session binding listener method - binding to session
+ *
+ * @param arg0
+ */
+ @Override
+ public void valueBound(HttpSessionBindingEvent arg0) {
+ }
+
+ /**
+ * Session binding listener method - unbinding from session.
+ * This occurs only when the session times out or is destroyed (in our case).
+ *
+ * @param arg0
+ */
+ @Override
+ public void valueUnbound(HttpSessionBindingEvent evt) {
+ if (isDebug) {
+ LOG.debug("PortletSessionBeanHolder unbound from session. ID=" + evt.getName());
+ }
+
+ synchronized(beans) {
+ for (String id : beans.keySet()) {
+ Map<Contextual<?>, BeanInstance<?>> beanMap = beans.get(id);
+ for (Contextual<?> bean : beanMap.keySet()) {
+ remove(id, beanMap, bean);
+ }
+ }
+ beans.clear();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/1fc34d12/pluto-container/src/main/java/org/apache/pluto/container/bean/processor/PortletSessionScopedConfig.java
----------------------------------------------------------------------
diff --git a/pluto-container/src/main/java/org/apache/pluto/container/bean/processor/PortletSessionScopedConfig.java b/pluto-container/src/main/java/org/apache/pluto/container/bean/processor/PortletSessionScopedConfig.java
index c4353a5..7a14ae9 100644
--- a/pluto-container/src/main/java/org/apache/pluto/container/bean/processor/PortletSessionScopedConfig.java
+++ b/pluto-container/src/main/java/org/apache/pluto/container/bean/processor/PortletSessionScopedConfig.java
@@ -156,7 +156,7 @@ public class PortletSessionScopedConfig implements Serializable {
* @param bean The bean
* @return <code>true</code> if the bean is portlet scoped
*/
- public Boolean isPortletScoped(Bean<?> bean) {
+ public Boolean isPortletScoped(Contextual<?> bean) {
PortletSessionScoped anno = context2Anno.get(bean);
assert anno != null;
return (anno.value() == PortletSession.PORTLET_SCOPE);
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/1fc34d12/pluto-container/src/test/java/org/apache/pluto/container/bean/processor/fixtures/SessionScopedApp2.java
----------------------------------------------------------------------
diff --git a/pluto-container/src/test/java/org/apache/pluto/container/bean/processor/fixtures/SessionScopedApp2.java b/pluto-container/src/test/java/org/apache/pluto/container/bean/processor/fixtures/SessionScopedApp2.java
new file mode 100644
index 0000000..7325413
--- /dev/null
+++ b/pluto-container/src/test/java/org/apache/pluto/container/bean/processor/fixtures/SessionScopedApp2.java
@@ -0,0 +1,37 @@
+/* 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.pluto.container.bean.processor.fixtures;
+
+import java.io.Serializable;
+
+import javax.enterprise.context.SessionScoped;
+
+/**
+ * PortletSessionScoped bean with APPLICATION_SCOPE
+ * @author Scott Nicklous
+ *
+ */
+@SessionScoped
+public class SessionScopedApp2 implements Serializable {
+ private static final long serialVersionUID = -65231174707289554L;
+
+ public String sayHi() {return "Hi!";}
+
+}
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/1fc34d12/pluto-container/src/test/java/org/apache/pluto/container/bean/processor/tests/PortletSessionAppScopeTest.java
----------------------------------------------------------------------
diff --git a/pluto-container/src/test/java/org/apache/pluto/container/bean/processor/tests/PortletSessionAppScopeTest.java b/pluto-container/src/test/java/org/apache/pluto/container/bean/processor/tests/PortletSessionAppScopeTest.java
index efdba48..8f054ec 100644
--- a/pluto-container/src/test/java/org/apache/pluto/container/bean/processor/tests/PortletSessionAppScopeTest.java
+++ b/pluto-container/src/test/java/org/apache/pluto/container/bean/processor/tests/PortletSessionAppScopeTest.java
@@ -43,7 +43,7 @@ import org.apache.pluto.container.bean.processor.PortletSessionScopedAnnotatedTy
import org.apache.pluto.container.bean.processor.PortletSessionScopedConfig;
import org.apache.pluto.container.bean.processor.PortletStateScopedConfig;
import org.apache.pluto.container.bean.processor.fixtures.PortletStateScopedClass;
-import org.apache.pluto.container.bean.processor.fixtures.SessionScopedApp1;
+import org.apache.pluto.container.bean.processor.fixtures.SessionScopedApp2;
import org.jglue.cdiunit.AdditionalClasses;
import org.jglue.cdiunit.AdditionalPackages;
import org.jglue.cdiunit.CdiRunner;
@@ -104,12 +104,12 @@ public class PortletSessionAppScopeTest {
}
@Test
- public void checkNoPortletSessionScoped() throws Exception {
+ public void checkNoSessionScoped() throws Exception {
Set<Annotation> annos = appScoped.getAnnotations();
assertNotEquals(0, annos.size());
boolean ok = true;
for (Annotation a : annos) {
- if (a.annotationType().equals(PortletSessionScoped.class)) {
+ if (a.annotationType().equals(SessionScoped.class)) {
ok = false;
break;
}
@@ -118,12 +118,12 @@ public class PortletSessionAppScopeTest {
}
@Test
- public void checkSessionScoped() throws Exception {
+ public void checkPortletSessionScoped() throws Exception {
Set<Annotation> annos = appScoped.getAnnotations();
assertEquals(1, annos.size());
boolean ok = false;
for (Annotation a : annos) {
- if (a.annotationType().equals(SessionScoped.class)) {
+ if (a.annotationType().equals(PortletSessionScoped.class)) {
ok = true;
break;
}
@@ -132,35 +132,35 @@ public class PortletSessionAppScopeTest {
}
@Test
- public void doesNotContainPortletSessionScoped() throws Exception {
- assertFalse(appScoped.isAnnotationPresent(PortletSessionScoped.class));
+ public void doesNotContainSessionScoped() throws Exception {
+ assertFalse(appScoped.isAnnotationPresent(SessionScoped.class));
}
@Test
public void containsPortletSessionScoped() throws Exception {
- assertTrue(appScoped.isAnnotationPresent(SessionScoped.class));
+ assertTrue(appScoped.isAnnotationPresent(PortletSessionScoped.class));
}
@Test
public void getAnnotation() throws Exception {
- assertNotNull(appScoped.getAnnotation(SessionScoped.class));
+ assertNotNull(appScoped.getAnnotation(PortletSessionScoped.class));
}
@Test
public void getAnnotationBad() throws Exception {
- assertNull(appScoped.getAnnotation(PortletSessionScoped.class));
+ assertNull(appScoped.getAnnotation(SessionScoped.class));
}
@Test
public void checkJavaClass() throws Exception {
Class<?> cls = appScoped.getJavaClass();
- assertEquals(SessionScopedApp1.class, cls);
+ assertEquals(SessionScopedApp2.class, cls);
}
@Test
public void checkBaseType() throws Exception {
Type type = appScoped.getBaseType();
- assertEquals(SessionScopedApp1.class, type);
+ assertEquals(SessionScopedApp2.class, type);
}
// @Test
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/1fc34d12/pluto-container/src/test/java/org/apache/pluto/container/bean/processor/tests/PortletSessionScopedTest.java
----------------------------------------------------------------------
diff --git a/pluto-container/src/test/java/org/apache/pluto/container/bean/processor/tests/PortletSessionScopedTest.java b/pluto-container/src/test/java/org/apache/pluto/container/bean/processor/tests/PortletSessionScopedTest.java
index 995d443..ab51e65 100644
--- a/pluto-container/src/test/java/org/apache/pluto/container/bean/processor/tests/PortletSessionScopedTest.java
+++ b/pluto-container/src/test/java/org/apache/pluto/container/bean/processor/tests/PortletSessionScopedTest.java
@@ -37,6 +37,8 @@ import org.apache.pluto.container.bean.processor.PortletCDIExtension;
import org.apache.pluto.container.bean.processor.PortletSessionScopedConfig;
import org.apache.pluto.container.bean.processor.PortletStateScopedConfig;
import org.apache.pluto.container.bean.processor.fixtures.PortletStateScopedClass;
+import org.apache.pluto.container.bean.processor.fixtures.SessionScopedApp1;
+import org.apache.pluto.container.bean.processor.fixtures.SessionScopedApp2;
import org.apache.pluto.container.bean.processor.fixtures.SessionScopedPortlet1;
import org.apache.pluto.container.bean.processor.fixtures.SessionScopedPortlet2;
import org.apache.pluto.container.bean.processor.fixtures.SessionScopedPortletBad1;
@@ -89,7 +91,7 @@ public class PortletSessionScopedTest {
public void annotatedClassPresent1() {
Set<Class<?>> classes = sessConfig.getBeanClasses();
assertNotNull(classes);
- assertEquals(2, classes.size());
+ assertEquals(4, classes.size());
}
@Test
@@ -107,6 +109,20 @@ public class PortletSessionScopedTest {
}
@Test
+ public void annotatedClassPresent4() {
+ Set<Class<?>> classes = sessConfig.getBeanClasses();
+ assertNotNull(classes);
+ assertTrue(classes.contains(SessionScopedApp1.class));
+ }
+
+ @Test
+ public void annotatedClassPresent5() {
+ Set<Class<?>> classes = sessConfig.getBeanClasses();
+ assertNotNull(classes);
+ assertTrue(classes.contains(SessionScopedApp2.class));
+ }
+
+ @Test
public void annotatedClassNotPresent() {
Set<Class<?>> classes = sessConfig.getBeanClasses();
assertNotNull(classes);