Author: chris.laprun(a)jboss.com
Date: 2010-01-17 11:52:24 -0500 (Sun, 17 Jan 2010)
New Revision: 1339
Added:
components/pc/trunk/federation/src/main/java/org/gatein/pc/federation/NullInvokerHandler.java
Modified:
components/pc/trunk/federation/src/main/java/org/gatein/pc/federation/FederatingPortletInvoker.java
components/pc/trunk/federation/src/main/java/org/gatein/pc/federation/impl/FederatingPortletInvokerService.java
components/pc/trunk/federation/src/test/java/org/gatein/pc/federation/FederatingPortletInvokerTestCase.java
Log:
- Added NullInvokerHandler concept to allow for easier resolution of federated invokers
when the default mechanism fails to resolve. This is
in particularly useful for WSRP so that we can activate and register consumers that we
know of but that haven't been made available to
a FederatingPortletInvoker. NullInvokerHandlers allows for the resolution behavior to be
extended without requiring the base resolution
mechanism to be overriden.
Modified:
components/pc/trunk/federation/src/main/java/org/gatein/pc/federation/FederatingPortletInvoker.java
===================================================================
---
components/pc/trunk/federation/src/main/java/org/gatein/pc/federation/FederatingPortletInvoker.java 2010-01-17
14:19:01 UTC (rev 1338)
+++
components/pc/trunk/federation/src/main/java/org/gatein/pc/federation/FederatingPortletInvoker.java 2010-01-17
16:52:24 UTC (rev 1339)
@@ -1,25 +1,25 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * 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. *
- ******************************************************************************/
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2010, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of
+ * individual contributors.
+ *
+ * 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.pc.federation;
import org.gatein.pc.api.Portlet;
@@ -86,4 +86,12 @@
* @return a Set containing only the portlets from remote federated invokers.
*/
Set<Portlet> getRemotePortlets() throws PortletInvokerException;
+
+ /**
+ * Specifies which NullInvokerHandler to use to attempt retrieval of a federated
invoker when default resolution
+ * mechanism cannot find an associated invoker.
+ *
+ * @param nullHandler
+ */
+ void setNullInvokerHandler(NullInvokerHandler nullHandler);
}
Added:
components/pc/trunk/federation/src/main/java/org/gatein/pc/federation/NullInvokerHandler.java
===================================================================
---
components/pc/trunk/federation/src/main/java/org/gatein/pc/federation/NullInvokerHandler.java
(rev 0)
+++
components/pc/trunk/federation/src/main/java/org/gatein/pc/federation/NullInvokerHandler.java 2010-01-17
16:52:24 UTC (rev 1339)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2010, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of
+ * individual contributors.
+ *
+ * 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.pc.federation;
+
+import org.gatein.pc.api.NoSuchPortletException;
+
+/**
+ * Encapsulates behavior to resolve FederatedPortletInvokers in the context of a
FederatingPortletInvoker when the
+ * default resolution mechanism fails to retrieve an associated FederatedPortletInvoker.
+ *
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public interface NullInvokerHandler
+{
+ NullInvokerHandler DEFAULT_HANDLER = new NullInvokerHandler()
+ {
+ public FederatedPortletInvoker resolvePortletInvokerFor(String compoundPortletId,
String invokerId) throws NoSuchPortletException
+ {
+ throw new NoSuchPortletException(compoundPortletId);
+ }
+ };
+
+ FederatedPortletInvoker resolvePortletInvokerFor(String compoundPortletId, String
invokerId) throws NoSuchPortletException;
+}
Modified:
components/pc/trunk/federation/src/main/java/org/gatein/pc/federation/impl/FederatingPortletInvokerService.java
===================================================================
---
components/pc/trunk/federation/src/main/java/org/gatein/pc/federation/impl/FederatingPortletInvokerService.java 2010-01-17
14:19:01 UTC (rev 1338)
+++
components/pc/trunk/federation/src/main/java/org/gatein/pc/federation/impl/FederatingPortletInvokerService.java 2010-01-17
16:52:24 UTC (rev 1339)
@@ -37,6 +37,7 @@
import org.gatein.pc.api.state.PropertyMap;
import org.gatein.pc.federation.FederatedPortletInvoker;
import org.gatein.pc.federation.FederatingPortletInvoker;
+import org.gatein.pc.federation.NullInvokerHandler;
import java.util.Collection;
import java.util.Collections;
@@ -64,6 +65,8 @@
/** The registred FederatedPortletInvokers. */
private volatile Map<String, FederatedPortletInvoker> registry = new
HashMap<String, FederatedPortletInvoker>();
+ private NullInvokerHandler nullHandler = NullInvokerHandler.DEFAULT_HANDLER;
+
public synchronized FederatedPortletInvoker registerInvoker(String federatedId,
PortletInvoker federatedInvoker)
{
if (federatedId == null)
@@ -162,20 +165,20 @@
public Portlet getPortlet(PortletContext compoundPortletContext) throws
IllegalArgumentException, PortletInvokerException
{
- FederatedPortletInvoker federated =
getFederatedPortletInvokerFor(compoundPortletContext);
+ PortletInvoker federated = getFederatedPortletInvokerFor(compoundPortletContext);
return federated.getPortlet(compoundPortletContext);
}
public PortletInvocationResponse invoke(PortletInvocation invocation) throws
PortletInvokerException
{
PortletContext compoundPortletContext = invocation.getTarget();
- FederatedPortletInvoker federated =
getFederatedPortletInvokerFor(compoundPortletContext);
+ PortletInvoker federated = getFederatedPortletInvokerFor(compoundPortletContext);
return federated.invoke(invocation);
}
public PortletContext createClone(PortletStateType stateType, PortletContext
compoundPortletContext) throws PortletInvokerException
{
- FederatedPortletInvoker federated =
getFederatedPortletInvokerFor(compoundPortletContext);
+ PortletInvoker federated = getFederatedPortletInvokerFor(compoundPortletContext);
return federated.createClone(stateType, compoundPortletContext);
}
@@ -191,10 +194,10 @@
}
// Get the invoker and check that we address only one invoker (for now)
- FederatedPortletInvoker invoker = null;
+ PortletInvoker invoker = null;
for (PortletContext compoundPortletContext : portletContexts)
{
- FederatedPortletInvoker federated =
getFederatedPortletInvokerFor(compoundPortletContext);
+ PortletInvoker federated =
getFederatedPortletInvokerFor(compoundPortletContext);
if (invoker == null)
{
invoker = federated;
@@ -211,22 +214,34 @@
public PropertyMap getProperties(PortletContext compoundPortletContext,
Set<String> keys) throws PortletInvokerException
{
- FederatedPortletInvoker federated =
getFederatedPortletInvokerFor(compoundPortletContext);
+ PortletInvoker federated = getFederatedPortletInvokerFor(compoundPortletContext);
return federated.getProperties(compoundPortletContext, keys);
}
public PropertyMap getProperties(PortletContext compoundPortletContext) throws
PortletInvokerException
{
- FederatedPortletInvoker federated =
getFederatedPortletInvokerFor(compoundPortletContext);
+ PortletInvoker federated = getFederatedPortletInvokerFor(compoundPortletContext);
return federated.getProperties(compoundPortletContext);
}
public PortletContext setProperties(PortletContext compoundPortletContext,
PropertyChange[] changes) throws IllegalArgumentException, PortletInvokerException,
UnsupportedOperationException
{
- FederatedPortletInvoker federated =
getFederatedPortletInvokerFor(compoundPortletContext);
+ PortletInvoker federated = getFederatedPortletInvokerFor(compoundPortletContext);
return federated.setProperties(compoundPortletContext, changes);
}
+ public synchronized void setNullInvokerHandler(NullInvokerHandler nullHandler)
+ {
+ if (nullHandler == null)
+ {
+ this.nullHandler = NullInvokerHandler.DEFAULT_HANDLER;
+ }
+ else
+ {
+ this.nullHandler = nullHandler;
+ }
+ }
+
// Support methods
**************************************************************************************************
/**
@@ -259,7 +274,7 @@
FederatedPortletInvoker federated = registry.get(invokerId);
if (federated == null)
{
- throw new NoSuchPortletException(compoundPortletId);
+ return nullHandler.resolvePortletInvokerFor(compoundPortletId, invokerId);
}
//
Modified:
components/pc/trunk/federation/src/test/java/org/gatein/pc/federation/FederatingPortletInvokerTestCase.java
===================================================================
---
components/pc/trunk/federation/src/test/java/org/gatein/pc/federation/FederatingPortletInvokerTestCase.java 2010-01-17
14:19:01 UTC (rev 1338)
+++
components/pc/trunk/federation/src/test/java/org/gatein/pc/federation/FederatingPortletInvokerTestCase.java 2010-01-17
16:52:24 UTC (rev 1339)
@@ -1,28 +1,29 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * 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. *
- ******************************************************************************/
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2010, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of
+ * individual contributors.
+ *
+ * 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.pc.federation;
import org.gatein.common.i18n.LocalizedString;
+import org.gatein.pc.api.NoSuchPortletException;
import org.gatein.pc.api.Portlet;
import org.gatein.pc.api.PortletContext;
import org.gatein.pc.api.PortletInvoker;
@@ -32,7 +33,6 @@
import org.gatein.pc.federation.impl.FederatingPortletInvokerService;
import org.gatein.pc.portlet.support.PortletInvokerSupport;
import org.gatein.pc.portlet.support.info.PortletInfoSupport;
-import static org.jboss.unit.api.Assert.*;
import org.jboss.unit.api.pojo.annotations.Create;
import org.jboss.unit.api.pojo.annotations.Destroy;
import org.jboss.unit.api.pojo.annotations.Test;
@@ -41,6 +41,8 @@
import java.util.Locale;
import java.util.Set;
+import static org.jboss.unit.api.Assert.*;
+
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
@@ -188,4 +190,41 @@
assertNotNull(portlet);
assertEquals("foo.MyPortlet", portlet.getContext().getId());
}
+
+ @Test
+ public void testDelegatedResolution() throws PortletInvokerException
+ {
+ // create an invoker to check NullInvokerHandler behavior
+ final TestFederatedPortletInvoker remote = new TestFederatedPortletInvoker();
+ PortletInfoSupport remoteInfo = new PortletInfoSupport();
+ remoteInfo.getMeta().setDisplayName("RemotePortlet");
+ Portlet portlet = remote.addPortlet("RemotePortlet", remoteInfo);
+
+ // this invoker is not registered
+ assertNull(federatingInvoker.getFederatedInvoker("inexistent"));
+
+ federatingInvoker.setNullInvokerHandler(new NullInvokerHandler()
+ {
+ public FederatedPortletInvoker resolvePortletInvokerFor(String
compoundPortletId, String invokerId) throws NoSuchPortletException
+ {
+ return remote;
+ }
+ });
+
+ assertEquals(portlet,
federatingInvoker.getPortlet(PortletContext.createPortletContext("inexistent.RemotePortlet")));
+ }
+
+ private class TestFederatedPortletInvoker extends PortletInvokerSupport implements
FederatedPortletInvoker
+ {
+
+ public String getId()
+ {
+ return "inexistent";
+ }
+
+ public PortletInvoker getPortletInvoker()
+ {
+ return null;
+ }
+ }
}