Browse Source

Updated TaskContext imp[lementation to reflect new interface

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271470 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Donald 23 years ago
parent
commit
b52e2b425f
1 changed files with 59 additions and 15 deletions
  1. +59
    -15
      proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/DefaultTaskContext.java

+ 59
- 15
proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/DefaultTaskContext.java View File

@@ -8,15 +8,17 @@
package org.apache.myrmidon.components.workspace; package org.apache.myrmidon.components.workspace;


import java.io.File; import java.io.File;
import java.util.Hashtable;
import java.util.Map;
import org.apache.avalon.excalibur.i18n.ResourceManager; import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources; import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.avalon.excalibur.io.FileUtil; import org.apache.avalon.excalibur.io.FileUtil;
import org.apache.avalon.excalibur.property.PropertyException;
import org.apache.avalon.excalibur.property.PropertyUtil;
import org.apache.avalon.framework.context.ContextException; import org.apache.avalon.framework.context.ContextException;
import org.apache.avalon.framework.context.DefaultContext;
import org.apache.myrmidon.api.TaskContext; import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.api.TaskException; import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.components.configurer.PropertyUtil;
import org.apache.myrmidon.components.configurer.PropertyException;
import org.apache.myrmidon.interfaces.configurer.TaskContextAdapter;
import org.apache.myrmidon.interfaces.service.ServiceException; import org.apache.myrmidon.interfaces.service.ServiceException;
import org.apache.myrmidon.interfaces.service.ServiceManager; import org.apache.myrmidon.interfaces.service.ServiceManager;


@@ -27,12 +29,13 @@ import org.apache.myrmidon.interfaces.service.ServiceManager;
* @version $Revision$ $Date$ * @version $Revision$ $Date$
*/ */
public class DefaultTaskContext public class DefaultTaskContext
extends DefaultContext
implements TaskContext implements TaskContext
{ {
private final static Resources REZ = private final static Resources REZ =
ResourceManager.getPackageResources( DefaultTaskContext.class ); ResourceManager.getPackageResources( DefaultTaskContext.class );


private final Map m_contextData = new Hashtable();
private final TaskContext m_parent;
private ServiceManager m_serviceManager; private ServiceManager m_serviceManager;


/** /**
@@ -65,10 +68,40 @@ public class DefaultTaskContext
public DefaultTaskContext( final TaskContext parent, public DefaultTaskContext( final TaskContext parent,
final ServiceManager serviceManager ) final ServiceManager serviceManager )
{ {
super( parent );
m_parent = parent;
m_serviceManager = serviceManager; m_serviceManager = serviceManager;
} }


/**
* Retrieve an item from the Context.
*
* @param key the key of item
* @return the item stored in context
* @exception ContextException if item not present
*/
public Object get( final Object key )
throws ContextException
{
final Object data = m_contextData.get( key );
if( null != data )
{
// if( data instanceof Resolvable )
// {
// return ( (Resolvable)data ).resolve( this );
// }
return data;
}

// If data was null, check the parent
if( null == m_parent )
{
// There was no parent, and no data
throw new ContextException( "Unable to locate " + key );
}

return m_parent.getProperty( key.toString() );
}

/** /**
* Retrieve Name of task. * Retrieve Name of task.
* *
@@ -133,10 +166,9 @@ public class DefaultTaskContext
} }


// Try parent // Try parent
final TaskContext parent = (TaskContext)getParent();
if( null != parent )
if( null != m_parent )
{ {
return parent.getService( serviceClass );
return m_parent.getService( serviceClass );
} }


// Not found // Not found
@@ -173,8 +205,10 @@ public class DefaultTaskContext
{ {
try try
{ {
final TaskContextAdapter context = new TaskContextAdapter( this );

final Object object = final Object object =
PropertyUtil.resolveProperty( value, this, false );
PropertyUtil.resolveProperty( value, context, false );


if( null == object ) if( null == object )
{ {
@@ -209,6 +243,16 @@ public class DefaultTaskContext
} }
} }


/**
* Retrieve a copy of all the properties accessible via context.
*
* @return the map of all property names to values
*/
public Map getPropertys()
{
return null;
}

/** /**
* Set property value in current context. * Set property value in current context.
* *
@@ -231,30 +275,30 @@ public class DefaultTaskContext


if( CURRENT == scope ) if( CURRENT == scope )
{ {
put( name, value );
m_contextData.put( name, value );
} }
else if( PARENT == scope ) else if( PARENT == scope )
{ {
if( null == getParent() )
if( null == m_parent )
{ {
final String message = REZ.getString( "no-parent.error" ); final String message = REZ.getString( "no-parent.error" );
throw new TaskException( message ); throw new TaskException( message );
} }
else else
{ {
( (TaskContext)getParent() ).setProperty( name, value );
m_parent.setProperty( name, value );
} }
} }
else if( TOP_LEVEL == scope ) else if( TOP_LEVEL == scope )
{ {
DefaultTaskContext context = this; DefaultTaskContext context = this;


while( null != context.getParent() )
while( null != context.m_parent )
{ {
context = (DefaultTaskContext)context.getParent();
context = (DefaultTaskContext)context.m_parent;
} }


context.put( name, value );
context.m_contextData.put( name, value );
} }
else else
{ {


Loading…
Cancel
Save