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


001:        /** 
002:         * This class loads the data sources for use by the editor.
003:         * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
004:         * the GNU Public License (GPL), please see license.txt for more details. If
005:         * you make commercial use of this software you must purchase a commercial
006:         * license from Xoetrope.</p>
007:         * <p> $Revision: 1.7 $</p>
008:         */package com.xoetrope.data;
009:
010:        import java.util.Hashtable;
011:        import net.xoetrope.data.XDataSource;
012:        import net.xoetrope.debug.DebugLogger;
013:        import net.xoetrope.editor.project.ProjectListener;
014:        import net.xoetrope.editor.project.XEditorProject;
015:        import net.xoetrope.optional.data.XDataModelLoader;
016:        import net.xoetrope.optional.data.XOptionalDataSource;
017:        import net.xoetrope.xui.XProject;
018:        import net.xoetrope.xui.helper.SwingWorker;
019:        import net.xoetrope.xml.XmlElement;
020:        import net.xoetrope.xui.build.BuildProperties;
021:        import net.xoetrope.xui.data.XModel;
022:        import net.xoetrope.xui.helper.ReflectionHelper;
023:
024:        public class DataSourceLoader implements  ProjectListener {
025:            // key: run time datasource class
026:            // value: design time datasource class
027:            protected Hashtable dataSources;
028:
029:            /**
030:             * Creates a new instance of DataSourceLoader
031:             */
032:            public DataSourceLoader() {
033:                initDataSources();
034:            }
035:
036:            /**
037:             * Fills the datasources hashtable 
038:             */
039:            @SuppressWarnings("all")
040:            private void initDataSources() {
041:                dataSources = new Hashtable();
042:
043:                dataSources.put(
044:                        "net.xoetrope.optional.data.pojo.XPojoDataSource",
045:                        "com.xoetrope.data.pojo.XPojoDataSourceEx");
046:
047:                dataSources
048:                        .put(
049:                                "net.xoetrope.optional.data.pojo.XPersistentPojoDataSource",
050:                                "com.xoetrope.data.pojo.XPersistentPojoDataSourceEx");
051:
052:                dataSources
053:                        .put(
054:                                "net.xoetrope.optional.data.pojo.XHibernatePojoDataSource",
055:                                "com.xoetrope.data.pojo.XHibernatePojoDataSourceEx");
056:            }
057:
058:            /**
059:             * Notification of project initialized.
060:             * @param project the editor project just initialized
061:             */
062:            public void projectInitialized(XEditorProject project) {
063:            }
064:
065:            /**
066:             * Builds data sources of the project for use
067:             * by the editor.
068:             * @param project the project whose data sources will
069:             * be loaded   
070:             */
071:            public void projectLoaded(XEditorProject project) {
072:                loadDatasets(project);
073:            }
074:
075:            /**
076:             * Loads the data sources for use by the editor (i.e. data visualizer)
077:             * @param project the project whose data sources are to be loaded
078:             */
079:            private void loadDatasets(XEditorProject project) {
080:                XOptionalDataSource modelDataSource = new XOptionalDataSource(
081:                        project);
082:                modelDataSource.setModelLoader(new DataLoader(project));
083:                try {
084:                    String fileName = project.getStartupParam("ModelData");
085:                    if (fileName != null) {
086:                        try {
087:                            modelDataSource.read(project.getBufferedReader(
088:                                    fileName, null));
089:                        } catch (Exception ex3) {
090:                            if (BuildProperties.DEBUG)
091:                                DebugLogger.logError("Could not access file:"
092:                                        + fileName);
093:                        }
094:                    }
095:                } catch (Exception ex) {
096:                    if (BuildProperties.DEBUG)
097:                        DebugLogger.logError("Exception in loadDatasets");
098:                }
099:            }
100:
101:            /**
102:             * The data source loader.
103:             */
104:            private class DataLoader implements  XDataModelLoader {
105:                private XEditorProject currentProject;
106:
107:                /**
108:                 * Creates a new instance of DataLoader
109:                 * @param project the current project
110:                 */
111:                public DataLoader(XEditorProject project) {
112:                    currentProject = project;
113:                }
114:
115:                /**
116:                 * Load a custom data model node by reflectively constructing a data model 
117:                 * loader and invoking its load method(s).
118:                 * @param cn the class to instantiate, a class implementing XDataModelLoader
119:                 * @param src the XML source being loaded
120:                 * @param model the model to load
121:                 */
122:                public void loadModel(String cn, final XmlElement src,
123:                        final XModel model) {
124:                    String className = (String) dataSources.get(cn);
125:                    // if there's no design time datasource version specified, use the runtime one
126:                    if (className == null)
127:                        className = cn;
128:
129:                    // create the data source object for use in the editor
130:                    final XDataSource dataSource = (XDataSource) ReflectionHelper
131:                            .constructViaReflection(
132:                                    getClass().getClassLoader(), className,
133:                                    XProject.class, currentProject);
134:
135:                    // create the "worker" tasked with loading the data to the model      
136:                    SwingWorker swingWorker = (new SwingWorker() {
137:
138:                        public Object construct() {
139:                            dataSource.loadTable(src, model);
140:                            return model;
141:                        }
142:
143:                        public void finished() {
144:                        }
145:                    });
146:
147:                    // load the data in a background thread
148:                    swingWorker.start();
149:                }
150:
151:                /*        
152:                public void loadModel( String className, final XmlElement src, final XModel model )
153:                {            
154:                  if ( "net.xoetrope.optional.data.pojo.XPersistentPojoDataSource".equals( className )) {
155:                    final XPojoDataSourceEx dataSource = new XPersistentPojoDataSourceEx( currentProject );                
156:                    SwingWorker swingWorker = new SwingWorker() {
157:                      
158:                      public Object construct() 
159:                      {
160:                        dataSource.loadTable( src, model );
161:                        return model;
162:                      }
163:                      
164:                      public void finished() 
165:                      {
166:                      }
167:                    };        
168:                    
169:                    swingWorker.start();               
170:                  } 
171:                  else if ( "net.xoetrope.optional.data.pojo.XPojoDataSource".equals( className )) {      
172:                    final XPojoDataSourceEx dataSource = new XPojoDataSourceEx( currentProject );                
173:                            
174:                    SwingWorker swingWorker = new SwingWorker() {
175:                      public Object construct() 
176:                      {
177:                        dataSource.loadTable( src, model );
178:                        return model;
179:                      }
180:                      
181:                      public void finished() 
182:                      { 
183:                      }
184:                    };
185:                    
186:                    swingWorker.start();         
187:                  } 
188:                  else {                        
189:                    Object[] values = new Object[]{ currentProject };
190:                    XDataSource dataSource = (XDataSource)ReflectionHelper.constructViaReflection( className, values );
191:                    if ( dataSource != null )
192:                      dataSource.loadTable( src, model );
193:                  }
194:                }
195:                 */
196:
197:            }
198:
199:            public void projectUpdated(XEditorProject project) {
200:            }
201:
202:            public void saveProject(XEditorProject project) {
203:            }
204:
205:            public void checkProject(XEditorProject project) {
206:            }
207:
208:            public void resetProject(String moduleName, XEditorProject project) {
209:            }
210:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.