Source Code Cross Referenced for OutcookieValues.java in  » Web-Framework » rife-1.6.1 » com » uwyn » rife » engine » 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 » rife 1.6.1 » com.uwyn.rife.engine 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003:         * Distributed under the terms of either:
004:         * - the common development and distribution license (CDDL), v1.0; or
005:         * - the GNU Lesser General Public License, v2.1 or later
006:         * $Id: OutcookieValues.java 3716 2007-04-11 06:21:18Z gbevin $
007:         */
008:        package com.uwyn.rife.engine;
009:
010:        import com.uwyn.rife.engine.exceptions.ElementOutjectionException;
011:        import com.uwyn.rife.engine.exceptions.OutcookieOutjectionException;
012:        import com.uwyn.rife.engine.exceptions.OutputOutjectionException;
013:        import com.uwyn.rife.tools.BeanPropertyProcessor;
014:        import com.uwyn.rife.tools.BeanUtils;
015:        import com.uwyn.rife.tools.Convert;
016:        import com.uwyn.rife.tools.exceptions.BeanUtilsException;
017:        import java.beans.PropertyDescriptor;
018:        import java.lang.reflect.InvocationTargetException;
019:        import java.lang.reflect.Method;
020:        import java.util.Collection;
021:        import java.util.Collections;
022:        import java.util.LinkedHashMap;
023:        import java.util.Map;
024:        import javax.servlet.http.Cookie;
025:
026:        class OutcookieValues {
027:            private ElementContext mContext = null;
028:            private ElementAware mElement = null;
029:
030:            private Map<String, String> mValues = null;
031:            private Map<String, Method> mOutcookieGetters = null;
032:
033:            OutcookieValues(ElementContext context) {
034:                assert context != null;
035:
036:                mContext = context;
037:                mContext.getElementInfo().getSite();
038:                mElement = mContext.getElementSupport().getElementAware();
039:                mValues = new LinkedHashMap<String, String>();
040:
041:                // try to obtain the outcookie getters from the cache
042:                // if this wasn't possible, detect them and store them in the cache
043:                final ElementInfo element_info = mContext.getElementInfo();
044:                mOutcookieGetters = element_info.getSite()
045:                        .getCachedOutcookieGetters(element_info.getId());
046:                if (null == mOutcookieGetters) {
047:                    final Collection<String> names_outcookies = element_info
048:                            .getOutcookieNames();
049:                    final Collection<String> names_globalcookies = element_info
050:                            .getGlobalCookieNames();
051:                    try {
052:                        BeanUtils.processProperties(BeanUtils.GETTERS, mElement
053:                                .getClass(), null, null, null,
054:                                new BeanPropertyProcessor() {
055:                                    public boolean gotProperty(String name,
056:                                            PropertyDescriptor descriptor)
057:                                            throws IllegalAccessException,
058:                                            IllegalArgumentException,
059:                                            InvocationTargetException {
060:                                        Method method = descriptor
061:                                                .getReadMethod();
062:                                        if (names_outcookies.contains(name)
063:                                                || names_globalcookies
064:                                                        .contains(name))
065:
066:                                        {
067:                                            if (null == mOutcookieGetters) {
068:                                                mOutcookieGetters = new LinkedHashMap<String, Method>();
069:                                            }
070:
071:                                            mOutcookieGetters.put(name, method);
072:                                        }
073:
074:                                        return true;
075:                                    }
076:                                });
077:
078:                        if (null == mOutcookieGetters) {
079:                            mOutcookieGetters = Collections.EMPTY_MAP;
080:                        }
081:                        element_info.getSite().putCachedOutcookieGetters(
082:                                element_info.getId(), mOutcookieGetters);
083:                    } catch (BeanUtilsException e) {
084:                        throw new ElementOutjectionException(mContext
085:                                .getElementInfo().getDeclarationName(),
086:                                mElement.getClass(), e);
087:                    }
088:                }
089:            }
090:
091:            void processGetters() {
092:                Object value = null;
093:                Cookie cookie = null;
094:                if (mOutcookieGetters != null && mOutcookieGetters.size() > 0) {
095:                    for (Map.Entry<String, Method> outcookie_getter : mOutcookieGetters
096:                            .entrySet()) {
097:                        if (!mValues.containsKey(outcookie_getter.getKey())) {
098:                            value = getPropertyValue(outcookie_getter.getKey());
099:                            if (value != null) {
100:                                cookie = new Cookie(outcookie_getter.getKey(),
101:                                        Convert.toString(value));
102:                                cookie.setPath("");
103:                                mContext.setCookieRaw(cookie);
104:                            }
105:                        }
106:                    }
107:                }
108:            }
109:
110:            void processGetterChildTriggers() {
111:                if (mContext.getElementState().inInheritanceStructure()) {
112:                    Collection<String> childtrigger_names = mContext
113:                            .getElementInfo().getChildTriggerNames();
114:
115:                    Object value = null;
116:                    if (mOutcookieGetters != null
117:                            && mOutcookieGetters.size() > 0) {
118:                        for (Map.Entry<String, Method> outcookie_getter : mOutcookieGetters
119:                                .entrySet()) {
120:                            if (childtrigger_names.contains(outcookie_getter
121:                                    .getKey())) {
122:                                value = getPropertyValue(outcookie_getter
123:                                        .getKey());
124:                                if (value != null) {
125:                                    mContext.triggerChild(outcookie_getter
126:                                            .getKey(), new String[] { Convert
127:                                            .toString(value) });
128:                                }
129:                            }
130:                        }
131:                    }
132:                }
133:            }
134:
135:            void put(String name, String value) {
136:                if (null == name)
137:                    return;
138:
139:                if (mOutcookieGetters != null) {
140:                    mOutcookieGetters.remove(name);
141:                }
142:
143:                mValues.put(name, value);
144:            }
145:
146:            String get(String name) {
147:                if (null == name)
148:                    return null;
149:
150:                String outcookie = mValues.get(name);
151:                if (null == outcookie
152:                        && mContext.getElementInfo().hasOutcookieDefaults()) {
153:                    outcookie = mContext.getElementInfo()
154:                            .getOutcookieDefaultValue(name);
155:                }
156:
157:                if (null == outcookie) {
158:                    outcookie = getPropertyValue(name);
159:                }
160:
161:                return outcookie;
162:            }
163:
164:            private String getPropertyValue(String name)
165:                    throws OutputOutjectionException {
166:                if (null == mOutcookieGetters) {
167:                    return null;
168:                }
169:
170:                Method method = mOutcookieGetters.get(name);
171:                if (method != null) {
172:                    try {
173:                        Object value = method.invoke(mElement, (Object[]) null);
174:                        if (value != null) {
175:                            return Convert.toString(value);
176:                        }
177:                    } catch (Exception e) {
178:                        throw new OutcookieOutjectionException(mContext
179:                                .getElementInfo().getDeclarationName(),
180:                                mElement.getClass(), e);
181:                    }
182:                }
183:
184:                return null;
185:            }
186:
187:            boolean contains(String name) {
188:                if (null == name)
189:                    return false;
190:
191:                if (mValues.containsKey(name)) {
192:                    return true;
193:                }
194:
195:                if (getPropertyValue(name) != null) {
196:                    return true;
197:                }
198:
199:                return false;
200:            }
201:
202:            Map<String, String> aggregateValues() {
203:                Map<String, String> entry_map = null;
204:
205:                // handle default outcookie values
206:                if (mContext.getElementInfo().hasOutcookieDefaults()) {
207:                    if (null == entry_map) {
208:                        entry_map = new LinkedHashMap<String, String>();
209:                    }
210:
211:                    for (Map.Entry<String, String> outcookie_defaults_entry : mContext
212:                            .getElementInfo().getOutcookieEntries()) {
213:                        if (outcookie_defaults_entry.getValue() != null) {
214:                            entry_map.put(outcookie_defaults_entry.getKey(),
215:                                    outcookie_defaults_entry.getValue());
216:                        }
217:                    }
218:                }
219:
220:                // handle outcookie getter outjection
221:                if (mOutcookieGetters != null && mOutcookieGetters.size() > 0) {
222:                    Object value = null;
223:                    try {
224:                        for (Map.Entry<String, Method> outcookie_getter : mOutcookieGetters
225:                                .entrySet()) {
226:                            value = outcookie_getter.getValue().invoke(
227:                                    mElement, (Object[]) null);
228:                            if (value != null) {
229:                                if (null == entry_map) {
230:                                    entry_map = new LinkedHashMap<String, String>();
231:                                }
232:
233:                                entry_map.put(outcookie_getter.getKey(),
234:                                        Convert.toString(value));
235:                            }
236:                        }
237:                    } catch (Exception e) {
238:                        throw new OutcookieOutjectionException(mContext
239:                                .getElementInfo().getDeclarationName(),
240:                                mElement.getClass(), e);
241:                    }
242:                }
243:
244:                // handle outcookies that have been explicitly set
245:                if (null == entry_map) {
246:                    return Collections.unmodifiableMap(mValues);
247:                } else {
248:                    entry_map.putAll(mValues);
249:                }
250:
251:                return Collections.unmodifiableMap(entry_map);
252:            }
253:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.