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 org.apache.myfaces.config.impl.digester.elements;
20  
21  import java.io.Serializable;
22  
23  import javax.faces.context.FacesContext;
24  import javax.faces.el.ValueBinding;
25  
26  import org.apache.myfaces.util.ContainerUtils;
27  
28  
29  /**
30   * @author <a href="mailto:oliver@rossmueller.com">Oliver Rossmueller</a> (latest modification by $Author$)
31   * @author Anton Koinov
32   *
33   * @version $Revision$ $Date$
34   */
35  public class ManagedPropertyImpl extends org.apache.myfaces.config.element.ManagedProperty implements Serializable
36  {
37      private static final ValueBinding DUMMY_VB = new DummyValueBinding();
38  
39      private int                       _type    = TYPE_UNKNOWN;
40      private String                    _propertyName;
41      private String                    _propertyClass;
42      private transient ValueBinding    _valueBinding;
43      private String                    _value;
44      private org.apache.myfaces.config.element.MapEntries                _mapEntries;
45      private org.apache.myfaces.config.element.ListEntries               _listEntries;
46  
47      public int getType()
48      {
49          return _type;
50      }
51      
52      public org.apache.myfaces.config.element.MapEntries getMapEntries()
53      {
54          return _mapEntries;
55      }
56      
57      public void setMapEntries(org.apache.myfaces.config.element.MapEntries mapEntries)
58      {
59          _mapEntries = mapEntries;
60          _type = TYPE_MAP;
61      }
62      
63      public org.apache.myfaces.config.element.ListEntries getListEntries()
64      {
65          return _listEntries;
66      }
67      
68      public void setListEntries(ListEntriesImpl listEntries)
69      {
70          _listEntries = listEntries;
71          _type = TYPE_LIST;
72      }
73      
74      public String getPropertyName()
75      {
76          return _propertyName;
77      }
78      
79      public void setPropertyName(String propertyName)
80      {
81          _propertyName = propertyName;
82      }
83      
84      public String getPropertyClass()
85      {
86          return _propertyClass;
87      }
88      
89      public void setPropertyClass(String propertyClass)
90      {
91          _propertyClass = propertyClass;
92      }
93      
94      public boolean isNullValue()
95      {
96          return _type == TYPE_NULL;
97      }
98      
99      public void setNullValue()
100     {
101         _type = TYPE_NULL;
102     }
103     
104     public void setValue(String value)
105     {
106         _value = value;
107         _type = TYPE_VALUE;
108     }
109 
110     public String getValue()
111     {
112         return _value;
113     }
114     
115     public Object getRuntimeValue(FacesContext facesContext)
116     {
117         getValueBinding(facesContext);
118 
119         return (_valueBinding == DUMMY_VB)
120             ? _value : _valueBinding.getValue(facesContext);
121     }
122     
123     public ValueBinding getValueBinding(FacesContext facesContext)
124     {
125         if (_valueBinding == null)
126         {
127             _valueBinding =
128                 isValueReference()
129                 ? facesContext.getApplication().createValueBinding(_value)
130                 : DUMMY_VB;
131         }
132         return _valueBinding;
133     }
134     
135     public boolean isValueReference()
136     {
137         return ContainerUtils.isValueReference(_value);
138     }
139     
140     private static class DummyValueBinding extends ValueBinding
141     {
142         @Override
143         public String getExpressionString()
144         {
145             throw new UnsupportedOperationException();
146         }
147 
148         @Override
149         public Class<?> getType(FacesContext facesContext)
150         {
151             throw new UnsupportedOperationException();
152         }
153 
154         @Override
155         public Object getValue(FacesContext facesContext)
156         {
157             throw new UnsupportedOperationException();
158         }
159 
160         @Override
161         public boolean isReadOnly(FacesContext facesContext)
162         {
163             throw new UnsupportedOperationException();
164         }
165 
166         @Override
167         public void setValue(FacesContext facesContext, Object value)
168         {
169             throw new UnsupportedOperationException();
170         }
171     }
172 }