Author: julien_viet
Date: 2010-02-22 06:29:35 -0500 (Mon, 22 Feb 2010)
New Revision: 1797
Added:
components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/content/StateContainerImpl.java
Modified:
components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/content/ContentManagerRegistry.java
components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/content/AbstractCustomization.java
components/mop/trunk/core/src/test/java/org/gatein/mop/core/support/content/gadget/GadgetContentProvider.java
components/mop/trunk/core/src/test/java/org/gatein/mop/core/support/content/portlet/PortletContentProvider.java
components/mop/trunk/spi/src/main/java/org/gatein/mop/spi/content/ContentProvider.java
components/mop/trunk/spi/src/main/java/org/gatein/mop/spi/content/StateContainer.java
Log:
better integration of content provider SPI
Modified:
components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/content/ContentManagerRegistry.java
===================================================================
---
components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/content/ContentManagerRegistry.java 2010-02-22
09:42:13 UTC (rev 1796)
+++
components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/content/ContentManagerRegistry.java 2010-02-22
11:29:35 UTC (rev 1797)
@@ -41,7 +41,7 @@
providers = new HashMap<String, ContentRegistration>();
}
- public synchronized <S> void register(ContentType<S> contentType,
ContentProvider<S> contentProvider)
+ public synchronized <E> void register(ContentType<E> contentType,
ContentProvider<E, ?> contentProvider)
{
if (contentType == null)
{
Modified:
components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/content/AbstractCustomization.java
===================================================================
---
components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/content/AbstractCustomization.java 2010-02-22
09:42:13 UTC (rev 1796)
+++
components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/content/AbstractCustomization.java 2010-02-22
11:29:35 UTC (rev 1797)
@@ -71,22 +71,6 @@
/** . */
public ChromatticSession session;
- /** . */
- private StateContainer container = new StateContainer() {
- public Object getState() {
- return getCustomizationState();
- }
-
- public void setState(Object state) {
- setCustomizationState((AbstractCustomizationState)state);
- }
- public <T> T create(Class<T> type) {
- T t = session.create(type);
- setCustomizationState((AbstractCustomizationState)t);
- return t;
- }
- };
-
@Id
public abstract String getId();
@@ -110,24 +94,19 @@
public abstract AbstractCustomization getParent();
- public Object getVirtualState()
+ private <E, I> E getVirtualState(ContentProvider<E, I> provider)
{
+ StateContainerImpl<E, I> container = new StateContainerImpl<E,
I>(provider, this);
- ContentType contentType = getType();
-
- String mimeType = contentType.getMimeType();
-
- ContentProvider contentProvider = registry.providers.get(mimeType).getProvider();
-
//
- Object childPayload = contentProvider.getState(container);
+ E childPayload = provider.getState(container);
//
- Object parentPayload = null;
+ E parentPayload = null;
AbstractCustomization parent = getParent();
if (parent != null)
{
- parentPayload = parent.getVirtualState();
+ parentPayload = parent.getVirtualState(provider);
}
//
@@ -135,7 +114,7 @@
{
if (childPayload != null)
{
- return contentProvider.combine(Arrays.asList(parentPayload, childPayload));
+ return provider.combine(Arrays.asList(parentPayload, childPayload));
}
else
{
@@ -148,12 +127,32 @@
}
}
+ private <E, I> E getState(ContentProvider<E, I> provider)
+ {
+ StateContainerImpl<E, I> container = new StateContainerImpl<E,
I>(provider, this);
+ return provider.getState(container);
+ }
+
+ private <E, I> void setState(ContentProvider<E, I> provider, E state)
+ {
+ StateContainerImpl<E, I> container = new StateContainerImpl<E,
I>(provider, this);
+ provider.setState(container, state);
+ }
+
+ public Object getVirtualState()
+ {
+ ContentType contentType = getType();
+ String mimeType = contentType.getMimeType();
+ ContentProvider<?, ?> provider =
registry.providers.get(mimeType).getProvider();
+ return getVirtualState(provider);
+ }
+
public Object getState()
{
ContentType contentType = getType();
String mimeType = contentType.getMimeType();
- ContentProvider contentProvider = registry.providers.get(mimeType).getProvider();
- return contentProvider.getState(container);
+ ContentProvider<?, ?> provider =
registry.providers.get(mimeType).getProvider();
+ return getState(provider);
}
public void setState(Object state)
@@ -161,7 +160,7 @@
ContentType contentType = getType();
String mimeType = contentType.getMimeType();
ContentProvider contentProvider = registry.providers.get(mimeType).getProvider();
- contentProvider.setState(container, state);
+ setState(contentProvider, state);
}
public Customization<Object> getCustomization(Set<CustomizationContext>
contexts)
Added:
components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/content/StateContainerImpl.java
===================================================================
---
components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/content/StateContainerImpl.java
(rev 0)
+++
components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/content/StateContainerImpl.java 2010-02-22
11:29:35 UTC (rev 1797)
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.gatein.mop.core.api.workspace.content;
+
+import org.gatein.mop.spi.content.ContentProvider;
+import org.gatein.mop.spi.content.StateContainer;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class StateContainerImpl<E, I> implements StateContainer<I> {
+
+ /** . */
+ private final AbstractCustomization customization;
+
+ /** . */
+ private final ContentProvider<E, I> provider;
+
+ /** . */
+ private final Class<I> stateType;
+
+ public StateContainerImpl(ContentProvider<E, I> provider, AbstractCustomization
customization) {
+ this.provider = provider;
+ this.stateType = provider.getInternalType();
+ this.customization = customization;
+ }
+
+ public I getState() {
+ return stateType.cast(customization.getCustomizationState());
+ }
+
+ public void setState(I state) {
+ customization.setCustomizationState((AbstractCustomizationState)state);
+ }
+
+ public I create() {
+ I i = customization.session.create(stateType);
+ setState(i);
+ return i;
+ }
+}
Modified:
components/mop/trunk/core/src/test/java/org/gatein/mop/core/support/content/gadget/GadgetContentProvider.java
===================================================================
---
components/mop/trunk/core/src/test/java/org/gatein/mop/core/support/content/gadget/GadgetContentProvider.java 2010-02-22
09:42:13 UTC (rev 1796)
+++
components/mop/trunk/core/src/test/java/org/gatein/mop/core/support/content/gadget/GadgetContentProvider.java 2010-02-22
11:29:35 UTC (rev 1797)
@@ -27,7 +27,7 @@
* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
* @version $Revision$
*/
-public class GadgetContentProvider implements ContentProvider<Gadget>
+public class GadgetContentProvider implements ContentProvider<Gadget, GadgetState>
{
public Gadget combine(List<Gadget> states)
@@ -35,9 +35,8 @@
throw new UnsupportedOperationException();
}
- public void setState(StateContainer container, Gadget state)
- {
- GadgetState prefs = (GadgetState)container.getState();
+ public void setState(StateContainer<GadgetState> container, Gadget state) {
+ GadgetState prefs = container.getState();
if (prefs != null)
{
if (state == null)
@@ -49,15 +48,15 @@
{
if (state != null)
{
- prefs = container.create(GadgetState.class);
+ prefs = container.create();
prefs.setUserPrefs(state.getUserPref());
}
}
}
- public Gadget getState(StateContainer container)
+ public Gadget getState(StateContainer<GadgetState> container)
{
- GadgetState prefs = (GadgetState)container.getState();
+ GadgetState prefs = container.getState();
if (prefs != null)
{
Gadget gadget = new Gadget();
@@ -70,8 +69,12 @@
}
}
- public Class<Gadget> getStateType()
+ public Class<Gadget> getExternalType()
{
return Gadget.class;
}
+
+ public Class<GadgetState> getInternalType() {
+ return GadgetState.class;
+ }
}
Modified:
components/mop/trunk/core/src/test/java/org/gatein/mop/core/support/content/portlet/PortletContentProvider.java
===================================================================
---
components/mop/trunk/core/src/test/java/org/gatein/mop/core/support/content/portlet/PortletContentProvider.java 2010-02-22
09:42:13 UTC (rev 1796)
+++
components/mop/trunk/core/src/test/java/org/gatein/mop/core/support/content/portlet/PortletContentProvider.java 2010-02-22
11:29:35 UTC (rev 1797)
@@ -29,7 +29,7 @@
* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
* @version $Revision$
*/
-public class PortletContentProvider implements ContentProvider<Preferences>
+public class PortletContentProvider implements ContentProvider<Preferences,
PortletPreferencesState>
{
public Preferences combine(List<Preferences> states)
@@ -53,9 +53,9 @@
return new Preferences(entries);
}
- public void setState(StateContainer container, Preferences state)
+ public void setState(StateContainer<PortletPreferencesState> container,
Preferences state)
{
- PortletPreferencesState prefs = (PortletPreferencesState)container.getState();
+ PortletPreferencesState prefs = container.getState();
//
if (prefs != null)
@@ -73,15 +73,15 @@
{
if (state != null)
{
- prefs = container.create(PortletPreferencesState.class);
+ prefs = container.create();
prefs.setPayload(state);
}
}
}
- public Preferences getState(StateContainer container)
+ public Preferences getState(StateContainer<PortletPreferencesState> container)
{
- PortletPreferencesState prefs = (PortletPreferencesState)container.getState();
+ PortletPreferencesState prefs = container.getState();
if (prefs != null)
{
return prefs.getPayload();
@@ -92,8 +92,12 @@
}
}
- public Class<Preferences> getStateType()
+ public Class<Preferences> getExternalType()
{
return Preferences.class;
}
+
+ public Class<PortletPreferencesState> getInternalType() {
+ return PortletPreferencesState.class;
+ }
}
Modified:
components/mop/trunk/spi/src/main/java/org/gatein/mop/spi/content/ContentProvider.java
===================================================================
---
components/mop/trunk/spi/src/main/java/org/gatein/mop/spi/content/ContentProvider.java 2010-02-22
09:42:13 UTC (rev 1796)
+++
components/mop/trunk/spi/src/main/java/org/gatein/mop/spi/content/ContentProvider.java 2010-02-22
11:29:35 UTC (rev 1797)
@@ -23,8 +23,10 @@
/**
* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
* @version $Revision$
+ * @param <E> the external state type
+ * @param <I> the internal state type
*/
-public interface ContentProvider<S>
+public interface ContentProvider<E, I>
{
/**
@@ -33,7 +35,7 @@
* @param states the various states to combine
* @return the combined state
*/
- S combine(List<S> states);
+ E combine(List<E> states);
/**
* Update the state container with the provided state.
@@ -41,7 +43,7 @@
* @param container the state container
* @param state the state
*/
- void setState(StateContainer container, S state);
+ void setState(StateContainer<I> container, E state);
/**
* Returns the state attached to the provided container.
@@ -49,13 +51,20 @@
* @param container the container
* @return the state
*/
- S getState(StateContainer container);
+ E getState(StateContainer<I> container);
/**
* Returns the class the represents the state as seen by the framework client.
*
* @return the external state class
*/
- Class<S> getStateType();
+ Class<E> getExternalType();
+ /**
+ * Returns the class that represents the state as seen by the provider.
+ *
+ * @return the internal state class
+ */
+ Class<I> getInternalType();
+
}
Modified:
components/mop/trunk/spi/src/main/java/org/gatein/mop/spi/content/StateContainer.java
===================================================================
---
components/mop/trunk/spi/src/main/java/org/gatein/mop/spi/content/StateContainer.java 2010-02-22
09:42:13 UTC (rev 1796)
+++
components/mop/trunk/spi/src/main/java/org/gatein/mop/spi/content/StateContainer.java 2010-02-22
11:29:35 UTC (rev 1797)
@@ -22,13 +22,13 @@
* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
* @version $Revision$
*/
-public interface StateContainer
+public interface StateContainer<I>
{
- Object getState();
+ I getState();
- void setState(Object state);
+ void setState(I state);
- <T> T create(Class<T> type);
+ I create();
}