01: /******************************************************************
02: Copyright (c) 2005 Andy Jefferson and others. All rights reserved.
03: Licensed under the Apache License, Version 2.0 (the "License");
04: you may not use this file except in compliance with the License.
05: You may obtain a copy of the License at
06:
07: http://www.apache.org/licenses/LICENSE-2.0
08:
09: Unless required by applicable law or agreed to in writing, software
10: distributed under the License is distributed on an "AS IS" BASIS,
11: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: See the License for the specific language governing permissions and
13: limitations under the License.
14:
15:
16: Contributors:
17: ...
18: *****************************************************************/package org.jpox.store;
19:
20: import java.util.Collection;
21: import java.util.HashSet;
22: import java.util.StringTokenizer;
23:
24: import org.jpox.ClassLoaderResolver;
25: import org.jpox.store.exceptions.DatastoreInitialisationException;
26:
27: /**
28: * An auto-starter mechanism that uses a defined list of classes
29: * to be loaded at start.
30: *
31: * @version $Revision: 1.13 $
32: */
33: public class ClassesAutoStarter extends AbstractAutoStartMechanism {
34: /** Names of the classes to start with. */
35: protected String classNames;
36:
37: /**
38: * Constructor, taking the names of the classes to use.
39: * @param storeMgr The StoreManager managing the store that we are auto-starting.
40: * @param clr The ClassLoaderResolver
41: */
42: public ClassesAutoStarter(StoreManager storeMgr,
43: ClassLoaderResolver clr) {
44: this .classNames = storeMgr.getOMFContext()
45: .getPersistenceConfiguration().getAutoStartClassNames();
46: }
47:
48: /**
49: * Accessor for all auto start data for this starter.
50: * @return The class auto start data. Collection of StoreData elements
51: * @throws DatastoreInitialisationException
52: */
53: public Collection getAllClassData()
54: throws DatastoreInitialisationException {
55: Collection classes = new HashSet();
56: if (classNames == null) {
57: return classes;
58: }
59:
60: StringTokenizer tokeniser = new StringTokenizer(classNames, ",");
61: while (tokeniser.hasMoreTokens()) {
62: classes.add(new StoreData(tokeniser.nextToken().trim(),
63: null, StoreData.FCO_TYPE, null));
64: }
65:
66: return classes;
67: }
68:
69: /**
70: * Method to add a class to the starter.
71: * @param data The store data to add
72: */
73: public void addClass(StoreData data) {
74: // Do nothing. We are fixed from construction
75: }
76:
77: /**
78: * Method to remove a class from the starter
79: * @param className The name of the class to remove.
80: */
81: public void deleteClass(String className) {
82: // Do nothing. We are fixed from construction
83: }
84:
85: /**
86: * Method to remove all classes from the starter.
87: */
88: public void deleteAllClasses() {
89: // Do nothing. We are fixed from construction
90: }
91:
92: /**
93: * Method to give a descriptive name for the starter process.
94: * @return Description of the starter process.
95: */
96: public String getStorageDescription() {
97: return LOCALISER.msg("034100");
98: }
99: }
|