1 | /*
|
---|
2 | * Copyright 2004 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 |
|
---|
18 | package org.apache.tools.ant.util;
|
---|
19 |
|
---|
20 | import java.util.List;
|
---|
21 | import java.util.Iterator;
|
---|
22 | import java.util.ArrayList;
|
---|
23 | import java.util.Collections;
|
---|
24 | import org.apache.tools.ant.types.Mapper;
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * A <code>FileNameMapper</code> that contains
|
---|
28 | * other <CODE>FileNameMapper</CODE>s.
|
---|
29 | * @see FileNameMapper
|
---|
30 | */
|
---|
31 | public abstract class ContainerMapper implements FileNameMapper {
|
---|
32 |
|
---|
33 | private List mappers = new ArrayList();
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Add a <code>Mapper</code>.
|
---|
37 | * @param mapper the <code>Mapper</code> to add.
|
---|
38 | */
|
---|
39 | public void addConfiguredMapper(Mapper mapper) {
|
---|
40 | add(mapper.getImplementation());
|
---|
41 | }
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * Add a <code>FileNameMapper</code>.
|
---|
45 | * @param fileNameMapper a <CODE>FileNameMapper</CODE>.
|
---|
46 | * @throws <CODE>IllegalArgumentException</CODE> if attempting to add this
|
---|
47 | * <CODE>ContainerMapper</CODE> to itself, or if the specified
|
---|
48 | * <CODE>FileNameMapper</CODE> is itself a <CODE>ContainerMapper</CODE>
|
---|
49 | * that contains this <CODE>ContainerMapper</CODE>.
|
---|
50 | */
|
---|
51 | public synchronized void add(FileNameMapper fileNameMapper) {
|
---|
52 | if (this == fileNameMapper
|
---|
53 | || (fileNameMapper instanceof ContainerMapper
|
---|
54 | && ((ContainerMapper)fileNameMapper).contains(this))) {
|
---|
55 | throw new IllegalArgumentException(
|
---|
56 | "Circular mapper containment condition detected");
|
---|
57 | } else {
|
---|
58 | mappers.add(fileNameMapper);
|
---|
59 | }
|
---|
60 | }
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * Return <CODE>true</CODE> if this <CODE>ContainerMapper</CODE> or any of
|
---|
64 | * its sub-elements contains the specified <CODE>FileNameMapper</CODE>.
|
---|
65 | * @param fileNameMapper the <CODE>FileNameMapper</CODE> to search for.
|
---|
66 | * @return <CODE>boolean</CODE>.
|
---|
67 | */
|
---|
68 | protected synchronized boolean contains(FileNameMapper fileNameMapper) {
|
---|
69 | boolean foundit = false;
|
---|
70 | for (Iterator iter = mappers.iterator(); iter.hasNext() && !foundit;) {
|
---|
71 | FileNameMapper next = (FileNameMapper)(iter.next());
|
---|
72 | foundit|= (next == fileNameMapper
|
---|
73 | || (next instanceof ContainerMapper
|
---|
74 | && ((ContainerMapper)next).contains(fileNameMapper)));
|
---|
75 | }
|
---|
76 | return foundit;
|
---|
77 | }
|
---|
78 |
|
---|
79 | /**
|
---|
80 | * Get the <CODE>List</CODE> of <CODE>FileNameMapper</CODE>s.
|
---|
81 | * @return <CODE>List</CODE>.
|
---|
82 | */
|
---|
83 | public synchronized List getMappers() {
|
---|
84 | return Collections.unmodifiableList(mappers);
|
---|
85 | }
|
---|
86 |
|
---|
87 | /**
|
---|
88 | * Empty implementation.
|
---|
89 | */
|
---|
90 | public void setFrom(String ignore) {
|
---|
91 | }
|
---|
92 |
|
---|
93 | /**
|
---|
94 | * Empty implementation.
|
---|
95 | */
|
---|
96 | public void setTo(String ignore) {
|
---|
97 | }
|
---|
98 |
|
---|
99 | }
|
---|
100 |
|
---|