001: /*
002: * Container.java
003: *
004: * Version: $Revision: 1.1 $
005: *
006: * Date: $Date: 2006/07/05 21:40:01 $
007: *
008: * Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
009: * Institute of Technology. All rights reserved.
010: *
011: * Redistribution and use in source and binary forms, with or without
012: * modification, are permitted provided that the following conditions are
013: * met:
014: *
015: * - Redistributions of source code must retain the above copyright
016: * notice, this list of conditions and the following disclaimer.
017: *
018: * - Redistributions in binary form must reproduce the above copyright
019: * notice, this list of conditions and the following disclaimer in the
020: * documentation and/or other materials provided with the distribution.
021: *
022: * - Neither the name of the Hewlett-Packard Company nor the name of the
023: * Massachusetts Institute of Technology nor the names of their
024: * contributors may be used to endorse or promote products derived from
025: * this software without specific prior written permission.
026: *
027: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
028: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
029: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
030: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
031: * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
032: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
033: * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
034: * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
035: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
036: * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
037: * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
038: * DAMAGE.
039: */
040:
041: package org.dspace.app.xmlui.wing.element;
042:
043: /**
044: * This class represents a generic Wing Container. The Container class adds a
045: * simlpe contents list which may be modified by the extending concret classes.
046: * When it comes time to process the element a toSAX method is provided that
047: * will iterate over the contents.
048: *
049: * @author Scott Phillips
050: */
051:
052: import java.util.ArrayList;
053: import java.util.List;
054:
055: import org.dspace.app.xmlui.wing.WingContext;
056: import org.dspace.app.xmlui.wing.WingException;
057: import org.xml.sax.ContentHandler;
058: import org.xml.sax.SAXException;
059: import org.xml.sax.ext.LexicalHandler;
060: import org.xml.sax.helpers.NamespaceSupport;
061:
062: public abstract class Container extends AbstractWingElement {
063:
064: /** The internal contents of this container */
065: protected List<AbstractWingElement> contents = new ArrayList<AbstractWingElement>();
066:
067: /**
068: * @param context
069: * (Required) The context this element is contained in.
070: */
071: protected Container(WingContext context) throws WingException {
072: super (context);
073: }
074:
075: /**
076: * Translate this element and all contained elements into SAX events. The
077: * events should be routed to the contentHandler found in the WingContext.
078: *
079: * This method does not create an inclosing block, the implementors of
080: * container class need to implement a method of toSAX() that provides the
081: * surrounding element block for that specific application.
082: *
083: * @param contentHandler
084: * (Required) The registered contentHandler where SAX events
085: * should be routed too.
086: * @param lexicalHandler
087: * (Required) The registered lexicalHandler where lexical events
088: * (such as CDATA, DTD, etc) should be routed too.
089: * @param namespaces
090: * (Required) SAX Helper class to keep track of namespaces able
091: * to determine the correct prefix for a given namespace URI.
092: */
093: public void toSAX(ContentHandler contentHandler,
094: LexicalHandler lexicalHandler, NamespaceSupport namespaces)
095: throws SAXException {
096: for (AbstractWingElement content : contents) {
097: content.toSAX(contentHandler, lexicalHandler, namespaces);
098: }
099: }
100:
101: /**
102: * Dispose
103: */
104: public void dispose() {
105:
106: if (this .contents != null) {
107: for (AbstractWingElement element : contents)
108: element.dispose();
109: this.contents.clear();
110: }
111: this.contents = null;
112: super.dispose();
113: }
114:
115: }
|