KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.hivemind.definition.ConfigurationPointDefinition;
18 import org.apache.hivemind.definition.Contribution;
19 import org.apache.hivemind.definition.ContributionDefinition;
20 import org.apache.hivemind.definition.ImplementationConstructor;
21 import org.apache.hivemind.definition.ImplementationDefinition;
22 import org.apache.hivemind.definition.ModuleDefinition;
23 import org.apache.hivemind.definition.Occurances;
24 import org.apache.hivemind.definition.ServicePointDefinition;
25 import org.apache.hivemind.definition.Visibility;
26 import org.apache.hivemind.impl.CreateClassServiceConstructor;
27 import org.apache.hivemind.internal.ServiceModel;
28
29 /**
30  * Helper class that offers convenience functions for the definition of modules
31  * and its extension points. All instances created are
32  * {@link org.apache.hivemind.definition.impl standard implementations}
33  * of the definition interfaces.
34  *
35  * @author Achim Huegen
36  */

37 public class ModuleDefinitionHelper
38 {
39     private ModuleDefinitionImpl _module;
40
41     public ModuleDefinitionHelper(ModuleDefinitionImpl module)
42     {
43         _module = module;
44     }
45
46     public ServicePointDefinition addServicePoint(String JavaDoc servicePointId, String JavaDoc serviceInterface)
47     {
48         ServicePointDefinitionImpl result = new ServicePointDefinitionImpl(_module, servicePointId, _module
49                 .getLocation(), Visibility.PUBLIC, serviceInterface);
50
51         _module.addServicePoint(result);
52         return result;
53     }
54
55     public ServicePointDefinition addServicePointWithDefaultImplementation(String JavaDoc servicePointId, String JavaDoc serviceInterface)
56     {
57         ServicePointDefinition result = addServicePoint(servicePointId, serviceInterface);
58         String JavaDoc defaultImplementationName = serviceInterface + "Impl";
59         addSimpleServiceImplementation(result, defaultImplementationName, ServiceModel.SINGLETON);
60         return result;
61     }
62  
63     public ImplementationDefinition addServiceImplementation(
64             ServicePointDefinition servicePoint,
65             ImplementationConstructor constructor, String JavaDoc serviceModel
66             )
67     {
68         // These implementations override the inline implementations, so default is true here
69
ImplementationDefinition result = new ImplementationDefinitionImpl(_module, _module
70                 .getLocation(), constructor, serviceModel, true);
71         servicePoint.addImplementation(result);
72         return result;
73     }
74     
75     public ImplementationDefinition addSimpleServiceImplementation(
76             ServicePointDefinition servicePoint,
77             String JavaDoc serviceImplementationClass, String JavaDoc serviceModel)
78     {
79         return addServiceImplementation(servicePoint,
80                 new CreateClassServiceConstructor(_module.getLocation(), serviceImplementationClass),
81                 serviceModel);
82     }
83     
84     public ConfigurationPointDefinition addConfigurationPoint(String JavaDoc configurationPointId, String JavaDoc containerType)
85     {
86         ConfigurationPointDefinitionImpl result = new ConfigurationPointDefinitionImpl(_module, configurationPointId, _module
87                 .getLocation(), Visibility.PUBLIC, containerType, Occurances.UNBOUNDED);
88
89         _module.addConfigurationPoint(result);
90         return result;
91     }
92     
93     public ContributionDefinition addContributionDefinition(ConfigurationPointDefinition configurationPoint,
94             Contribution contributionConstructor)
95     {
96         ContributionDefinition result = new ContributionDefinitionImpl(_module, _module.getLocation(), contributionConstructor, false);
97         configurationPoint.addContribution(result);
98         return result;
99     }
100     
101     public ContributionDefinition addContributionDefinition(String JavaDoc qualifiedConfigurationPointId,
102             Contribution contributionConstructor)
103     {
104         ContributionDefinitionImpl result = new ContributionDefinitionImpl(_module, _module.getLocation(), contributionConstructor, false);
105         _module.addContribution(qualifiedConfigurationPointId, result);
106         return result;
107     }
108
109     public ModuleDefinition getModule()
110     {
111         return _module;
112     }
113
114 }
115
Popular Tags