Source Code Cross Referenced for XWorkMapPropertyAccessor.java in  » J2EE » webwork-2.2.6 » com » opensymphony » xwork » util » 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 » J2EE » webwork 2.2.6 » com.opensymphony.xwork.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2002-2006 by OpenSymphony
003:         * All rights reserved.
004:         */
005:
006:        package com.opensymphony.xwork.util;
007:
008:        import com.opensymphony.xwork.ObjectFactory;
009:        import ognl.MapPropertyAccessor;
010:        import ognl.OgnlException;
011:
012:        import java.util.Map;
013:
014:        import org.apache.commons.logging.Log;
015:        import org.apache.commons.logging.LogFactory;
016:
017:        /**
018:         * Implementation of PropertyAccessor that sets and gets properties by storing and looking
019:         * up values in Maps.
020:         *
021:         * @author Gabriel Zimmerman
022:         */
023:        public class XWorkMapPropertyAccessor extends MapPropertyAccessor {
024:
025:            private static final Log _log = LogFactory
026:                    .getLog(XWorkMapPropertyAccessor.class);
027:
028:            private static final String[] INDEX_ACCESS_PROPS = new String[] {
029:                    "size", "isEmpty", "keys", "values" };
030:
031:            private static final XWorkConverter _converter = XWorkConverter
032:                    .getInstance();
033:
034:            public Object getProperty(Map context, Object target, Object name)
035:                    throws OgnlException {
036:
037:                if (_log.isDebugEnabled()) {
038:                    _log.debug("Entering getProperty (" + context + ","
039:                            + target + "," + name + ")");
040:                }
041:
042:                OgnlContextState.updateCurrentPropertyPath(context, name);
043:                // if this is one of the regular index access
044:                // properties then just let the superclass deal with the
045:                // get.
046:                if (name instanceof  String
047:                        && contains(INDEX_ACCESS_PROPS, (String) name)) {
048:                    return super .getProperty(context, target, name);
049:                }
050:
051:                Object result = null;
052:
053:                try {
054:                    result = super .getProperty(context, target, name);
055:                } catch (ClassCastException ex) {
056:                }
057:
058:                if (result == null) {
059:                    //find the key class and convert the name to that class
060:                    Class lastClass = (Class) context
061:                            .get(XWorkConverter.LAST_BEAN_CLASS_ACCESSED);
062:
063:                    String lastProperty = (String) context
064:                            .get(XWorkConverter.LAST_BEAN_PROPERTY_ACCESSED);
065:                    if (lastClass == null || lastProperty == null) {
066:                        return super .getProperty(context, target, name);
067:                    }
068:                    Class keyClass = _converter.getObjectTypeDeterminer()
069:                            .getKeyClass(lastClass, lastProperty);
070:
071:                    if (keyClass == null) {
072:
073:                        keyClass = java.lang.String.class;
074:                    }
075:                    Object key = getKey(context, name);
076:                    Map map = (Map) target;
077:                    result = map.get(key);
078:
079:                    if (result == null
080:                            && context
081:                                    .get(InstantiatingNullHandler.CREATE_NULL_OBJECTS) != null
082:                            && XWorkConverter.getInstance()
083:                                    .getObjectTypeDeterminer()
084:                                    .shouldCreateIfNew(lastClass, lastProperty,
085:                                            target, null, false)) {
086:                        Class valueClass = _converter.getObjectTypeDeterminer()
087:                                .getElementClass(lastClass, lastProperty, key);
088:
089:                        try {
090:                            result = ObjectFactory.getObjectFactory()
091:                                    .buildBean(valueClass, context);
092:                            map.put(key, result);
093:                        } catch (Exception exc) {
094:
095:                        }
096:
097:                    }
098:                }
099:                return result;
100:            }
101:
102:            /**
103:             * @param array
104:             * @param name
105:             */
106:            private boolean contains(String[] array, String name) {
107:                for (int i = 0; i < array.length; i++) {
108:                    if (array[i].equals(name)) {
109:                        return true;
110:                    }
111:                }
112:
113:                return false;
114:            }
115:
116:            public void setProperty(Map context, Object target, Object name,
117:                    Object value) throws OgnlException {
118:                if (_log.isDebugEnabled()) {
119:                    _log.debug("Entering setProperty(" + context + "," + target
120:                            + "," + name + "," + value + ")");
121:                }
122:
123:                Object key = getKey(context, name);
124:                Map map = (Map) target;
125:                map.put(key, getValue(context, value));
126:            }
127:
128:            private Object getValue(Map context, Object value) {
129:                Class lastClass = (Class) context
130:                        .get(XWorkConverter.LAST_BEAN_CLASS_ACCESSED);
131:                String lastProperty = (String) context
132:                        .get(XWorkConverter.LAST_BEAN_PROPERTY_ACCESSED);
133:                if (lastClass == null || lastProperty == null) {
134:                    return value;
135:                }
136:                Class elementClass = _converter.getObjectTypeDeterminer()
137:                        .getElementClass(lastClass, lastProperty, null);
138:                if (elementClass == null) {
139:                    return value; // nothing is specified, we assume it will be the value passed in.
140:                }
141:                return _converter.convertValue(context, value, elementClass);
142:            }
143:
144:            private Object getKey(Map context, Object name) {
145:                Class lastClass = (Class) context
146:                        .get(XWorkConverter.LAST_BEAN_CLASS_ACCESSED);
147:                String lastProperty = (String) context
148:                        .get(XWorkConverter.LAST_BEAN_PROPERTY_ACCESSED);
149:                if (lastClass == null || lastProperty == null) {
150:                    // return java.lang.String.class;
151:                    // commented out the above -- it makes absolutely no sense for when setting basic maps!
152:                    return name;
153:                }
154:                Class keyClass = _converter.getObjectTypeDeterminer()
155:                        .getKeyClass(lastClass, lastProperty);
156:                if (keyClass == null) {
157:                    keyClass = java.lang.String.class;
158:                }
159:
160:                return _converter.convertValue(context, name, keyClass);
161:
162:            }
163:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.