Source Code Cross Referenced for BeanAction.java in  » Scripting » Pnuts » pnuts » xml » action » 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 » Scripting » Pnuts » pnuts.xml.action 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


01:        /*
02:         * @(#)BeanAction.java 1.2 04/12/06
03:         *
04:         * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
05:         *
06:         * See the file "LICENSE.txt" for information on usage and redistribution
07:         * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
08:         */
09:        package pnuts.xml.action;
10:
11:        import pnuts.xml.DigestAction;
12:        import pnuts.beans.BeanUtil;
13:        import java.util.Map;
14:        import java.util.HashMap;
15:        import java.util.List;
16:        import java.util.Iterator;
17:        import org.xml.sax.Attributes;
18:
19:        /**
20:         * This action creates an instance of the class, which was passed to the
21:         * constructor, and adds it to the object on the stack top, in a way that
22:         * depends on the type of the object. Then it pushes the object on the stack.
23:         * <ul>
24:         * <li>If a List object is on the stack top, the created object is added to the List.
25:         * <li>If a Map object is on the stack top, a map entry of {<em>keyword</em> => the
26:         * created object} is added to the Map.
27:         * <li>Otherwise, this action assigns the created object to the Bean property whose name
28:         * is the <em>keyword</em>.  The type of the Bean property must match the type of the created object.
29:         * </ul>
30:         * If the element has one or more attributes, this action assigns the
31:         * attribute's value to the Bean property, whose name is the name of the
32:         * attribute.  If the Bean property is of a primitive type, the attribute's
33:         * value is automatically converted to the appropriate value.
34:         */
35:        public class BeanAction extends DigestAction {
36:            static Object[] NOARGS = new Object[] {};
37:            static Class[] NOTYPES = new Class[] {};
38:
39:            Class cls;
40:
41:            protected BeanAction() {
42:            }
43:
44:            public BeanAction(Class cls) {
45:                this .cls = cls;
46:            }
47:
48:            /**
49:             * Defines bean properties from the [qName->value] mapping in the specified Attibutes.
50:             *
51:             * @param bean the target object
52:             * @param attributeMap a [qName->value] mapping.
53:             */
54:            protected void setAttributes(Object bean, Map attributeMap)
55:                    throws Exception {
56:                for (Iterator it = attributeMap.entrySet().iterator(); it
57:                        .hasNext();) {
58:                    Map.Entry entry = (Map.Entry) it.next();
59:                    setBeanProperty(bean, (String) entry.getKey(),
60:                            (String) entry.getValue());
61:                }
62:            }
63:
64:            /**
65:             * Defines a bean property
66:             *
67:             * @param bean the target object
68:             * @param name the property name
69:             * @param text a string
70:             */
71:            protected void setBeanProperty(Object bean, String name, String text)
72:                    throws Exception {
73:                BeanHelper.setBeanProperty(bean, name, text);
74:            }
75:
76:            public void start(String path, String key, Map attributeMap,
77:                    Object top) throws Exception {
78:                Object bean = cls.newInstance();
79:                setAttributes(bean, attributeMap);
80:                if (top instanceof  List) {
81:                    ((List) top).add(bean);
82:                } else if (top instanceof  Map) {
83:                    ((Map) top).put(key, bean);
84:                    push(path, bean);
85:                } else {
86:                    BeanUtil.setProperty(top, key, bean);
87:                    push(path, bean);
88:                }
89:            }
90:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.