KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > jsfext > layout > descriptor > Resource


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.tools.jsfext.layout.descriptor;
24
25 import com.sun.enterprise.tools.jsfext.resource.ResourceFactory;
26
27
28 /**
29  * <p> This class holds information that describes a Resource. It
30  * provides access to a {@link ResourceFactory} for obtaining the
31  * actual Resource object described by this descriptor. See the
32  * layout.dtd file for more information on how to define a Resource
33  * via XML. The LayoutDefinition will add all defined Resources to
34  * the request scope for easy access (including via JSF EL).</p>
35  *
36  * @author Ken Paulsen (ken.paulsen@sun.com)
37  */

38 public class Resource implements java.io.Serializable JavaDoc {
39
40     /**
41      * <p> This is the id for the Resource.</p>
42      */

43     private String JavaDoc _id = null;
44
45     /**
46      * <p> This holds "extraInfo" for the Resource, such as a ResourceBundle
47      * baseName.</p>
48      */

49     private String JavaDoc _extraInfo = null;
50
51
52     /**
53      * <p> This is a String className for the Factory.</p>
54      */

55     private String JavaDoc _factoryClass = null;
56
57
58     /**
59      * <p> The Factory that produces the desired <code>UIComponent</code>.</p>
60      */

61     private transient ResourceFactory _factory = null;
62
63
64     /**
65      * <p> Constructor.</p>
66      */

67     public Resource(String JavaDoc id, String JavaDoc extraInfo, String JavaDoc factoryClass) {
68     if (id == null) {
69         throw new NullPointerException JavaDoc("'id' cannot be null!");
70     }
71     if (factoryClass == null) {
72         throw new NullPointerException JavaDoc("'factoryClass' cannot be null!");
73     }
74     _id = id;
75     _extraInfo = extraInfo;
76     _factoryClass = factoryClass;
77     _factory = createFactory();
78     }
79
80
81     /**
82      * <p> Accessor method for ID. This is the key the resource will be stored
83      * under in the Request scope.</p>
84      */

85     public String JavaDoc getId() {
86     return _id;
87     }
88
89     /**
90      * <p> This holds "extraInfo" for the Resource, such as a
91      * <code>ResourceBundle</code> baseName.</p>
92      */

93     public String JavaDoc getExtraInfo() {
94     return _extraInfo;
95     }
96
97
98     /**
99      * <p> This method provides access to the {@link ResourceFactory}.</p>
100      *
101      * @return The {@link ResourceFactory}.
102      */

103     public ResourceFactory getFactory() {
104     if (_factory == null) {
105         _factory = createFactory();
106     }
107     return _factory;
108     }
109
110     /**
111      * <p> This method creates a new {@link ResourceFactory}.</p>
112      *
113      * @return The new {@link ResourceFactory}.
114      */

115     protected ResourceFactory createFactory() {
116     try {
117         Class JavaDoc cls = Class.forName(_factoryClass);
118         return (ResourceFactory) cls.newInstance();
119     } catch (ClassNotFoundException JavaDoc ex) {
120         throw new RuntimeException JavaDoc(ex);
121     } catch (InstantiationException JavaDoc ex) {
122         throw new RuntimeException JavaDoc(ex);
123     } catch (IllegalAccessException JavaDoc ex) {
124         throw new RuntimeException JavaDoc(ex);
125     }
126     }
127 }
128
Popular Tags