source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/main/org/apache/tools/ant/util/facade/FacadeTaskHelper.java@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

File size: 4.1 KB
Line 
1/*
2 * Copyright 2002-2005 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18package org.apache.tools.ant.util.facade;
19
20import java.util.Enumeration;
21import java.util.Vector;
22
23/**
24 * Helper class for facade implementations - encapsulates treatment of
25 * explicit implementation choices, magic properties and
26 * implementation specific command line arguments.
27 *
28 *
29 * @since Ant 1.5
30 */
31public class FacadeTaskHelper {
32
33 /**
34 * Command line arguments.
35 */
36 private Vector args = new Vector();
37
38 /**
39 * The explicitly chosen implementation.
40 */
41 private String userChoice;
42
43 /**
44 * The magic property to consult.
45 */
46 private String magicValue;
47
48 /**
49 * The default value.
50 */
51 private String defaultValue;
52
53 /**
54 * @param defaultValue The default value for the implementation.
55 * Must not be null.
56 */
57 public FacadeTaskHelper(String defaultValue) {
58 this(defaultValue, null);
59 }
60
61 /**
62 * @param defaultValue The default value for the implementation.
63 * Must not be null.
64 * @param magicValue the value of a magic property that may hold a user.
65 * choice. May be null.
66 */
67 public FacadeTaskHelper(String defaultValue, String magicValue) {
68 this.defaultValue = defaultValue;
69 this.magicValue = magicValue;
70 }
71
72 /**
73 * Used to set the value of the magic property.
74 * @param magicValue the value of a magic property that may hold a user.
75 */
76 public void setMagicValue(String magicValue) {
77 this.magicValue = magicValue;
78 }
79
80 /**
81 * Used for explicit user choices.
82 * @param userChoice the explicitly chosen implementation.
83 */
84 public void setImplementation(String userChoice) {
85 this.userChoice = userChoice;
86 }
87
88 /**
89 * Retrieves the implementation.
90 * @return the implementation.
91 */
92 public String getImplementation() {
93 return userChoice != null ? userChoice
94 : (magicValue != null ? magicValue
95 : defaultValue);
96 }
97
98 /**
99 * Retrieves the explicit user choice.
100 * @return the explicit user choice.
101 */
102 public String getExplicitChoice() {
103 return userChoice;
104 }
105
106 /**
107 * Command line argument.
108 * @param arg an argument to add.
109 */
110 public void addImplementationArgument(ImplementationSpecificArgument arg) {
111 args.addElement(arg);
112 }
113
114 /**
115 * Retrieves the command line arguments enabled for the current
116 * facade implementation.
117 * @return an array of command line arguements.
118 */
119 public String[] getArgs() {
120 Vector tmp = new Vector(args.size());
121 for (Enumeration e = args.elements(); e.hasMoreElements();) {
122 ImplementationSpecificArgument arg =
123 ((ImplementationSpecificArgument) e.nextElement());
124 String[] curr = arg.getParts(getImplementation());
125 for (int i = 0; i < curr.length; i++) {
126 tmp.addElement(curr[i]);
127 }
128 }
129 String[] res = new String[tmp.size()];
130 tmp.copyInto(res);
131 return res;
132 }
133
134 /**
135 * Tests whether the implementation has been chosen by the user
136 * (either via a magic property or explicitly.
137 * @return true if magic or user choice has be set.
138 * @since Ant 1.5.2
139 */
140 public boolean hasBeenSet() {
141 return userChoice != null || magicValue != null;
142 }
143}
Note: See TracBrowser for help on using the repository browser.