001: /* ====================================================================
002: The Jicarilla Software License
003:
004: Copyright (c) 2003 Leo Simons.
005: All rights reserved.
006:
007: Permission is hereby granted, free of charge, to any person obtaining
008: a copy of this software and associated documentation files (the
009: "Software"), to deal in the Software without restriction, including
010: without limitation the rights to use, copy, modify, merge, publish,
011: distribute, sublicense, and/or sell copies of the Software, and to
012: permit persons to whom the Software is furnished to do so, subject to
013: the following conditions:
014:
015: The above copyright notice and this permission notice shall be
016: included in all copies or substantial portions of the Software.
017:
018: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
019: EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
020: MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
021: IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
022: CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
023: TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
024: SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
025: ==================================================================== */
026: package org.jicarilla.container.tck.components;
027:
028: import org.jicarilla.container.tck.components.interfaces.Bart;
029: import org.jicarilla.container.tck.components.interfaces.Homer;
030: import org.jicarilla.container.tck.components.interfaces.InvalidChildException;
031: import org.jicarilla.container.tck.components.interfaces.Marge;
032: import org.jicarilla.lang.CascadingRuntimeException;
033:
034: import java.lang.reflect.Method;
035:
036: /**
037: *
038: *
039: * @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
040: * @version $Id: AbstractBart.java,v 1.5 2004/03/23 13:37:54 lsimons Exp $
041: */
042: public abstract class AbstractBart extends AbstractComponent implements
043: Bart {
044: private Homer m_homer;
045: private Marge m_marge;
046:
047: // ----------------------------------------------------------------------
048: // Poor-Man's Invocation Logging
049: // ----------------------------------------------------------------------
050: public final static Method setHomer;
051: public final static Method setMarge;
052: public final static Method swear;
053: static {
054: try {
055: setHomer = AbstractBart.class.getDeclaredMethod("setHomer",
056: new Class[] { Homer.class });
057: setMarge = AbstractBart.class.getDeclaredMethod("setMarge",
058: new Class[] { Marge.class });
059: swear = AbstractBart.class.getMethod("swear", new Class[0]);
060: } catch (NoSuchMethodException e) {
061: throw new CascadingRuntimeException(e.getMessage(), e);
062: }
063: }
064:
065: public void swear() {
066: super .log(swear);
067: }
068:
069: protected Homer getHomer() {
070: return m_homer;
071: }
072:
073: protected void setHomer(Homer homer) {
074: super .log(setHomer, homer);
075: m_homer = homer;
076:
077: if (m_homer != null) {
078: try // conveniently break IoC :D
079: {
080: m_homer.addChild(this );
081: } catch (InvalidChildException ice) {
082: throw new IllegalArgumentException(
083: "Homer does not accept me as a child!");
084: }
085: }
086: }
087:
088: protected Marge getMarge() {
089: return m_marge;
090: }
091:
092: protected void setMarge(Marge marge) {
093: super .log(setMarge, marge);
094: m_marge = marge;
095:
096: if (m_marge != null) {
097: try // conveniently break IoC :D
098: {
099: m_marge.addChild(this );
100: } catch (InvalidChildException ice) {
101: throw new IllegalArgumentException(
102: "Marge does not accept me as a child!");
103: }
104: }
105: }
106: }
|