This project has retired. For details please refer to its Attic page.
StoreManagerFactory 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.inmemory.storedobj.impl;
20  
21  import org.apache.chemistry.opencmis.inmemory.storedobj.api.StoreManager;
22  import org.apache.commons.logging.Log;
23  import org.apache.commons.logging.LogFactory;
24  
25  /**
26   * create objects that are stored in a persistent store
27   *
28   * @author Jens
29   */
30  public class StoreManagerFactory {
31  
32      private static final Log log = LogFactory.getLog(StoreManagerFactory.class);
33  
34      private StoreManagerFactory() {
35      }
36  
37      public static StoreManager createInstance(String className) {
38  
39          Class<?> clazz = null;
40          try {
41              clazz = Class.forName(className);
42          } catch (ClassNotFoundException e) {
43              String msg = "Failed to create StoredObjectCreator, class " + className + " does not exist.";
44              log.error(msg, e);
45              e.printStackTrace();
46              throw new RuntimeException(msg, e);
47          }
48  
49          Object obj = null;
50          try {
51              obj = clazz.newInstance();
52          } catch (InstantiationException e) {
53              log.error("Failed to create StoredObjectCreator from class " + className, e);
54              e.printStackTrace();
55          } catch (IllegalAccessException e) {
56              log.error("Failed to create StoredObjectCreator from class " + className, e);
57              e.printStackTrace();
58          }
59  
60          if (obj instanceof StoreManager) {
61              return (StoreManager) obj;
62          } else {
63              log.error("Failed to create StoredObjectCreator, class " + className
64                      + " does not implement interface StoredObjectCreator");
65              return null;
66          }
67      }
68  
69  }