001: /*
002: Copyright (c) 2003, Dennis M. Sosnoski
003: All rights reserved.
004:
005: Redistribution and use in source and binary forms, with or without modification,
006: are permitted provided that the following conditions are met:
007:
008: * Redistributions of source code must retain the above copyright notice, this
009: list of conditions and the following disclaimer.
010: * Redistributions in binary form must reproduce the above copyright notice,
011: this list of conditions and the following disclaimer in the documentation
012: and/or other materials provided with the distribution.
013: * Neither the name of JiBX nor the names of its contributors may be used
014: to endorse or promote products derived from this software without specific
015: prior written permission.
016:
017: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
018: ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
019: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
020: DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
021: ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
022: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
023: LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
024: ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
025: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
026: SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
027: */
028:
029: package org.jibx.binding.def;
030:
031: import org.jibx.runtime.JiBXException;
032:
033: /**
034: * Base class for components that can be linked from multiple locations within
035: * the binding definition structure. The implemented basic behavior is a simple
036: * pass-through component, with the addition of recursion checking during the
037: * linking phase.
038: *
039: * @author Dennis M. Sosnoski
040: * @version 1.0
041: */
042:
043: public abstract class LinkableBase extends PassThroughComponent {
044: /** Flag for linkage in progress. */
045: private boolean m_isLinking;
046:
047: /** Flag for linkage complete. */
048: private boolean m_isLinked;
049:
050: /**
051: * No argument constructor. This requires the component to be set later,
052: * using the {@link
053: * org.jibx.binding.def.PassThroughComponent#setWrappedComponent} method.
054: */
055:
056: protected LinkableBase() {
057: }
058:
059: /**
060: * Constructor.
061: *
062: * @param wrap wrapped binding component
063: */
064:
065: public LinkableBase(IComponent wrap) {
066: super (wrap);
067: }
068:
069: /**
070: * Handler for recursion. If recursion is found during linking this method
071: * will be called. The base class implementation does nothing, but may be
072: * overridden by subclases to implement the appropriate behavior.
073: */
074:
075: protected void handleRecursion() {
076: }
077:
078: //
079: // IComponent interface method definitions
080:
081: // subclasses should call the base class implementation if they override
082: // this method
083: public void setLinkages() throws JiBXException {
084: if (m_isLinking) {
085: handleRecursion();
086: } else {
087: if (!m_isLinked) {
088: m_isLinking = true;
089: m_component.setLinkages();
090: m_isLinking = false;
091: m_isLinked = true;
092: }
093: }
094: }
095:
096: // DEBUG
097: public void print(int depth) {
098: BindingDefinition.indent(depth);
099: System.out.println("linkable wrapper");
100: m_component.print(depth + 1);
101: }
102: }
|