View Javadoc

1   package net.sourceforge.pmd.lang.vm.directive;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.    
20   */
21  
22  /**
23   * Base class for all directives used in Velocity.
24   *
25   * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
26   * @author Nathan Bubna
27   * @version $Id: Directive.java 778045 2009-05-23 22:17:46Z nbubna $
28   */
29  public abstract class Directive implements DirectiveConstants, Cloneable
30  {
31      private int line = 0;
32      private int column = 0;
33      private boolean provideScope = false;
34      private String templateName;
35  
36      /**
37       * Return the name of this directive.
38       * @return The name of this directive.
39       */
40      public abstract String getName();
41  
42      /**
43       * Get the directive type BLOCK/LINE.
44       * @return The directive type BLOCK/LINE.
45       */
46      public abstract int getType();
47  
48      /**
49       * Allows the template location to be set.
50       * @param line
51       * @param column
52       */
53      public void setLocation( int line, int column )
54      {
55          this.line = line;
56          this.column = column;
57      }
58  
59      /**
60       * Allows the template location to be set.
61       * @param line
62       * @param column
63       */
64      public void setLocation(int line, int column, String templateName)
65      {
66          setLocation(line, column);
67          this.templateName = templateName;
68      }
69  
70      /**
71       * for log msg purposes
72       * @return The current line for log msg purposes.
73       */
74      public int getLine()
75      {
76          return line;
77      }
78  
79      /**
80       * for log msg purposes
81       * @return The current column for log msg purposes.
82       */
83      public int getColumn()
84      {
85          return column;
86      }
87      
88      /**
89       * @return The template file name this directive was defined in, or null if not 
90       * defined in a file.
91       */
92      public String getTemplateName()
93      {
94        return templateName;
95      }
96  
97      /**
98       * @returns the name to be used when a scope control is provided for this
99       * directive.
100      */
101     public String getScopeName()
102     {
103         return getName();
104     }
105 
106     /**
107      * @return true if there will be a scope control injected into the context
108      * when rendering this directive.
109      */
110     public boolean isScopeProvided()
111     {
112         return provideScope;
113     }
114 
115 }