File: Playable.java

package info (click to toggle)
freetts 1.2.2-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 65,244 kB
  • sloc: java: 21,305; xml: 1,340; sh: 969; lisp: 587; ansic: 241; makefile: 25; awk: 11
file content (146 lines) | stat: -rw-r--r-- 3,558 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/**
 * Copyright 2001 Sun Microsystems, Inc.
 * 
 * See the file "license.terms" for information on usage and
 * redistribution of this file, and for a DISCLAIMER OF ALL 
 * WARRANTIES.
 */
import java.io.File;

/**
 * An object that can be played by the Player. Contains type information,
 * and stores actual object that will be played.
 */
public class Playable {

    private PlayableType type;
    private Object data = null;
    private String name;
    
    /**
     * Creates a JSML text Playable object with the given text.
     *
     * @param jsmlText the JSML text of the Playable object
     *
     * @return a JSML text Playable object 
     */
    public static Playable createJSMLPlayable(String jsmlText) {
	return new Playable(PlayableType.JSML, jsmlText, jsmlText);
    }

    /**
     * Creates a JSML file Playable object with the given File.
     *
     * @param jsmlFile the JSML file
     *
     * @return a JSML file Playable object
     */
    public static Playable createJSMLFilePlayable(File jsmlFile) {
	return new Playable
	    (PlayableType.JSML_FILE, jsmlFile, jsmlFile.getName());
    }
    
    /**
     * Creates an ASCII text Playable object with the given text.
     *
     * @param text the ASCII text
     *
     * @return an ASCII text JSML file Playable object
     */
    public static Playable createTextPlayable(String text) {
	return new Playable(PlayableType.TEXT, text, text);
    }

    /**
     * Creates an ASCII file Playable object with the given text file.
     *
     * @param textFile the ASCII text file
     *
     * @return an ASCII text file Playable object
     */
    public static Playable createTextFilePlayable(File textFile) {
	return new Playable
	    (PlayableType.TEXT_FILE, textFile, textFile.getName());
    }

    /**
     * Creates a URL Playable object with the given URL.
     *
     * @param url the URL
     *
     * @return a URL Playable object
     */
    public static Playable createURLPlayable(String url) {
	return new Playable(PlayableType.URL, url, url.toString());
    }
    
    
    /**
     * Constructs a Playable object of the given type and data.
     *
     * @param type the Playable type
     * @param data the object containing the Playable data
     */
    private Playable(PlayableType type, Object data, String name) {
	this.type = type;
	this.data = data;
	this.name = name;
    }

    /**
     * Returns the Playable type.
     *
     * @return the PlayableType
     */
    public PlayableType getType() {
	return type;
    }
    
    /**
     * Returns the File corresponding to this Playable.
     * 
     * @return the Playable File
     */
    public File getFile() {
	if (type == PlayableType.TEXT_FILE ||
	    type == PlayableType.JSML_FILE) {
	    return (File) data;
	} else {
	    return null;
	}
    }

    /**
     * Returns the text corresponding to this Playable.
     *
     * @return the Playable text
     */
    public String getText() {
	if (type == PlayableType.JSML || type == PlayableType.TEXT) {
	    return (String) data;
	} else {
	    return null;
	}
    }

    /**
     * Returns the name of this Playable
     *
     * @return the name of this Playable
     */
    public String getName() {
	return name;
    }

    /**
     * Returns a String describing the type and name of this Playable, e.g.,
     * <p><code>[JSML file] example1.jsml</code>
     *
     * @return the type and name of this Playable
     */
    public String toString() {
	String typeName = "[" + type.toString() + "] ";
	return typeName + name;
    }
    
}