1 15 package org.apache.hivemind.definition.impl; 16 17 import java.util.ArrayList ; 18 import java.util.Collection ; 19 import java.util.Collections ; 20 import java.util.HashMap ; 21 import java.util.Map ; 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 39 public class ConfigurationPointDefinitionImpl extends ExtensionPointDefinitionImpl implements ConfigurationPointDefinition 40 { 41 private String _containerClassName; 42 43 private Occurances _expectedContributions; 44 45 private Collection _contributions = new ArrayList (); 46 47 private Map _parsers = new HashMap (); 48 49 public ConfigurationPointDefinitionImpl(ModuleDefinition module) 50 { 51 super(module); 52 } 53 54 public ConfigurationPointDefinitionImpl(ModuleDefinition module, String id, Location location, Visibility visibility, 55 String containerClassName, Occurances expectedContributions) 56 { 57 super(module, id, location, visibility); 58 _containerClassName = containerClassName; 59 _expectedContributions = expectedContributions; 60 } 61 62 65 public String getConfigurationTypeName() 66 { 67 return _containerClassName; 68 } 69 70 73 public void setConfigurationTypeName(String containerClassName) 74 { 75 _containerClassName = containerClassName; 76 } 77 78 81 public Occurances getExpectedContributions() 82 { 83 return _expectedContributions; 84 } 85 86 89 public void setExpectedContributions(Occurances expectedContributions) 90 { 91 _expectedContributions = expectedContributions; 92 } 93 94 97 public Collection getContributions() 98 { 99 return Collections.unmodifiableCollection(_contributions); 100 } 101 102 105 public void addContribution(ContributionDefinition contribution) 106 { 107 checkVisibility(contribution); 108 _contributions.add(contribution); 109 } 110 111 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 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 143 public Collection getParsers() 144 { 145 return Collections.unmodifiableCollection(_parsers.values()); 146 } 147 148 151 public ConfigurationParserDefinition getParser(String inputFormat) 152 { 153 return (ConfigurationParserDefinition) _parsers.get(inputFormat); 154 } 155 156 157 } 158 | Popular Tags |