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