View Javadoc

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.math.BigInteger;
24  import java.util.List;
25  
26  import org.apache.chemistry.opencmis.client.bindings.spi.BindingSession;
27  import org.apache.chemistry.opencmis.commons.data.ExtensionsData;
28  import org.apache.chemistry.opencmis.commons.data.RepositoryInfo;
29  import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
30  import org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionContainer;
31  import org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionList;
32  import org.apache.chemistry.opencmis.commons.server.CmisService;
33  import org.apache.chemistry.opencmis.commons.server.CmisServiceFactory;
34  import org.apache.chemistry.opencmis.commons.spi.RepositoryService;
35  
36  /**
37   * Repository Service local client.
38   */
39  public class RepositoryServiceImpl extends AbstractLocalService implements RepositoryService {
40  
41      /**
42       * Constructor.
43       */
44      public RepositoryServiceImpl(BindingSession session, CmisServiceFactory factory) {
45          setSession(session);
46          setServiceFactory(factory);
47      }
48  
49      @Override
50      public RepositoryInfo getRepositoryInfo(String repositoryId, ExtensionsData extension) {
51          CmisService service = getService(repositoryId);
52  
53          try {
54              if (stopBeforeService(service)) {
55                  return null;
56              }
57  
58              RepositoryInfo serviceResult = service.getRepositoryInfo(repositoryId, extension);
59  
60              if (stopAfterService(service)) {
61                  return null;
62              }
63  
64              return serviceResult;
65          } finally {
66              service.close();
67          }
68      }
69  
70      @Override
71      public List<RepositoryInfo> getRepositoryInfos(ExtensionsData extension) {
72          CmisService service = getService(null);
73  
74          try {
75              if (stopBeforeService(service)) {
76                  return null;
77              }
78  
79              List<RepositoryInfo> serviceResult = service.getRepositoryInfos(extension);
80  
81              if (stopAfterService(service)) {
82                  return null;
83              }
84  
85              return serviceResult;
86          } finally {
87              service.close();
88          }
89      }
90  
91      @Override
92      public TypeDefinition getTypeDefinition(String repositoryId, String typeId, ExtensionsData extension) {
93          CmisService service = getService(repositoryId);
94  
95          try {
96              if (stopBeforeService(service)) {
97                  return null;
98              }
99  
100             TypeDefinition serviceResult = service.getTypeDefinition(repositoryId, typeId, extension);
101 
102             if (stopAfterService(service)) {
103                 return null;
104             }
105 
106             return serviceResult;
107         } finally {
108             service.close();
109         }
110     }
111 
112     @Override
113     public TypeDefinitionList getTypeChildren(String repositoryId, String typeId, Boolean includePropertyDefinitions,
114             BigInteger maxItems, BigInteger skipCount, ExtensionsData extension) {
115         CmisService service = getService(repositoryId);
116 
117         try {
118             if (stopBeforeService(service)) {
119                 return null;
120             }
121 
122             TypeDefinitionList serviceResult = service.getTypeChildren(repositoryId, typeId,
123                     includePropertyDefinitions, maxItems, skipCount, extension);
124 
125             if (stopAfterService(service)) {
126                 return null;
127             }
128 
129             return serviceResult;
130         } finally {
131             service.close();
132         }
133     }
134 
135     @Override
136     public List<TypeDefinitionContainer> getTypeDescendants(String repositoryId, String typeId, BigInteger depth,
137             Boolean includePropertyDefinitions, ExtensionsData extension) {
138         CmisService service = getService(repositoryId);
139 
140         try {
141             if (stopBeforeService(service)) {
142                 return null;
143             }
144 
145             List<TypeDefinitionContainer> serviceResult = service.getTypeDescendants(repositoryId, typeId, depth,
146                     includePropertyDefinitions, extension);
147 
148             if (stopAfterService(service)) {
149                 return null;
150             }
151 
152             return serviceResult;
153         } finally {
154             service.close();
155         }
156     }
157 
158     @Override
159     public TypeDefinition createType(String repositoryId, TypeDefinition type, ExtensionsData extension) {
160         CmisService service = getService(repositoryId);
161 
162         try {
163             if (stopBeforeService(service)) {
164                 return null;
165             }
166 
167             TypeDefinition serviceResult = service.createType(repositoryId, type, extension);
168 
169             if (stopAfterService(service)) {
170                 return null;
171             }
172 
173             return serviceResult;
174         } finally {
175             service.close();
176         }
177     }
178 
179     @Override
180     public TypeDefinition updateType(String repositoryId, TypeDefinition type, ExtensionsData extension) {
181         CmisService service = getService(repositoryId);
182 
183         try {
184             if (stopBeforeService(service)) {
185                 return null;
186             }
187 
188             TypeDefinition serviceResult = service.updateType(repositoryId, type, extension);
189 
190             if (stopAfterService(service)) {
191                 return null;
192             }
193 
194             return serviceResult;
195         } finally {
196             service.close();
197         }
198     }
199 
200     @Override
201     public void deleteType(String repositoryId, String typeId, ExtensionsData extension) {
202         CmisService service = getService(repositoryId);
203 
204         try {
205             if (stopBeforeService(service)) {
206                 return;
207             }
208 
209             service.deleteType(repositoryId, typeId, extension);
210 
211             if (stopAfterService(service)) {
212                 return;
213             }
214         } finally {
215             service.close();
216         }
217     }
218 
219 }