KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > finalist > jag > skelet > SkeletDataObj


1 /* Copyright (C) 2003 Finalist IT Group
2  *
3  * This file is part of JAG - the Java J2EE Application Generator
4  *
5  * JAG is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  * JAG is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  * You should have received a copy of the GNU General Public License
14  * along with JAG; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  */

17
18 package com.finalist.jag.skelet;
19
20
21 import java.util.*;
22
23
24 /**
25  * Class SkeletDataObj
26  *
27  *
28  * @author Wendel D. de Witte
29  * @version %I%, %G%
30  */

31 public class SkeletDataObj extends ModuleData {
32
33    /** Field config */
34    private JagSkeletConfig config = null;
35
36
37    /**
38     * Constructor SkeletDataObj
39     *
40     *
41     * @param name
42     *
43     */

44    public SkeletDataObj(String JavaDoc name) {
45       super(name, new ArrayList());
46    }
47
48
49    /**
50     * Method getConfig
51     *
52     *
53     * @return
54     *
55     */

56    public JagSkeletConfig getConfig() {
57       return (this.config);
58    }
59
60
61    /**
62     * Method setConfig
63     *
64     *
65     * @param config
66     *
67     */

68    public void setConfig(JagSkeletConfig config) {
69       this.config = config;
70    }
71
72
73    /**
74     * Method processReferences
75     *
76     *
77     * @throws JagSkeletException
78     *
79     */

80    public void processReferences() throws JagSkeletException {
81
82       HashMap refNames = new HashMap();
83
84       createRefMap(this, refNames);
85       replaceReferences(this, refNames);
86    }
87
88
89    /**
90     * Method createRefMap
91     *
92     *
93     * @param root
94     * @param refNames
95     *
96     * @throws JagSkeletException
97     *
98     */

99    protected void createRefMap(ModuleData root, HashMap refNames)
100       throws JagSkeletException {
101
102       Collection modules = (Collection) getValue();
103       Iterator iterator = modules.iterator();
104
105       while (iterator.hasNext()) {
106          SkeletModule module = (SkeletModule) iterator.next();
107
108          if (!"".equals(module.getRefname()) && refNames.get(module.getRefname()) != null) {
109             throw new JagSkeletException(
110                "Found duplicate ref-name field : "
111                + module.getRefname());
112          }
113
114          refNames.put(module.getRefname(), module);
115       }
116    }
117
118
119    /**
120     * Method replaceReferences
121     *
122     *
123     * @param root
124     * @param refNames
125     *
126     */

127    protected void replaceReferences(ModuleData root, HashMap refNames) {
128
129       Collection modules = (Collection) getValue();
130       Iterator iterator = modules.iterator();
131
132       while (iterator.hasNext()) {
133          SkeletModule module = (SkeletModule) iterator.next();
134          Collection refs = module.getRefs();
135          Iterator iteratorRefs = refs.iterator();
136
137          while (iteratorRefs.hasNext()) {
138             SkeletModule refModule =
139                (SkeletModule) refNames.get((String JavaDoc) iteratorRefs.next());
140
141             ((Collection) module.getValue()).add(refModule);
142          }
143       }
144    }
145 }
Popular Tags