10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7298SMark.J.Nelson@Sun.COM  * Common Development and Distribution License (the "License").
6*7298SMark.J.Nelson@Sun.COM  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
220Sstevel@tonic-gate  * Copyright (c) 1999 by Sun Microsystems, Inc.
230Sstevel@tonic-gate  * All rights reserved.
240Sstevel@tonic-gate  *
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate //  URLAttributeVerifier.java: Parse a service template from a URL
280Sstevel@tonic-gate //  Author:           James Kempf
290Sstevel@tonic-gate //  Created On:       Mon Jun 23 11:52:04 1997
300Sstevel@tonic-gate //  Last Modified By: James Kempf
310Sstevel@tonic-gate //  Last Modified On: Thu Jun 11 13:24:03 1998
320Sstevel@tonic-gate //  Update Count:     22
330Sstevel@tonic-gate //
340Sstevel@tonic-gate 
350Sstevel@tonic-gate package com.sun.slp;
360Sstevel@tonic-gate 
370Sstevel@tonic-gate import java.util.*;
380Sstevel@tonic-gate import java.net.*;
390Sstevel@tonic-gate import java.io.*;
400Sstevel@tonic-gate 
410Sstevel@tonic-gate /**
420Sstevel@tonic-gate  * A URLAttributeVerifier object performs service template parsing from
430Sstevel@tonic-gate  * a URL. Most of the work is done by the superclass. This class
440Sstevel@tonic-gate  * takes care of opening the Reader on the URL.
450Sstevel@tonic-gate  *
460Sstevel@tonic-gate  * @author James Kempf
470Sstevel@tonic-gate  *
480Sstevel@tonic-gate  */
490Sstevel@tonic-gate 
500Sstevel@tonic-gate class URLAttributeVerifier extends AttributeVerifier {
510Sstevel@tonic-gate 
520Sstevel@tonic-gate     /**
530Sstevel@tonic-gate      * Construct a URLAttributeVerifier for the file named in the parameter.
540Sstevel@tonic-gate      *
550Sstevel@tonic-gate      * @param url URL from which to read the template
560Sstevel@tonic-gate      * @exception ServiceLocationException Error code may be:
570Sstevel@tonic-gate      *				       SYSTEM_ERROR
580Sstevel@tonic-gate      *					   when the URL can't be opened or
590Sstevel@tonic-gate      *					   some other i/o error occurs.
600Sstevel@tonic-gate      *					PARSE_ERROR
610Sstevel@tonic-gate      *					    if an error occurs during
620Sstevel@tonic-gate      *					    attribute parsing.
630Sstevel@tonic-gate      */
640Sstevel@tonic-gate 
URLAttributeVerifier(String url)650Sstevel@tonic-gate     URLAttributeVerifier(String url)
660Sstevel@tonic-gate 	throws ServiceLocationException {
670Sstevel@tonic-gate 
680Sstevel@tonic-gate 	super();
690Sstevel@tonic-gate 
700Sstevel@tonic-gate 	initialize(url);
710Sstevel@tonic-gate 
720Sstevel@tonic-gate     }
730Sstevel@tonic-gate 
740Sstevel@tonic-gate     // Open a reader on the URL and initialize the attribute verifier.
750Sstevel@tonic-gate 
initialize(String urlName)760Sstevel@tonic-gate     private void initialize(String urlName)
770Sstevel@tonic-gate 	throws ServiceLocationException {
780Sstevel@tonic-gate 
790Sstevel@tonic-gate 	InputStream is = null;
800Sstevel@tonic-gate 
810Sstevel@tonic-gate 	try {
820Sstevel@tonic-gate 
830Sstevel@tonic-gate 	    // Open the URL.
840Sstevel@tonic-gate 
850Sstevel@tonic-gate 	    URL url = new URL(urlName);
860Sstevel@tonic-gate 
870Sstevel@tonic-gate 	    // Open an input stream on the URL.
880Sstevel@tonic-gate 
890Sstevel@tonic-gate 	    is = url.openStream();
900Sstevel@tonic-gate 
910Sstevel@tonic-gate 	    // Initialize the verifier, by parsing the file.
920Sstevel@tonic-gate 
930Sstevel@tonic-gate 	    super.initialize(new InputStreamReader(is));
940Sstevel@tonic-gate 
950Sstevel@tonic-gate 	} catch (MalformedURLException ex) {
960Sstevel@tonic-gate 
970Sstevel@tonic-gate 	    throw
980Sstevel@tonic-gate 		new ServiceLocationException(
990Sstevel@tonic-gate 				ServiceLocationException.INTERNAL_SYSTEM_ERROR,
1000Sstevel@tonic-gate 				"invalid_url",
1010Sstevel@tonic-gate 				new Object[] {urlName});
1020Sstevel@tonic-gate 
1030Sstevel@tonic-gate 	} catch (IOException ex) {
1040Sstevel@tonic-gate 
1050Sstevel@tonic-gate 	    throw
1060Sstevel@tonic-gate 	  new ServiceLocationException(
1070Sstevel@tonic-gate 				ServiceLocationException.INTERNAL_SYSTEM_ERROR,
1080Sstevel@tonic-gate 				"url_ioexception",
1090Sstevel@tonic-gate 				new Object[] { urlName, ex.getMessage()});
1100Sstevel@tonic-gate 
1110Sstevel@tonic-gate 	}
1120Sstevel@tonic-gate 
1130Sstevel@tonic-gate 	try {
1140Sstevel@tonic-gate 
1150Sstevel@tonic-gate 	    is.close();
1160Sstevel@tonic-gate 
1170Sstevel@tonic-gate 	} catch (IOException ex) {
1180Sstevel@tonic-gate 
1190Sstevel@tonic-gate 	}
1200Sstevel@tonic-gate 
1210Sstevel@tonic-gate     }
1220Sstevel@tonic-gate }
123