Author: julien(a)jboss.com
Date: 2007-05-29 06:05:40 -0400 (Tue, 29 May 2007)
New Revision: 7348
Added:
trunk/common/src/main/org/jboss/portal/common/path/PathMapper.java
trunk/common/src/main/org/jboss/portal/common/path/PathMapperContext.java
trunk/common/src/main/org/jboss/portal/common/path/PathMapperResult.java
trunk/common/src/main/org/jboss/portal/common/path/SimplePathMapper.java
trunk/common/src/main/org/jboss/portal/test/common/PathMapperTestCase.java
Removed:
trunk/core/src/main/org/jboss/portal/core/impl/invocation/Mapper.java
trunk/core/src/main/org/jboss/portal/core/impl/invocation/MappingContext.java
trunk/core/src/main/org/jboss/portal/core/impl/invocation/MappingResult.java
trunk/core/src/main/org/jboss/portal/core/impl/invocation/SimpleMapper.java
trunk/core/src/main/org/jboss/portal/test/core/MapperTestCase.java
Modified:
trunk/common/build.xml
Log:
moved path parser stuff from core to common package
Modified: trunk/common/build.xml
===================================================================
--- trunk/common/build.xml 2007-05-29 08:53:17 UTC (rev 7347)
+++ trunk/common/build.xml 2007-05-29 10:05:40 UTC (rev 7348)
@@ -244,6 +244,7 @@
<test todir="${test.reports}"
name="org.jboss.portal.test.common.ToolsTestCase"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.common.ModifierTestCase"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.common.IteratorStatusTestCase"/>
+ <test todir="${test.reports}"
name="org.jboss.portal.test.common.PathMapperTestCase"/>
</x-test>
<x-classpath>
<pathelement location="${build.classes}"/>
Added: trunk/common/src/main/org/jboss/portal/common/path/PathMapper.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/path/PathMapper.java
(rev 0)
+++ trunk/common/src/main/org/jboss/portal/common/path/PathMapper.java 2007-05-29 10:05:40
UTC (rev 7348)
@@ -0,0 +1,43 @@
+/******************************************************************************
+ * 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. *
+ ******************************************************************************/
+package org.jboss.portal.common.path;
+
+/**
+ * Map request uri path to portal object.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 5448 $
+ */
+public interface PathMapper
+{
+
+ /**
+ * Map a path to a result.
+ *
+ * @param pathMapperContext the context of the mapping
+ * @param path the path to map
+ * @return returns a path mapper result
+ */
+ public PathMapperResult map(PathMapperContext pathMapperContext, String path);
+
+}
Property changes on: trunk/common/src/main/org/jboss/portal/common/path/PathMapper.java
___________________________________________________________________
Name: svn:executable
+ *
Added: trunk/common/src/main/org/jboss/portal/common/path/PathMapperContext.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/path/PathMapperContext.java
(rev 0)
+++ trunk/common/src/main/org/jboss/portal/common/path/PathMapperContext.java 2007-05-29
10:05:40 UTC (rev 7348)
@@ -0,0 +1,46 @@
+/******************************************************************************
+ * 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. *
+ ******************************************************************************/
+package org.jboss.portal.common.path;
+
+/**
+ * Interface that provide access to objects that are mapped to pathes.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 5448 $
+ */
+public interface PathMapperContext
+{
+ /**
+ * Returns the object graph root.
+ *
+ * @return the root object
+ */
+ Object getRoot();
+
+ /**
+ * Return the child object having the specified name or null if it does not exists.
+ *
+ * @return the child of the parent object matching the specifed name
+ */
+ Object getChild(Object parent, String name);
+}
Property changes on:
trunk/common/src/main/org/jboss/portal/common/path/PathMapperContext.java
___________________________________________________________________
Name: svn:executable
+ *
Added: trunk/common/src/main/org/jboss/portal/common/path/PathMapperResult.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/path/PathMapperResult.java
(rev 0)
+++ trunk/common/src/main/org/jboss/portal/common/path/PathMapperResult.java 2007-05-29
10:05:40 UTC (rev 7348)
@@ -0,0 +1,95 @@
+/******************************************************************************
+ * 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. *
+ ******************************************************************************/
+package org.jboss.portal.common.path;
+
+/**
+ * The result of a request to a mapper.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 5448 $
+ */
+public class PathMapperResult
+{
+
+ /** . */
+ private final Object target;
+
+ /** . */
+ private final String targetPath;
+
+ /** . */
+ private final String targetPathInfo;
+
+ public PathMapperResult(Object target, String targetPath, String targetPathInfo)
+ {
+ this.target = target;
+ this.targetPath = targetPath;
+ this.targetPathInfo = targetPathInfo;
+ }
+
+ public Object getTarget()
+ {
+ return target;
+ }
+
+ public String getTargetPathInfo()
+ {
+ return targetPathInfo;
+ }
+
+ public int hashCode()
+ {
+ int hashCode = (target != null ? target.hashCode() : 0) +
+ (targetPath != null ? targetPath.hashCode() : 0) +
+ (targetPathInfo != null ? targetPathInfo.hashCode() : 0);
+ return hashCode;
+ }
+
+ public boolean equals(Object obj)
+ {
+ if (obj == this)
+ {
+ return true;
+ }
+ if (obj instanceof PathMapperResult)
+ {
+ PathMapperResult other = (PathMapperResult)obj;
+ return (target == null ? (other.target == null) : target.equals(other.target))
&&
+ (targetPath == null ? (other.targetPath == null) :
targetPath.equals(other.targetPath)) &&
+ (targetPathInfo == null ? (other.targetPathInfo == null) :
targetPathInfo.equals(other.targetPathInfo));
+ }
+ return false;
+ }
+
+ public String toString()
+ {
+ StringBuffer buffer = new StringBuffer("MappingResult[");
+ buffer.append(target == null ? "-" : target.toString());
+ buffer.append(',');
+ buffer.append(targetPath == null ? "-" : targetPath);
+ buffer.append(',');
+ buffer.append(targetPathInfo == null ? "-" : targetPathInfo);
+ buffer.append("]");
+ return buffer.toString();
+ }
+}
Property changes on:
trunk/common/src/main/org/jboss/portal/common/path/PathMapperResult.java
___________________________________________________________________
Name: svn:executable
+ *
Added: trunk/common/src/main/org/jboss/portal/common/path/SimplePathMapper.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/path/SimplePathMapper.java
(rev 0)
+++ trunk/common/src/main/org/jboss/portal/common/path/SimplePathMapper.java 2007-05-29
10:05:40 UTC (rev 7348)
@@ -0,0 +1,119 @@
+/******************************************************************************
+ * 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. *
+ ******************************************************************************/
+package org.jboss.portal.common.path;
+
+/**
+ * A simple mapper implementation. The limitations is that only the root and its children
can have children
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 5448 $
+ */
+public class SimplePathMapper implements PathMapper
+{
+ public PathMapperResult map(PathMapperContext ctx, String path)
+ {
+ Object root = ctx.getRoot();
+ Object target = null;
+ String targetPath = null;
+ String targetPathInfo = null;
+
+ if (path == null || path.length() == 0)
+ {
+ targetPath = null;
+ targetPathInfo = null;
+ }
+ else if ("/".equals(path))
+ {
+ targetPath = null;
+ targetPathInfo = "/";
+ }
+ else
+ {
+ int firstSlashPos = path.indexOf('/', 1);
+ if (firstSlashPos == -1)
+ {
+ String firstChunk = path.substring(1);
+ target = ctx.getChild(root, firstChunk);
+ if (target != null)
+ {
+ targetPath = path;
+ targetPathInfo = null;
+ }
+ else
+ {
+ targetPath = null;
+ targetPathInfo = path;
+ }
+ }
+ else if (firstSlashPos == 1)
+ {
+ targetPath = null;
+ targetPathInfo = "/";
+ }
+ else
+ {
+ String firstChunk = path.substring(1, firstSlashPos);
+ target = ctx.getChild(root, firstChunk);
+ if (target != null)
+ {
+ int secondSlashPos = path.indexOf('/', firstSlashPos + 1);
+ if (secondSlashPos == -1)
+ {
+ String secondChunck = path.substring(firstSlashPos + 1);
+ if (secondChunck.length() == 0)
+ {
+ targetPath = "/" + firstChunk;
+ targetPathInfo = "/";
+ }
+ else
+ {
+ Object child = ctx.getChild(target, secondChunck);
+ if (child != null)
+ {
+ target = child;
+ targetPath = path;
+ targetPathInfo = null;
+ }
+ else
+ {
+ targetPath = "/" + firstChunk;
+ targetPathInfo = "/" + secondChunck;
+ }
+ }
+ }
+ else
+ {
+ targetPath = "/" + firstChunk;
+ targetPathInfo = path.substring(firstSlashPos);
+ }
+ }
+ else
+ {
+ targetPath = null;
+ targetPathInfo = path;
+ }
+ }
+ }
+ return new PathMapperResult(target, targetPath, targetPathInfo);
+ }
+}
Property changes on:
trunk/common/src/main/org/jboss/portal/common/path/SimplePathMapper.java
___________________________________________________________________
Name: svn:executable
+ *
Added: trunk/common/src/main/org/jboss/portal/test/common/PathMapperTestCase.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/test/common/PathMapperTestCase.java
(rev 0)
+++ trunk/common/src/main/org/jboss/portal/test/common/PathMapperTestCase.java 2007-05-29
10:05:40 UTC (rev 7348)
@@ -0,0 +1,156 @@
+/******************************************************************************
+ * 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. *
+ ******************************************************************************/
+package org.jboss.portal.test.common;
+
+import junit.framework.TestCase;
+import org.jboss.portal.common.path.PathMapper;
+import org.jboss.portal.common.path.PathMapperContext;
+import org.jboss.portal.common.path.PathMapperResult;
+import org.jboss.portal.common.path.SimplePathMapper;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 5448 $
+ */
+public class PathMapperTestCase extends TestCase
+{
+
+ public PathMapperTestCase(String s)
+ {
+ super(s);
+ }
+
+ private PathMapper mapper;
+
+ protected void setUp() throws Exception
+ {
+ mapper = new SimplePathMapper();
+ }
+
+ protected void tearDown() throws Exception
+ {
+ mapper = null;
+ }
+
+ public void testEmptyContext()
+ {
+ PathMapperContextImpl root = new PathMapperContextImpl(null);
+
+ assertEquals(new PathMapperResult(null, null, null), mapper.map(root, null));
+ assertEquals(new PathMapperResult(null, null, null), mapper.map(root,
""));
+ assertEquals(new PathMapperResult(null, null, "/"), mapper.map(root,
"/"));
+ assertEquals(new PathMapperResult(null, null, "/"), mapper.map(root,
"//"));
+
+ assertEquals(new PathMapperResult(null, null, "/a"), mapper.map(root,
"/a"));
+ assertEquals(new PathMapperResult(null, null, "/a/"), mapper.map(root,
"/a/"));
+ assertEquals(new PathMapperResult(null, null, "/a/b"), mapper.map(root,
"/a/b"));
+ assertEquals(new PathMapperResult(null, null, "/a/b/"), mapper.map(root,
"/a/b/"));
+ assertEquals(new PathMapperResult(null, null, "/a/b/c"), mapper.map(root,
"/a/b/c"));
+ }
+
+ public void testOneChild()
+ {
+ PathMapperContextImpl root = new PathMapperContextImpl(null);
+ PathMapperContextImpl child = new PathMapperContextImpl(null);
+ root.addChild("a", child);
+
+ assertEquals(new PathMapperResult(null, null, null), mapper.map(root, null));
+ assertEquals(new PathMapperResult(null, null, null), mapper.map(root,
""));
+ assertEquals(new PathMapperResult(null, null, "/"), mapper.map(root,
"/"));
+ assertEquals(new PathMapperResult(null, null, "/"), mapper.map(root,
"//"));
+
+ assertEquals(new PathMapperResult(child, "/a", null), mapper.map(root,
"/a"));
+ assertEquals(new PathMapperResult(child, "/a", "/"),
mapper.map(root, "/a/"));
+ assertEquals(new PathMapperResult(child, "/a", "/b"),
mapper.map(root, "/a/b"));
+ assertEquals(new PathMapperResult(child, "/a", "/b/"),
mapper.map(root, "/a/b/"));
+ assertEquals(new PathMapperResult(child, "/a", "/b/c"),
mapper.map(root, "/a/b/c"));
+
+ assertEquals(new PathMapperResult(null, null, "/b"), mapper.map(root,
"/b"));
+ assertEquals(new PathMapperResult(null, null, "/b/"), mapper.map(root,
"/b/"));
+ assertEquals(new PathMapperResult(null, null, "/b/c"), mapper.map(root,
"/b/c"));
+ assertEquals(new PathMapperResult(null, null, "/b/c/"), mapper.map(root,
"/b/c/"));
+ assertEquals(new PathMapperResult(null, null, "/b/c/d"), mapper.map(root,
"/b/c/d"));
+ }
+
+ public void testOneChildHavingOneChild()
+ {
+ PathMapperContextImpl root = new PathMapperContextImpl(null);
+ PathMapperContextImpl child = new PathMapperContextImpl(null);
+ PathMapperContextImpl childOfChild = new PathMapperContextImpl(null);
+ root.addChild("a", child);
+ child.addChild("b", childOfChild);
+
+ assertEquals(new PathMapperResult(null, null, null), mapper.map(root, null));
+ assertEquals(new PathMapperResult(null, null, null), mapper.map(root,
""));
+ assertEquals(new PathMapperResult(null, null, "/"), mapper.map(root,
"/"));
+ assertEquals(new PathMapperResult(null, null, "/"), mapper.map(root,
"//"));
+
+ assertEquals(new PathMapperResult(child, "/a", null), mapper.map(root,
"/a"));
+ assertEquals(new PathMapperResult(child, "/a", "/"),
mapper.map(root, "/a/"));
+ assertEquals(new PathMapperResult(childOfChild, "/a/b", null),
mapper.map(root, "/a/b"));
+ assertEquals(new PathMapperResult(child, "/a", "/b/"),
mapper.map(root, "/a/b/"));
+ assertEquals(new PathMapperResult(child, "/a", "/b/c"),
mapper.map(root, "/a/b/c"));
+
+ assertEquals(new PathMapperResult(null, null, "/b"), mapper.map(root,
"/b"));
+ assertEquals(new PathMapperResult(null, null, "/b/"), mapper.map(root,
"/b/"));
+ assertEquals(new PathMapperResult(null, null, "/b/c"), mapper.map(root,
"/b/c"));
+ assertEquals(new PathMapperResult(null, null, "/b/c/"), mapper.map(root,
"/b/c/"));
+ assertEquals(new PathMapperResult(null, null, "/b/c/d"), mapper.map(root,
"/b/c/d"));
+ }
+
+ private static class Context
+ {
+ private final Map children;
+
+ public Context(Object dflt)
+ {
+ children = new HashMap();
+ }
+
+ public void addChild(String name, Object child)
+ {
+ children.put(name, child);
+ }
+ }
+
+ private static class PathMapperContextImpl extends Context implements
PathMapperContext
+ {
+ public PathMapperContextImpl(Object dflt)
+ {
+ super(dflt);
+ }
+
+ public Object getRoot()
+ {
+ return this;
+ }
+
+ public Object getChild(Object parent, String name)
+ {
+ return ((Context)parent).children.get(name);
+ }
+ }
+}
Property changes on:
trunk/common/src/main/org/jboss/portal/test/common/PathMapperTestCase.java
___________________________________________________________________
Name: svn:executable
+ *
Deleted: trunk/core/src/main/org/jboss/portal/core/impl/invocation/Mapper.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/impl/invocation/Mapper.java 2007-05-29
08:53:17 UTC (rev 7347)
+++ trunk/core/src/main/org/jboss/portal/core/impl/invocation/Mapper.java 2007-05-29
10:05:40 UTC (rev 7348)
@@ -1,36 +0,0 @@
-/******************************************************************************
- * 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. *
- ******************************************************************************/
-package org.jboss.portal.core.impl.invocation;
-
-/**
- * Map request uri path to portal object.
- *
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision$
- */
-public interface Mapper
-{
-
- public MappingResult map(MappingContext ctx, String path);
-
-}
Deleted: trunk/core/src/main/org/jboss/portal/core/impl/invocation/MappingContext.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/impl/invocation/MappingContext.java 2007-05-29
08:53:17 UTC (rev 7347)
+++
trunk/core/src/main/org/jboss/portal/core/impl/invocation/MappingContext.java 2007-05-29
10:05:40 UTC (rev 7348)
@@ -1,38 +0,0 @@
-/******************************************************************************
- * 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. *
- ******************************************************************************/
-package org.jboss.portal.core.impl.invocation;
-
-/**
- * Interface that provide access to portal object during a mapping request.
- *
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision$
- */
-public interface MappingContext
-{
- /** Return the object graph root. */
- Object getRoot();
-
- /** Return the child object having the specified name or null if it does not exists.
*/
- Object getChild(Object parent, String name);
-}
Deleted: trunk/core/src/main/org/jboss/portal/core/impl/invocation/MappingResult.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/impl/invocation/MappingResult.java 2007-05-29
08:53:17 UTC (rev 7347)
+++
trunk/core/src/main/org/jboss/portal/core/impl/invocation/MappingResult.java 2007-05-29
10:05:40 UTC (rev 7348)
@@ -1,90 +0,0 @@
-/******************************************************************************
- * 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. *
- ******************************************************************************/
-package org.jboss.portal.core.impl.invocation;
-
-/**
- * The result of a request to a mapper.
- *
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision$
- */
-public class MappingResult
-{
-
- private final Object target;
- private final String targetPath;
- private final String targetPathInfo;
-
- public MappingResult(Object target, String targetPath, String targetPathInfo)
- {
- this.target = target;
- this.targetPath = targetPath;
- this.targetPathInfo = targetPathInfo;
- }
-
- public Object getTarget()
- {
- return target;
- }
-
- public String getTargetPathInfo()
- {
- return targetPathInfo;
- }
-
- public int hashCode()
- {
- int hashCode = (target != null ? target.hashCode() : 0) +
- (targetPath != null ? targetPath.hashCode() : 0) +
- (targetPathInfo != null ? targetPathInfo.hashCode() : 0);
- return hashCode;
- }
-
- public boolean equals(Object obj)
- {
- if (obj == this)
- {
- return true;
- }
- if (obj instanceof MappingResult)
- {
- MappingResult other = (MappingResult)obj;
- return (target == null ? (other.target == null) : target.equals(other.target))
&&
- (targetPath == null ? (other.targetPath == null) :
targetPath.equals(other.targetPath)) &&
- (targetPathInfo == null ? (other.targetPathInfo == null) :
targetPathInfo.equals(other.targetPathInfo));
- }
- return false;
- }
-
- public String toString()
- {
- StringBuffer buffer = new StringBuffer("MappingResult[");
- buffer.append(target == null ? "-" : target.toString());
- buffer.append(',');
- buffer.append(targetPath == null ? "-" : targetPath);
- buffer.append(',');
- buffer.append(targetPathInfo == null ? "-" : targetPathInfo);
- buffer.append("]");
- return buffer.toString();
- }
-}
Deleted: trunk/core/src/main/org/jboss/portal/core/impl/invocation/SimpleMapper.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/impl/invocation/SimpleMapper.java 2007-05-29
08:53:17 UTC (rev 7347)
+++ trunk/core/src/main/org/jboss/portal/core/impl/invocation/SimpleMapper.java 2007-05-29
10:05:40 UTC (rev 7348)
@@ -1,119 +0,0 @@
-/******************************************************************************
- * 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. *
- ******************************************************************************/
-package org.jboss.portal.core.impl.invocation;
-
-/**
- * A simple mapper implementation. The limitations is that only the root and its children
can have children
- *
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision$
- */
-public class SimpleMapper implements Mapper
-{
- public MappingResult map(MappingContext ctx, String path)
- {
- Object root = ctx.getRoot();
- Object target = null;
- String targetPath = null;
- String targetPathInfo = null;
-
- if (path == null || path.length() == 0)
- {
- targetPath = null;
- targetPathInfo = null;
- }
- else if ("/".equals(path))
- {
- targetPath = null;
- targetPathInfo = "/";
- }
- else
- {
- int firstSlashPos = path.indexOf('/', 1);
- if (firstSlashPos == -1)
- {
- String firstChunk = path.substring(1);
- target = ctx.getChild(root, firstChunk);
- if (target != null)
- {
- targetPath = path;
- targetPathInfo = null;
- }
- else
- {
- targetPath = null;
- targetPathInfo = path;
- }
- }
- else if (firstSlashPos == 1)
- {
- targetPath = null;
- targetPathInfo = "/";
- }
- else
- {
- String firstChunk = path.substring(1, firstSlashPos);
- target = ctx.getChild(root, firstChunk);
- if (target != null)
- {
- int secondSlashPos = path.indexOf('/', firstSlashPos + 1);
- if (secondSlashPos == -1)
- {
- String secondChunck = path.substring(firstSlashPos + 1);
- if (secondChunck.length() == 0)
- {
- targetPath = "/" + firstChunk;
- targetPathInfo = "/";
- }
- else
- {
- Object child = ctx.getChild(target, secondChunck);
- if (child != null)
- {
- target = child;
- targetPath = path;
- targetPathInfo = null;
- }
- else
- {
- targetPath = "/" + firstChunk;
- targetPathInfo = "/" + secondChunck;
- }
- }
- }
- else
- {
- targetPath = "/" + firstChunk;
- targetPathInfo = path.substring(firstSlashPos);
- }
- }
- else
- {
- targetPath = null;
- targetPathInfo = path;
- }
- }
- }
- return new MappingResult(target, targetPath, targetPathInfo);
- }
-}
Deleted: trunk/core/src/main/org/jboss/portal/test/core/MapperTestCase.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/test/core/MapperTestCase.java 2007-05-29 08:53:17
UTC (rev 7347)
+++ trunk/core/src/main/org/jboss/portal/test/core/MapperTestCase.java 2007-05-29 10:05:40
UTC (rev 7348)
@@ -1,156 +0,0 @@
-/******************************************************************************
- * 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. *
- ******************************************************************************/
-package org.jboss.portal.test.core;
-
-import junit.framework.TestCase;
-import org.jboss.portal.core.impl.invocation.Mapper;
-import org.jboss.portal.core.impl.invocation.MappingContext;
-import org.jboss.portal.core.impl.invocation.MappingResult;
-import org.jboss.portal.core.impl.invocation.SimpleMapper;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision$
- */
-public class MapperTestCase extends TestCase
-{
-
- public MapperTestCase(String s)
- {
- super(s);
- }
-
- private Mapper mapper;
-
- protected void setUp() throws Exception
- {
- mapper = new SimpleMapper();
- }
-
- protected void tearDown() throws Exception
- {
- mapper = null;
- }
-
- public void testEmptyContext()
- {
- MappingContextImpl root = new MappingContextImpl(null);
-
- assertEquals(new MappingResult(null, null, null), mapper.map(root, null));
- assertEquals(new MappingResult(null, null, null), mapper.map(root, ""));
- assertEquals(new MappingResult(null, null, "/"), mapper.map(root,
"/"));
- assertEquals(new MappingResult(null, null, "/"), mapper.map(root,
"//"));
-
- assertEquals(new MappingResult(null, null, "/a"), mapper.map(root,
"/a"));
- assertEquals(new MappingResult(null, null, "/a/"), mapper.map(root,
"/a/"));
- assertEquals(new MappingResult(null, null, "/a/b"), mapper.map(root,
"/a/b"));
- assertEquals(new MappingResult(null, null, "/a/b/"), mapper.map(root,
"/a/b/"));
- assertEquals(new MappingResult(null, null, "/a/b/c"), mapper.map(root,
"/a/b/c"));
- }
-
- public void testOneChild()
- {
- MappingContextImpl root = new MappingContextImpl(null);
- MappingContextImpl child = new MappingContextImpl(null);
- root.addChild("a", child);
-
- assertEquals(new MappingResult(null, null, null), mapper.map(root, null));
- assertEquals(new MappingResult(null, null, null), mapper.map(root, ""));
- assertEquals(new MappingResult(null, null, "/"), mapper.map(root,
"/"));
- assertEquals(new MappingResult(null, null, "/"), mapper.map(root,
"//"));
-
- assertEquals(new MappingResult(child, "/a", null), mapper.map(root,
"/a"));
- assertEquals(new MappingResult(child, "/a", "/"),
mapper.map(root, "/a/"));
- assertEquals(new MappingResult(child, "/a", "/b"),
mapper.map(root, "/a/b"));
- assertEquals(new MappingResult(child, "/a", "/b/"),
mapper.map(root, "/a/b/"));
- assertEquals(new MappingResult(child, "/a", "/b/c"),
mapper.map(root, "/a/b/c"));
-
- assertEquals(new MappingResult(null, null, "/b"), mapper.map(root,
"/b"));
- assertEquals(new MappingResult(null, null, "/b/"), mapper.map(root,
"/b/"));
- assertEquals(new MappingResult(null, null, "/b/c"), mapper.map(root,
"/b/c"));
- assertEquals(new MappingResult(null, null, "/b/c/"), mapper.map(root,
"/b/c/"));
- assertEquals(new MappingResult(null, null, "/b/c/d"), mapper.map(root,
"/b/c/d"));
- }
-
- public void testOneChildHavingOneChild()
- {
- MappingContextImpl root = new MappingContextImpl(null);
- MappingContextImpl child = new MappingContextImpl(null);
- MappingContextImpl childOfChild = new MappingContextImpl(null);
- root.addChild("a", child);
- child.addChild("b", childOfChild);
-
- assertEquals(new MappingResult(null, null, null), mapper.map(root, null));
- assertEquals(new MappingResult(null, null, null), mapper.map(root, ""));
- assertEquals(new MappingResult(null, null, "/"), mapper.map(root,
"/"));
- assertEquals(new MappingResult(null, null, "/"), mapper.map(root,
"//"));
-
- assertEquals(new MappingResult(child, "/a", null), mapper.map(root,
"/a"));
- assertEquals(new MappingResult(child, "/a", "/"),
mapper.map(root, "/a/"));
- assertEquals(new MappingResult(childOfChild, "/a/b", null),
mapper.map(root, "/a/b"));
- assertEquals(new MappingResult(child, "/a", "/b/"),
mapper.map(root, "/a/b/"));
- assertEquals(new MappingResult(child, "/a", "/b/c"),
mapper.map(root, "/a/b/c"));
-
- assertEquals(new MappingResult(null, null, "/b"), mapper.map(root,
"/b"));
- assertEquals(new MappingResult(null, null, "/b/"), mapper.map(root,
"/b/"));
- assertEquals(new MappingResult(null, null, "/b/c"), mapper.map(root,
"/b/c"));
- assertEquals(new MappingResult(null, null, "/b/c/"), mapper.map(root,
"/b/c/"));
- assertEquals(new MappingResult(null, null, "/b/c/d"), mapper.map(root,
"/b/c/d"));
- }
-
- private static class Context
- {
- private final Map children;
-
- public Context(Object dflt)
- {
- children = new HashMap();
- }
-
- public void addChild(String name, Object child)
- {
- children.put(name, child);
- }
- }
-
- private static class MappingContextImpl extends Context implements MappingContext
- {
- public MappingContextImpl(Object dflt)
- {
- super(dflt);
- }
-
- public Object getRoot()
- {
- return this;
- }
-
- public Object getChild(Object parent, String name)
- {
- return ((Context)parent).children.get(name);
- }
- }
-}