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.Iterator ; 21 22 import org.apache.hivemind.ApplicationRuntimeException; 23 import org.apache.hivemind.Location; 24 import org.apache.hivemind.definition.DefinitionMessages; 25 import org.apache.hivemind.definition.ExtensionDefinition; 26 import org.apache.hivemind.definition.ImplementationDefinition; 27 import org.apache.hivemind.definition.InterceptorDefinition; 28 import org.apache.hivemind.definition.ModuleDefinition; 29 import org.apache.hivemind.definition.ServicePointDefinition; 30 import org.apache.hivemind.definition.Visibility; 31 32 37 public class ServicePointDefinitionImpl extends ExtensionPointDefinitionImpl implements ServicePointDefinition 38 { 39 private String _interfaceClassName; 40 41 private Collection _implementations = new ArrayList (); 42 43 private Collection _interceptors = new ArrayList (); 44 45 public ServicePointDefinitionImpl(ModuleDefinition module) 46 { 47 super(module); 48 } 49 50 public ServicePointDefinitionImpl(ModuleDefinition module, String id, Location location, Visibility visibility, String interfaceClassName) 51 { 52 super(module, id, location, visibility); 53 _interfaceClassName = interfaceClassName; 54 } 55 56 59 public String getInterfaceClassName() 60 { 61 return _interfaceClassName; 62 } 63 64 70 public void setInterfaceClassName(String interfaceClassName) 71 { 72 _interfaceClassName = interfaceClassName; 73 } 74 75 78 public Collection getImplementations() 79 { 80 return Collections.unmodifiableCollection(_implementations); 81 } 82 83 86 public ImplementationDefinition getDefaultImplementation() 87 { 88 ImplementationDefinition defaulImplementation = null; 89 for (Iterator iter = _implementations.iterator(); iter.hasNext();) 90 { 91 ImplementationDefinition impl = (ImplementationDefinition) iter.next(); 92 if (defaulImplementation == null) 93 defaulImplementation = impl; 94 if (impl.isDefault()) { 95 defaulImplementation = impl; 96 break; 97 } 98 } 99 100 return defaulImplementation; 101 } 102 103 107 private void checkVisibility(ExtensionDefinition extension) 108 { 109 if (Visibility.PRIVATE.equals(getVisibility()) 110 && !extension.getModuleId().equals(getModuleId())) 111 { 112 throw new ApplicationRuntimeException(DefinitionMessages.servicePointNotVisible( 113 this, 114 extension.getModule())); 115 } 116 } 117 118 121 public void addImplementation(ImplementationDefinition implementation) 122 { 123 checkVisibility(implementation); 124 _implementations.add(implementation); 125 } 126 127 130 public Collection getInterceptors() 131 { 132 return Collections.unmodifiableCollection(_interceptors); 133 } 134 135 138 public void addInterceptor(InterceptorDefinition interceptor) 139 { 140 checkVisibility(interceptor); 141 _interceptors.add(interceptor); 142 } 143 } 144 | Popular Tags |