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;
27 import javax.ws.rs.core.UriInfo;
29 import org.collectionspace.services.common.ResourceMap;
30 import org.collectionspace.services.common.security.UnauthorizedException;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
36 * RemoteServiceContextImpl
38 * $LastChangedRevision: $
41 public class RemoteServiceContextImpl<IT, OT>
42 extends AbstractServiceContextImpl<IT, OT>
43 implements RemoteServiceContext<IT, OT> {
46 final Logger logger = LoggerFactory.getLogger(RemoteServiceContextImpl.class);
47 //input stores original content as received over the wire
52 /** The target of the HTTP request **/
53 JaxRsContext jaxRsContext;
55 ResourceMap resourceMap = null;
58 public void setJaxRsContext(JaxRsContext theJaxRsContext) {
59 this.jaxRsContext = theJaxRsContext;
63 public JaxRsContext getJaxRsContext() {
64 return this.jaxRsContext;
68 * Instantiates a new remote service context impl.
70 * @param serviceName the service name
72 * @throws UnauthorizedException the unauthorized exception
74 protected RemoteServiceContextImpl(String serviceName) throws UnauthorizedException {
79 * Instantiates a new remote service context impl. (This is "package" protected for the Factory class)
81 * @param serviceName the service name
83 * @throws UnauthorizedException the unauthorized exception
85 protected RemoteServiceContextImpl(String serviceName, IT theInput) throws UnauthorizedException {
87 this.input = theInput;
91 * Instantiates a new remote service context impl. (This is "package" protected for the Factory class)
93 * @param serviceName the service name
94 * @param theInput the the input
95 * @param queryParams the query params
97 * @throws UnauthorizedException the unauthorized exception
99 protected RemoteServiceContextImpl(String serviceName,
101 ResourceMap resourceMap,
102 UriInfo uriInfo) throws UnauthorizedException {
103 this(serviceName, theInput);
104 this.setResourceMap(resourceMap);
105 this.setUriInfo(uriInfo);
106 if (uriInfo != null) {
107 this.setQueryParams(uriInfo.getQueryParameters());
112 * @see org.collectionspace.services.common.context.AbstractServiceContextImpl#getInput()
115 public IT getInput() {
120 * @see org.collectionspace.services.common.context.AbstractServiceContextImpl#setInput(java.lang.Object)
123 public void setInput(IT input) {
124 //for security reasons, do not allow to set input again (from handlers)
125 if (this.input != null) {
126 String msg = "Non-null input cannot be set!";
128 throw new IllegalStateException(msg);
134 * @see org.collectionspace.services.common.context.AbstractServiceContextImpl#getOutput()
137 public OT getOutput() {
142 * @see org.collectionspace.services.common.context.AbstractServiceContextImpl#setOutput(java.lang.Object)
145 public void setOutput(OT output) {
146 this.output = output;
150 * @return the map of service names to resource classes.
152 public ResourceMap getResourceMap() {
157 * @param map the map of service names to resource instances.
159 public void setResourceMap(ResourceMap map) {
160 this.resourceMap = map;
166 * @see org.collectionspace.services.common.context.RemoteServiceContext#getLocalContext(java.lang.String)
169 public ServiceContext getLocalContext(String localContextClassName) throws Exception {
170 ClassLoader cloader = Thread.currentThread().getContextClassLoader();
171 Class<?> ctxClass = cloader.loadClass(localContextClassName);
172 if (!ServiceContext.class.isAssignableFrom(ctxClass)) {
173 throw new IllegalArgumentException("getLocalContext requires "
174 + " implementation of " + ServiceContext.class.getName());
177 Constructor ctor = ctxClass.getConstructor(java.lang.String.class);
178 ServiceContext ctx = (ServiceContext) ctor.newInstance(getServiceName());