KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > util > ContainerMapper


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
19 package org.apache.tools.ant.util;
20
21 import java.util.List JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.Collections JavaDoc;
25 import org.apache.tools.ant.types.Mapper;
26
27 /**
28  * A <code>FileNameMapper</code> that contains
29  * other <code>FileNameMapper</code>s.
30  * @see FileNameMapper
31  */

32 public abstract class ContainerMapper implements FileNameMapper {
33
34     private List JavaDoc mappers = new ArrayList JavaDoc();
35
36     /**
37      * Add a <code>Mapper</code>.
38      * @param mapper the <code>Mapper</code> to add.
39      */

40     public void addConfiguredMapper(Mapper mapper) {
41         add(mapper.getImplementation());
42     }
43
44     /**
45      * An add configured version of the add method.
46      * This class used to contain an add method and an
47      * addConfiguredMapper method. Dur to ordering,
48      * the add method was always called first. This
49      * addConfigued method has been added to allow
50      * chaining to work correctly.
51      * @param fileNameMapper a <code>FileNameMapper</code>.
52      */

53     public void addConfigured(FileNameMapper fileNameMapper) {
54         add(fileNameMapper);
55     }
56
57     /**
58      * Add a <code>FileNameMapper</code>.
59      * @param fileNameMapper a <code>FileNameMapper</code>.
60      * @throws IllegalArgumentException if attempting to add this
61      * <code>ContainerMapper</code> to itself, or if the specified
62      * <code>FileNameMapper</code> is itself a <code>ContainerMapper</code>
63      * that contains this <code>ContainerMapper</code>.
64      */

65     public synchronized void add(FileNameMapper fileNameMapper) {
66         if (this == fileNameMapper
67             || (fileNameMapper instanceof ContainerMapper
68             && ((ContainerMapper) fileNameMapper).contains(this))) {
69             throw new IllegalArgumentException JavaDoc(
70                 "Circular mapper containment condition detected");
71         } else {
72             mappers.add(fileNameMapper);
73         }
74     }
75
76     /**
77      * Return <code>true</code> if this <code>ContainerMapper</code> or any of
78      * its sub-elements contains the specified <code>FileNameMapper</code>.
79      * @param fileNameMapper the <code>FileNameMapper</code> to search for.
80      * @return <code>boolean</code>.
81      */

82     protected synchronized boolean contains(FileNameMapper fileNameMapper) {
83         boolean foundit = false;
84         for (Iterator JavaDoc iter = mappers.iterator(); iter.hasNext() && !foundit;) {
85             FileNameMapper next = (FileNameMapper) (iter.next());
86             foundit |= (next == fileNameMapper
87                 || (next instanceof ContainerMapper
88                 && ((ContainerMapper) next).contains(fileNameMapper)));
89         }
90         return foundit;
91     }
92
93     /**
94      * Get the <code>List</code> of <code>FileNameMapper</code>s.
95      * @return <code>List</code>.
96      */

97     public synchronized List JavaDoc getMappers() {
98         return Collections.unmodifiableList(mappers);
99     }
100
101     /**
102      * Empty implementation.
103      * @param ignore ignored.
104      */

105     public void setFrom(String JavaDoc ignore) {
106         //Empty
107
}
108
109     /**
110      * Empty implementation.
111      * @param ignore ignored.
112      */

113     public void setTo(String JavaDoc ignore) {
114         //Empty
115
}
116
117 }
118
119
Popular Tags