Source Code Cross Referenced for RouterManager.java in  » ESB » celtix-1.0 » org » objectweb » celtix » routing » 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 » ESB » celtix 1.0 » org.objectweb.celtix.routing 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.objectweb.celtix.routing;
002:
003:        import java.io.File;
004:        import java.io.IOException;
005:        import java.net.MalformedURLException;
006:        import java.net.URL;
007:        import java.net.URLClassLoader;
008:        import java.util.ArrayList;
009:        import java.util.List;
010:
011:        import javax.wsdl.Definition;
012:        import javax.wsdl.WSDLException;
013:        import javax.xml.ws.WebServiceException;
014:
015:        import org.objectweb.celtix.Bus;
016:        import org.objectweb.celtix.BusException;
017:        import org.objectweb.celtix.configuration.Configuration;
018:        import org.objectweb.celtix.configuration.ConfigurationBuilder;
019:        import org.objectweb.celtix.configuration.ConfigurationBuilderFactory;
020:        import org.objectweb.celtix.routing.configuration.UrlListPolicy;
021:        import org.objectweb.celtix.tools.WSDLToJava;
022:        import org.objectweb.celtix.tools.common.ToolConstants;
023:        import org.objectweb.celtix.tools.common.toolspec.ToolRunner;
024:
025:        public class RouterManager {
026:            public static final String ROUTING_CONFIGURATION_URI = "http://celtix.objectweb.org/routing/configuration";
027:            public static final String ROUTING_CONFIGURATION_ID = "router";
028:            public static final String ROUTING_WSDL_ID = "routesWSDL";
029:            public static final String ROUTER_CONFIG_RESOURCE = "config-metadata/router-config.xml";
030:            private final Bus bus;
031:            private final Configuration config;
032:            private URLClassLoader seiClassLoader;
033:            private RouterFactory factory;
034:            private List<Definition> wsdlModelList;
035:            private List<Router> routerList;
036:
037:            public RouterManager(Bus b) {
038:                bus = b;
039:                config = createConfiguration();
040:                wsdlModelList = new ArrayList<Definition>();
041:                routerList = new ArrayList<Router>();
042:            }
043:
044:            private Configuration createConfiguration() {
045:
046:                Configuration busCfg = bus.getConfiguration();
047:                assert null != busCfg;
048:                Configuration cfg = null;
049:                ConfigurationBuilder cb = ConfigurationBuilderFactory
050:                        .getBuilder(null);
051:                cb.addModel(ROUTER_CONFIG_RESOURCE);
052:                cfg = cb.getConfiguration(ROUTING_CONFIGURATION_URI,
053:                        ROUTING_CONFIGURATION_ID, busCfg);
054:                if (null == cfg) {
055:                    cfg = cb.buildConfiguration(ROUTING_CONFIGURATION_URI,
056:                            ROUTING_CONFIGURATION_ID, busCfg);
057:                }
058:                return cfg;
059:            }
060:
061:            private URLClassLoader createSEIClassLoader(File classDir) {
062:
063:                URLClassLoader loader = null;
064:                try {
065:                    loader = URLClassLoader.newInstance(new URL[] { classDir
066:                            .toURL() }, Thread.currentThread()
067:                            .getContextClassLoader());
068:                } catch (MalformedURLException mue) {
069:                    throw new WebServiceException(
070:                            "URLClassLoader creation failed", mue);
071:                }
072:
073:                return loader;
074:            }
075:
076:            private void loadWSDL() {
077:                try {
078:                    List<String> wsdlUrlList = getRouteWSDLList();
079:                    for (String wsdlUrl : wsdlUrlList) {
080:                        URL url = getClass().getResource(wsdlUrl);
081:                        //String url = getFile(wsdlUrl);
082:                        wsdlModelList.add(bus.getWSDLManager().getDefinition(
083:                                url));
084:                    }
085:                } catch (WSDLException we) {
086:                    throw new WebServiceException("Could not load router wsdl",
087:                            we);
088:                }
089:            }
090:
091:            private void addRoutes() {
092:                for (Definition def : wsdlModelList) {
093:                    List<Router> rList = factory.addRoutes(def);
094:                    routerList.addAll(rList);
095:                }
096:            }
097:
098:            protected void publishRoutes() {
099:                for (Router r : routerList) {
100:                    r.publish();
101:                }
102:            }
103:
104:            protected void invokeWSDLToJava(File srcDir, File classDir) {
105:                List<String> wsdlUrlList = getRouteWSDLList();
106:
107:                for (String wsdlUrl : wsdlUrlList) {
108:                    invokeWSDLToJava(wsdlUrl, srcDir, classDir);
109:                }
110:            }
111:
112:            private void invokeWSDLToJava(String wsdlUrl, File srcDir,
113:                    File classDir) {
114:                try {
115:                    String file = getFile(wsdlUrl);
116:                    if (null != file) {
117:                        String[] args = new String[] { "-compile", "-d",
118:                                srcDir.getCanonicalPath(), "-classdir",
119:                                classDir.getCanonicalPath(), file };
120:
121:                        ToolRunner
122:                                .runTool(
123:                                        WSDLToJava.class,
124:                                        WSDLToJava.class
125:                                                .getResourceAsStream(ToolConstants.TOOLSPECS_BASE
126:                                                        + "wsdl2java.xml"),
127:                                        false, args);
128:                    }
129:                } catch (Exception ex) {
130:                    throw new WebServiceException("wsdl2java exception", ex);
131:                }
132:            }
133:
134:            private String getFile(String wsdlUrl) {
135:                try {
136:                    URL url = getClass().getResource(wsdlUrl);
137:                    File f = new File(url.getFile());
138:                    if (f.exists()) {
139:                        wsdlUrl = f.getCanonicalPath();
140:                    }
141:                } catch (IOException ioe) {
142:                    throw new WebServiceException("Could not load wsdl", ioe);
143:                }
144:                return wsdlUrl;
145:            }
146:
147:            private void mkDir(File dir) {
148:                if (dir == null) {
149:                    throw new WebServiceException("Could not create dir");
150:                }
151:
152:                if (dir.isFile()) {
153:                    throw new WebServiceException(
154:                            "Unable to create directory as a file "
155:                                    + "already exists with that name: "
156:                                    + dir.getAbsolutePath());
157:                }
158:
159:                if (!dir.exists()) {
160:                    dir.mkdirs();
161:                }
162:            }
163:
164:            public void init() {
165:                factory = new RouterFactory(this );
166:                factory.init(bus);
167:
168:                loadWSDL();
169:
170:                File opDir = new File(System.getProperty("user.dir"),
171:                        "/celtix-router-tmp");
172:                File classDir = new File(opDir, "/classes");
173:                mkDir(classDir);
174:
175:                invokeWSDLToJava(opDir, classDir);
176:                seiClassLoader = createSEIClassLoader(classDir);
177:
178:                addRoutes();
179:                publishRoutes();
180:            }
181:
182:            public List<String> getRouteWSDLList() {
183:                UrlListPolicy urlList = config.getObject(UrlListPolicy.class,
184:                        ROUTING_WSDL_ID);
185:                if (null == urlList) {
186:                    throw new WebServiceException("Router WSDL not specified");
187:                }
188:                return urlList.getUrl();
189:            }
190:
191:            public RouterFactory getRouterFactory() {
192:                return factory;
193:            }
194:
195:            public List<Router> getRouters() {
196:                return routerList;
197:            }
198:
199:            public URLClassLoader getSEIClassLoader() {
200:                return seiClassLoader;
201:            }
202:
203:            public static void main(String[] args) {
204:                try {
205:                    Bus bus = Bus.init(args);
206:                    RouterManager rm = new RouterManager(bus);
207:                    rm.init();
208:                    bus.run();
209:                } catch (BusException be) {
210:                    throw new WebServiceException("Could not initialize bus",
211:                            be);
212:                }
213:            }
214:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.