KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > config > serverbeans > validation > FrameHolderBuilder


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
24 package com.sun.enterprise.config.serverbeans.validation;
25
26 import java.util.Stack JavaDoc;
27 import org.xml.sax.Attributes JavaDoc;
28 import org.xml.sax.ContentHandler JavaDoc;
29 import org.xml.sax.ContentHandler JavaDoc;
30 import org.xml.sax.Locator JavaDoc;
31 import org.xml.sax.SAXException JavaDoc;
32 import org.xml.sax.XMLFilter JavaDoc;
33 import org.xml.sax.helpers.DefaultHandler JavaDoc;
34 import org.xml.sax.helpers.XMLFilterImpl JavaDoc;
35
36
37
38 /**
39  * FrameHolderBuilder.java
40  * Instances of the class are responsible for handling a SAX input
41  * stream to build a series of connected Frames to hold the
42  * system-property definitions found inside the XML.
43  *
44  * The Frames are connected by an inheritance pattern - it is this
45  * class that knows what that inheritance pattern is. As of the time
46  * of writing the pattern is:
47  * <verbatim>
48  * server [-> cluster] -> config -> domain
49  * </verbatim>
50  * With the cluster inheritance being optional, and only occuring when
51  * a cluster refers to a server. (So, a server might look as if its
52  * inheriting from one config, but a cluster can override the
53  * server's own settings and cause the server to inherit from the
54  * cluster and thus from some other config).
55  *
56  * The inheritance hierarchy between configs and domains is
57  * implicit. Between the other elements it is explicit, and is
58  * achieved through the XML attributes "config-ref", "server-ref".
59  *
60  * This system will function even if the XML is quite poorly formed,
61  * but the results will be peculiar, to say the least! The best
62  * debugging method is to extract each frame from the resulting
63  * FrameHolder and print it out - that gives you a pretty good picture
64  * of what the inheritance tree looks like (at least in terms of
65  * properties!).
66  *
67  * @author <a HREF="mailto:toby.h.ferguson@sun.com">Toby H Ferguson</a>
68  * @version $Revision: 1.3 $
69  */

70
71 // Upon revisiting this code I can't help but believe that this class
72
// should be called something slightly different. It appears to be an
73
// inheritance manager, and tightly tied into the Framer concept. I'm
74
// unsure why I built it this way!
75
public class FrameHolderBuilder extends Framer
76 {
77     protected final Frame getClusterFrame(Attributes JavaDoc atts){
78         final Frame f = super.getClusterFrame(atts);
79         inheritFromConfigPerhaps(f, atts);
80 // final String sr = atts.getValue(NAMESPACE, SERVER_REF);
81
// if (sr != null){
82
// frameHolder.getServerFrame(sr).inheritFrom(f);
83
// }
84
return f;
85     }
86
87     protected final void handleStartServerRefEvent(Attributes JavaDoc atts){
88         final String JavaDoc sr = atts.getValue(NAMESPACE, NAME);
89         if (sr != null){
90             frameHolder.getServerFrame(sr).inheritFrom(currentFrame());
91         }
92     }
93     
94     protected final Frame getConfigFrame(Attributes JavaDoc atts){
95         final Frame f = super.getConfigFrame(atts);
96         f.inheritFrom(frameHolder.getDomainFrame());
97         return f;
98     }
99     
100     protected final Frame getServerFrame(Attributes JavaDoc atts){
101         final Frame f = super.getServerFrame(atts);
102         return inheritFromConfigPerhaps(f, atts);
103     }
104
105     private final Frame inheritFromConfigPerhaps(Frame f, Attributes JavaDoc atts){
106         final String JavaDoc cr = atts.getValue(NAMESPACE, CONFIG_REF);
107         if (cr != null){
108             f.inheritFrom(frameHolder.getConfigFrame(cr));
109         }
110         return f;
111     }
112
113 }
114
115
116
117
Popular Tags