01: /*
02: * Copyright 2006 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.apache.myfaces.el.unified.resolver.implicitobject;
18:
19: import java.beans.FeatureDescriptor;
20: import javax.el.ELContext;
21: import javax.el.ELResolver;
22: import javax.faces.context.ExternalContext;
23: import javax.faces.context.FacesContext;
24:
25: /**
26: * Implementors of this class encapsulate the information needed to resolve
27: * the implicit object.
28: *
29: * @author Stan Silvert
30: */
31: public abstract class ImplicitObject {
32:
33: public abstract Object getValue(ELContext context);
34:
35: public abstract FeatureDescriptor getDescriptor();
36:
37: /**
38: * Returns an interned String representing the name of the
39: * implicit object.
40: */
41: public abstract String getName();
42:
43: /**
44: * Returns the most general type allowed for a future call to setValue()
45: */
46: public abstract Class getType();
47:
48: protected FeatureDescriptor makeDescriptor(String name,
49: String description, Class elResolverType) {
50: FeatureDescriptor fd = new FeatureDescriptor();
51: fd.setValue(ELResolver.RESOLVABLE_AT_DESIGN_TIME, Boolean.TRUE);
52: fd.setValue(ELResolver.TYPE, elResolverType);
53: fd.setName(name);
54: fd.setDisplayName(name);
55: fd.setShortDescription(description);
56: fd.setExpert(false);
57: fd.setHidden(false);
58: fd.setPreferred(true);
59: return fd;
60: }
61:
62: // get the FacesContext from the ELContext
63: protected FacesContext facesContext(ELContext context) {
64: return (FacesContext) context.getContext(FacesContext.class);
65: }
66:
67: protected ExternalContext externalContext(ELContext context) {
68: return facesContext(context).getExternalContext();
69: }
70:
71: }
|