]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
9391805f4db9b6ca9b05c17b8ee46733692de6be
[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 AbstractServiceContextImpl<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         //for security reasons, do not allow to set input again (from handlers)
58         if (this.input != null) {
59             String msg = "Non-null input cannot be set!";
60             logger.error(msg);
61             throw new IllegalStateException(msg);
62         }
63         this.input = input;
64     }
65
66     @Override
67     public OT getOutput() {
68         return output;
69     }
70
71     @Override
72     public void setOutput(OT output) {
73         this.output = output;
74     }
75
76     @Override
77     public ServiceContext getLocalContext(String localContextClassName) throws Exception {
78         ClassLoader cloader = Thread.currentThread().getContextClassLoader();
79         Class ctxClass = cloader.loadClass(localContextClassName);
80         if (!ServiceContext.class.isAssignableFrom(ctxClass)) {
81             throw new IllegalArgumentException("getLocalContext requires "
82                     + " implementation of " + ServiceContext.class.getName());
83         }
84
85         Constructor ctor = ctxClass.getConstructor(java.lang.String.class);
86         ServiceContext ctx = (ServiceContext) ctor.newInstance(getServiceName());
87         return ctx;
88     }
89 }