Author: julien(a)jboss.com
Date: 2008-07-23 15:49:11 -0400 (Wed, 23 Jul 2008)
New Revision: 11562
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/coordination/CoordinationConfigurator.java
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/coordination/CoordinationManager.java
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/portlet/ControllerPageNavigationalState.java
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/portlet/ControllerPortletControllerContext.java
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/impl/coordination/CoordinationService.java
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/test/core/model/portal/coordination/CoordinationServiceTestCase.java
Log:
implement alias binding runtime update
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/coordination/CoordinationConfigurator.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/coordination/CoordinationConfigurator.java 2008-07-23
19:28:07 UTC (rev 11561)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/coordination/CoordinationConfigurator.java 2008-07-23
19:49:11 UTC (rev 11562)
@@ -142,7 +142,7 @@
void setAliasBinding(Page page, String aliasName, Set<QName> qnames) throws
IllegalCoordinationException;
/**
- * Removes alias binding
+ * Removes an alias binding.
*
* @param aliasInfo
* @throws IllegalCoordinationException
@@ -153,24 +153,24 @@
* @param page
* @return collection of alias bindings connected to the given page
*/
- Collection<AliasBindingInfo> getAliasBindings(Page page);
+ Collection<? extends AliasBindingInfo> getAliasBindings(Page page);
/**
* @param page
* @param parameterQName
* @return window bindings for a given parameter qname
*/
- Collection<WindowBindingInfo> getWindowBindings(Page page, QName
parameterQName);
+ Collection<? extends WindowBindingInfo> getWindowBindings(Page page, QName
parameterQName);
/**
* @param page
* @return window bindings define in the scope of a given page
*/
- Collection<WindowBindingInfo> getWindowBindings(Page page);
+ Collection<? extends WindowBindingInfo> getWindowBindings(Page page);
/**
* @param window
* @return window bindings where given window is involved
*/
- Collection<WindowBindingInfo> getWindowBindings(Window window);
+ Collection<? extends WindowBindingInfo> getWindowBindings(Window window);
}
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/coordination/CoordinationManager.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/coordination/CoordinationManager.java 2008-07-23
19:28:07 UTC (rev 11561)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/coordination/CoordinationManager.java 2008-07-23
19:49:11 UTC (rev 11562)
@@ -50,30 +50,31 @@
Map<Window, PortletWindowEvent> getEventWindows(PortletWindowEvent event,
ControllerPortletControllerContext context) throws IllegalCoordinationException;
- /**
- * Resolves implicit strategy. If there is no strategy defined for this page container
method will browse
+ /**
+ * Resolves implicit wiring strategy. If there is no strategy defined for this page
container method will browse
* parent object to resolve inherited recursive strategies. If no strategy is set this
method will return default one
*
* @param page
* @return
- * @throws IllegalCoordinationException
*/
- CoordinationStrategy resolveBindingStrategy(PageContainer page);
+ CoordinationStrategy resolveEventWiringStrategy(PageContainer page);
- /**
- * Resolves implicit wiring strategy. If there is no strategy defined for this page
container method will browse
+ /**
+ * Resolves implicit strategy. If there is no strategy defined for this page container
method will browse
* parent object to resolve inherited recursive strategies. If no strategy is set this
method will return default one
*
- * @param page
- * @return
- * @throws IllegalCoordinationException
+ * @param pageContainer the page container
+ * @return the coordination strategy
*/
- CoordinationStrategy resolveEventWiringStrategy(PageContainer page);
+ CoordinationStrategy resolveBindingStrategy(PageContainer pageContainer);
/**
- * @param window
- * @param name
- * @return all parameter binding names with a given window/qname mapping
+ * Returns the list of bindings for a given window and a given name. The collection is
an aggregation
+ * of window bindings and alias bindings.
+ *
+ * @param window the target window
+ * @param name the target name
+ * @return all parameter binding names with a given window/name mapping
*/
Collection<String> getBindingNames(Window window, QName name);
}
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/portlet/ControllerPageNavigationalState.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/portlet/ControllerPageNavigationalState.java 2008-07-23
19:28:07 UTC (rev 11561)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/portlet/ControllerPageNavigationalState.java 2008-07-23
19:49:11 UTC (rev 11562)
@@ -32,6 +32,7 @@
import org.jboss.portal.core.navstate.NavigationalStateContext;
import org.jboss.portal.core.model.portal.Window;
import org.jboss.portal.core.model.portal.Page;
+import org.jboss.portal.core.model.portal.Page;
import org.jboss.portal.core.model.portal.PortalObject;
import org.jboss.portal.core.model.portal.navstate.PageNavigationalState;
import org.jboss.portal.core.controller.coordination.CoordinationManager;
@@ -44,7 +45,6 @@
import java.util.Map;
import java.util.Set;
import java.util.Collection;
-import java.util.HashSet;
/**
* @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
@@ -76,6 +76,9 @@
/** . */
private Map<String, HashMap<QName, String[]>>
windowPublicNavigationalStateUpdate;
+ /** . */
+ private final CoordinationStrategy coordinationStrategy;
+
public ControllerPageNavigationalState(
NavigationalStateContext navigationalStateContext,
ControllerPortletControllerContext controllerContext,
@@ -87,6 +90,8 @@
this.updates = null;
this.pageUpdates = null;
this.windowPublicNavigationalStateUpdate = null;
+ this.coordinationStrategy =
getCoordinationManager().resolveBindingStrategy(controllerContext.getPage());
+
}
public ControllerPageNavigationalState(
@@ -99,6 +104,7 @@
this.updates = that.updates != null ? new HashMap<String,
org.jboss.portal.core.model.portal.navstate.WindowNavigationalState>(that.updates) :
null;
this.pageUpdates = that.pageUpdates != null ? new HashMap<QName,
String[]>(that.pageUpdates) : null;
this.windowPublicNavigationalStateUpdate = that.windowPublicNavigationalStateUpdate
!= null ? new HashMap<String, HashMap<QName,
String[]>>(that.windowPublicNavigationalStateUpdate) : null;
+ this.coordinationStrategy =
getCoordinationManager().resolveBindingStrategy(controllerContext.getPage());
}
/**
@@ -399,8 +405,8 @@
String parameterId = parameterInfo.getId();
//
- if (strategy.equals(CoordinationStrategy.EXPLICIT) ||
- (strategy.equals(CoordinationStrategy.FALLBACK) &&
explicitParameterValue != null))
+ if (coordinationStrategy == CoordinationStrategy.EXPLICIT ||
+ (coordinationStrategy == CoordinationStrategy.FALLBACK &&
explicitParameterValue != null))
{
// We clone the value here so we keep the internal state not
potentially changed
if (explicitParameterValue != null)
@@ -468,6 +474,7 @@
//
if (info != null)
{
+ Window window = getWindow(windowName);
NavigationInfo navigationInfo = info.getNavigation();
for (Map.Entry<String, String[]> entry : update.entrySet())
{
@@ -482,8 +489,10 @@
QName name = parameterInfo.getName();
String[] value = entry.getValue();
+ //
CoordinationStrategy strategy =
manager.resolveBindingStrategy(getWindow(windowName).getPage());
+ //
Collection<String> bindings =
manager.getBindingNames(getWindow(windowName), name);
@@ -500,20 +509,22 @@
{
setWindowPublicNavigationalState(windowName, name, REMOVAL);
}
-
}
else
{
- if (value.length > 0)
+ if (coordinationStrategy != CoordinationStrategy.EXPLICIT)
{
- setPublicNavigationalState(name, value);
+ if (value.length > 0)
+ {
+ setPublicNavigationalState(name, value);
+ }
+ else
+ {
+ removePublicNavigationalState(name);
+ }
}
- else
- {
- removePublicNavigationalState(name);
- }
- // Explicit bindings
+ //
for (String binding : bindings)
{
setPublicNavigationalState(new QName(XMLConstants.DEFAULT_NS_PREFIX,
binding), value);
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/portlet/ControllerPortletControllerContext.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/portlet/ControllerPortletControllerContext.java 2008-07-23
19:28:07 UTC (rev 11561)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/portlet/ControllerPortletControllerContext.java 2008-07-23
19:49:11 UTC (rev 11562)
@@ -87,6 +87,9 @@
/** . */
private final String pageId;
+ /** . */
+ private final Page page;
+
public ControllerPortletControllerContext(ControllerContext controllerContext, Page
page)
{
InstanceContainer instanceContainer =
controllerContext.getController().getInstanceContainer();
@@ -162,8 +165,14 @@
this.infos = infos;
this.instances = instances;
this.pageId = page.getId().toString();
+ this.page = page;
}
+ public Page getPage()
+ {
+ return page;
+ }
+
public String getPageId()
{
return pageId;
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/impl/coordination/CoordinationService.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/impl/coordination/CoordinationService.java 2008-07-23
19:28:07 UTC (rev 11561)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/impl/coordination/CoordinationService.java 2008-07-23
19:49:11 UTC (rev 11562)
@@ -170,12 +170,10 @@
public Collection<String> getBindingNames(Window window, QName name)
{
-
Set<String> names = new HashSet<String>();
- Collection<WindowBindingInfo> infos = getWindowBindings(window);
-
- for (WindowBindingInfo info : infos)
+ //
+ for (WindowBindingInfo info : getWindowBindings(window))
{
for (Map.Entry<Window, QName> entry : info.getWindows().entrySet())
{
@@ -186,6 +184,16 @@
}
}
+ //
+ for (AliasBindingInfo info : getAliasBindings(window.getPage()))
+ {
+ if (info.getQNames().contains(name))
+ {
+ names.add(info.getName());
+ }
+ }
+
+ //
return names;
}
@@ -419,13 +427,8 @@
// Examine window properties and create page events
- Collection<Window> windows = getWindows(page);
-
Map<String, EventInfoPOJO> events = new HashMap<String,
EventInfoPOJO>();
-
-
-
- for (Window window : windows)
+ for (PortalObject window : page.getChildren(PortalObject.WINDOW_MASK))
{
Set<String> propNames = window.getProperties().keySet();
@@ -461,11 +464,11 @@
if (qname != null && role != null &&
role.equalsIgnoreCase("source"))
{
- info.getSources().put(window, qname);
+ info.getSources().put((Window)window, qname);
}
else if (qname != null && role != null &&
role.equalsIgnoreCase("destination"))
{
- info.getDestinations().put(window, qname);
+ info.getDestinations().put((Window)window, qname);
}
}
@@ -520,54 +523,45 @@
return events;
}
+ // Binding stuff
*****************************************************************************************
+
public void setWindowBinding(String name, Map<Window, QName> windows) throws
IllegalCoordinationException
{
if (windows == null)
{
throw new IllegalArgumentException("windows are null");
}
-
if (name == null)
{
throw new IllegalArgumentException("name is null");
}
-
if (windows.isEmpty())
{
throw new IllegalArgumentException("empty windows map");
}
-
// Obtain parent page and check that all windows are in one branch...
-
Page parentPage = null;
-
- Set<Window> dw = windows.keySet();
-
-
- for (Window window : dw)
+ for (Window window : windows.keySet())
{
if (parentPage == null)
{
parentPage = window.getPage();
}
-
if (!window.getPage().getId().equals(parentPage.getId()))
{
throw new IllegalCoordinationException("Parent page is not the same for
all windows");
}
}
-
// Set window properties
-
String prop_wiring = PREFIX_PARAMETER_BINDING + "." + name;
- for (Window window : dw)
+ //
+ for (Window window : windows.keySet())
{
window.setDeclaredProperty(prop_wiring, windows.get(window).toString());
}
-
}
public void removeWindowBinding(WindowBindingInfo info) throws
IllegalCoordinationException
@@ -578,9 +572,9 @@
}
// Remove all entries
-
String prop_wiring = PREFIX_PARAMETER_BINDING + "." + info.getName();
+ //
for (Window window : info.getWindows().keySet())
{
window.setDeclaredProperty(prop_wiring, null);
@@ -594,7 +588,7 @@
throw new IllegalArgumentException("pageContainer is null");
}
-
+ //
setStrategy(pageContainer, strategy, PREFIX_PARAMETER_IMPLICIT_STRATEGY);
}
@@ -606,18 +600,20 @@
throw new IllegalArgumentException("page is null");
}
+ //
return decodeStrategy(pageContainer, PREFIX_PARAMETER_IMPLICIT_STRATEGY);
}
- public CoordinationStrategy resolveBindingStrategy(PageContainer page)
+ public CoordinationStrategy resolveBindingStrategy(PageContainer pageContainer)
{
- if (page == null)
+ if (pageContainer == null)
{
throw new IllegalArgumentException("page is null");
}
- return resolveStrategy(page, PREFIX_PARAMETER_IMPLICIT_STRATEGY);
+ //
+ return resolveStrategy(pageContainer, PREFIX_PARAMETER_IMPLICIT_STRATEGY);
}
@@ -636,37 +632,34 @@
throw new IllegalArgumentException("qnames set is null");
}
+ //
String propName = PREFIX_PARAMETER_ALIAS_NAME + "." + aliasName;
-
// Check if qname consist separator string
-
for (QName qname : qnames)
{
-
-
if (qname.toString().contains(QNAME_SEPARATOR))
{
throw new IllegalCoordinationException("Qname: " + qname + "
contains forbidden character: " + QNAME_SEPARATOR);
}
}
+ //
StringBuilder qnameList = new StringBuilder();
+ //
for (Iterator i = qnames.iterator(); i.hasNext(); )
{
QName qname = (QName)i.next();
-
qnameList.append(qname.toString());
-
if (i.hasNext())
{
qnameList.append(QNAME_SEPARATOR);
}
}
+ //
page.setDeclaredProperty(propName, qnameList.toString());
-
}
public void removeAliasBinding(AliasBindingInfo aliasInfo) throws
IllegalCoordinationException
@@ -676,8 +669,8 @@
throw new IllegalArgumentException("alias info is null");
}
+ //
String propName = PREFIX_PARAMETER_ALIAS_NAME + "." +
aliasInfo.getName();
-
if (aliasInfo.getPage().getProperties().keySet().contains(propName))
{
aliasInfo.getPage().setDeclaredProperty(propName,null);
@@ -691,20 +684,18 @@
throw new IllegalArgumentException("page is null");
}
+ //
HashSet<AliasBindingInfo> aliases = new HashSet<AliasBindingInfo>();
+ //
for (String propertyName : page.getProperties().keySet())
{
if (propertyName.startsWith(PREFIX_PARAMETER_ALIAS_NAME))
{
String aliasName =
propertyName.substring(PREFIX_PARAMETER_ALIAS_NAME.length() + 1);
-
AliasInfoPOJO info = new AliasInfoPOJO(aliasName, page);
-
String qnameList = page.getProperty(propertyName);
-
String[] qnames = qnameList.split(QNAME_SEPARATOR);
-
if (qnames != null)
{
for (String string : qnames)
@@ -713,60 +704,75 @@
info.getQNames().add(qname);
}
}
-
aliases.add(info.getImmutableInfo());
}
}
+ //
return aliases;
}
- public Collection<WindowBindingInfo> getWindowBindings(Page page, QName
parameterQName)
+ public Collection<? extends WindowBindingInfo> getWindowBindings(Page page,
QName parameterName)
{
-
if (page == null)
{
- throw new IllegalArgumentException("page is null");
+ throw new IllegalArgumentException("Page is null");
}
- if (parameterQName == null)
+ //
+ if (parameterName == null)
{
- throw new IllegalArgumentException("QName is null");
+ throw new IllegalArgumentException("Name is null");
}
- Collection<WindowBindingInfo> pageParams = getWindowBindings(page);
+ //
+ Collection<? extends WindowBindingInfo> pageParams =
getWindowBindings(page);
+ //
Collection<WindowBindingInfo> infos = new
HashSet<WindowBindingInfo>();
+ //
for (WindowBindingInfo pageParam : pageParams)
{
- if (pageParam.getWindows().containsValue(parameterQName))
+ if (pageParam.getWindows().containsValue(parameterName))
{
infos.add(pageParam);
}
}
+ //
return infos;
}
- public Collection<WindowBindingInfo> getWindowBindings(Page page)
+ public Collection<WindowBindingInfo> getWindowBindings(Window window)
{
+ Collection<? extends WindowBindingInfo> pageParams =
getWindowBindings(window.getPage());
+ Collection<WindowBindingInfo> infos = new
HashSet<WindowBindingInfo>();
+ for (WindowBindingInfo pageParam : pageParams)
+ {
+ if (pageParam.getWindows().keySet().contains(window))
+ {
+ infos.add(pageParam);
+ }
+ }
+ return infos;
+ }
+
+ public Collection<? extends WindowBindingInfo> getWindowBindings(Page page)
+ {
if (page == null)
{
throw new IllegalArgumentException("page is null");
}
// Examine window properties and create page parameters
+ Collection<PortalObject> children =
page.getChildren(PortalObject.WINDOW_MASK);
- Collection<Window> windows = getWindows(page);
-
+ //
Map<String, WindowInfoPOJO> params = new HashMap<String,
WindowInfoPOJO>();
-
-
-
- for (Window window : windows)
+ for (PortalObject child : children)
{
- Set<String> propNames = window.getProperties().keySet();
+ Set<String> propNames = child.getProperties().keySet();
for (String propName : propNames)
{
@@ -785,56 +791,28 @@
info = params.get(pn);
}
- String binding = window.getProperty(propName);
+ //
+ String binding = child.getProperty(propName);
-
- //TODO: if the imformation from properties is not consistent should we
throw exception?
-
+ //TODO: if the information from properties is not consistent should we
throw exception?
if (binding != null)
{
QName qname = decodeQName(binding);
-
+ //
if (qname != null)
{
- info.getWindows().put(window, qname);
+ info.windows.put((Window)child, qname);
}
-
}
-
-
}
}
}
- // Make immutable copy
- Collection<WindowBindingInfo> immutableParams = new
HashSet<WindowBindingInfo>();
-
- for (WindowInfoPOJO info : params.values())
- {
- immutableParams.add(info.getImmutableInfo());
- }
-
- return immutableParams;
+ //
+ return Collections.unmodifiableCollection(params.values());
}
- public Collection<WindowBindingInfo> getWindowBindings(Window window)
- {
- Collection<WindowBindingInfo> pageParams =
getWindowBindings(window.getPage());
-
- Collection<WindowBindingInfo> infos = new
HashSet<WindowBindingInfo>();
-
- for (WindowBindingInfo pageParam : pageParams)
- {
- if (pageParam.getWindows().keySet().contains(window))
- {
- infos.add(pageParam);
- }
- }
-
- return infos;
- }
-
// SETTERS & GETTERS
public PortalObjectContainer getPortalObjectContainer()
@@ -968,23 +946,6 @@
return null;
}
-
-
-
- Collection<Window> getWindows(Page page)
- {
- Set<Window> windows = new HashSet<Window>();
- for (PortalObject portalObject : page.getChildren())
- {
-
- if (portalObject instanceof Window)
- {
- windows.add((Window)portalObject);
- }
- }
- return windows;
- }
-
private QName decodeQName(String fullString)
{
if (fullString.startsWith("{"))
@@ -1051,19 +1012,20 @@
private class WindowInfoPOJO implements WindowBindingInfo
{
+ /** . */
private final String name;
+
+ /** . */
private final Map<Window, QName> windows;
- private WindowInfoPOJO(String name, Map<Window, QName> windows)
- {
- this.name = name;
- this.windows = windows;
- }
+ /** . */
+ private final Map<Window, QName> immutableWindows;
private WindowInfoPOJO(String name)
{
this.name = name;
this.windows = new HashMap<Window,QName>();
+ this.immutableWindows = Collections.unmodifiableMap(windows);
}
public String getName()
@@ -1073,14 +1035,8 @@
public Map<Window, QName> getWindows()
{
- return windows;
+ return immutableWindows;
}
-
- WindowBindingInfo getImmutableInfo()
- {
- return new WindowInfoPOJO(name, Collections.unmodifiableMap(windows));
- }
-
}
private class AliasInfoPOJO implements AliasBindingInfo
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/test/core/model/portal/coordination/CoordinationServiceTestCase.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/test/core/model/portal/coordination/CoordinationServiceTestCase.java 2008-07-23
19:28:07 UTC (rev 11561)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/test/core/model/portal/coordination/CoordinationServiceTestCase.java 2008-07-23
19:49:11 UTC (rev 11562)
@@ -261,7 +261,7 @@
cos.setWindowBinding("binding1", ws);
- Collection<WindowBindingInfo> bindings = cos.getWindowBindings(page1);
+ Collection<? extends WindowBindingInfo> bindings =
cos.getWindowBindings(page1);
assertEquals(1, bindings.size());