Author: chris.laprun(a)jboss.com
Date: 2011-08-08 18:50:34 -0400 (Mon, 08 Aug 2011)
New Revision: 7012
Modified:
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/id/ComplexApplicationContext.java
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/id/ComplexApplicationId.java
portal/branches/api/component/api-impl/src/test/java/org/gatein/portal/api/impl/id/ComplexApplicationContextTestCase.java
Log:
- Made ComplexApplication* able to handle more id formats.
Modified:
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/id/ComplexApplicationContext.java
===================================================================
---
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/id/ComplexApplicationContext.java 2011-08-08
21:30:11 UTC (rev 7011)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/id/ComplexApplicationContext.java 2011-08-08
22:50:34 UTC (rev 7012)
@@ -50,9 +50,9 @@
throw new IllegalArgumentException("ComplexApplicationContext can only
create Id<Portlet>. Was asked to create Id<" + type.getSimpleName() +
">");
}
- if (additionalComponents != null && additionalComponents.length == 2)
+ if (additionalComponents != null && additionalComponents.length == 3)
{
- return (Id<T>)new ComplexApplicationId(rootComponent,
additionalComponents[0], additionalComponents[1], this);
+ return (Id<T>)new ComplexApplicationId(rootComponent,
additionalComponents[0], additionalComponents[1], additionalComponents[2], this);
}
else
{
@@ -70,17 +70,19 @@
final int index = idAsString.indexOf(ComplexApplicationId.START);
if (index < 0)
{
- throw new IllegalArgumentException("'" + idAsString + "'
cannot be understood by ComplexApplicationContext. Understood format is
'local._applicationName.portletName'");
+ throw new IllegalArgumentException("'" + idAsString + "'
cannot be understood by ComplexApplicationContext. Understood format is
'category/local.(_|/)applicationName.portletName'");
}
final int slash = idAsString.indexOf('/');
String category = idAsString.substring(0, slash);
- final int separator = idAsString.indexOf('.', index +
ComplexApplicationId.START.length());
- String app = idAsString.substring(index + ComplexApplicationId.START.length(),
separator);
- String portlet = idAsString.substring(separator + 1);
+ final int length = ComplexApplicationId.START.length();
+ final int sepIndex = idAsString.indexOf('.', index + length);
+ String separator = idAsString.substring(index + length, index + length + 1);
+ String app = idAsString.substring(index + length + 1, sepIndex);
+ String portlet = idAsString.substring(sepIndex + 1);
- return create(expectedType, category, app, portlet);
+ return create(expectedType, category, app, portlet, separator);
}
public String toString(Id id)
Modified:
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/id/ComplexApplicationId.java
===================================================================
---
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/id/ComplexApplicationId.java 2011-08-08
21:30:11 UTC (rev 7011)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/id/ComplexApplicationId.java 2011-08-08
22:50:34 UTC (rev 7012)
@@ -32,18 +32,20 @@
public class ComplexApplicationId implements Id<Portlet>
{
public static final String LOCAL = "local";
- public static final String START = LOCAL + "._";
+ public static final String START = LOCAL + ".";
private final String category;
private final String app;
private final String portlet;
private final Context context;
+ private final String separator;
- public ComplexApplicationId(String category, String appName, String portletName,
ComplexApplicationContext context)
+ public ComplexApplicationId(String category, String appName, String portletName,
String separator, ComplexApplicationContext context)
{
this.category = category;
this.app = appName;
this.portlet = portletName;
this.context = context;
+ this.separator = separator;
}
@Override
@@ -56,7 +58,7 @@
{
if (this.context.equals(context))
{
- return category + '/' + START + app + '.' + portlet;
+ return category + '/' + START + separator + app + '.' +
portlet;
}
else
{
Modified:
portal/branches/api/component/api-impl/src/test/java/org/gatein/portal/api/impl/id/ComplexApplicationContextTestCase.java
===================================================================
---
portal/branches/api/component/api-impl/src/test/java/org/gatein/portal/api/impl/id/ComplexApplicationContextTestCase.java 2011-08-08
21:30:11 UTC (rev 7011)
+++
portal/branches/api/component/api-impl/src/test/java/org/gatein/portal/api/impl/id/ComplexApplicationContextTestCase.java 2011-08-08
22:50:34 UTC (rev 7012)
@@ -33,11 +33,19 @@
@Test
public void checkParsing()
{
- final Id<Portlet> id =
ComplexApplicationContext.INSTANCE.parse("category/local._webapp.portlet",
Portlet.class);
+ Id<Portlet> id =
ComplexApplicationContext.INSTANCE.parse("category/local._webapp.portlet",
Portlet.class);
assert
"category".equals(id.getComponent(GateInImpl.CATEGORY_COMPONENT));
assert
"webapp".equals(id.getComponent(GateInImpl.APPLICATION_COMPONENT));
assert "portlet".equals(id.getComponent(GateInImpl.PORTLET_COMPONENT));
assert id.equals(ComplexApplicationContext.INSTANCE.parse(id.toString()));
+
+
+ id =
ComplexApplicationContext.INSTANCE.parse("category/local./webapp.portlet",
Portlet.class);
+ assert
"category".equals(id.getComponent(GateInImpl.CATEGORY_COMPONENT));
+ assert
"webapp".equals(id.getComponent(GateInImpl.APPLICATION_COMPONENT));
+ assert "portlet".equals(id.getComponent(GateInImpl.PORTLET_COMPONENT));
+
+ assert id.equals(ComplexApplicationContext.INSTANCE.parse(id.toString()));
}
}
Show replies by date