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


001:        /*
002:         * @(#)JavaBeansConfiguration.java 1.3 05/05/09
003:         *
004:         * Copyright (c) 1997-2004 Sun Microsystems, Inc. All Rights Reserved.
005:         *
006:         * See the file "LICENSE.txt" for information on usage and redistribution
007:         * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
008:         */
009:        package pnuts.lang;
010:
011:        import java.lang.reflect.Constructor;
012:        import java.lang.reflect.InvocationTargetException;
013:        import java.lang.reflect.Method;
014:        import java.security.AccessController;
015:        import java.security.PrivilegedAction;
016:        import org.pnuts.lang.*;
017:
018:        /**
019:         * This is a configuration for JavaBeans. Only methods in method descriptors can
020:         * be called. Field access expression reads/writes property of the Beans.
021:         */
022:        abstract class JavaBeansConfiguration extends Configuration {
023:
024:            private Class stopClass;
025:
026:            /**
027:             * Constructor
028:             */
029:            public JavaBeansConfiguration() {
030:            }
031:
032:            /**
033:             * Constructor
034:             */
035:            public JavaBeansConfiguration(Class stopClass) {
036:                this .stopClass = stopClass;
037:            }
038:
039:            /*
040:             * Gets the Introspector's "stopClass"
041:             * 
042:             * @see java.beans.Introspector
043:             */
044:            protected Class getStopClass() {
045:                return stopClass;
046:            }
047:
048:            /**
049:             * Collects the Bean methods for the specified class.
050:             */
051:            public Method[] getMethods(Class cls) {
052:                return ObjectDescFactory.getDefault().create(cls, stopClass)
053:                        .getMethods();
054:            }
055:
056:            /**
057:             * Get all public constructors of the specified class.
058:             * 
059:             * @param cls the class
060:             * @return an array of Constructor objects
061:             */
062:            public Constructor[] getConstructors(final Class cls) {
063:                return (Constructor[]) AccessController
064:                        .doPrivileged(new PrivilegedAction() {
065:                            public Object run() {
066:                                return cls.getConstructors();
067:                            }
068:                        });
069:            }
070:
071:            /**
072:             * Gets a Bean property of the specified bean.
073:             * 
074:             * @param context
075:             *            the context in which the property is read
076:             * @param target
077:             *            the target bean
078:             * @param name
079:             *            the Bean property name
080:             */
081:            public Object getField(Context context, Object target, String name) {
082:                return getBeanProperty(context, target, name);
083:            }
084:
085:            /**
086:             * Gets a Bean property of the specified bean.
087:             * 
088:             * @param context
089:             *            the context in which the property is read
090:             * @param target
091:             *            the target bean
092:             * @param name
093:             *            the Bean property name
094:             */
095:            protected Object getBeanProperty(Context context, Object target,
096:                    String name) {
097:                try {
098:                    return context.runtime.getBeanProperty(target, name,
099:                            stopClass);
100:                } catch (InvocationTargetException e1) {
101:                    throw new PnutsException(e1.getTargetException(), context);
102:                } catch (IllegalAccessException e2) {
103:                    throw new PnutsException(e2, context);
104:                }
105:            }
106:
107:            /**
108:             * Sets a Bean property of the specified bean.
109:             * 
110:             * @param context
111:             *            the context in which the property is read
112:             * @param target
113:             *            the target bean
114:             * @param name
115:             *            the Bean property name
116:             * @param value
117:             *            the new property value
118:             */
119:            public void putField(Context context, Object target, String name,
120:                    Object value) {
121:                setBeanProperty(context, target, name, value);
122:            }
123:
124:            /**
125:             * Sets a Bean property of the specified bean.
126:             * 
127:             * @param context
128:             *            the context in which the property is read
129:             * @param target
130:             *            the target bean
131:             * @param name
132:             *            the Bean property name
133:             * @param value
134:             *            the new property value
135:             */
136:            protected void setBeanProperty(Context context, Object target,
137:                    String name, Object value) {
138:                try {
139:                    context.runtime.setBeanProperty(target, name, value,
140:                            stopClass);
141:                } catch (InvocationTargetException e1) {
142:                    throw new PnutsException(e1.getTargetException(), context);
143:                } catch (IllegalAccessException e2) {
144:                    throw new PnutsException(e2, context);
145:                }
146:            }
147:
148:            /**
149:             * Calls a method
150:             * 
151:             * @param context
152:             *            the contexct
153:             * @param c
154:             *            the class of the method
155:             * @param name
156:             *            the name of the method
157:             * @param args
158:             *            arguments
159:             * @param types
160:             *            type information of each arguments
161:             * @param target
162:             *            the target object of the method call
163:             * @return the result of the method call
164:             */
165:            public Object callMethod(Context context, Class c, String name,
166:                    Object args[], Class types[], Object target) {
167:                try {
168:                    return context.runtime._callMethod(context, c, name, args,
169:                            types, target);
170:                } catch (PnutsException pe) {
171:                    PnutsException.TraceInfo trace = new PnutsException.TraceInfo(
172:                            target, name, args, context.getScriptSource(),
173:                            context.beginLine, context.beginColumn);
174:                    pe.backtrace(trace);
175:                    throw pe;
176:                }
177:            }
178:
179:            /**
180:             * Calls a constructor
181:             * 
182:             * @param context
183:             *            the context
184:             * @param c
185:             *            class of the constructor
186:             * @param args
187:             *            the arguments
188:             * @param types
189:             *            type information of each arguments
190:             * @return the result
191:             */
192:            public Object callConstructor(Context context, Class c,
193:                    Object[] args, Class[] types) {
194:                try {
195:                    return context.runtime._callConstructor(context, c, args,
196:                            types);
197:                } catch (PnutsException pe) {
198:                    PnutsException.TraceInfo trace = new PnutsException.TraceInfo(
199:                            c, args, context.getScriptSource(),
200:                            context.beginLine, context.beginColumn);
201:                    pe.backtrace(trace);
202:                    throw pe;
203:                }
204:            }
205:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.