KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > wings > template > StreamTemplateSource


1 /*
2  * $Id: StreamTemplateSource.java,v 1.3 2004/12/01 07:54:28 hengels Exp $
3  * Copyright 2000,2005 wingS development team.
4  *
5  * This file is part of wingS (http://www.j-wings.org).
6  *
7  * wingS is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2.1
10  * of the License, or (at your option) any later version.
11  *
12  * Please see COPYING for the complete licence.
13  */

14 package org.wings.template;
15
16 import java.io.IOException JavaDoc;
17 import java.io.InputStream JavaDoc;
18
19 /**
20  * A <CODE>StreamDataSource</CODE> implements a DataSource
21  * as a wrapper around a Stream.
22  *
23  * @author <A HREF="mailto:joachim.karrer@mercatis.de">Joachim Karrer</A>
24  * @version $Revision: 1.3 $
25  */

26 public class StreamTemplateSource implements TemplateSource {
27     /**
28      * enable debug output
29      */

30     private static final boolean DEBUG = true;
31
32     /**
33      * <p>the <code>InputStream</code> from which we are reading data.</p>
34      */

35     private InputStream JavaDoc iStream;
36
37     /**
38      * <p>the last time the <code>InputStream</code> was updated.</p>
39      */

40     private long modificationTime;
41
42     /**
43      * <p>generates a new StreamDataSource with the given Stream</p>
44      *
45      * @param iStream the InputStream from which the template is read.
46      */

47     public StreamTemplateSource(InputStream JavaDoc iStream) {
48         setInputStream(iStream);
49     }
50
51     /**
52      * <p>sets the InputStream and the modificationTime</p>
53      *
54      * @param iStream the InputStream from which the template is read.
55      */

56     public void setInputStream(InputStream JavaDoc iStream) {
57         if (iStream == null) {
58             throw new IllegalArgumentException JavaDoc("stream is null, this is invalid!!");
59         }
60         this.iStream = iStream;
61         setModificationTime();
62     }
63
64     /**
65      * <p>sets the modificationTime to the currentTimeMillis</p>
66      */

67     public void setModificationTime() {
68         modificationTime = System.currentTimeMillis();
69     }
70
71     /**
72      * <p>returns the canonical name of the inputStream (uaaaah!)</p>
73      *
74      * @return <p>always null, because stream is always to be parsed</p>
75      */

76     public String JavaDoc getCanonicalName() {
77         return null;
78     }
79
80     /**
81      * <p>Returns the time the content of this stream
82      * was last modified.</p>
83      * <p>The return value is used to decide whether to reparse a
84      * Source or not. Reparsing is done if the value returned
85      * here differs from the value returned at the last processing
86      * time.</p>
87      * <p><em>Attention: Modificationtime is only updated if a new stream is set!</em></p>
88      *
89      * @return long a modification time
90      */

91     public long lastModified() {
92         return modificationTime;
93     }
94
95     /**
96      * Gets an InputStream of the File.
97      *
98      * @return the actually set InputStream
99      */

100     public InputStream JavaDoc getInputStream() throws IOException JavaDoc {
101         iStream.reset();
102         return iStream;
103     }
104 }
105
106
107
Popular Tags