Source Code Cross Referenced for ComponentContext.java in  » Web-Framework » struts-1.3.8 » org » apache » struts » tiles » 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 » Web Framework » struts 1.3.8 » org.apache.struts.tiles 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: ComponentContext.java 471754 2006-11-06 14:55:09Z husted $
003:         *
004:         * Licensed to the Apache Software Foundation (ASF) under one
005:         * or more contributor license agreements.  See the NOTICE file
006:         * distributed with this work for additional information
007:         * regarding copyright ownership.  The ASF licenses this file
008:         * to you under the Apache License, Version 2.0 (the
009:         * "License"); you may not use this file except in compliance
010:         * with the License.  You may obtain a copy of the License at
011:         *
012:         *  http://www.apache.org/licenses/LICENSE-2.0
013:         *
014:         * Unless required by applicable law or agreed to in writing,
015:         * software distributed under the License is distributed on an
016:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017:         * KIND, either express or implied.  See the License for the
018:         * specific language governing permissions and limitations
019:         * under the License.
020:         */
021:
022:        package org.apache.struts.tiles;
023:
024:        import java.io.Serializable;
025:        import java.util.Collections;
026:        import java.util.HashMap;
027:        import java.util.Iterator;
028:        import java.util.Map;
029:        import java.util.Set;
030:
031:        import javax.servlet.ServletRequest;
032:        import javax.servlet.jsp.PageContext;
033:
034:        import org.apache.struts.tiles.taglib.ComponentConstants;
035:
036:        /**
037:         * Component context.
038:         */
039:        public class ComponentContext implements  Serializable {
040:
041:            /**
042:             * Component attributes.
043:             */
044:            private Map attributes = null;
045:
046:            /**
047:             * Constructor.
048:             */
049:            public ComponentContext() {
050:                super ();
051:            }
052:
053:            /**
054:             * Constructor.
055:             * Create a context and set specified attributes.
056:             * @param attributes Attributes to initialize context.
057:             */
058:            public ComponentContext(Map attributes) {
059:                if (attributes != null) {
060:                    this .attributes = new HashMap(attributes);
061:                }
062:            }
063:
064:            /**
065:             * Add all attributes to this context.
066:             * Copies all of the mappings from the specified attribute map to this context.
067:             * New attribute mappings will replace any mappings that this context had for any of the keys
068:             * currently in the specified attribute map.
069:             * @param newAttributes Attributes to add.
070:             */
071:            public void addAll(Map newAttributes) {
072:                if (attributes == null) {
073:                    attributes = new HashMap(newAttributes);
074:                    return;
075:                }
076:
077:                attributes.putAll(newAttributes);
078:            }
079:
080:            /**
081:             * Add all missing attributes to this context.
082:             * Copies all of the mappings from the specified attributes map to this context.
083:             * New attribute mappings will be added only if they don't already exist in
084:             * this context.
085:             * @param defaultAttributes Attributes to add.
086:             */
087:            public void addMissing(Map defaultAttributes) {
088:                if (defaultAttributes == null) {
089:                    return;
090:                }
091:
092:                if (attributes == null) {
093:                    attributes = new HashMap(defaultAttributes);
094:                    return;
095:                }
096:
097:                Set entries = defaultAttributes.entrySet();
098:                Iterator iterator = entries.iterator();
099:                while (iterator.hasNext()) {
100:                    Map.Entry entry = (Map.Entry) iterator.next();
101:                    if (!attributes.containsKey(entry.getKey())) {
102:                        attributes.put(entry.getKey(), entry.getValue());
103:                    }
104:                }
105:            }
106:
107:            /**
108:             * Get an attribute from context.
109:             * @param name Name of the attribute.
110:             * @return <{Object}>
111:             */
112:            public Object getAttribute(String name) {
113:                if (attributes == null) {
114:                    return null;
115:                }
116:
117:                return attributes.get(name);
118:            }
119:
120:            /**
121:             * Get names of all attributes.
122:             * @return <{Object}>
123:             */
124:            public Iterator getAttributeNames() {
125:                if (attributes == null) {
126:                    return Collections.EMPTY_LIST.iterator();
127:                }
128:
129:                return attributes.keySet().iterator();
130:            }
131:
132:            /**
133:             * Put a new attribute to context.
134:             * @param name Name of the attribute.
135:             * @param value Value of the attribute.
136:             */
137:            public void putAttribute(String name, Object value) {
138:                if (attributes == null) {
139:                    attributes = new HashMap();
140:                }
141:
142:                attributes.put(name, value);
143:            }
144:
145:            /**
146:             * Find object in one of the contexts.
147:             * Order : component then pageContext.findAttribute()
148:             * @param beanName Name of the bean to find.
149:             * @param pageContext Page context.
150:             * @return Requested bean or <code>null</code> if not found.
151:             */
152:            public Object findAttribute(String beanName, PageContext pageContext) {
153:                Object attribute = getAttribute(beanName);
154:                if (attribute == null) {
155:                    attribute = pageContext.findAttribute(beanName);
156:                }
157:
158:                return attribute;
159:            }
160:
161:            /**
162:             * Get object from requested context.
163:             * Context can be 'component'.
164:             * @param beanName Name of the bean to find.
165:             * @param scope Search scope (see {@link PageContext}).
166:             * @param pageContext Page context.
167:             * @return requested bean or <code>null</code> if not found.
168:             */
169:            public Object getAttribute(String beanName, int scope,
170:                    PageContext pageContext) {
171:
172:                if (scope == ComponentConstants.COMPONENT_SCOPE) {
173:                    return getAttribute(beanName);
174:                }
175:
176:                return pageContext.getAttribute(beanName, scope);
177:            }
178:
179:            /**
180:             * Get component context from request.
181:             * @param request ServletRequest.
182:             * @return ComponentContext or null if context is not found or an
183:             * jspException is present in the request.
184:             */
185:            static public ComponentContext getContext(ServletRequest request) {
186:                if (request.getAttribute("javax.servlet.jsp.jspException") != null) {
187:                    return null;
188:                }
189:                return (ComponentContext) request
190:                        .getAttribute(ComponentConstants.COMPONENT_CONTEXT);
191:            }
192:
193:            /**
194:             * Store component context into request.
195:             * @param context ComponentContext to store.
196:             * @param request Request to store ComponentContext.
197:             */
198:            static public void setContext(ComponentContext context,
199:                    ServletRequest request) {
200:
201:                request.setAttribute(ComponentConstants.COMPONENT_CONTEXT,
202:                        context);
203:            }
204:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.