KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > types > Substitution


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;
19
20
21 import org.apache.tools.ant.Project;
22
23 /***
24  * A regular expression substitution datatype. It is an expression
25  * that is meant to replace a regular expression.
26  *
27  * <pre>
28  * &lt;substitition [ [id="id"] expression="expression" | refid="id" ]
29  * /&gt;
30  * </pre>
31  *
32  * @see org.apache.oro.text.regex.Perl5Substitution
33  */

34 public class Substitution extends DataType {
35     /** The name of this data type */
36     public static final String JavaDoc DATA_TYPE_NAME = "substitition";
37
38     private String JavaDoc expression;
39
40     /** Constructor for Substitution. */
41     public Substitution() {
42         this.expression = null;
43     }
44
45     /**
46      * Set the pattern string for this regular expression substitution.
47      * @param expression the regular expression to use
48      */

49     public void setExpression(String JavaDoc expression) {
50         this.expression = expression;
51     }
52
53     /***
54      * Gets the pattern string for this RegularExpression in the
55      * given project.
56      * @param p the project to look for the regular expression if this object is
57      * a reference
58      * @return the pattern string
59      */

60     public String JavaDoc getExpression(Project p) {
61         if (isReference()) {
62             return getRef(p).getExpression(p);
63         }
64
65         return expression;
66     }
67
68     /***
69      * Get the RegularExpression this reference refers to in
70      * the given project. Check for circular references too.
71      * @param p the project to look for the regular expression reference
72      * @return the resolved reference
73      */

74     public Substitution getRef(Project p) {
75         return (Substitution) getCheckedRef(p);
76     }
77 }
78
Popular Tags