Source Code Cross Referenced for StrictStaticHandler.java in  » Database-ORM » beankeeper » hu » netmind » persistence » 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 » Database ORM » beankeeper » hu.netmind.persistence 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Copyright (C) 2006 NetMind Consulting Bt.
003:         *
004:         * This library is free software; you can redistribute it and/or
005:         * modify it under the terms of the GNU Lesser General Public
006:         * License as published by the Free Software Foundation; either
007:         * version 3 of the License, or (at your option) any later version.
008:         *
009:         * This library is distributed in the hope that it will be useful,
010:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
012:         * Lesser General Public License for more details.
013:         *
014:         * You should have received a copy of the GNU Lesser General Public
015:         * License along with this library; if not, write to the Free Software
016:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
017:         */package hu.netmind.persistence;
018:
019:        import java.util.HashMap;
020:        import java.util.Map;
021:        import java.util.List;
022:        import java.util.Vector;
023:        import java.util.Iterator;
024:        import java.lang.reflect.Field;
025:        import java.lang.reflect.Modifier;
026:        import org.apache.log4j.Logger;
027:        import java.util.Date;
028:
029:        /**
030:         * Information and transformations on a given class. This class 
031:         * implements reflecting of classes, and type knowledge.
032:         * @author Brautigam Robert
033:         * @version Revision: $Revision$
034:         */
035:        public class StrictStaticHandler implements  StrictClassHandler {
036:            private static Logger logger = Logger
037:                    .getLogger(StrictStaticHandler.class);
038:
039:            protected StoreContext context;
040:            protected ClassEntry sourceEntry;
041:            protected HashMap attributeTypes;
042:            private HashMap attributes;
043:
044:            StrictStaticHandler(StoreContext context, ClassEntry sourceEntry) {
045:                this .context = context;
046:                // Init
047:                this .sourceEntry = sourceEntry;
048:                attributes = new HashMap();
049:                attributeTypes = new HashMap();
050:                // If this class is a dynamic class, it has no static attributes!
051:                if (sourceEntry.getDynamicName() != null)
052:                    return;
053:                // Add this class' attribute to sets
054:                Field[] fields = sourceEntry.getSourceClass()
055:                        .getDeclaredFields();
056:                for (int i = 0; i < fields.length; i++) {
057:                    if ((!Modifier.isTransient(fields[i].getModifiers()))
058:                            && (!Modifier.isStatic(fields[i].getModifiers()))) {
059:                        String attributeName = fields[i].getName()
060:                                .toLowerCase();
061:                        fields[i].setAccessible(true);
062:                        attributes.put(attributeName, fields[i]);
063:                        attributeTypes.put(attributeName, fields[i].getType());
064:                    }
065:                }
066:            }
067:
068:            public static boolean hasStaticAttributes(ClassEntry entry) {
069:                StrictStaticHandler tmpHandler = new StrictStaticHandler(null,
070:                        entry);
071:                List attributeNames = tmpHandler.getAttributeNames();
072:                for (int i = 0; i < attributeNames.size(); i++)
073:                    if (!((String) attributeNames.get(i))
074:                            .startsWith("persistence"))
075:                        return true;
076:                return false;
077:            }
078:
079:            public ClassEntry getSourceEntry() {
080:                return sourceEntry;
081:            }
082:
083:            public boolean hasChanged() {
084:                return false;
085:            }
086:
087:            public Map getAttributeTypes() {
088:                return attributeTypes;
089:            }
090:
091:            public List getAttributeNames() {
092:                return new Vector(attributeTypes.keySet());
093:            }
094:
095:            /**
096:             * Get the attribute value from a given object of this class and 
097:             * from given attribute.
098:             */
099:            public Object getAttributeValue(Object obj, String attributeName) {
100:                Field field = (Field) attributes.get(attributeName
101:                        .toLowerCase());
102:                if (field == null)
103:                    return null;
104:                try {
105:                    return field.get(obj);
106:                } catch (Throwable e) {
107:                    throw new StoreException(
108:                            "object value cannot be get, name: "
109:                                    + attributeName, e);
110:                }
111:            }
112:
113:            /**
114:             * Return whether the given attribute name is a static attribute.
115:             */
116:            protected boolean isStatic(String attributeName) {
117:                return attributes.get(attributeName.toLowerCase()) != null;
118:            }
119:
120:            /**
121:             * Set an object as value into object given.
122:             */
123:            public void setAttributeValue(Object obj, String attributeName,
124:                    Object value) {
125:                Field field = (Field) attributes.get(attributeName
126:                        .toLowerCase());
127:                if (field == null)
128:                    return;
129:                Class attrClass = (Class) attributeTypes.get(attributeName
130:                        .toLowerCase());
131:                try {
132:                    field
133:                            .set(obj, ObjectTracker.getTypeValue(value,
134:                                    attrClass));
135:                } catch (Throwable e) {
136:                    Class valueClass = null;
137:                    if (value != null)
138:                        valueClass = value.getClass();
139:                    throw new StoreException(
140:                            "object value cannot be set, objectclass: "
141:                                    + obj.getClass() + " name: "
142:                                    + attributeName + " (class: " + attrClass
143:                                    + ", value: " + value + " (class: "
144:                                    + valueClass + "))", e);
145:                }
146:            }
147:
148:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.