Source Code Cross Referenced for ModelEditor.java in  » Workflow-Engines » osbl-1_0 » model » 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 » Workflow Engines » osbl 1_0 » model 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * 
003:         */package model;
004:
005:        import java.io.File;
006:        import java.util.ArrayList;
007:        import java.util.HashMap;
008:        import java.util.Iterator;
009:        import java.util.List;
010:        import java.util.Map;
011:
012:        import logging.LoggingPlugin;
013:
014:        import org.eclipse.core.resources.IContainer;
015:        import org.eclipse.core.resources.ResourcesPlugin;
016:        import org.eclipse.core.runtime.ILog;
017:        import org.eclipse.core.runtime.IPath;
018:        import org.eclipse.core.runtime.IStatus;
019:        import org.eclipse.core.runtime.Path;
020:        import org.eclipse.core.runtime.Status;
021:        import org.eclipse.emf.common.util.URI;
022:        import org.eclipse.emf.ecore.resource.ResourceSet;
023:        import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
024:        import org.openarchitectureware.emf.XmiReader;
025:        import org.openarchitectureware.workflow.WorkflowContext;
026:        import org.openarchitectureware.workflow.WorkflowContextDefaultImpl;
027:        import org.openarchitectureware.workflow.issues.Issues;
028:        import org.openarchitectureware.workflow.issues.IssuesImpl;
029:        import org.openarchitectureware.workflow.monitor.NullProgressMonitor;
030:
031:        /**
032:         * @author sh
033:         *
034:         */
035:        public class ModelEditor {
036:
037:            // singleton
038:            public static final ModelEditor INSTANCE = new ModelEditor();
039:
040:            private Issues issues = null;
041:
042:            /**
043:             * Read the Process Metamodel by a XMI Reader
044:             * 
045:             * @return model the Ecore model
046:             * @throws Exception
047:             */
048:            public List<Map<WorkflowContext, String>> loadModels() {
049:                // initialize the issues object which stores errors and warnings
050:                // of the load process
051:                this .issues = new IssuesImpl();
052:
053:                // 1. search for the Meta Model File
054:                List<String> metaModelFile = getMetaModelFiles();
055:
056:                // 2. search for the model File(s)
057:                List<String> modelFiles = getModelFiles();
058:
059:                // 3. check if model files and meta model files were found
060:                if (metaModelFile == null || modelFiles == null)
061:                    return null;
062:                if (metaModelFile.isEmpty() || modelFiles.isEmpty())
063:                    return null;
064:
065:                // 4. read the object trees from the models
066:                return readModels(metaModelFile, modelFiles);
067:            }
068:
069:            /**
070:             * Searches for meta model files in the workspace.
071:             * For the process editor these files ends with ".ecore".
072:             * Only opened projects are considered.
073:             * 
074:             * @return metaModelFile a list containing all found
075:             * 			meta model files
076:             */
077:            private List<String> getMetaModelFiles() {
078:                List<String> metaModelFile = ModelUtil.getMetaModelFiles();
079:                if (metaModelFile == null || metaModelFile.isEmpty()) {
080:                    String message = "No Meta Model File (*.ecore) has been found !";
081:                    issues.addError(message);
082:                    ILog logger = LoggingPlugin.getDefault().getLog();
083:                    String symName = LoggingPlugin.getDefault().getBundle()
084:                            .getSymbolicName();
085:                    logger.log(new Status(IStatus.ERROR, symName, 0, message,
086:                            null));
087:                    throw new RuntimeException(message);
088:                }
089:                return metaModelFile;
090:            }
091:
092:            /**
093:             * Searches for model files in the workspace.
094:             * For the process editor these files ends with "concept".
095:             * Only opened projects are considered.
096:             *  
097:             * @return modelFiles a list containing all found
098:             * 			model files
099:             */
100:            private List<String> getModelFiles() {
101:                List<String> modelFiles = ModelUtil.getModelFiles();
102:                if (modelFiles == null || modelFiles.isEmpty()) {
103:                    String message = "No Process Model Files to refactor have been found !";
104:                    issues.addError(message);
105:                    ILog logger = LoggingPlugin.getDefault().getLog();
106:                    String symName = LoggingPlugin.getDefault().getBundle()
107:                            .getSymbolicName();
108:                    logger.log(new Status(IStatus.ERROR, symName, 0, message,
109:                            null));
110:                    throw new RuntimeException(message);
111:                }
112:                return modelFiles;
113:            }
114:
115:            /**
116:             * This helper method reads the given model files an creates 
117:             * the object tree for that model. The meta model file is needed
118:             * to instanciate the object tree for the given models.
119:             *   
120:             * @param metaModelFile a list containing all meta models
121:             * @param modelFiles al list containing all model files to load
122:             * @return models a map containing a list consisting of object tree 
123:             * 				model file pairs
124:             */
125:            private List<Map<WorkflowContext, String>> readModels(
126:                    List<String> metaModelFile, List<String> modelFiles) {
127:                XmiReader reader = new XmiReader();
128:                reader.setMetaModelFile(metaModelFile.get(0).toString());
129:                Map<WorkflowContext, String> contextFileMap = null;
130:                WorkflowContext ctx = null;
131:                List<Map<WorkflowContext, String>> models = new ArrayList<Map<WorkflowContext, String>>();
132:                for (Iterator<String> iterator = modelFiles.iterator(); iterator
133:                        .hasNext();) {
134:                    String modelFile = (String) iterator.next();
135:                    reader.setModelFile(modelFile);
136:                    try {
137:                        reader
138:                                .setMetaModelPackage("newprocess.NewprocessPackage");
139:                    } catch (RuntimeException e) {
140:                        //throw new RuntimeException(e);
141:                        // TODO: has to be fixed because a ClassCast Exception occures
142:                    }
143:                    reader.setFirstElementOnly(true);
144:                    ctx = new WorkflowContextDefaultImpl();
145:                    reader.invoke(ctx, new NullProgressMonitor(), this .issues);
146:
147:                    // add the Workflow Context and the concerning ModelFile Path to the Collection
148:                    contextFileMap = new HashMap<WorkflowContext, String>();
149:                    contextFileMap.put(ctx, modelFile);
150:                    models.add(contextFileMap);
151:                }
152:                return models;
153:            }
154:
155:            /**
156:             * Write the edited Process Metamodel by a XMI Writer
157:             * 
158:             * @param ctx the Workflow Context containing the model
159:             */
160:            public void writeModel(List<Map<WorkflowContext, String>> binding) {
161:                for (Iterator<Map<WorkflowContext, String>> iterator = binding
162:                        .iterator(); iterator.hasNext();) {
163:                    Map<WorkflowContext, String> ctxModelMap = iterator.next();
164:
165:                    for (Iterator<WorkflowContext> contextIter = ctxModelMap
166:                            .keySet().iterator(); contextIter.hasNext();) {
167:                        WorkflowContext ctx = (WorkflowContext) contextIter
168:                                .next();
169:                        String path = ctxModelMap.get(ctx);
170:
171:                        IPath filePath = new Path(path);
172:                        IContainer[] root = ResourcesPlugin.getWorkspace()
173:                                .getRoot().findContainersForLocation(filePath);
174:                        for (int i = 0; i < root.length; i++) {
175:                            IContainer container = root[i];
176:                            filePath = container.getFullPath();
177:                        }
178:
179:                        Writer writer = new Writer();
180:                        writer.setModelSlot("default");
181:                        URI url = URI.createPlatformResourceURI(filePath
182:                                .toString(), true);
183:                        writer.setUri(url.toString());
184:                        ResourceSet rs = new ResourceSetImpl();
185:                        writer.setResourceSet(rs);
186:                        new StandaloneSetup().setPlatformUri(new File("..")
187:                                .getAbsolutePath());
188:                        this .issues = new IssuesImpl();
189:                        writer.invoke(ctx, new NullProgressMonitor(),
190:                                this .issues);
191:                    }
192:                }
193:            }
194:
195:            /**
196:             * getter for the issues property.
197:             * 
198:             * @return issues
199:             */
200:            public Issues getIssues() {
201:                return this.issues;
202:            }
203:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.