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


001:        package org.andromda.core.common;
002:
003:        import java.net.URL;
004:
005:        import java.util.ArrayList;
006:        import java.util.Collection;
007:        import java.util.HashMap;
008:        import java.util.Iterator;
009:        import java.util.Map;
010:
011:        import org.andromda.core.configuration.Namespaces;
012:        import org.apache.commons.lang.StringUtils;
013:        import org.apache.commons.lang.builder.ToStringBuilder;
014:        import org.apache.log4j.Logger;
015:
016:        /**
017:         * Contains the configuration of a template object which are objects that are
018:         * made available to the cartridge templates.
019:         *
020:         * @author Chad Brandon
021:         */
022:        public class TemplateObject {
023:            private static Logger logger = Logger
024:                    .getLogger(TemplateObject.class);
025:
026:            /**
027:             * The name of this template object made available to the
028:             * template.
029:             */
030:            private String name;
031:
032:            /**
033:             * Gets the current name of this TemplateObject.
034:             *
035:             * @return String
036:             */
037:            public String getName() {
038:                final String methodName = "TemplateObject.getName";
039:                if (StringUtils.isEmpty(this .name)) {
040:                    throw new TemplateObjectException(methodName
041:                            + " - templateObject '" + this 
042:                            + "' has no name defined");
043:                }
044:                return this .name;
045:            }
046:
047:            /**
048:             * Caches the template objects.
049:             */
050:            private final Map objectCache = new HashMap();
051:
052:            /**
053:             * Returns the actuall object instance described by this
054:             * template object.
055:             *
056:             * @return the actual object instance.
057:             */
058:            public Object getObject() {
059:                final String methodName = "TemplateObject.getTemplateObject";
060:                if (StringUtils.isEmpty(this .className)) {
061:                    throw new TemplateObjectException(methodName
062:                            + " - templateObject '" + this 
063:                            + "' has no className defined");
064:                }
065:                Object templateObject = this .objectCache.get(this .className);
066:                try {
067:                    if (templateObject == null) {
068:                        final Class templateObjectClass = ClassUtils
069:                                .loadClass(this .className);
070:                        templateObject = templateObjectClass.newInstance();
071:                        this .objectCache.put(this .className, templateObject);
072:                    }
073:
074:                    // - we want to set the properties each time we retrieve (in case they've changed)
075:                    this .setProperties(templateObject);
076:                } catch (final Throwable throwable) {
077:                    throw new TemplateObjectException(throwable);
078:                }
079:                return templateObject;
080:            }
081:
082:            /**
083:             * Sets all the nested properties on the templateObject object.
084:             *
085:             * @param templateObject the template object on which to populate properties.
086:             */
087:            protected void setProperties(final Object templateObject) {
088:                for (final Iterator iterator = propertyReferences.iterator(); iterator
089:                        .hasNext();) {
090:                    final String reference = (String) iterator.next();
091:                    String value = Namespaces.instance().getPropertyValue(
092:                            this .getNamespace(), reference);
093:                    if (value != null) {
094:                        if (this .getLogger().isDebugEnabled()) {
095:                            this .getLogger().debug(
096:                                    "populating template object '" + this .name
097:                                            + "' property '" + reference
098:                                            + "' with value '" + value
099:                                            + "' for namespace '" + namespace
100:                                            + "'");
101:                        }
102:                        try {
103:                            Introspector.instance().setProperty(templateObject,
104:                                    reference, value);
105:                        } catch (final Exception exception) {
106:                            // - don't throw the exception
107:                            final String message = "Error setting property '"
108:                                    + reference + "' with '" + value
109:                                    + "' on templateObject --> '"
110:                                    + templateObject + "'";
111:                            logger.warn(message);
112:                        }
113:                    }
114:                }
115:            }
116:
117:            /**
118:             * Sets the name of the template object (this name will be what the template class is stored under in the template)
119:             *
120:             * @param name the name of the template object.
121:             */
122:            public void setName(final String name) {
123:                this .name = StringUtils.trimToEmpty(name);
124:            }
125:
126:            /**
127:             * The name of the class for this template object.
128:             */
129:            private String className;
130:
131:            /**
132:             * Sets the class of the transformation object.
133:             *
134:             * @param className the name of the template object class.
135:             */
136:            public void setClassName(final String className) {
137:                ExceptionUtils.checkEmpty("className", className);
138:                this .className = className;
139:            }
140:
141:            /**
142:             * The property references that configure this template object.
143:             */
144:            private final Collection propertyReferences = new ArrayList();
145:
146:            /**
147:             * Adds a templateObject property reference (used to customize templateObjects). Property references are used to
148:             * populate bean like properties of template objects.
149:             *
150:             * @param reference the name of the property reference.
151:             */
152:            public void addPropertyReference(final String reference) {
153:                this .propertyReferences.add(reference);
154:            }
155:
156:            /**
157:             * The resource in which the template object was found.
158:             */
159:            private URL resource;
160:
161:            /**
162:             * The resource in which the templateObject was found.
163:             *
164:             * @return the resource as a URL.
165:             */
166:            public URL getResource() {
167:                return resource;
168:            }
169:
170:            /**
171:             * Sets the resource in which the templateObject was defined.
172:             *
173:             * @param resource the resource on which this template object was defined.
174:             */
175:            public void setResource(final URL resource) {
176:                this .resource = resource;
177:            }
178:
179:            /**
180:             * The namespace to which this template object belongs.
181:             */
182:            private String namespace;
183:
184:            /**
185:             * Gets the namespace to which this template object belongs.
186:             *
187:             * @return Returns the namespace.
188:             */
189:            public String getNamespace() {
190:                return namespace;
191:            }
192:
193:            /**
194:             * Sets the namespace to which this template object belongs.
195:             *
196:             * @param namespace The namespace to set.
197:             */
198:            public void setNamespace(final String namespace) {
199:                this .namespace = StringUtils.trimToEmpty(namespace);
200:            }
201:
202:            /**
203:             * Gets the namespace logger (the logger under which output for this
204:             * template object should be written).
205:             *
206:             * @return the logger instance.
207:             */
208:            protected Logger getLogger() {
209:                return AndroMDALogger.getNamespaceLogger(this .namespace);
210:            }
211:
212:            /**
213:             * @see java.lang.Object#toString()
214:             */
215:            public String toString() {
216:                return ToStringBuilder.reflectionToString(this);
217:            }
218:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.