Source Code Cross Referenced for IncludeAdapterDefinition.java in  » UML » MetaBoss » com » metaboss » sdlctools » applications » anttasks » builder » modules » subelements » 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 » MetaBoss » com.metaboss.sdlctools.applications.anttasks.builder.modules.subelements 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
002:        // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
003:        // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
004:        // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
005:        // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
006:        // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
007:        // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
008:        // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
009:        // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
010:        // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
011:        // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
012:        // POSSIBILITY OF SUCH DAMAGE.
013:        //
014:        // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
015:        package com.metaboss.sdlctools.applications.anttasks.builder.modules.subelements;
016:
017:        import java.io.File;
018:        import java.util.ArrayList;
019:        import java.util.Arrays;
020:        import java.util.HashSet;
021:        import java.util.Iterator;
022:        import java.util.List;
023:        import java.util.Map;
024:        import java.util.Properties;
025:        import java.util.Set;
026:        import java.util.TreeMap;
027:        import java.util.TreeSet;
028:
029:        import javax.jmi.reflect.JmiException;
030:        import javax.naming.Context;
031:        import javax.naming.InitialContext;
032:        import javax.naming.NamingException;
033:
034:        import org.apache.tools.ant.BuildException;
035:
036:        import com.metaboss.enterprise.bs.BSException;
037:        import com.metaboss.sdlctools.applications.anttasks.builder.ModuleDefinition;
038:        import com.metaboss.sdlctools.applications.anttasks.builder.ModuleElementDefinition;
039:        import com.metaboss.sdlctools.applications.anttasks.builder.ToolInvocationDefinition;
040:        import com.metaboss.sdlctools.applications.anttasks.builder.tools.AdapterGeneratorInvocationDefinition;
041:        import com.metaboss.sdlctools.applications.anttasks.builder.tools.CoreCodeGeneratorInvocationDefinition;
042:        import com.metaboss.sdlctools.applications.anttasks.builder.tools.JavaCompilerInvocationDefinitionUtils;
043:        import com.metaboss.sdlctools.models.metabossmodel.ModelElement;
044:        import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.DataDictionary;
045:        import com.metaboss.sdlctools.models.metabossmodel.designlibrarymodel.DesignLibrary;
046:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Enterprise;
047:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Servicemodule;
048:        import com.metaboss.sdlctools.services.codegeneration.BSAdapterGenerator;
049:        import com.metaboss.util.StringUtils;
050:
051:        /** The definition of how to build a business services adapter. */
052:        public class IncludeAdapterDefinition extends ModuleElementDefinition {
053:            // Initialise metadata for supplying in the constructor
054:            private static ElementMetadata sElementMetadata = new ElementMetadata();
055:            static {
056:                sElementMetadata.ElementTypeName = "IncludeAdapter";
057:                sElementMetadata.SupportsModelElementRefs = true;
058:                sElementMetadata.AllowedModelElementTypes = new Class[] {
059:                        Enterprise.class,
060:                        com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System.class,
061:                        Servicemodule.class, DataDictionary.class,
062:                        DesignLibrary.class, };
063:            }
064:            private String mType = null;
065:            private List mReferencedServicemodulesToDo = new ArrayList(); // Referenced only. Need to generate and compile but do not package
066:            private List mReferencedDataDictionariesToDo = new ArrayList(); // Referenced only. Need to generate and compile but do not package
067:            private List mServicemodulesToDo = new ArrayList(); // Included. Do everything
068:            private List mDataDictionariesToDo = new ArrayList(); // Included. Do everything
069:            private List mDataDictionariesToGenerateAndCompile = new ArrayList(); // Combined list to use when generating and compiling
070:            private List mServicemodulesToGenerateAndCompile = new ArrayList(); // Combined list to use when generating and compiling
071:            private List mTypesToDo = new ArrayList(); // Adapter types to do
072:
073:            /** The only available constructor */
074:            public IncludeAdapterDefinition(ModuleDefinition pOwnerDefinition) {
075:                super (pOwnerDefinition, sElementMetadata);
076:            }
077:
078:            // The setter for the "type" attribute
079:            public void setType(String pType) {
080:                mType = pType;
081:            }
082:
083:            // The getter for the "type" attribute
084:            public String getType() {
085:                if (mType == null)
086:                    throw new BuildException(
087:                            "Missing 'type' attribute, which is mandatory for adapter definition.");
088:                return mType;
089:            }
090:
091:            // Called when initialisation of parameters has been completed and generation is about to commence
092:            public void completeInitialisation() throws BuildException {
093:                try {
094:                    // Work on included module elements
095:                    ModelElement[] lIncludedModelElements = getIncludedModelElements();
096:                    // First collect list of al domains to generate implementations for
097:                    for (int lElementsIndex = 0; lElementsIndex < lIncludedModelElements.length; lElementsIndex++) {
098:                        ModelElement lIncludedModelElement = lIncludedModelElements[lElementsIndex];
099:                        mServicemodulesToDo.addAll(Arrays.asList(getOwnerTask()
100:                                .findModelElementsByXPath(
101:                                        lIncludedModelElement,
102:                                        "descendant-or-self::Servicemodule",
103:                                        new Class[] { Servicemodule.class })));
104:                        mDataDictionariesToDo
105:                                .addAll(Arrays
106:                                        .asList(getOwnerTask()
107:                                                .findModelElementsByXPath(
108:                                                        lIncludedModelElement,
109:                                                        "descendant-or-self::DataDictionary",
110:                                                        new Class[] { DataDictionary.class })));
111:                    }
112:                    // Now we have all servicemodules and datadictionaries explicitly included in the adapter.
113:                    // It is possible that there is an external data dictionary or servicemodule we need to have
114:                    // available to compile this one successfully.
115:                    for (Iterator lServicemodulesIterator = mServicemodulesToDo
116:                            .iterator(); lServicemodulesIterator.hasNext();) {
117:                        Servicemodule lServicemodule = (Servicemodule) lServicemodulesIterator
118:                                .next();
119:                        mReferencedDataDictionariesToDo.addAll(lServicemodule
120:                                .getReferencedDataDictionaries());
121:                        mReferencedServicemodulesToDo.addAll(lServicemodule
122:                                .getReferencedServicemodules());
123:                    }
124:                    for (Iterator lDataDictionariesIterator = mDataDictionariesToDo
125:                            .iterator(); lDataDictionariesIterator.hasNext();) {
126:                        DataDictionary lDataDictionary = (DataDictionary) lDataDictionariesIterator
127:                                .next();
128:                        mReferencedDataDictionariesToDo.addAll(lDataDictionary
129:                                .getReferencedDataDictionaries());
130:                    }
131:
132:                    // Create combined lists 
133:                    mDataDictionariesToGenerateAndCompile
134:                            .addAll(mReferencedDataDictionariesToDo);
135:                    mDataDictionariesToGenerateAndCompile
136:                            .addAll(mDataDictionariesToDo);
137:                    mServicemodulesToGenerateAndCompile
138:                            .addAll(mReferencedServicemodulesToDo);
139:                    mServicemodulesToGenerateAndCompile
140:                            .addAll(mServicemodulesToDo);
141:
142:                    // Build the list of adapters this one depends on
143:                    Set lAlreadyProcessedTypes = new HashSet();
144:                    lAlreadyProcessedTypes.add(getType());
145:                    String[] lRequiredTypes = getRequiredAdapterTypes(
146:                            getType(), lAlreadyProcessedTypes);
147:                    mTypesToDo.addAll(Arrays.asList(lRequiredTypes));
148:                    mTypesToDo.add(getType());
149:                } catch (JmiException e) {
150:                    throw new BuildException(
151:                            "Caught exception while preparing to build the Servicemodule Adapter. "
152:                                    + e.getMessage());
153:                } catch (BSException e) {
154:                    throw new BuildException(
155:                            "Caught exception while preparing to build the Servicemodule Adapter. "
156:                                    + e.getMessage());
157:                }
158:            }
159:
160:            /** Returns array of servicemodules included in this definition and referenced from within it */
161:            public Servicemodule[] getIncludedAndReferencedServicemodules() {
162:                return (Servicemodule[]) mServicemodulesToGenerateAndCompile
163:                        .toArray(new Servicemodule[mServicemodulesToGenerateAndCompile
164:                                .size()]);
165:            }
166:
167:            /** Returns array of servicemodules included in this definition */
168:            public Servicemodule[] getIncludedServicemodules() {
169:                return (Servicemodule[]) mServicemodulesToDo
170:                        .toArray(new Servicemodule[mServicemodulesToDo.size()]);
171:            }
172:
173:            /** Returns array of servicemodules refeenced from this definition */
174:            public Servicemodule[] getReferencedServicemodules() {
175:                return (Servicemodule[]) mReferencedServicemodulesToDo
176:                        .toArray(new Servicemodule[mReferencedServicemodulesToDo
177:                                .size()]);
178:            }
179:
180:            /** Returns array of data dictionaries included in this definition and referenced from within it */
181:            public DataDictionary[] getIncludedAndReferencedDataDictionaries() {
182:                return (DataDictionary[]) mDataDictionariesToGenerateAndCompile
183:                        .toArray(new DataDictionary[mDataDictionariesToGenerateAndCompile
184:                                .size()]);
185:            }
186:
187:            /** Returns array of data dictionaries included in this definition */
188:            public DataDictionary[] getIncludedDataDictionaries() {
189:                return (DataDictionary[]) mDataDictionariesToDo
190:                        .toArray(new DataDictionary[mDataDictionariesToDo
191:                                .size()]);
192:            }
193:
194:            /** Returns array of data dictionaries included in this definition */
195:            public DataDictionary[] getReferencedDataDictionaries() {
196:                return (DataDictionary[]) mReferencedDataDictionariesToDo
197:                        .toArray(new DataDictionary[mReferencedDataDictionariesToDo
198:                                .size()]);
199:            }
200:
201:            // Returns plan to invoke any number of code generators necessary to build the module  
202:            public ToolInvocationDefinition[] getGenerationPlan() {
203:                try {
204:                    List lInvocations = new ArrayList();
205:                    // Work on referenced and included data dictionaries
206:                    for (Iterator lDataDictionariesIterator = mDataDictionariesToGenerateAndCompile
207:                            .iterator(); lDataDictionariesIterator.hasNext();) {
208:                        DataDictionary lDataDictionary = (DataDictionary) lDataDictionariesIterator
209:                                .next();
210:                        // Will need to generate core of the system this is where service definitions are
211:                        CoreCodeGeneratorInvocationDefinition lCoreGeneratorInvocationDefinition = new CoreCodeGeneratorInvocationDefinition(
212:                                getOwnerTask());
213:                        lCoreGeneratorInvocationDefinition
214:                                .setDataDictionaryRef(lDataDictionary.getRef());
215:                        lInvocations.add(lCoreGeneratorInvocationDefinition);
216:                        // DataDictionary code must be compiled immediately
217:                        if (getOwnerTask().getTypesSrcDir() != null) {
218:                            // Compile custom enterprise types
219:                            lInvocations
220:                                    .add(JavaCompilerInvocationDefinitionUtils
221:                                            .createForCustomDataDictionaryTypes(
222:                                                    this , lDataDictionary));
223:                        }
224:                        lInvocations.add(JavaCompilerInvocationDefinitionUtils
225:                                .createForDataDictionaryTypes(this ,
226:                                        lDataDictionary));
227:                    }
228:                    // Now generate the code for adapters
229:                    for (Iterator lDataDictionariesIterator = mDataDictionariesToGenerateAndCompile
230:                            .iterator(); lDataDictionariesIterator.hasNext();) {
231:                        DataDictionary lDataDictionary = (DataDictionary) lDataDictionariesIterator
232:                                .next();
233:                        // Generate all dependent adapters
234:                        for (Iterator lTypesIterator = mTypesToDo.iterator(); lTypesIterator
235:                                .hasNext();) {
236:                            String lTypeToDo = (String) lTypesIterator.next();
237:                            // If this is referenced data dictionary we should only generate code for it if it is not present on the compile classpath
238:                            if ((mReferencedDataDictionariesToDo
239:                                    .contains(lDataDictionary) == false)
240:                                    || (getOwnerTask()
241:                                            .isArtefactPresentOnCompileClasspath(
242:                                                    getGeneratorIdentifier(lTypeToDo),
243:                                                    lDataDictionary.getRef()) == false)) {
244:                                AdapterGeneratorInvocationDefinition lAdapterGeneratorInvocationDefinition = new AdapterGeneratorInvocationDefinition(
245:                                        getOwnerTask());
246:                                lAdapterGeneratorInvocationDefinition
247:                                        .setDataDictionaryRef(lDataDictionary
248:                                                .getRef());
249:                                lAdapterGeneratorInvocationDefinition
250:                                        .setType(lTypeToDo);
251:                                lAdapterGeneratorInvocationDefinition
252:                                        .setGenerator(getGenerator(lTypeToDo));
253:                                lInvocations
254:                                        .add(lAdapterGeneratorInvocationDefinition);
255:                            }
256:                        }
257:                    }
258:                    // Work on referenced and included servicemodules
259:                    for (Iterator lServicemodulesIterator = mServicemodulesToGenerateAndCompile
260:                            .iterator(); lServicemodulesIterator.hasNext();) {
261:                        Servicemodule lServicemodule = (Servicemodule) lServicemodulesIterator
262:                                .next();
263:                        // Will need to generate core of the system this is where service definitions are
264:                        CoreCodeGeneratorInvocationDefinition lCoreGeneratorInvocationDefinition = new CoreCodeGeneratorInvocationDefinition(
265:                                getOwnerTask());
266:                        lCoreGeneratorInvocationDefinition
267:                                .setSystemRef(lServicemodule.getSystem()
268:                                        .getRef());
269:                        lInvocations.add(lCoreGeneratorInvocationDefinition);
270:                        // Generate all dependent adapters
271:                        for (Iterator lTypesIterator = mTypesToDo.iterator(); lTypesIterator
272:                                .hasNext();) {
273:                            String lTypeToDo = (String) lTypesIterator.next();
274:                            // If this is referenced servicemodule we should only generate code for it if it is not present on the compile classpath
275:                            if ((mReferencedServicemodulesToDo
276:                                    .contains(lServicemodule) == false)
277:                                    || (getOwnerTask()
278:                                            .isArtefactPresentOnCompileClasspath(
279:                                                    getGeneratorIdentifier(lTypeToDo),
280:                                                    lServicemodule.getRef()) == false)) {
281:                                AdapterGeneratorInvocationDefinition lAdapterGeneratorInvocationDefinition = new AdapterGeneratorInvocationDefinition(
282:                                        getOwnerTask());
283:                                lAdapterGeneratorInvocationDefinition
284:                                        .setServicemoduleRef(lServicemodule
285:                                                .getRef());
286:                                lAdapterGeneratorInvocationDefinition
287:                                        .setType(lTypeToDo);
288:                                lAdapterGeneratorInvocationDefinition
289:                                        .setGenerator(getGenerator(lTypeToDo));
290:                                lInvocations
291:                                        .add(lAdapterGeneratorInvocationDefinition);
292:                            }
293:                        }
294:                    }
295:                    // Return what we have		
296:                    return (ToolInvocationDefinition[]) lInvocations
297:                            .toArray(new ToolInvocationDefinition[lInvocations
298:                                    .size()]);
299:                } catch (BSException e) {
300:                    throw new BuildException(
301:                            "Caught exception while generating adapter definition generation plan."
302:                                    + e.getMessage());
303:                }
304:            }
305:
306:            // Returns tasks to do after generation. (Normally compillation would go in here  
307:            public ToolInvocationDefinition[] getCompilationPlan() {
308:                try {
309:                    List lInvocations = new ArrayList();
310:                    // Work on referenced and included data dictionaries
311:                    for (Iterator lDataDictionariesIterator = mDataDictionariesToGenerateAndCompile
312:                            .iterator(); lDataDictionariesIterator.hasNext();) {
313:                        DataDictionary lDataDictionary = (DataDictionary) lDataDictionariesIterator
314:                                .next();
315:                        // Service adapters in order of dependency
316:                        for (Iterator lTypesIterator = mTypesToDo.iterator(); lTypesIterator
317:                                .hasNext();) {
318:                            String lTypeToDo = (String) lTypesIterator.next();
319:                            // If this is referenced data dictionary we should only compile it if it is not present on the compile classpath
320:                            if ((mReferencedDataDictionariesToDo
321:                                    .contains(lDataDictionary) == false)
322:                                    || (getOwnerTask()
323:                                            .isArtefactPresentOnCompileClasspath(
324:                                                    getGeneratorIdentifier(lTypeToDo),
325:                                                    lDataDictionary.getRef()) == false)) {
326:                                lInvocations
327:                                        .add(JavaCompilerInvocationDefinitionUtils
328:                                                .createForDataDictionaryAdapter(
329:                                                        this , lTypeToDo,
330:                                                        lDataDictionary,
331:                                                        getGenerator(lTypeToDo)));
332:                            }
333:                        }
334:                    }
335:                    // Work on referenced and included servicemodules
336:                    for (Iterator lServicemodulesIterator = mServicemodulesToGenerateAndCompile
337:                            .iterator(); lServicemodulesIterator.hasNext();) {
338:                        Servicemodule lServicemodule = (Servicemodule) lServicemodulesIterator
339:                                .next();
340:                        //				// Will need to compile enterprise types
341:                        //				lInvocations.add(JavaCompilerInvocationDefinitionUtils.createForEnterpriseTypes(this,lServicemodule.getSystem().getEnterprise()));
342:                        //				// Will need to compile system types
343:                        //				lInvocations.add(JavaCompilerInvocationDefinitionUtils.createForSystemTypes(this,lServicemodule.getSystem()));
344:                        // Will need to compile servicemodule interfaces types
345:                        lInvocations.add(JavaCompilerInvocationDefinitionUtils
346:                                .createForServicemoduleInterfaces(this ,
347:                                        lServicemodule));
348:                        // Service adapters in order of dependency
349:                        for (Iterator lTypesIterator = mTypesToDo.iterator(); lTypesIterator
350:                                .hasNext();) {
351:                            String lTypeToDo = (String) lTypesIterator.next();
352:                            // If this is referenced servicemodule we should only compile it if it is not present on the compile classpath
353:                            if ((mReferencedServicemodulesToDo
354:                                    .contains(lServicemodule) == false)
355:                                    || (getOwnerTask()
356:                                            .isArtefactPresentOnCompileClasspath(
357:                                                    getGeneratorIdentifier(lTypeToDo),
358:                                                    lServicemodule.getRef()) == false)) {
359:                                lInvocations
360:                                        .add(JavaCompilerInvocationDefinitionUtils
361:                                                .createForServicemoduleAdapter(
362:                                                        this , lTypeToDo,
363:                                                        lServicemodule,
364:                                                        getGenerator(lTypeToDo)));
365:                            }
366:                        }
367:                    }
368:                    // Return what we have		
369:                    return (ToolInvocationDefinition[]) lInvocations
370:                            .toArray(new ToolInvocationDefinition[lInvocations
371:                                    .size()]);
372:                } catch (BSException e) {
373:                    throw new BuildException(
374:                            "Caught exception while generating adapter definition compilation plan. "
375:                                    + e.getMessage());
376:                }
377:            }
378:
379:            // Reruns includes for the jar from the compiled classes subdir  
380:            public String[] getJarClassIncludes() throws BSException {
381:                List lJarClassIncludes = new ArrayList();
382:                // Work on included data dictionaries
383:                for (Iterator lDataDictionariesIterator = mDataDictionariesToDo
384:                        .iterator(); lDataDictionariesIterator.hasNext();) {
385:                    DataDictionary lDataDictionary = (DataDictionary) lDataDictionariesIterator
386:                            .next();
387:                    for (Iterator lTypesIterator = mTypesToDo.iterator(); lTypesIterator
388:                            .hasNext();) {
389:                        String lTypeToDo = (String) lTypesIterator.next();
390:                        String lAdapterPackage = getGenerator(lTypeToDo)
391:                                .getPackageNameForDataDictionary(
392:                                        lDataDictionary.getRef());
393:                        String lAdapterSubdirectory = StringUtils.replace(
394:                                lAdapterPackage, ".", File.separator);
395:                        lJarClassIncludes.add(lAdapterSubdirectory
396:                                + File.separator + "*.*");
397:                        lJarClassIncludes.add(lAdapterSubdirectory
398:                                + File.separator + "**" + File.separator
399:                                + "*.*");
400:                    }
401:                }
402:                // Work on included servicemodules
403:                for (Iterator lServicemodulesIterator = mServicemodulesToDo
404:                        .iterator(); lServicemodulesIterator.hasNext();) {
405:                    Servicemodule lServicemodule = (Servicemodule) lServicemodulesIterator
406:                            .next();
407:                    // Service adapters in order of dependency
408:                    for (Iterator lTypesIterator = mTypesToDo.iterator(); lTypesIterator
409:                            .hasNext();) {
410:                        String lTypeToDo = (String) lTypesIterator.next();
411:                        // Include services
412:                        {
413:                            String lServicesAdapterPackage = getGenerator(
414:                                    lTypeToDo)
415:                                    .getPackageNameForServicemoduleServices(
416:                                            lServicemodule.getRef());
417:                            String lServicesAdapterSubdirectory = StringUtils
418:                                    .replace(lServicesAdapterPackage, ".",
419:                                            File.separator);
420:                            lJarClassIncludes.add(lServicesAdapterSubdirectory
421:                                    + File.separator + "*.*");
422:                            lJarClassIncludes.add(lServicesAdapterSubdirectory
423:                                    + File.separator + "**" + File.separator
424:                                    + "*.*");
425:                        }
426:                        // Include event publishers
427:                        {
428:                            String lEventPublishersAdapterPackage = getGenerator(
429:                                    lTypeToDo)
430:                                    .getPackageNameForServicemoduleEventPublishers(
431:                                            lServicemodule.getRef());
432:                            String lEventPublishersAdapterSubdirectory = StringUtils
433:                                    .replace(lEventPublishersAdapterPackage,
434:                                            ".", File.separator);
435:                            lJarClassIncludes
436:                                    .add(lEventPublishersAdapterSubdirectory
437:                                            + File.separator + "*.*");
438:                            lJarClassIncludes
439:                                    .add(lEventPublishersAdapterSubdirectory
440:                                            + File.separator + "**"
441:                                            + File.separator + "*.*");
442:                        }
443:                    }
444:                }
445:                // Return what we have		
446:                return (String[]) lJarClassIncludes
447:                        .toArray(new String[lJarClassIncludes.size()]);
448:            }
449:
450:            // Returns contents of the jar being prepared. This is in the map
451:            // format where key is the generator package name (unique generator id) and
452:            // value is the set of model element refs which are packaged in
453:            public Map getJarContentsInformation() {
454:                Set lModelElementRefs = new TreeSet();
455:
456:                // Work on included data dictionaries
457:                for (Iterator lDataDictionariesIterator = mDataDictionariesToDo
458:                        .iterator(); lDataDictionariesIterator.hasNext();) {
459:                    DataDictionary lDataDictionary = (DataDictionary) lDataDictionariesIterator
460:                            .next();
461:                    lModelElementRefs.add(lDataDictionary.getRef());
462:                }
463:                // Work on included servicemodules
464:                for (Iterator lServicemodulesIterator = mServicemodulesToDo
465:                        .iterator(); lServicemodulesIterator.hasNext();) {
466:                    Servicemodule lServicemodule = (Servicemodule) lServicemodulesIterator
467:                            .next();
468:                    lModelElementRefs.add(lServicemodule.getRef());
469:                }
470:
471:                // Build the set
472:                Map lJarContentsMap = new TreeMap();
473:                for (Iterator lTypesIterator = mTypesToDo.iterator(); lTypesIterator
474:                        .hasNext();) {
475:                    String lTypeToDo = (String) lTypesIterator.next();
476:                    String lGeneratorId = getGeneratorIdentifier(lTypeToDo);
477:                    lJarContentsMap.put(lGeneratorId, lModelElementRefs);
478:                }
479:
480:                return lJarContentsMap;
481:            }
482:
483:            // Retuns includes for the jar from the compiled sources  
484:            public String[] getJarSourceIncludes() throws BSException {
485:                List lJarSourceIncludes = new ArrayList();
486:                // Work on included data dictionaries
487:                for (Iterator lDataDictionariesIterator = mDataDictionariesToDo
488:                        .iterator(); lDataDictionariesIterator.hasNext();) {
489:                    DataDictionary lDataDictionary = (DataDictionary) lDataDictionariesIterator
490:                            .next();
491:                    for (Iterator lTypesIterator = mTypesToDo.iterator(); lTypesIterator
492:                            .hasNext();) {
493:                        String lTypeToDo = (String) lTypesIterator.next();
494:                        String lAdapterPackage = getGenerator(lTypeToDo)
495:                                .getPackageNameForDataDictionary(
496:                                        lDataDictionary.getRef());
497:                        String lAdapterSubdirectory = StringUtils.replace(
498:                                lAdapterPackage, ".", File.separator);
499:                        lJarSourceIncludes.add(lAdapterSubdirectory
500:                                + File.separator + "*.xsd");
501:                        lJarSourceIncludes.add(lAdapterSubdirectory
502:                                + File.separator + "**" + File.separator
503:                                + "*.xsd");
504:                        lJarSourceIncludes.add(lAdapterSubdirectory
505:                                + File.separator + "*.properties");
506:                        lJarSourceIncludes.add(lAdapterSubdirectory
507:                                + File.separator + "**" + File.separator
508:                                + "*.properties");
509:                    }
510:                }
511:                // Work on included servicemodules
512:                for (Iterator lServicemodulesIterator = mServicemodulesToDo
513:                        .iterator(); lServicemodulesIterator.hasNext();) {
514:                    Servicemodule lServicemodule = (Servicemodule) lServicemodulesIterator
515:                            .next();
516:                    // Service adapters in order of dependency
517:                    for (Iterator lTypesIterator = mTypesToDo.iterator(); lTypesIterator
518:                            .hasNext();) {
519:                        String lTypeToDo = (String) lTypesIterator.next();
520:                        // Include services
521:                        {
522:                            String lServicesAdapterPackage = getGenerator(
523:                                    lTypeToDo)
524:                                    .getPackageNameForServicemoduleServices(
525:                                            lServicemodule.getRef());
526:                            String lServicesAdapterSubdirectory = StringUtils
527:                                    .replace(lServicesAdapterPackage, ".",
528:                                            File.separator);
529:                            lJarSourceIncludes.add(lServicesAdapterSubdirectory
530:                                    + File.separator + "*.xsd");
531:                            lJarSourceIncludes.add(lServicesAdapterSubdirectory
532:                                    + File.separator + "*.properties");
533:                            lJarSourceIncludes.add(lServicesAdapterSubdirectory
534:                                    + File.separator + "**" + File.separator
535:                                    + "*.properties");
536:                        }
537:                        // Include event publishers
538:                        {
539:                            String lEventPublishersAdapterPackage = getGenerator(
540:                                    lTypeToDo)
541:                                    .getPackageNameForServicemoduleEventPublishers(
542:                                            lServicemodule.getRef());
543:                            String lEventPublishersAdapterSubdirectory = StringUtils
544:                                    .replace(lEventPublishersAdapterPackage,
545:                                            ".", File.separator);
546:                            lJarSourceIncludes
547:                                    .add(lEventPublishersAdapterSubdirectory
548:                                            + File.separator + "*.xsd");
549:                            lJarSourceIncludes
550:                                    .add(lEventPublishersAdapterSubdirectory
551:                                            + File.separator + "*.properties");
552:                            lJarSourceIncludes
553:                                    .add(lEventPublishersAdapterSubdirectory
554:                                            + File.separator + "**"
555:                                            + File.separator + "*.properties");
556:                        }
557:                    }
558:                }
559:                // Return what we have		
560:                return (String[]) lJarSourceIncludes
561:                        .toArray(new String[lJarSourceIncludes.size()]);
562:            }
563:
564:            // List all as yet unaccounted for adapter types required for this adapter
565:            private static String[] getRequiredAdapterTypes(
566:                    String lTypeToDiscover, Set pAlreadyProcessedTypes)
567:                    throws BSException {
568:                List lTypesToReturn = new ArrayList();
569:                BSAdapterGenerator lGenerator = getGenerator(lTypeToDiscover);
570:                String[] lRequiredAdapterTypes = lGenerator
571:                        .getRequiredAdapters();
572:                if (lRequiredAdapterTypes != null
573:                        && lRequiredAdapterTypes.length > 0) {
574:                    for (int i = 0; i < lRequiredAdapterTypes.length; i++) {
575:                        String lRequiredAdapterType = lRequiredAdapterTypes[i];
576:                        if (pAlreadyProcessedTypes
577:                                .contains(lRequiredAdapterType) == false) {
578:                            pAlreadyProcessedTypes.add(lRequiredAdapterType);
579:                            String[] lRequiredTypes = getRequiredAdapterTypes(
580:                                    lRequiredAdapterType,
581:                                    pAlreadyProcessedTypes);
582:                            lTypesToReturn
583:                                    .addAll(Arrays.asList(lRequiredTypes));
584:                            lTypesToReturn.add(lRequiredAdapterType);
585:                        }
586:                    }
587:                }
588:                return (String[]) lTypesToReturn
589:                        .toArray(new String[lTypesToReturn.size()]);
590:            }
591:
592:            // Get generator for the adapter	
593:            private static BSAdapterGenerator getGenerator(String pTypeRequired) {
594:                try {
595:                    // First obtain the implementation generator
596:                    Properties lContextProps = new Properties();
597:                    lContextProps
598:                            .setProperty(
599:                                    "com.metaboss.naming.component.com.metaboss.sdlctools.services.codegeneration.BSAdapterGenerator",
600:                                    "com.metaboss.sdlctools.services.codegeneration.servicemoduleadaptergenerator."
601:                                            + pTypeRequired);
602:                    Context lContext = new InitialContext(lContextProps);
603:                    return (BSAdapterGenerator) lContext
604:                            .lookup(BSAdapterGenerator.COMPONENT_URL);
605:                } catch (NamingException e) {
606:                    throw new BuildException(
607:                            "Unable to locate generator for the Servicemodule Adapter of type '"
608:                                    + pTypeRequired
609:                                    + "'. Caught NamingException: "
610:                                    + e.getMessage());
611:                }
612:            }
613:
614:            // Retruns the globally unique id of the generator
615:            private static String getGeneratorIdentifier(String pGeneratorType) {
616:                return "com.metaboss.sdlctools.services.codegeneration.servicemoduleadaptergenerator."
617:                        + pGeneratorType;
618:            }
619:        }
w__w_w_.__j_av___a_2s___.__c___om___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.