KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > definition > impl > ServicePointDefinitionImpl


1 // Copyright 2007 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.definition.impl;
16
17 import java.util.ArrayList JavaDoc;
18 import java.util.Collection JavaDoc;
19 import java.util.Collections JavaDoc;
20 import java.util.Iterator JavaDoc;
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 /**
33  * Default implementation of {@link ServicePointDefinition}.
34  *
35  * @author Achim Huegen
36  */

37 public class ServicePointDefinitionImpl extends ExtensionPointDefinitionImpl implements ServicePointDefinition
38 {
39     private String JavaDoc _interfaceClassName;
40     
41     private Collection JavaDoc _implementations = new ArrayList JavaDoc();
42
43     private Collection JavaDoc _interceptors = new ArrayList JavaDoc();
44
45     public ServicePointDefinitionImpl(ModuleDefinition module)
46     {
47         super(module);
48     }
49
50     public ServicePointDefinitionImpl(ModuleDefinition module, String JavaDoc id, Location location, Visibility visibility, String JavaDoc interfaceClassName)
51     {
52         super(module, id, location, visibility);
53         _interfaceClassName = interfaceClassName;
54     }
55
56     /**
57      * @see org.apache.hivemind.definition.ServicePointDefinition#getInterfaceClassName()
58      */

59     public String JavaDoc getInterfaceClassName()
60     {
61         return _interfaceClassName;
62     }
63
64     /**
65      * Sets the class name of the service interface.
66      *
67      * @param interfaceClassName the fully qualified class name of the service interface.
68      * This may be the name of a ordinary class or an interface.
69      */

70     public void setInterfaceClassName(String JavaDoc interfaceClassName)
71     {
72         _interfaceClassName = interfaceClassName;
73     }
74
75     /**
76      * @see org.apache.hivemind.definition.ServicePointDefinition#getImplementations()
77      */

78     public Collection JavaDoc getImplementations()
79     {
80         return Collections.unmodifiableCollection(_implementations);
81     }
82     
83     /**
84      * @see org.apache.hivemind.definition.ServicePointDefinition#getDefaultImplementation()
85      */

86     public ImplementationDefinition getDefaultImplementation()
87     {
88         ImplementationDefinition defaulImplementation = null;
89         for (Iterator JavaDoc 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     /**
104      * Checks if Extension can see this service point.
105      * @throws ApplicationRuntimeException if not visible
106      */

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     /**
119      * @see org.apache.hivemind.definition.ServicePointDefinition#addImplementation(org.apache.hivemind.definition.ImplementationDefinition)
120      */

121     public void addImplementation(ImplementationDefinition implementation)
122     {
123         checkVisibility(implementation);
124         _implementations.add(implementation);
125     }
126     
127     /**
128      * @see org.apache.hivemind.definition.ServicePointDefinition#getInterceptors()
129      */

130     public Collection JavaDoc getInterceptors()
131     {
132         return Collections.unmodifiableCollection(_interceptors);
133     }
134
135     /**
136      * @see org.apache.hivemind.definition.ServicePointDefinition#addInterceptor(org.apache.hivemind.definition.InterceptorDefinition)
137      */

138     public void addInterceptor(InterceptorDefinition interceptor)
139     {
140         checkVisibility(interceptor);
141         _interceptors.add(interceptor);
142     }
143 }
144
Popular Tags