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:
027: package com.sun.perseus.model;
028:
029: import com.sun.perseus.util.SVGConstants;
030:
031: import org.w3c.dom.DOMException;
032:
033: import java.util.Vector;
034:
035: /**
036: * <code>Animate</code> represents an SVG Tiny <code><animate></code>
037: * element.
038: *
039: * @version $Id: Animate.java,v 1.4 2006/06/29 10:47:29 ln156897 Exp $
040: */
041: public class Animate extends AbstractAnimate {
042: /**
043: * Required Animate traits
044: */
045: static final String[] REQUIRED_TRAITS = { SVGConstants.SVG_ATTRIBUTE_NAME_ATTRIBUTE };
046:
047: /**
048: * The trait's qualified name.
049: */
050: String traitQName = null;
051:
052: /**
053: * Builds a new Animate element that belongs to the given
054: * document. This <code>Animate</code> will belong
055: * to the <code>DocumentNode</code>'s time container.
056: *
057: * @param ownerDocument the document this node belongs to.
058: * @throws IllegalArgumentException if the input ownerDocument is null
059: */
060: public Animate(final DocumentNode ownerDocument) {
061: super (ownerDocument, SVGConstants.SVG_ANIMATE_TAG);
062: }
063:
064: /**
065: * Builds a new Animate element that belongs to the given
066: * document. This <code>Animate</code> will belong
067: * to the <code>DocumentNode</code>'s time container.
068: *
069: * @param ownerDocument the document this node belongs to.
070: * @param localName the animation element's local name.
071: * @throws IllegalArgumentException if the input ownerDocument is null
072: */
073: public Animate(final DocumentNode ownerDocument,
074: final String localName) {
075: super (ownerDocument, localName);
076: }
077:
078: /**
079: * Used by <code>DocumentNode</code> to create a new instance from
080: * a prototype <code>TimedElementNode</code>.
081: *
082: * @param doc the <code>DocumentNode</code> for which a new node is
083: * should be created.
084: * @return a new <code>TimedElementNode</code> for the requested document.
085: */
086: public ElementNode newInstance(final DocumentNode doc) {
087: return new Animate(doc, getLocalName());
088: }
089:
090: /**
091: * @param traitName the name of the trait which the element may support.
092: * @return true if this element supports the given trait in one of the
093: * trait accessor methods.
094: */
095: boolean supportsTrait(final String traitName) {
096: if (SVGConstants.SVG_ATTRIBUTE_NAME_ATTRIBUTE == traitName) {
097: return true;
098: } else {
099: return super .supportsTrait(traitName);
100: }
101: }
102:
103: /**
104: * @return an array of traits that are required by this element.
105: */
106: public String[] getRequiredTraits() {
107: return REQUIRED_TRAITS;
108: }
109:
110: // JAVADOC COMMENT ELIDED
111: public String getTraitImpl(final String name) throws DOMException {
112: if (SVGConstants.SVG_ATTRIBUTE_NAME_ATTRIBUTE == name) {
113: return traitQName;
114: } else {
115: return super .getTraitImpl(name);
116: }
117: }
118:
119: /**
120: * Animate supports the to, from, by, values, keyTimes, keySplines,
121: * and attributeName traits.
122: *
123: * @param name the trait's name.
124: * @param value the trait's value.
125: *
126: * @throws DOMException with error code NOT_SUPPORTED_ERR if the requested
127: * trait is not supported on this element or null.
128: * @throws DOMException with error code TYPE_MISMATCH_ERR if the requested
129: * trait's value cannot be specified as a String
130: * @throws DOMException with error code INVALID_ACCESS_ERR if the input
131: * value is an invalid value for the given trait or null.
132: * @throws DOMException with error code NO_MODIFICATION_ALLOWED_ERR: if
133: * attempt is made to change readonly trait.
134: */
135: public void setTraitImpl(final String name, final String value)
136: throws DOMException {
137: if (SVGConstants.SVG_ATTRIBUTE_NAME_ATTRIBUTE == name) {
138: checkWriteLoading(name);
139:
140: if (value == null) {
141: throw illegalTraitValue(name, value);
142: }
143:
144: // Now, if this is a QName, we need to use the namespace prefix map.
145: int i = value.indexOf(':');
146: if (i == -1) {
147: this .traitName = value.intern();
148: this .traitQName = value.intern();
149: } else {
150: if (i == value.length() - 1) {
151: // ':' is the last character, this is invalid.
152: throw illegalTraitValue(name, value);
153: }
154:
155: String prefix = value.substring(0, i);
156: String tName = value.substring(i + 1);
157:
158: String ns = ownerDocument.toNamespace(prefix, this);
159: if (ns == null) {
160: throw illegalTraitValue(name, value);
161: }
162:
163: traitName = tName.intern();
164: traitNamespace = ns.intern();
165: traitQName = value;
166: }
167: } else {
168: super.setTraitImpl(name, value);
169: }
170: }
171:
172: }
|