KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > nava > informa > utils > manager > PersistenceManagerConfig


1 //
2
// Informa -- RSS Library for Java
3
// Copyright (c) 2002 by Niko Schmuck
4
//
5
// Niko Schmuck
6
// http://sourceforge.net/projects/informa
7
// mailto:niko_schmuck@users.sourceforge.net
8
//
9
// This library is free software.
10
//
11
// You may redistribute it and/or modify it under the terms of the GNU
12
// Lesser General Public License as published by the Free Software Foundation.
13
//
14
// Version 2.1 of the license should be included with this distribution in
15
// the file LICENSE. If the license is not included with this distribution,
16
// you may find a copy at the FSF web site at 'www.gnu.org' or 'www.fsf.org',
17
// or you may write to the Free Software Foundation, 675 Mass Ave, Cambridge,
18
// MA 02139 USA.
19
//
20
// This library is distributed in the hope that it will be useful,
21
// but WITHOUT ANY WARRANTY; without even the implied waranty of
22
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23
// Lesser General Public License for more details.
24
//
25
// $Id: PersistenceManagerConfig.java,v 1.2 2004/08/24 09:43:41 spyromus Exp $
26
//
27

28 package de.nava.informa.utils.manager;
29
30 /**
31  * Persistence manager configuration class. At application start it reads the value of
32  * JVM property <code>informa.persistencemanager</code> and
33  * instantiates class with given name as persistence manager. Class, mentioned in property
34  * should implement <code>PersistenceManagerIF</code> interface.
35  * <p/>
36  * Client application can get instance of persistence manager using
37  * <code>getPersistenceManager()</code> method. Single instance of persistence manager
38  * is shared.
39  *
40  * @author Aleksey Gureev (spyromus@noizeramp.com)
41  */

42 public final class PersistenceManagerConfig {
43
44   private static PersistenceManagerIF manager;
45
46   /** Initialize manager. */
47   static {
48     // Read the value of property.
49
final String JavaDoc propertyName = "informa.persistencemanager";
50     String JavaDoc className = System.getProperty(propertyName);
51     try {
52       setPersistenceManagerClassName(className);
53     } catch (Exception JavaDoc e) {
54       e.printStackTrace();
55     }
56   }
57
58   /**
59    * Hidden constructor of utility class.
60    */

61   private PersistenceManagerConfig() {
62   }
63
64   /**
65    * Sets the name of <code>PersistenceManagerIF</code> interface implementation class.
66    * If class is successfully located instance can be taken with
67    * <code>getPersistenceManager()</code> method.
68    *
69    * @param className name of implemenation class.
70    * @throws ClassNotFoundException if class not found.
71    * @throws IllegalAccessException if the class or its nullary constructor is not accessible.
72    * @throws InstantiationException if this Class represents an abstract class, an interface,
73    * an array class, a primitive type, or void;
74    * or if the class has no nullary constructor;
75    * or if the instantiation fails for some other reason.
76    */

77   public static void setPersistenceManagerClassName(String JavaDoc className)
78     throws ClassNotFoundException JavaDoc, IllegalAccessException JavaDoc, InstantiationException JavaDoc {
79
80     manager = null;
81
82     // If property is specified instantiate manager.
83
if (className != null) {
84       manager = (PersistenceManagerIF) Class.forName(className).newInstance();
85     }
86   }
87
88   /**
89    * Returns instance of persistence manager chosen by application.
90    *
91    * @return instance or NULL if manager is not instantiated.
92    */

93   public static PersistenceManagerIF getPersistenceManager() {
94     return manager;
95   }
96 }
97
Popular Tags