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