KickJava   Java API By Example, From Geeks To Geeks.

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


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.component.factory.ComponentFactory;
26
27
28 /**
29  * <p> This class holds information that describes a {@link LayoutComponent}
30  * type. It provides access to a {@link ComponentFactory} for
31  * instantiating an instance of a the <code>UIComponent</code> described
32  * by this descriptor. See the layout.dtd file for more information on
33  * how to declare types via XML.</p>
34  *
35  * @author Ken Paulsen (ken.paulsen@sun.com)
36  */

37 public class ComponentType implements java.io.Serializable JavaDoc {
38
39     /**
40      * <p> Constructor.</p>
41      */

42     public ComponentType(String JavaDoc id, String JavaDoc factoryClass) {
43     if (id == null) {
44         throw new NullPointerException JavaDoc("'id' cannot be null!");
45     }
46     if (factoryClass == null) {
47         throw new NullPointerException JavaDoc("'factoryClass' cannot be null!");
48     }
49     _id = id;
50     _factoryClass = factoryClass;
51     _factory = createFactory();
52     }
53
54
55     public String JavaDoc getId() {
56     return _id;
57     }
58
59
60     /**
61      * <p> This method provides access to the {@link ComponentFactory}.</p>
62      *
63      * @return The {@link ComponentFactory}.
64      */

65     public ComponentFactory getFactory() {
66     if (_factory == null) {
67         _factory = createFactory();
68     }
69     return _factory;
70     }
71
72
73     /**
74      * <p> This method creates a new factory.</p>
75      *
76      * @return The new {@link ComponentFactory}.
77      */

78     protected ComponentFactory createFactory() {
79     try {
80         Class JavaDoc cls = Class.forName(_factoryClass);
81         return (ComponentFactory) cls.newInstance();
82     } catch (ClassNotFoundException JavaDoc ex) {
83         throw new RuntimeException JavaDoc(ex);
84     } catch (InstantiationException JavaDoc ex) {
85         throw new RuntimeException JavaDoc(ex);
86     } catch (IllegalAccessException JavaDoc ex) {
87         throw new RuntimeException JavaDoc(ex);
88     }
89     }
90
91
92     /**
93      * <p> This is the id for the ComponentType.</p>
94      */

95     private String JavaDoc _id = null;
96
97
98     /**
99      * <p> This is a String className for the Factory.</p>
100      */

101     private String JavaDoc _factoryClass = null;
102
103
104     /**
105      * <p> The {@link ComponentFactory} that produces the desired
106      * <code>UIComponent</code>.</p>
107      */

108     private transient ComponentFactory _factory = null;
109 }
110
Popular Tags