]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
a5e3eafe870bf45c7f0e566f33562d19fa38f95c
[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
28 import javax.ws.rs.core.MultivaluedMap;
29
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;
35
36 /**
37  * RemoteServiceContextImpl
38  *
39  * $LastChangedRevision: $
40  * $LastChangedDate: $
41  */
42 public class RemoteServiceContextImpl<IT, OT>
43         extends AbstractServiceContextImpl<IT, OT>
44         implements RemoteServiceContext<IT, OT> {
45
46     /** The logger. */
47     final Logger logger = LoggerFactory.getLogger(RemoteServiceContextImpl.class);
48     //input stores original content as received over the wire
49     /** The input. */
50     private IT input;
51     
52     /** The output. */
53     private OT output;
54
55     /**
56      * Instantiates a new remote service context impl.
57      * 
58      * @param serviceName the service name
59      * 
60      * @throws UnauthorizedException the unauthorized exception
61      */
62     protected RemoteServiceContextImpl(String serviceName) throws UnauthorizedException {
63         super(serviceName);
64     }
65
66     /**
67      * Instantiates a new remote service context impl. (This is "package" protected for the Factory class)
68      * 
69      * @param serviceName the service name
70      * 
71      * @throws UnauthorizedException the unauthorized exception
72      */
73     protected RemoteServiceContextImpl(String serviceName, IT theInput) throws UnauthorizedException {
74         this(serviceName);
75         this.input = theInput;
76     }
77
78     /**
79      * Instantiates a new remote service context impl. (This is "package" protected for the Factory class)
80      * 
81      * @param serviceName the service name
82      * @param theInput the the input
83      * @param queryParams the query params
84      * 
85      * @throws UnauthorizedException the unauthorized exception
86      */
87     protected RemoteServiceContextImpl(String serviceName,
88                 IT theInput,
89                 MultivaluedMap<String, String> queryParams) throws UnauthorizedException {
90         this(serviceName, theInput);
91         this.setQueryParams(queryParams);
92     }
93
94     /* (non-Javadoc)
95      * @see org.collectionspace.services.common.context.AbstractServiceContextImpl#getInput()
96      */
97     @Override
98     public IT getInput() {
99         return input;
100     }
101
102     /* (non-Javadoc)
103      * @see org.collectionspace.services.common.context.AbstractServiceContextImpl#setInput(java.lang.Object)
104      */
105     @Override
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!";
110             logger.error(msg);
111             throw new IllegalStateException(msg);
112         }
113         this.input = input;
114     }
115
116     /* (non-Javadoc)
117      * @see org.collectionspace.services.common.context.AbstractServiceContextImpl#getOutput()
118      */
119     @Override
120     public OT getOutput() {
121         return output;
122     }
123
124     /* (non-Javadoc)
125      * @see org.collectionspace.services.common.context.AbstractServiceContextImpl#setOutput(java.lang.Object)
126      */
127     @Override
128     public void setOutput(OT output) {
129         this.output = output;
130     }
131
132     /* (non-Javadoc)
133      * @see org.collectionspace.services.common.context.RemoteServiceContext#getLocalContext(java.lang.String)
134      */
135     @Override
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());
142         }
143
144         Constructor ctor = ctxClass.getConstructor(java.lang.String.class);
145         ServiceContext ctx = (ServiceContext) ctor.newInstance(getServiceName());
146         return ctx;
147     }    
148 }