Source Code Cross Referenced for ImplicitObjectELResolver.java in  » EJB-Server-GlassFish » servlet » javax » servlet » jsp » el » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » EJB Server GlassFish » servlet » javax.servlet.jsp.el 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003:         * 
0004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005:         * 
0006:         * Portions Copyright Apache Software Foundation.
0007:         * 
0008:         * The contents of this file are subject to the terms of either the GNU
0009:         * General Public License Version 2 only ("GPL") or the Common Development
0010:         * and Distribution License("CDDL") (collectively, the "License").  You
0011:         * may not use this file except in compliance with the License. You can obtain
0012:         * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
0013:         * or glassfish/bootstrap/legal/LICENSE.txt.  See the License for the specific
0014:         * language governing permissions and limitations under the License.
0015:         * 
0016:         * When distributing the software, include this License Header Notice in each
0017:         * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
0018:         * Sun designates this particular file as subject to the "Classpath" exception
0019:         * as provided by Sun in the GPL Version 2 section of the License file that
0020:         * accompanied this code.  If applicable, add the following below the License
0021:         * Header, with the fields enclosed by brackets [] replaced by your own
0022:         * identifying information: "Portions Copyrighted [year]
0023:         * [name of copyright owner]"
0024:         * 
0025:         * Contributor(s):
0026:         * 
0027:         * If you wish your version of this file to be governed by only the CDDL or
0028:         * only the GPL Version 2, indicate your decision by adding "[Contributor]
0029:         * elects to include this software in this distribution under the [CDDL or GPL
0030:         * Version 2] license."  If you don't indicate a single choice of license, a
0031:         * recipient has the option to distribute your version of this file under
0032:         * either the CDDL, the GPL Version 2 or to extend the choice of license to
0033:         * its licensees as provided above.  However, if you add GPL Version 2 code
0034:         * and therefore, elected the GPL Version 2 license, then the option applies
0035:         * only if the new code is made subject to such option by the copyright
0036:         * holder.
0037:         */
0038:
0039:        package javax.servlet.jsp.el;
0040:
0041:        import java.beans.FeatureDescriptor;
0042:        import java.util.Iterator;
0043:        import java.util.ArrayList;
0044:        import java.util.Collection;
0045:        import java.util.Enumeration;
0046:        import java.util.HashMap;
0047:        import java.util.List;
0048:        import java.util.Map;
0049:        import java.util.Set;
0050:
0051:        import javax.servlet.ServletContext;
0052:        import javax.servlet.http.Cookie;
0053:        import javax.servlet.http.HttpServletRequest;
0054:        import javax.servlet.jsp.PageContext;
0055:        import javax.servlet.jsp.JspContext;
0056:
0057:        import javax.el.PropertyNotWritableException;
0058:        import javax.el.ELContext;
0059:        import javax.el.ELResolver;
0060:
0061:        /**
0062:         * Defines variable resolution behavior for the EL implicit objects
0063:         * defined in the JSP specification.
0064:         * 
0065:         * <p>The following variables are resolved by this <code>ELResolver</code>,
0066:         * as per the JSP specification:
0067:         * <ul>
0068:         *   <li><code>pageContext</code> - the <code>PageContext</code> object.</li>
0069:         *   <li><code>pageScope</code> - a <code>Map</code> that maps page-scoped 
0070:         *       attribute names to their values.</li>
0071:         *   <li><code>requestScope</code> - a <code>Map</code> that maps 
0072:         *       request-scoped attribute names to their values.</li>
0073:         *   <li><code>sessionScope</code> - a <code>Map</code> that maps 
0074:         *       session-scoped attribute names to their values.</li>
0075:         *   <li><code>applicationScope</code> - a <code>Map</code> that maps 
0076:         *       application-scoped attribute names to their values.</li>
0077:         *   <li><code>param</code> - a <code>Map</code> that maps parameter 
0078:         *       names to a single String parameter value (obtained by calling 
0079:         *       <code>ServletRequest.getParameter(String name)).</li>
0080:         *   <li><code>paramValues</code> - a <code>Map</code> that maps parameter
0081:         *       names to a <code>String[]</code> of all values for that 
0082:         *       parameter (obtained by calling
0083:         *       <code>ServletRequest.getParameterValues(String name))</code>.</li>
0084:         *   <li><code>header</code> - a <code>Map</code> that maps header names 
0085:         *       to a single String header value (obtained by calling 
0086:         *       <code>HttpServletRequest.getHeader(String name))</code>.</li>
0087:         *   <li><code>headerValues</code> - a <code>Map</code> that maps header 
0088:         *       names to a <code>String[]</code> of all values for that header
0089:         *       (obtained by calling 
0090:         *       <code>HttpServletRequest.getHeaders(String))</code>.</li>
0091:         *   <li><code>cookie</code> - a <code>Map</code> that maps cookie names 
0092:         *       to a single <code>Cookie</code> object. Cookies are retrieved 
0093:         *       according to the semantics of 
0094:         *       <code>HttpServletRequest.getCookies()</code>. If the same name 
0095:         *       is shared by multiple cookies, an implementation must use the 
0096:         *       first one encountered in the array of <code>Cookie</code> objects
0097:         *       returned by the <code>getCookies()</code> method. However, users
0098:         *       of the cookie implicit object must be aware that the ordering 
0099:         *       of cookies is currently unspecified in the servlet 
0100:         *       specification.</li>
0101:         *   <li><code>initParam</code> - a <code>Map</code> that maps context
0102:         *       initialization parameter names to their String parameter 
0103:         *       value (obtained by calling 
0104:         *       <code>ServletContext.getInitParameter(String name))</code>.</li>
0105:         * </ul></p>
0106:         *
0107:         * @see javax.el.ELResolver
0108:         * @since JSP 2.1
0109:         */
0110:        public class ImplicitObjectELResolver extends ELResolver {
0111:
0112:            /**
0113:             * If the base object is <code>null</code>, and the property matches
0114:             * the name of a JSP implicit object, returns the implicit object.
0115:             *
0116:             * <p>The <code>propertyResolved</code> property of the 
0117:             * <code>ELContext</code> object must be set to <code>true</code> by 
0118:             * this resolver before returning if an implicit object is matched. If 
0119:             * this property is not <code>true</code> after this method is called,
0120:             * the caller should ignore the return value.</p>
0121:             *
0122:             * @param context The context of this evaluation.
0123:             * @param base Only <code>null</code> is handled by this resolver.
0124:             *     Other values will result in an immediate return.
0125:             * @param property The name of the implicit object to resolve.
0126:             * @return If the <code>propertyResolved</code> property of 
0127:             *     <code>ELContext</code> was set to <code>true</code>, then
0128:             *     the implicit object; otherwise undefined.
0129:             * @throws NullPointerException if context is <code>null</code>
0130:             * @throws ELException if an exception was thrown while performing
0131:             *     the property or variable resolution. The thrown exception
0132:             *     must be included as the cause property of this exception, if
0133:             *     available.
0134:             */
0135:            public Object getValue(ELContext context, Object base,
0136:                    Object property) {
0137:
0138:                if (context == null) {
0139:                    throw new NullPointerException();
0140:                }
0141:
0142:                if (base != null) {
0143:                    return null;
0144:                }
0145:
0146:                PageContext ctxt = (PageContext) context
0147:                        .getContext(JspContext.class);
0148:
0149:                if ("pageContext".equals(property)) {
0150:                    context.setPropertyResolved(true);
0151:                    return ctxt;
0152:                }
0153:                ImplicitObjects implicitObjects = ImplicitObjects
0154:                        .getImplicitObjects(ctxt);
0155:                if ("pageScope".equals(property)) {
0156:                    context.setPropertyResolved(true);
0157:                    return implicitObjects.getPageScopeMap();
0158:                }
0159:                if ("requestScope".equals(property)) {
0160:                    context.setPropertyResolved(true);
0161:                    return implicitObjects.getRequestScopeMap();
0162:                }
0163:                if ("sessionScope".equals(property)) {
0164:                    context.setPropertyResolved(true);
0165:                    return implicitObjects.getSessionScopeMap();
0166:                }
0167:                if ("applicationScope".equals(property)) {
0168:                    context.setPropertyResolved(true);
0169:                    return implicitObjects.getApplicationScopeMap();
0170:                }
0171:                if ("param".equals(property)) {
0172:                    context.setPropertyResolved(true);
0173:                    return implicitObjects.getParamMap();
0174:                }
0175:                if ("paramValues".equals(property)) {
0176:                    context.setPropertyResolved(true);
0177:                    return implicitObjects.getParamsMap();
0178:                }
0179:                if ("header".equals(property)) {
0180:                    context.setPropertyResolved(true);
0181:                    return implicitObjects.getHeaderMap();
0182:                }
0183:                if ("headerValues".equals(property)) {
0184:                    context.setPropertyResolved(true);
0185:                    return implicitObjects.getHeadersMap();
0186:                }
0187:                if ("initParam".equals(property)) {
0188:                    context.setPropertyResolved(true);
0189:                    return implicitObjects.getInitParamMap();
0190:                }
0191:                if ("cookie".equals(property)) {
0192:                    context.setPropertyResolved(true);
0193:                    return implicitObjects.getCookieMap();
0194:                }
0195:                return null;
0196:            }
0197:
0198:            /**
0199:             * If the base object is <code>null</code>, and the property matches
0200:             * the name of a JSP implicit object, returns <code>null</code> to
0201:             * indicate that no types are ever accepted to <code>setValue()</code>.
0202:             *
0203:             * <p>The <code>propertyResolved</code> property of the 
0204:             * <code>ELContext</code> object must be set to <code>true</code> by 
0205:             * this resolver before returning if an implicit object is matched. If 
0206:             * this property is not <code>true</code> after this method is called,
0207:             * the caller should ignore the return value.</p>
0208:             *
0209:             * @param context The context of this evaluation.
0210:             * @param base Only <code>null</code> is handled by this resolver.
0211:             *     Other values will result in an immediate return.
0212:             * @param property The name of the implicit object to resolve.
0213:             * @return If the <code>propertyResolved</code> property of 
0214:             *     <code>ELContext</code> was set to <code>true</code>, then
0215:             *     <code>null</code>; otherwise undefined.
0216:             * @throws NullPointerException if context is <code>null</code>
0217:             * @throws ELException if an exception was thrown while performing
0218:             *     the property or variable resolution. The thrown exception
0219:             *     must be included as the cause property of this exception, if
0220:             *     available.
0221:             */
0222:            public Class getType(ELContext context, Object base, Object property) {
0223:
0224:                if (context == null) {
0225:                    throw new NullPointerException();
0226:                }
0227:
0228:                if ((base == null)
0229:                        && ("pageContext".equals(property) || "pageScope"
0230:                                .equals(property))
0231:                        || "requestScope".equals(property)
0232:                        || "sessionScope".equals(property)
0233:                        || "applicationScope".equals(property)
0234:                        || "param".equals(property)
0235:                        || "paramValues".equals(property)
0236:                        || "header".equals(property)
0237:                        || "headerValues".equals(property)
0238:                        || "initParam".equals(property)
0239:                        || "cookie".equals(property)) {
0240:                    context.setPropertyResolved(true);
0241:                }
0242:                return null;
0243:            }
0244:
0245:            /**
0246:             * If the base object is <code>null</code>, and the property matches
0247:             * the name of a JSP implicit object, throws
0248:             * <code>PropertyNotWritableException</code> to indicate that implicit
0249:             * objects cannot be overwritten.
0250:             *
0251:             * <p>The <code>propertyResolved</code> property of the 
0252:             * <code>ELContext</code> object must be set to <code>true</code> by 
0253:             * this resolver before returning if an implicit object is matched. If 
0254:             * this property is not <code>true</code> after this method is called,
0255:             * the caller should ignore the return value.</p>
0256:             *
0257:             * @param context The context of this evaluation.
0258:             * @param base Only <code>null</code> is handled by this resolver.
0259:             *     Other values will result in an immediate return.
0260:             * @param property The name of the implicit object.
0261:             * @param val The value to be associated with the implicit object.
0262:             * @throws NullPointerException if context is <code>null</code>.
0263:             * @throws PropertyNotWritableException always thrown, if the 
0264:             *     implicit object name is recognized by this resolver.
0265:             * @throws ELException if an exception was thrown while performing
0266:             *     the property or variable resolution. The thrown exception
0267:             *     must be included as the cause property of this exception, if
0268:             *     available.
0269:             */
0270:            public void setValue(ELContext context, Object base,
0271:                    Object property, Object val) {
0272:
0273:                if (context == null) {
0274:                    throw new NullPointerException();
0275:                }
0276:
0277:                if ((base == null)
0278:                        && ("pageContext".equals(property) || "pageScope"
0279:                                .equals(property))
0280:                        || "requestScope".equals(property)
0281:                        || "sessionScope".equals(property)
0282:                        || "applicationScope".equals(property)
0283:                        || "param".equals(property)
0284:                        || "paramValues".equals(property)
0285:                        || "header".equals(property)
0286:                        || "headerValues".equals(property)
0287:                        || "initParam".equals(property)
0288:                        || "cookie".equals(property)) {
0289:                    throw new PropertyNotWritableException();
0290:                }
0291:            }
0292:
0293:            /**
0294:             * If the base object is <code>null</code>, and the property matches
0295:             * the name of a JSP implicit object, returns <code>true</code>
0296:             * to indicate that implicit objects cannot be overwritten.
0297:             *
0298:             * <p>The <code>propertyResolved</code> property of the 
0299:             * <code>ELContext</code> object must be set to <code>true</code> by 
0300:             * this resolver before returning if an implicit object is matched. If 
0301:             * this property is not <code>true</code> after this method is called,
0302:             * the caller should ignore the return value.</p>
0303:             *
0304:             * @param context The context of this evaluation.
0305:             * @param base Only <code>null</code> is handled by this resolver.
0306:             *     Other values will result in an immediate return.
0307:             * @param property The name of the implicit object.
0308:             * @return If the <code>propertyResolved</code> property of 
0309:             *     <code>ELContext</code> was set to <code>true</code>, then
0310:             *     <code>true</code>; otherwise undefined.
0311:             * @throws NullPointerException if context is <code>null</code>.
0312:             * @throws ELException if an exception was thrown while performing
0313:             *     the property or variable resolution. The thrown exception
0314:             *     must be included as the cause property of this exception, if
0315:             *     available.
0316:             */
0317:            public boolean isReadOnly(ELContext context, Object base,
0318:                    Object property) {
0319:                if (context == null) {
0320:                    throw new NullPointerException();
0321:                }
0322:
0323:                if ((base == null)
0324:                        && ("pageContext".equals(property) || "pageScope"
0325:                                .equals(property))
0326:                        || "requestScope".equals(property)
0327:                        || "sessionScope".equals(property)
0328:                        || "applicationScope".equals(property)
0329:                        || "param".equals(property)
0330:                        || "paramValues".equals(property)
0331:                        || "header".equals(property)
0332:                        || "headerValues".equals(property)
0333:                        || "initParam".equals(property)
0334:                        || "cookie".equals(property)) {
0335:                    context.setPropertyResolved(true);
0336:                    return true;
0337:                }
0338:                return false; // Doesn't matter
0339:            }
0340:
0341:            /**
0342:             * If the base object is <code>null</code>, and the property matches
0343:             * the name of a JSP implicit object, returns an <code>Iterator</code>
0344:             * containing <code>FeatureDescriptor</code> objects with information
0345:             * about each JSP implicit object resolved by this resolver. Otherwise,
0346:             * returns <code>null</code>.
0347:             *
0348:             * <p>The <code>Iterator</code> returned must contain one instance of 
0349:             * {@link java.beans.FeatureDescriptor} for each of the EL implicit objects
0350:             * defined by the JSP spec. Each info object contains information about 
0351:             * a single implicit object, and is initialized as follows:
0352:             * <dl>
0353:             *     <li>displayName - The name of the implicit object.</li>
0354:             *     <li>name - Same as displayName property.</li>
0355:             *     <li>shortDescription - A suitable description for the implicit
0356:             *         object. Will vary by implementation.</li>
0357:             *     <li>expert - <code>false</code></li>
0358:             *     <li>hidden - <code>false</code></li>
0359:             *     <li>preferred - <code>true</code></li>
0360:             * </dl>
0361:             * In addition, the following named attributes must be set in the
0362:             * returned <code>FeatureDescriptor</code>s:
0363:             * <dl>
0364:             *     <li>{@link ELResolver#TYPE} - The runtime type of the implicit object.</li>
0365:             *     <li>{@link ELResolver#RESOLVABLE_AT_DESIGN_TIME} - <code>true</code>.</li>
0366:             * </dl></p>
0367:             *
0368:             * @param context The context of this evaluation.
0369:             * @param base Only <code>null</code> is handled by this resolver.
0370:             *     Other values will result in a <code>null</code> return value.
0371:             * @return An <code>Iterator</code> containing one 
0372:             *     <code>FeatureDescriptor</code> object for each implicit object, or
0373:             *     <code>null</code> if <code>base</code> is not <code>null</code>.
0374:             */
0375:            public Iterator<FeatureDescriptor> getFeatureDescriptors(
0376:                    ELContext context, Object base) {
0377:                ArrayList<FeatureDescriptor> list = new ArrayList<FeatureDescriptor>(
0378:                        11);
0379:
0380:                // pageContext
0381:                FeatureDescriptor descriptor = new FeatureDescriptor();
0382:                descriptor.setName("pageContext");
0383:                descriptor.setDisplayName("pageContext");
0384:                //descriptor.setShortDescription("");
0385:                descriptor.setExpert(false);
0386:                descriptor.setHidden(false);
0387:                descriptor.setPreferred(true);
0388:                descriptor
0389:                        .setValue("type", javax.servlet.jsp.PageContext.class);
0390:                descriptor.setValue("resolvableAtDesignTime", Boolean.TRUE);
0391:                list.add(descriptor);
0392:
0393:                // pageScope
0394:                descriptor = new FeatureDescriptor();
0395:                descriptor.setName("pageScope");
0396:                descriptor.setDisplayName("pageScope");
0397:                //descriptor.setShortDescription("");
0398:                descriptor.setExpert(false);
0399:                descriptor.setHidden(false);
0400:                descriptor.setPreferred(true);
0401:                descriptor.setValue("type", Map.class);
0402:                descriptor.setValue("resolvableAtDesignTime", Boolean.TRUE);
0403:                list.add(descriptor);
0404:
0405:                // requestScope
0406:                descriptor = new FeatureDescriptor();
0407:                descriptor.setName("requestScope");
0408:                descriptor.setDisplayName("requestScope");
0409:                //descriptor.setShortDescription("");
0410:                descriptor.setExpert(false);
0411:                descriptor.setHidden(false);
0412:                descriptor.setPreferred(true);
0413:                descriptor.setValue("type", Map.class);
0414:                descriptor.setValue("resolvableAtDesignTime", Boolean.TRUE);
0415:                list.add(descriptor);
0416:
0417:                // sessionScope
0418:                descriptor = new FeatureDescriptor();
0419:                descriptor.setName("sessionScope");
0420:                descriptor.setDisplayName("sessionScope");
0421:                //descriptor.setShortDescription("");
0422:                descriptor.setExpert(false);
0423:                descriptor.setHidden(false);
0424:                descriptor.setPreferred(true);
0425:                descriptor.setValue("type", Map.class);
0426:                descriptor.setValue("resolvableAtDesignTime", Boolean.TRUE);
0427:                list.add(descriptor);
0428:
0429:                // applicationScope
0430:                descriptor = new FeatureDescriptor();
0431:                descriptor.setName("applicationScope");
0432:                descriptor.setDisplayName("applicationScope");
0433:                //descriptor.setShortDescription("");
0434:                descriptor.setExpert(false);
0435:                descriptor.setHidden(false);
0436:                descriptor.setPreferred(true);
0437:                descriptor.setValue("type", Map.class);
0438:                descriptor.setValue("resolvableAtDesignTime", Boolean.TRUE);
0439:                list.add(descriptor);
0440:
0441:                // param
0442:                descriptor = new FeatureDescriptor();
0443:                descriptor.setName("param");
0444:                descriptor.setDisplayName("param");
0445:                //descriptor.setShortDescription("");
0446:                descriptor.setExpert(false);
0447:                descriptor.setHidden(false);
0448:                descriptor.setPreferred(true);
0449:                descriptor.setValue("type", Map.class);
0450:                descriptor.setValue("resolvableAtDesignTime", Boolean.TRUE);
0451:                list.add(descriptor);
0452:
0453:                // paramValues
0454:                descriptor = new FeatureDescriptor();
0455:                descriptor.setName("paramValues");
0456:                descriptor.setDisplayName("paramValues");
0457:                //descriptor.setShortDescription("");
0458:                descriptor.setExpert(false);
0459:                descriptor.setHidden(false);
0460:                descriptor.setPreferred(true);
0461:                descriptor.setValue("type", Map.class);
0462:                descriptor.setValue("resolvableAtDesignTime", Boolean.TRUE);
0463:                list.add(descriptor);
0464:
0465:                // header
0466:                descriptor = new FeatureDescriptor();
0467:                descriptor.setName("header");
0468:                descriptor.setDisplayName("header");
0469:                //descriptor.setShortDescription("");
0470:                descriptor.setExpert(false);
0471:                descriptor.setHidden(false);
0472:                descriptor.setPreferred(true);
0473:                descriptor.setValue("type", Map.class);
0474:                descriptor.setValue("resolvableAtDesignTime", Boolean.TRUE);
0475:                list.add(descriptor);
0476:
0477:                // headerValues
0478:                descriptor = new FeatureDescriptor();
0479:                descriptor.setName("headerValues");
0480:                descriptor.setDisplayName("headerValues");
0481:                //descriptor.setShortDescription("");
0482:                descriptor.setExpert(false);
0483:                descriptor.setHidden(false);
0484:                descriptor.setPreferred(true);
0485:                descriptor.setValue("type", Map.class);
0486:                descriptor.setValue("resolvableAtDesignTime", Boolean.TRUE);
0487:                list.add(descriptor);
0488:
0489:                // cookie
0490:                descriptor = new FeatureDescriptor();
0491:                descriptor.setName("cookie");
0492:                descriptor.setDisplayName("cookie");
0493:                //descriptor.setShortDescription("");
0494:                descriptor.setExpert(false);
0495:                descriptor.setHidden(false);
0496:                descriptor.setPreferred(true);
0497:                descriptor.setValue("type", Map.class);
0498:                descriptor.setValue("resolvableAtDesignTime", Boolean.TRUE);
0499:                list.add(descriptor);
0500:
0501:                // initParam
0502:                descriptor = new FeatureDescriptor();
0503:                descriptor.setName("initParam");
0504:                descriptor.setDisplayName("initParam");
0505:                //descriptor.setShortDescription("");
0506:                descriptor.setExpert(false);
0507:                descriptor.setHidden(false);
0508:                descriptor.setPreferred(true);
0509:                descriptor.setValue("type", Map.class);
0510:                descriptor.setValue("resolvableAtDesignTime", Boolean.TRUE);
0511:                list.add(descriptor);
0512:
0513:                return list.iterator();
0514:            }
0515:
0516:            /**
0517:             * If the base object is <code>null</code>, returns 
0518:             * <code>String.class</code>.  Otherwise, returns <code>null</code>.
0519:             *
0520:             * @param context The context of this evaluation.
0521:             * @param base Only <code>null</code> is handled by this resolver.
0522:             *     Other values will result in a <code>null</code> return value.
0523:             * @return <code>null</code> if base is not <code>null</code>; otherwise
0524:             *     <code>String.class</code>.
0525:             */
0526:            public Class<String> getCommonPropertyType(ELContext context,
0527:                    Object base) {
0528:                if (base == null) {
0529:                    return String.class;
0530:                }
0531:                return null;
0532:            }
0533:
0534:            // XXX - I moved this class from commons-el to an inner class here
0535:            // so that we do not have a dependency from the JSP APIs into commons-el.
0536:            // There might be a better way to do this.
0537:            /**
0538:             * <p>This class is used to generate the implicit Map and List objects
0539:             * that wrap various elements of the PageContext.  It also returns the
0540:             * correct implicit object for a given implicit object name.
0541:             * 
0542:             * @author Nathan Abramson - Art Technology Group
0543:             **/
0544:            private static class ImplicitObjects {
0545:                //-------------------------------------
0546:                // Constants
0547:                //-------------------------------------
0548:
0549:                // XXX - This probably needs to change, now that this is in a 
0550:                // standard pkg.
0551:                static final String sAttributeName = "org.apache.taglibs.standard.ImplicitObjects";
0552:
0553:                //-------------------------------------
0554:                // Member variables
0555:                //-------------------------------------
0556:
0557:                PageContext mContext;
0558:                Map mPage;
0559:                Map mRequest;
0560:                Map mSession;
0561:                Map mApplication;
0562:                Map mParam;
0563:                Map mParams;
0564:                Map mHeader;
0565:                Map mHeaders;
0566:                Map mInitParam;
0567:                Map mCookie;
0568:
0569:                //-------------------------------------
0570:                /**
0571:                 *
0572:                 * Constructor
0573:                 **/
0574:                public ImplicitObjects(PageContext pContext) {
0575:                    mContext = pContext;
0576:                }
0577:
0578:                //-------------------------------------
0579:                /**
0580:                 *
0581:                 * Finds the ImplicitObjects associated with the PageContext,
0582:                 * creating it if it doesn't yet exist.
0583:                 **/
0584:                public static ImplicitObjects getImplicitObjects(
0585:                        PageContext pContext) {
0586:                    ImplicitObjects objs = (ImplicitObjects) pContext
0587:                            .getAttribute(sAttributeName,
0588:                                    PageContext.PAGE_SCOPE);
0589:                    if (objs == null) {
0590:                        objs = new ImplicitObjects(pContext);
0591:                        pContext.setAttribute(sAttributeName, objs,
0592:                                PageContext.PAGE_SCOPE);
0593:                    }
0594:                    return objs;
0595:                }
0596:
0597:                //-------------------------------------
0598:                /**
0599:                 *
0600:                 * Returns the Map that "wraps" page-scoped attributes
0601:                 **/
0602:                public Map getPageScopeMap() {
0603:                    if (mPage == null) {
0604:                        mPage = createPageScopeMap(mContext);
0605:                    }
0606:                    return mPage;
0607:                }
0608:
0609:                //-------------------------------------
0610:                /**
0611:                 *
0612:                 * Returns the Map that "wraps" request-scoped attributes
0613:                 **/
0614:                public Map getRequestScopeMap() {
0615:                    if (mRequest == null) {
0616:                        mRequest = createRequestScopeMap(mContext);
0617:                    }
0618:                    return mRequest;
0619:                }
0620:
0621:                //-------------------------------------
0622:                /**
0623:                 *
0624:                 * Returns the Map that "wraps" session-scoped attributes
0625:                 **/
0626:                public Map getSessionScopeMap() {
0627:                    if (mSession == null) {
0628:                        mSession = createSessionScopeMap(mContext);
0629:                    }
0630:                    return mSession;
0631:                }
0632:
0633:                //-------------------------------------
0634:                /**
0635:                 *
0636:                 * Returns the Map that "wraps" application-scoped attributes
0637:                 **/
0638:                public Map getApplicationScopeMap() {
0639:                    if (mApplication == null) {
0640:                        mApplication = createApplicationScopeMap(mContext);
0641:                    }
0642:                    return mApplication;
0643:                }
0644:
0645:                //-------------------------------------
0646:                /**
0647:                 *
0648:                 * Returns the Map that maps parameter name to a single parameter
0649:                 * values.
0650:                 **/
0651:                public Map getParamMap() {
0652:                    if (mParam == null) {
0653:                        mParam = createParamMap(mContext);
0654:                    }
0655:                    return mParam;
0656:                }
0657:
0658:                //-------------------------------------
0659:                /**
0660:                 *
0661:                 * Returns the Map that maps parameter name to an array of parameter
0662:                 * values.
0663:                 **/
0664:                public Map getParamsMap() {
0665:                    if (mParams == null) {
0666:                        mParams = createParamsMap(mContext);
0667:                    }
0668:                    return mParams;
0669:                }
0670:
0671:                //-------------------------------------
0672:                /**
0673:                 *
0674:                 * Returns the Map that maps header name to a single header
0675:                 * values.
0676:                 **/
0677:                public Map getHeaderMap() {
0678:                    if (mHeader == null) {
0679:                        mHeader = createHeaderMap(mContext);
0680:                    }
0681:                    return mHeader;
0682:                }
0683:
0684:                //-------------------------------------
0685:                /**
0686:                 *
0687:                 * Returns the Map that maps header name to an array of header
0688:                 * values.
0689:                 **/
0690:                public Map getHeadersMap() {
0691:                    if (mHeaders == null) {
0692:                        mHeaders = createHeadersMap(mContext);
0693:                    }
0694:                    return mHeaders;
0695:                }
0696:
0697:                //-------------------------------------
0698:                /**
0699:                 *
0700:                 * Returns the Map that maps init parameter name to a single init
0701:                 * parameter values.
0702:                 **/
0703:                public Map getInitParamMap() {
0704:                    if (mInitParam == null) {
0705:                        mInitParam = createInitParamMap(mContext);
0706:                    }
0707:                    return mInitParam;
0708:                }
0709:
0710:                //-------------------------------------
0711:                /**
0712:                 *
0713:                 * Returns the Map that maps cookie name to the first matching
0714:                 * Cookie in request.getCookies().
0715:                 **/
0716:                public Map getCookieMap() {
0717:                    if (mCookie == null) {
0718:                        mCookie = createCookieMap(mContext);
0719:                    }
0720:                    return mCookie;
0721:                }
0722:
0723:                //-------------------------------------
0724:                // Methods for generating wrapper maps
0725:                //-------------------------------------
0726:                /**
0727:                 *
0728:                 * Creates the Map that "wraps" page-scoped attributes
0729:                 **/
0730:                public static Map createPageScopeMap(PageContext pContext) {
0731:                    final PageContext context = pContext;
0732:                    return new EnumeratedMap() {
0733:                        public Enumeration enumerateKeys() {
0734:                            return context
0735:                                    .getAttributeNamesInScope(PageContext.PAGE_SCOPE);
0736:                        }
0737:
0738:                        public Object getValue(Object pKey) {
0739:                            if (pKey instanceof  String) {
0740:                                return context.getAttribute((String) pKey,
0741:                                        PageContext.PAGE_SCOPE);
0742:                            } else {
0743:                                return null;
0744:                            }
0745:                        }
0746:
0747:                        public boolean isMutable() {
0748:                            return true;
0749:                        }
0750:                    };
0751:                }
0752:
0753:                //-------------------------------------
0754:                /**
0755:                 *
0756:                 * Creates the Map that "wraps" request-scoped attributes
0757:                 **/
0758:                public static Map createRequestScopeMap(PageContext pContext) {
0759:                    final PageContext context = pContext;
0760:                    return new EnumeratedMap() {
0761:                        public Enumeration enumerateKeys() {
0762:                            return context
0763:                                    .getAttributeNamesInScope(PageContext.REQUEST_SCOPE);
0764:                        }
0765:
0766:                        public Object getValue(Object pKey) {
0767:                            if (pKey instanceof  String) {
0768:                                return context.getAttribute((String) pKey,
0769:                                        PageContext.REQUEST_SCOPE);
0770:                            } else {
0771:                                return null;
0772:                            }
0773:                        }
0774:
0775:                        public boolean isMutable() {
0776:                            return true;
0777:                        }
0778:                    };
0779:                }
0780:
0781:                //-------------------------------------
0782:                /**
0783:                 *
0784:                 * Creates the Map that "wraps" session-scoped attributes
0785:                 **/
0786:                public static Map createSessionScopeMap(PageContext pContext) {
0787:                    final PageContext context = pContext;
0788:                    return new EnumeratedMap() {
0789:                        public Enumeration enumerateKeys() {
0790:                            return context
0791:                                    .getAttributeNamesInScope(PageContext.SESSION_SCOPE);
0792:                        }
0793:
0794:                        public Object getValue(Object pKey) {
0795:                            if (pKey instanceof  String) {
0796:                                return context.getAttribute((String) pKey,
0797:                                        PageContext.SESSION_SCOPE);
0798:                            } else {
0799:                                return null;
0800:                            }
0801:                        }
0802:
0803:                        public boolean isMutable() {
0804:                            return true;
0805:                        }
0806:                    };
0807:                }
0808:
0809:                //-------------------------------------
0810:                /**
0811:                 *
0812:                 * Creates the Map that "wraps" application-scoped attributes
0813:                 **/
0814:                public static Map createApplicationScopeMap(PageContext pContext) {
0815:                    final PageContext context = pContext;
0816:                    return new EnumeratedMap() {
0817:                        public Enumeration enumerateKeys() {
0818:                            return context
0819:                                    .getAttributeNamesInScope(PageContext.APPLICATION_SCOPE);
0820:                        }
0821:
0822:                        public Object getValue(Object pKey) {
0823:                            if (pKey instanceof  String) {
0824:                                return context.getAttribute((String) pKey,
0825:                                        PageContext.APPLICATION_SCOPE);
0826:                            } else {
0827:                                return null;
0828:                            }
0829:                        }
0830:
0831:                        public boolean isMutable() {
0832:                            return true;
0833:                        }
0834:                    };
0835:                }
0836:
0837:                //-------------------------------------
0838:                /**
0839:                 *
0840:                 * Creates the Map that maps parameter name to single parameter
0841:                 * value.
0842:                 **/
0843:                public static Map createParamMap(PageContext pContext) {
0844:                    final HttpServletRequest request = (HttpServletRequest) pContext
0845:                            .getRequest();
0846:                    return new EnumeratedMap() {
0847:                        public Enumeration enumerateKeys() {
0848:                            return request.getParameterNames();
0849:                        }
0850:
0851:                        public Object getValue(Object pKey) {
0852:                            if (pKey instanceof  String) {
0853:                                return request.getParameter((String) pKey);
0854:                            } else {
0855:                                return null;
0856:                            }
0857:                        }
0858:
0859:                        public boolean isMutable() {
0860:                            return false;
0861:                        }
0862:                    };
0863:                }
0864:
0865:                //-------------------------------------
0866:                /**
0867:                 *
0868:                 * Creates the Map that maps parameter name to an array of parameter
0869:                 * values.
0870:                 **/
0871:                public static Map createParamsMap(PageContext pContext) {
0872:                    final HttpServletRequest request = (HttpServletRequest) pContext
0873:                            .getRequest();
0874:                    return new EnumeratedMap() {
0875:                        public Enumeration enumerateKeys() {
0876:                            return request.getParameterNames();
0877:                        }
0878:
0879:                        public Object getValue(Object pKey) {
0880:                            if (pKey instanceof  String) {
0881:                                return request
0882:                                        .getParameterValues((String) pKey);
0883:                            } else {
0884:                                return null;
0885:                            }
0886:                        }
0887:
0888:                        public boolean isMutable() {
0889:                            return false;
0890:                        }
0891:                    };
0892:                }
0893:
0894:                //-------------------------------------
0895:                /**
0896:                 *
0897:                 * Creates the Map that maps header name to single header
0898:                 * value.
0899:                 **/
0900:                public static Map createHeaderMap(PageContext pContext) {
0901:                    final HttpServletRequest request = (HttpServletRequest) pContext
0902:                            .getRequest();
0903:                    return new EnumeratedMap() {
0904:                        public Enumeration enumerateKeys() {
0905:                            return request.getHeaderNames();
0906:                        }
0907:
0908:                        public Object getValue(Object pKey) {
0909:                            if (pKey instanceof  String) {
0910:                                return request.getHeader((String) pKey);
0911:                            } else {
0912:                                return null;
0913:                            }
0914:                        }
0915:
0916:                        public boolean isMutable() {
0917:                            return false;
0918:                        }
0919:                    };
0920:                }
0921:
0922:                //-------------------------------------
0923:                /**
0924:                 *
0925:                 * Creates the Map that maps header name to an array of header
0926:                 * values.
0927:                 **/
0928:                public static Map createHeadersMap(PageContext pContext) {
0929:                    final HttpServletRequest request = (HttpServletRequest) pContext
0930:                            .getRequest();
0931:                    return new EnumeratedMap() {
0932:                        public Enumeration enumerateKeys() {
0933:                            return request.getHeaderNames();
0934:                        }
0935:
0936:                        public Object getValue(Object pKey) {
0937:                            if (pKey instanceof  String) {
0938:                                // Drain the header enumeration
0939:                                List l = new ArrayList();
0940:                                Enumeration e = request
0941:                                        .getHeaders((String) pKey);
0942:                                if (e != null) {
0943:                                    while (e.hasMoreElements()) {
0944:                                        l.add(e.nextElement());
0945:                                    }
0946:                                }
0947:                                String[] ret = (String[]) l
0948:                                        .toArray(new String[l.size()]);
0949:                                return ret;
0950:                            } else {
0951:                                return null;
0952:                            }
0953:                        }
0954:
0955:                        public boolean isMutable() {
0956:                            return false;
0957:                        }
0958:                    };
0959:                }
0960:
0961:                //-------------------------------------
0962:                /**
0963:                 *
0964:                 * Creates the Map that maps init parameter name to single init
0965:                 * parameter value.
0966:                 **/
0967:                public static Map createInitParamMap(PageContext pContext) {
0968:                    final ServletContext context = pContext.getServletContext();
0969:                    return new EnumeratedMap() {
0970:                        public Enumeration enumerateKeys() {
0971:                            return context.getInitParameterNames();
0972:                        }
0973:
0974:                        public Object getValue(Object pKey) {
0975:                            if (pKey instanceof  String) {
0976:                                return context.getInitParameter((String) pKey);
0977:                            } else {
0978:                                return null;
0979:                            }
0980:                        }
0981:
0982:                        public boolean isMutable() {
0983:                            return false;
0984:                        }
0985:                    };
0986:                }
0987:
0988:                //-------------------------------------
0989:                /**
0990:                 *
0991:                 * Creates the Map that maps cookie name to the first matching
0992:                 * Cookie in request.getCookies().
0993:                 **/
0994:                public static Map createCookieMap(PageContext pContext) {
0995:                    // Read all the cookies and construct the entire map
0996:                    HttpServletRequest request = (HttpServletRequest) pContext
0997:                            .getRequest();
0998:                    Cookie[] cookies = request.getCookies();
0999:                    Map ret = new HashMap();
1000:                    for (int i = 0; cookies != null && i < cookies.length; i++) {
1001:                        Cookie cookie = cookies[i];
1002:                        if (cookie != null) {
1003:                            String name = cookie.getName();
1004:                            if (!ret.containsKey(name)) {
1005:                                ret.put(name, cookie);
1006:                            }
1007:                        }
1008:                    }
1009:                    return ret;
1010:                }
1011:
1012:                //-------------------------------------
1013:            }
1014:
1015:            // XXX - I moved this class from commons-el to an inner class here
1016:            // so that we do not have a dependency from the JSP APIs into commons-el.
1017:            // There might be a better way to do this.
1018:            /**
1019:             * <p>This is a Map implementation driven by a data source that only
1020:             * provides an enumeration of keys and a getValue(key) method.  This
1021:             * class must be subclassed to implement those methods.
1022:             *
1023:             * <p>Some of the methods may incur a performance penalty that
1024:             * involves enumerating the entire data source.  In these cases, the
1025:             * Map will try to save the results of that enumeration, but only if
1026:             * the underlying data source is immutable.
1027:             * 
1028:             * @author Nathan Abramson - Art Technology Group
1029:             **/
1030:            private static abstract class EnumeratedMap implements  Map {
1031:                //-------------------------------------
1032:                // Member variables
1033:                //-------------------------------------
1034:
1035:                Map mMap;
1036:
1037:                //-------------------------------------
1038:                public void clear() {
1039:                    throw new UnsupportedOperationException();
1040:                }
1041:
1042:                //-------------------------------------
1043:                public boolean containsKey(Object pKey) {
1044:                    return getValue(pKey) != null;
1045:                }
1046:
1047:                //-------------------------------------
1048:                public boolean containsValue(Object pValue) {
1049:                    return getAsMap().containsValue(pValue);
1050:                }
1051:
1052:                //-------------------------------------
1053:                public Set entrySet() {
1054:                    return getAsMap().entrySet();
1055:                }
1056:
1057:                //-------------------------------------
1058:                public Object get(Object pKey) {
1059:                    return getValue(pKey);
1060:                }
1061:
1062:                //-------------------------------------
1063:                public boolean isEmpty() {
1064:                    return !enumerateKeys().hasMoreElements();
1065:                }
1066:
1067:                //-------------------------------------
1068:                public Set keySet() {
1069:                    return getAsMap().keySet();
1070:                }
1071:
1072:                //-------------------------------------
1073:                public Object put(Object pKey, Object pValue) {
1074:                    throw new UnsupportedOperationException();
1075:                }
1076:
1077:                //-------------------------------------
1078:                public void putAll(Map pMap) {
1079:                    throw new UnsupportedOperationException();
1080:                }
1081:
1082:                //-------------------------------------
1083:                public Object remove(Object pKey) {
1084:                    throw new UnsupportedOperationException();
1085:                }
1086:
1087:                //-------------------------------------
1088:                public int size() {
1089:                    return getAsMap().size();
1090:                }
1091:
1092:                //-------------------------------------
1093:                public Collection values() {
1094:                    return getAsMap().values();
1095:                }
1096:
1097:                //-------------------------------------
1098:                // Abstract methods
1099:                //-------------------------------------
1100:                /**
1101:                 *
1102:                 * Returns an enumeration of the keys
1103:                 **/
1104:                public abstract Enumeration enumerateKeys();
1105:
1106:                //-------------------------------------
1107:                /**
1108:                 *
1109:                 * Returns true if it is possible for this data source to change
1110:                 **/
1111:                public abstract boolean isMutable();
1112:
1113:                //-------------------------------------
1114:                /**
1115:                 *
1116:                 * Returns the value associated with the given key, or null if not
1117:                 * found.
1118:                 **/
1119:                public abstract Object getValue(Object pKey);
1120:
1121:                //-------------------------------------
1122:                /**
1123:                 *
1124:                 * Converts the MapSource to a Map.  If the map is not mutable, this
1125:                 * is cached
1126:                 **/
1127:                public Map getAsMap() {
1128:                    if (mMap != null) {
1129:                        return mMap;
1130:                    } else {
1131:                        Map m = convertToMap();
1132:                        if (!isMutable()) {
1133:                            mMap = m;
1134:                        }
1135:                        return m;
1136:                    }
1137:                }
1138:
1139:                //-------------------------------------
1140:                /**
1141:                 *
1142:                 * Converts to a Map
1143:                 **/
1144:                Map convertToMap() {
1145:                    Map ret = new HashMap();
1146:                    for (Enumeration e = enumerateKeys(); e.hasMoreElements();) {
1147:                        Object key = e.nextElement();
1148:                        Object value = getValue(key);
1149:                        ret.put(key, value);
1150:                    }
1151:                    return ret;
1152:                }
1153:
1154:                //-------------------------------------
1155:            }
1156:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.