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.Homer;
029: import org.jicarilla.container.tck.components.interfaces.InvalidChildException;
030: import org.jicarilla.container.tck.components.interfaces.Maggie;
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: AbstractMaggie.java,v 1.4 2004/03/23 13:37:54 lsimons Exp $
041: */
042: public abstract class AbstractMaggie extends AbstractComponent
043: implements Maggie {
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: static {
053: try {
054: setHomer = AbstractMaggie.class.getDeclaredMethod(
055: "setHomer", new Class[] { Homer.class });
056: setMarge = AbstractMaggie.class.getDeclaredMethod(
057: "setMarge", new Class[] { Marge.class });
058: } catch (NoSuchMethodException e) {
059: throw new CascadingRuntimeException(e.getMessage(), e);
060: }
061: }
062:
063: protected Homer getHomer() {
064: return m_homer;
065: }
066:
067: protected void setHomer(Homer homer) {
068: super .log(setHomer, homer);
069: m_homer = homer;
070:
071: if (m_homer != null) {
072: try // conveniently break IoC :D
073: {
074: m_homer.addChild(this );
075: } catch (InvalidChildException ice) {
076: throw new IllegalArgumentException(
077: "Homer does not accept me as a child!");
078: }
079: }
080: }
081:
082: protected Marge getMarge() {
083: return m_marge;
084: }
085:
086: protected void setMarge(Marge marge) {
087: super .log(setMarge, marge);
088: m_marge = marge;
089:
090: if (m_marge != null) {
091: try // conveniently break IoC :D
092: {
093: m_marge.addChild(this );
094: } catch (InvalidChildException ice) {
095: throw new IllegalArgumentException(
096: "Marge does not accept me as a child!");
097: }
098: }
099: }
100: }
|