KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > impl > ServiceImplementationFactoryParametersImpl


1 // Copyright 2004, 2005 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.impl;
16
17 import java.util.List JavaDoc;
18
19 import org.apache.commons.logging.Log;
20 import org.apache.hivemind.ApplicationRuntimeException;
21 import org.apache.hivemind.ErrorLog;
22 import org.apache.hivemind.ServiceImplementationFactoryParameters;
23 import org.apache.hivemind.internal.Module;
24 import org.apache.hivemind.internal.ServicePoint;
25 import org.apache.hivemind.util.Defense;
26
27 /**
28  * Wrapper around a {@link org.apache.hivemind.internal.ServicePoint} and a List of parameters,
29  * passed to a {@link org.apache.hivemind.ServiceImplementationFactory}.
30  *
31  * @author Howard M. Lewis Ship
32  * @since 1.1
33  */

34 public class ServiceImplementationFactoryParametersImpl implements
35         ServiceImplementationFactoryParameters
36 {
37     private ServicePoint _servicePoint;
38
39     private Module _invokingModule;
40
41     private Object JavaDoc _parameters;
42
43     public ServiceImplementationFactoryParametersImpl(ServicePoint servicePoint,
44             Module invokingModule, Object JavaDoc parameters)
45     {
46         Defense.notNull(servicePoint, "servicePoint");
47         Defense.notNull(invokingModule, "invokingModule");
48
49         _servicePoint = servicePoint;
50         _invokingModule = invokingModule;
51         _parameters = parameters;
52     }
53
54     /**
55      * This method is only used in testing.
56      */

57
58     public boolean equals(Object JavaDoc other)
59     {
60         ServiceImplementationFactoryParametersImpl p = (ServiceImplementationFactoryParametersImpl) other;
61
62         return _servicePoint == p._servicePoint && _invokingModule == p._invokingModule
63                 && ((_parameters == null && p._parameters == null) || _parameters.equals(p._parameters));
64     }
65
66     public String JavaDoc getServiceId()
67     {
68         return _servicePoint.getExtensionPointId();
69     }
70
71     public Class JavaDoc getServiceInterface()
72     {
73         return _servicePoint.getServiceInterface();
74     }
75
76     public Log getLog()
77     {
78         return _servicePoint.getLog();
79     }
80
81     public ErrorLog getErrorLog()
82     {
83         return _servicePoint.getErrorLog();
84     }
85
86     public Module getInvokingModule()
87     {
88         return _invokingModule;
89     }
90
91     public List JavaDoc getParameters()
92     {
93         // For backward compatibility lists are handled specially. The behaviour
94
// of hivemind 1.x is emulated
95
if (_parameters instanceof List JavaDoc) {
96             return (List JavaDoc) _parameters;
97         } else {
98             throw new ApplicationRuntimeException("Parameters are not contained in a list. Use getParametersContainer instead.");
99         }
100     }
101     
102     public Object JavaDoc getParametersContainer()
103     {
104         return _parameters;
105     }
106
107     public Object JavaDoc getFirstParameter()
108     {
109         // For backward compatibility lists are handled specially. The behaviour
110
// of hivemind 1.x is emulated
111
if (_parameters instanceof List JavaDoc) {
112             return ((List JavaDoc) _parameters).isEmpty() ? null : ((List JavaDoc) _parameters).get(0);
113         } else {
114             return _parameters;
115         }
116     }
117
118 }
Popular Tags