01: /*******************************************************************************
02: * Copyright (c) 2000, 2004 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM - Initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.build.ant;
11:
12: import java.util.*;
13:
14: /**
15: * Represents an Ant condition.
16: */
17: public class Condition {
18:
19: /**
20: * Types of conditions.
21: */
22: protected String type;
23: public static final String TYPE_AND = "and"; //$NON-NLS-1$
24: protected List singleConditions;
25: protected List nestedConditions;
26:
27: /**
28: * Default constructor for the class.
29: */
30: public Condition() {
31: this .singleConditions = new ArrayList(5);
32: this .nestedConditions = new ArrayList(5);
33: }
34:
35: public Condition(String type) {
36: this ();
37: this .type = type;
38: }
39:
40: /**
41: * Add this Ant condition to the given Ant script.
42: *
43: * @param script the script to add the condition to
44: */
45: protected void print(AntScript script) {
46: if (type != null) {
47: script.indent++;
48: script.printStartTag(type);
49: }
50: for (Iterator iterator = singleConditions.iterator(); iterator
51: .hasNext();)
52: script.printString((String) iterator.next());
53: for (Iterator iterator = nestedConditions.iterator(); iterator
54: .hasNext();) {
55: Condition condition = (Condition) iterator.next();
56: condition.print(script);
57: }
58: if (type != null) {
59: script.printEndTag(type);
60: script.indent--;
61: }
62: }
63:
64: /**
65: * Add an "equals" condition to this Ant condition.
66: *
67: * @param arg1 the left-hand side of the equals
68: * @param arg2 the right-hand side of the equals
69: */
70: public void addEquals(String arg1, String arg2) {
71: StringBuffer condition = new StringBuffer();
72: condition.append("<equals "); //$NON-NLS-1$
73: condition.append("arg1=\""); //$NON-NLS-1$
74: condition.append(arg1);
75: condition.append("\" "); //$NON-NLS-1$
76: condition.append("arg2=\""); //$NON-NLS-1$
77: condition.append(arg2);
78: condition.append("\"/>"); //$NON-NLS-1$
79: singleConditions.add(condition.toString());
80: }
81:
82: /**
83: * Add the given condition to this Ant condition.
84: *
85: * @param condition the condition to add
86: */
87: public void add(Condition condition) {
88: nestedConditions.add(condition);
89: }
90:
91: }
|