KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jibx > binding > def > LinkableBase


1 /*
2 Copyright (c) 2003, Dennis M. Sosnoski
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without modification,
6 are permitted provided that the following conditions are met:
7
8  * Redistributions of source code must retain the above copyright notice, this
9    list of conditions and the following disclaimer.
10  * Redistributions in binary form must reproduce the above copyright notice,
11    this list of conditions and the following disclaimer in the documentation
12    and/or other materials provided with the distribution.
13  * Neither the name of JiBX nor the names of its contributors may be used
14    to endorse or promote products derived from this software without specific
15    prior written permission.
16
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */

28
29 package org.jibx.binding.def;
30
31
32 import org.jibx.runtime.JiBXException;
33
34 /**
35  * Base class for components that can be linked from multiple locations within
36  * the binding definition structure. The implemented basic behavior is a simple
37  * pass-through component, with the addition of recursion checking during the
38  * linking phase.
39  *
40  * @author Dennis M. Sosnoski
41  * @version 1.0
42  */

43
44 public abstract class LinkableBase extends PassThroughComponent
45 {
46     /** Flag for linkage in progress. */
47     private boolean m_isLinking;
48     
49     /** Flag for linkage complete. */
50     private boolean m_isLinked;
51
52     /**
53      * No argument constructor. This requires the component to be set later,
54      * using the {@link
55      * org.jibx.binding.def.PassThroughComponent#setWrappedComponent} method.
56      */

57
58     protected LinkableBase() {}
59
60     /**
61      * Constructor.
62      *
63      * @param wrap wrapped binding component
64      */

65
66     public LinkableBase(IComponent wrap) {
67         super(wrap);
68     }
69
70     /**
71      * Handler for recursion. If recursion is found during linking this method
72      * will be called. The base class implementation does nothing, but may be
73      * overridden by subclases to implement the appropriate behavior.
74      */

75
76     protected void handleRecursion() {}
77
78     //
79
// IComponent interface method definitions
80

81     // subclasses should call the base class implementation if they override
82
// this method
83
public void setLinkages() throws JiBXException {
84         if (m_isLinking) {
85             handleRecursion();
86         } else {
87             if (!m_isLinked) {
88                 m_isLinking = true;
89                 m_component.setLinkages();
90                 m_isLinking = false;
91                 m_isLinked = true;
92             }
93         }
94     }
95     
96     // DEBUG
97
public void print(int depth) {
98         BindingDefinition.indent(depth);
99         System.out.println("linkable wrapper");
100         m_component.print(depth+1);
101     }
102 }
103
Popular Tags