Source Code Cross Referenced for XWorkListPropertyAccessor.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:        package com.opensymphony.xwork.util;
006:
007:        import com.opensymphony.xwork.ObjectFactory;
008:        import com.opensymphony.xwork.XworkException;
009:        import ognl.ListPropertyAccessor;
010:        import ognl.OgnlException;
011:
012:        import java.util.Collection;
013:        import java.util.List;
014:        import java.util.Map;
015:
016:        /**
017:         * Overrides the list property accessor so in the case of trying
018:         * to add properties of a given bean and the JavaBean is not present,
019:         * this class will create the necessary blank JavaBeans.
020:         *
021:         * @author Gabriel Zimmerman
022:         */
023:        public class XWorkListPropertyAccessor extends ListPropertyAccessor {
024:
025:            private XWorkCollectionPropertyAccessor _sAcc = new XWorkCollectionPropertyAccessor();
026:
027:            public Object getProperty(Map context, Object target, Object name)
028:                    throws OgnlException {
029:
030:                if (OgnlContextState.isGettingByKeyProperty(context)
031:                        || name
032:                                .equals(XWorkCollectionPropertyAccessor.KEY_PROPERTY_FOR_CREATION)) {
033:                    return _sAcc.getProperty(context, target, name);
034:                } else if (name instanceof  String) {
035:                    return super .getProperty(context, target, name);
036:                }
037:                OgnlContextState.updateCurrentPropertyPath(context, name);
038:                //System.out.println("Entering XWorkListPropertyAccessor. Name: " + name);
039:                Class lastClass = (Class) context
040:                        .get(XWorkConverter.LAST_BEAN_CLASS_ACCESSED);
041:                String lastProperty = (String) context
042:                        .get(XWorkConverter.LAST_BEAN_PROPERTY_ACCESSED);
043:
044:                if (name instanceof  Number
045:                        && OgnlContextState.isCreatingNullObjects(context)
046:                        && XWorkConverter.getInstance()
047:                                .getObjectTypeDeterminer().shouldCreateIfNew(
048:                                        lastClass, lastProperty, target, null,
049:                                        true)) {
050:
051:                    //System.out.println("Getting index from List");
052:                    List list = (List) target;
053:                    int index = ((Number) name).intValue();
054:                    int listSize = list.size();
055:
056:                    if (lastClass == null || lastProperty == null) {
057:                        return super .getProperty(context, target, name);
058:                    }
059:                    Class beanClass = XWorkConverter.getInstance()
060:                            .getObjectTypeDeterminer().getElementClass(
061:                                    lastClass, lastProperty, name);
062:                    if (listSize <= index) {
063:                        Object result = null;
064:
065:                        for (int i = listSize; i < index; i++) {
066:
067:                            list.add(null);
068:
069:                        }
070:                        try {
071:                            list.add(index, result = ObjectFactory
072:                                    .getObjectFactory().buildBean(beanClass,
073:                                            context));
074:                        } catch (Exception exc) {
075:                            throw new XworkException(exc);
076:                        }
077:                        return result;
078:                    } else if (list.get(index) == null) {
079:                        Object result = null;
080:                        try {
081:                            list.set(index, result = ObjectFactory
082:                                    .getObjectFactory().buildBean(beanClass,
083:                                            context));
084:                        } catch (Exception exc) {
085:                            throw new XworkException(exc);
086:                        }
087:                        return result;
088:                    }
089:                }
090:                return super .getProperty(context, target, name);
091:            }
092:
093:            public void setProperty(Map context, Object target, Object name,
094:                    Object value) throws OgnlException {
095:
096:                Class lastClass = (Class) context
097:                        .get(XWorkConverter.LAST_BEAN_CLASS_ACCESSED);
098:                String lastProperty = (String) context
099:                        .get(XWorkConverter.LAST_BEAN_PROPERTY_ACCESSED);
100:                Class convertToClass = XWorkConverter.getInstance()
101:                        .getObjectTypeDeterminer().getElementClass(lastClass,
102:                                lastProperty, name);
103:
104:                if (name instanceof  String && value.getClass().isArray()) {
105:                    // looks like the input game in the form of "someList.foo" and
106:                    // we are expected to define the index values ourselves.
107:                    // So let's do it:
108:
109:                    Collection c = (Collection) target;
110:                    Object[] values = (Object[]) value;
111:                    for (int i = 0; i < values.length; i++) {
112:                        Object v = values[i];
113:                        try {
114:                            Object o = ObjectFactory.getObjectFactory()
115:                                    .buildBean(convertToClass, context);
116:                            OgnlUtil.setValue((String) name, context, o, v);
117:                            c.add(o);
118:                        } catch (Exception e) {
119:                            throw new OgnlException(
120:                                    "Error converting given String values for Collection.",
121:                                    e);
122:                        }
123:                    }
124:
125:                    // we don't want to do the normal list property setting now, since we've already done the work
126:                    // just return instead
127:                    return;
128:                }
129:
130:                Object realValue = getRealValue(context, value, convertToClass);
131:
132:                if (target instanceof  List && name instanceof  Number) {
133:                    //make sure there are enough spaces in the List to set
134:                    List list = (List) target;
135:                    int listSize = list.size();
136:                    int count = ((Number) name).intValue();
137:                    if (count >= listSize) {
138:                        for (int i = listSize; i <= count; i++) {
139:                            list.add(null);
140:                        }
141:                    }
142:                }
143:
144:                super .setProperty(context, target, name, realValue);
145:            }
146:
147:            private Object getRealValue(Map context, Object value,
148:                    Class convertToClass) {
149:                if (value == null || convertToClass == null) {
150:                    return value;
151:                }
152:                return XWorkConverter.getInstance().convertValue(context,
153:                        value, convertToClass);
154:            }
155:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.