1 /**
2 * AUTOHIT 2003
3 * Copyright Erich P Gatejen (c) 1989,1997,2003,2004
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Additional license information can be found in the documentation.
19 * @author Erich P Gatejen
20 */
21 package autohit.universe;
22
23 import java.io.IOException;
24 import java.io.InputStream;
25
26 import javax.activation.DataSource;
27
28 /**
29 * A Universe Data Source useable by the activation framework. This is a
30 * lightweight implementation. It is not valid until init(...) is called.
31 *
32 * @author Erich P. Gatejen
33 * @version 1.0
34 * <i>Version History</i>
35 * <code>EPG - New - 8Aug03</code>
36 *
37 */
38 public class UniverseDataSource implements DataSource {
39
40 /**
41 * Name of this universe object.
42 */
43 public String name;
44
45 /**
46 * Owning universe.
47 */
48 public Universe uni;
49
50 /**
51 * Default Constructor.
52 */
53 public UniverseDataSource() {
54
55 }
56
57 /**
58 * Initializer.
59 * @param uniObj name of the universe object to source.
60 * @param u the universe to source from.
61 */
62 public void init(String uniObj, Universe u) {
63 name = uniObj;
64 uni = u;
65 }
66
67 /**
68 * Get the InputStream for this source.
69 * @return The input stream
70 */
71 public java.io.InputStream getInputStream() throws java.io.IOException {
72 InputStream result = null;
73 try {
74 result = uni.getStream(name);
75 } catch (UniverseException e) {
76 IOException ioe = new IOException(e.numeric + ":" + e.getMessage());
77 ioe.initCause(e);
78 throw ioe;
79 }
80 return result;
81 }
82
83 /**
84 * Get the OutStream for this source.
85 * This implementation doesn't support this.
86 * @return The input stream
87 */
88 public java.io.OutputStream getOutputStream() throws java.io.IOException {
89 throw new IOException("UniverseDataSource does not support getOutputStream().");
90 }
91
92 /**
93 * Get the content type. LIE! We'll always say an octet stream.
94 * @return the type
95 */
96 public java.lang.String getContentType() {
97 return "application/octet-stream";
98 }
99
100 /**
101 * Get the underlying object descriptor.
102 * @return the type
103 */
104 public java.lang.String getName() {
105 return name;
106 }
107
108 }
|