mcconnell 2004/01/07 04:49:14
Modified:
merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl
Tag: Ver_3_4 DefaultContainmentModel.java
Log:
Add support for ./ and ../ path references during relative address resolution.
Revision Changes Path
No revision
No revision
1.13.2.11 +46 -5
avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultContainmentModel.java
Index: DefaultContainmentModel.java
===================================================================
RCS file:
/home/cvs/avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultContainmentModel.java,v
retrieving revision 1.13.2.10
retrieving revision 1.13.2.11
diff -u -r1.13.2.10 -r1.13.2.11
--- DefaultContainmentModel.java 6 Jan 2004 23:16:49 -0000 1.13.2.10
+++ DefaultContainmentModel.java 7 Jan 2004 12:49:14 -0000 1.13.2.11
@@ -1400,6 +1400,9 @@
*/
public DeploymentModel getModel( String path )
{
+ ContainmentModel parent =
+ m_context.getParentContainmentModel();
+
if( path.equals( "" ) )
{
return this;
@@ -1411,9 +1414,9 @@
// root container
//
- if( null != m_context.getParentContainmentModel() )
+ if( null != parent )
{
- return m_context.getParentContainmentModel().getModel( path );
+ return parent.getModel( path );
}
else
{
@@ -1436,8 +1439,47 @@
// repository
//
- if( path.indexOf( "/" ) < 0 )
+ final String root = getRootName( path );
+
+ if( root.equals( ".." ) )
+ {
+ //
+ // its a relative reference in the form "../xxx/yyy"
+ // in which case we simply redirect "xxx/yyy" to the
+ // parent container
+ //
+
+ if( null != parent )
+ {
+ final String remainder = getRemainder( root, path );
+ return parent.getModel( remainder );
+ }
+ else
+ {
+ final String error =
+ "Supplied path ["
+ + path
+ + "] references a container above the root container.";
+ throw new IllegalArgumentException( error );
+ }
+ }
+ else if( root.equals( "." ) )
{
+ //
+ // its a path with a redundant "./xxx/yyy" which is
+ // equivalent to "xxx/yyy"
+ //
+
+ final String remainder = getRemainder( root, path );
+ return getModel( remainder );
+ }
+ else if( path.indexOf( "/" ) < 0 )
+ {
+ //
+ // its a path in the form "xxx" so we can use this
+ // to lookup and return a local child
+ //
+
return m_context.getModelRepository().getModel( path );
}
else
@@ -1447,7 +1489,6 @@
// getModel to the container
//
- final String root = getRootName( path );
DeploymentModel model =
m_context.getModelRepository().getModel( root );
if( model != null )
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]