KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jalisto > se > JalistoFactory


1 /*
2  * Jalisto - JAva LIght STOrage
3  * Copyright (C) 2000-2005 Xcalia http://www.xcalia.com
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
18  *
19  * Xcalia
20  * 71, rue Desnouettes
21  * 75014 Paris - France
22  * http://www.xcalia.com
23  */

24 package org.objectweb.jalisto.se;
25
26 import org.objectweb.jalisto.se.api.*;
27 import org.objectweb.jalisto.se.api.internal.Constants;
28 import org.objectweb.jalisto.se.api.internal.InternalFactory;
29 import org.objectweb.jalisto.se.api.query.FieldDescription;
30 import org.objectweb.jalisto.se.exception.JalistoException;
31 import org.objectweb.jalisto.se.impl.meta.ClassDescriptionImpl;
32 import org.objectweb.jalisto.se.impl.meta.FieldDescriptionImpl;
33 import org.objectweb.jalisto.se.impl.util.JalistoUtils;
34
35 import java.io.IOException JavaDoc;
36 import java.util.Properties JavaDoc;
37
38 /**
39  * JalistoFactory is used to create new connection to Jalisto, represented by a Session object.
40  * JalistoFactory need properties file path of the base to create Session instances.
41  */

42 public class JalistoFactory {
43
44     private static InternalFactory internalFactory;
45     private static String JavaDoc internalFactoryClass;
46
47     public static synchronized InternalFactory getInternalFactory(String JavaDoc propertiesFilePath) {
48         if (internalFactory == null) {
49             try {
50                 Properties JavaDoc props = new Properties JavaDoc();
51                 JalistoUtils.loadPropertiesFileIn(propertiesFilePath, props);
52                 internalFactoryClass = props.getProperty(JalistoProperties.INTERNAL_FACTORY_CLASS_KEY,
53                                                          Constants.INTERNALFACTORYCLASS_DIC);
54             } catch (IOException JavaDoc ioe) {
55                 throw new JalistoException("error during initial loading of "+propertiesFilePath, ioe);
56             }
57         }
58         return getInternalFactory();
59     }
60
61     public static synchronized InternalFactory getInternalFactory() {
62         if (internalFactory == null) {
63             try {
64                 internalFactory = (InternalFactory) Class.forName(internalFactoryClass).newInstance();
65                 internalFactory.init();
66                 internalFactory.setSelfInstance();
67             } catch (InstantiationException JavaDoc e) {
68                 throw new JalistoException("cannot instanciate "+internalFactoryClass, e);
69             } catch (IllegalAccessException JavaDoc e) {
70                 throw new JalistoException("cannot initialize "+internalFactoryClass, e);
71             } catch (ClassNotFoundException JavaDoc e) {
72                 throw new JalistoException("cannot find "+internalFactoryClass, e);
73             }
74         }
75         return internalFactory;
76     }
77
78     /**
79      * Create a new instance of Session interface, working on the base corresponding to the properties file specified.
80      *
81      * @param propertiesFilePath properties file path. This path can be absolute, relative to working directory, or can be the name of a file in the working classpath.
82      * @return Session the new Session instance just created
83      * @throws org.objectweb.jalisto.se.exception.JalistoException
84      * Thrown if a problem occured during initialisation of the session.
85      */

86     public static synchronized Session getSession(String JavaDoc propertiesFilePath) {
87         return getInternalFactory(propertiesFilePath).getSession(propertiesFilePath);
88     }
89
90     public static ClassDescription createClassDescription(String JavaDoc fullClassName) {
91         return new ClassDescriptionImpl(fullClassName);
92     }
93
94     public static FieldDescription createFieldDescription(String JavaDoc fieldName, MetaType type) {
95         return new FieldDescriptionImpl(fieldName, type);
96     }
97
98     public static void launchJMXServer(Session session) {
99         getInternalFactory().launchMBeanHtmlServer(session.getInternalSession().getProperties());
100     }
101
102     public static void launchJMXServer(String JavaDoc jalistoPropertiesPath) {
103         JalistoProperties properties = getInternalFactory(jalistoPropertiesPath).getProperties(jalistoPropertiesPath);
104         getInternalFactory().launchMBeanHtmlServer(properties);
105     }
106 }
107
Popular Tags