2 * Copyright 2001 Sun Microsystems, Inc.
4 * See the file "license.terms" for information on usage and
5 * redistribution of this file, and for a DISCLAIMER OF ALL
11 * An object that can be played by the Player. Contains type information,
12 * and stores actual object that will be played.
14 public class Playable {
16 private PlayableType type;
17 private Object data = null;
21 * Creates a JSML text Playable object with the given text.
23 * @param jsmlText the JSML text of the Playable object
25 * @return a JSML text Playable object
27 public static Playable createJSMLPlayable(String jsmlText) {
28 return new Playable(PlayableType.JSML, jsmlText, jsmlText);
32 * Creates a JSML file Playable object with the given File.
34 * @param jsmlFile the JSML file
36 * @return a JSML file Playable object
38 public static Playable createJSMLFilePlayable(File jsmlFile) {
40 (PlayableType.JSML_FILE, jsmlFile, jsmlFile.getName());
44 * Creates an ASCII text Playable object with the given text.
46 * @param text the ASCII text
48 * @return an ASCII text JSML file Playable object
50 public static Playable createTextPlayable(String text) {
51 return new Playable(PlayableType.TEXT, text, text);
55 * Creates an ASCII file Playable object with the given text file.
57 * @param textFile the ASCII text file
59 * @return an ASCII text file Playable object
61 public static Playable createTextFilePlayable(File textFile) {
63 (PlayableType.TEXT_FILE, textFile, textFile.getName());
67 * Creates a URL Playable object with the given URL.
71 * @return a URL Playable object
73 public static Playable createURLPlayable(String url) {
74 return new Playable(PlayableType.URL, url, url.toString());
79 * Constructs a Playable object of the given type and data.
81 * @param type the Playable type
82 * @param data the object containing the Playable data
84 private Playable(PlayableType type, Object data, String name) {
91 * Returns the Playable type.
93 * @return the PlayableType
95 public PlayableType getType() {
100 * Returns the File corresponding to this Playable.
102 * @return the Playable File
104 public File getFile() {
105 if (type == PlayableType.TEXT_FILE ||
106 type == PlayableType.JSML_FILE) {
114 * Returns the text corresponding to this Playable.
116 * @return the Playable text
118 public String getText() {
119 if (type == PlayableType.JSML || type == PlayableType.TEXT) {
120 return (String) data;
127 * Returns the name of this Playable
129 * @return the name of this Playable
131 public String getName() {
136 * Returns a String describing the type and name of this Playable, e.g.,
137 * <p><code>[JSML file] example1.jsml</code>
139 * @return the type and name of this Playable
141 public String toString() {
142 String typeName = "[" + type.toString() + "] ";
143 return typeName + name;