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


001:        package org.andromda.repositories.emf;
002:
003:        import java.io.InputStream;
004:
005:        import java.net.URL;
006:
007:        import java.util.HashMap;
008:        import java.util.Iterator;
009:        import java.util.List;
010:        import java.util.Map;
011:
012:        import org.andromda.core.common.AndroMDALogger;
013:        import org.andromda.core.common.ResourceUtils;
014:        import org.apache.log4j.Logger;
015:        import org.eclipse.emf.common.util.URI;
016:        import org.eclipse.emf.ecore.resource.impl.URIConverterImpl;
017:
018:        /**
019:         * Extends the default URIConverterImpl to be able to discover the physical path of URIs when
020:         * given the moduleSearchPaths.
021:         *
022:         * @author Chad Brandon
023:         */
024:        public class EMFURIConverter extends URIConverterImpl {
025:            /**
026:             * Creates a new instance of EMFURIConvert taking the <code>moduleSearchPaths</code>
027:             * as an argument. These are the paths used to attempt to normalize a given URI during
028:             * the call to {@link #normalize(URI)} provided that it couldn't be found in the normal manner.
029:             *
030:             * @param moduleSearchPaths the paths to search for modules.
031:             */
032:            public EMFURIConverter(final List moduleSearchPaths) {
033:                this .moduleSearchPaths = moduleSearchPaths;
034:                if (logger.isDebugEnabled()) {
035:                    for (final Iterator pathIterator = this .moduleSearchPaths
036:                            .iterator(); pathIterator.hasNext();) {
037:                        logger
038:                                .debug("Model search path:"
039:                                        + pathIterator.next());
040:                    }
041:                }
042:            }
043:
044:            /**
045:             * Stores the module search paths.
046:             */
047:            private List moduleSearchPaths;
048:
049:            /**
050:             * Stores the URIs that have been normalized.
051:             */
052:            private final Map normalizedUris = new HashMap();
053:
054:            /**
055:             * The logger instance.
056:             */
057:            private static Logger logger = Logger
058:                    .getLogger(EMFURIConverter.class);
059:
060:            /**
061:             * Overridden to provide the normalization of uris given the module search paths.
062:             *
063:             * @see org.eclipse.emf.ecore.resource.URIConverter#normalize(org.eclipse.emf.common.util.URI)
064:             */
065:            public URI normalize(final URI uri) {
066:                URI normalizedUri = super .normalize(uri);
067:                if (normalizedUri.equals(uri)) {
068:                    if (this .moduleSearchPaths != null) {
069:                        if (!this .normalizedUris.containsKey(uri)) {
070:                            final String resourceName = uri.toString()
071:                                    .replaceAll(".*(\\\\+|/)", "");
072:                            for (final Iterator iterator = this .moduleSearchPaths
073:                                    .iterator(); iterator.hasNext();) {
074:                                final String searchPath = (String) iterator
075:                                        .next();
076:                                final URI fileURI = EMFRepositoryFacadeUtils
077:                                        .createUri(ResourceUtils
078:                                                .normalizePath(searchPath));
079:                                if (fileURI.lastSegment().equals(resourceName)) {
080:                                    AndroMDALogger
081:                                            .info("referenced model --> '"
082:                                                    + fileURI + "'");
083:                                    normalizedUri = fileURI;
084:                                    this .normalizedUris.put(uri, normalizedUri);
085:                                    break;
086:                                }
087:
088:                                final String completePath = ResourceUtils
089:                                        .normalizePath(searchPath + '/'
090:                                                + resourceName);
091:
092:                                try {
093:                                    InputStream stream;
094:                                    URL url = ResourceUtils.toURL(completePath);
095:                                    if (url != null) {
096:                                        try {
097:                                            stream = url.openStream();
098:                                            stream.close();
099:                                            AndroMDALogger
100:                                                    .info("referenced model --> '"
101:                                                            + url + "'");
102:                                        } catch (final Exception exception) {
103:                                            url = null;
104:                                        } finally {
105:                                            stream = null;
106:                                        }
107:                                        if (url != null) {
108:                                            normalizedUri = EMFRepositoryFacadeUtils
109:                                                    .createUri(url.toString());
110:                                            this .normalizedUris.put(uri,
111:                                                    normalizedUri);
112:                                            break;
113:                                        }
114:                                    }
115:                                } catch (final Exception exception) {
116:                                    logger
117:                                            .debug(
118:                                                    "Caught exception in EMFURIConverter",
119:                                                    exception);
120:                                }
121:                            }
122:
123:                            // - if the normalized URI isn't part of the module search path,
124:                            //   still store it so we don't continue to look it up each time (which is really slow)
125:                            if (!this .normalizedUris.containsKey(uri)) {
126:                                this .normalizedUris.put(uri, normalizedUri);
127:                            }
128:                        } else {
129:                            normalizedUri = (URI) this.normalizedUris.get(uri);
130:                        }
131:                    }
132:                }
133:
134:                return normalizedUri;
135:            }
136:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.