1 15 package org.apache.hivemind.xml.definition.impl; 16 17 import java.io.InputStream ; 18 import java.util.List ; 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 33 public final class HiveMindSchemaParser implements ConfigurationParser 34 { 35 public final static String INPUT_FORMAT_NAME = "hivemind-schema"; 36 37 private Schema _schema; 38 39 public HiveMindSchemaParser(Schema schema) 40 { 41 _schema = schema; 42 } 43 44 48 public Object parse(ContributionContext context, Object data) 49 { 50 SchemaProcessorImpl processor = new SchemaProcessorImpl(context.getConfigurationPoint() 51 .getErrorLog(), _schema); 52 Object contributionObject = constructContributionObject(_schema, context.getDefiningModule()); 53 processor.process(contributionObject, (List ) data, context.getDefiningModule()); 54 return contributionObject; 55 } 56 57 public Object 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 parse(ContributionContext context, InputStream data) 69 { 70 throw new UnsupportedOperationException ("Parsing of an InputStream is not currently supported"); 71 } 72 73 public Schema getSchema() 74 { 75 return _schema; 76 } 77 } | Popular Tags |