Source Code Cross Referenced for MetafacadeUtils.java in  » UML » AndroMDA-3.2 » org » andromda » core » metafacade » 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 » UML » AndroMDA 3.2 » org.andromda.core.metafacade 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.andromda.core.metafacade;
002:
003:        import java.lang.reflect.Constructor;
004:
005:        import java.util.Collection;
006:        import java.util.Iterator;
007:        import java.util.Map;
008:
009:        import org.andromda.core.common.ClassUtils;
010:        import org.andromda.core.common.Introspector;
011:        import org.andromda.core.configuration.Namespaces;
012:        import org.apache.log4j.Logger;
013:
014:        /**
015:         * Contains static utility methods for dealing with metafacade instances.
016:         *
017:         * @author Chad Brandon
018:         */
019:        final class MetafacadeUtils {
020:            /**
021:             * Indicates whether or not the mapping properties (present on the mapping, if any) are valid on the
022:             * <code>metafacade</code>.
023:             *
024:             * @param metafacade the metafacade instance on which the properties will be validated.
025:             * @param mapping the MetafacadeMapping instance that contains the properties.
026:             * @return true/false
027:             */
028:            static boolean propertiesValid(final MetafacadeBase metafacade,
029:                    final MetafacadeMapping mapping) {
030:                boolean valid = false;
031:                final Collection propertyGroups = mapping
032:                        .getMappingPropertyGroups();
033:                if (propertyGroups != null && !propertyGroups.isEmpty()) {
034:                    try {
035:                        if (getLogger().isDebugEnabled()) {
036:                            getLogger()
037:                                    .debug(
038:                                            "evaluating "
039:                                                    + propertyGroups.size()
040:                                                    + " property groups(s) on metafacade '"
041:                                                    + metafacade + "'");
042:                        }
043:                        final Introspector introspector = Introspector
044:                                .instance();
045:                        for (final Iterator tterator = propertyGroups
046:                                .iterator(); tterator.hasNext();) {
047:                            final MetafacadeMapping.PropertyGroup propertyGroup = (MetafacadeMapping.PropertyGroup) tterator
048:                                    .next();
049:                            for (final Iterator propertyIterator = propertyGroup
050:                                    .getProperties().iterator(); propertyIterator
051:                                    .hasNext();) {
052:                                final MetafacadeMapping.Property property = (MetafacadeMapping.Property) propertyIterator
053:                                        .next();
054:                                valid = introspector.containsValidProperty(
055:                                        metafacade, property.getName(),
056:                                        property.getValue());
057:                                if (getLogger().isDebugEnabled()) {
058:                                    getLogger().debug(
059:                                            "property '" + property.getName()
060:                                                    + "', with value '"
061:                                                    + property.getValue()
062:                                                    + "' on metafacade '"
063:                                                    + metafacade
064:                                                    + "', evaluated to --> '"
065:                                                    + valid + "'");
066:                                }
067:
068:                                // - if the property is invalid, we break out
069:                                //   of the loop (since we're evaluating with 'AND')
070:                                if (!valid) {
071:                                    break;
072:                                }
073:                            }
074:
075:                            // - we break on the first true value since
076:                            //   property groups are evaluated as 'OR'
077:                            if (valid) {
078:                                break;
079:                            }
080:                        }
081:                    } catch (final Throwable throwable) {
082:                        if (getLogger().isDebugEnabled()) {
083:                            getLogger()
084:                                    .debug(
085:                                            "An error occured while "
086:                                                    + "evaluating properties on metafacade '"
087:                                                    + metafacade
088:                                                    + "', setting valid to 'false'",
089:                                            throwable);
090:                        }
091:                        valid = false;
092:                    }
093:                    if (getLogger().isDebugEnabled()) {
094:                        getLogger().debug(
095:                                "completed evaluating " + propertyGroups.size()
096:                                        + " properties on metafacade '"
097:                                        + metafacade
098:                                        + "' with a result of --> '" + valid
099:                                        + "'");
100:                    }
101:                }
102:                return valid;
103:            }
104:
105:            /**
106:             * Constructs a new <code>metafacade</code> from the given
107:             * <code>metafacadeClass</code> and <code>mappingObject</code>.
108:             *
109:             * @param metafacadeClass the metafacade class.
110:             * @param mappingObject the object to which the metafacade is mapped.
111:             * @return the new metafacade.
112:             * @throws Exception if any error occurs during metafacade creation
113:             */
114:            static MetafacadeBase constructMetafacade(
115:                    final Class metafacadeClass, final Object mappingObject,
116:                    final String context) throws Exception {
117:                if (getLogger().isDebugEnabled()) {
118:                    getLogger().debug(
119:                            "constructing metafacade from class '"
120:                                    + metafacadeClass + "' mapping object '"
121:                                    + mappingObject + "', and context '"
122:                                    + context + "'");
123:                }
124:                final Constructor constructor = metafacadeClass
125:                        .getDeclaredConstructors()[0];
126:                return (MetafacadeBase) constructor.newInstance(new Object[] {
127:                        mappingObject, context });
128:            }
129:
130:            /**
131:             * Retrieves the inherited mapping class name for the given <code>mapping</code> by traveling 
132:             * up the inheritance hiearchy to find the first one that has the mapping class name declared.
133:             *
134:             * @param mapping the {@link MetafacadeMapping} instance for which we'll retrieve it's mapping class.
135:             * @return the name of the mapping class.
136:             */
137:            public static String getInheritedMappingClassName(
138:                    final MetafacadeMapping mapping) {
139:                final Class metafacadeClass = mapping.getMetafacadeClass();
140:                final Collection interfaces = ClassUtils
141:                        .getAllInterfaces(metafacadeClass);
142:                final MetafacadeImpls metafacadeImpls = MetafacadeImpls
143:                        .instance();
144:                final Map mappingInstances = MetafacadeMappings
145:                        .getAllMetafacadeMappingInstances();
146:                String className = null;
147:                for (final Iterator iterator = interfaces.iterator(); iterator
148:                        .hasNext()
149:                        && className == null;) {
150:                    final String metafacadeInterface = ((Class) iterator.next())
151:                            .getName();
152:                    final Class metafacadeImplClass = metafacadeImpls
153:                            .getMetafacadeImplClass(metafacadeInterface);
154:                    className = (String) mappingInstances
155:                            .get(metafacadeImplClass);
156:                }
157:                if (className == null) {
158:                    throw new MetafacadeMappingsException(
159:                            "No mapping class could be found for '"
160:                                    + metafacadeClass.getName() + "'");
161:                }
162:                return className;
163:            }
164:
165:            /**
166:             * Indicates whether or not a metafacade model facade is present within the 
167:             * given namespace
168:             * 
169:             * @param namespace the namespace to check.
170:             * @return true/false
171:             */
172:            public static boolean isMetafacadeModelPresent(
173:                    final String namespace) {
174:                boolean present = false;
175:                if (ClassUtils.isClassOfTypePresent(Namespaces.instance()
176:                        .getResourceRoots(namespace), ModelAccessFacade.class)) {
177:                    present = true;
178:                }
179:                return present;
180:            }
181:
182:            /**
183:             * Gets the logger instance which should be used for logging output within this class.
184:             *
185:             * @return the logger instance.
186:             */
187:            private static Logger getLogger() {
188:                return MetafacadeFactory.getInstance().getLogger();
189:            }
190:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.