You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by ad...@apache.org on 2002/07/02 04:21:24 UTC
cvs commit: jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/core IsInstanceCondition.java Resources.properties
adammurdoch 2002/07/01 19:21:24
Modified: antlib/src/java/org/apache/antlib/core Resources.properties
Added: antlib/src/java/org/apache/antlib/core
IsInstanceCondition.java
Log:
Added <is-instance> condition. Useful for tests.
Revision Changes Path
1.8 +5 -1 jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/core/Resources.properties
Index: Resources.properties
===================================================================
RCS file: /home/cvs/jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/core/Resources.properties,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Resources.properties 26 Jun 2002 02:12:36 -0000 1.7
+++ Resources.properties 2 Jul 2002 02:21:24 -0000 1.8
@@ -38,4 +38,8 @@
load-dom.load-file.error=Could not load file "{0}".
include.no-file.error=No source file specified.
-include.load-file.error=Could not load file "{0}".
\ No newline at end of file
+include.load-file.error=Could not load file "{0}".
+
+is-instance.no-property.error=No property name specified.
+is-instance.no-role.error=No role specified.
+is-instance.unknown-role.error=Unknown role "{0}".
\ No newline at end of file
1.1 jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/core/IsInstanceCondition.java
Index: IsInstanceCondition.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.antlib.core;
import org.apache.myrmidon.framework.conditions.Condition;
import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.interfaces.role.RoleManager;
import org.apache.myrmidon.interfaces.role.RoleInfo;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
/**
* Checks whether a property is set to an instance of a particular type.
*
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
* @version $Revision: 1.1 $ $Date: 2002/07/02 02:21:24 $
*
* @ant.type type="condition" name="is-instance"
*/
public class IsInstanceCondition
implements Condition
{
private static final Resources REZ =
ResourceManager.getPackageResources( IsInstanceCondition.class );
private String m_property;
private String m_role;
/**
* The property to check.
*/
public void setProperty( final String property )
{
m_property = property;
}
/**
* The role to check.
*/
public void setRole( final String role )
{
m_role = role;
}
/**
* Evaluates this condition.
*
* @param context
* The context to evaluate the condition in.
*/
public boolean evaluate( final TaskContext context )
throws TaskException
{
if( m_property == null )
{
final String message = REZ.getString( "is-instance.no-property.error" );
throw new TaskException( message );
}
if( m_role == null )
{
final String message = REZ.getString( "is-instance.no-role.error" );
throw new TaskException( message );
}
final Object propValue = context.getProperty( m_property );
if( propValue == null )
{
return false;
}
// Get meta-info for role
final RoleManager roleManager = (RoleManager)context.getService( RoleManager.class );
final RoleInfo role = roleManager.getRoleByShortName( m_role );
if( role == null )
{
final String message = REZ.getString( "is-instance.unknown-role.error", m_role );
throw new TaskException( message );
}
return role.getImplementationClass().isInstance( propValue );
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>