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


001:        package org.andromda.maven;
002:
003:        import java.io.FileNotFoundException;
004:
005:        import java.net.MalformedURLException;
006:        import java.net.URL;
007:
008:        import java.util.ArrayList;
009:        import java.util.Collection;
010:
011:        import org.andromda.core.AndroMDA;
012:        import org.andromda.core.AndroMDAServer;
013:        import org.andromda.core.common.ResourceUtils;
014:        import org.andromda.core.configuration.Configuration;
015:        import org.apache.commons.collections.CollectionUtils;
016:        import org.apache.commons.jelly.JellyContext;
017:        import org.apache.commons.jelly.expression.Expression;
018:        import org.apache.commons.lang.StringUtils;
019:        import org.apache.commons.lang.exception.ExceptionUtils;
020:        import org.apache.maven.jelly.MavenJellyContext;
021:
022:        /**
023:         * This bean is used with the AndroMDA Maven plugin.
024:         *
025:         * @author Chad Brandon
026:         * @see org.andromda.core.engine.ModelProcessor
027:         */
028:        public class AndroMDARunner {
029:            /**
030:             * The URI to the configuration;
031:             */
032:            private String configurationUri;
033:
034:            /**
035:             * Sets the URI to the configuration file.
036:             *
037:             * @param configurationUri
038:             */
039:            public void setConfigurationUri(final String configurationUri) {
040:                this .configurationUri = configurationUri;
041:            }
042:
043:            /**
044:             * Stores the search location for mapping files.
045:             */
046:            private String mappingsSearchLocation;
047:
048:            /**
049:             * Sets the mappings search location.
050:             *
051:             * @param MappingsSearchLocation
052:             */
053:            public void setMappingsSearchLocation(
054:                    final String mappingsSearchLocation) {
055:                this .mappingsSearchLocation = mappingsSearchLocation;
056:            }
057:
058:            /**
059:             *  Runs AndroMDA.
060:             */
061:            public String run() {
062:                // - since maven doesn't fail on exceptions on this method (for some reason)
063:                //   we'll save the error message and if present call ant fail from within
064:                //   the plugin jelly.
065:                String message = null;
066:                Thread.currentThread().setContextClassLoader(
067:                        AndroMDARunner.class.getClassLoader());
068:                try {
069:                    final AndroMDA andromda = AndroMDA.newInstance();
070:                    andromda.run(this .getConfiguration());
071:                    andromda.shutdown();
072:                } catch (Throwable throwable) {
073:                    final Throwable cause = ExceptionUtils.getCause(throwable);
074:                    if (cause != null) {
075:                        throwable = cause;
076:                    }
077:                    if (throwable instanceof  FileNotFoundException) {
078:                        message = "No configuration could be loaded from --> '"
079:                                + configurationUri + "'";
080:                    } else if (throwable instanceof  MalformedURLException) {
081:                        message = "Configuration is not a valid URI --> '"
082:                                + configurationUri + "'";
083:                    }
084:                    throwable.printStackTrace();
085:                    message = throwable.toString();
086:                } finally {
087:                    // Set the context class loader back ot its system class loaders
088:                    // so that any processes running after won't be trying to use
089:                    // the ContextClassLoader for this class.
090:                    Thread.currentThread().setContextClassLoader(
091:                            ClassLoader.getSystemClassLoader());
092:                }
093:                return message;
094:            }
095:
096:            /**
097:             * Creates the Configuration instance from the {@link #configurationUri}
098:             * @return the configuration instance
099:             * @throws MalformedURLException if the URL is invalid.
100:             */
101:            private Configuration getConfiguration()
102:                    throws MalformedURLException {
103:                final URL uri = ResourceUtils.toURL(this .configurationUri);
104:                ;
105:                final Configuration configuration = Configuration
106:                        .getInstance(this .replaceProperties(ResourceUtils
107:                                .getContents(uri)));
108:                configuration
109:                        .addMappingsSearchLocation(this .mappingsSearchLocation);
110:                return configuration;
111:            }
112:
113:            /**
114:             * The server instance.
115:             */
116:            private AndroMDAServer server = AndroMDAServer.newInstance();
117:
118:            /**
119:             * Starts the AndroMDA server instance listening
120:             * for requests.
121:             *
122:             * @throws MalformedURLException
123:             */
124:            public void startServer() throws MalformedURLException {
125:                this .server.start(this .getConfiguration());
126:            }
127:
128:            /**
129:             * Stops the AndroMDA server instance.
130:             */
131:            public void stopServer() throws MalformedURLException {
132:                this .server.stop(this .getConfiguration());
133:            }
134:
135:            /**
136:             * The maven jelly context.
137:             */
138:            private MavenJellyContext context;
139:
140:            /**
141:             * Sets the maven jelly context for this instance.
142:             */
143:            public void setContext(MavenJellyContext context) {
144:                this .context = context;
145:            }
146:
147:            /**
148:             * Gets all property names.
149:             *
150:             * @return the property names.
151:             */
152:            public String[] getPropertyNames() {
153:                final Collection properties = new ArrayList();
154:                for (JellyContext context = this .context; context != null; context = context
155:                        .getParent()) {
156:                    CollectionUtils.addAll(properties, context
157:                            .getVariableNames());
158:                }
159:                return (String[]) properties.toArray(new String[0]);
160:            }
161:
162:            /**
163:             * Replaces all properties having the style
164:             * <code>${some.property}</code> with the value
165:             * of the specified property if there is one.
166:             *
167:             * @param fileContents the fileContents to perform replacement on.
168:             */
169:            protected String replaceProperties(String string) {
170:                final String[] names = this .getPropertyNames();
171:                if (names != null && names.length > 0) {
172:                    for (int ctr = 0; ctr < names.length; ctr++) {
173:                        String value = null;
174:                        final String name = names[ctr];
175:                        final String property = "${" + name + "}";
176:                        Object object = this .context.getVariable(name);
177:                        if (object instanceof  String) {
178:                            value = (String) object;
179:                        } else if (object instanceof  Expression) {
180:                            value = ((Expression) object).getExpressionText();
181:                        }
182:                        if (value != null) {
183:                            string = StringUtils.replace(string, property,
184:                                    value);
185:                        }
186:                    }
187:                }
188:
189:                // remove any left over property references
190:                string = AndroMDAMavenUtils.removePropertyReferences(string);
191:                return string;
192:            }
193:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.