KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_lib > deployment > api > 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.3 2004/07/21 11:37:34 joaninh Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package org.objectweb.jonas_lib.deployment.api;
28
29 import org.objectweb.jonas_lib.deployment.xml.ResourceRef;
30 import org.objectweb.jonas_lib.deployment.xml.JonasResource;
31
32
33 /**
34  * This class represents the description of a ResourceRef object
35  * @author Christophe Ney
36  * @author Florent Benoit
37  */

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

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

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

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

58     private String JavaDoc name;
59
60     /**
61      * The resource ref type name.
62      */

63     private String JavaDoc typeName;
64
65     /**
66      * The resource ref authentication.
67      */

68     private int authentication;
69
70     /**
71      * The resource ref jndi name.
72      */

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

83     public ResourceRefDesc(ClassLoader JavaDoc classLoader,
84                            ResourceRef res, JonasResource jRes)
85         throws DeploymentDescException {
86         name = res.getResRefName();
87         typeName = new String JavaDoc(res.getResType());
88         String JavaDoc auth = res.getResAuth();
89
90         if (auth.equals("Application")) {
91             authentication = APPLICATION_AUTH;
92         } else if (auth.equals("Container")) {
93             authentication = CONTAINER_AUTH;
94         } else {
95             throw new DeploymentDescException("res-auth not valid for resource-ref " + name);
96         }
97         jndiName = jRes.getJndiName();
98     }
99
100     /**
101      * Get resource ref. name
102      * @return Name of the resource ref.
103      */

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

112     public String JavaDoc getTypeName() {
113         return typeName;
114     }
115
116     /**
117      * Get the authentication of the resource ref.
118      * @return Authentication value within APPLICATION_AUTH, CONTAINER_AUTH
119      */

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

128     public boolean isJdbc() {
129         return "javax.sql.DataSource".equals(typeName);
130     }
131
132     /**
133      * Get the jndi name of the resource ref.
134      * @return String representation of the JNDI name
135      */

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

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