KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > kilim > repository > ResourceMapping


1 /**
2  * Copyright (C) 2002 Kelua SA
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library 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 GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18 package org.objectweb.kilim.repository;
19 import java.util.HashMap JavaDoc;
20 import java.util.Iterator JavaDoc;
21 import java.util.LinkedList JavaDoc;
22
23 import org.objectweb.kilim.description.Instance;
24 import org.objectweb.kilim.description.KILIM;
25 import org.objectweb.kilim.description.TemplateDescription;
26
27 /**
28  * The {@link ResourceMapping} implementation used by the {@link org.objectweb.kilim.repository.TemplateDescriptionParser}.
29  * This class is just asimple container used to propagate informations related to template during the parsing process. It contains :
30  * 1) a list of already referenced but unparsed templates.
31  * 2)a table of known templates whose key is the template name,
32  * 3) a table of templates whose key is the instance
33  * 4) a table of unknown super template of instances.
34  * @author dutoo, horn
35  */

36 public class ResourceMapping {
37     private Repository repository;
38     private LinkedList JavaDoc unParsedTemplates;
39     private HashMap JavaDoc knownTemplates;
40     private LinkedList JavaDoc unknownSuperTemplateOfInstances;
41     
42     /**
43      * Constructor for ResourceMappingImpl.
44      * @param aRepository the repository to be used at template
45      * naming resolution time.
46      */

47     public ResourceMapping(Repository aRepository) {
48         repository = aRepository;
49     }
50     
51     /**
52      * Method addUnParsedTemplate. This method is invoked when the parser encounters a reference to a template not yet parsed.
53      * @param name : the name of the template
54      */

55     public void addUnparsedTemplate(String JavaDoc name) {
56         if (name == null) {
57             return;
58         }
59         
60         if (unParsedTemplates == null) {
61             unParsedTemplates = new LinkedList JavaDoc();
62         }
63         if (unParsedTemplates.contains(name)) {
64             return;
65         }
66         unParsedTemplates.add(name);
67     }
68     
69     /**
70      * Method removeUnparsedTemplate. This method is invoked when the parser starts the parsing of a new template.
71      * @param name :
72      */

73     public void removeUnparsedTemplate(String JavaDoc name) {
74         if (name == null) {
75             return;
76         }
77         if (unParsedTemplates == null) {
78             return;
79         }
80         unParsedTemplates.remove(name);
81     }
82         
83     /**
84      * Method addParsedTemplate.
85      * @param name :
86      * @param aTemplate :
87      */

88     public void addKnownTemplate(String JavaDoc name, TemplateDescription aTemplate) {
89         if (name == null || aTemplate == null) {
90             return;
91         }
92         if (knownTemplates == null) {
93             knownTemplates = new HashMap JavaDoc();
94         }
95         if (knownTemplates.containsKey(name)) {
96             return;
97         }
98         knownTemplates.put(name, aTemplate);
99     }
100     
101     /**
102      * Method removeParsedTemplates.
103      * @param name :
104      */

105     public void removeKnownTemplate(String JavaDoc name) {
106         if (name == null) {
107             return;
108         }
109         if (knownTemplates == null) {
110             return;
111         }
112         knownTemplates.remove(name);
113     }
114     
115     /**
116      * Method getParsedTemplate.
117      * @param name :
118      * @return Template
119      */

120     public TemplateDescription getKnownTemplate(String JavaDoc name) {
121         if (name == null || knownTemplates == null) {
122             return null;
123         }
124         return (TemplateDescription) knownTemplates.get(name);
125     }
126         
127     /**
128      * Method getNextUnparsedTemplate.
129      * @return String
130      */

131     public String JavaDoc getNextUnparsedTemplate() {
132         if (unParsedTemplates == null) {
133             return null;
134         }
135         if (unParsedTemplates.size() > 0) {
136             String JavaDoc result = (String JavaDoc) unParsedTemplates.getFirst();
137             unParsedTemplates.removeFirst();
138             return result;
139         }
140         return null;
141     }
142         
143     /**
144      * Method addUnknownSuperTemplateOfInstance.
145      * @param aInstance :
146      */

147     public void addUnknownSuperTemplateOfInstance(Instance aInstance) {
148         if (unknownSuperTemplateOfInstances == null) {
149             //unknownSuperTemplateOfInstances = new HashMap();
150
unknownSuperTemplateOfInstances = new LinkedList JavaDoc();
151         }
152         //unknownSuperTemplateOfInstances.put(aInstance, aTemplate);
153
unknownSuperTemplateOfInstances.addLast(aInstance);
154     }
155     
156     /**
157      * Method getUnknownSuperTemplateOfInstances.
158      * @return Iterator
159      */

160     public Iterator JavaDoc getUnknownSuperTemplateOfInstances() {
161         if (unknownSuperTemplateOfInstances == null) {
162             return KILIM.EMPTY_ITERATOR;
163         }
164
165         return unknownSuperTemplateOfInstances.iterator();
166     }
167 }
Popular Tags