Source Code Cross Referenced for ServiceManager.java in  » XML-UI » xui32 » com » xoetrope » carousel » services » 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 » XML UI » xui32 » com.xoetrope.carousel.services 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.xoetrope.carousel.services;
002:
003:        import java.io.File;
004:        import java.io.FileNotFoundException;
005:        import java.io.FileReader;
006:        import java.io.FileWriter;
007:
008:        import net.xoetrope.editor.project.XEditorProject;
009:        import net.xoetrope.editor.project.XEditorProjectProperty;
010:        import net.xoetrope.optional.data.XOptionalDataSource;
011:        import net.xoetrope.xml.XmlElement;
012:        import net.xoetrope.xml.nanoxml.NanoXmlParser;
013:        import net.xoetrope.xui.data.XBaseModel;
014:        import net.xoetrope.data.XDataSource;
015:        import net.xoetrope.debug.DebugLogger;
016:        import net.xoetrope.xui.data.XModelHelper;
017:        import net.xoetrope.xui.helper.Constants;
018:
019:        /**
020:         * Singleton class for tracking loaded services and changes being made in the
021:         * editor to the services. The services are stored as XmlElements within the
022:         * services Hashtable. This storage mechanism makes it easier to load and save
023:         * data
024:         * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
025:         * the GNU Public License (GPL), please see license.txt for more details. If
026:         * you make commercial use of this software you must purchase a commercial
027:         * license from Xoetrope.</p>
028:         * <p> $Revision: 1.8 $</p>
029:         */
030:        public class ServiceManager {
031:            private XEditorProject currentProject;
032:            private XBaseModel clientServicesMdl, serverServicesMdl;
033:            public final static int SIDE_CLIENT = 1;
034:            public final static int SIDE_SERVER = 2;
035:
036:            /**
037:             * Create the services Hashtable
038:             */
039:            public ServiceManager(XEditorProject proj) {
040:                currentProject = proj;
041:
042:                if (currentProject.getObject(Constants.SERVER_DATASETS) == null) {
043:                    DebugLogger
044:                            .logError("You must define a value for the server side routes and service configuration in the startup properties to use XUI's routes and servives");
045:                    currentProject
046:                            .fixError(
047:                                    getClass(),
048:                                    "com.xoetrope.carousel.debug.selfhealing.ServerPropertiesMissing",
049:                                    this , null);
050:                }
051:
052:                loadServicesFromFile(currentProject);
053:            }
054:
055:            /**
056:             * Get the sevices file name from the XLibXModelManager and load it into an
057:             * xml element. Iterate the child elements and add them to the services
058:             * Hashtable.
059:             * 
060:             * @param currentProject the currentProject we are working with
061:             */
062:            public void loadServicesFromFile(XEditorProject proj) {
063:                currentProject = proj;
064:
065:                if (clientServicesMdl == null) {
066:                    clientServicesMdl = new XBaseModel();
067:                    clientServicesMdl.setTagName(Constants.SERVICES);
068:                }
069:
070:                if (serverServicesMdl == null) {
071:                    serverServicesMdl = new XBaseModel();
072:                    serverServicesMdl.setTagName(Constants.SERVICES);
073:                }
074:
075:                String servicesFilename = (String) ((XEditorProjectProperty) currentProject
076:                        .getObject(Constants.SERVICES)).property;
077:                loadServiceFile(clientServicesMdl, servicesFilename,
078:                        "resources");
079:
080:                servicesFilename = (String) ((XEditorProjectProperty) currentProject
081:                        .getObject(Constants.SERVER_SERVICES)).property;
082:                loadServiceFile(serverServicesMdl, servicesFilename,
083:                        "resources" + File.separator + "server");
084:            }
085:
086:            private void loadServiceFile(XBaseModel targetMdl,
087:                    String servicesFilename, String resPath) {
088:                if (servicesFilename != null) {
089:                    servicesFilename = currentProject.getPath()
090:                            + File.separator + resPath + File.separator
091:                            + servicesFilename;
092:                    XOptionalDataSource xlibDS = new XOptionalDataSource(
093:                            currentProject);
094:
095:                    try {
096:                        FileReader fr = new FileReader(servicesFilename);
097:                        NanoXmlParser parser = new NanoXmlParser();
098:                        XmlElement ele = parser.parse(fr);
099:                        if (ele != null)
100:                            xlibDS.loadTable(ele, targetMdl);
101:                    } catch (FileNotFoundException ex) {
102:                    }
103:                }
104:            }
105:
106:            public String getRouteName(String serviceName, int side) {
107:                XBaseModel serviceMdl = (XBaseModel) getServices(side).get(
108:                        serviceName);
109:                return XModelHelper.getAttrib(serviceMdl, "route");
110:            }
111:
112:            public void setRouteName(String serviceName, String routeName,
113:                    int side) {
114:                XBaseModel serviceMdl = (XBaseModel) getServices(side).get(
115:                        serviceName);
116:                XModelHelper.setAttrib(serviceMdl, "route", routeName);
117:            }
118:
119:            public void removeService(String serviceName, int side) {
120:                XBaseModel targetMdl = getServices(side);
121:                targetMdl.removeChild(serviceName);
122:            }
123:
124:            /**
125:             * Get a reference to the services Hashtable.
126:             * @return the services Hashtable
127:             */
128:            public XBaseModel getServices(int side) {
129:                return (side == SIDE_CLIENT ? clientServicesMdl
130:                        : serverServicesMdl);
131:            }
132:
133:            /**
134:             * Save the services file using the filename passed. Iterate the services
135:             * Hashtable and build up the xml hierarchy. Save the file using the root
136:             * node.
137:             * 
138:             * @param currentProject the currentProject we are working with
139:             * @param filename the name of the services file
140:             */
141:            public void saveServices(XEditorProject project) {
142:                String servicesFilename = (String) ((XEditorProjectProperty) project
143:                        .getObject(Constants.SERVICES)).property;
144:                servicesFilename = project.getPath() + File.separator
145:                        + "resources" + File.separator + servicesFilename;
146:                saveServiceFile(servicesFilename, clientServicesMdl);
147:
148:                servicesFilename = (String) ((XEditorProjectProperty) project
149:                        .getObject(Constants.SERVER_SERVICES)).property;
150:                servicesFilename = project.getPath() + File.separator
151:                        + "resources" + File.separator + "server"
152:                        + File.separator + servicesFilename;
153:                saveServiceFile(servicesFilename, serverServicesMdl);
154:            }
155:
156:            private void saveServiceFile(String path, XBaseModel targetMdl) {
157:                try {
158:                    FileWriter fw = new FileWriter(path);
159:                    XDataSource.outputModel(fw, targetMdl);
160:                    fw.flush();
161:                    fw.close();
162:                } catch (Exception e) {
163:                    e.printStackTrace();
164:                }
165:            }
166:
167:            private ModelManager getModelManager() {
168:                RouteManager routeMgr = (RouteManager) currentProject
169:                        .getObject(ProjectRouteManager.ROUTE_MGR_LOOKUP);
170:                return routeMgr.getModelMgr();
171:            }
172:
173:            /**
174:             * Add a service with the specified name to the Hashtable. The object added is
175:             * an XmlElement.
176:             * @param name
177:             */
178:            public void addService(String name, int side) {
179:                XBaseModel newService = new XBaseModel(getServices(side), name,
180:                        null);
181:                newService.setTagName("service");
182:            }
183:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.