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.HotdogBuyer;
031: import org.jicarilla.container.tck.components.interfaces.InvalidChildException;
032: import org.jicarilla.container.tck.components.interfaces.Lisa;
033: import org.jicarilla.container.tck.components.interfaces.Maggie;
034: import org.jicarilla.container.tck.components.interfaces.Marge;
035: import org.jicarilla.lang.CascadingRuntimeException;
036:
037: import java.lang.reflect.Method;
038: import java.util.List;
039: import java.util.ArrayList;
040:
041: /**
042: *
043: *
044: * @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
045: * @version $Id: AbstractHomer.java,v 1.6 2004/04/03 12:09:20 lsimons Exp $
046: */
047: public abstract class AbstractHomer extends AbstractComponent implements
048: Homer, HotdogBuyer {
049: // ----------------------------------------------------------------------
050: // Properties
051: // ----------------------------------------------------------------------
052: protected Marge m_marge;
053: protected List m_children = new ArrayList();
054: protected List m_hotdogs;
055:
056: // ----------------------------------------------------------------------
057: // Poor-Man's Invocation Logging
058: // ----------------------------------------------------------------------
059: public final static Method setMarge;
060: public final static Method buyHotdog;
061: public final static Method burp;
062: public final static Method addChild;
063: static {
064: try {
065: setMarge = AbstractHomer.class.getDeclaredMethod(
066: "setMarge", new Class[] { Marge.class });
067: buyHotdog = AbstractHomer.class.getMethod("buyHotdog",
068: new Class[] { Object.class });
069: burp = AbstractHomer.class.getMethod("burp", new Class[0]);
070: addChild = AbstractHomer.class.getMethod("addChild",
071: new Class[] { Object.class });
072: } catch (NoSuchMethodException e) {
073: throw new CascadingRuntimeException(e.getMessage(), e);
074: }
075: }
076:
077: // ----------------------------------------------------------------------
078: // Methods
079: // ----------------------------------------------------------------------
080:
081: public void buyHotdog(Object hotdog) {
082: super .log(buyHotdog, hotdog);
083: m_hotdogs.add(hotdog);
084: }
085:
086: public void addChild(Object child) throws InvalidChildException {
087: super .log(addChild, child);
088: if (!(child instanceof Bart || child instanceof Lisa || child instanceof Maggie))
089: throw new InvalidChildException();
090:
091: m_children.add(child);
092: }
093:
094: public void burp() {
095: super .log(burp);
096: }
097:
098: // ----------------------------------------------------------------------
099: // Getters / Setters
100: // ----------------------------------------------------------------------
101:
102: protected List getHotdogs() {
103: return m_hotdogs;
104: }
105:
106: protected void setMarge(Marge marge) {
107: super .log(setMarge, marge);
108: m_marge = marge;
109: }
110:
111: protected Marge getMarge() {
112: return m_marge;
113: }
114:
115: }
|