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


001:        /*
002:         * PublicMemberAccessor.java
003:         *
004:         * Copyright (c) 1997-2007 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.ext;
010:
011:        import java.lang.reflect.Constructor;
012:        import java.lang.reflect.Field;
013:        import java.lang.reflect.Method;
014:        import java.security.AccessController;
015:        import java.security.PrivilegedAction;
016:        import java.security.PrivilegedActionException;
017:        import java.security.PrivilegedExceptionAction;
018:        import java.util.Map;
019:
020:        import pnuts.lang.Configuration;
021:        import pnuts.lang.Context;
022:        import pnuts.lang.PnutsException;
023:        import pnuts.lang.Property;
024:        import pnuts.lang.Runtime;
025:        import org.pnuts.util.*;
026:
027:        public class PublicMemberAccessor extends
028:                pnuts.lang.PublicMemberAccessor {
029:
030:            private transient Cache fieldCache = new MemoryCache();
031:
032:            public PublicMemberAccessor() {
033:            }
034:
035:            public PublicMemberAccessor(Configuration conf) {
036:                super (conf);
037:            }
038:
039:            /**
040:             * Gets a field value of the target object.
041:             * 
042:             * @param context
043:             *            the context in which the field is read
044:             * @param target
045:             *            the target object
046:             * @param name
047:             *            the field name
048:             * @return the field value
049:             */
050:            public Object getField(Context context, Object target, String name) {
051:                if (target instanceof  Context) {
052:                    return ((Context) target).get(name);
053:                } else if (target instanceof  Property) {
054:                    return ((Property) target).get(name, context);
055:                } else if (target instanceof  Map) {
056:                    return ((Map) target).get(name);
057:                } else {
058:                    return super .getField(context, target, name);
059:                }
060:            }
061:
062:            /**
063:             * Sets a field value of the specified object.
064:             * 
065:             * @param context  the context in which the field is written.
066:             * @param target  the target object
067:             * @param name  the field name
068:             * @param expr  the field value
069:             */
070:            public void putField(Context context, Object target, String name,
071:                    Object expr) {
072:                if (target instanceof  Context) {
073:                    ((Context) target).set(name, expr);
074:                } else if (target instanceof  Property) {
075:                    ((Property) target).set(name, expr, context);
076:                } else if (target instanceof  Map) {
077:                    ((Map) target).put(name, expr);
078:                } else {
079:                    super .putField(context, target, name, expr);
080:                }
081:            }
082:
083:            public Object getStaticField(Context context, Class clazz,
084:                    String name) {
085:                try {
086:                    return getField(clazz, name).get(null);
087:                } catch (PnutsException p) {
088:                    throw p;
089:                } catch (NoSuchFieldException f) {
090:                    throw new PnutsException("field.notFound", new Object[] {
091:                            name, clazz }, context);
092:                } catch (Throwable t) {
093:                    throw new PnutsException(t, context);
094:                }
095:            }
096:
097:            public void putStaticField(Context context, Class clazz,
098:                    String name, Object value) {
099:                try {
100:                    Field field = getField(clazz, name);
101:                    Class type = field.getType();
102:                    if (Runtime.isArray(value) && type.isArray()) {
103:                        if (!type.isInstance(value)) {
104:                            value = Runtime.transform(type, value, context);
105:                        }
106:                    }
107:                    field.set(null, value);
108:                } catch (PnutsException e0) {
109:                    throw e0;
110:                } catch (NoSuchFieldException f) {
111:                    throw new PnutsException("field.notFound", new Object[] {
112:                            name, clazz }, context);
113:                } catch (Throwable e) {
114:                    throw new PnutsException(e, context);
115:                }
116:            }
117:
118:            protected Field getField(final Class cls, final String name)
119:                    throws NoSuchFieldException {
120:                try {
121:                    return (Field) AccessController
122:                            .doPrivileged(new PrivilegedExceptionAction() {
123:                                public Object run() throws Exception {
124:                                    return cls.getField(name);
125:                                }
126:                            });
127:                } catch (PrivilegedActionException e) {
128:                    throw (NoSuchFieldException) e.getException();
129:                }
130:            }
131:
132:            public Method[] getMethods(final Class cls) {
133:                return (Method[]) AccessController
134:                        .doPrivileged(new PrivilegedAction() {
135:                            public Object run() {
136:                                return cls.getMethods();
137:                            }
138:                        });
139:            }
140:
141:            public Constructor[] getConstructors(final Class cls) {
142:                return (Constructor[]) AccessController
143:                        .doPrivileged(new PrivilegedAction() {
144:                            public Object run() {
145:                                return cls.getConstructors();
146:                            }
147:                        });
148:            }
149:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.