1:
17: package ;
18:
19: import ;
20: import ;
21: import ;
22: import ;
23: import ;
24: import ;
25:
26: import ;
27: import ;
28:
29:
42: public class DefaultingCommandLine extends CommandLineImpl
43: {
44:
47: private final List m_commandLines = new ArrayList();
48:
49:
56: public void appendCommandLine( final CommandLine commandLine )
57: {
58: m_commandLines.add( commandLine );
59: }
60:
61:
67: public void insertCommandLine(
68: final int index,
69: final CommandLine commandLine )
70: {
71: m_commandLines.add( index, commandLine );
72: }
73:
74:
79: public Iterator commandLines()
80: {
81: return Collections.unmodifiableList( m_commandLines ).iterator();
82: }
83:
84:
90: public Option getOption( String trigger )
91: {
92: for( final Iterator i = m_commandLines.iterator(); i.hasNext();)
93: {
94: final CommandLine commandLine = (CommandLine) i.next();
95: final Option actual = commandLine.getOption( trigger );
96: if( actual != null )
97: {
98: return actual;
99: }
100: }
101: return null;
102: }
103:
104:
109: public List getOptions()
110: {
111: final List options = new ArrayList();
112: final List temp = new ArrayList();
113: for( final Iterator i = m_commandLines.iterator(); i.hasNext();)
114: {
115: final CommandLine commandLine = (CommandLine) i.next();
116: temp.clear();
117: temp.addAll( commandLine.getOptions() );
118: temp.removeAll( options );
119: options.addAll( temp );
120: }
121: return Collections.unmodifiableList( options );
122: }
123:
124:
129: public Set getOptionTriggers()
130: {
131: final Set all = new HashSet();
132: for( final Iterator i = m_commandLines.iterator(); i.hasNext();)
133: {
134: final CommandLine commandLine = (CommandLine) i.next();
135: all.addAll( commandLine.getOptionTriggers() );
136: }
137: return Collections.unmodifiableSet( all );
138: }
139:
140:
146: public boolean hasOption( Option option )
147: {
148: for( final Iterator i = m_commandLines.iterator(); i.hasNext();)
149: {
150: final CommandLine commandLine = (CommandLine) i.next();
151: if( commandLine.hasOption( option ) )
152: {
153: return true;
154: }
155: }
156: return false;
157: }
158:
159:
166: public List getValues( Option option, List defaultValues )
167: {
168: for( final Iterator i = m_commandLines.iterator(); i.hasNext();)
169: {
170: final CommandLine commandLine = (CommandLine) i.next();
171: final List actual = commandLine.getValues( option );
172: if( actual != null && !actual.isEmpty() )
173: {
174: return actual;
175: }
176: }
177: if( defaultValues == null )
178: {
179: return Collections.EMPTY_LIST;
180: }
181: else
182: {
183: return defaultValues;
184: }
185: }
186:
187:
194: public Boolean getSwitch( Option option, Boolean defaultValue )
195: {
196: for( final Iterator i = m_commandLines.iterator(); i.hasNext();)
197: {
198: final CommandLine commandLine = (CommandLine) i.next();
199: final Boolean actual = commandLine.getSwitch( option );
200: if( actual != null )
201: {
202: return actual;
203: }
204: }
205: return defaultValue;
206: }
207:
208:
215: public String getProperty( String property, String defaultValue )
216: {
217: for( final Iterator i = m_commandLines.iterator(); i.hasNext();)
218: {
219: final CommandLine commandLine = (CommandLine) i.next();
220: final String actual = commandLine.getProperty( property );
221: if( actual != null )
222: {
223: return actual;
224: }
225: }
226: return defaultValue;
227: }
228:
229:
234: public Set getProperties()
235: {
236: final Set all = new HashSet();
237: for( final Iterator i = m_commandLines.iterator(); i.hasNext();)
238: {
239: final CommandLine commandLine = (CommandLine) i.next();
240: all.addAll( commandLine.getProperties() );
241: }
242: return Collections.unmodifiableSet( all );
243: }
244: }