1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.chemistry.opencmis.client.bindings.impl;
20
21 import java.lang.reflect.Constructor;
22
23 import org.apache.chemistry.opencmis.client.bindings.spi.BindingSession;
24 import org.apache.chemistry.opencmis.client.bindings.spi.CmisSpi;
25 import org.apache.chemistry.opencmis.commons.SessionParameter;
26 import org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException;
27 import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
28 import org.apache.chemistry.opencmis.commons.spi.AuthenticationProvider;
29
30
31
32
33
34 public final class CmisBindingsHelper {
35
36 public static final String REPOSITORY_INFO_CACHE = "org.apache.chemistry.opencmis.binding.repositoryInfoCache";
37 public static final String TYPE_DEFINTION_CACHE = "org.apache.chemistry.opencmis.binding.typeDefintionCache";
38 public static final String SPI_OBJECT = "org.apache.chemistry.opencmis.binding.spi.object";
39 public static final String AUTHENTICATION_PROVIDER_OBJECT = "org.apache.chemistry.opencmis.binding.auth.object";
40 public static final String ACCEPT_LANGUAGE = "org.apache.chemistry.opencmis.binding.acceptLanguage";
41
42
43
44
45 private CmisBindingsHelper() {
46 }
47
48
49
50
51
52
53
54
55
56
57
58 public static CmisSpi getSPI(BindingSession session) {
59
60 CmisSpi spi = (CmisSpi) session.get(SPI_OBJECT);
61 if (spi != null) {
62 return spi;
63 }
64
65 session.writeLock();
66 try {
67
68 spi = (CmisSpi) session.get(SPI_OBJECT);
69 if (spi != null) {
70 return spi;
71 }
72
73
74 try {
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) {
79 throw e;
80 } catch (Exception e) {
81 throw new CmisRuntimeException("SPI cannot be initialized: " + e.getMessage(), e);
82 }
83
84
85 session.put(SPI_OBJECT, spi, true);
86 } finally {
87 session.writeUnlock();
88 }
89
90 return spi;
91 }
92
93
94
95
96
97 public static AuthenticationProvider getAuthenticationProvider(BindingSession session) {
98 return (AuthenticationProvider) session.get(AUTHENTICATION_PROVIDER_OBJECT);
99 }
100
101
102
103
104 public static RepositoryInfoCache getRepositoryInfoCache(BindingSession session) {
105 return (RepositoryInfoCache) session.get(REPOSITORY_INFO_CACHE);
106 }
107
108
109
110
111 public static TypeDefinitionCache getTypeDefinitionCache(BindingSession session) {
112 return (TypeDefinitionCache) session.get(TYPE_DEFINTION_CACHE);
113 }
114 }