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