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.util.ArrayList;
27 import java.util.HashMap;
28 import java.util.List;
30 import java.util.Properties;
32 import javax.ws.rs.core.MultivaluedMap;
33 import javax.ws.rs.core.UriInfo;
35 import org.collectionspace.authentication.spi.AuthNContext;
36 import org.collectionspace.services.client.AuthorityClient;
37 import org.collectionspace.services.client.CollectionSpaceClient;
38 import org.collectionspace.services.client.IClientQueryParams;
39 import org.collectionspace.services.client.IQueryManager;
40 import org.collectionspace.services.client.workflow.WorkflowClient;
41 import org.collectionspace.services.common.ServiceMain;
42 import org.collectionspace.services.common.api.Tools;
43 import org.collectionspace.services.common.authorization_mgt.AuthorizationCommon;
44 import org.collectionspace.services.common.config.PropertyItemUtils;
45 import org.collectionspace.services.common.config.ServiceConfigUtils;
46 import org.collectionspace.services.common.config.TenantBindingConfigReaderImpl;
47 import org.collectionspace.services.common.document.DocumentHandler;
48 import org.collectionspace.services.common.document.DocumentFilter;
49 import org.collectionspace.services.common.document.ValidatorHandler;
50 import org.collectionspace.services.common.security.SecurityContext;
51 import org.collectionspace.services.common.security.SecurityContextImpl;
52 import org.collectionspace.services.common.security.UnauthorizedException;
53 import org.collectionspace.services.config.ClientType;
54 import org.collectionspace.services.config.service.ObjectPartType;
55 import org.collectionspace.services.config.service.ServiceBindingType;
56 import org.collectionspace.services.config.tenant.RemoteClientConfig;
57 import org.collectionspace.services.config.tenant.RepositoryDomainType;
58 import org.collectionspace.services.config.tenant.TenantBindingType;
59 import org.collectionspace.services.config.types.PropertyItemType;
60 import org.collectionspace.services.config.types.PropertyType;
61 import org.slf4j.Logger;
62 import org.slf4j.LoggerFactory;
65 * AbstractServiceContext
67 * $LastChangedRevision: $
82 @SuppressWarnings("rawtypes")
83 public abstract class AbstractServiceContextImpl<IT, OT>
84 implements ServiceContext<IT, OT> {
87 final Logger logger = LoggerFactory.getLogger(AbstractServiceContextImpl.class);
89 /** The properties. */
90 Map<String, Object> properties = new HashMap<String, Object>();
91 /** The object part map. */
92 Map<String, ObjectPartType> objectPartMap = new HashMap<String, ObjectPartType>();
93 /** The service binding. */
94 protected ServiceBindingType serviceBinding;
95 /** The tenant binding. */
96 private TenantBindingType tenantBinding;
97 /** repository domain used by the service */
98 private RepositoryDomainType repositoryDomain;
99 /** The override document type. */
100 private String overrideDocumentType = null;
101 /** The val handlers. */
102 private List<ValidatorHandler<IT, OT>> valHandlers = null;
103 /** The authority client -use for shared authority server */
104 private AuthorityClient authorityClient = null;
105 /** The doc handler. */
106 private DocumentHandler docHandler = null;
107 /** security context */
108 private SecurityContext securityContext;
109 /** The sessions JAX-RS URI information */
110 private UriInfo uriInfo;
111 /** The current repository session */
112 private Object currentRepositorySession;
113 /** A reference count for the current repository session */
114 private int currentRepoSesssionRefCount = 0;
117 * Instantiates a new abstract service context impl.
119 private AbstractServiceContextImpl() {
120 // private constructor for singleton pattern
122 // request query params
123 /** The query params. */
124 private MultivaluedMap<String, String> queryParams;
127 * Instantiates a new abstract service context impl.
129 * @param serviceName the service name
131 * @throws UnauthorizedException the unauthorized exception
133 protected AbstractServiceContextImpl(String serviceName, UriInfo uriInfo) throws UnauthorizedException {
135 //establish security context
136 securityContext = new SecurityContextImpl(uriInfo);
137 //make sure tenant context exists
138 checkTenantContext();
140 String tenantId = securityContext.getCurrentTenantId();
141 if (AuthorizationCommon.ALL_TENANTS_MANAGER_TENANT_ID.equals(tenantId) ||
142 AuthNContext.ANONYMOUS_TENANT_ID.equals(tenantId)) {
143 // Tenant Manager has no tenant binding, so don't bother...
144 tenantBinding = null;
145 serviceBinding = null;
146 repositoryDomain = null;
148 //retrieve service bindings
149 TenantBindingConfigReaderImpl tReader =
150 ServiceMain.getInstance().getTenantBindingConfigReader();
151 tenantBinding = tReader.getTenantBinding(tenantId);
152 if (tenantBinding == null) {
153 String msg = "No tenant binding found for tenantId=" + tenantId
154 + " while processing request for service= " + serviceName;
156 throw new IllegalStateException(msg);
158 serviceBinding = tReader.getServiceBinding(tenantId, serviceName);
159 if (serviceBinding == null) {
160 String msg = "No service binding found while processing request for "
161 + serviceName + " for tenant id=" + getTenantId()
162 + " name=" + getTenantName();
164 throw new IllegalStateException(msg);
166 if (logger.isDebugEnabled()) {
167 logger.debug("tenantId=" + tenantId
168 + " service binding=" + serviceBinding.getName());
170 repositoryDomain = tReader.getRepositoryDomain(tenantId, serviceName);
171 if (repositoryDomain != null) {
172 if (logger.isDebugEnabled()) {
173 logger.debug("tenantId=" + tenantId
174 + " repository doamin=" + repositoryDomain.getName());
180 public int getTimeoutParam(UriInfo ui) {
181 int result = DEFAULT_TX_TIMEOUT;
183 MultivaluedMap<String, String> queryParams = (ui == null) ? null : ui.getQueryParameters();
184 if (queryParams != null) {
185 String timeoutString = queryParams.getFirst(IClientQueryParams.IMPORT_TIMEOUT_PARAM);
186 if (timeoutString != null)
188 result = Integer.parseInt(timeoutString);
189 } catch (NumberFormatException e) {
190 logger.warn("Transaction timeout period parameter could not be parsed. The characters in the parameter string must all be decimal digits. The Import service will use the default timeout period instead.",
199 public int getTimeoutSecs() {
200 UriInfo uriInfo = this.getUriInfo();
201 return this.getTimeoutParam(uriInfo);
205 * @see org.collectionspace.services.common.context.ServiceContext#getCommonPartLabel()
208 public String getCommonPartLabel() {
209 return getCommonPartLabel(getServiceName());
213 * @see org.collectionspace.services.common.context.ServiceContext#getCommonPartLabel(java.lang.String)
215 public String getCommonPartLabel(String schemaName) {
216 return schemaName.toLowerCase() + PART_LABEL_SEPARATOR + PART_COMMON_LABEL;
220 * @see org.collectionspace.services.common.context.ServiceContext#getPartsMetadata()
223 public Map<String, ObjectPartType> getPartsMetadata() {
224 if (objectPartMap.size() != 0) {
225 return objectPartMap;
227 ServiceBindingUtils.getPartsMetadata(getServiceBinding(), objectPartMap);
228 return objectPartMap;
232 * Gets the properties for part.
234 * @param partLabel the part label
236 * @return the properties for part
238 public List<PropertyItemType> getPropertiesForPart(String partLabel) {
239 Map<String, ObjectPartType> partMap = getPartsMetadata();
240 ObjectPartType part = partMap.get(partLabel);
242 throw new RuntimeException("No such part found: " + partLabel);
244 List<PropertyType> propNodeList = part.getProperties();
245 return propNodeList.isEmpty() ? null : propNodeList.get(0).getItem();
249 * @param partLabel The name of the scehma part to search in
250 * @param propName The name of the property (or properties) to find
251 * @param qualified Whether the returned values should be qualified with the
252 * partLabel. This is when the property values are schema field references.
253 * @return List of property values for the matched property on the named schema part.
255 public List<String> getPropertyValuesForPart(String partLabel, String propName, boolean qualified) {
256 List<PropertyItemType> allProps = getPropertiesForPart(partLabel);
257 return PropertyItemUtils.getPropertyValuesByName(allProps, propName,
258 (qualified ? (partLabel + ":") : null));
262 * @param propName The name of the property (or properties) to find
263 * @param qualified Whether the returned values should be qualified with the
264 * partLabel. This is when the property values are schema field references.
265 * @return List of property values for the matched property on any schema part.
267 public List<String> getAllPartsPropertyValues(String propName, boolean qualified) {
268 return ServiceBindingUtils.getAllPartsPropertyValues(getServiceBinding(), propName, qualified);
272 * @see org.collectionspace.services.common.context.ServiceContext#getServiceBindingPropertyValue(java.lang.String)
274 public String getServiceBindingPropertyValue(String propName) {
275 return ServiceBindingUtils.getPropertyValue(getServiceBinding(), propName);
279 * Gets the common part properties.
281 * @return the common part properties
283 public List<PropertyItemType> getCommonPartProperties() {
284 return getPropertiesForPart(getCommonPartLabel());
288 * @param propName The name of the property (or properties) to find
289 * @param qualified Whether the returned values should be qualified with the
290 * partLabel. This is when the property values are schema field references.
291 * @return List of property values for the matched property on the common schema part.
293 public List<String> getCommonPartPropertyValues(String propName, boolean qualified) {
294 return getPropertyValuesForPart(getCommonPartLabel(), propName, qualified);
298 * @see org.collectionspace.services.common.context.ServiceContext#getQualifiedServiceName()
301 public String getQualifiedServiceName() {
302 return TenantBindingConfigReaderImpl.getTenantQualifiedServiceName(getTenantId(), getServiceName());
306 * @see org.collectionspace.services.common.context.ServiceContext#getRepositoryClientName()
309 public String getRepositoryClientName() {
310 if (repositoryDomain == null) {
313 return repositoryDomain.getRepositoryClient();
317 * @see org.collectionspace.services.common.context.ServiceContext#getRepositoryClientType()
320 public ClientType getRepositoryClientType() {
321 //assumption: there is only one repository client configured
322 return ServiceMain.getInstance().getClientType();
326 * @see org.collectionspace.services.common.context.ServiceContext#getRepositoryDomainName()
329 public String getRepositoryDomainName() {
330 if (repositoryDomain == null) {
333 return repositoryDomain.getName();
337 * @see org.collectionspace.services.common.context.ServiceContext#getRepositoryDomainName()
340 public String getRepositoryDomainStorageName() {
341 if (repositoryDomain == null) {
344 return repositoryDomain.getStorageName();
348 * @see org.collectionspace.services.common.context.ServiceContext#getRepositoryWorkspaceId()
351 public String getRepositoryWorkspaceId() {
352 return ServiceMain.getInstance().getWorkspaceId(getTenantId(), getServiceName());
356 * @see org.collectionspace.services.common.context.ServiceContext#getRepositoryWorkspaceName()
359 public String getRepositoryWorkspaceName() {
360 //service name is workspace name by convention
361 return serviceBinding.getName();
365 * @see org.collectionspace.services.common.context.ServiceContext#getServiceBinding()
368 public ServiceBindingType getServiceBinding() {
369 return serviceBinding;
373 * @see org.collectionspace.services.common.context.ServiceContext#getServiceName()
376 public String getServiceName() {
377 return serviceBinding.getName();
381 * @see org.collectionspace.services.common.context.ServiceContext#getDocumentType()
384 public String getDocumentType() {
385 // If they have not overridden the setting, use the type of the service
387 return (overrideDocumentType != null) ? overrideDocumentType : serviceBinding.getObject().getName();
391 public String getTenantQualifiedDoctype(String docType) {
392 // If they have not overridden the setting, use the type of the service
394 String result = ServiceBindingUtils.getTenantQualifiedDocType(this.getTenantId(), docType);
400 public String getTenantQualifiedDoctype() {
401 String docType = (overrideDocumentType != null) ? overrideDocumentType : serviceBinding.getObject().getName();
402 return getTenantQualifiedDoctype(docType);
406 * @see org.collectionspace.services.common.context.ServiceContext#setDocumentType(java.lang.String)
409 public void setDocumentType(String docType) {
410 overrideDocumentType = docType;
414 * @see org.collectionspace.services.common.context.ServiceContext#getSecurityContext()
417 public SecurityContext getSecurityContext() {
418 return securityContext;
422 * @see org.collectionspace.services.common.context.ServiceContext#getUserId()
425 public String getUserId() {
426 return securityContext.getUserId();
430 * @see org.collectionspace.services.common.context.ServiceContext#getTenantId()
433 public String getTenantId() {
434 return securityContext.getCurrentTenantId();
438 * @see org.collectionspace.services.common.context.ServiceContext#getTenantName()
441 public String getTenantName() {
442 return securityContext.getCurrentTenantName();
446 * @see org.collectionspace.services.common.context.ServiceContext#getInput()
449 public abstract IT getInput();
452 * @see org.collectionspace.services.common.context.ServiceContext#setInput(java.lang.Object)
455 public abstract void setInput(IT input);
458 * @see org.collectionspace.services.common.context.ServiceContext#getOutput()
461 public abstract OT getOutput();
464 * @see org.collectionspace.services.common.context.ServiceContext#setOutput(java.lang.Object)
467 public abstract void setOutput(OT output);
470 * @see org.collectionspace.services.common.context.ServiceContext#getProperties()
473 public Map<String, Object> getProperties() {
478 * @see org.collectionspace.services.common.context.ServiceContext#setProperties(java.util.Map)
481 public void setProperties(Map<String, Object> props) {
482 properties.putAll(props);
486 * @see org.collectionspace.services.common.context.ServiceContext#getProperty(java.lang.String)
488 public Object getProperty(String name) {
489 return properties.get(name);
493 * @see org.collectionspace.services.common.context.ServiceContext#setProperty(java.lang.String, java.lang.Object)
495 public void setProperty(String name, Object o) {
496 properties.put(name, o);
500 * checkTenantContext makss sure tenant context exists
504 * @throws UnauthorizedException the unauthorized exception
506 private void checkTenantContext() throws UnauthorizedException {
508 String tenantId = securityContext.getCurrentTenantId();
509 if (tenantId == null) {
510 String msg = "Could not find tenant context";
512 throw new UnauthorizedException(msg);
517 * Helps to filter for queries that either want to include or exclude documents in deleted workflow states.
522 private static String buildWorkflowWhereClause(MultivaluedMap<String, String> queryParams) {
523 String result = null;
525 String includeDeleted = queryParams.getFirst(WorkflowClient.WORKFLOW_QUERY_NONDELETED);
526 String includeOnlyDeleted = queryParams.getFirst(WorkflowClient.WORKFLOW_QUERY_ONLY_DELETED);
528 if (includeDeleted != null && includeDeleted.equalsIgnoreCase(Boolean.FALSE.toString())) {
529 result = String.format("(ecm:currentLifeCycleState <> '%s' AND ecm:currentLifeCycleState <> '%s' AND ecm:currentLifeCycleState <> '%s')",
530 WorkflowClient.WORKFLOWSTATE_DELETED, WorkflowClient.WORKFLOWSTATE_LOCKED_DELETED, WorkflowClient.WORKFLOWSTATE_REPLICATED_DELETED);
531 } else if (includeOnlyDeleted != null && includeOnlyDeleted.equalsIgnoreCase(Boolean.TRUE.toString())) {
532 result = String.format("(ecm:currentLifeCycleState <> '%s' AND ecm:currentLifeCycleState <> '%s' AND ecm:currentLifeCycleState <> '%s')",
533 WorkflowClient.WORKFLOWSTATE_PROJECT, WorkflowClient.WORKFLOWSTATE_LOCKED, WorkflowClient.WORKFLOWSTATE_REPLICATED);
540 * Creates the document handler instance.
542 * @return the document handler
544 * @throws Exception the exception
546 private DocumentHandler createDocumentHandlerInstance() throws Exception {
547 docHandler = ServiceConfigUtils.createDocumentHandlerInstance(tenantBinding, serviceBinding);
549 // Create a default document filter
551 docHandler.setServiceContext(this);
552 DocumentFilter docFilter = docHandler.createDocumentFilter();
554 // If the context was created with query parameters,
555 // reflect the values of those parameters in the document filter
556 // to specify sort ordering, pagination, etc.
558 MultivaluedMap<String, String> queryParameters = this.getQueryParams();
559 if (queryParameters != null) {
560 docFilter.setSortOrder(queryParameters);
561 docFilter.setPagination(queryParameters);
562 String workflowWhereClause = buildWorkflowWhereClause(queryParameters);
563 if (workflowWhereClause != null) {
564 docFilter.appendWhereClause(workflowWhereClause, IQueryManager.SEARCH_QUALIFIER_AND);
568 docHandler.setDocumentFilter(docFilter);
574 * @see org.collectionspace.services.common.context.ServiceContext#getDocumentHandler()
577 public DocumentHandler getDocumentHandler() throws Exception {
578 DocumentHandler result = docHandler;
579 // create a new instance if one does not yet exist
580 if (result == null) {
581 result = createDocumentHandlerInstance();
587 public void setDocumentHandler(DocumentHandler handler) throws Exception {
588 if (handler != null) {
589 docHandler = handler;
594 * @see org.collectionspace.services.common.context.ServiceContext#getDocumentHanlder(javax.ws.rs.core.MultivaluedMap)
597 public DocumentHandler getDocumentHandler(MultivaluedMap<String, String> queryParams) throws Exception {
598 DocumentHandler result = getDocumentHandler();
599 DocumentFilter documentFilter = result.getDocumentFilter(); //to see results in debugger variables view
600 documentFilter.setPagination(queryParams);
605 * If this element is set in the service binding then use it otherwise
606 * assume that asserts are NOT disabled.
608 private boolean disableValidationAsserts() {
610 Boolean disableAsserts = getServiceBinding().isDisableAsserts();
611 result = (disableAsserts != null) ? disableAsserts : false;
616 * @see org.collectionspace.services.common.context.ServiceContext#getValidatorHandlers()
619 public List<ValidatorHandler<IT, OT>> getValidatorHandlers() throws Exception {
620 if (valHandlers != null) {
623 List<String> handlerClazzes = getServiceBinding().getValidatorHandler();
624 List<ValidatorHandler<IT, OT>> handlers = new ArrayList<ValidatorHandler<IT, OT>>(handlerClazzes.size());
625 ClassLoader tccl = Thread.currentThread().getContextClassLoader();
626 for (String clazz : handlerClazzes) {
627 clazz = clazz.trim();
629 Class<?> c = tccl.loadClass(clazz);
630 if (disableValidationAsserts() == false) {
631 // enable validation assertions
632 tccl.setClassAssertionStatus(clazz, true);
634 if (ValidatorHandler.class.isAssignableFrom(c)) {
635 handlers.add((ValidatorHandler) c.newInstance());
637 } catch (ClassNotFoundException e) {
638 String msg = String.format("Missing document validation handler: '%s'.", clazz);
640 logger.trace(msg, e);
643 valHandlers = handlers;
648 * If one doesn't already exist, use the default properties filename to load a set of properties that
649 * will be used to create an HTTP client to a CollectionSpace instance.
652 public AuthorityClient getClient() throws Exception {
653 AuthorityClient result = authorityClient;
655 if (authorityClient == null) {
656 result = authorityClient = getClient(CollectionSpaceClient.DEFAULT_CLIENT_PROPERTIES_FILENAME);
663 * Use the properties filename passed in to load the URL and credentials that will be used
664 * to create a new HTTP client.
666 * Never uses or resets the this.authorityClient member. Always creates a new HTTP client using
667 * the loaded properties.
670 * @see org.collectionspace.services.common.context.ServiceContext#getClient(java.lang.String)
673 public AuthorityClient getClient(String clientPropertiesFilename) throws Exception {
674 AuthorityClient result = null;
676 Properties inProperties = Tools.loadProperties(clientPropertiesFilename, true);
677 result = getClient(inProperties);
682 public AuthorityClient getClient(Properties inProperties) throws Exception {
683 AuthorityClient result = null;
685 String authorityClientClazz = getServiceBinding().getClientHandler();
686 ClassLoader tccl = Thread.currentThread().getContextClassLoader();
687 authorityClientClazz = authorityClientClazz.trim();
689 Class<?> c = tccl.loadClass(authorityClientClazz);
690 if (AuthorityClient.class.isAssignableFrom(c)) {
691 result = authorityClient = ((AuthorityClient) c.newInstance());
692 result.setClientProperties(inProperties);
694 logger.error(String.format("The service binding clientHandler class '%s' for '%s' service was not of type AuthorityClient.",
695 authorityClientClazz, this.getServiceName()));
697 } catch (ClassNotFoundException e) {
698 String msg = String.format("Missing document validation handler: '%s'.", authorityClientClazz);
700 logger.trace(msg, e);
707 public AuthorityClient getClient(RemoteClientConfig remoteClientConfig) throws Exception {
708 AuthorityClient result = null;
710 Properties properties = new Properties();
711 properties.setProperty(AuthorityClient.URL_PROPERTY, remoteClientConfig.getUrl());
712 properties.setProperty(AuthorityClient.USER_PROPERTY, remoteClientConfig.getUser());
713 properties.setProperty(AuthorityClient.PASSWORD_PROPERTY, remoteClientConfig.getPassword());
714 properties.setProperty(AuthorityClient.SSL_PROPERTY, remoteClientConfig.getSsl());
715 properties.setProperty(AuthorityClient.AUTH_PROPERTY, remoteClientConfig.getAuth());
716 properties.setProperty(AuthorityClient.TENANT_ID_PROPERTY, remoteClientConfig.getTenantId());
717 properties.setProperty(AuthorityClient.TENANT_NAME_PROPERTY, remoteClientConfig.getTenantName());
719 result = getClient(properties);
725 public void addValidatorHandler(ValidatorHandler<IT, OT> validator) throws Exception {
726 if (valHandlers == null) {
727 valHandlers = new ArrayList<ValidatorHandler<IT, OT>>();
729 valHandlers.add(validator);
733 * @see java.lang.Object#toString()
736 public String toString() {
737 StringBuilder msg = new StringBuilder();
738 msg.append("AbstractServiceContext [");
739 msg.append("service name=" + serviceBinding.getName() + " ");
740 msg.append("service version=" + serviceBinding.getVersion() + " ");
741 msg.append("tenant id=" + tenantBinding.getId() + " ");
742 msg.append("tenant name=" + tenantBinding.getName() + " ");
743 msg.append(tenantBinding.getDisplayName() + " ");
744 if (repositoryDomain != null) {
745 msg.append("tenant repository domain=" + repositoryDomain.getName());
747 for (Map.Entry<String, Object> entry : properties.entrySet()) {
748 msg.append("property name=" + entry.getKey() + " value=" + entry.getValue().toString());
751 return msg.toString();
755 * @see org.collectionspace.services.common.context.ServiceContext#getQueryParams()
758 public MultivaluedMap<String, String> getQueryParams() {
760 if (queryParams == null){
761 if (this.uriInfo != null){
762 queryParams = this.uriInfo.getQueryParameters();
765 if (queryParams == null){
766 queryParams = new org.jboss.resteasy.specimpl.MultivaluedMapImpl<String,String>();
768 return this.queryParams;
772 public MultivaluedMap<String, String> getQueryParamsPtr() {
773 return this.queryParams;
777 * @see org.collectionspace.services.common.context.ServiceContext#setQueryParams(javax.ws.rs.core.MultivaluedMap)
780 public void setQueryParams(MultivaluedMap<String, String> theQueryParams) {
781 this.queryParams = theQueryParams;
785 public void setUriInfo(UriInfo ui){
790 public UriInfo getUriInfo() {
795 * We expect the 'currentRepositorySession' member to be set only once per instance. Also, we expect only one open repository session
796 * per HTTP request. We'll log an error if we see more than one attempt to set a service context's current repo session.
798 * @see org.collectionspace.services.common.context.ServiceContext#setCurrentRepositorySession(java.lang.Object)
801 public void setCurrentRepositorySession(Object repoSession) throws Exception {
802 if (repoSession == null) {
803 String errMsg = "Setting a service context's repository session to null is not allowed.";
804 logger.error(errMsg);
805 throw new Exception(errMsg);
806 } else if (currentRepositorySession != null && currentRepositorySession != repoSession) {
807 String errMsg = "The current service context's repository session was replaced. This may cause unexpected behavior and/or data loss.";
808 logger.error(errMsg);
809 throw new Exception(errMsg);
812 currentRepositorySession = repoSession;
813 this.currentRepoSesssionRefCount++;
817 public void clearCurrentRepositorySession() {
818 if (this.currentRepoSesssionRefCount > 0) {
819 currentRepoSesssionRefCount--;
822 if (currentRepoSesssionRefCount == 0) {
823 this.currentRepositorySession = null;
828 public Object getCurrentRepositorySession() {
829 // TODO Auto-generated method stub
830 return currentRepositorySession;
834 public RepositoryDomainType getRepositoryDomain() {
835 return repositoryDomain;
839 public void setRepositoryDomain(RepositoryDomainType repositoryDomain) {
840 this.repositoryDomain = repositoryDomain;