]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
d5321864445168e377103da9770779b36da76b73
[tmp/jakarta-migration.git] /
1 /**
2  *  This document is a part of the source code and related artifacts
3  *  for CollectionSpace, an open source collections management system
4  *  for museums and related institutions:
5
6  *  http://www.collectionspace.org
7  *  http://wiki.collectionspace.org
8
9  *  Copyright 2009 University of California at Berkeley
10
11  *  Licensed under the Educational Community License (ECL), Version 2.0.
12  *  You may not use this file except in compliance with this License.
13
14  *  You may obtain a copy of the ECL 2.0 License at
15
16  *  https://source.collectionspace.org/collection-space/LICENSE.txt
17
18  *  Unless required by applicable law or agreed to in writing, software
19  *  distributed under the License is distributed on an "AS IS" BASIS,
20  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  *  See the License for the specific language governing permissions and
22  *  limitations under the License.
23  */
24 package org.collectionspace.services.common.context;
25
26 import java.lang.reflect.Constructor;
27 import org.collectionspace.services.common.security.UnauthorizedException;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31 /**
32  * RemoteServiceContextImpl
33  *
34  * $LastChangedRevision: $
35  * $LastChangedDate: $
36  */
37 public class RemoteServiceContextImpl<IT, OT>
38         extends AbstractServiceContext<IT, OT>
39         implements RemoteServiceContext<IT, OT> {
40
41     final Logger logger = LoggerFactory.getLogger(RemoteServiceContextImpl.class);
42     //input stores original content as received over the wire
43     private IT input;
44     private OT output;
45
46     public RemoteServiceContextImpl(String serviceName) throws UnauthorizedException {
47         super(serviceName);
48     }
49
50     @Override
51     public IT getInput() {
52         return input;
53     }
54
55     @Override
56     public void setInput(IT input){
57         this.input = input;
58     }
59
60     @Override
61     public OT getOutput() {
62         return output;
63     }
64
65     @Override
66     public void setOutput(OT output){
67         this.output = output;
68     }
69
70
71     @Override
72     public ServiceContext getLocalContext(String localContextClassName) throws Exception {
73         ClassLoader cloader = Thread.currentThread().getContextClassLoader();
74         Class ctxClass = cloader.loadClass(localContextClassName);
75         if(!ServiceContext.class.isAssignableFrom(ctxClass)) {
76             throw new IllegalArgumentException("getLocalContext requires " +
77                     " implementation of " + ServiceContext.class.getName());
78         }
79         
80         Constructor ctor = ctxClass.getConstructor(java.lang.String.class);
81         ServiceContext ctx = (ServiceContext)ctor.newInstance(getServiceName());
82         return ctx;
83     }
84 }