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:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright 2009 University of California at Berkeley
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
16 * https://source.collectionspace.org/collection-space/LICENSE.txt
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.
24 package org.collectionspace.services.common.context;
26 import java.lang.reflect.Constructor;
28 import javax.ws.rs.core.MultivaluedMap;
30 import org.collectionspace.services.common.document.DocumentFilter;
31 import org.collectionspace.services.common.document.DocumentHandler;
32 import org.collectionspace.services.common.security.UnauthorizedException;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
37 * RemoteServiceContextImpl
39 * $LastChangedRevision: $
42 public class RemoteServiceContextImpl<IT, OT>
43 extends AbstractServiceContextImpl<IT, OT>
44 implements RemoteServiceContext<IT, OT> {
47 final Logger logger = LoggerFactory.getLogger(RemoteServiceContextImpl.class);
48 //input stores original content as received over the wire
56 * Instantiates a new remote service context impl.
58 * @param serviceName the service name
60 * @throws UnauthorizedException the unauthorized exception
62 protected RemoteServiceContextImpl(String serviceName) throws UnauthorizedException {
67 * Instantiates a new remote service context impl. (This is "package" protected for the Factory class)
69 * @param serviceName the service name
71 * @throws UnauthorizedException the unauthorized exception
73 protected RemoteServiceContextImpl(String serviceName, IT theInput) throws UnauthorizedException {
75 this.input = theInput;
79 * Instantiates a new remote service context impl. (This is "package" protected for the Factory class)
81 * @param serviceName the service name
82 * @param theInput the the input
83 * @param queryParams the query params
85 * @throws UnauthorizedException the unauthorized exception
87 protected RemoteServiceContextImpl(String serviceName,
89 MultivaluedMap<String, String> queryParams) throws UnauthorizedException {
90 this(serviceName, theInput);
91 this.setQueryParams(queryParams);
95 * @see org.collectionspace.services.common.context.AbstractServiceContextImpl#getInput()
98 public IT getInput() {
103 * @see org.collectionspace.services.common.context.AbstractServiceContextImpl#setInput(java.lang.Object)
106 public void setInput(IT input) {
107 //for security reasons, do not allow to set input again (from handlers)
108 if (this.input != null) {
109 String msg = "Non-null input cannot be set!";
111 throw new IllegalStateException(msg);
117 * @see org.collectionspace.services.common.context.AbstractServiceContextImpl#getOutput()
120 public OT getOutput() {
125 * @see org.collectionspace.services.common.context.AbstractServiceContextImpl#setOutput(java.lang.Object)
128 public void setOutput(OT output) {
129 this.output = output;
133 * @see org.collectionspace.services.common.context.RemoteServiceContext#getLocalContext(java.lang.String)
136 public ServiceContext getLocalContext(String localContextClassName) throws Exception {
137 ClassLoader cloader = Thread.currentThread().getContextClassLoader();
138 Class ctxClass = cloader.loadClass(localContextClassName);
139 if (!ServiceContext.class.isAssignableFrom(ctxClass)) {
140 throw new IllegalArgumentException("getLocalContext requires "
141 + " implementation of " + ServiceContext.class.getName());
144 Constructor ctor = ctxClass.getConstructor(java.lang.String.class);
145 ServiceContext ctx = (ServiceContext) ctor.newInstance(getServiceName());