1 /*
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
321 * been returned. This set will be updated to contain the names
322 * that will be yielded from the returned {@code Iterator}.
323 * @return A (possibly empty) {@code Iterator} that will yield the
324 * provider-class names in the given configuration file that are
325 * not yet members of the returned set
326 * @throws ServiceConfigurationError If an I/O error occurs while reading from the given URL, or
327 * if a configuration-file format error is detected
328 */
329 @SuppressWarnings({"StatementWithEmptyBody"})
330 private static Iterator<String> parse(Class service, URL u, Set<String> returned)
331 throws ServiceConfigurationError {
332 InputStream in = null;
333 BufferedReader r = null;
334 ArrayList<String> names = new ArrayList<String>();
335 try {
336 in = u.openStream();
337 r = new BufferedReader(new InputStreamReader(in, "utf-8"));
338 int lc = 1;
339 while ((lc = parseLine(service, u, r, lc, names, returned)) >= 0) ;
340 } catch (IOException x) {
341 fail(service, ": " + x);
342 } finally {
343 try {
344 if (r != null) r.close();
345 if (in != null) in.close();
346 } catch (IOException y) {
347 fail(service, ": " + y);
348 }
349 }
350 return names.iterator();
351 }
352
353 private static ComponentEx getComponentEx(Component component) {
354 if (component instanceof ComponentEx)
355 return (ComponentEx) component;
356
357 return component != null ? new ComponentExWrapper(component) : null;
358 }
359
360 private static class ComponentExWrapper implements ComponentEx {
361 private final Component component;
362
363 public ComponentExWrapper(Component component) {
364 this.component = component;
365 }
366
367 public <S> S getSPI(Class<S> spiType) {
|
1 /*
2 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
321 * been returned. This set will be updated to contain the names
322 * that will be yielded from the returned {@code Iterator}.
323 * @return A (possibly empty) {@code Iterator} that will yield the
324 * provider-class names in the given configuration file that are
325 * not yet members of the returned set
326 * @throws ServiceConfigurationError If an I/O error occurs while reading from the given URL, or
327 * if a configuration-file format error is detected
328 */
329 @SuppressWarnings({"StatementWithEmptyBody"})
330 private static Iterator<String> parse(Class service, URL u, Set<String> returned)
331 throws ServiceConfigurationError {
332 InputStream in = null;
333 BufferedReader r = null;
334 ArrayList<String> names = new ArrayList<String>();
335 try {
336 in = u.openStream();
337 r = new BufferedReader(new InputStreamReader(in, "utf-8"));
338 int lc = 1;
339 while ((lc = parseLine(service, u, r, lc, names, returned)) >= 0) ;
340 } catch (IOException x) {
341 fail(service, ": " + x +";URL is :"+u.toString());
342 } finally {
343 try {
344 if (r != null) r.close();
345 if (in != null) in.close();
346 } catch (IOException y) {
347 fail(service, ": " + y +";URL is :"+u.toString());
348 }
349 }
350 return names.iterator();
351 }
352
353 private static ComponentEx getComponentEx(Component component) {
354 if (component instanceof ComponentEx)
355 return (ComponentEx) component;
356
357 return component != null ? new ComponentExWrapper(component) : null;
358 }
359
360 private static class ComponentExWrapper implements ComponentEx {
361 private final Component component;
362
363 public ComponentExWrapper(Component component) {
364 this.component = component;
365 }
366
367 public <S> S getSPI(Class<S> spiType) {
|