01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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 java.net;
19:
20: import java.io.IOException;
21:
22: /**
23: * This class converts the content of a certain format into a Java type Object.
24: * It is implemented differently for each content type in each platform. It is
25: * created by <code>ContentHandlerFactory</code>
26: *
27: * @see ContentHandlerFactory
28: * @see URL
29: * @see URLConnection#getContent()
30: */
31: public abstract class ContentHandler {
32: /**
33: * Answers the object pointed by the specified URL Connection
34: * <code>uConn</code>.
35: *
36: * @return java.lang.Object the object referred by <code>uConn</code>
37: * @param uConn
38: * URLConnection the URL connection that points to the desired
39: * object
40: * @throws IOException
41: * thrown if an IO error occurs during the retrieval of the
42: * object
43: */
44: public abstract Object getContent(URLConnection uConn)
45: throws IOException;
46:
47: /**
48: * Answers the object pointed by the specified URL Connection
49: * <code>uConn</code>.
50: *
51: * @param uConn
52: * java.net.URLConnection the URL connection that points to the
53: * desired object
54: * @param types
55: * The list of acceptable content types
56: * @return Object The object of the resource pointed by this URL, or null if
57: * the content does not match a specified content type.
58: *
59: * @throws IOException
60: * If an error occurred obtaining the content.
61: */
62: // Class arg not generified in the spec.
63: @SuppressWarnings("unchecked")
64: public Object getContent(URLConnection uConn, Class[] types)
65: throws IOException {
66: Object content = getContent(uConn);
67: for (int i = 0; i < types.length; i++) {
68: if (types[i].isInstance(content)) {
69: return content;
70: }
71: }
72: return null;
73: }
74: }
|