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

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.server.impl.dummy;
20  
21  import java.util.Map;
22  
23  import org.apache.chemistry.opencmis.commons.impl.server.AbstractServiceFactory;
24  import org.apache.chemistry.opencmis.commons.server.CallContext;
25  import org.apache.chemistry.opencmis.commons.server.CmisService;
26  import org.apache.commons.logging.Log;
27  import org.apache.commons.logging.LogFactory;
28  
29  /**
30   * Implementation of a repository factory without back-end for test purposes.
31   */
32  public class DummyServicesFactory extends AbstractServiceFactory {
33  
34      private static final String REPOSITORY_ID = "repository.id";
35      private static final String REPOSITORY_ID_DEFAULT = "test-rep";
36  
37      private static final String REPOSITORY_NAME = "repository.name";
38      private static final String REPOSITORY_NAME_DEFAULT = "Test Repository";
39  
40      private static final Log LOG = LogFactory.getLog(DummyServicesFactory.class.getName());
41  
42      private DummyService service;
43      private String id;
44      private String name;
45  
46      @Override
47      public void init(Map<String, String> parameters) {
48          // get the id
49          id = parameters.get(REPOSITORY_ID);
50          if ((id == null) || (id.trim().length() == 0)) {
51              id = REPOSITORY_ID_DEFAULT;
52          }
53  
54          // get the name
55          name = parameters.get(REPOSITORY_NAME);
56          if ((name == null) || (name.trim().length() == 0)) {
57              name = REPOSITORY_NAME_DEFAULT;
58          }
59  
60          // create a repository service
61          service = new DummyService(id, name);
62  
63          LOG.info("Initialized dummy repository '" + name + "' (" + id + ")");
64      }
65  
66      @Override
67      public void destroy() {
68          LOG.info("Destroyed dummy repository '" + name + "' (" + id + ")");
69      }
70  
71      @Override
72      public CmisService getService(CallContext context) {
73          return service;
74      }
75  }