KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > build > ant > Condition


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM - Initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.build.ant;
12
13 import java.util.*;
14
15 /**
16  * Represents an Ant condition.
17  */

18 public class Condition {
19
20     /**
21      * Types of conditions.
22      */

23     protected String JavaDoc type;
24     public static final String JavaDoc TYPE_AND = "and"; //$NON-NLS-1$
25
protected List singleConditions;
26     protected List nestedConditions;
27
28     /**
29      * Default constructor for the class.
30      */

31     public Condition() {
32         this.singleConditions = new ArrayList(5);
33         this.nestedConditions = new ArrayList(5);
34     }
35
36     public Condition(String JavaDoc type) {
37         this();
38         this.type = type;
39     }
40
41     /**
42      * Add this Ant condition to the given Ant script.
43      *
44      * @param script the script to add the condition to
45      */

46     protected void print(AntScript script) {
47         if (type != null) {
48             script.indent++;
49             script.printStartTag(type);
50         }
51         for (Iterator iterator = singleConditions.iterator(); iterator.hasNext();)
52             script.printString((String JavaDoc) iterator.next());
53         for (Iterator iterator = nestedConditions.iterator(); iterator.hasNext();) {
54             Condition condition = (Condition) iterator.next();
55             condition.print(script);
56         }
57         if (type != null) {
58             script.printEndTag(type);
59             script.indent--;
60         }
61     }
62
63     /**
64      * Add an "equals" condition to this Ant condition.
65      *
66      * @param arg1 the left-hand side of the equals
67      * @param arg2 the right-hand side of the equals
68      */

69     public void addEquals(String JavaDoc arg1, String JavaDoc arg2) {
70         StringBuffer JavaDoc condition = new StringBuffer JavaDoc();
71         condition.append("<equals "); //$NON-NLS-1$
72
condition.append("arg1=\""); //$NON-NLS-1$
73
condition.append(arg1);
74         condition.append("\" "); //$NON-NLS-1$
75
condition.append("arg2=\""); //$NON-NLS-1$
76
condition.append(arg2);
77         condition.append("\"/>"); //$NON-NLS-1$
78
singleConditions.add(condition.toString());
79     }
80
81     /**
82      * Add the given condition to this Ant condition.
83      *
84      * @param condition the condition to add
85      */

86     public void add(Condition condition) {
87         nestedConditions.add(condition);
88     }
89
90 }
91
Popular Tags