KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > types > optional > ScriptMapper


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.optional;
19
20 import org.apache.tools.ant.util.FileNameMapper;
21
22 import java.util.ArrayList JavaDoc;
23
24 /**
25  * Script support at map time.
26  * @since Ant1.7
27  */

28 public class ScriptMapper extends AbstractScriptComponent implements FileNameMapper {
29
30
31     private ArrayList JavaDoc files;
32     static final String JavaDoc[] EMPTY_STRING_ARRAY = new String JavaDoc[0];
33
34
35     /**
36      * Sets the from part of the transformation rule.
37      *
38      * @param from a string.
39      */

40     public void setFrom(String JavaDoc from) {
41
42     }
43
44     /**
45      * Sets the to part of the transformation rule.
46      *
47      * @param to a string.
48      */

49     public void setTo(String JavaDoc to) {
50
51     }
52
53     /**
54      * Reset the list of files
55      */

56     public void clear() {
57         files = new ArrayList JavaDoc(1);
58     }
59
60     /**
61      * Add a mapped name
62      * @param mapping the value to use.
63      */

64     public void addMappedName(String JavaDoc mapping) {
65         files.add(mapping);
66     }
67
68     /**
69      * Returns an array containing the target filename(s) for the given source
70      * file.
71      * <p/>
72      * <p>if the given rule doesn't apply to the source file, implementation
73      * must return null. SourceFileScanner will then omit the source file in
74      * question.</p>
75      *
76      * @param sourceFileName the name of the source file relative to some given
77      * basedirectory.
78      * @return an array of strings if the rule applies to the source file, or
79      * null if it does not.
80      */

81
82     public String JavaDoc[] mapFileName(String JavaDoc sourceFileName) {
83         initScriptRunner();
84         getRunner().addBean("source", sourceFileName);
85         clear();
86         executeScript("ant_mapper");
87         if (files.size() == 0) {
88             return null;
89         } else {
90             return (String JavaDoc[]) files.toArray(EMPTY_STRING_ARRAY);
91         }
92     }
93 }
94
Popular Tags