Source Code Cross Referenced for GlobalRelationStore.java in  » Testing » Ejb3Unit » com » bm » introspectors » relations » 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 » Testing » Ejb3Unit » com.bm.introspectors.relations 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.bm.introspectors.relations;
002:
003:        import java.lang.reflect.ParameterizedType;
004:        import java.util.HashMap;
005:        import java.util.HashSet;
006:        import java.util.Map;
007:        import java.util.Set;
008:
009:        import com.bm.introspectors.Property;
010:
011:        /**
012:         * The problems in finding releations using introspectors is to avaid cyclic
013:         * dependencies. This singelton is used as such a store of properties
014:         * (OneToMany, OneToOne,...) to avoid such dependencies
015:         * 
016:         * @author Daniel Wiese
017:         * 
018:         */
019:        public final class GlobalRelationStore {
020:
021:            private static final GlobalRelationStore singelton = new GlobalRelationStore();
022:
023:            private Map<Class, Set<Property>> store = new HashMap<Class, Set<Property>>();
024:
025:            private GlobalRelationStore() {
026:                // singelton constructor
027:            }
028:
029:            /**
030:             * Returns the singelton instance.
031:             * 
032:             * @return - the singelton instance
033:             */
034:            public static GlobalRelationStore getStore() {
035:                return singelton;
036:            }
037:
038:            /**
039:             * Save a property wich represents a relation in a class (bean).
040:             * 
041:             * @param forClass -
042:             *            the entity bean class
043:             * @param toSave -
044:             *            the property to save
045:             */
046:            public void put(Class forClass, Property toSave) {
047:                if (store.containsKey(forClass)) {
048:                    final Set<Property> tmp = store.get(forClass);
049:                    tmp.add(toSave);
050:                } else {
051:                    final Set<Property> tmp = new HashSet<Property>();
052:                    tmp.add(toSave);
053:                    store.put(forClass, tmp);
054:                }
055:            }
056:
057:            /**
058:             * Returns the property based on the class and the name.
059:             * 
060:             * @param forClass -
061:             *            the class where the property is in
062:             * @param propertyName -
063:             *            the name of the property
064:             * @return - the property or null (if not found)
065:             */
066:            public Property getProperty(Class forClass, String propertyName) {
067:
068:                if (store.containsKey(forClass)) {
069:                    final Set<Property> tmp = store.get(forClass);
070:                    for (Property akt : tmp) {
071:                        if (akt.getName().equals(propertyName)) {
072:                            return akt;
073:                        }
074:                    }
075:                }
076:
077:                return null;
078:            }
079:
080:            /**
081:             * Returns the releation properties for special class (entity bean).
082:             * 
083:             * @param forClass -
084:             *            the class where the property is in
085:             * @param forType -
086:             *            the type of the property
087:             * @return - the property or null (if not found)
088:             */
089:            public Property getProperty(Class forClass, Class forType) {
090:
091:                if (store.containsKey(forClass)) {
092:                    final Set<Property> tmp = store.get(forClass);
093:                    for (Property akt : tmp) {
094:                        // e.g clollections> we are searching the typed
095:                        if (akt.getType().equals(forType)
096:                                || this .isGenericTypeEqual(akt, forType)) {
097:                            return akt;
098:                        }
099:                    }
100:                }
101:
102:                return null;
103:            }
104:
105:            private boolean isGenericTypeEqual(Property aktProperty, Class clazz) {
106:                if (aktProperty.getGenericType() instanceof  ParameterizedType) {
107:                    final ParameterizedType type = (ParameterizedType) aktProperty
108:                            .getGenericType();
109:                    if (type.getActualTypeArguments().length == 1) {
110:                        Class<Object> ty = (Class<Object>) type
111:                                .getActualTypeArguments()[0];
112:                        if (ty.equals(clazz)) {
113:                            return true;
114:                        }
115:                    }
116:                }
117:                return false;
118:            }
119:
120:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.