Source Code Cross Referenced for BuildObjectViewer_2.java in  » J2EE » Jaffa » org » jaffa » tools » patternmetaengine » 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 » J2EE » Jaffa » org.jaffa.tools.patternmetaengine 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * ====================================================================
003:         * JAFFA - Java Application Framework For All
004:         *
005:         * Copyright (C) 2002 JAFFA Development Group
006:         *
007:         *     This library is free software; you can redistribute it and/or
008:         *     modify it under the terms of the GNU Lesser General Public
009:         *     License as published by the Free Software Foundation; either
010:         *     version 2.1 of the License, or (at your option) any later version.
011:         *
012:         *     This library is distributed in the hope that it will be useful,
013:         *     but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015:         *     Lesser General Public License for more details.
016:         *
017:         *     You should have received a copy of the GNU Lesser General Public
018:         *     License along with this library; if not, write to the Free Software
019:         *     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
020:         *
021:         * Redistribution and use of this software and associated documentation ("Software"),
022:         * with or without modification, are permitted provided that the following conditions are met:
023:         * 1.	Redistributions of source code must retain copyright statements and notices.
024:         *         Redistributions must also contain a copy of this document.
025:         * 2.	Redistributions in binary form must reproduce the above copyright notice,
026:         * 	this list of conditions and the following disclaimer in the documentation
027:         * 	and/or other materials provided with the distribution.
028:         * 3.	The name "JAFFA" must not be used to endorse or promote products derived from
029:         * 	this Software without prior written permission. For written permission,
030:         * 	please contact mail to: jaffagroup@yahoo.com.
031:         * 4.	Products derived from this Software may not be called "JAFFA" nor may "JAFFA"
032:         * 	appear in their names without prior written permission.
033:         * 5.	Due credit should be given to the JAFFA Project (http://jaffa.sourceforge.net).
034:         *
035:         * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
036:         * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
037:         * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
038:         * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
039:         * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
040:         * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
041:         * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
042:         * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
043:         * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
044:         * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
045:         * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
046:         * SUCH DAMAGE.
047:         * ====================================================================
048:         */
049:        package org.jaffa.tools.patternmetaengine;
050:
051:        import java.io.File;
052:        import java.io.FileOutputStream;
053:        import java.io.IOException;
054:        import java.io.FileNotFoundException;
055:        import java.util.List;
056:        import java.util.Iterator;
057:        import java.util.ArrayList;
058:        import java.util.Properties;
059:
060:        import javax.xml.bind.JAXBContext;
061:        import javax.xml.bind.Validator;
062:        import javax.xml.bind.ValidationException;
063:        import javax.xml.bind.JAXBException;
064:        import javax.xml.bind.Marshaller;
065:        import javax.xml.bind.util.ValidationEventCollector;
066:        import javax.xml.bind.ValidationEvent;
067:
068:        import org.apache.log4j.Logger;
069:        import org.jaffa.util.StringHelper;
070:        import org.jaffa.datatypes.Defaults;
071:        import org.jaffa.tools.patternmetaengine.domain.ApplicationBuilder;
072:        import org.jaffa.tools.patternmetaengine.domain.Module;
073:        import org.jaffa.patterns.library.domain_creator_1_1.domain.Field;
074:        import org.jaffa.patterns.library.domain_creator_1_1.domain.Relationship;
075:        import org.jaffa.patterns.library.domain_creator_1_1.domain.RelationshipField;
076:        import org.jaffa.patterns.library.object_viewer_meta_2_0.domain.*;
077:        import java.io.ByteArrayOutputStream;
078:        import java.beans.XMLEncoder;
079:
080:        /** Create the meta data for an Object Viewer Pattern, based on a specified
081:         * Domain Object.
082:         *
083:         * @author  PaulE
084:         * @version 1.0
085:         */
086:        public class BuildObjectViewer_2 implements  IBuilder {
087:
088:            /** Set up Logging for Log4J */
089:            private static Logger log = Logger
090:                    .getLogger(BuildObjectViewer.class);
091:
092:            private ApplicationBuilder m_app = null;
093:            private Module m_module = null;
094:            private org.jaffa.patterns.library.domain_creator_1_1.domain.Root m_domain = null;
095:            private DomainObjectHelper m_doList;
096:            private ObjectViewerMeta m_viewer = null;
097:
098:            private List m_upDomain = null;
099:            private List m_upRel = null;
100:            private Properties m_labels = null;
101:            private ComponentRegistry m_compReg = null;
102:
103:            /** Creates a new instance of BuildObjectViewer */
104:            public BuildObjectViewer_2(
105:                    ApplicationBuilder app,
106:                    ComponentRegistry comps,
107:                    Module module,
108:                    org.jaffa.patterns.library.domain_creator_1_1.domain.Root domain,
109:                    DomainObjectHelper doList, Properties labels) {
110:
111:                log.debug("Create Viewer For - " + domain.getDomainObject());
112:                m_compReg = comps;
113:                m_app = app;
114:                m_module = module;
115:                m_domain = domain;
116:                m_doList = doList;
117:                m_labels = labels;
118:            }
119:
120:            /** Causes the meta data object to be build ready for saving.
121:             * @param fullPackage If true then the .applications. and .modules. package names
122:             * are used. If this is false, these are ommited for a much more condensed package
123:             * naming convention
124:             */
125:            public void buildPhase1(boolean fullPackage) throws Exception {
126:
127:                initUpEntities();
128:
129:                ObjectFactory objFactory = new ObjectFactory();
130:                try {
131:                    m_viewer = objFactory.createObjectViewerMeta();
132:                    m_viewer
133:                            .setPatternTemplate("patterns/library/object_viewer_2_0/ObjectViewerPattern.xml"); // Mand
134:                    m_viewer.setApplication(m_app.getApplicationName()); // Mand
135:                    m_viewer.setModule(m_module.getName()); // Mand
136:                    m_viewer
137:                            .setComponent(m_domain.getDomainObject() + "Viewer"); // Mand
138:                    StringBuffer sb = new StringBuffer();
139:                    sb.append(m_app.getPackagePrefix());
140:                    sb.append(".");
141:                    if (fullPackage)
142:                        sb.append("applications.");
143:                    sb.append(m_app.getApplicationName());
144:                    sb.append(".");
145:                    if (fullPackage)
146:                        sb.append("modules.");
147:                    sb.append(m_module.getName());
148:                    m_viewer.setBasePackage(sb.toString().toLowerCase()); // Mand
149:                    m_viewer.setDomainObject(m_domain.getDomainObject()); // Mand
150:                    m_viewer.setDomainPackage(m_domain.getDomainPackage()); // Mand
151:
152:                    // Create Labels for the screen titles
153:                    String labelDomain = m_domain.getLabelToken();// get it from the domain object or fabricate it!
154:                    if (labelDomain == null)
155:                        labelDomain = "[label."
156:                                + StringHelper.getUpper1(m_app
157:                                        .getApplicationName())
158:                                + "."
159:                                + StringHelper.getUpper1(m_module.getName())
160:                                + "."
161:                                + StringHelper.getUpper1(m_domain
162:                                        .getDomainObject()) + "]";
163:                    String labelId = "title."
164:                            + StringHelper
165:                                    .getUpper1(m_app.getApplicationName())
166:                            + "."
167:                            + StringHelper.getUpper1(m_module.getName())
168:                            + "."
169:                            + StringHelper
170:                                    .getUpper1(m_domain.getDomainObject())
171:                            + "Viewer.";
172:                    // Set Title
173:                    m_viewer.setTitle("[" + labelId + "view" + "]"); // Opt
174:                    m_labels.put(labelId + "view", labelDomain + " Details");
175:
176:                    // Add in tiles customizations of specified
177:                    if (m_module.getModuleTilePrefix() != null
178:                            && m_module.getModuleTilePrefix().length() > 0) {
179:                        m_viewer.setMainLayout(m_module.getModuleTilePrefix()
180:                                + ".MainLayout");
181:                        m_viewer.setViewerLayout(m_module.getModuleTilePrefix()
182:                                + ".ViewerLayout");
183:                    }
184:
185:                    // Add All Fields as Criteria Fields
186:                    List fields = m_domain.getFields().getField();
187:                    if (fields == null || fields.isEmpty()) {
188:                        log
189:                                .error("Domain Object "
190:                                        + m_domain.getDomainObject()
191:                                        + " has no fields, this is needed to build a valid viewer");
192:                    } else {
193:
194:                        //--------------------------------
195:                        // Create Criteria Fields
196:                        CriteriaFields cfields = objFactory
197:                                .createCriteriaFields();
198:                        m_viewer.setCriteriaFields(cfields);
199:                        for (Iterator it1 = fields.iterator(); it1.hasNext();) {
200:                            Field fld = (Field) it1.next();
201:
202:                            //--------------------------------
203:                            // Only make the primary key field available for the retreive
204:                            if (fld.getPrimaryKey().equalsIgnoreCase("t")) {
205:                                CriteriaField cfld = objFactory
206:                                        .createCriteriaField();
207:                                cfields.getCriteriaField().add(cfld);
208:                                cfld.setName(reservedName(fld.getName()));
209:                                String dt = Defaults.getDataType(fld
210:                                        .getDataType());
211:                                if (dt == null)
212:                                    throw new Exception(
213:                                            "Can't Translate Java Class "
214:                                                    + fld.getDataType()
215:                                                    + " to a supported Data Type");
216:                                cfld.setDataType(dt);
217:                                cfld.setDomainField(fld.getName());
218:                            }
219:                        }
220:
221:                        //--------------------------------
222:                        // Create Results/Display Fields
223:                        ResultsFields rfields = objFactory
224:                                .createResultsFields();
225:                        m_viewer.setResultsFields(rfields);
226:                        for (Iterator it1 = fields.iterator(); it1.hasNext();) {
227:                            Field fld = (Field) it1.next();
228:
229:                            //--------------------------------
230:                            // Create a basic display field
231:                            ResultsField rfld = objFactory.createResultsField();
232:                            rfields.getResultsField().add(rfld);
233:
234:                            rfld.setName(reservedName(fld.getName()));
235:                            String dt = Defaults.getDataType(fld.getDataType());
236:                            if (dt == null)
237:                                throw new Exception(
238:                                        "Can't Translate Java Class "
239:                                                + fld.getDataType()
240:                                                + " to a supported Data Type");
241:                            rfld.setDataType(dt);
242:                            rfld.setDisplay(true);
243:                            rfld
244:                                    .setLabel(fld.getLabelToken() /*"[" + labelDomain + "." + fld.getName() + "]"*/);
245:                            rfld.setDomainField(fld.getName());
246:
247:                        }
248:
249:                        //----------------
250:                        // Include section for each aggregated entity
251:                        if (m_domain.getRelationships() != null) {
252:                            List rels = m_domain.getRelationships()
253:                                    .getRelationship();
254:                            if (rels != null) {
255:
256:                                // Create list of related objects
257:                                RelatedObjects relObjs = objFactory
258:                                        .createRelatedObjects();
259:                                List relList = relObjs.getRelatedObject();
260:
261:                                //------------------------------
262:                                // Loop through the relationships
263:                                for (Iterator it2 = rels.iterator(); it2
264:                                        .hasNext();) {
265:                                    Relationship rel = (Relationship) it2
266:                                            .next();
267:                                    // Get the related domain object
268:                                    if (!rel.getType().equalsIgnoreCase(
269:                                            "association")) {
270:                                        org.jaffa.patterns.library.domain_creator_1_1.domain.Root innerDomain = m_doList
271:                                                .getByDomain(rel
272:                                                        .getToDomainObject());
273:
274:                                        // Create a related object in the viewer
275:                                        RelatedObject relObj = objFactory
276:                                                .createRelatedObject();
277:                                        relList.add(relObj);
278:                                        relObj.setObjectName(innerDomain
279:                                                .getDomainObject());
280:                                        relObj.setPackage(innerDomain
281:                                                .getDomainPackage());
282:
283:                                        //------------------------------
284:                                        // Add the join fields for this relationship
285:                                        RelatedObjectJoinFields rojf = objFactory
286:                                                .createRelatedObjectJoinFields();
287:                                        relObj.setRelatedObjectJoinFields(rojf);
288:                                        List rojbList = rojf
289:                                                .getRelatedObjectJoinBetween();
290:                                        List domainKeys = rel.getFromFields()
291:                                                .getRelationshipField();
292:                                        List foreignKeys = rel.getToFields()
293:                                                .getRelationshipField();
294:                                        // loop through joined fields
295:                                        for (int i = 0; i < domainKeys.size(); i++) {
296:                                            RelatedObjectJoinBetween rojb = objFactory
297:                                                    .createRelatedObjectJoinBetween();
298:                                            rojbList.add(rojb);
299:                                            rojb
300:                                                    .setDomainField(((RelationshipField) domainKeys
301:                                                            .get(i)).getName());
302:                                            rojb
303:                                                    .setRelatedObjectDomainField(((RelationshipField) foreignKeys
304:                                                            .get(i)).getName());
305:                                            // use same name for fields as the domain names
306:                                            rojb.setName(rojb.getDomainField());
307:                                            rojb
308:                                                    .setRelatedObjectFieldName(rojb
309:                                                            .getRelatedObjectDomainField());
310:                                        }
311:
312:                                        //------------------------------
313:                                        // Add the related fields
314:
315:                                        /*
316:                                        String innerLabelDomain = "label." + StringHelper.getUpper1(m_app.getApplicationName()) +
317:                                            "." + StringHelper.getUpper1(m_module.getName()) + "." +
318:                                            StringHelper.getUpper1(innerDomain.getDomainObject());
319:                                         */
320:                                        List innerFlds = innerDomain
321:                                                .getFields().getField();
322:                                        RelatedObjectFields rofs = objFactory
323:                                                .createRelatedObjectFields();
324:                                        relObj.setRelatedObjectFields(rofs);
325:                                        List relFields = rofs
326:                                                .getRelatedObjectField();
327:
328:                                        KeyFields kfs = objFactory
329:                                                .createKeyFields();
330:                                        relObj.setKeyFields(kfs);
331:                                        List relKeys = kfs.getKeyField();
332:
333:                                        OrderByFields obfs = objFactory
334:                                                .createOrderByFields();
335:                                        relObj.setOrderByFields(obfs);
336:                                        List orderFlds = obfs.getOrderByField();
337:
338:                                        for (Iterator it3 = innerFlds
339:                                                .iterator(); it3.hasNext();) {
340:                                            Field innerFld = (Field) it3.next();
341:
342:                                            //------------------------------
343:                                            // If this field is used in the relationship, ignore it!
344:                                            List toflds = rel.getToFields()
345:                                                    .getRelationshipField();
346:                                            boolean inRel = false;
347:                                            for (Iterator it4 = toflds
348:                                                    .iterator(); it4.hasNext();) {
349:                                                RelationshipField rf = (RelationshipField) it4
350:                                                        .next();
351:                                                if (rf.getName().equals(
352:                                                        innerFld.getName())) {
353:                                                    inRel = true;
354:                                                    break;
355:                                                }
356:                                            }
357:                                            String dt = Defaults
358:                                                    .getDataType(innerFld
359:                                                            .getDataType());
360:                                            if (dt == null)
361:                                                throw new Exception(
362:                                                        "Can't Translate Java Class "
363:                                                                + innerFld
364:                                                                        .getDataType()
365:                                                                + " to a supported Data Type");
366:
367:                                            //------------------------------
368:                                            // Create related field
369:                                            RelatedObjectField rof = objFactory
370:                                                    .createRelatedObjectField();
371:                                            relFields.add(rof);
372:                                            rof.setName(innerFld.getName());
373:                                            rof.setDataType(dt);
374:                                            rof.setDisplay(!inRel);
375:                                            rof.setDisplayAsKey(innerFld
376:                                                    .getPrimaryKey()
377:                                                    .equalsIgnoreCase("t"));
378:                                            //rof.setLabel("[" + innerLabelDomain + "." + innerFld.getName() + "]");
379:                                            rof.setLabel(innerFld
380:                                                    .getLabelToken());
381:                                            rof.setDomainField(innerFld
382:                                                    .getName());
383:
384:                                            //------------------
385:                                            // If this is a key add it to the related object key
386:                                            if (innerFld.getPrimaryKey()
387:                                                    .equalsIgnoreCase("t")) {
388:                                                KeyField kf = objFactory
389:                                                        .createKeyField();
390:                                                relKeys.add(kf);
391:                                                kf.setDataType(dt);
392:                                                kf
393:                                                        .setRelatedObjectFieldName(innerFld
394:                                                                .getName());
395:                                                kf
396:                                                        .setFieldNameInTargetComponent(innerFld
397:                                                                .getName());
398:                                            }
399:
400:                                            // If this is a key, display it.
401:                                            if (rof.isDisplayAsKey()) {
402:                                                OrderByField obf = objFactory
403:                                                        .createOrderByField();
404:                                                orderFlds.add(obf);
405:                                                obf.setDomainFieldName(innerFld
406:                                                        .getName());
407:                                                obf.setSortAscending("true");
408:                                            }
409:                                        }
410:                                    } // !=association
411:                                } // Loop through the relationships
412:
413:                                // Only add object list if there were some to add
414:                                log.debug("Relationship procssed "
415:                                        + rels.size() + ", " + relList.size()
416:                                        + " added to pattern");
417:                                if (relList.size() > 0)
418:                                    m_viewer.setRelatedObjects(relObjs);
419:
420:                            } // No relationhips
421:                        } // No relationships
422:                    } // Domain Object has fields!
423:
424:                } catch (JAXBException e) {
425:                    log.error("Failed to create Viewer Object");
426:                }
427:            }
428:
429:            /** Saves the generated meta data to the prespecified location as an XML file
430:             * NOTE: assumes that the build(..) method has been called!
431:             */
432:            public boolean save() {
433:                String filename = m_app.getOutputRoot()
434:                        + m_app.getOutputViewers() +
435:                        /* m_module.getName().toLowerCase() + File.separator + */
436:                        m_domain.getDomainObject() + "Viewer.xml";
437:                File file = new File(filename);
438:                File path = new File(file.getParent());
439:                if (!path.exists())
440:                    path.mkdirs();
441:
442:                // Create output stream
443:                FileOutputStream out = null;
444:                try {
445:                    try {
446:                        out = new FileOutputStream(file.getPath());
447:                    } catch (FileNotFoundException e) {
448:                        log.error("Failed to open output stream !", e);
449:                        return false;
450:                    }
451:
452:                    try {
453:                        // create a JAXBContext capable of handling classes generated into the package
454:                        JAXBContext jc = JAXBContext
455:                                .newInstance("org.jaffa.patterns.library.object_viewer_meta_2_0.domain");
456:                        // create a Validator
457:                        Validator v = jc.createValidator();
458:                        ValidationEventCollector valErrors = new ValidationEventCollector();
459:                        v.setEventHandler(valErrors);
460:                        // validate the content tree
461:                        if (!v.validateRoot(m_viewer)) {
462:                            log.error("Failed to validate Structure !");
463:                            JAXBHelper.showErrors(log, valErrors);
464:
465:                            // Display current XML
466:                            ByteArrayOutputStream s = new ByteArrayOutputStream();
467:                            XMLEncoder e = new XMLEncoder(s);
468:                            e.writeObject(m_viewer);
469:                            e.close();
470:                            log
471:                                    .error("Here is a XML representation of the invalid JavaBean...\n"
472:                                            + s.toString());
473:
474:                            return false;
475:                        }
476:
477:                        // Write out XML document to file
478:                        Marshaller m = jc.createMarshaller();
479:                        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,
480:                                Boolean.TRUE);
481:                        JAXBHelper
482:                                .marshalWithDocType(
483:                                        m,
484:                                        m_viewer,
485:                                        out,
486:                                        "Root",
487:                                        "-//JAFFA//DTD Object Viewer Meta 2.0//EN",
488:                                        "http://jaffa.sourceforge.net/DTD/object-viewer-meta_2_0.dtd");
489:
490:                    } catch (ValidationException e) {
491:                        log.error("Failed to validate Structure !", e);
492:                        return false;
493:                    } catch (JAXBException e) {
494:                        log
495:                                .error(
496:                                        "Failed to marshal xml to output stream !",
497:                                        e);
498:                        return false;
499:                    }
500:                } finally {
501:                    if (out != null)
502:                        try {
503:                            out.close();
504:                        } catch (IOException e) {
505:                        }
506:                }
507:                return true;
508:            }
509:
510:            private static List reservedAttr = null;
511:            static {
512:                reservedAttr = new ArrayList();
513:                reservedAttr.add("component");
514:            }
515:
516:            private String reservedName(String name) {
517:                if (reservedAttr.contains(name.toLowerCase()))
518:                    return name + "1";
519:                else
520:                    return name;
521:            }
522:
523:            private void initUpEntities() {
524:                m_upDomain = new ArrayList();
525:                m_upRel = new ArrayList();
526:
527:                for (Iterator it = m_doList.iterator(); it.hasNext();) {
528:                    org.jaffa.patterns.library.domain_creator_1_1.domain.Root domain = (org.jaffa.patterns.library.domain_creator_1_1.domain.Root) it
529:                            .next();
530:                    if (domain.getRelationships() != null) {
531:                        List rels = domain.getRelationships().getRelationship();
532:                        if (rels != null && !rels.isEmpty())
533:                            for (Iterator it2 = rels.iterator(); it2.hasNext();) {
534:                                org.jaffa.patterns.library.domain_creator_1_1.domain.Relationship rel = (org.jaffa.patterns.library.domain_creator_1_1.domain.Relationship) it2
535:                                        .next();
536:                                if (m_domain.getDomainObject().equals(
537:                                        rel.getToDomainObject())
538:                                        && m_domain.getDomainPackage().equals(
539:                                                rel.getToDomainPackage())) {
540:                                    // This domain object relates to this one
541:                                    m_upDomain.add(domain);
542:                                    m_upRel.add(rel);
543:                                    break;
544:                                }
545:                            }
546:                    }
547:                }
548:
549:                // Show the results in debug mode
550:                /*
551:                if(log.isDebugEnabled()) {
552:                    log.debug("Finding Up Entities For " + m_domain.getDomainObject());
553:                    for(int i = 0; i < m_upDomain.size(); i++ ) {
554:                        org.jaffa.patterns.library.domain_creator_1_1.domain.Root domain = (org.jaffa.patterns.library.domain_creator_1_1.domain.Root) m_upDomain.get(i);
555:                        log.debug("...Found - " + domain.getDomainObject() );
556:                    }
557:                }
558:                 */
559:            }
560:
561:            private int getUpDomain(String fieldname) {
562:                for (int i = 0; i < m_upDomain.size(); i++) {
563:                    org.jaffa.patterns.library.domain_creator_1_1.domain.Root domain = (org.jaffa.patterns.library.domain_creator_1_1.domain.Root) m_upDomain
564:                            .get(i);
565:                    org.jaffa.patterns.library.domain_creator_1_1.domain.Relationship rel = (org.jaffa.patterns.library.domain_creator_1_1.domain.Relationship) m_upRel
566:                            .get(i);
567:                    List toFields = rel.getToFields().getRelationshipField();
568:                    if (toFields.size() == 1) {
569:                        org.jaffa.patterns.library.domain_creator_1_1.domain.RelationshipField toFld = (org.jaffa.patterns.library.domain_creator_1_1.domain.RelationshipField) toFields
570:                                .get(0);
571:                        if (toFld.getName().equals(fieldname)) {
572:                            log.debug("...Found - " + domain.getDomainObject());
573:                            return i;
574:                        }
575:                    }
576:                }
577:                return -1;
578:            }
579:
580:            public String getApplication() {
581:                return m_viewer.getApplication();
582:            }
583:
584:            public String getComponentControllerClass() {
585:                return m_viewer.getComponent() + "Component";
586:            }
587:
588:            public String getComponentControllerPackage() {
589:                return m_viewer.getBasePackage() + ".components."
590:                        + m_viewer.getComponent().toLowerCase() + ".ui";
591:            }
592:
593:            public String getComponentName() {
594:                return getModule() + "."
595:                        + StringHelper.getUpper1(m_viewer.getComponent());
596:            }
597:
598:            public String getComponentType() {
599:                return "Viewer";
600:            }
601:
602:            public String getDomain() {
603:                return m_viewer.getDomainPackage() + "."
604:                        + m_viewer.getDomainObject();
605:            }
606:
607:            public String getModule() {
608:                return StringHelper.getUpper1(m_viewer.getModule());
609:            }
610:
611:            public String getName() {
612:                return StringHelper.getUpper1(m_viewer.getComponent());
613:            }
614:
615:            /** Causes the meta data object to be build ready for saving.
616:             * @param fullPackage If true then the .applications. and .modules. package names
617:             * are used. If this is false, these are ommited for a much more condensed package
618:             * naming convention
619:             */
620:            public void buildPhase2(boolean fullPackage) throws Exception {
621:                ObjectFactory objFactory = new ObjectFactory();
622:
623:                //--------------------------------
624:                // Loop through the results fields,
625:                List results = m_viewer.getResultsFields().getResultsField();
626:                for (Iterator it = results.iterator(); it.hasNext();) {
627:                    ResultsField rfld = (ResultsField) it.next();
628:
629:                    //--------------------------------
630:                    // If this is a foriegn key, link it to the parent viewer
631:                    // ..todo..
632:                    int upDomainIdx = getUpDomain(rfld.getName());
633:                    if (upDomainIdx != -1) {
634:                        org.jaffa.patterns.library.domain_creator_1_1.domain.Root upDomain = (org.jaffa.patterns.library.domain_creator_1_1.domain.Root) m_upDomain
635:                                .get(upDomainIdx);
636:                        org.jaffa.patterns.library.domain_creator_1_1.domain.Relationship upRel = (org.jaffa.patterns.library.domain_creator_1_1.domain.Relationship) m_upRel
637:                                .get(upDomainIdx);
638:                        log.debug("Linking 'Up' Viewer "
639:                                + upDomain.getDomainObject() + " to "
640:                                + m_domain.getDomainObject());
641:                        // Find viewer
642:                        IBuilder vcomp = m_compReg.findComponent(upDomain
643:                                .getDomainPackage()
644:                                + "." + upDomain.getDomainObject(), "Viewer");
645:                        if (vcomp != null) {
646:                            // Link this to a viewer now....
647:                            Viewer viewer = objFactory.createViewer();
648:                            rfld.setViewer(viewer);
649:                            viewer.setClassName(vcomp
650:                                    .getComponentControllerClass());
651:                            viewer.setComponentName(vcomp.getComponentName());
652:                            viewer.setPackage(vcomp
653:                                    .getComponentControllerPackage());
654:                            viewer
655:                                    .setFieldNameInTargetComponent(reservedName(((org.jaffa.patterns.library.domain_creator_1_1.domain.RelationshipField) upRel
656:                                            .getFromFields()
657:                                            .getRelationshipField().get(0))
658:                                            .getName()));
659:                        } else
660:                            log.info("No related viewer found in "
661:                                    + getComponentName() + " for "
662:                                    + upDomain.getDomainObject());
663:                    }
664:                }
665:
666:                //-----------------------------
667:                // Loop through all related objects an link in there viewers
668:                if (m_viewer.getRelatedObjects() != null) {
669:                    List related = m_viewer.getRelatedObjects()
670:                            .getRelatedObject();
671:                    for (Iterator it = related.iterator(); it.hasNext();) {
672:                        RelatedObject robj = (RelatedObject) it.next();
673:
674:                        log.debug("Linking 'Down' Viewer "
675:                                + robj.getObjectName() + " to "
676:                                + m_domain.getDomainObject());
677:
678:                        // Find related viewer
679:                        IBuilder vcomp = m_compReg.findComponent(robj
680:                                .getPackage()
681:                                + "." + robj.getObjectName(), "Viewer");
682:                        if (vcomp != null) {
683:                            RelatedObjectViewer rviewer = objFactory
684:                                    .createRelatedObjectViewer();
685:                            robj.setRelatedObjectViewer(rviewer);
686:                            rviewer.setClassName(vcomp
687:                                    .getComponentControllerClass());
688:                            rviewer.setComponentName(vcomp.getComponentName());
689:                            rviewer.setPackage(vcomp
690:                                    .getComponentControllerPackage());
691:                        } else
692:                            log.info("No related viewer in component "
693:                                    + getComponentName() + " for domain "
694:                                    + robj.getObjectName());
695:                    }
696:                }
697:
698:                // Find The Related Maintenance Component To Link To
699:                IBuilder mcomp = m_compReg.findComponent(this .getDomain(),
700:                        "Maintenance");
701:                if (mcomp != null) {
702:                    // Updator
703:                    Updator updator = objFactory.createUpdator();
704:                    m_viewer.setUpdator(updator);
705:                    updator.setClassName(mcomp.getComponentControllerClass());
706:                    updator.setComponentName(mcomp.getComponentName());
707:                    updator.setPackage(mcomp.getComponentControllerPackage());
708:                }
709:
710:            }
711:
712:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.