Package: ResourceBundleELResolver
ResourceBundleELResolver
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ResourceBundleELResolver() |
|
|
|
|
|
||||||||||||||||||||
getCommonPropertyType(ELContext, Object) |
|
|
|
|
|
||||||||||||||||||||
getType(ELContext, Object, Object) |
|
|
|
|
|
||||||||||||||||||||
getValue(ELContext, Object, Object) |
|
|
|
|
|
||||||||||||||||||||
isReadOnly(ELContext, Object, Object) |
|
|
|
|
|
||||||||||||||||||||
setValue(ELContext, Object, Object, Object) |
|
|
|
|
|
Coverage
1: /*
2: * Copyright (c) 1997, 2022 Oracle and/or its affiliates and others.
3: * All rights reserved.
4: * Copyright 2004 The Apache Software Foundation
5: *
6: * Licensed under the Apache License, Version 2.0 (the "License");
7: * you may not use this file except in compliance with the License.
8: * 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, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: package jakarta.el;
20:
21: import java.util.MissingResourceException;
22: import java.util.ResourceBundle;
23:
24: /**
25: * Defines property resolution behavior on instances of {@link java.util.ResourceBundle}.
26: *
27: * <p>
28: * This resolver handles base objects of type <code>java.util.ResourceBundle</code>. It accepts any object as a property
29: * and coerces it to a <code>java.lang.String</code> for invoking
30: * {@link java.util.ResourceBundle#getObject(java.lang.String)}.
31: *
32: * <p>
33: * This resolver is read only and will throw a {@link PropertyNotWritableException} if <code>setValue</code> is called.
34: *
35: * <p>
36: * <code>ELResolver</code>s are combined together using {@link CompositeELResolver}s, to define rich semantics for
37: * evaluating an expression. See the javadocs for {@link ELResolver} for details.
38: *
39: * @see CompositeELResolver
40: * @see ELResolver
41: * @see java.util.ResourceBundle
42: *
43: * @since Jakarta Server Pages 2.1
44: */
45: public class ResourceBundleELResolver extends ELResolver {
46:
47: /**
48: * If the base object is an instance of <code>ResourceBundle</code>, the provided property will first be coerced to a
49: * <code>String</code>. The <code>Object</code> returned by <code>getObject</code> on the base
50: * <code>ResourceBundle</code> will be returned.
51: *
52: * <p>
53: * If the base is <code>ResourceBundle</code>, the <code>propertyResolved</code> property of the <code>ELContext</code>
54: * object must be set to <code>true</code> by this resolver, before returning. If this property is not <code>true</code>
55: * after this method is called, the caller should ignore the return value.
56: *
57: * @param context The context of this evaluation.
58: * @param base The ResourceBundle to analyze.
59: * @param property The name of the property to analyze. Will be coerced to a <code>String</code>.
60: * @return If the <code>propertyResolved</code> property of <code>ELContext</code> was set to <code>true</code>, then
61: * <code>null</code> if property is <code>null</code> otherwise the <code>Object</code> for the given key (property
62: * coerced to <code>String</code>) from the <code>ResourceBundle</code>. If no object for the given key can be found,
63: * then the <code>String</code> "???" + key + "???".
64: * @throws NullPointerException if context is <code>null</code>
65: * @throws ELException if an exception was thrown while performing the property or variable resolution. The thrown
66: * exception must be included as the cause property of this exception, if available.
67: */
68: @Override
69: public Object getValue(ELContext context, Object base, Object property) {
70:• if (context == null) {
71: throw new NullPointerException();
72: }
73:
74:• if (base instanceof ResourceBundle) {
75: context.setPropertyResolved(true);
76:• if (property != null) {
77: try {
78: return ((ResourceBundle) base).getObject(property.toString());
79: } catch (MissingResourceException e) {
80: return "???" + property + "???";
81: }
82: }
83: }
84:
85: return null;
86: }
87:
88: /**
89: * If the base object is an instance of <code>ResourceBundle</code>, return <code>null</code>, since the resolver is
90: * read only.
91: *
92: * <p>
93: * If the base is <code>ResourceBundle</code>, the <code>propertyResolved</code> property of the <code>ELContext</code>
94: * object must be set to <code>true</code> by this resolver, before returning. If this property is not <code>true</code>
95: * after this method is called, the caller should ignore the return value.
96: * </p>
97: *
98: * @param context The context of this evaluation.
99: * @param base The ResourceBundle to analyze.
100: * @param property The name of the property to analyze.
101: * @return If the <code>propertyResolved</code> property of <code>ELContext</code> was set to <code>true</code>, then
102: * <code>null</code> otherwise undefined.
103: * @throws NullPointerException if context is <code>null</code>
104: */
105: @Override
106: public Class<?> getType(ELContext context, Object base, Object property) {
107:• if (context == null) {
108: throw new NullPointerException();
109: }
110:
111:• if (base instanceof ResourceBundle) {
112: context.setPropertyResolved(true);
113: /*
114: * ResourceBundles are always read-only so fall-through to return
115: * null
116: */
117: }
118:
119: return null;
120: }
121:
122: /**
123: * If the base object is a ResourceBundle, throw a {@link PropertyNotWritableException}.
124: *
125: * @param context The context of this evaluation.
126: * @param base The ResourceBundle to be modified. Only bases that are of type ResourceBundle are handled.
127: * @param property The String property to use.
128: * @param value The value to be set.
129: * @throws NullPointerException if context is <code>null</code>.
130: * @throws PropertyNotWritableException Always thrown if base is an instance of ReasourceBundle.
131: */
132: @Override
133: public void setValue(ELContext context, Object base, Object property, Object value) {
134:• if (context == null) {
135: throw new NullPointerException();
136: }
137:
138:• if (base instanceof ResourceBundle) {
139: context.setPropertyResolved(true);
140: throw new PropertyNotWritableException("ResourceBundles are immutable");
141: }
142: }
143:
144: /**
145: * If the base object is not null and an <code>instanceof</code> {@link ResourceBundle}, return <code>true</code>.
146: *
147: * @param context The context of this evaluation.
148: * @param base The ResourceBundle to be modified. Only bases that are of type ResourceBundle are handled.
149: * @param property The String property to use.
150: * @return If the <code>propertyResolved</code> property of <code>ELContext</code> was set to <code>true</code>, then
151: * <code>true</code> otherwise undefined.
152: * @throws NullPointerException if context is <code>null</code>
153: */
154: @Override
155: public boolean isReadOnly(ELContext context, Object base, Object property) {
156:• if (context == null) {
157: throw new NullPointerException();
158: }
159:
160:• if (base instanceof ResourceBundle) {
161: context.setPropertyResolved(true);
162: return true;
163: }
164:
165: return false;
166: }
167:
168: /**
169: * If the base object is a ResourceBundle, returns the most general type that this resolver accepts for the
170: * <code>property</code> argument. Otherwise, returns <code>null</code>.
171: *
172: * <p>
173: * Assuming the base is a <code>ResourceBundle</code>, this method will always return <code>String.class</code>.
174: *
175: * @param context The context of this evaluation.
176: * @param base The bundle to analyze. Only bases of type <code>ResourceBundle</code> are handled by this resolver.
177: * @return <code>null</code> if base is not a <code>ResourceBundle</code> otherwise <code>String.class</code>.
178: */
179: @Override
180: public Class<?> getCommonPropertyType(ELContext context, Object base) {
181:• if (base instanceof ResourceBundle) {
182: return String.class;
183: }
184:
185: return null;
186: }
187: }