KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > bull > eclipse > jonas > utils > xml > ResourceRefDesc


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 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: Christophe Ney
22  * --------------------------------------------------------------------------
23  * $Id: ResourceRefDesc.java,v 1.1 2003/10/27 14:46:32 benoitf Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package com.bull.eclipse.jonas.utils.xml;
28
29
30
31 /**
32  * This class represents the description of a ResourceRef object
33  * @author Christophe Ney
34  * @author Florent Benoit
35  */

36 public class ResourceRefDesc {
37
38     /**
39      * To indicate that the application manage the authentication.
40      */

41     public static final int APPLICATION_AUTH = 0;
42
43     /**
44      * To indicate that the container manage the authentication.
45      */

46     public static final int CONTAINER_AUTH = 1;
47
48     /**
49      * List of all possible authentication.
50      */

51     private static final String JavaDoc[] AUTH = {"APPLICATION_AUTH", "CONTAINER_AUTH"};
52
53     /**
54      * The resource ref name.
55      */

56     private String JavaDoc name;
57
58     /**
59      * The resource ref type.
60      */

61     private Class JavaDoc type;
62
63     /**
64      * The resource ref authentication.
65      */

66     private int authentication;
67
68     /**
69      * The resource ref jndi name.
70      */

71     private String JavaDoc jndiName;
72
73     /**
74      * Construct a descriptor for the resource-ref and jonas-resource tags.
75      * @param classLoader the classloader for the classes.
76      * @param res the resource-ref resulting of the web.xml parsing.
77      * @param jRes the jonas-resource resulting of the jonas-web.xml parsing.
78      * @throws DeploymentDescException when missing information for
79      * creating the ResourceRefDesc.
80      */

81 // public ResourceRefDesc(ClassLoader classLoader,
82
// ResourceRef res, JonasResource jRes)
83
// throws DeploymentDescException {
84
// name = res.getResRefName();
85
// try {
86
// type = classLoader.loadClass(res.getResType());
87
// } catch (ClassNotFoundException e) {
88
// throw new DeploymentDescException("res-type class not found for resource-ref " + name, e);
89
// }
90
// String auth = res.getResAuth();
91
//
92
// if (auth.equals("Application")) {
93
// authentication = APPLICATION_AUTH;
94
// } else if (auth.equals("Container")) {
95
// authentication = CONTAINER_AUTH;
96
// } else {
97
// throw new DeploymentDescException("res-auth not valid for resource-ref " + name);
98
// }
99
// jndiName = jRes.getJndiName();
100
// }
101

102     /**
103      * Get resource ref. name
104      * @return Name of the resource ref.
105      */

106     public String JavaDoc getName() {
107         return name;
108     }
109
110     /**
111      * Get resource ref. type
112      * @return Class of the resource ref.
113      */

114     public Class JavaDoc getType() {
115         return type;
116     }
117
118     /**
119      * Get the authentication of the resource ref.
120      * @return Authentication value within APPLICATION_AUTH, CONTAINER_AUTH
121      */

122     public int getAuthentication() {
123         return authentication;
124     }
125     
126     /**
127      * Assessor for JDBC resource
128      * @return true if the resource is Jdbc compliant
129      */

130     public boolean isJdbc() {
131         Class JavaDoc jdbcClass = javax.sql.DataSource JavaDoc.class;
132         return jdbcClass.isAssignableFrom(type);
133     }
134
135     /**
136      * Get the jndi name of the resource ref.
137      * @return String representation of the JNDI name
138      */

139     public String JavaDoc getJndiName() {
140         return jndiName;
141     }
142     
143     /**
144      * String representation of the object for test purpose
145      * @return String representation of this object
146      */

147     public String JavaDoc toString() {
148         StringBuffer JavaDoc ret = new StringBuffer JavaDoc();
149         ret.append("\ngetName()=" + getName());
150         ret.append("\ngetType()=" + getType());
151         ret.append("\ngetAuthentication()=" + AUTH[getAuthentication()]);
152         ret.append("\nisJdbc()=" + new Boolean JavaDoc(isJdbc()).toString());
153         ret.append("\ngetJndiName()=" + getJndiName());
154         return ret.toString();
155     }
156 }
157
Popular Tags