KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > security > realm > factory > JResourceDSFactory


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999-2004 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or 1any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * Initial developer: Florent BENOIT
22  * --------------------------------------------------------------------------
23  * $Id: JResourceDSFactory.java,v 1.4 2004/05/25 15:13:28 benoitf Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package org.objectweb.jonas.security.realm.factory;
28
29 //import java
30
import java.util.Hashtable JavaDoc;
31
32 //import javax
33
import javax.naming.Context JavaDoc;
34 import javax.naming.Name JavaDoc;
35 import javax.naming.Reference JavaDoc;
36
37 //import objectweb.util
38
import org.objectweb.util.monolog.api.BasicLevel;
39
40 /**
41  * This class provides an implementation of a JResource Datasource factory for
42  * managing users
43  * @author Florent Benoit
44  */

45 public class JResourceDSFactory extends JResourceFactory {
46
47     /**
48      * The Java type for which this factory knows how to create objects.
49      */

50     private static final String JavaDoc FACTORY_TYPE = "org.objectweb.jonas.security.realm.factory.JResourceDS";
51
52     /**
53      * Creates a javax.mail.Session object using the location or reference
54      * information specified.
55      * @param obj the possibly null object containing location or reference
56      * information that can be used in creating an object.
57      * @param name the name of this object relative to nameCtx, or null if no
58      * name is specified.
59      * @param nameCtx the context relative to which the name parameter is
60      * specified, or null if name is relative to the default initial
61      * context.
62      * @param environment the possibly null environment that is used in creating
63      * the object.
64      * @return a newly created javax.mail.Session object with the specific
65      * configuration; null if an object cannot be created.
66      * @throws Exception if this object factory encountered an exception while
67      * attempting to create an object, and no other object factories are
68      * to be tried.
69      */

70     public Object JavaDoc getObjectInstance(Object JavaDoc obj, Name JavaDoc name, Context JavaDoc nameCtx, Hashtable JavaDoc environment) throws Exception JavaDoc {
71
72         //Get the reference
73
Reference JavaDoc ref = (Reference JavaDoc) obj;
74
75         //Get the class name
76
String JavaDoc clname = ref.getClassName();
77
78         //Check the class name
79
if (!ref.getClassName().equals(FACTORY_TYPE)) {
80             getLogger().log(BasicLevel.ERROR, "Cannot create object : required type is '" + FACTORY_TYPE
81                     + "', but found type is '" + clname + "'.");
82             return (null);
83         }
84
85         String JavaDoc jResName = (String JavaDoc) ref.get("name").getContent();
86         String JavaDoc dsName = (String JavaDoc) ref.get("dsName").getContent();
87         String JavaDoc userTable = (String JavaDoc) ref.get("userTable").getContent();
88         String JavaDoc userTableUsernameCol = (String JavaDoc) ref.get("userTableUsernameCol").getContent();
89         String JavaDoc userTablePasswordCol = (String JavaDoc) ref.get("userTablePasswordCol").getContent();
90         String JavaDoc roleTable = (String JavaDoc) ref.get("roleTable").getContent();
91         String JavaDoc roleTableUsernameCol = (String JavaDoc) ref.get("roleTableUsernameCol").getContent();
92         String JavaDoc roleTableRolenameCol = (String JavaDoc) ref.get("roleTableRolenameCol").getContent();
93         String JavaDoc userPrincipalsQuery = (String JavaDoc) ref.get("userPrincipalsQuery").getContent();
94         String JavaDoc userRolesQuery = (String JavaDoc) ref.get("userRolesQuery").getContent();
95         String JavaDoc algorithm = (String JavaDoc) ref.get("algorithm").getContent();
96
97         // Create and return a new object
98
JResourceDS jResourceDS = new JResourceDS();
99         jResourceDS.setName(jResName);
100         jResourceDS.setDsName(dsName);
101         jResourceDS.setUserTable(userTable);
102         jResourceDS.setUserTableUsernameCol(userTableUsernameCol);
103         jResourceDS.setUserTablePasswordCol(userTablePasswordCol);
104         jResourceDS.setRoleTable(roleTable);
105         jResourceDS.setRoleTableUsernameCol(roleTableUsernameCol);
106         jResourceDS.setRoleTableRolenameCol(roleTableRolenameCol);
107         jResourceDS.setUserPrincipalsQuery(userPrincipalsQuery);
108         jResourceDS.setUserRolesQuery(userRolesQuery);
109         jResourceDS.setAlgorithm(algorithm);
110
111         return jResourceDS;
112     }
113
114 }
Popular Tags