View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package javax.faces.view.facelets;
20  
21  import javax.el.MethodExpression;
22  import javax.el.ValueExpression;
23  import javax.faces.view.Location;
24  
25  /**
26   * Representation of a Tag's attribute in a Facelet File
27   */
28  public abstract class TagAttribute
29  {
30      public TagAttribute()
31      {
32          
33      }
34  
35      /**
36       * If literal, return {@link Boolean#getBoolean(java.lang.String) Boolean.getBoolean(java.lang.String)} passing our
37       * value, otherwise call {@link #getObject(FaceletContext, Class) getObject(FaceletContext, Class)}.
38       * 
39       * @see Boolean#getBoolean(java.lang.String)
40       * @see #getObject(FaceletContext, Class)
41       * @param ctx
42       *            FaceletContext to use
43       * @return boolean value
44       */
45      public abstract boolean getBoolean(FaceletContext ctx);
46  
47      /**
48       * If literal, call {@link Integer#parseInt(java.lang.String) Integer.parseInt(String)}, otherwise call
49       * {@link #getObject(FaceletContext, Class) getObject(FaceletContext, Class)}.
50       * 
51       * @see Integer#parseInt(java.lang.String)
52       * @see #getObject(FaceletContext, Class)
53       * @param ctx
54       *            FaceletContext to use
55       * @return int value
56       */
57      public abstract int getInt(FaceletContext ctx);
58  
59      /**
60       * Local name of this attribute
61       * 
62       * @return local name of this attribute
63       */
64      public abstract String getLocalName();
65  
66      /**
67       * The location of this attribute in the FaceletContext
68       * 
69       * @return the TagAttribute's location
70       */
71      public abstract Location getLocation();
72  
73      /**
74       * Create a MethodExpression, using this attribute's value as the expression String.
75       * 
76       * @see javax.el.ExpressionFactory#createMethodExpression(javax.el.ELContext, java.lang.String, java.lang.Class,
77       *      java.lang.Class[])
78       * @see MethodExpression
79       * @param ctx
80       *            FaceletContext to use
81       * @param type
82       *            expected return type
83       * @param paramTypes
84       *            parameter type
85       * @return a MethodExpression instance
86       */
87      public abstract MethodExpression getMethodExpression(FaceletContext ctx, Class type, Class[] paramTypes);
88  
89      /**
90       * The resolved Namespace for this attribute
91       * 
92       * @return resolved Namespace
93       */
94      public abstract String getNamespace();
95  
96      /**
97       * Delegates to getObject with Object.class as a param
98       * 
99       * @see #getObject(FaceletContext, Class)
100      * @param ctx
101      *            FaceletContext to use
102      * @return Object representation of this attribute's value
103      */
104     public abstract Object getObject(FaceletContext ctx);
105 
106     /**
107      * If literal, simply coerce our String literal value using an ExpressionFactory, otherwise create a ValueExpression
108      * and evaluate it.
109      * 
110      * @see javax.el.ExpressionFactory#coerceToType(java.lang.Object, java.lang.Class)
111      * @see javax.el.ExpressionFactory#createValueExpression(javax.el.ELContext, java.lang.String, java.lang.Class)
112      * @see ValueExpression
113      * @param ctx
114      *            FaceletContext to use
115      * @param type
116      *            expected return type
117      * @return Object value of this attribute
118      */
119     public abstract Object getObject(FaceletContext ctx, Class type);
120 
121     /**
122      * The qualified name for this attribute
123      * 
124      * @return the qualified name for this attribute
125      */
126     public abstract String getQName();
127 
128     /**
129      * Return the literal value of this attribute
130      * 
131      * @return literal value
132      */
133     public abstract String getValue();
134 
135     /**
136      * If literal, then return our value, otherwise delegate to getObject, passing String.class.
137      * 
138      * @see #getObject(FaceletContext, Class)
139      * @param ctx
140      *            FaceletContext to use
141      * @return String value of this attribute
142      */
143     public abstract String getValue(FaceletContext ctx);
144 
145     /**
146      * Create a ValueExpression, using this attribute's literal value and the passed expected type.
147      * 
148      * @see javax.el.ExpressionFactory#createValueExpression(javax.el.ELContext, java.lang.String, java.lang.Class)
149      * @see ValueExpression
150      * @param ctx
151      *            FaceletContext to use
152      * @param type
153      *            expected return type
154      * @return ValueExpression instance
155      */
156     public abstract ValueExpression getValueExpression(FaceletContext ctx, Class type);
157 
158     /**
159      * If this TagAttribute is literal (not #{..} or ${..})
160      * 
161      * @return true if this attribute is literal
162      */
163     public abstract boolean isLiteral();
164     
165     /**
166      * @since 2.2
167      * @return 
168      */
169     public Tag getTag()
170     {
171         return null;
172     }
173 
174     /**
175      * @since 2.2
176      * @param tag 
177      */
178     public void setTag(Tag tag)
179     {
180     }
181 }