From 41848e70855c8e21a755bd66dba9d7dbc3960a13 Mon Sep 17 00:00:00 2001 From: Glen Mazza Date: Wed, 25 Feb 2004 03:32:17 +0000 Subject: [PATCH] Removal of Visitor patterns from AbstractRenderer, moving of business logic from InlineArea to AbstractRenderer. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197368 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/fop/area/inline/Character.java | 10 -- .../apache/fop/area/inline/InlineArea.java | 13 -- .../fop/area/inline/InlineAreaVisitor.java | 103 ----------- .../apache/fop/area/inline/InlineParent.java | 10 -- .../org/apache/fop/area/inline/Leader.java | 10 -- .../org/apache/fop/area/inline/Space.java | 10 -- .../org/apache/fop/area/inline/TextArea.java | 10 -- .../org/apache/fop/area/inline/Viewport.java | 10 -- .../apache/fop/render/AbstractRenderer.java | 163 ++++++------------ .../apache/fop/render/xml/XMLRenderer.java | 4 +- 10 files changed, 55 insertions(+), 288 deletions(-) delete mode 100644 src/java/org/apache/fop/area/inline/InlineAreaVisitor.java diff --git a/src/java/org/apache/fop/area/inline/Character.java b/src/java/org/apache/fop/area/inline/Character.java index e1eacd682..d4da2711d 100644 --- a/src/java/org/apache/fop/area/inline/Character.java +++ b/src/java/org/apache/fop/area/inline/Character.java @@ -66,16 +66,6 @@ public class Character extends InlineArea { character = ch; } - /** - * Handle InlineAreaVisitor request by passing this back to it. - * - * @param visitor the InlineAreaVisitor wishing to process this. - * @see org.apache.fop.area.inline.InlineAreaVisitor - */ - public void acceptVisitor(InlineAreaVisitor visitor) { - visitor.serveVisitor(this); - } - /** * Get the character for this inline character area. * diff --git a/src/java/org/apache/fop/area/inline/InlineArea.java b/src/java/org/apache/fop/area/inline/InlineArea.java index 87e4207ff..7493c6451 100644 --- a/src/java/org/apache/fop/area/inline/InlineArea.java +++ b/src/java/org/apache/fop/area/inline/InlineArea.java @@ -58,8 +58,6 @@ import org.apache.fop.traits.BorderProps; * Inline Area * This area is for all inline areas that can be placed * in a line area. - * Extensions of this class should render themselves with the - * requested renderer. */ public class InlineArea extends Area { // int width; @@ -74,17 +72,6 @@ public class InlineArea extends Area { */ protected int verticalPosition = 0; - /** - * Handle a visitor (usually a renderer) for this inline area. - * Inline areas that extend this class are expected - * to pass themselves back to the visitor so that the visitor can process - * them, usually by rendering them. - * - * @param visitor the InlineAreaVisitor that will process this - */ - public void acceptVisitor(InlineAreaVisitor visitor) { - } - /** * Set the width of this inline area. * Currently sets the ipd. diff --git a/src/java/org/apache/fop/area/inline/InlineAreaVisitor.java b/src/java/org/apache/fop/area/inline/InlineAreaVisitor.java deleted file mode 100644 index 0a5911b39..000000000 --- a/src/java/org/apache/fop/area/inline/InlineAreaVisitor.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * $Id$ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modifica- - * tion, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * 3. The end-user documentation included with the redistribution, if any, must - * include the following acknowledgment: "This product includes software - * developed by the Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, if - * and wherever such third-party acknowledgments normally appear. - * - * 4. The names "FOP" and "Apache Software Foundation" must not be used to - * endorse or promote products derived from this software without prior - * written permission. For written permission, please contact - * apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", nor may - * "Apache" appear in their name, without prior written permission of the - * Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * ============================================================================ - * - * This software consists of voluntary contributions made by many individuals - * on behalf of the Apache Software Foundation and was originally created by - * James Tauber . For more information on the Apache - * Software Foundation, please see . - */ -package org.apache.fop.area.inline; - -/** - *

Implements the GoF Visitor design pattern to allow access to inline areas - * without knowing what subclass of InlineArea is being accessed. This is used - * primarily to keep the area tree classes isolated from any classes (typically - * renderers) that might need access to them.

- */ -public interface InlineAreaVisitor { - - /** - * Handle a visitor request to process an inline viewport. - * - * @param viewport The viewport area - */ - void serveVisitor(Viewport viewport); - - /** - * Handle a visitor request to process inline text. - * - * @param area The text area - */ - void serveVisitor(TextArea area); - - /** - * Handle a visitor request to process an inline parent area. - * - * @param ip The inline parent area - */ - void serveVisitor(InlineParent ip); - - /** - * Handle a visitor request to process an inline character. - * - * @param ch The inline character - */ - void serveVisitor(org.apache.fop.area.inline.Character ch); - - /** - * Handle a visitor request to process an inline space. - * - * @param space The inline space - */ - void serveVisitor(Space space); - - /** - * Handle a visitor request to process an inline leader area. - * - * @param area The inline leader area. - */ - void serveVisitor(Leader area); - -} diff --git a/src/java/org/apache/fop/area/inline/InlineParent.java b/src/java/org/apache/fop/area/inline/InlineParent.java index e8f93c3f8..dd830b53c 100644 --- a/src/java/org/apache/fop/area/inline/InlineParent.java +++ b/src/java/org/apache/fop/area/inline/InlineParent.java @@ -76,16 +76,6 @@ public class InlineParent extends InlineArea { public InlineParent() { } - /** - * Handle InlineAreaVisitor request by passing this back to it. - * - * @param visitor the InlineAreaVisitor wishing to process this. - * @see org.apache.fop.area.inline.InlineAreaVisitor - */ - public void acceptVisitor(InlineAreaVisitor visitor) { - visitor.serveVisitor(this); - } - /** * Override generic Area method. * diff --git a/src/java/org/apache/fop/area/inline/Leader.java b/src/java/org/apache/fop/area/inline/Leader.java index d535fc99b..bfa5f098c 100644 --- a/src/java/org/apache/fop/area/inline/Leader.java +++ b/src/java/org/apache/fop/area/inline/Leader.java @@ -108,15 +108,5 @@ public class Leader extends InlineArea { return ruleThickness; } - /** - * Handle InlineAreaVisitor request by passing this back to it. - * - * @param visitor the InlineAreaVisitor wishing to process this. - * @see org.apache.fop.area.inline.InlineAreaVisitor - */ - public void acceptVisitor(InlineAreaVisitor visitor) { - visitor.serveVisitor(this); - } - } diff --git a/src/java/org/apache/fop/area/inline/Space.java b/src/java/org/apache/fop/area/inline/Space.java index 92095eb82..a0549848a 100644 --- a/src/java/org/apache/fop/area/inline/Space.java +++ b/src/java/org/apache/fop/area/inline/Space.java @@ -56,14 +56,4 @@ package org.apache.fop.area.inline; */ public class Space extends InlineArea { - /** - * Handle InlineAreaVisitor request by passing this back to it. - * - * @param visitor the InlineAreaVisitor wishing to process this. - * @see org.apache.fop.area.inline.InlineAreaVisitor - */ - public void acceptVisitor(InlineAreaVisitor visitor) { - visitor.serveVisitor(this); - } - } diff --git a/src/java/org/apache/fop/area/inline/TextArea.java b/src/java/org/apache/fop/area/inline/TextArea.java index 00e90193d..c187264a6 100644 --- a/src/java/org/apache/fop/area/inline/TextArea.java +++ b/src/java/org/apache/fop/area/inline/TextArea.java @@ -67,16 +67,6 @@ public class TextArea extends InlineArea { public TextArea() { } - /** - * Handle InlineAreaVisitor request by passing this back to it. - * - * @param visitor the InlineAreaVisitor wishing to process this. - * @see org.apache.fop.area.inline.InlineAreaVisitor - */ - public void acceptVisitor(InlineAreaVisitor visitor) { - visitor.serveVisitor(this); - } - /** * Set the text string * diff --git a/src/java/org/apache/fop/area/inline/Viewport.java b/src/java/org/apache/fop/area/inline/Viewport.java index 6c01afb3f..aa454cf6a 100644 --- a/src/java/org/apache/fop/area/inline/Viewport.java +++ b/src/java/org/apache/fop/area/inline/Viewport.java @@ -124,16 +124,6 @@ public class Viewport extends InlineArea { return content; } - /** - * Handle InlineAreaVisitor request by passing this back to it. - * - * @param visitor the InlineAreaVisitor wishing to process this. - * @see org.apache.fop.area.inline.InlineAreaVisitor - */ - public void acceptVisitor(InlineAreaVisitor visitor) { - visitor.serveVisitor(this); - } - private void writeObject(java.io.ObjectOutputStream out) throws IOException { out.writeBoolean(contentPosition != null); diff --git a/src/java/org/apache/fop/render/AbstractRenderer.java b/src/java/org/apache/fop/render/AbstractRenderer.java index 5ed907c35..cfa2758d1 100644 --- a/src/java/org/apache/fop/render/AbstractRenderer.java +++ b/src/java/org/apache/fop/render/AbstractRenderer.java @@ -85,7 +85,6 @@ import org.apache.fop.area.inline.Container; import org.apache.fop.area.inline.ForeignObject; import org.apache.fop.area.inline.Image; import org.apache.fop.area.inline.InlineArea; -import org.apache.fop.area.inline.InlineAreaVisitor; import org.apache.fop.area.inline.InlineParent; import org.apache.fop.area.inline.Leader; import org.apache.fop.area.inline.Space; @@ -109,7 +108,7 @@ import org.apache.avalon.framework.configuration.ConfigurationException; * handle viewports. This keeps track of the current block and inline position. */ public abstract class AbstractRenderer extends AbstractLogEnabled - implements Renderer, Configurable, InlineAreaVisitor, Constants { + implements Renderer, Configurable, Constants { /** * user agent @@ -618,10 +617,61 @@ public abstract class AbstractRenderer extends AbstractLogEnabled for (int count = 0; count < children.size(); count++) { InlineArea inline = (InlineArea) children.get(count); - inline.acceptVisitor(this); + renderInlineArea(inline); } } + protected void renderInlineArea(InlineArea inlineArea) { + if (inlineArea instanceof TextArea) { + renderText((TextArea) inlineArea); + } else if (inlineArea instanceof InlineParent) { + renderInlineParent((InlineParent) inlineArea); + } else if (inlineArea instanceof Space) { + renderInlineSpace((Space) inlineArea); + } else if (inlineArea instanceof Character) { + renderCharacter((Character) inlineArea); + } else if (inlineArea instanceof Viewport) { + renderViewport((Viewport) inlineArea); + } else if (inlineArea instanceof Leader) { + renderLeader((Leader) inlineArea); + } + } + + + /** @see org.apache.fop.render.Renderer */ + public void renderCharacter(Character ch) { + currentBlockIPPosition += ch.getWidth(); + } + + /** @see org.apache.fop.render.Renderer */ + public void renderInlineSpace(Space space) { + // an inline space moves the inline progression position + // for the current block by the width or height of the space + // it may also have styling (only on this object) that needs + // handling + currentBlockIPPosition += space.getWidth(); + } + + /** @see org.apache.fop.render.Renderer */ + public void renderLeader(Leader area) { + currentBlockIPPosition += area.getWidth(); + } + + /** @see org.apache.fop.render.Renderer */ + public void renderText(TextArea text) { + currentBlockIPPosition += text.getWidth(); + } + + /** @see org.apache.fop.render.Renderer */ + public void renderInlineParent(InlineParent ip) { + int saveIP = currentBlockIPPosition; + Iterator iter = ip.getChildAreas().iterator(); + while (iter.hasNext()) { + renderInlineArea((InlineArea) iter.next()); + } + currentBlockIPPosition = saveIP + ip.getWidth(); + } + /** @see org.apache.fop.render.Renderer */ public void renderViewport(Viewport viewport) { Area content = viewport.getContent(); @@ -677,40 +727,6 @@ public abstract class AbstractRenderer extends AbstractLogEnabled // Some renderers (ex. Text) don't support foreign objects. } - /** @see org.apache.fop.render.Renderer */ - public void renderCharacter(Character ch) { - currentBlockIPPosition += ch.getWidth(); - } - - /** @see org.apache.fop.render.Renderer */ - public void renderInlineSpace(Space space) { - // an inline space moves the inline progression position - // for the current block by the width or height of the space - // it may also have styling (only on this object) that needs - // handling - currentBlockIPPosition += space.getWidth(); - } - - /** @see org.apache.fop.render.Renderer */ - public void renderLeader(Leader area) { - currentBlockIPPosition += area.getWidth(); - } - - /** @see org.apache.fop.render.Renderer */ - public void renderText(TextArea text) { - currentBlockIPPosition += text.getWidth(); - } - - /** @see org.apache.fop.render.Renderer */ - public void renderInlineParent(InlineParent ip) { - int saveIP = currentBlockIPPosition; - Iterator iter = ip.getChildAreas().iterator(); - while (iter.hasNext()) { - ((InlineArea) iter.next()).acceptVisitor(this); - } - currentBlockIPPosition = saveIP + ip.getWidth(); - } - /** * Set the default xml handler for the given mime type. * @param mime MIME type @@ -770,78 +786,5 @@ public abstract class AbstractRenderer extends AbstractLogEnabled + "No handler defined for XML: " + namespace); } } - - /** - * Render the specified Viewport. - * Required by InlineAreaVisitor interface, which is used to determine which - * InlineArea subclass should be rendered. - * - * @param viewport The Viewport area to be rendered - * @see org.apache.fop.area.inline.InlineAreaVisitor - */ - public void serveVisitor(Viewport viewport) { - renderViewport(viewport); - } - - /** - * Render the specified Text. - * Required by InlineAreaVisitor interface, which is used to determine which - * InlineArea subclass should be rendered. - * - * @param area The Text area to be rendered - * @see org.apache.fop.area.inline.InlineAreaVisitor - */ - public void serveVisitor(TextArea area) { - renderText(area); - } - - /** - * Render the specified InlineParent. - * Required by InlineAreaVisitor interface, which is used to determine which - * InlineArea subclass should be rendered. - * - * @param ip The InlineParent area to be rendered - * @see org.apache.fop.area.inline.InlineAreaVisitor - */ - public void serveVisitor(InlineParent ip) { - renderInlineParent(ip); - } - - /** - * Render the specified Character. - * Required by InlineAreaVisitor interface, which is used to determine which - * InlineArea subclass should be rendered. - * - * @param ch The Character area to be rendered - * @see org.apache.fop.area.inline.InlineAreaVisitor - */ - public void serveVisitor(org.apache.fop.area.inline.Character ch) { - renderCharacter(ch); - } - - /** - * Render the specified Space. - * Required by InlineAreaVisitor interface, which is used to determine which - * InlineArea subclass should be rendered. - * - * @param space The Space area to be rendered - * @see org.apache.fop.area.inline.InlineAreaVisitor - */ - public void serveVisitor(Space space) { - renderInlineSpace(space); - } - - /** - * Render the specified Leader. - * Required by InlineAreaVisitor interface, which is used to determine which - * InlineArea subclass should be rendered. - * - * @param area The Leader area to be rendered - * @see org.apache.fop.area.inline.InlineAreaVisitor - */ - public void serveVisitor(Leader area) { - renderLeader(area); - } - } diff --git a/src/java/org/apache/fop/render/xml/XMLRenderer.java b/src/java/org/apache/fop/render/xml/XMLRenderer.java index 80e48d98d..0950e5dad 100644 --- a/src/java/org/apache/fop/render/xml/XMLRenderer.java +++ b/src/java/org/apache/fop/render/xml/XMLRenderer.java @@ -272,7 +272,7 @@ public class XMLRenderer extends AbstractRenderer { for (int count = 0; count < children.size(); count++) { InlineArea inline = (InlineArea) children.get(count); - inline.acceptVisitor(this); + renderInlineArea(inline); } writeEndTag(""); @@ -476,7 +476,7 @@ public class XMLRenderer extends AbstractRenderer { } writeStartTag(""); super.renderInlineParent(ip); - writeEndTag(""); + writeEndTag(""); } /** -- 2.39.5