KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > xml > definition > impl > XmlContributionImpl


1 // Copyright 2004, 2005 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.xml.definition.impl;
16
17 import java.util.ArrayList JavaDoc;
18 import java.util.Collections JavaDoc;
19 import java.util.List JavaDoc;
20
21 import org.apache.hivemind.Element;
22 import org.apache.hivemind.definition.ConfigurationParser;
23 import org.apache.hivemind.definition.ConfigurationParserDefinition;
24 import org.apache.hivemind.definition.ConfigurationPointDefinition;
25 import org.apache.hivemind.definition.Contribution;
26 import org.apache.hivemind.definition.ContributionContext;
27
28 /**
29  * Implements the {@link org.apache.hivemind.definition.Contribution} interface.
30  * Contributes data that is defined as xml in a HiveMind xml module.
31  * The data is passed in as instances of {@link Element}.
32  *
33  * @author Howard Lewis Ship
34  */

35 public final class XmlContributionImpl implements Contribution
36 {
37     private String JavaDoc _contributingModuleId;
38
39     private List JavaDoc _elements;
40
41     public XmlContributionImpl(String JavaDoc moduleId, List JavaDoc elements)
42     {
43         _contributingModuleId = moduleId;
44         _elements = elements;
45     }
46
47     public String JavaDoc getContributingModuleId()
48     {
49         return _contributingModuleId;
50     }
51
52     public void addElements(List JavaDoc elements)
53     {
54         if (_elements == null)
55             _elements = new ArrayList JavaDoc(elements);
56         else
57             _elements.addAll(elements);
58     }
59
60     public List JavaDoc getElements()
61     {
62         if (_elements == null)
63             return Collections.EMPTY_LIST;
64
65         return _elements;
66     }
67
68     /**
69      * @see org.apache.hivemind.definition.Contribution#contribute(org.apache.hivemind.definition.ContributionContext)
70      */

71     public void contribute(ContributionContext context)
72     {
73         // Retrieve parser for HiveMind schema
74
ConfigurationPointDefinition cpd = context.getConfigurationPoint()
75                 .getConfigurationPointDefinition();
76         ConfigurationParserDefinition parserDef = cpd.getParser(HiveMindSchemaParser.INPUT_FORMAT_NAME);
77         if (parserDef == null)
78         {
79             // This is a valid situation. The unparsed elements are contributed
80
context.mergeContribution(getElements());
81         } else {
82             // Construct and execute the parser
83
ConfigurationParser parser = parserDef.getParserConstructor().constructParser(context);
84             Object JavaDoc contribution = parser.parse(context, getElements());
85             context.mergeContribution(contribution);
86         }
87     }
88
89 }
Popular Tags