This project has retired. For details please refer to its
Attic page.
CmisBindingsHelper xref
1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing,13 * software distributed under the License is distributed on an14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15 * KIND, either express or implied. See the License for the16 * specific language governing permissions and limitations17 * under the License.18 */19package org.apache.chemistry.opencmis.client.bindings.impl;
2021import java.lang.reflect.Constructor;
2223import org.apache.chemistry.opencmis.client.bindings.spi.BindingSession;
24import org.apache.chemistry.opencmis.client.bindings.spi.CmisSpi;
25import org.apache.chemistry.opencmis.commons.SessionParameter;
26import org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException;
27import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
28import org.apache.chemistry.opencmis.commons.spi.AuthenticationProvider;
2930/**31 * A collection of static methods that are used in multiple places within the32 * bindings implementation.33 */34publicfinalclassCmisBindingsHelper {
3536publicstaticfinal String REPOSITORY_INFO_CACHE = "org.apache.chemistry.opencmis.binding.repositoryInfoCache";
37publicstaticfinal String TYPE_DEFINTION_CACHE = "org.apache.chemistry.opencmis.binding.typeDefintionCache";
38publicstaticfinal String SPI_OBJECT = "org.apache.chemistry.opencmis.binding.spi.object";
39publicstaticfinal String AUTHENTICATION_PROVIDER_OBJECT = "org.apache.chemistry.opencmis.binding.auth.object";
40publicstaticfinal String ACCEPT_LANGUAGE = "org.apache.chemistry.opencmis.binding.acceptLanguage";
4142/**43 * Private constructor.44 */45privateCmisBindingsHelper() {
46 }
4748/**49 * Gets the SPI object for the given session. If there is already a SPI50 * object in the session it will be returned. If there is no SPI object it51 * will be created and put into the session.52 * 53 * @param session54 * the session object55 * 56 * @return the SPI object57 */58publicstaticCmisSpi getSPI(BindingSession session) {
59// fetch from session60CmisSpi spi = (CmisSpi) session.get(SPI_OBJECT);
61if (spi != null) {
62return spi;
63 }
6465 session.writeLock();
66try {
67// try again68 spi = (CmisSpi) session.get(SPI_OBJECT);
69if (spi != null) {
70return spi;
71 }
7273// ok, we have to create it...74try {
75 String spiName = (String) session.get(SessionParameter.BINDING_SPI_CLASS);
76 Constructor<?> c = Class.forName(spiName).getConstructor(BindingSession.class);
77 spi = (CmisSpi) c.newInstance(session);
78 } catch (CmisBaseException e) {
79throw e;
80 } catch (Exception e) {
81thrownew CmisRuntimeException("SPI cannot be initialized: " + e.getMessage(), e);
82 }
8384// we have a SPI object -> put it into the session85 session.put(SPI_OBJECT, spi, true);
86 } finally {
87 session.writeUnlock();
88 }
8990return spi;
91 }
9293/**94 * Returns the authentication provider from the session or <code>null</code>95 * if no authentication provider is set.96 */97publicstatic AuthenticationProvider getAuthenticationProvider(BindingSession session) {
98return (AuthenticationProvider) session.get(AUTHENTICATION_PROVIDER_OBJECT);
99 }
100101/**102 * Returns the repository info cache from the session.103 */104publicstaticRepositoryInfoCache getRepositoryInfoCache(BindingSession session) {
105return (RepositoryInfoCache) session.get(REPOSITORY_INFO_CACHE);
106 }
107108/**109 * Returns the type definition cache from the session.110 */111publicstaticTypeDefinitionCache getTypeDefinitionCache(BindingSession session) {
112return (TypeDefinitionCache) session.get(TYPE_DEFINTION_CACHE);
113 }
114 }