KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > types > resources > selectors > ResourceSelectorContainer


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */

18 package org.apache.tools.ant.types.resources.selectors;
19
20 import java.util.Stack JavaDoc;
21 import java.util.Vector JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import java.util.Collections JavaDoc;
24
25 import org.apache.tools.ant.Project;
26 import org.apache.tools.ant.BuildException;
27 import org.apache.tools.ant.types.DataType;
28
29 /**
30  * ResourceSelector container.
31  * @since Ant 1.7
32  */

33 public class ResourceSelectorContainer extends DataType {
34
35     private Vector JavaDoc v = new Vector JavaDoc();
36
37     /**
38      * Default constructor.
39      */

40     public ResourceSelectorContainer() {
41     }
42
43     /**
44      * Construct a new ResourceSelectorContainer with the specified array of selectors.
45      * @param r the ResourceSelector[] to add.
46      */

47     public ResourceSelectorContainer(ResourceSelector[] r) {
48         for (int i = 0; i < r.length; i++) {
49             add(r[i]);
50         }
51     }
52
53     /**
54      * Add a ResourceSelector to the container.
55      * @param s the ResourceSelector to add.
56      */

57     public void add(ResourceSelector s) {
58         if (isReference()) {
59             throw noChildrenAllowed();
60         }
61         if (s == null) {
62             return;
63         }
64         v.add(s);
65         setChecked(false);
66     }
67
68     /**
69      * Learn whether this ResourceSelectorContainer has selectors.
70      * @return boolean indicating whether selectors have been added to the container.
71      */

72     public boolean hasSelectors() {
73         if (isReference()) {
74             return ((ResourceSelectorContainer) getCheckedRef()).hasSelectors();
75         }
76         dieOnCircularReference();
77         return !v.isEmpty();
78     }
79
80     /**
81      * Get the count of nested selectors.
82      * @return the selector count as int.
83      */

84     public int selectorCount() {
85         if (isReference()) {
86             return ((ResourceSelectorContainer) getCheckedRef()).selectorCount();
87         }
88         dieOnCircularReference();
89         return v.size();
90     }
91
92     /**
93      * Return an Iterator over the nested selectors.
94      * @return Iterator of ResourceSelectors.
95      */

96     public Iterator JavaDoc getSelectors() {
97         if (isReference()) {
98             return ((ResourceSelectorContainer) getCheckedRef()).getSelectors();
99         }
100         dieOnCircularReference();
101         return Collections.unmodifiableList(v).iterator();
102     }
103
104     /**
105      * Overrides the version from DataType to recurse on nested ResourceSelectors.
106      * @param stk the Stack of references.
107      * @param p the Project to resolve against.
108      * @throws BuildException on error.
109      */

110     protected void dieOnCircularReference(Stack JavaDoc stk, Project p)
111         throws BuildException {
112         if (isChecked()) {
113             return;
114         }
115         if (isReference()) {
116             super.dieOnCircularReference(stk, p);
117         } else {
118             for (Iterator JavaDoc i = v.iterator(); i.hasNext();) {
119                 Object JavaDoc o = i.next();
120                 if (o instanceof DataType) {
121                     stk.push(o);
122                     invokeCircularReferenceCheck((DataType) o, stk, p);
123                 }
124             }
125             setChecked(true);
126         }
127     }
128
129 }
130
Popular Tags