KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > definition > impl > ConfigurationPointDefinitionImpl


1 // Copyright 2007 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.hivemind.definition.impl;
16
17 import java.util.ArrayList JavaDoc;
18 import java.util.Collection JavaDoc;
19 import java.util.Collections JavaDoc;
20 import java.util.HashMap JavaDoc;
21 import java.util.Map JavaDoc;
22
23 import org.apache.hivemind.ApplicationRuntimeException;
24 import org.apache.hivemind.Location;
25 import org.apache.hivemind.definition.ConfigurationParserDefinition;
26 import org.apache.hivemind.definition.ConfigurationPointDefinition;
27 import org.apache.hivemind.definition.ContributionDefinition;
28 import org.apache.hivemind.definition.DefinitionMessages;
29 import org.apache.hivemind.definition.ExtensionDefinition;
30 import org.apache.hivemind.definition.ModuleDefinition;
31 import org.apache.hivemind.definition.Occurances;
32 import org.apache.hivemind.definition.Visibility;
33
34 /**
35  * Default implementation of {@link ConfigurationPointDefinition}.
36  *
37  * @author Achim Huegen
38  */

39 public class ConfigurationPointDefinitionImpl extends ExtensionPointDefinitionImpl implements ConfigurationPointDefinition
40 {
41     private String JavaDoc _containerClassName;
42
43     private Occurances _expectedContributions;
44
45     private Collection JavaDoc _contributions = new ArrayList JavaDoc();
46     
47     private Map JavaDoc _parsers = new HashMap JavaDoc();
48
49     public ConfigurationPointDefinitionImpl(ModuleDefinition module)
50     {
51         super(module);
52     }
53
54     public ConfigurationPointDefinitionImpl(ModuleDefinition module, String JavaDoc id, Location location, Visibility visibility,
55             String JavaDoc containerClassName, Occurances expectedContributions)
56     {
57         super(module, id, location, visibility);
58         _containerClassName = containerClassName;
59         _expectedContributions = expectedContributions;
60     }
61
62     /**
63      * @see org.apache.hivemind.definition.ConfigurationPointDefinition#getConfigurationTypeName()
64      */

65     public String JavaDoc getConfigurationTypeName()
66     {
67         return _containerClassName;
68     }
69
70     /**
71      * Set the class name of the configuration.
72      */

73     public void setConfigurationTypeName(String JavaDoc containerClassName)
74     {
75         _containerClassName = containerClassName;
76     }
77
78     /**
79      * @see org.apache.hivemind.definition.ConfigurationPointDefinition#getExpectedContributions()
80      */

81     public Occurances getExpectedContributions()
82     {
83         return _expectedContributions;
84     }
85
86     /**
87      * Sets the expected number of contributions to the configuration.
88      */

89     public void setExpectedContributions(Occurances expectedContributions)
90     {
91         _expectedContributions = expectedContributions;
92     }
93
94     /**
95      * @see org.apache.hivemind.definition.ConfigurationPointDefinition#getContributions()
96      */

97     public Collection JavaDoc getContributions()
98     {
99         return Collections.unmodifiableCollection(_contributions);
100     }
101
102     /**
103      * @see org.apache.hivemind.definition.ConfigurationPointDefinition#addContribution(org.apache.hivemind.definition.ContributionDefinition)
104      */

105     public void addContribution(ContributionDefinition contribution)
106     {
107         checkVisibility(contribution);
108         _contributions.add(contribution);
109     }
110
111     /**
112      * Checks if Extension can see this configuration point.
113      * @throws ApplicationRuntimeException if not visible
114      */

115     private void checkVisibility(ExtensionDefinition extension)
116     {
117         if (Visibility.PRIVATE.equals(getVisibility())
118                 && !extension.getModuleId().equals(getModuleId()))
119         {
120             throw new ApplicationRuntimeException(DefinitionMessages.configurationPointNotVisible(
121                     this,
122                     extension.getModule()));
123         }
124     }
125     
126     /**
127      * @see org.apache.hivemind.definition.ConfigurationPointDefinition#addParser(org.apache.hivemind.definition.ConfigurationParserDefinition)
128      */

129     public void addParser(ConfigurationParserDefinition parser)
130     {
131         checkVisibility(parser);
132
133         if (_parsers.containsKey(parser.getInputFormat())) {
134             throw new ApplicationRuntimeException(DefinitionMessages.duplicateParserInputFormat(parser.getInputFormat(),
135                     this));
136         }
137         _parsers.put(parser.getInputFormat(), parser);
138     }
139
140     /**
141      * @see org.apache.hivemind.definition.ConfigurationPointDefinition#getParsers()
142      */

143     public Collection JavaDoc getParsers()
144     {
145         return Collections.unmodifiableCollection(_parsers.values());
146     }
147
148     /**
149      * @see org.apache.hivemind.definition.ConfigurationPointDefinition#getParser(java.lang.String)
150      */

151     public ConfigurationParserDefinition getParser(String JavaDoc inputFormat)
152     {
153         return (ConfigurationParserDefinition) _parsers.get(inputFormat);
154     }
155
156
157 }
158
Popular Tags