Source Code Cross Referenced for BuildObjectViewer_1.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_1_0.domain.*;
077:
078:        /** Create the meta data for an Object Viewer Pattern, based on a specified
079:         * Domain Object.
080:         *
081:         * @author  PaulE
082:         * @version 1.0
083:         */
084:        public class BuildObjectViewer_1 implements  IBuilder {
085:
086:            /** Set up Logging for Log4J */
087:            private static Logger log = Logger
088:                    .getLogger(BuildObjectViewer.class);
089:
090:            private ApplicationBuilder m_app = null;
091:            private Module m_module = null;
092:            private org.jaffa.patterns.library.domain_creator_1_1.domain.Root m_domain = null;
093:            private DomainObjectHelper m_doList;
094:            private ObjectViewerMeta m_viewer = null;
095:
096:            private List m_upDomain = null;
097:            private List m_upRel = null;
098:            private Properties m_labels = null;
099:            private ComponentRegistry m_compReg = null;
100:
101:            /** Creates a new instance of BuildObjectViewer */
102:            public BuildObjectViewer_1(
103:                    ApplicationBuilder app,
104:                    ComponentRegistry comps,
105:                    Module module,
106:                    org.jaffa.patterns.library.domain_creator_1_1.domain.Root domain,
107:                    DomainObjectHelper doList, Properties labels) {
108:
109:                log.debug("Create Viewer For - " + domain.getDomainObject());
110:                m_compReg = comps;
111:                m_app = app;
112:                m_module = module;
113:                m_domain = domain;
114:                m_doList = doList;
115:                m_labels = labels;
116:            }
117:
118:            /** Causes the meta data object to be build ready for saving.
119:             * @param fullPackage If true then the .applications. and .modules. package names
120:             * are used. If this is false, these are ommited for a much more condensed package
121:             * naming convention
122:             */
123:            public void buildPhase1(boolean fullPackage) throws Exception {
124:
125:                initUpEntities();
126:
127:                ObjectFactory objFactory = new ObjectFactory();
128:                try {
129:                    m_viewer = objFactory.createObjectViewerMeta();
130:                    m_viewer
131:                            .setPatternTemplate("patterns/library/object_viewer_1_0/ObjectViewerPattern.xml"); // Mand
132:                    m_viewer.setApplication(m_app.getApplicationName()); // Mand
133:                    m_viewer.setModule(m_module.getName()); // Mand
134:                    m_viewer
135:                            .setComponent(m_domain.getDomainObject() + "Viewer"); // Mand
136:                    StringBuffer sb = new StringBuffer();
137:                    sb.append(m_app.getPackagePrefix());
138:                    sb.append(".");
139:                    if (fullPackage)
140:                        sb.append("applications.");
141:                    sb.append(m_app.getApplicationName());
142:                    sb.append(".");
143:                    if (fullPackage)
144:                        sb.append("modules.");
145:                    sb.append(m_module.getName());
146:                    m_viewer.setBasePackage(sb.toString().toLowerCase()); // Mand
147:                    m_viewer.setDomainObject(m_domain.getDomainObject()); // Mand
148:                    m_viewer.setDomainPackage(m_domain.getDomainPackage()); // Mand
149:
150:                    // Create Labels for the screen titles
151:                    String labelDomain = "label."
152:                            + StringHelper
153:                                    .getUpper1(m_app.getApplicationName())
154:                            + "."
155:                            + StringHelper.getUpper1(m_module.getName())
156:                            + "."
157:                            + StringHelper
158:                                    .getUpper1(m_domain.getDomainObject());
159:                    String labelId = "title."
160:                            + StringHelper
161:                                    .getUpper1(m_app.getApplicationName())
162:                            + "."
163:                            + StringHelper.getUpper1(m_module.getName())
164:                            + "."
165:                            + StringHelper
166:                                    .getUpper1(m_domain.getDomainObject())
167:                            + "Viewer.";
168:                    // Set Title
169:                    m_viewer.setTitle(labelId + "view"); // Opt
170:                    m_labels.put(m_viewer.getTitle(), "[" + labelDomain
171:                            + "] Details");
172:
173:                    // Add All Fields as Criteria Fields
174:                    List fields = m_domain.getFields().getField();
175:                    if (fields == null || fields.isEmpty()) {
176:                        log
177:                                .error("Domain Object "
178:                                        + m_domain.getDomainObject()
179:                                        + " has no fields, this is needed to build a valid viewer");
180:                    } else {
181:
182:                        //--------------------------------
183:                        // Create Criteria Fields
184:                        CriteriaFields cfields = objFactory
185:                                .createCriteriaFields();
186:                        m_viewer.setCriteriaFields(cfields);
187:                        for (Iterator it1 = fields.iterator(); it1.hasNext();) {
188:                            Field fld = (Field) it1.next();
189:
190:                            //--------------------------------
191:                            // Only make the primary key field available for the retreive
192:                            if (fld.getPrimaryKey().equalsIgnoreCase("t")) {
193:                                CriteriaField cfld = objFactory
194:                                        .createCriteriaField();
195:                                cfields.getCriteriaField().add(cfld);
196:                                cfld.setName(reservedName(fld.getName()));
197:                                String dt = Defaults.getDataType(fld
198:                                        .getDataType());
199:                                if (dt == null)
200:                                    throw new Exception(
201:                                            "Can't Translate Java Class "
202:                                                    + fld.getDataType()
203:                                                    + " to a supported Data Type");
204:                                cfld.setDataType(dt);
205:                                cfld.setDomainField(fld.getName());
206:                            }
207:                        }
208:
209:                        //--------------------------------
210:                        // Create Results/Display Fields
211:                        ResultsFields rfields = objFactory
212:                                .createResultsFields();
213:                        m_viewer.setResultsFields(rfields);
214:                        for (Iterator it1 = fields.iterator(); it1.hasNext();) {
215:                            Field fld = (Field) it1.next();
216:
217:                            //--------------------------------
218:                            // Create a basic display field
219:                            ResultsField rfld = objFactory.createResultsField();
220:                            rfields.getResultsField().add(rfld);
221:
222:                            rfld.setName(reservedName(fld.getName()));
223:                            String dt = Defaults.getDataType(fld.getDataType());
224:                            if (dt == null)
225:                                throw new Exception(
226:                                        "Can't Translate Java Class "
227:                                                + fld.getDataType()
228:                                                + " to a supported Data Type");
229:                            rfld.setDataType(dt);
230:                            rfld.setDisplay(true);
231:                            rfld.setLabel("[" + labelDomain + "."
232:                                    + fld.getName() + "]");
233:                            rfld
234:                                    .setWidth("300px" /*""+ ( (fld.getIntSize()!=null ? fld.getIntSize().intValue() : 0) +
235:                                                                            (fld.getFracSize()!=null ? fld.getFracSize().intValue() : 0) + 2) */);
236:                            rfld.setDomainField(fld.getName());
237:
238:                        }
239:
240:                        //----------------
241:                        // Include section for each aggregated entity
242:                        if (m_domain.getRelationships() != null) {
243:                            List rels = m_domain.getRelationships()
244:                                    .getRelationship();
245:                            if (rels != null) {
246:
247:                                // Create list of related objects
248:                                RelatedObjects relObjs = objFactory
249:                                        .createRelatedObjects();
250:                                m_viewer.setRelatedObjects(relObjs);
251:                                List relList = relObjs.getRelatedObject();
252:
253:                                //------------------------------
254:                                // Loop through the relationships
255:                                for (Iterator it2 = rels.iterator(); it2
256:                                        .hasNext();) {
257:                                    Relationship rel = (Relationship) it2
258:                                            .next();
259:                                    // Get the related domain object
260:                                    org.jaffa.patterns.library.domain_creator_1_1.domain.Root innerDomain = m_doList
261:                                            .getByDomain(rel
262:                                                    .getToDomainObject());
263:
264:                                    // Create a related object in the viewer
265:                                    RelatedObject relObj = objFactory
266:                                            .createRelatedObject();
267:                                    relList.add(relObj);
268:                                    relObj.setObjectName(innerDomain
269:                                            .getDomainObject());
270:                                    relObj.setPackage(innerDomain
271:                                            .getDomainPackage());
272:
273:                                    //------------------------------
274:                                    // Add the join fields for this relationship
275:                                    RelatedObjectJoinFields rojf = objFactory
276:                                            .createRelatedObjectJoinFields();
277:                                    relObj.setRelatedObjectJoinFields(rojf);
278:                                    List rojbList = rojf
279:                                            .getRelatedObjectJoinBetween();
280:                                    List domainKeys = rel.getFromFields()
281:                                            .getRelationshipField();
282:                                    List foreignKeys = rel.getToFields()
283:                                            .getRelationshipField();
284:                                    // loop through joined fields
285:                                    for (int i = 0; i < domainKeys.size(); i++) {
286:                                        RelatedObjectJoinBetween rojb = objFactory
287:                                                .createRelatedObjectJoinBetween();
288:                                        rojbList.add(rojb);
289:                                        rojb
290:                                                .setDomainObjectField(((RelationshipField) domainKeys
291:                                                        .get(i)).getName());
292:                                        rojb
293:                                                .setRelatedObjectFieldName(((RelationshipField) foreignKeys
294:                                                        .get(i)).getName());
295:                                    }
296:
297:                                    //------------------------------
298:                                    // Add the related fields
299:
300:                                    /*
301:                                    String innerLabelDomain = "label." + StringHelper.getUpper1(m_app.getApplicationName()) +
302:                                        "." + StringHelper.getUpper1(m_module.getName()) + "." +
303:                                        StringHelper.getUpper1(innerDomain.getDomainObject());
304:                                     */
305:                                    List innerFlds = innerDomain.getFields()
306:                                            .getField();
307:                                    RelatedObjectFields rofs = objFactory
308:                                            .createRelatedObjectFields();
309:                                    relObj.setRelatedObjectFields(rofs);
310:                                    List relFields = rofs
311:                                            .getRelatedObjectField();
312:
313:                                    KeyFields kfs = objFactory
314:                                            .createKeyFields();
315:                                    relObj.setKeyFields(kfs);
316:                                    List relKeys = kfs.getKeyField();
317:
318:                                    OrderByFields obfs = objFactory
319:                                            .createOrderByFields();
320:                                    relObj.setOrderByFields(obfs);
321:                                    List orderFlds = obfs.getOrderByField();
322:
323:                                    for (Iterator it3 = innerFlds.iterator(); it3
324:                                            .hasNext();) {
325:                                        Field innerFld = (Field) it3.next();
326:
327:                                        //------------------------------
328:                                        // If this field is used in the relationship, ignore it!
329:                                        List toflds = rel.getToFields()
330:                                                .getRelationshipField();
331:                                        boolean inRel = false;
332:                                        for (Iterator it4 = toflds.iterator(); it4
333:                                                .hasNext();) {
334:                                            RelationshipField rf = (RelationshipField) it4
335:                                                    .next();
336:                                            if (rf.getName().equals(
337:                                                    innerFld.getName())) {
338:                                                inRel = true;
339:                                                break;
340:                                            }
341:                                        }
342:                                        String dt = Defaults
343:                                                .getDataType(innerFld
344:                                                        .getDataType());
345:                                        if (dt == null)
346:                                            throw new Exception(
347:                                                    "Can't Translate Java Class "
348:                                                            + innerFld
349:                                                                    .getDataType()
350:                                                            + " to a supported Data Type");
351:
352:                                        //------------------------------
353:                                        // Create related field
354:                                        RelatedObjectField rof = objFactory
355:                                                .createRelatedObjectField();
356:                                        relFields.add(rof);
357:                                        rof.setName(innerFld.getName());
358:                                        rof.setDataType(dt);
359:                                        rof.setDisplay(!inRel);
360:                                        rof.setDisplayAsKey(innerFld
361:                                                .getPrimaryKey()
362:                                                .equalsIgnoreCase("t"));
363:                                        //rof.setLabel("[" + innerLabelDomain + "." + innerFld.getName() + "]");
364:                                        rof.setLabel(innerFld.getLabelToken());
365:                                        rof
366:                                                .setWidth("300px" /*""+ ( (innerFld.getIntSize()!=null ? innerFld.getIntSize().intValue() : 0) +
367:                                                                                    (innerFld.getFracSize()!=null ? innerFld.getFracSize().intValue() : 0) + 2) */);
368:                                        rof.setDomainField(innerFld.getName());
369:
370:                                        //------------------
371:                                        // If this is a key add it to the related object key
372:                                        if (innerFld.getPrimaryKey()
373:                                                .equalsIgnoreCase("t")) {
374:                                            KeyField kf = objFactory
375:                                                    .createKeyField();
376:                                            relKeys.add(kf);
377:                                            kf.setDataType(dt);
378:                                            kf
379:                                                    .setRelatedObjectFieldName(innerFld
380:                                                            .getName());
381:                                            kf
382:                                                    .setFieldNameInTargetComponent(innerFld
383:                                                            .getName());
384:                                        }
385:
386:                                        // If this is a key, display it.
387:                                        if (rof.isDisplayAsKey()) {
388:                                            OrderByField obf = objFactory
389:                                                    .createOrderByField();
390:                                            orderFlds.add(obf);
391:                                            obf.setDomainFieldName(innerFld
392:                                                    .getName());
393:                                            obf.setSortAscending("true");
394:                                        }
395:                                    }
396:                                }
397:                            }
398:                        }
399:                    }
400:
401:                } catch (JAXBException e) {
402:                    log.error("Failed to create Viewer Object");
403:                }
404:            }
405:
406:            /** Saves the generated meta data to the prespecified location as an XML file
407:             * NOTE: assumes that the build(..) method has been called!
408:             */
409:            public boolean save() {
410:                String filename = m_app.getOutputRoot()
411:                        + m_app.getOutputViewers() + m_domain.getDomainObject()
412:                        + "Viewer.xml";
413:                File file = new File(filename);
414:                File path = new File(file.getParent());
415:                if (!path.exists())
416:                    path.mkdirs();
417:
418:                // Create output stream
419:                FileOutputStream out = null;
420:                try {
421:                    try {
422:                        out = new FileOutputStream(file.getPath());
423:                    } catch (FileNotFoundException e) {
424:                        log.error("Failed to open output stream !", e);
425:                        return false;
426:                    }
427:
428:                    try {
429:                        // create a JAXBContext capable of handling classes generated into the package
430:                        JAXBContext jc = JAXBContext
431:                                .newInstance("org.jaffa.patterns.library.object_viewer_meta_1_0.domain");
432:                        // create a Validator
433:                        Validator v = jc.createValidator();
434:                        ValidationEventCollector valErrors = new ValidationEventCollector();
435:                        v.setEventHandler(valErrors);
436:                        // validate the content tree
437:                        if (!v.validateRoot(m_viewer)) {
438:                            log.error("Failed to validate Structure !");
439:                            JAXBHelper.showErrors(log, valErrors);
440:                            return false;
441:                        }
442:
443:                        // Write out XML document to file
444:                        Marshaller m = jc.createMarshaller();
445:
446:                        //m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
447:                        //m.marshal(m_viewer, out);
448:                        JAXBHelper
449:                                .marshalWithDocType(
450:                                        m,
451:                                        m_viewer,
452:                                        out,
453:                                        "Root",
454:                                        "-//JAFFA//DTD Object Viewer Meta 1.0//EN",
455:                                        "http://jaffa.sourceforge.net/DTD/object-viewer-meta_1_0.dtd");
456:
457:                    } catch (ValidationException e) {
458:                        log.error("Failed to validate Structure !", e);
459:                        return false;
460:                    } catch (JAXBException e) {
461:                        log
462:                                .error(
463:                                        "Failed to marshal xml to output stream !",
464:                                        e);
465:                        return false;
466:                    }
467:                } finally {
468:                    if (out != null)
469:                        try {
470:                            out.close();
471:                        } catch (IOException e) {
472:                        }
473:                }
474:                return true;
475:            }
476:
477:            private static List reservedAttr = null;
478:            static {
479:                reservedAttr = new ArrayList();
480:                reservedAttr.add("component");
481:            }
482:
483:            private String reservedName(String name) {
484:                if (reservedAttr.contains(name.toLowerCase()))
485:                    return name + "1";
486:                else
487:                    return name;
488:            }
489:
490:            private void initUpEntities() {
491:                m_upDomain = new ArrayList();
492:                m_upRel = new ArrayList();
493:
494:                for (Iterator it = m_doList.iterator(); it.hasNext();) {
495:                    org.jaffa.patterns.library.domain_creator_1_1.domain.Root domain = (org.jaffa.patterns.library.domain_creator_1_1.domain.Root) it
496:                            .next();
497:                    if (domain.getRelationships() != null) {
498:                        List rels = domain.getRelationships().getRelationship();
499:                        if (rels != null && !rels.isEmpty())
500:                            for (Iterator it2 = rels.iterator(); it2.hasNext();) {
501:                                org.jaffa.patterns.library.domain_creator_1_1.domain.Relationship rel = (org.jaffa.patterns.library.domain_creator_1_1.domain.Relationship) it2
502:                                        .next();
503:                                if (m_domain.getDomainObject().equals(
504:                                        rel.getToDomainObject())
505:                                        && m_domain.getDomainPackage().equals(
506:                                                rel.getToDomainPackage())) {
507:                                    // This domain object relates to this one
508:                                    m_upDomain.add(domain);
509:                                    m_upRel.add(rel);
510:                                    break;
511:                                }
512:                            }
513:                    }
514:                }
515:
516:                // Show the results in debug mode
517:                /*
518:                if(log.isDebugEnabled()) {
519:                    log.debug("Finding Up Entities For " + m_domain.getDomainObject());
520:                    for(int i = 0; i < m_upDomain.size(); i++ ) {
521:                        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);
522:                        log.debug("...Found - " + domain.getDomainObject() );
523:                    }
524:                }
525:                 */
526:            }
527:
528:            private int getUpDomain(String fieldname) {
529:                for (int i = 0; i < m_upDomain.size(); i++) {
530:                    org.jaffa.patterns.library.domain_creator_1_1.domain.Root domain = (org.jaffa.patterns.library.domain_creator_1_1.domain.Root) m_upDomain
531:                            .get(i);
532:                    org.jaffa.patterns.library.domain_creator_1_1.domain.Relationship rel = (org.jaffa.patterns.library.domain_creator_1_1.domain.Relationship) m_upRel
533:                            .get(i);
534:                    List toFields = rel.getToFields().getRelationshipField();
535:                    if (toFields.size() == 1) {
536:                        org.jaffa.patterns.library.domain_creator_1_1.domain.RelationshipField toFld = (org.jaffa.patterns.library.domain_creator_1_1.domain.RelationshipField) toFields
537:                                .get(0);
538:                        if (toFld.getName().equals(fieldname)) {
539:                            log.debug("...Found - " + domain.getDomainObject());
540:                            return i;
541:                        }
542:                    }
543:                }
544:                return -1;
545:            }
546:
547:            public String getApplication() {
548:                return m_viewer.getApplication();
549:            }
550:
551:            public String getComponentControllerClass() {
552:                return m_viewer.getComponent() + "Component";
553:            }
554:
555:            public String getComponentControllerPackage() {
556:                return m_viewer.getBasePackage() + ".components."
557:                        + m_viewer.getComponent().toLowerCase() + ".ui";
558:            }
559:
560:            public String getComponentName() {
561:                return getModule() + "."
562:                        + StringHelper.getUpper1(m_viewer.getComponent());
563:            }
564:
565:            public String getComponentType() {
566:                return "Viewer";
567:            }
568:
569:            public String getDomain() {
570:                return m_viewer.getDomainPackage() + "."
571:                        + m_viewer.getDomainObject();
572:            }
573:
574:            public String getModule() {
575:                return StringHelper.getUpper1(m_viewer.getModule());
576:            }
577:
578:            public String getName() {
579:                return StringHelper.getUpper1(m_viewer.getComponent());
580:            }
581:
582:            /** Causes the meta data object to be build ready for saving.
583:             * @param fullPackage If true then the .applications. and .modules. package names
584:             * are used. If this is false, these are ommited for a much more condensed package
585:             * naming convention
586:             */
587:            public void buildPhase2(boolean fullPackage) throws Exception {
588:                ObjectFactory objFactory = new ObjectFactory();
589:
590:                //--------------------------------
591:                // Loop through the results fields,
592:                List results = m_viewer.getResultsFields().getResultsField();
593:                for (Iterator it = results.iterator(); it.hasNext();) {
594:                    ResultsField rfld = (ResultsField) it.next();
595:
596:                    //--------------------------------
597:                    // If this is a foriegn key, link it to the parent viewer
598:                    // ..todo..
599:                    int upDomainIdx = getUpDomain(rfld.getName());
600:                    if (upDomainIdx != -1) {
601:                        org.jaffa.patterns.library.domain_creator_1_1.domain.Root upDomain = (org.jaffa.patterns.library.domain_creator_1_1.domain.Root) m_upDomain
602:                                .get(upDomainIdx);
603:                        org.jaffa.patterns.library.domain_creator_1_1.domain.Relationship upRel = (org.jaffa.patterns.library.domain_creator_1_1.domain.Relationship) m_upRel
604:                                .get(upDomainIdx);
605:                        log.debug("Linking 'Up' Viewer "
606:                                + upDomain.getDomainObject() + " to "
607:                                + m_domain.getDomainObject());
608:                        // Find viewer
609:                        IBuilder vcomp = m_compReg.findComponent(upDomain
610:                                .getDomainPackage()
611:                                + "." + upDomain.getDomainObject(), "Viewer");
612:                        if (vcomp != null) {
613:                            // Link this to a viewer now....
614:                            Viewer viewer = objFactory.createViewer();
615:                            rfld.setViewer(viewer);
616:                            viewer.setClassName(vcomp
617:                                    .getComponentControllerClass());
618:                            viewer.setComponentName(vcomp.getComponentName());
619:                            viewer.setPackage(vcomp
620:                                    .getComponentControllerPackage());
621:                            viewer
622:                                    .setFieldNameInTargetComponent(reservedName(((org.jaffa.patterns.library.domain_creator_1_1.domain.RelationshipField) upRel
623:                                            .getFromFields()
624:                                            .getRelationshipField().get(0))
625:                                            .getName()));
626:                        } else
627:                            log.info("No related viewer found in "
628:                                    + getComponentName() + " for "
629:                                    + upDomain.getDomainObject());
630:                    }
631:                }
632:
633:                //-----------------------------
634:                // Loop through all related objects an link in there viewers
635:                if (m_viewer.getRelatedObjects() != null) {
636:                    List related = m_viewer.getRelatedObjects()
637:                            .getRelatedObject();
638:                    for (Iterator it = related.iterator(); it.hasNext();) {
639:                        RelatedObject robj = (RelatedObject) it.next();
640:
641:                        log.debug("Linking 'Down' Viewer "
642:                                + robj.getObjectName() + " to "
643:                                + m_domain.getDomainObject());
644:
645:                        // Find related viewer
646:                        IBuilder vcomp = m_compReg.findComponent(robj
647:                                .getPackage()
648:                                + "." + robj.getObjectName(), "Viewer");
649:                        if (vcomp != null) {
650:                            RelatedObjectViewer rviewer = objFactory
651:                                    .createRelatedObjectViewer();
652:                            robj.setRelatedObjectViewer(rviewer);
653:                            rviewer.setClassName(vcomp
654:                                    .getComponentControllerClass());
655:                            rviewer.setComponentName(vcomp.getComponentName());
656:                            rviewer.setPackage(vcomp
657:                                    .getComponentControllerPackage());
658:                        } else
659:                            log.info("No related viewer in component "
660:                                    + getComponentName() + " for domain "
661:                                    + robj.getObjectName());
662:                    }
663:                }
664:            }
665:
666:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.