View Javadoc

1   package org.devaki.nextobjects.util;
2   /*
3    *  nextobjects Copyright (C) 2001-2005 Emmanuel Florent
4    *  This program is free software; you can redistribute it and/or modify
5    *  it under the terms of the GNU General Public License as published by the
6    *  Free Software Foundation; either version 2 of the License, or (at your
7    *  option) any later version.
8    *  This program is distributed in the hope that it will
9    *  be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
10   *  of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11   *  PURPOSE. See the GNU General Public License for more details.
12   *  You should have received a copy of the GNU General Public License along
13   *  with this program; if not, write to the Free Software Foundation, Inc., 59
14   *  Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15   */
16  import java.awt.Color;
17  import java.awt.Dimension;
18  import java.awt.Point;
19  import java.io.File;
20  import java.io.IOException;
21  import java.util.List;
22  import java.util.Vector;
23  import javax.swing.JOptionPane;
24  import javax.xml.parsers.DocumentBuilder;
25  import javax.xml.parsers.DocumentBuilderFactory;
26  import javax.xml.parsers.FactoryConfigurationError;
27  import javax.xml.parsers.ParserConfigurationException;
28  import org.apache.commons.logging.Log;
29  import org.apache.commons.logging.LogFactory;
30  import org.apache.maven.project.Build;
31  import org.apache.maven.project.Contributor;
32  import org.apache.maven.project.Dependency;
33  import org.apache.maven.project.Developer;
34  import org.apache.maven.project.License;
35  import org.apache.maven.project.MailingList;
36  import org.apache.maven.project.Resource;
37  import org.apache.maven.project.UnitTest;
38  import org.devaki.nextobjects.NextObjects;
39  import org.devaki.nextobjects.constants.CstGraphics;
40  import org.devaki.nextobjects.workspace.models.BaseModel;
41  import org.devaki.nextobjects.workspace.models.ConceptualModel;
42  import org.devaki.nextobjects.workspace.models.PhysicalModel;
43  import org.devaki.nextobjects.workspace.models.Property;
44  import org.devaki.nextobjects.workspace.models.columns.Column;
45  import org.devaki.nextobjects.workspace.models.columns.ColumnType;
46  import org.devaki.nextobjects.workspace.models.graphics.ClassView;
47  import org.devaki.nextobjects.workspace.models.graphics.LineView;
48  import org.devaki.nextobjects.workspace.models.graphics.ModelTitleView;
49  import org.devaki.nextobjects.workspace.models.objects.Association;
50  import org.devaki.nextobjects.workspace.models.objects.AssociationLink;
51  import org.devaki.nextobjects.workspace.models.objects.BaseClass;
52  import org.devaki.nextobjects.workspace.models.objects.Constraint;
53  import org.devaki.nextobjects.workspace.models.objects.Entity;
54  import org.devaki.nextobjects.workspace.models.objects.InheritanceLink;
55  import org.devaki.nextobjects.workspace.models.objects.Label;
56  import org.devaki.nextobjects.workspace.models.objects.Table;
57  import org.devaki.nextobjects.workspace.models.styles.ClassStyle;
58  import org.devaki.nextobjects.workspace.models.styles.LineStyle;
59  import org.w3c.dom.Document;
60  import org.w3c.dom.Element;
61  import org.w3c.dom.Node;
62  import org.w3c.dom.NodeList;
63  import org.xml.sax.ErrorHandler;
64  import org.xml.sax.SAXException;
65  /***
66   *  this class is responsible for devaki-nextobjects XML input this is for load
67   *  .cdm, .pdm, project.xml, ${project-schema}.xml
68   *
69   * @author     <a href="mailto:eflorent@devaki.org">Emmanuel Florent</a>
70   * @created    December 27, 2003
71   * @see        http://maven.apache.org/reference/project-descriptor.html
72   * @todo       externalize ctrl points Size&location
73   * @todo       split in separates classes (+NOCDMOutputter +NOPDMOutputter)
74   * @todo       load/save FK with multiples references
75   * @todo       load/save property, unitTests, versions
76   * @todo       declare labels in DTDs properties,unitTest
77   */
78  public final class NOXMLFactory
79  {
80      /***  the Conceptual Model doctype */
81      public static final int DOCTYPE_CDM = 1;
82      /***  the Physical Model doctype */
83      public static final int DOCTYPE_PDM = 2;
84      /***  The Torque doctype */
85      public static final int DOCTYPE_TORQUE = 3;
86      /***  Project.xml doctype */
87      public static final int DOCTYPE_MAVEN = 4;
88      /***  Unknow doctype */
89      public static final int DOCTYPE_UNKNOW = 0;
90      /***  the logger */
91      private static Log logger = LogFactory.getLog(NOXMLFactory.class);
92      /***  Construct do nothing */
93      private NOXMLFactory()
94      {
95      }
96      /***
97       *  Convert a XML stream into an ConceptualModel
98       *
99       * @param  doc      the document
100      * @param  pMerise  the conceptual model
101      */
102     public static void loadCdm(
103         final Document doc,
104         final ConceptualModel pMerise)
105     {
106         // Edit merise object.
107         Element root = doc.getDocumentElement();
108         loadBaseModel(root, pMerise);
109         // work on entities
110         NodeList mls = root.getElementsByTagName("entity");
111         for (int i = 0; i < mls.getLength(); i++)
112         {
113             Element child = (Element) mls.item(i);
114             Entity entity = new Entity(pMerise);
115             loadBaseClass(child, entity);
116             loadClassStyle(child, entity);
117             ModelMan.addEntity(pMerise, entity);
118         }
119         // work on association
120         NodeList associations = root.getElementsByTagName("association");
121         for (int i = 0; i < associations.getLength(); i++)
122         {
123             Element child3 = (Element) associations.item(i);
124             Association association = new Association(pMerise);
125             loadBaseClass(child3, association);
126             loadClassStyle(child3, association);
127             // work on association's links
128             NodeList associationLinks =
129                 child3.getElementsByTagName("associationLink");
130             for (int j = 0; j < associationLinks.getLength(); j++)
131             {
132                 Element eltLinks = (Element) associationLinks.item(j);
133                 Association pAssociation = association;
134                 Entity pEntity =
135                     pMerise.getEntity(eltLinks.getAttribute("linkedEntity"));
136                 int pCard =
137                     new Integer(eltLinks.getAttribute("cardinality"))
138                         .intValue();
139                 AssociationLink associationLink =
140                     new AssociationLink(pAssociation, pEntity, pCard);
141                 if (eltLinks.getAttribute("localCtrlPoint").length() > 0
142                     && eltLinks.getAttribute("foreignCtrlPoint").length() > 0)
143                 {
144                     (
145                         (LineView) associationLink
146                             .getObjectView())
147                             .setLocalPosition(
148                         Integer.parseInt(
149                             eltLinks.getAttribute("localCtrlPoint")));
150                     (
151                         (LineView) associationLink
152                             .getObjectView())
153                             .setForeignPosition(
154                         Integer.parseInt(
155                             eltLinks.getAttribute("foreignCtrlPoint")));
156                 }
157                 else
158                 {
159                     ((LineView) associationLink.getObjectView())
160                         .computeBestPoints();
161                 }
162                 // load the style of the association link
163                 String pLineColor = eltLinks.getAttribute("lineColor");
164                 Color cLineColor = NOGraphicsUtil.hexString2Color(pLineColor);
165                 LineStyle lineStyle =
166                     new LineStyle(associationLink.getObjectView(), cLineColor);
167                 ((LineView) associationLink.getObjectView()).setStyle(
168                     lineStyle);
169                 pMerise.getAssociationLinks().addElement(associationLink);
170             }
171             ModelMan.addAssociation(pMerise, association);
172         }
173         // work on inheritance links
174         NodeList inheritanceLinks =
175             root.getElementsByTagName("inheritanceLink");
176         for (int i = 0; i < inheritanceLinks.getLength(); i++)
177         {
178             Element child7 = (Element) inheritanceLinks.item(i);
179             String sChildClass = child7.getAttribute("childClass");
180             String sParentClass = child7.getAttribute("parentClass");
181             InheritanceLink inheritanceLink =
182                 new InheritanceLink(pMerise, sChildClass, sParentClass);
183             //Ctrl point position
184             if (child7.getAttribute("localCtrlPoint").length() > 0
185                 && child7.getAttribute("foreignCtrlPoint").length() > 0)
186             {
187                 ((LineView) inheritanceLink.getObjectView()).setLocalPosition(
188                     Integer.parseInt(child7.getAttribute("localCtrlPoint")));
189                 (
190                     (LineView) inheritanceLink
191                         .getObjectView())
192                         .setForeignPosition(
193                     Integer.parseInt(child7.getAttribute("foreignCtrlPoint")));
194             }
195             else
196             {
197                 ((LineView) inheritanceLink.getObjectView())
198                     .computeBestPoints();
199             }
200             String pLineColor = child7.getAttribute("lineColor");
201             Color cLineColor = NOGraphicsUtil.hexString2Color(pLineColor);
202             LineStyle lineStyle =
203                 new LineStyle(inheritanceLink.getObjectView(), cLineColor);
204             ((LineView) inheritanceLink.getObjectView()).setStyle(lineStyle);
205             ModelMan.addInheritanceLink(pMerise, inheritanceLink);
206         }
207     }
208     /***
209      *  Load a PDM from an XML stream
210      *
211      * @param  doc   the document
212      * @param  pPDM  the physical model
213      */
214     public static void loadPdm(final Document doc, final PhysicalModel pPDM)
215     {
216         Element root = doc.getDocumentElement();
217         loadBaseModel(root, pPDM);
218         // work on tables
219         NodeList entities = root.getElementsByTagName("table");
220         for (int i = 0; i < entities.getLength(); i++)
221         {
222             Element child = (Element) entities.item(i);
223             Table table = new Table(pPDM);
224             loadBaseClass(child, table);
225             loadClassStyle(child, table);
226             ModelMan.addTable(pPDM, table);
227         }
228         // work on foreign-keys (as all table 've been created
229         NodeList tables = root.getElementsByTagName("table");
230         for (int i = 0; i < tables.getLength(); i++)
231         {
232             Element eltTable = (Element) tables.item(i);
233             NodeList foreignkeys = eltTable.getElementsByTagName("foreign-key");
234             for (int j = 0; j < foreignkeys.getLength(); j++)
235             {
236                 Element eltCst = (Element) foreignkeys.item(j);
237                 Table tmpTable =
238                     pPDM.getTableForId(
239                         loadElementData(eltTable.getElementsByTagName("code"))
240                             .toString());
241                 //use name rather than code if as project-schema.xml
242                 if (tmpTable == null)
243                 {
244                     tmpTable =
245                         pPDM.getTableForId(eltTable.getAttribute("name"));
246                 }
247                 //if still null skip and inform else load...
248                 if (tmpTable != null)
249                 {
250                     ModelMan.addConstraint(
251                         pPDM,
252                         loadForeignKey(eltCst, tmpTable));
253                 }
254                 else
255                 {
256                     logger.error("Wrong FK : " + eltCst);
257                     logger.error("skipping");
258                 }
259             }
260         }
261         // work on inheritance links
262         NodeList inheritanceLinks =
263             root.getElementsByTagName("inheritanceLink");
264         for (int i = 0; i < inheritanceLinks.getLength(); i++)
265         {
266             Element eltInhr = (Element) inheritanceLinks.item(i);
267             String sChildClass = eltInhr.getAttribute("childClass");
268             String sParentClass = eltInhr.getAttribute("parentClass");
269             InheritanceLink inheritanceLink =
270                 new InheritanceLink(pPDM, sChildClass, sParentClass);
271             //Ctrl point position
272             if (eltInhr.getAttribute("localCtrlPoint").length() > 0
273                 && eltInhr.getAttribute("foreignCtrlPoint").length() > 0)
274             {
275                 ((LineView) inheritanceLink.getObjectView()).setLocalPosition(
276                     Integer.parseInt(eltInhr.getAttribute("localCtrlPoint")));
277                 (
278                     (LineView) inheritanceLink
279                         .getObjectView())
280                         .setForeignPosition(
281                     Integer.parseInt(eltInhr.getAttribute("foreignCtrlPoint")));
282             }
283             else
284             {
285                 ((LineView) inheritanceLink.getObjectView())
286                     .computeBestPoints();
287             }
288             String pLineColor = eltInhr.getAttribute("lineColor");
289             Color cLineColor = NOGraphicsUtil.hexString2Color(pLineColor);
290             LineStyle lineStyle =
291                 new LineStyle(inheritanceLink.getObjectView(), cLineColor);
292             ((LineView) inheritanceLink.getObjectView()).setStyle(lineStyle);
293             ModelMan.addInheritanceLink(pPDM, inheritanceLink);
294         }
295     }
296     /***
297      *  Load a model from a file
298      *
299      * @param  file            the file
300      * @return                 the document
301      * @throws  IOException
302      * @throws  JDOMException
303      */
304     public static Document loadModel(final File file)
305     {
306         Document document = null;
307         try
308         {
309             DocumentBuilderFactory factory =
310                 DocumentBuilderFactory.newInstance();
311             factory.setAttribute(
312                 "http://xml.org/sax/features/validation",
313                 new Boolean(false));
314             factory.setAttribute(
315                 "http://apache.org/xml/features/nonvalidating/load-external-dtd",
316                 new Boolean(true));
317             DocumentBuilder builder = factory.newDocumentBuilder();
318             builder.setEntityResolver(new NODTDResolver());
319             NOErrorHandler erh = new NOErrorHandler();
320             builder.setErrorHandler((ErrorHandler) erh);
321             document = builder.parse(file);
322         }
323         catch (FactoryConfigurationError e)
324         {
325             logger.error(" unable to get a document builder factory");
326         }
327         catch (ParserConfigurationException e)
328         {
329             logger.error(e.getMessage());
330             logger.error(" parser was unable to be configured");
331         }
332         catch (SAXException e)
333         {
334             logger.error(e.getMessage());
335         }
336         catch (IOException e)
337         {
338             logger.error(e.getMessage());
339         }
340         return document;
341     }
342     /***
343      *  Description of the Method
344      *
345      * @param  doc  Description of the Parameter
346      * @return      Description of the Return Value
347      */
348     public static int parseDocType(final Document doc)
349     {
350         /*
351          *  instead of using the real doc type we use the root element
352          *  in a way it works with project.xml which doesn't contains
353          *  doctype declaration - it is the same as the doc type fix the
354          *  document element
355          */
356         int docType = DOCTYPE_UNKNOW;
357         Element elt = doc.getDocumentElement();
358         if (elt.getTagName().equals("cdm"))
359         {
360             docType = DOCTYPE_CDM;
361         }
362         else
363             if (elt.getTagName().equals("pdm"))
364             {
365                 docType = DOCTYPE_PDM;
366             }
367             else
368                 if (elt.getTagName().equals("database"))
369                 {
370                     docType = DOCTYPE_TORQUE;
371                 }
372                 else
373                     if (elt.getTagName().equals("project"))
374                     {
375                         docType = DOCTYPE_MAVEN;
376                     }
377         return docType;
378     }
379     /***
380      *  Load a label
381      *
382      * @param  pChild  the tree node
383      * @param  lbl     the label
384      */
385     private static void loadLabel(final Element pChild, final Label lbl)
386     {
387         lbl.setName(pChild.getAttribute("name"));
388         if (pChild.getAttribute("x").length() > 0
389             && pChild.getAttribute("y").length() > 0
390             && pChild.getAttribute("width").length() > 0
391             && pChild.getAttribute("height").length() > 0)
392         {
393             try
394             {
395                 lbl.getObjectView().setLocation(
396                     new Point(
397                         new Integer(pChild.getAttribute("x")).intValue(),
398                         new Integer(pChild.getAttribute("y")).intValue()));
399                 lbl.getObjectView().setSize(
400                     new Dimension(
401                         new Integer(pChild.getAttribute("width")).intValue(),
402                         new Integer(pChild.getAttribute("height")).intValue()));
403             }
404             catch (Exception e)
405             {
406                 logger.error("unexpected error " + e.getMessage());
407                 e.printStackTrace();
408             }
409         }
410         else
411         {
412             lbl.getObjectView().setLocation(new Point(5300, 2600));
413         }
414         lbl.setNotes(
415             loadElementData(pChild.getElementsByTagName("notes")).toString());
416     }
417     /***
418      *  Load a label
419      *
420      * @param  pChild           the tree node
421      * @param  pModelTitleView  the model-title object
422      */
423     private static void loadModelTitleView(
424         final Element pChild,
425         final ModelTitleView pModelTitleView)
426     {
427         if (pChild.getAttribute("x").length() > 0)
428         {
429             try
430             {
431                 pModelTitleView.setLocation(
432                     new Point(
433                         new Integer(pChild.getAttribute("x")).intValue(),
434                         new Integer(pChild.getAttribute("y")).intValue()));
435                 pModelTitleView.setSize(
436                     new Dimension(
437                         new Integer(pChild.getAttribute("width")).intValue(),
438                         new Integer(pChild.getAttribute("height")).intValue()));
439                 ((ClassView) pModelTitleView).getOldrectangle().setLocation(
440                     pModelTitleView.getLocation());
441             }
442             catch (Exception e)
443             {
444                 logger.error("unexpected error " + e.getMessage());
445                 e.printStackTrace();
446             }
447         }
448         else
449         {
450             pModelTitleView.setLocation(new Point(5300, 2600));
451         }
452     }
453     /***
454      *  Convert a JDom Elment into a FK
455      *
456      * @param  pEltForeignKey  the tree node
457      * @param  pTable          the table
458      * @return                 the constraint
459      */
460     protected static Constraint loadForeignKey(
461         final Element pEltForeignKey,
462         final Table pTable)
463     {
464         //local keys
465         List vlk = new Vector();
466         //foreign keys
467         List vfk = new Vector();
468         Column foreignColumn = null;
469         Column localColumn = null;
470         Table foreignTable = null;
471         Element reference =
472             (Element) pEltForeignKey.getElementsByTagName("reference").item(0);
473         foreignTable =
474             ((PhysicalModel) pTable.getMyModel()).getTableForId(
475                 pEltForeignKey.getAttribute("foreignTable"));
476         if (foreignTable != null && reference != null)
477         {
478             foreignColumn =
479                 foreignTable.getColumnForId(reference.getAttribute("foreign"));
480             vfk.add(foreignColumn);
481         }
482         if (pTable != null && reference != null)
483         {
484             localColumn =
485                 pTable.getColumnForId(reference.getAttribute("local"));
486             vlk.add(localColumn);
487         }
488         if (foreignTable != null
489             && pTable != null
490             && foreignColumn != null
491             && localColumn != null)
492         {
493             Constraint tmpConstraint =
494                 new Constraint(
495                     (PhysicalModel) pTable.getMyModel(),
496                     pTable,
497                     vlk,
498                     foreignTable,
499                     vfk);
500             tmpConstraint.setOnUpdate(pEltForeignKey.getAttribute("onUpdate"));
501             tmpConstraint.setOnDelete(pEltForeignKey.getAttribute("onDelete"));
502             //load constraint graphics anchors
503             if (pEltForeignKey.getAttribute("localCtrlPoint").length() > 0
504                 && pEltForeignKey.getAttribute("foreignCtrlPoint").length() > 0)
505             {
506                 ((LineView) tmpConstraint.getObjectView()).setLocalPosition(
507                     Integer.parseInt(
508                         pEltForeignKey.getAttribute("localCtrlPoint")));
509                 ((LineView) tmpConstraint.getObjectView()).setForeignPosition(
510                     Integer.parseInt(
511                         pEltForeignKey.getAttribute("foreignCtrlPoint")));
512             }
513             else
514             {
515                 ((LineView) tmpConstraint.getObjectView()).computeBestPoints();
516             }
517             if (pEltForeignKey.getElementsByTagName("style").item(0) != null)
518             {
519                 Element style =
520                     (Element) pEltForeignKey.getElementsByTagName(
521                         "style").item(
522                         0);
523                 Color cLineColor =
524                     NOGraphicsUtil.hexString2Color(
525                         style.getAttribute("lineColor"));
526                 LineStyle lineStyle =
527                     new LineStyle(tmpConstraint.getObjectView(), cLineColor);
528                 ((LineView) tmpConstraint.getObjectView()).setStyle(lineStyle);
529             }
530             return tmpConstraint;
531         }
532         else
533         {
534             logger.error(
535                 "Bad constraint "
536                     + pTable
537                     + "::"
538                     + localColumn
539                     + " reference "
540                     + foreignTable
541                     + "::"
542                     + foreignColumn);
543             logger.info("skipping ...");
544             return null;
545         }
546     }
547     /***
548      *  Convert a JDom Elment into an BaseModel
549      *
550      * @param  root        the tree element to parse
551      * @param  pBaseModel  the model to be loaded.
552      */
553     protected static void loadBaseModel(
554         final Element root,
555         final BaseModel pBaseModel)
556     {
557         pBaseModel.setName(root.getAttribute("name"));
558         pBaseModel.setId(root.getAttribute("id"));
559         // work on object-model properties
560         if (root.getAttribute("defaultIdMethod").length() > 0)
561         {
562             pBaseModel.setDefaultIdMethod(root.getAttribute("defaultIdMethod"));
563         }
564         else
565         {
566             pBaseModel.setDefaultIdMethod("none");
567         }
568         if (root.getAttribute("defaultJavaType").length() > 0)
569         {
570             pBaseModel.setDefaultJavaType(root.getAttribute("defaultJavaType"));
571         }
572         else
573         {
574             pBaseModel.setDefaultJavaType("primitive");
575         }
576         if (root.getAttribute("package").length() > 0)
577         {
578             pBaseModel.setPackageName(root.getAttribute("package"));
579         }
580         if (root.getAttribute("baseClass").length() > 0)
581         {
582             pBaseModel.setBaseClass(root.getAttribute("baseClass"));
583         }
584         if (root.getAttribute("basePeer").length() > 0)
585         {
586             pBaseModel.setBasePeer(root.getAttribute("basePeer"));
587         }
588         if (root.getAttribute("defaultJavaNamingMethod").length() > 0)
589         {
590             pBaseModel.setDefaultJavaNamingMethod(
591                 root.getAttribute("defaultJavaNamingMethod"));
592         }
593         else
594         {
595             pBaseModel.setDefaultJavaNamingMethod("underscore");
596         }
597         if (root.getAttribute("heavyIndexing") != null)
598         {
599             pBaseModel.setHeavyIndexing(
600                 new Boolean(root.getAttribute("heavyIndexing")).booleanValue());
601         }
602         else
603         {
604             pBaseModel.setHeavyIndexing(false);
605         }
606         pBaseModel.setCompany(
607             loadElementData(root.getElementsByTagName("company").item(0))
608                 .toString());
609         pBaseModel.setProjectURL(
610             loadElementData(root.getElementsByTagName("projectURL").item(0))
611                 .toString());
612         pBaseModel.setDescription(
613             loadElementData(root.getElementsByTagName("description").item(0))
614                 .toString());
615         pBaseModel.setNotes(
616             loadElementData(root.getElementsByTagName("notes").item(0))
617                 .toString());
618         // work on database properties
619         if (root.getElementsByTagName("databaseProperties").getLength() == 1)
620         {
621             Element eltDbProp =
622                 (Element) root.getElementsByTagName("databaseProperties").item(
623                     0);
624             if (eltDbProp.getElementsByTagName("dbType").item(0) != null)
625             {
626                 pBaseModel.setDbType(
627                     new Integer(
628                         eltDbProp
629                             .getElementsByTagName("dbType")
630                             .item(0)
631                             .getFirstChild()
632                             .getNodeValue())
633                         .intValue());
634             }
635             pBaseModel.setCreateDatabaseUrl(
636                 loadElementData(
637                     eltDbProp.getElementsByTagName("createDatabaseUrl"))
638                     .toString());
639             pBaseModel.setBuildDatabaseUrl(
640                 loadElementData(
641                     eltDbProp.getElementsByTagName("buildDatabaseUrl"))
642                     .toString());
643             pBaseModel.setSchema(
644                 loadElementData(eltDbProp.getElementsByTagName("schema"))
645                     .toString());
646             pBaseModel.setDatabaseHost(
647                 loadElementData(eltDbProp.getElementsByTagName("databaseHost"))
648                     .toString());
649             pBaseModel.setDatabaseUser(
650                 loadElementData(eltDbProp.getElementsByTagName("databaseUser"))
651                     .toString());
652             pBaseModel.setDatabasePassword(
653                 loadElementData(
654                     eltDbProp.getElementsByTagName("databasePassword"))
655                     .toString());
656         }
657         if (root.getElementsByTagName("project").item(0) != null)
658         {
659             loadProjectDotXml(
660                 (Element) root.getElementsByTagName("project").item(0),
661                 pBaseModel);
662         }
663         // work on labels
664         NodeList labels = root.getElementsByTagName("label");
665         for (int i = 0; i < labels.getLength(); i++)
666         {
667             Element child10 = (Element) labels.item(i);
668             Label lbl = new Label(pBaseModel);
669             loadLabel(child10, lbl);
670             ModelMan.addLabel(pBaseModel, lbl);
671         }
672         //work on model title
673         Element modelTitleElement =
674             (Element) root.getElementsByTagName("modelTitleView").item(0);
675         if (modelTitleElement != null)
676         {
677             loadModelTitleView(
678                 modelTitleElement,
679                 pBaseModel.getModelView().getModelTitleView());
680         }
681     }
682     /***
683      *  load a project.xml tree for a given model
684      *
685      * @param  file        the file
686      * @param  pBaseModel  the model
687      */
688     protected static void loadProjectDotXml(
689         final File file,
690         final BaseModel pBaseModel)
691     {
692         Document doc = null;
693         Element prjElement = null;
694         try
695         {
696             doc = loadModel(file);
697             prjElement = doc.getDocumentElement();
698         }
699         catch (Exception e)
700         {
701             logger.error(e);
702         }
703         loadProjectDotXml(prjElement, pBaseModel);
704         JOptionPane.showMessageDialog(
705             NextObjects.getReference(),
706             "File " + file.toString() + "  loaded.",
707             "Loaded project definition.",
708             JOptionPane.WARNING_MESSAGE);
709     }
710     /***
711      *  load a project.xml tree for a given model
712      *
713      * @param  pProject    the given project tree node
714      * @param  pBaseModel  the model
715      */
716     private static void loadProjectDotXml(
717         final Element pProject,
718         final BaseModel pBaseModel)
719     {
720         pBaseModel.setParentProject(
721             loadElementData(pProject.getElementsByTagName("extend").item(0))
722                 .toString());
723         pBaseModel.setName(
724             loadElementData(pProject.getElementsByTagName("name").item(0))
725                 .toString());
726         pBaseModel.setId(
727             loadElementData(pProject.getElementsByTagName("id").item(0))
728                 .toString());
729         pBaseModel.setGroupId(
730             loadElementData(pProject.getElementsByTagName("groupId").item(0))
731                 .toString());
732         pBaseModel.setCurrentVersion(
733             loadElementData(
734                 pProject.getElementsByTagName("currentVersion").item(0))
735                 .toString());
736         if (pProject.getElementsByTagName("organization").item(0) != null)
737         {
738             pBaseModel.setOrganizationName(
739                 loadElementData(
740                     ((Element) pProject
741                         .getElementsByTagName("organization")
742                         .item(0))
743                         .getElementsByTagName("name")
744                         .item(0))
745                     .toString());
746             pBaseModel.setOrganizationUrl(
747                 loadElementData(
748                     ((Element) pProject
749                         .getElementsByTagName("organization")
750                         .item(0))
751                         .getElementsByTagName("url")
752                         .item(0))
753                     .toString());
754             pBaseModel.setOrganizationLogo(
755                 loadElementData(
756                     ((Element) pProject
757                         .getElementsByTagName("organization")
758                         .item(0))
759                         .getElementsByTagName("logo")
760                         .item(0))
761                     .toString());
762         }
763         pBaseModel.setInceptionYear(
764             loadElementData(
765                 pProject.getElementsByTagName("inceptionYear").item(0))
766                 .toString());
767         pBaseModel.setPackageName(
768             loadElementData(pProject.getElementsByTagName("package").item(0))
769                 .toString());
770         pBaseModel.setLogo(
771             loadElementData(pProject.getElementsByTagName("logo").item(0))
772                 .toString());
773         pBaseModel.setAlternateProjectId(
774             loadElementData(
775                 pProject.getElementsByTagName("gumpRepositoryId").item(0))
776                 .toString());
777         pBaseModel.setDescription(
778             loadElementData(
779                 pProject.getElementsByTagName("description").item(0))
780                 .toString());
781         pBaseModel.setShortDescription(
782             loadElementData(
783                 pProject.getElementsByTagName("shortDescription").item(0))
784                 .toString());
785         pBaseModel.setProjectURL(
786             loadElementData(pProject.getElementsByTagName("url").item(0))
787                 .toString());
788         pBaseModel.setIssueTrackingUrl(
789             loadElementData(
790                 pProject.getElementsByTagName("issueTrackingUrl").item(0))
791                 .toString());
792         pBaseModel.setSiteAddress(
793             loadElementData(
794                 pProject.getElementsByTagName("siteAddress").item(0))
795                 .toString());
796         pBaseModel.setSiteDirectory(
797             loadElementData(
798                 pProject.getElementsByTagName("siteDirectory").item(0))
799                 .toString());
800         pBaseModel.setDistributionDirectory(
801             loadElementData(
802                 pProject.getElementsByTagName("distributionDirectory").item(0))
803                 .toString());
804         if (pProject.getElementsByTagName("repository").item(0) != null)
805         {
806             pBaseModel.setRepositoryConnection(
807                 loadElementData(
808                     ((Element) pProject
809                         .getElementsByTagName("repository")
810                         .item(0))
811                         .getElementsByTagName("connection")
812                         .item(0))
813                     .toString());
814             pBaseModel.setRepositoryUrl(
815                 loadElementData(
816                     ((Element) pProject
817                         .getElementsByTagName("repository")
818                         .item(0))
819                         .getElementsByTagName("url")
820                         .item(0))
821                     .toString());
822         }
823         if (pProject.getElementsByTagName("mailingLists").item(0) != null)
824         {
825             NodeList mls =
826                 (
827                     (Element) pProject.getElementsByTagName(
828                         "mailingLists").item(
829                         0)).getElementsByTagName(
830                     "mailingList");
831             for (int i = 0; i < mls.getLength(); i++)
832             {
833                 pBaseModel.getMailingLists().addElement(
834                     loadMailingList((Element) mls.item(i)));
835             }
836         }
837         if (pProject.getElementsByTagName("developers").item(0) != null)
838         {
839             NodeList mls =
840                 (
841                     (Element) pProject.getElementsByTagName("developers").item(
842                         0)).getElementsByTagName(
843                     "developer");
844             for (int i = 0; i < mls.getLength(); i++)
845             {
846                 pBaseModel.getDevelopers().addElement(
847                     loadDeveloper((Element) mls.item(i)));
848             }
849         }
850         if (pProject.getElementsByTagName("contributors").item(0) != null)
851         {
852             NodeList mls =
853                 (
854                     (Element) pProject.getElementsByTagName(
855                         "contributors").item(
856                         0)).getElementsByTagName(
857                     "contributor");
858             for (int i = 0; i < mls.getLength(); i++)
859             {
860                 pBaseModel.getContributors().addElement(
861                     loadContributor((Element) mls.item(i)));
862             }
863         }
864         if (pProject.getElementsByTagName("licenses").item(0) != null)
865         {
866             NodeList mls =
867                 (
868                     (Element) pProject.getElementsByTagName("licenses").item(
869                         0)).getElementsByTagName(
870                     "license");
871             for (int i = 0; i < mls.getLength(); i++)
872             {
873                 pBaseModel.getLicenses().addElement(
874                     loadLicense((Element) mls.item(i)));
875             }
876         }
877         if (pProject.getElementsByTagName("dependencies").item(0) != null)
878         {
879             NodeList mls =
880                 (
881                     (Element) pProject.getElementsByTagName(
882                         "dependencies").item(
883                         0)).getElementsByTagName(
884                     "dependency");
885             for (int i = 0; i < mls.getLength(); i++)
886             {
887                 pBaseModel.getDependencies().addElement(
888                     loadDependency((Element) mls.item(i)));
889             }
890         }
891         if (pProject.getElementsByTagName("build").item(0) != null)
892         {
893             pBaseModel.setBuild(
894                 loadBuild(
895                     (Element) pProject.getElementsByTagName("build").item(0)));
896         }
897         NodeList mls = pProject.getElementsByTagName("property");
898         for (int i = 0; i < mls.getLength(); i++)
899         {
900             Element elt = (Element) mls.item(i);
901             pBaseModel.getProperties().addElement(
902                 new Property(
903                     elt.getAttribute("name"),
904                     elt.getAttribute("value")));
905         }
906     }
907     /***
908      *  Convert a JDom Elment into an Entity
909      *
910      * @param  child       the tree node to parse
911      * @param  pBaseClass  the entity to load.
912      * @return             the baseClass object
913      */
914     protected static BaseClass loadBaseClass(
915         final Element child,
916         final BaseClass pBaseClass)
917     {
918         pBaseClass.setName(child.getAttribute("name"));
919         if (child.getAttribute("javaName").length() > 0)
920         {
921             pBaseClass.setJavaName(child.getAttribute("javaName"));
922         }
923         if (child.getElementsByTagName("code").item(0) != null)
924         {
925             pBaseClass.setCode(
926                 loadElementData(child.getElementsByTagName("code").item(0))
927                     .toString());
928         }
929         else
930         {
931             pBaseClass.setCode(pBaseClass.getName());
932         }
933         if (child.getAttribute("idMethod").length() > 0)
934         {
935             pBaseClass.setIdMethod(child.getAttribute("idMethod"));
936         }
937         else
938         {
939             pBaseClass.setIdMethod("none");
940         }
941         if (child.getAttribute("skipSql").length() > 0)
942         {
943             pBaseClass.setSkipSql(
944                 new Boolean(child.getAttribute("skipSql")).booleanValue());
945         }
946         else
947         {
948             pBaseClass.setSkipSql(false);
949         }
950         if (child.getAttribute("abstract").length() > 0)
951         {
952             pBaseClass.setAbstractClass(
953                 new Boolean(child.getAttribute("abstract")).booleanValue());
954         }
955         else
956         {
957             pBaseClass.setAbstractClass(false);
958         }
959         pBaseClass.setAlias(child.getAttribute("alias"));
960         pBaseClass.setBasePeer(child.getAttribute("basePeer"));
961         pBaseClass.setBaseClass(child.getAttribute("baseClass"));
962         pBaseClass.setJavaNamingMethod(child.getAttribute("javaNamingMethod"));
963         pBaseClass.setDescription(child.getAttribute("description"));
964         pBaseClass.setNotes(
965             loadElementData(child.getElementsByTagName("notes").item(0))
966                 .toString());
967         // work on entities column
968         NodeList columns = child.getElementsByTagName("column");
969         for (int i = 0; i < columns.getLength(); i++)
970         {
971             Element child2 = (Element) columns.item(i);
972             pBaseClass.getData().addElement(loadColumn(child2, pBaseClass));
973         }
974         NodeList uniques = child.getElementsByTagName("unique");
975         for (int i = 0; i < uniques.getLength(); i++)
976         {
977             Element eltUnique = (Element) uniques.item(i);
978             loadUniques(eltUnique, pBaseClass);
979         }
980         // work on indexes
981         NodeList indexes = child.getElementsByTagName("index");
982         for (int i = 0; i < indexes.getLength(); i++)
983         {
984             Element eltIndex = (Element) indexes.item(i);
985             loadIndexes(eltIndex, pBaseClass);
986         }
987         //work on entities
988         if (child.getAttribute("x").length() > 0
989             && child.getAttribute("y").length() > 0
990             && child.getAttribute("width").length() > 0
991             && child.getAttribute("height").length() > 0)
992         {
993             pBaseClass.getObjectView().setLocation(
994                 new Point(
995                     new Integer(child.getAttribute("x")).intValue(),
996                     new Integer(child.getAttribute("y")).intValue()));
997             Dimension tempDim =
998                 new Dimension(
999                     new Integer(child.getAttribute("width")).intValue(),
1000                     new Integer(child.getAttribute("height")).intValue());
1001             pBaseClass.getObjectView().setSize(tempDim);
1002             ((ClassView) pBaseClass.getObjectView()).setOldSize(tempDim);
1003         }
1004         else
1005         {
1006             pBaseClass.getObjectView().setLocation(new Point(5300, 2600));
1007         }
1008         return pBaseClass;
1009     }
1010     /***
1011      *  Loads the style of a class
1012      *
1013      * @param  child       the tree node to parse
1014      * @param  pBaseClass  the class to load.
1015      */
1016     protected static void loadClassStyle(
1017         final Element child,
1018         final BaseClass pBaseClass)
1019     {
1020         //Don't know why there is a loop here are there should exist only one
1021         //see cvs history ?!
1022         NodeList styles = child.getElementsByTagName("style");
1023         Color cBorderColor = CstGraphics.DEFAULT_ENTITY_BACKGROUND_COLOR;
1024         Color cBackgroundColor = CstGraphics.DEFAULT_ENTITY_BORDER_COLOR;
1025         for (int i = 0; i < styles.getLength(); i++)
1026         {
1027             Element pChild = (Element) styles.item(i);
1028             boolean pTextAdjusted = false;
1029             if (pChild.getAttribute("adjusted").length() > 0)
1030             {
1031                 pTextAdjusted =
1032                     new Boolean(pChild.getAttribute("adjusted")).booleanValue();
1033             }
1034             if (pChild.getAttribute("backgroundColor").length() > 0)
1035             {
1036                 String pBackgroundColor =
1037                     pChild.getAttribute("backgroundColor");
1038                 cBackgroundColor =
1039                     NOGraphicsUtil.hexString2Color(pBackgroundColor);
1040             }
1041             if (pChild.getAttribute("borderColor").length() > 0)
1042             {
1043                 String pBorderColor = pChild.getAttribute("borderColor");
1044                 cBorderColor = NOGraphicsUtil.hexString2Color(pBorderColor);
1045             }
1046             ClassStyle classStyle =
1047                 new ClassStyle(
1048                     pBaseClass.getObjectView(),
1049                     cBackgroundColor,
1050                     cBorderColor,
1051                     pTextAdjusted);
1052             ((ClassView) pBaseClass.getObjectView()).setStyle(classStyle);
1053         }
1054     }
1055     /***
1056      *  Load the unique data
1057      *
1058      * @param  child       the unique element
1059      * @param  pBaseClass  related table
1060      */
1061     private static void loadUniques(
1062         final Element child,
1063         final BaseClass pBaseClass)
1064     {
1065         NodeList mls = child.getElementsByTagName("unique-column");
1066         for (int i = 0; i < mls.getLength(); i++)
1067         {
1068             String colname = ((Element) mls.item(i)).getAttribute("name");
1069             pBaseClass.getColumnForId(colname).setUnique(true);
1070         }
1071     }
1072     /***
1073      *  Load indexes information
1074      *
1075      * @param  child       the element
1076      * @param  pBaseClass  the table
1077      */
1078     private static void loadIndexes(
1079         final Element child,
1080         final BaseClass pBaseClass)
1081     {
1082         NodeList mls = child.getElementsByTagName("index-column");
1083         for (int i = 0; i < mls.getLength(); i++)
1084         {
1085             String colname = ((Element) mls.item(i)).getAttribute("name");
1086             pBaseClass.getColumnForId(colname).setIndex(true);
1087         }
1088     }
1089     /***
1090      *  Convert a JDom Elment into a FK
1091      *
1092      * @param  pChild      the tree node to parse
1093      * @param  pBaseClass  the entity to load.
1094      * @return             the column
1095      */
1096     protected static Column loadColumn(
1097         final Element pChild,
1098         final BaseClass pBaseClass)
1099     {
1100         String pName = pChild.getAttribute("name");
1101         String pCode = pName;
1102         // set the code only if not empty string
1103         if (pChild.getAttribute("code").length() > 0)
1104         {
1105             pCode = pChild.getAttribute("code");
1106         }
1107         String pJavaName = pChild.getAttribute("javaName");
1108         boolean pPrimaryKey = false;
1109         if (pChild.getAttribute("primaryKey").length() > 0)
1110         {
1111             pPrimaryKey =
1112                 new Boolean(pChild.getAttribute("primaryKey")).booleanValue();
1113         }
1114         boolean pRequired = false;
1115         if (pChild.getAttribute("required").length() > 0)
1116         {
1117             pRequired =
1118                 new Boolean(pChild.getAttribute("required")).booleanValue();
1119         }
1120         ColumnType pColumnType = new ColumnType("VARCHAR", null, "");
1121         if (pChild.getAttribute("type") != null)
1122         {
1123             pColumnType = new ColumnType(pChild.getAttribute("type"), null, "");
1124         }
1125         String pJavaType = pChild.getAttribute("javaType");
1126         String pSize = pChild.getAttribute("size");
1127         String pDefaultValue = pChild.getAttribute("default");
1128         boolean pAutoIncrement = false;
1129         if (pChild.getAttribute("autoIncrement").length() > 0)
1130         {
1131             pAutoIncrement =
1132                 new Boolean(pChild.getAttribute("autoIncrement"))
1133                     .booleanValue();
1134         }
1135         String pInheritance = "false";
1136         if (pChild.getAttribute("inheritance").length() > 0)
1137         {
1138             pInheritance = pChild.getAttribute("inheritance");
1139         }
1140         String pInputValidator = pChild.getAttribute("inputValidator");
1141         String pJavaNamingMethod = pChild.getAttribute("javaNamingMethod");
1142         String pDescription = pChild.getAttribute("description");
1143         Column col =
1144             new Column(
1145                 pName,
1146                 pCode,
1147                 pColumnType,
1148                 pSize,
1149                 pDefaultValue,
1150                 pPrimaryKey,
1151                 pRequired,
1152                 pAutoIncrement,
1153                 false,            // unique
1154     false,            // index
1155     pJavaName,
1156         pJavaType,
1157         pInheritance,
1158         pInputValidator,
1159         pJavaNamingMethod,
1160         pDescription,
1161         pBaseClass);
1162         return col;
1163     }
1164     /***
1165      *  Load a mailing list from XML
1166      *
1167      * @param  pElement  the mailing-list element
1168      * @return           the mailing-list
1169      */
1170     private static MailingList loadMailingList(final Element pElement)
1171     {
1172         MailingList mailingList = new MailingList();
1173         mailingList.setName(
1174             loadElementData(pElement.getElementsByTagName("name").item(0))
1175                 .toString());
1176         mailingList.setSubscribe(
1177             loadElementData(pElement.getElementsByTagName("subscribe").item(0))
1178                 .toString());
1179         mailingList.setUnsubscribe(
1180             loadElementData(
1181                 pElement.getElementsByTagName("unsubscribe").item(0))
1182                 .toString());
1183         mailingList.setArchive(
1184             loadElementData(pElement.getElementsByTagName("archive").item(0))
1185                 .toString());
1186         return mailingList;
1187     }
1188     /***
1189      *  Load a mailing list from XML
1190      *
1191      * @param  pElement  a license element
1192      * @return           a single license object
1193      */
1194     private static License loadLicense(final Element pElement)
1195     {
1196         License license = new License();
1197         license.setName(
1198             loadElementData(pElement.getElementsByTagName("name").item(0))
1199                 .toString());
1200         license.setUrl(
1201             loadElementData(pElement.getElementsByTagName("url").item(0))
1202                 .toString());
1203         license.setDistribution(
1204             loadElementData(
1205                 pElement.getElementsByTagName("distribution").item(0))
1206                 .toString());
1207         return license;
1208     }
1209     /***
1210      *  Load a developer from XML
1211      *
1212      * @param  pElement  the developer element
1213      * @return           a single developer object
1214      */
1215     private static Developer loadDeveloper(final Element pElement)
1216     {
1217         Developer developer = new Developer();
1218         developer.setName(
1219             loadElementData(pElement.getElementsByTagName("name").item(0))
1220                 .toString());
1221         developer.setId(
1222             loadElementData(pElement.getElementsByTagName("id").item(0))
1223                 .toString());
1224         developer.setEmail(
1225             loadElementData(pElement.getElementsByTagName("email").item(0))
1226                 .toString());
1227         developer.setOrganization(
1228             loadElementData(
1229                 pElement.getElementsByTagName("organization").item(0))
1230                 .toString());
1231         developer.setUrl(
1232             loadElementData(pElement.getElementsByTagName("url").item(0))
1233                 .toString());
1234         //Finally contributors roles, ...
1235         Element eltRoles =
1236             (Element) pElement.getElementsByTagName("roles").item(0);
1237         if (eltRoles != null)
1238         {
1239             NodeList mls = eltRoles.getElementsByTagName("role");
1240             for (int i = 0; i < mls.getLength(); i++)
1241             {
1242                 developer.addRole(loadElementData(mls.item(i)).toString());
1243             }
1244         }
1245         return developer;
1246     }
1247     /***
1248      *  Load a contributor from XML
1249      *
1250      * @param  pElement  the contributor element
1251      * @return           a single contributor object
1252      */
1253     private static Contributor loadContributor(final Element pElement)
1254     {
1255         Contributor contributor = new Contributor();
1256         contributor.setName(
1257             loadElementData(pElement.getElementsByTagName("name").item(0))
1258                 .toString());
1259         contributor.setEmail(
1260             loadElementData(pElement.getElementsByTagName("email").item(0))
1261                 .toString());
1262         contributor.setOrganization(
1263             loadElementData(
1264                 pElement.getElementsByTagName("organization").item(0))
1265                 .toString());
1266         //Contributors Roles
1267         Element eltRoles =
1268             (Element) pElement.getElementsByTagName("roles").item(0);
1269         if (eltRoles != null)
1270         {
1271             NodeList mls = eltRoles.getElementsByTagName("role");
1272             for (int i = 0; i < mls.getLength(); i++)
1273             {
1274                 contributor.addRole(loadElementData(mls.item(i)).toString());
1275             }
1276         }
1277         return contributor;
1278     }
1279     /***
1280      *  Load a dependency from XML
1281      *
1282      * @param  pElement  the dependency dom element
1283      * @return           the dependency
1284      */
1285     private static Dependency loadDependency(final Element pElement)
1286     {
1287         Dependency dep = new Dependency();
1288         dep.setId(
1289             loadElementData(pElement.getElementsByTagName("id").item(0))
1290                 .toString());
1291         dep.setVersion(
1292             loadElementData(pElement.getElementsByTagName("version").item(0))
1293                 .toString());
1294         dep.setJar(
1295             loadElementData(pElement.getElementsByTagName("jar").item(0))
1296                 .toString());
1297         dep.setUrl(
1298             loadElementData(pElement.getElementsByTagName("url").item(0))
1299                 .toString());
1300         return dep;
1301     }
1302     /***
1303      *  Load a resource from XML
1304      *
1305      * @param  pElement  the resource element
1306      * @return           the ressource
1307      */
1308     private static Resource loadResource(final Element pElement)
1309     {
1310         Resource resource = new Resource();
1311         resource.setDirectory(
1312             loadElementData(pElement.getElementsByTagName("directory").item(0))
1313                 .toString());
1314         resource.setTargetPath(
1315             loadElementData(
1316                 pElement.getElementsByTagName("targetPath").item(0))
1317                 .toString());
1318         if (pElement.getElementsByTagName("includes").item(0) != null)
1319         {
1320             List lst =
1321                 loadIncludes(
1322                     (Element) pElement.getElementsByTagName("includes").item(
1323                         0));
1324             for (int i = 0; i < lst.size(); i++)
1325             {
1326                 resource.addInclude(lst.get(i).toString());
1327             }
1328         }
1329         if (pElement.getElementsByTagName("excludes").item(0) != null)
1330         {
1331             List lst =
1332                 loadExcludes(
1333                     (Element) pElement.getElementsByTagName("excludes").item(
1334                         0));
1335             for (int i = 0; i < lst.size(); i++)
1336             {
1337                 resource.addExclude(lst.get(i).toString());
1338             }
1339         }
1340         return resource;
1341     }
1342     /***
1343      *  Load a unit test from XML
1344      *
1345      * @param  pElement  the unit-test element
1346      * @return           the unit test
1347      */
1348     private static UnitTest loadUnitTest(final Element pElement)
1349     {
1350         UnitTest unitTest = new UnitTest();
1351         if (pElement.getElementsByTagName("resources").item(0) != null)
1352         {
1353             NodeList mls =
1354                 (
1355                     (Element) pElement.getElementsByTagName("resources").item(
1356                         0)).getElementsByTagName(
1357                     "resource");
1358             for (int i = 0; i < mls.getLength(); i++)
1359             {
1360                 unitTest.addResource(loadResource((Element) mls.item(i)));
1361             }
1362         }
1363         return unitTest;
1364     }
1365     /***
1366      *  Load a build from XML
1367      *
1368      * @param  pElement  the dom element
1369      * @return           the build
1370      */
1371     private static Build loadBuild(final Element pElement)
1372     {
1373         Build build = new Build();
1374         build.setNagEmailAddress(
1375             loadElementData(
1376                 pElement.getElementsByTagName("nagEmailAddress").item(0))
1377                 .toString());
1378         build.setUnitTestSourceDirectory(
1379             loadElementData(
1380                 pElement.getElementsByTagName("unitTestSourceDirectory").item(
1381                     0))
1382                 .toString());
1383         build.setSourceDirectory(
1384             loadElementData(
1385                 pElement.getElementsByTagName("sourceDirectory").item(0))
1386                 .toString());
1387         build.setAspectSourceDirectory(
1388             loadElementData(
1389                 pElement.getElementsByTagName("aspectSourceDirectory").item(0))
1390                 .toString());
1391         if (pElement.getElementsByTagName("resources").item(0) != null)
1392         {
1393             NodeList mls =
1394                 (
1395                     (Element) pElement.getElementsByTagName("resources").item(
1396                         0)).getElementsByTagName(
1397                     "resource");
1398             for (int i = 0; i < mls.getLength(); i++)
1399             {
1400                 build.addResource(loadResource((Element) mls.item(i)));
1401             }
1402         }
1403         if (pElement.getElementsByTagName("unitTest").item(0) != null)
1404         {
1405             build.setUnitTest(
1406                 loadUnitTest(
1407                     (Element) pElement.getElementsByTagName("unitTest").item(
1408                         0)));
1409         }
1410         return build;
1411     }
1412     /***
1413      *  Load the includes element
1414      *
1415      * @param  pElement  the includes element
1416      * @return           the includes
1417      */
1418     private static List loadIncludes(final Element pElement)
1419     {
1420         List includes = new Vector(1);
1421         String str = "";
1422         NodeList lst = pElement.getElementsByTagName("include");
1423         for (int i = 0; i < lst.getLength(); i++)
1424         {
1425             includes.add(loadElementData((Element) lst.item(i)));
1426         }
1427         return includes;
1428     }
1429     /***
1430      *  Load the excludes element
1431      *
1432      * @param  pElement  the exclude element
1433      * @return           excludes
1434      */
1435     private static List loadExcludes(final Element pElement)
1436     {
1437         List excludes = new Vector(1);
1438         String str = "";
1439         NodeList lst = pElement.getElementsByTagName("exclude");
1440         for (int i = 0; i < lst.getLength(); i++)
1441         {
1442             excludes.add(loadElementData((Element) lst.item(i)));
1443         }
1444         return excludes;
1445     }
1446     /***
1447      *  Return the text content of an XML tag Anyway return an empty string
1448      *
1449      * @param  pElement  the DOM node
1450      * @return           str the content
1451      */
1452     private static StringBuffer loadElementData(final Node pElement)
1453     {
1454         StringBuffer str = new StringBuffer().append("");
1455         if (pElement != null)
1456         {
1457             if (pElement.getFirstChild() != null)
1458             {
1459                 str.append(pElement.getFirstChild().getNodeValue());
1460             }
1461         }
1462         return str;
1463     }
1464     /***
1465      *  Return the text content of an XML tag Anyway return an empty string
1466      *
1467      * @param  pElement  a node list
1468      * @return           str the content
1469      */
1470     private static StringBuffer loadElementData(final NodeList pElement)
1471     {
1472         if (pElement.item(0) != null)
1473         {
1474             return loadElementData(pElement.item(0));
1475         }
1476         else
1477         {
1478             return new StringBuffer().append("");
1479         }
1480     }
1481 }