KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.InputStream JavaDoc;
18 import java.util.List JavaDoc;
19
20 import org.apache.hivemind.Element;
21 import org.apache.hivemind.definition.ConfigurationParser;
22 import org.apache.hivemind.definition.ContributionContext;
23 import org.apache.hivemind.impl.SchemaProcessorImpl;
24 import org.apache.hivemind.internal.Module;
25 import org.apache.hivemind.schema.Schema;
26 import org.apache.hivemind.util.Defense;
27 import org.apache.hivemind.util.InstanceCreationUtils;
28
29 /**
30  * Implementation of {@link ConfigurationParser} that parses data whose format
31  * is described by a HiveMind {@link Schema} definition in a HiveMind xml module.
32  */

33 public final class HiveMindSchemaParser implements ConfigurationParser
34 {
35     public final static String JavaDoc INPUT_FORMAT_NAME = "hivemind-schema";
36     
37     private Schema _schema;
38
39     public HiveMindSchemaParser(Schema schema)
40     {
41         _schema = schema;
42     }
43
44     /**
45      * @param a list of {@link Element}s
46      * @see org.apache.hivemind.definition.ConfigurationParser#parse(org.apache.hivemind.definition.ContributionContext, java.lang.Object)
47      */

48     public Object JavaDoc parse(ContributionContext context, Object JavaDoc data)
49     {
50         SchemaProcessorImpl processor = new SchemaProcessorImpl(context.getConfigurationPoint()
51                 .getErrorLog(), _schema);
52         Object JavaDoc contributionObject = constructContributionObject(_schema, context.getDefiningModule());
53         processor.process(contributionObject, (List JavaDoc) data, context.getDefiningModule());
54         return contributionObject;
55     }
56
57     public Object JavaDoc constructContributionObject(Schema contributionsSchema, Module definingModule)
58     {
59         Defense.notNull(contributionsSchema.getRootElementClassName(), "schema.rootElementClassName");
60
61         return InstanceCreationUtils.createInstance(
62                 definingModule,
63                 contributionsSchema.getRootElementClassName(),
64                 contributionsSchema.getLocation());
65     }
66
67     
68     public Object JavaDoc parse(ContributionContext context, InputStream JavaDoc data)
69     {
70         throw new UnsupportedOperationException JavaDoc("Parsing of an InputStream is not currently supported");
71     }
72     
73     public Schema getSchema()
74     {
75         return _schema;
76     }
77 }
Popular Tags