commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From patri...@apache.org
Subject cvs commit: jakarta-commons-sandbox/daemon/src/java/org/apache/commons/launcher/types ConditionalVariableSet.java ConditionalArgument.java ConditionalVariable.java SysPropertySet.java
Date Sat, 13 Jul 2002 20:12:34 GMT
patrickl    2002/07/13 13:12:34

  Modified:    daemon/src/java/org/apache/commons/launcher/types
                        ConditionalArgument.java ConditionalVariable.java
                        SysPropertySet.java
  Added:       daemon/src/java/org/apache/commons/launcher/types
                        ConditionalVariableSet.java
  Log:
  Separate out methods in SysPropertySet class that can be reused by other similar classes
  
  Revision  Changes    Path
  1.2       +2 -2      jakarta-commons-sandbox/daemon/src/java/org/apache/commons/launcher/types/ConditionalArgument.java
  
  Index: ConditionalArgument.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/daemon/src/java/org/apache/commons/launcher/types/ConditionalArgument.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ConditionalArgument.java	13 Jul 2002 18:56:25 -0000	1.1
  +++ ConditionalArgument.java	13 Jul 2002 20:12:34 -0000	1.2
  @@ -71,7 +71,7 @@
    */
   public class ConditionalArgument {
   
  -    //-------------------------------------------------------------- Fields
  +    //------------------------------------------------------------------ Fields
   
       /**
        * Cached "if" condition flag
  @@ -88,7 +88,7 @@
        */
       private String value = null;
   
  -    //------------------------------------------------------------- Methods
  +    //----------------------------------------------------------------- Methods
   
       /**
        * Get the "if" condition flag.
  
  
  
  1.2       +2 -2      jakarta-commons-sandbox/daemon/src/java/org/apache/commons/launcher/types/ConditionalVariable.java
  
  Index: ConditionalVariable.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/daemon/src/java/org/apache/commons/launcher/types/ConditionalVariable.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ConditionalVariable.java	13 Jul 2002 18:56:25 -0000	1.1
  +++ ConditionalVariable.java	13 Jul 2002 20:12:34 -0000	1.2
  @@ -71,7 +71,7 @@
    */
   public class ConditionalVariable extends Environment.Variable {
   
  -    //-------------------------------------------------------------- Fields
  +    //------------------------------------------------------------------ Fields
   
       /**
        * Cached "if" condition flag
  @@ -83,7 +83,7 @@
        */
       private String unlessCondition = null;
   
  -    //------------------------------------------------------------- Methods
  +    //----------------------------------------------------------------- Methods
   
       /**
        * Get the "if" condition flag.
  
  
  
  1.2       +5 -69     jakarta-commons-sandbox/daemon/src/java/org/apache/commons/launcher/types/SysPropertySet.java
  
  Index: SysPropertySet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/daemon/src/java/org/apache/commons/launcher/types/SysPropertySet.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SysPropertySet.java	13 Jul 2002 18:56:25 -0000	1.1
  +++ SysPropertySet.java	13 Jul 2002 20:12:34 -0000	1.2
  @@ -57,28 +57,16 @@
   
   package org.apache.commons.launcher.types;
   
  -import java.util.Enumeration;
  -import java.util.Stack;
   import java.util.Vector;
  -import org.apache.commons.launcher.Launcher;
  -import org.apache.commons.launcher.types.ConditionalVariable;
  -import org.apache.tools.ant.BuildException;
  -import org.apache.tools.ant.types.DataType;
  -import org.apache.tools.ant.types.Reference;
   
   /**
    * A class that represents a set of nested <sysproperty> elements.
    *
    * @author Patrick Luby
    */
  -public class SysPropertySet extends DataType {
  +public class SysPropertySet extends ConditionalVariableSet {
   
  -    //-------------------------------------------------------------- Fields
  -
  -    /**
  -     * Cached variables and nested SysPropertySet objects
  -     */
  -    private Vector list = new Vector();
  +    //----------------------------------------------------------------- Methods
   
       /**
        * Add a {@link ConditionalVariable}.
  @@ -88,9 +76,7 @@
        */
       public void addSysproperty(ConditionalVariable variable) {
   
  -        if (isReference())
  -            throw noChildrenAllowed();
  -        list.addElement(variable);
  +        addConditionalvariable(variable);
   
       }
   
  @@ -101,9 +87,7 @@
        */
       public void addSyspropertyset(SysPropertySet set) {
   
  -        if (isReference())
  -            throw noChildrenAllowed();
  -        list.addElement(set);
  +        addConditionalvariableset(set);
   
       }
   
  @@ -114,55 +98,7 @@
        */
       public Vector getSysproperties() {
   
  -        // Make sure we don't have a circular reference to this instance
  -        if (!checked) {
  -            Stack stk = new Stack();
  -            stk.push(this);
  -            dieOnCircularReference(stk, project);
  -        }
  -
  -        // Recursively work through the tree of SysPropertySet objects
  -        // and accumulate the list of ConditionalVariable objects
  -        Vector mergedList = new Vector(list.size());
  -        Enumeration enum = list.elements();
  -        while (enum.hasMoreElements()) {
  -            Object o = enum.nextElement();
  -            SysPropertySet nestedSet = null;
  -            if (o instanceof Reference) {
  -                o = ((Reference)o).getReferencedObject(project);
  -                // Only references to this class are allowed
  -                if (!(o instanceof SysPropertySet))
  -                    throw new BuildException(Launcher.getLocalizedString("cannot.reference",
this.getClass().getName()));
  -                nestedSet = (SysPropertySet)o;
  -            } else if (o instanceof SysPropertySet) {
  -                nestedSet = (SysPropertySet)o;
  -            } else if (o instanceof ConditionalVariable) {
  -                mergedList.addElement(o);
  -            } else {
  -                throw new BuildException(Launcher.getLocalizedString("cannot.nest", this.getClass().getName()));
  -            }
  -            if (nestedSet != null)
  -                mergedList.addAll(nestedSet.getSysproperties());
  -        }
  -
  -        return mergedList;
  -
  -    }
  -
  -    /**
  -     * Makes this instance a reference to another instance. You must not
  -     * set another attribute or nest elements inside this element if you
  -     * make it a reference.
  -     *
  -     * @param r the reference to another {@link SysPropertySet}
  -     *  instance
  -     */
  -    public void setRefid(Reference r) throws BuildException {
  -
  -        if (!list.isEmpty())
  -            throw tooManyAttributes();
  -        list.addElement(r);
  -        super.setRefid(r);
  +        return getConditionalvariables();
   
       }
   
  
  
  
  1.1                  jakarta-commons-sandbox/daemon/src/java/org/apache/commons/launcher/types/ConditionalVariableSet.java
  
  Index: ConditionalVariableSet.java
  ===================================================================
  /* ========================================================================= *
   *                                                                           *
   *                 The Apache Software License,  Version 1.1                 *
   *                                                                           *
   *             Copyright (c) 2002 The Apache Software Foundation.            *
   *                           All rights reserved.                            *
   *                                                                           *
   * ========================================================================= *
   *                                                                           *
   * Redistribution and use in source and binary forms,  with or without modi- *
   * fication, are permitted provided that the following conditions are met:   *
   *                                                                           *
   * 1. Redistributions of source code  must retain the above copyright notice *
   *    notice, this list of conditions and the following disclaimer.          *
   *                                                                           *
   * 2. Redistributions  in binary  form  must  reproduce the  above copyright *
   *    notice,  this list of conditions  and the following  disclaimer in the *
   *    documentation and/or other materials provided with the distribution.   *
   *                                                                           *
   * 3. The end-user documentation  included with the redistribution,  if any, *
   *    must include the following acknowlegement:                             *
   *                                                                           *
   *       "This product includes  software developed  by the Apache  Software *
   *        Foundation <http://www.apache.org/>."                              *
   *                                                                           *
   *    Alternately, this acknowlegement may appear in the software itself, if *
   *    and wherever such third-party acknowlegements normally appear.         *
   *                                                                           *
   * 4. The names  "The Jakarta  Project",  and  "Apache  Software Foundation" *
   *    must not  be used  to endorse  or promote  products derived  from this *
   *    software without  prior written  permission.  For written  permission, *
   *    please contact <apache@apache.org>.                                    *
   *                                                                           *
   * 5. Products derived from this software may not be called "Apache" nor may *
   *    "Apache" appear in their names without prior written permission of the *
   *    Apache Software Foundation.                                            *
   *                                                                           *
   * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES *
   * INCLUDING, BUT NOT LIMITED TO,  THE IMPLIED WARRANTIES OF MERCHANTABILITY *
   * AND FITNESS FOR  A PARTICULAR PURPOSE  ARE DISCLAIMED.  IN NO EVENT SHALL *
   * THE APACHE  SOFTWARE  FOUNDATION OR  ITS CONTRIBUTORS  BE LIABLE  FOR ANY *
   * DIRECT,  INDIRECT,   INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR  CONSEQUENTIAL *
   * DAMAGES (INCLUDING,  BUT NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE GOODS *
   * OR SERVICES;  LOSS OF USE,  DATA,  OR PROFITS;  OR BUSINESS INTERRUPTION) *
   * HOWEVER CAUSED AND  ON ANY  THEORY  OF  LIABILITY,  WHETHER IN  CONTRACT, *
   * STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN *
   * ANY  WAY  OUT OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF  ADVISED  OF THE *
   * POSSIBILITY OF SUCH DAMAGE.                                               *
   *                                                                           *
   * ========================================================================= *
   *                                                                           *
   * This software  consists of voluntary  contributions made  by many indivi- *
   * duals on behalf of the  Apache Software Foundation.  For more information *
   * on the Apache Software Foundation, please see <http://www.apache.org/>.   *
   *                                                                           *
   * ========================================================================= */
  
  package org.apache.commons.launcher.types;
  
  import java.util.Enumeration;
  import java.util.Stack;
  import java.util.Vector;
  import org.apache.commons.launcher.Launcher;
  import org.apache.tools.ant.BuildException;
  import org.apache.tools.ant.types.DataType;
  import org.apache.tools.ant.types.Reference;
  
  /**
   * A class that represents a set of nested elements of
   * {@link ConditionalVariable} objects.
   *
   * @author Patrick Luby
   */
  public class ConditionalVariableSet extends DataType {
  
      //------------------------------------------------------------------ Fields
  
      /**
       * Cached variables and nested ConditionalVariableSet objects
       */
      private Vector list = new Vector();
  
      //----------------------------------------------------------------- Methods
  
      /**
       * Add a {@link ConditionalVariable}.
       *
       * @param variable the {@link ConditionalVariable} to be
       *  added
       */
      protected void addConditionalvariable(ConditionalVariable variable) {
  
          if (isReference())
              throw noChildrenAllowed();
          list.addElement(variable);
  
      }
  
      /**
       * Add a {@link ConditionalVariableSet}.
       *
       * @param set the {@link ConditionalVariableSet} to be added
       */
      protected void addConditionalvariableset(ConditionalVariableSet set) {
  
          if (isReference())
              throw noChildrenAllowed();
          list.addElement(set);
  
      }
  
      /**
       * Get {@link ConditionalVariable} instances.
       *
       * @return the {@link ConditionalVariable} instances
       */
      protected Vector getConditionalvariables() {
  
          // Make sure we don't have a circular reference to this instance
          if (!checked) {
              Stack stk = new Stack();
              stk.push(this);
              dieOnCircularReference(stk, project);
          }
  
          // Recursively work through the tree of ConditionalVariableSet objects
          // and accumulate the list of ConditionalVariable objects.
          Vector mergedList = new Vector(list.size());
          Enumeration enum = list.elements();
          while (enum.hasMoreElements()) {
              Object o = enum.nextElement();
              ConditionalVariableSet nestedSet = null;
              if (o instanceof Reference) {
                  o = ((Reference)o).getReferencedObject(project);
                  // Only references to this class are allowed
                  if (!o.getClass().isInstance(this))
                      throw new BuildException(Launcher.getLocalizedString("cannot.reference",
this.getClass().getName()));
                  nestedSet = (ConditionalVariableSet)o;
              } else if (o.getClass().isInstance(this)) {
                  nestedSet = (ConditionalVariableSet)o;
              } else if (o instanceof ConditionalVariable) {
                  mergedList.addElement(o);
              } else {
                  throw new BuildException(Launcher.getLocalizedString("cannot.nest", this.getClass().getName()));
              }
              if (nestedSet != null)
                  mergedList.addAll(nestedSet.getConditionalvariables());
          }
  
          return mergedList;
  
      }
  
      /**
       * Makes this instance a reference to another instance. You must not
       * set another attribute or nest elements inside this element if you
       * make it a reference.
       *
       * @param r the reference to another {@link ConditionalVariableSet}
       *  instance
       */
      public void setRefid(Reference r) throws BuildException {
  
          if (!list.isEmpty())
              throw tooManyAttributes();
          list.addElement(r);
          super.setRefid(r);
  
      }
  
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message