This project has retired. For details please refer to its Attic page.
CmisLocalSpi xref

1   /*
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   *
20   */
21  package org.apache.chemistry.opencmis.client.bindings.spi.local;
22  
23  import java.util.HashMap;
24  import java.util.Map;
25  
26  import org.apache.chemistry.opencmis.client.bindings.spi.BindingSession;
27  import org.apache.chemistry.opencmis.client.bindings.spi.CmisSpi;
28  import org.apache.chemistry.opencmis.commons.SessionParameter;
29  import org.apache.chemistry.opencmis.commons.exceptions.CmisConnectionException;
30  import org.apache.chemistry.opencmis.commons.server.CmisServiceFactory;
31  import org.apache.chemistry.opencmis.commons.spi.AclService;
32  import org.apache.chemistry.opencmis.commons.spi.DiscoveryService;
33  import org.apache.chemistry.opencmis.commons.spi.MultiFilingService;
34  import org.apache.chemistry.opencmis.commons.spi.NavigationService;
35  import org.apache.chemistry.opencmis.commons.spi.ObjectService;
36  import org.apache.chemistry.opencmis.commons.spi.PolicyService;
37  import org.apache.chemistry.opencmis.commons.spi.RelationshipService;
38  import org.apache.chemistry.opencmis.commons.spi.RepositoryService;
39  import org.apache.chemistry.opencmis.commons.spi.VersioningService;
40  import org.apache.commons.logging.Log;
41  import org.apache.commons.logging.LogFactory;
42  
43  /**
44   * * CMIS local SPI implementation.
45   */
46  public class CmisLocalSpi implements CmisSpi {
47  
48      private static final Log log = LogFactory.getLog(CmisLocalSpi.class);
49  
50      private final CmisServiceFactory factory;
51  
52      private final RepositoryService repositoryService;
53      private final NavigationService navigationService;
54      private final ObjectService objectService;
55      private final VersioningService versioningService;
56      private final DiscoveryService discoveryService;
57      private final MultiFilingService multiFilingService;
58      private final RelationshipService relationshipService;
59      private final PolicyService policyService;
60      private final AclService aclService;
61  
62      /**
63       * Constructor.
64       */
65      public CmisLocalSpi(BindingSession session) {
66          if (log.isDebugEnabled()) {
67              log.debug("Initializing local SPI...");
68          }
69  
70          // get the service factory class name
71          String serviceFactoryClassname = (String) session.get(SessionParameter.LOCAL_FACTORY);
72          if (serviceFactoryClassname == null) {
73              throw new CmisConnectionException("Factory class not set!");
74          }
75  
76          try {
77              // gather parameters from session
78              Map<String, String> parameters = new HashMap<String, String>();
79              for (String key : session.getKeys()) {
80                  Object value = session.get(key);
81                  if (value instanceof String) {
82                      parameters.put(key, (String) value);
83                  }
84              }
85  
86              // create and initialize factory
87              factory = (CmisServiceFactory) Class.forName(serviceFactoryClassname).newInstance();
88              factory.init(parameters);
89          } catch (Exception e) {
90              throw new CmisConnectionException("Factory cannot be created: " + e.getMessage(), e);
91          }
92  
93          repositoryService = new RepositoryServiceImpl(session, factory);
94          navigationService = new NavigationServiceImpl(session, factory);
95          objectService = new ObjectServiceImpl(session, factory);
96          versioningService = new VersioningServiceImpl(session, factory);
97          discoveryService = new DiscoveryServiceImpl(session, factory);
98          multiFilingService = new MultiFilingServiceImpl(session, factory);
99          relationshipService = new RelationshipServiceImpl(session, factory);
100         policyService = new PolicyServiceImpl(session, factory);
101         aclService = new AclServiceImpl(session, factory);
102     }
103 
104     public RepositoryService getRepositoryService() {
105         return repositoryService;
106     }
107 
108     public NavigationService getNavigationService() {
109         return navigationService;
110     }
111 
112     public ObjectService getObjectService() {
113         return objectService;
114     }
115 
116     public DiscoveryService getDiscoveryService() {
117         return discoveryService;
118     }
119 
120     public VersioningService getVersioningService() {
121         return versioningService;
122     }
123 
124     public MultiFilingService getMultiFilingService() {
125         return multiFilingService;
126     }
127 
128     public RelationshipService getRelationshipService() {
129         return relationshipService;
130     }
131 
132     public PolicyService getPolicyService() {
133         return policyService;
134     }
135 
136     public AclService getAclService() {
137         return aclService;
138     }
139 
140     public void clearAllCaches() {
141     }
142 
143     public void clearRepositoryCache(String repositoryId) {
144     }
145 
146     public void close() {
147         factory.destroy();
148     }
149 }