KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > annotations > internal > MethodCallImplementationConstructor


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.annotations.internal;
16
17 import java.lang.reflect.Method JavaDoc;
18
19 import org.apache.hivemind.ApplicationRuntimeException;
20 import org.apache.hivemind.Location;
21 import org.apache.hivemind.annotations.definition.Service;
22 import org.apache.hivemind.definition.ImplementationConstructionContext;
23 import org.apache.hivemind.definition.ImplementationConstructor;
24 import org.apache.hivemind.internal.AbstractServiceImplementationConstructor;
25
26 /**
27  * Constructs a service implementation by calling a factory method defined in
28  * an annotated module by use of the {@link Service} annotation.
29  *
30  * @author Achim Huegen
31  */

32 public class MethodCallImplementationConstructor extends AbstractServiceImplementationConstructor implements
33         ImplementationConstructor
34 {
35     private Method JavaDoc _factoryMethod;
36
37     private ModuleInstanceProvider _moduleInstanceProvider;
38
39     public MethodCallImplementationConstructor(Location location, Method JavaDoc factoryMethod,
40             ModuleInstanceProvider moduleInstanceProvider)
41     {
42         super(location);
43         _factoryMethod = factoryMethod;
44         _moduleInstanceProvider = moduleInstanceProvider;
45     }
46
47     public Object JavaDoc constructCoreServiceImplementation(ImplementationConstructionContext context)
48     {
49         try
50         {
51             Object JavaDoc result = _factoryMethod.invoke(_moduleInstanceProvider.getModuleInstance(), (Object JavaDoc[]) null);
52             return result;
53         }
54         catch (Exception JavaDoc ex)
55         {
56             throw new ApplicationRuntimeException(ex.getMessage(), getLocation(), ex);
57         }
58     }
59
60 }
61
Popular Tags