ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/framework Condition.java
Date Wed, 27 Jun 2001 00:47:43 GMT
donaldp     01/06/26 17:47:43

  Added:       proposal/myrmidon/src/java/org/apache/myrmidon/framework
                        Condition.java
  Removed:     proposal/myrmidon/src/java/org/apache/myrmidon/components/model
                        Condition.java
  Log:
  Migrate Condition class to framework
  
  Revision  Changes    Path
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/framework/Condition.java
  
  Index: Condition.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 file.
   */
  package org.apache.myrmidon.framework;
  
  import org.apache.avalon.excalibur.property.PropertyException;
  import org.apache.avalon.excalibur.property.PropertyUtil;
  import org.apache.avalon.framework.component.Component;
  import org.apache.avalon.framework.context.Context;
  import org.apache.avalon.framework.context.ContextException;
  import org.apache.myrmidon.api.TaskException;
  
  /**
   * Class representing a condition.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public class Condition
      implements Component
  {
      private String            m_condition;
      private boolean           m_isIfCondition;
  
      public Condition( final boolean isIfCondition, final String condition )
      {
          m_isIfCondition = isIfCondition;
          m_condition = condition;
      }
  
      public String getCondition()
      {
          return m_condition;
      }
  
      public boolean isIfCondition()
      {
          return m_isIfCondition;
      }
  
      public boolean evaluate( final Context context )
          throws TaskException
      {
          boolean result = false;
  
          try
          {
              final Object resolved =
                  PropertyUtil.resolveProperty( getCondition(), context, false );
  
              if( null != resolved )
              {
                  final Object object = context.get( resolved );
                  //TODO: Do more than just check for presence????????????
  
                  //true as object present
                  result = true;
              }
          }
          catch( final ContextException ce )
          {
              result = false;
          }
          catch( final PropertyException pe )
          {
              throw new TaskException( "Error resolving " + m_condition, pe );
          }
  
          if( !m_isIfCondition )
          {
              result = !result;
          }
  
          return result;
      }
  }
  
  
  
  
  

Mime
View raw message