View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.chemistry.opencmis.client.bindings.spi.browser;
20  
21  import org.apache.chemistry.opencmis.client.bindings.cache.TypeDefinitionCache;
22  import org.apache.chemistry.opencmis.client.bindings.impl.CmisBindingsHelper;
23  import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
24  import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
25  import org.apache.chemistry.opencmis.commons.impl.TypeCache;
26  
27  public class ClientTypeCacheImpl implements TypeCache {
28  
29      private final String repositoryId;
30      private final AbstractBrowserBindingService service;
31  
32      public ClientTypeCacheImpl(String repositoryId, AbstractBrowserBindingService service) {
33          this.repositoryId = repositoryId;
34          this.service = service;
35      }
36  
37      @Override
38      public TypeDefinition getTypeDefinition(String typeId) {
39  
40          TypeDefinitionCache cache = CmisBindingsHelper.getTypeDefinitionCache(service.getSession());
41  
42          TypeDefinition type = cache.get(repositoryId, typeId);
43          if (type == null) {
44              type = service.getTypeDefinitionInternal(repositoryId, typeId);
45              if (type != null) {
46                  cache.put(repositoryId, type);
47              }
48          }
49  
50          return type;
51      }
52  
53      @Override
54      public TypeDefinition reloadTypeDefinition(String typeId) {
55  
56          TypeDefinitionCache cache = CmisBindingsHelper.getTypeDefinitionCache(service.getSession());
57  
58          TypeDefinition type = service.getTypeDefinitionInternal(repositoryId, typeId);
59          if (type != null) {
60              cache.put(repositoryId, type);
61          }
62  
63          return type;
64      }
65  
66      @Override
67      public TypeDefinition getTypeDefinitionForObject(String objectId) {
68          // not used
69          assert false;
70          return null;
71      }
72  
73      @Override
74      public PropertyDefinition<?> getPropertyDefinition(String propId) {
75          assert false;
76          return null;
77      }
78  }