KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hpsf > PropertySetFactory


1
2 /* ====================================================================
3    Copyright 2002-2004 Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16 ==================================================================== */

17         
18 package org.apache.poi.hpsf;
19
20 import java.io.InputStream JavaDoc;
21 import java.io.IOException JavaDoc;
22 import java.io.UnsupportedEncodingException JavaDoc;
23 import java.rmi.UnexpectedException JavaDoc;
24
25 /**
26  * <p>Factory class to create instances of {@link SummaryInformation},
27  * {@link DocumentSummaryInformation} and {@link PropertySet}.</p>
28  *
29  * @author Rainer Klute <a
30  * HREF="mailto:klute@rainer-klute.de">&lt;klute@rainer-klute.de&gt;</a>
31  * @version $Id: PropertySetFactory.java,v 1.12 2004/06/22 16:11:39 klute Exp $
32  * @since 2002-02-09
33  */

34 public class PropertySetFactory
35 {
36
37     /**
38      * <p>Creates the most specific {@link PropertySet} from an {@link
39      * InputStream}. This is preferrably a {@link
40      * DocumentSummaryInformation} or a {@link SummaryInformation}. If
41      * the specified {@link InputStream} does not contain a property
42      * set stream, an exception is thrown and the {@link InputStream}
43      * is repositioned at its beginning.</p>
44      *
45      * @param stream Contains the property set stream's data.
46      * @return The created {@link PropertySet}.
47      * @throws NoPropertySetStreamException if the stream does not
48      * contain a property set.
49      * @throws MarkUnsupportedException if the stream does not support
50      * the <code>mark</code> operation.
51      * @throws IOException if some I/O problem occurs.
52      * @exception UnsupportedEncodingException if the specified codepage is not
53      * supported.
54      */

55     public static PropertySet create(final InputStream JavaDoc stream)
56         throws NoPropertySetStreamException, MarkUnsupportedException,
57                UnsupportedEncodingException JavaDoc, IOException JavaDoc
58     {
59         final PropertySet ps = new PropertySet(stream);
60         try
61         {
62             if (ps.isSummaryInformation())
63                 return new SummaryInformation(ps);
64             else if (ps.isDocumentSummaryInformation())
65                 return new DocumentSummaryInformation(ps);
66             else
67                 return ps;
68         }
69         catch (UnexpectedPropertySetTypeException ex)
70         {
71             /* This exception will never be throws because we already checked
72              * explicitly for this case above. */

73             throw new UnexpectedException JavaDoc(ex.toString());
74         }
75     }
76
77 }
78
Popular Tags