01: /*
02: *
03: *
04: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
05: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License version
09: * 2 only, as published by the Free Software Foundation.
10: *
11: * This program is distributed in the hope that it will be useful, but
12: * WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * General Public License version 2 for more details (a copy is
15: * included at /legal/license.txt).
16: *
17: * You should have received a copy of the GNU General Public License
18: * version 2 along with this work; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA
21: *
22: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
23: * Clara, CA 95054 or visit www.sun.com if you need additional
24: * information or have any questions.
25: */
26: package com.sun.perseus.model;
27:
28: import com.sun.perseus.util.SVGConstants;
29:
30: import java.util.Vector;
31:
32: /**
33: * A <code>TimeCondition</code> represents a value in a
34: * <code>TimedElementSupport</code> begin or end conditions list.
35: *
36: * @version $Id: TimeCondition.java,v 1.2 2006/04/21 06:39:19 st125089 Exp $
37: */
38: public abstract class TimeCondition {
39: /**
40: * Controls whether this condition is part of a begin or end list
41: */
42: boolean isBegin;
43:
44: /**
45: * The associated <code>TimedElement</code>
46: */
47: TimedElementSupport timedElement;
48:
49: /**
50: * As a result of constructing a new <code>TimeCondition</code>, the
51: * condition is added to the associated <code>TimedElementSupport</code>'s
52: * begin or end list of conditions.
53: *
54: * @param timedElement the associated <code>TimedElementSupport</code>.
55: * Should not be null.
56: * @param isBegin defines whether this condition is for a begin list.
57: */
58: public TimeCondition(final TimedElementSupport timedElement,
59: final boolean isBegin) {
60: if (timedElement == null) {
61: throw new NullPointerException();
62: }
63:
64: this .timedElement = timedElement;
65: this .isBegin = isBegin;
66:
67: timedElement.addTimeCondition(this );
68: }
69:
70: /**
71: * Converts a vector of TimeCondition instances to a string trait value.
72: *
73: * @param v the TimeCondition vector to convert. Should not be null.
74: * This should be called with a TimedElementSupport begin or
75: * end condition vector, which should <b>never</b> be null.
76: * @return the string trait value.
77: */
78: protected static String toStringTrait(final Vector v) {
79: final int n = v.size();
80: StringBuffer sb = new StringBuffer();
81:
82: for (int i = 0; i < n - 1; i++) {
83: TimeCondition tc = (TimeCondition) v.elementAt(i);
84: sb.append(tc.toStringTrait());
85: sb.append(SVGConstants.SEMI_COLON);
86: }
87:
88: sb.append(((TimeCondition) v.elementAt(n - 1)).toStringTrait());
89: return sb.toString();
90: }
91:
92: /**
93: * Converts this <code>TimeCondition</code> to a String trait.
94: *
95: * @return a string describing this <code>TimeCondition</code>
96: */
97: protected abstract String toStringTrait();
98: }
|