001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026: package com.sun.perseus.model;
027:
028: /**
029: * Base class for representing time instances in a
030: * <code>TimedElementSupport</code>'s begin and end instance times lists.
031: *
032: * @version $Id: TimeInstance.java,v 1.2 2006/04/21 06:39:25 st125089 Exp $
033: */
034: class TimeInstance {
035: /**
036: * The associated <code>TimeElement</code>
037: */
038: TimedElementSupport timedElement;
039:
040: /**
041: * If true, this <code>TimeInstance</code> should be cleared from
042: * the <code>TimedElementSupport</code> intance list on reset.
043: */
044: boolean clearOnReset;
045:
046: /**
047: * This instance's time.
048: */
049: Time time;
050:
051: /**
052: * True if this instance is in the begin instance list.
053: * Fals if it is part of an end instance list.
054: */
055: boolean isBegin;
056:
057: /**
058: * Builds an instance time for the input <code>TimedElementSupport</code>
059: * and time. The constructor will insert the <code>Instance</code>
060: * automatically into the <code>TimedElementSupport</code> corresponding
061: * instance list.
062: *
063: * @param timedElement the associated <code>TimedElementSupport</code>
064: * @param time the instance time value.
065: * @param clearOnReset defines whether or not this instance should
066: * be cleared from instance times lists on reset.
067: * @param isBegin true if this object is part of the
068: * timedElement's begin instance list.
069: * @throws NullPointerException if time or timedElement is null
070: */
071: public TimeInstance(final TimedElementSupport timedElement,
072: final Time time, final boolean clearOnReset,
073: final boolean isBegin) {
074: if (timedElement == null || time == null) {
075: throw new NullPointerException();
076: }
077:
078: this .timedElement = timedElement;
079: this .time = time;
080: this .clearOnReset = clearOnReset;
081: this .isBegin = isBegin;
082:
083: timedElement.addTimeInstance(this );
084: }
085:
086: /**
087: * Updates this instance time. This notifies the associated
088: * <code>TimedElementSupport</code> through its <code>instanceUpdate</code>
089: * method.
090: *
091: * @param newTime the new instance time. Should not be null.
092: * @throws NullPointerException if newTime is null.
093: */
094: void setTime(final Time newTime) {
095: if (newTime == null) {
096: throw new NullPointerException();
097: }
098:
099: time = newTime;
100: timedElement.onTimeInstanceUpdate(this);
101: }
102: }
|