xref: /illumos-gate/usr/src/lib/libslp/javalib/com/sun/slp/URLAttributeVerifier.java (revision 968633ad8faee931821fd6b656eb0d96d4b186c0)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright (c) 1999 by Sun Microsystems, Inc.
23  * All rights reserved.
24  *
25  */
26 
27 //  URLAttributeVerifier.java: Parse a service template from a URL
28 //  Author:           James Kempf
29 //  Created On:       Mon Jun 23 11:52:04 1997
30 //  Last Modified By: James Kempf
31 //  Last Modified On: Thu Jun 11 13:24:03 1998
32 //  Update Count:     22
33 //
34 
35 package com.sun.slp;
36 
37 import java.util.*;
38 import java.net.*;
39 import java.io.*;
40 
41 /**
42  * A URLAttributeVerifier object performs service template parsing from
43  * a URL. Most of the work is done by the superclass. This class
44  * takes care of opening the Reader on the URL.
45  *
46  * @author James Kempf
47  *
48  */
49 
50 class URLAttributeVerifier extends AttributeVerifier {
51 
52     /**
53      * Construct a URLAttributeVerifier for the file named in the parameter.
54      *
55      * @param url URL from which to read the template
56      * @exception ServiceLocationException Error code may be:
57      *				       SYSTEM_ERROR
58      *					   when the URL can't be opened or
59      *					   some other i/o error occurs.
60      *					PARSE_ERROR
61      *					    if an error occurs during
62      *					    attribute parsing.
63      */
64 
65     URLAttributeVerifier(String url)
66 	throws ServiceLocationException {
67 
68 	super();
69 
70 	initialize(url);
71 
72     }
73 
74     // Open a reader on the URL and initialize the attribute verifier.
75 
76     private void initialize(String urlName)
77 	throws ServiceLocationException {
78 
79 	InputStream is = null;
80 
81 	try {
82 
83 	    // Open the URL.
84 
85 	    URL url = new URL(urlName);
86 
87 	    // Open an input stream on the URL.
88 
89 	    is = url.openStream();
90 
91 	    // Initialize the verifier, by parsing the file.
92 
93 	    super.initialize(new InputStreamReader(is));
94 
95 	} catch (MalformedURLException ex) {
96 
97 	    throw
98 		new ServiceLocationException(
99 				ServiceLocationException.INTERNAL_SYSTEM_ERROR,
100 				"invalid_url",
101 				new Object[] {urlName});
102 
103 	} catch (IOException ex) {
104 
105 	    throw
106 	  new ServiceLocationException(
107 				ServiceLocationException.INTERNAL_SYSTEM_ERROR,
108 				"url_ioexception",
109 				new Object[] { urlName, ex.getMessage()});
110 
111 	}
112 
113 	try {
114 
115 	    is.close();
116 
117 	} catch (IOException ex) {
118 
119 	}
120 
121     }
122 }
123