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


001:        package org.andromda.core.configuration;
002:
003:        import org.andromda.core.common.ResourceUtils;
004:        import org.andromda.core.common.XmlObjectFactory;
005:        import org.andromda.core.mapping.Mappings;
006:        import org.apache.commons.lang.StringUtils;
007:
008:        import java.io.InputStream;
009:        import java.io.InputStreamReader;
010:        import java.io.Serializable;
011:        import java.net.URL;
012:        import java.util.ArrayList;
013:        import java.util.Arrays;
014:        import java.util.Collection;
015:        import java.util.Iterator;
016:
017:        /**
018:         * This object is configured from the AndroMDA configuration
019:         * XML file.  Its used to configure AndroMDA before modeling
020:         * processing occurs.
021:         *
022:         * @author Chad Brandon
023:         */
024:        public class Configuration implements  Serializable {
025:            /**
026:             * Gets a Configuration instance from the given <code>uri</code>.
027:             *
028:             * @param uri the URI to the configuration file.
029:             * @return the configured instance.
030:             */
031:            public static Configuration getInstance(final URL uri) {
032:                final Configuration configuration = (Configuration) XmlObjectFactory
033:                        .getInstance(Configuration.class).getObject(uri);
034:                configuration.setContents(ResourceUtils.getContents(uri));
035:                return configuration;
036:            }
037:
038:            /**
039:             * Gets a Configuration instance from the given <code>stream</code>.
040:             *
041:             * @param stream the InputStream containing the configuration file.
042:             * @return the configured instance.
043:             */
044:            public static Configuration getInstance(final InputStream stream) {
045:                final Configuration configuration = (Configuration) XmlObjectFactory
046:                        .getInstance(Configuration.class).getObject(
047:                                new InputStreamReader(stream));
048:                configuration.setContents(ResourceUtils
049:                        .getContents(new InputStreamReader(stream)));
050:                return configuration;
051:            }
052:
053:            /**
054:             * Gets a Configuration instance from the given <code>string</code>.
055:             *
056:             * @param string the String containing the configuration.
057:             * @return the configured instance.
058:             */
059:            public static Configuration getInstance(final String string) {
060:                final Configuration configuration = (Configuration) XmlObjectFactory
061:                        .getInstance(Configuration.class).getObject(string);
062:                configuration.setContents(string);
063:                return configuration;
064:            }
065:
066:            /**
067:             * Initializes this configuration instance.
068:             */
069:            public void initialize() {
070:                this .initializeNamespaces();
071:                this .initializeMappings();
072:            }
073:
074:            /**
075:             * Stores the repositories for this Configuration instance.
076:             */
077:            private final Collection repositories = new ArrayList();
078:
079:            /**
080:             * Adds the repository to this configuration.
081:             *
082:             * @param repository the repository instance.
083:             */
084:            public void addRepository(final Repository repository) {
085:                this .repositories.add(repository);
086:            }
087:
088:            /**
089:             * Gets the repository instances belonging to this configuration.
090:             *
091:             * @return the collection of repository instances.
092:             */
093:            public Repository[] getRepositories() {
094:                return (Repository[]) this .repositories
095:                        .toArray(new Repository[0]);
096:            }
097:
098:            /**
099:             * Stores the configuration namespaces.
100:             */
101:            private final Collection namespaces = new ArrayList();
102:
103:            /**
104:             * Adds a namespace to this configuration.
105:             *
106:             * @param namespace the configured namespace to add.
107:             */
108:            public void addNamespace(final Namespace namespace) {
109:                this .namespaces.add(namespace);
110:            }
111:
112:            /**
113:             * Gets the configuration namespaces.
114:             *
115:             * @return the array of {@link Namespace} instances.
116:             */
117:            public Namespace[] getNamespaces() {
118:                return (Namespace[]) this .namespaces.toArray(new Namespace[0]);
119:            }
120:
121:            /**
122:             * Stores the properties for this configuration (these
123:             * gobally configure AndroMDA).
124:             */
125:            private final Collection properties = new ArrayList();
126:
127:            /**
128:             * Adds a property to this configuration instance.
129:             *
130:             * @param property the property to add.
131:             */
132:            public void addProperty(final Property property) {
133:                this .properties.add(property);
134:            }
135:
136:            /**
137:             * Gets the properties belonging to this configuration.
138:             *
139:             * @return the collection of {@link Property} instances.
140:             */
141:            public Property[] getProperties() {
142:                return (Property[]) this .properties.toArray(new Property[0]);
143:            }
144:
145:            /**
146:             * Stores the AndroMDA server configuration information.
147:             */
148:            private Server server;
149:
150:            /**
151:             * Sets the server instance for this configuration.
152:             *
153:             * @param server the information which configures the AndroMDA server.
154:             */
155:            public void setServer(final Server server) {
156:                this .server = server;
157:            }
158:
159:            /**
160:             * Gets the server instance for this configuration.
161:             * The {@link Server} holds the information to configure
162:             * the AndroMDA server.
163:             *
164:             * @return the andromda server.
165:             */
166:            public Server getServer() {
167:                return this .server;
168:            }
169:
170:            /**
171:             * The locations in which to search for mappings.
172:             */
173:            private final Collection mappingsSearchLocations = new ArrayList();
174:
175:            /**
176:             * Adds a mappings search location (these are the locations
177:             * in which a search for mappings is performed).
178:             *
179:             * @param location a location path.
180:             * @see #addMappingsSearchLocation(String)
181:             */
182:            public void addMappingsSearchLocation(final Location location) {
183:                if (location != null) {
184:                    this .mappingsSearchLocations.add(location);
185:                }
186:            }
187:
188:            /**
189:             * Adds a mappings search location path (a location
190:             * without a pattern defined).
191:             *
192:             * @param path a location path.
193:             * @see #addMappingsSearchLocation(Location)
194:             */
195:            public void addMappingsSearchLocation(final String path) {
196:                if (path != null) {
197:                    final Location location = new Location();
198:                    location.setPath(path);
199:                    this .mappingsSearchLocations.add(location);
200:                }
201:            }
202:
203:            /**
204:             * Gets the mappings search locations for this configuration instance.
205:             *
206:             * @return the mappings search locations.
207:             */
208:            public Location[] getMappingsSearchLocations() {
209:                return (Location[]) this .mappingsSearchLocations
210:                        .toArray(new Location[0]);
211:            }
212:
213:            /**
214:             * Stores the contents of the configuration as a string.
215:             */
216:            private String contents = null;
217:
218:            /**
219:             * Gets the URI from which this instance was
220:             * configured or null (it it was not set).
221:             * @return the URI as a String instance
222:             */
223:            public String getContents() {
224:                return this .contents;
225:            }
226:
227:            /**
228:             * Clears out any caches used by this configuration.
229:             */
230:            public static void clearCaches() {
231:                Model.clearLastModifiedTimes();
232:            }
233:
234:            /**
235:             * Sets the contents of this configuration as a
236:             * string.
237:             * @param contents the contents of this configuration as a string.
238:             */
239:            private void setContents(final String contents) {
240:                this .contents = StringUtils.trimToEmpty(contents);
241:            }
242:
243:            /**
244:             * Initializes the namespaces with the namespaces from
245:             * this configuration.
246:             */
247:            private void initializeNamespaces() {
248:                final Namespaces namespaces = Namespaces.instance();
249:                namespaces.clear();
250:                namespaces.addNamespaces(this .getNamespaces());
251:            }
252:
253:            /**
254:             * Loads all mappings from the specified mapping search locations.
255:             * If the location points to a directory the directory
256:             * contents will be loaded, otherwise just the mapping itself will be loaded.
257:             */
258:            private void initializeMappings() {
259:                if (this .mappingsSearchLocations != null) {
260:                    final Collection mappingsLocations = new ArrayList();
261:                    final Location[] locations = this 
262:                            .getMappingsSearchLocations();
263:                    for (int ctr = 0; ctr < locations.length; ctr++) {
264:                        mappingsLocations.addAll(Arrays.asList(locations[ctr]
265:                                .getResources()));
266:                    }
267:
268:                    // clear out any old cached mappings
269:                    Mappings.clearLogicalMappings();
270:
271:                    for (final Iterator iterator = mappingsLocations.iterator(); iterator
272:                            .hasNext();) {
273:                        try {
274:                            Mappings.addLogicalMappings((URL) iterator.next());
275:                        } catch (final Throwable throwable) {
276:                            // - ignore the exception (probably means its a file
277:                            //   other than a mapping and in that case we don't care)
278:                        }
279:                    }
280:                    // - now initialize the logical mappings since we've found them all
281:                    Mappings.initializeLogicalMappings();
282:                }
283:            }
284:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.