KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > core > comp > renderer > DOMComponentRenderer


1 /*
2  * Copyright (C) 2003 Christian Cryder [christianc@granitepeaks.com]
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * $Id: DOMComponentRenderer.java,v 1.10 2004/02/01 05:16:27 christianc Exp $
19  */

20 package org.enhydra.barracuda.core.comp.renderer;
21
22 import java.util.*;
23 import org.w3c.dom.*;
24 import org.w3c.dom.html.*;
25
26 import org.apache.log4j.Logger;
27
28 import org.enhydra.barracuda.core.comp.*;
29 import org.enhydra.barracuda.core.util.dom.*;
30 import org.enhydra.barracuda.plankton.*;
31
32 /**
33  * This interface defines the methods needed to implement a Renderer.
34  */

35 public abstract class DOMComponentRenderer implements Renderer {
36
37     /**
38      * The purpose of this method is for a renderer to provide
39      * a default node (if none exists). This is essentially where you
40      * would say "if I need to render myself, and I'm not actually bound
41      * to anything, what should the default markup look like if I had
42      * to create it."
43      *
44      * In most cases, its perfectly fine to just throw an
45      * UnsupportedFormatException (indicating that there is no default). The
46      * only renderer that currently implements this method is the
47      * HTMLLinkRenderer.
48      *
49      * @param doc the master Document which can be used to create elements
50      * from scratch
51      * @param comp the component that we're dealing with for the current request
52      * @param vc the view context for the current request
53      * @return a default node (created from scratch)
54      * @throws UnsupportedFormatException if the renderer has no default node
55      */

56 //csc_110501.1 public Node createDefaultNode(Document doc, ViewContext vc) throws UnsupportedFormatException;
57
public Node createDefaultNode(Document doc, BComponent comp, ViewContext vc) throws UnsupportedFormatException { //csc_110501.1
58
throw new UnsupportedFormatException("Cannot create default node");
59     }
60
61     /**
62      * The purpose of this method is to add a child to a parent. In many
63      * cases, this method is used to ensure that the resulting markup is
64      * valid, by inserting the appropriate markup in between the child and
65      * the parent. In many cases, the generic Component renderer will be the
66      * only renderer that actually implements this method.
67      *
68      * @param parent the parent Node
69      * @param child the child Node
70      * @return the resulting parent node
71      * @throws InvalidNodeException if teh child cannot be added to the parent
72      */

73     public Node addChildToParent(Node parent, Node child) throws InvalidNodeException {
74         //eliminate the obvious
75
if (parent==null || child==null) throw new InvalidNodeException("Invalid node: cannot add child:"+child+" to parent:"+parent);
76
77         //make any adjustments specific to the markup
78
//(--n/a--)
79

80         //now add the child in
81
if (child!=null) parent.appendChild(child);
82         
83         //return the parent
84
return parent;
85     }
86
87     /**
88      * This method should actually render the data from the component
89      * into the view, taking into consideration the specified ViewContext.
90      * Generally, every renderer will implement this method.
91      *
92      * @param comp the component to be rendered
93      * @param view the view the component should be rendered in
94      * @param vc the view context
95      * @throws RenderException if unable to render the component in the
96      * specified view
97      */

98     public void renderComponent(BComponent comp, View view, ViewContext vc) throws RenderException {
99         //plain jane components don't have any rendering by default
100
}
101
102
103     /**
104      * This is just a debugging method to make it easy to show
105      * the interfaces of a view being rendered...
106      */

107     public void showNodeInterfaces(View view, Logger extLogger) {
108         //get the node
109
Node node = view.getNode();
110         if (extLogger.isDebugEnabled()) extLogger.debug("node [id="+DOMUtil.getID(node)+"] implements the following interfaces:");
111         Iterator it = Classes.getAllInterfaces(node).iterator();
112         while (it.hasNext()) {
113             Object JavaDoc o = it.next();
114             if (extLogger.isDebugEnabled()) extLogger.debug(" "+o.toString());
115         }
116     }
117 }
Popular Tags