KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > naming > ResourceRef


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18
19 package org.apache.naming;
20
21 import java.util.Enumeration JavaDoc;
22
23 import javax.naming.Context JavaDoc;
24 import javax.naming.RefAddr JavaDoc;
25 import javax.naming.Reference JavaDoc;
26 import javax.naming.StringRefAddr JavaDoc;
27
28 /**
29  * Represents a reference address to a resource.
30  *
31  * @author Remy Maucherat
32  * @version $Revision: 467222 $ $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $
33  */

34
35 public class ResourceRef
36     extends Reference JavaDoc {
37
38
39     // -------------------------------------------------------------- Constants
40

41
42     /**
43      * Default factory for this reference.
44      */

45     public static final String JavaDoc DEFAULT_FACTORY =
46         org.apache.naming.factory.Constants.DEFAULT_RESOURCE_FACTORY;
47
48
49     /**
50      * Description address type.
51      */

52     public static final String JavaDoc DESCRIPTION = "description";
53
54
55     /**
56      * Scope address type.
57      */

58     public static final String JavaDoc SCOPE = "scope";
59
60
61     /**
62      * Auth address type.
63      */

64     public static final String JavaDoc AUTH = "auth";
65
66
67     // ----------------------------------------------------------- Constructors
68

69
70     /**
71      * Resource Reference.
72      *
73      * @param resourceClass Resource class
74      * @param scope Resource scope
75      * @param auth Resource authetication
76      */

77     public ResourceRef(String JavaDoc resourceClass, String JavaDoc description,
78                        String JavaDoc scope, String JavaDoc auth) {
79         this(resourceClass, description, scope, auth, null, null);
80     }
81
82
83     /**
84      * Resource Reference.
85      *
86      * @param resourceClass Resource class
87      * @param scope Resource scope
88      * @param auth Resource authetication
89      */

90     public ResourceRef(String JavaDoc resourceClass, String JavaDoc description,
91                        String JavaDoc scope, String JavaDoc auth, String JavaDoc factory,
92                        String JavaDoc factoryLocation) {
93         super(resourceClass, factory, factoryLocation);
94         StringRefAddr JavaDoc refAddr = null;
95         if (description != null) {
96             refAddr = new StringRefAddr JavaDoc(DESCRIPTION, description);
97             add(refAddr);
98         }
99         if (scope != null) {
100             refAddr = new StringRefAddr JavaDoc(SCOPE, scope);
101             add(refAddr);
102         }
103         if (auth != null) {
104             refAddr = new StringRefAddr JavaDoc(AUTH, auth);
105             add(refAddr);
106         }
107     }
108
109
110     // ----------------------------------------------------- Instance Variables
111

112
113     // ------------------------------------------------------ Reference Methods
114

115
116     /**
117      * Retrieves the class name of the factory of the object to which this
118      * reference refers.
119      */

120     public String JavaDoc getFactoryClassName() {
121         String JavaDoc factory = super.getFactoryClassName();
122         if (factory != null) {
123             return factory;
124         } else {
125             factory = System.getProperty(Context.OBJECT_FACTORIES);
126             if (factory != null) {
127                 return null;
128             } else {
129                 return DEFAULT_FACTORY;
130             }
131         }
132     }
133
134
135     // --------------------------------------------------------- Public Methods
136

137
138     /**
139      * Return a String rendering of this object.
140      */

141     public String JavaDoc toString() {
142
143         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("ResourceRef[");
144         sb.append("className=");
145         sb.append(getClassName());
146         sb.append(",factoryClassLocation=");
147         sb.append(getFactoryClassLocation());
148         sb.append(",factoryClassName=");
149         sb.append(getFactoryClassName());
150         Enumeration JavaDoc refAddrs = getAll();
151         while (refAddrs.hasMoreElements()) {
152             RefAddr JavaDoc refAddr = (RefAddr JavaDoc) refAddrs.nextElement();
153             sb.append(",{type=");
154             sb.append(refAddr.getType());
155             sb.append(",content=");
156             sb.append(refAddr.getContent());
157             sb.append("}");
158         }
159         sb.append("]");
160         return (sb.toString());
161
162     }
163
164
165     // ------------------------------------------------------------- Properties
166

167
168 }
169
Popular Tags