feat(jdk8): move files to new folder to avoid resources compiled.
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.ws.policy.privateutil;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Utility class to invoke sun.reflect.misc.MethodUtil.invoke() if available. If not (other then Oracle JDK) fallbacks
|
||||
* to java.lang,reflect.Method.invoke()
|
||||
*/
|
||||
class MethodUtil {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(MethodUtil.class.getName());
|
||||
private static final Method INVOKE_METHOD;
|
||||
|
||||
static {
|
||||
Method method;
|
||||
try {
|
||||
Class<?> clazz = Class.forName("sun.reflect.misc.MethodUtil");
|
||||
method = clazz.getMethod("invoke", Method.class, Object.class, Object[].class);
|
||||
if (LOGGER.isLoggable(Level.FINE)) {
|
||||
LOGGER.log(Level.FINE, "Class sun.reflect.misc.MethodUtil found; it will be used to invoke methods.");
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
method = null;
|
||||
if (LOGGER.isLoggable(Level.FINE)) {
|
||||
LOGGER.log(Level.FINE, "Class sun.reflect.misc.MethodUtil not found, probably non-Oracle JVM");
|
||||
}
|
||||
}
|
||||
INVOKE_METHOD = method;
|
||||
}
|
||||
|
||||
static Object invoke(Object target, Method method, Object[] args) throws IllegalAccessException, InvocationTargetException {
|
||||
if (INVOKE_METHOD != null) {
|
||||
// sun.reflect.misc.MethodUtil.invoke(method, owner, args)
|
||||
if (LOGGER.isLoggable(Level.FINE)) {
|
||||
LOGGER.log(Level.FINE, "Invoking method using sun.reflect.misc.MethodUtil");
|
||||
}
|
||||
try {
|
||||
return INVOKE_METHOD.invoke(null, method, target, args);
|
||||
} catch (InvocationTargetException ite) {
|
||||
// unwrap invocation exception added by reflection code ...
|
||||
throw unwrapException(ite);
|
||||
}
|
||||
} else {
|
||||
// other then Oracle JDK ...
|
||||
if (LOGGER.isLoggable(Level.FINE)) {
|
||||
LOGGER.log(Level.FINE, "Invoking method directly, probably non-Oracle JVM");
|
||||
}
|
||||
return method.invoke(target, args);
|
||||
}
|
||||
}
|
||||
|
||||
private static InvocationTargetException unwrapException(InvocationTargetException ite) {
|
||||
Throwable targetException = ite.getTargetException();
|
||||
if (targetException != null && targetException instanceof InvocationTargetException) {
|
||||
if (LOGGER.isLoggable(Level.FINE)) {
|
||||
LOGGER.log(Level.FINE, "Unwrapping invocation target exception");
|
||||
}
|
||||
return (InvocationTargetException) targetException;
|
||||
} else {
|
||||
return ite;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.ws.policy.privateutil;
|
||||
|
||||
import com.sun.istack.internal.logging.Logger;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
* This is a helper class that provides some conveniece methods wrapped around the
|
||||
* standard {@link java.util.logging.Logger} interface.
|
||||
*
|
||||
* @author Marek Potociar
|
||||
* @author Fabian Ritzmann
|
||||
*/
|
||||
public final class PolicyLogger extends Logger {
|
||||
|
||||
/**
|
||||
* If we run with JAX-WS, we are using its logging domain (appended with ".wspolicy").
|
||||
* Otherwise we default to "wspolicy".
|
||||
*/
|
||||
private static final String POLICY_PACKAGE_ROOT = "com.sun.xml.internal.ws.policy";
|
||||
|
||||
/**
|
||||
* Make sure this class cannot be instantiated by client code.
|
||||
*
|
||||
* @param policyLoggerName The name of the subsystem to be logged.
|
||||
* @param className The fully qualified class name.
|
||||
*/
|
||||
private PolicyLogger(final String policyLoggerName, final String className) {
|
||||
super(policyLoggerName, className);
|
||||
}
|
||||
|
||||
/**
|
||||
* The factory method returns preconfigured PolicyLogger wrapper for the class. Since there is no caching implemented,
|
||||
* it is advised that the method is called only once per a class in order to initialize a final static logger variable,
|
||||
* which is then used through the class to perform actual logging tasks.
|
||||
*
|
||||
* @param componentClass class of the component that will use the logger instance. Must not be {@code null}.
|
||||
* @return logger instance preconfigured for use with the component
|
||||
* @throws NullPointerException if the componentClass parameter is {@code null}.
|
||||
*/
|
||||
public static PolicyLogger getLogger(final Class<?> componentClass) {
|
||||
final String componentClassName = componentClass.getName();
|
||||
|
||||
if (componentClassName.startsWith(POLICY_PACKAGE_ROOT)) {
|
||||
return new PolicyLogger(getLoggingSubsystemName() + componentClassName.substring(POLICY_PACKAGE_ROOT.length()),
|
||||
componentClassName);
|
||||
} else {
|
||||
return new PolicyLogger(getLoggingSubsystemName() + "." + componentClassName, componentClassName);
|
||||
}
|
||||
}
|
||||
|
||||
private static String getLoggingSubsystemName() {
|
||||
String loggingSubsystemName = "wspolicy";
|
||||
try {
|
||||
// Looking up JAX-WS class at run-time, so that we don't need to depend
|
||||
// on it at compile-time.
|
||||
Class jaxwsConstants = Class.forName("com.sun.xml.internal.ws.util.Constants");
|
||||
Field loggingDomainField = jaxwsConstants.getField("LoggingDomain");
|
||||
Object loggingDomain = loggingDomainField.get(null);
|
||||
loggingSubsystemName = loggingDomain.toString().concat(".wspolicy");
|
||||
} catch (RuntimeException e) {
|
||||
// if we catch an exception, we stick with the default name
|
||||
// this catch is redundant but works around a Findbugs warning
|
||||
} catch (Exception e) {
|
||||
// if we catch an exception, we stick with the default name
|
||||
}
|
||||
return loggingSubsystemName;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,480 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.ws.policy.privateutil;
|
||||
|
||||
import com.sun.xml.internal.ws.policy.PolicyException;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
|
||||
/**
|
||||
* This is a wrapper class for various utilities that may be reused within Policy API implementation.
|
||||
* The class is not part of public Policy API. Do not use it from your client code!
|
||||
*
|
||||
* @author Marek Potociar
|
||||
*/
|
||||
public final class PolicyUtils {
|
||||
private PolicyUtils() { }
|
||||
|
||||
public static class Commons {
|
||||
/**
|
||||
* Method returns the name of the method that is on the {@code methodIndexInStack}
|
||||
* position in the call stack of the current {@link Thread}.
|
||||
*
|
||||
* @param methodIndexInStack index to the call stack to get the method name for.
|
||||
* @return the name of the method that is on the {@code methodIndexInStack}
|
||||
* position in the call stack of the current {@link Thread}.
|
||||
*/
|
||||
public static String getStackMethodName(final int methodIndexInStack) {
|
||||
final String methodName;
|
||||
|
||||
final StackTraceElement[] stack = Thread.currentThread().getStackTrace();
|
||||
if (stack.length > methodIndexInStack + 1) {
|
||||
methodName = stack[methodIndexInStack].getMethodName();
|
||||
} else {
|
||||
methodName = "UNKNOWN METHOD";
|
||||
}
|
||||
|
||||
return methodName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function returns the name of the caller method for the method executing this
|
||||
* function.
|
||||
*
|
||||
* @return caller method name from the call stack of the current {@link Thread}.
|
||||
*/
|
||||
public static String getCallerMethodName() {
|
||||
String result = getStackMethodName(5);
|
||||
if (result.equals("invoke0")) {
|
||||
// We are likely running on Mac OS X, which returns a shorter stack trace
|
||||
result = getStackMethodName(4);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public static class IO {
|
||||
private static final PolicyLogger LOGGER = PolicyLogger.getLogger(PolicyUtils.IO.class);
|
||||
|
||||
/**
|
||||
* If the {@code resource} is not {@code null}, this method will try to close the
|
||||
* {@code resource} instance and log warning about any unexpected
|
||||
* {@link IOException} that may occur.
|
||||
*
|
||||
* @param resource resource to be closed
|
||||
*/
|
||||
public static void closeResource(Closeable resource) {
|
||||
if (resource != null) {
|
||||
try {
|
||||
resource.close();
|
||||
} catch (IOException e) {
|
||||
LOGGER.warning(LocalizationMessages.WSP_0023_UNEXPECTED_ERROR_WHILE_CLOSING_RESOURCE(resource.toString()), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If the {@code reader} is not {@code null}, this method will try to close the
|
||||
* {@code reader} instance and log warning about any unexpected
|
||||
* {@link IOException} that may occur.
|
||||
*
|
||||
* @param reader resource to be closed
|
||||
*/
|
||||
public static void closeResource(XMLStreamReader reader) {
|
||||
if (reader != null) {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (XMLStreamException e) {
|
||||
LOGGER.warning(LocalizationMessages.WSP_0023_UNEXPECTED_ERROR_WHILE_CLOSING_RESOURCE(reader.toString()), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Text utilities wrapper.
|
||||
*/
|
||||
public static class Text {
|
||||
/**
|
||||
* System-specific line separator character retrieved from the Java system property
|
||||
* <code>line.separator</code>
|
||||
*/
|
||||
public final static String NEW_LINE = System.getProperty("line.separator");
|
||||
|
||||
/**
|
||||
* Method creates indent string consisting of as many {@code TAB} characters as specified by {@code indentLevel} parameter
|
||||
*
|
||||
* @param indentLevel indentation level
|
||||
* @return indentation string as specified by indentation level
|
||||
*
|
||||
*/
|
||||
public static String createIndent(final int indentLevel) {
|
||||
final char[] charData = new char[indentLevel * 4];
|
||||
Arrays.fill(charData, ' ');
|
||||
return String.valueOf(charData);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Comparison {
|
||||
/**
|
||||
* The comparator comapres QName objects according to their publicly accessible attributes, in the following
|
||||
* order of attributes:
|
||||
*
|
||||
* 1. namespace (not null String)
|
||||
* 2. local name (not null String)
|
||||
*/
|
||||
public static final Comparator<QName> QNAME_COMPARATOR = new Comparator<QName>() {
|
||||
public int compare(final QName qn1, final QName qn2) {
|
||||
if (qn1 == qn2 || qn1.equals(qn2)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int result;
|
||||
|
||||
result = qn1.getNamespaceURI().compareTo(qn2.getNamespaceURI());
|
||||
if (result != 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
return qn1.getLocalPart().compareTo(qn2.getLocalPart());
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Compares two boolean values in the following way: {@code false < true}
|
||||
*
|
||||
* @return {@code -1} if {@code b1 < b2}, {@code 0} if {@code b1 == b2}, {@code 1} if {@code b1 > b2}
|
||||
*/
|
||||
public static int compareBoolean(final boolean b1, final boolean b2) {
|
||||
final int i1 = (b1) ? 1 : 0;
|
||||
final int i2 = (b2) ? 1 : 0;
|
||||
|
||||
return i1 - i2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares two String values, that may possibly be null in the following way: {@code null < "string value"}
|
||||
*
|
||||
* @return {@code -1} if {@code s1 < s2}, {@code 0} if {@code s1 == s2}, {@code 1} if {@code s1 > s2}
|
||||
*/
|
||||
public static int compareNullableStrings(final String s1, final String s2) {
|
||||
return ((s1 == null) ? ((s2 == null) ? 0 : -1) : ((s2 == null) ? 1 : s1.compareTo(s2)));
|
||||
}
|
||||
}
|
||||
|
||||
public static class Collections {
|
||||
/**
|
||||
* TODO javadocs
|
||||
*
|
||||
* @param initialBase the combination base that will be present in each combination. May be {@code null} or empty.
|
||||
* @param options options that should be combined. May be {@code null} or empty.
|
||||
* @param ignoreEmptyOption flag identifies whether empty options should be ignored or whether the method should halt
|
||||
* processing and return {@code null} when an empty option is encountered
|
||||
* @return TODO
|
||||
*/
|
||||
public static <E, T extends Collection<? extends E>, U extends Collection<? extends E>> Collection<Collection<E>> combine(final U initialBase, final Collection<T> options, final boolean ignoreEmptyOption) {
|
||||
List<Collection<E>> combinations = null;
|
||||
if (options == null || options.isEmpty()) {
|
||||
// no combination creation needed
|
||||
if (initialBase != null) {
|
||||
combinations = new ArrayList<Collection<E>>(1);
|
||||
combinations.add(new ArrayList<E>(initialBase));
|
||||
}
|
||||
return combinations;
|
||||
}
|
||||
|
||||
// creating defensive and modifiable copy of the base
|
||||
final Collection<E> base = new LinkedList<E>();
|
||||
if (initialBase != null && !initialBase.isEmpty()) {
|
||||
base.addAll(initialBase);
|
||||
}
|
||||
/**
|
||||
* now we iterate over all options and build up an option processing queue:
|
||||
* 1. if ignoreEmptyOption flag is not set and we found an empty option, we are going to stop processing and return null. Otherwise we
|
||||
* ignore the empty option.
|
||||
* 2. if the option has one child only, we add the child directly to the base.
|
||||
* 3. if there are more children in examined node, we add it to the queue for further processing and precoumpute the final size of
|
||||
* resulting collection of combinations.
|
||||
*/
|
||||
int finalCombinationsSize = 1;
|
||||
final Queue<T> optionProcessingQueue = new LinkedList<T>();
|
||||
for (T option : options) {
|
||||
final int optionSize = option.size();
|
||||
|
||||
if (optionSize == 0) {
|
||||
if (!ignoreEmptyOption) {
|
||||
return null;
|
||||
}
|
||||
} else if (optionSize == 1) {
|
||||
base.addAll(option);
|
||||
} else {
|
||||
optionProcessingQueue.offer(option);
|
||||
finalCombinationsSize *= optionSize;
|
||||
}
|
||||
}
|
||||
|
||||
// creating final combinations
|
||||
combinations = new ArrayList<Collection<E>>(finalCombinationsSize);
|
||||
combinations.add(base);
|
||||
if (finalCombinationsSize > 1) {
|
||||
T processedOption;
|
||||
while ((processedOption = optionProcessingQueue.poll()) != null) {
|
||||
final int actualSemiCombinationCollectionSize = combinations.size();
|
||||
final int newSemiCombinationCollectionSize = actualSemiCombinationCollectionSize * processedOption.size();
|
||||
|
||||
int semiCombinationIndex = 0;
|
||||
for (E optionElement : processedOption) {
|
||||
for (int i = 0; i < actualSemiCombinationCollectionSize; i++) {
|
||||
final Collection<E> semiCombination = combinations.get(semiCombinationIndex); // unfinished combination
|
||||
|
||||
if (semiCombinationIndex + actualSemiCombinationCollectionSize < newSemiCombinationCollectionSize) {
|
||||
// this is not the last optionElement => we create a new combination copy for the next child
|
||||
combinations.add(new LinkedList<E>(semiCombination));
|
||||
}
|
||||
|
||||
semiCombination.add(optionElement);
|
||||
semiCombinationIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return combinations;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reflection utilities wrapper
|
||||
*/
|
||||
static class Reflection {
|
||||
private static final PolicyLogger LOGGER = PolicyLogger.getLogger(PolicyUtils.Reflection.class);
|
||||
|
||||
/**
|
||||
* Reflectively invokes specified method on the specified target
|
||||
*/
|
||||
static <T> T invoke(final Object target, final String methodName,
|
||||
final Class<T> resultClass, final Object... parameters) throws RuntimePolicyUtilsException {
|
||||
Class[] parameterTypes;
|
||||
if (parameters != null && parameters.length > 0) {
|
||||
parameterTypes = new Class[parameters.length];
|
||||
int i = 0;
|
||||
for (Object parameter : parameters) {
|
||||
parameterTypes[i++] = parameter.getClass();
|
||||
}
|
||||
} else {
|
||||
parameterTypes = null;
|
||||
}
|
||||
|
||||
return invoke(target, methodName, resultClass, parameters, parameterTypes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reflectively invokes specified method on the specified target
|
||||
*/
|
||||
public static <T> T invoke(final Object target, final String methodName, final Class<T> resultClass,
|
||||
final Object[] parameters, final Class[] parameterTypes) throws RuntimePolicyUtilsException {
|
||||
try {
|
||||
final Method method = target.getClass().getMethod(methodName, parameterTypes);
|
||||
final Object result = MethodUtil.invoke(target, method,parameters);
|
||||
|
||||
return resultClass.cast(result);
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw LOGGER.logSevereException(new RuntimePolicyUtilsException(createExceptionMessage(target, parameters, methodName), e));
|
||||
} catch (InvocationTargetException e) {
|
||||
throw LOGGER.logSevereException(new RuntimePolicyUtilsException(createExceptionMessage(target, parameters, methodName), e));
|
||||
} catch (IllegalAccessException e) {
|
||||
throw LOGGER.logSevereException(new RuntimePolicyUtilsException(createExceptionMessage(target, parameters, methodName), e.getCause()));
|
||||
} catch (SecurityException e) {
|
||||
throw LOGGER.logSevereException(new RuntimePolicyUtilsException(createExceptionMessage(target, parameters, methodName), e));
|
||||
} catch (NoSuchMethodException e) {
|
||||
throw LOGGER.logSevereException(new RuntimePolicyUtilsException(createExceptionMessage(target, parameters, methodName), e));
|
||||
}
|
||||
}
|
||||
|
||||
private static String createExceptionMessage(final Object target, final Object[] parameters, final String methodName) {
|
||||
return LocalizationMessages.WSP_0061_METHOD_INVOCATION_FAILED(target.getClass().getName(), methodName,
|
||||
parameters == null ? null : Arrays.asList(parameters).toString());
|
||||
}
|
||||
}
|
||||
|
||||
public static class ConfigFile {
|
||||
/**
|
||||
* Generates a config file resource name from provided config file identifier.
|
||||
* The generated file name can be transformed into a URL instance using
|
||||
* {@link #loadFromContext(String, Object)} or {@link #loadFromClasspath(String)}
|
||||
* method.
|
||||
*
|
||||
* @param configFileIdentifier the string used to generate the config file URL that will be parsed. Each WSIT config
|
||||
* file is in form of <code>wsit-<i>{configFileIdentifier}</i>.xml</code>. Must not be {@code null}.
|
||||
* @return generated config file resource name
|
||||
* @throw PolicyException If configFileIdentifier is null.
|
||||
*/
|
||||
public static String generateFullName(final String configFileIdentifier) throws PolicyException {
|
||||
if (configFileIdentifier != null) {
|
||||
final StringBuffer buffer = new StringBuffer("wsit-");
|
||||
buffer.append(configFileIdentifier).append(".xml");
|
||||
return buffer.toString();
|
||||
} else {
|
||||
throw new PolicyException(LocalizationMessages.WSP_0080_IMPLEMENTATION_EXPECTED_NOT_NULL());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a URL pointing to the given config file. The file name is
|
||||
* looked up as a resource from a ServletContext.
|
||||
*
|
||||
* May return null if the file can not be found.
|
||||
*
|
||||
* @param configFileName The name of the file resource
|
||||
* @param context A ServletContext object. May not be null.
|
||||
*/
|
||||
public static URL loadFromContext(final String configFileName, final Object context) {
|
||||
return Reflection.invoke(context, "getResource", URL.class, configFileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a URL pointing to the given config file. The file is looked up as
|
||||
* a resource on the classpath.
|
||||
*
|
||||
* May return null if the file can not be found.
|
||||
*
|
||||
* @param configFileName the name of the file resource. May not be {@code null}.
|
||||
*/
|
||||
public static URL loadFromClasspath(final String configFileName) {
|
||||
final ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||
if (cl == null) {
|
||||
return ClassLoader.getSystemResource(configFileName);
|
||||
} else {
|
||||
return cl.getResource(configFileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for ServiceFinder class which is not part of the Java SE yet.
|
||||
*/
|
||||
public static class ServiceProvider {
|
||||
/**
|
||||
* Locates and incrementally instantiates the available providers of a
|
||||
* given service using the given class loader.
|
||||
* <p/>
|
||||
* <p> This method transforms the name of the given service class into a
|
||||
* provider-configuration filename as described above and then uses the
|
||||
* <tt>getResources</tt> method of the given class loader to find all
|
||||
* available files with that name. These files are then read and parsed to
|
||||
* produce a list of provider-class names. Eventually each provider class is
|
||||
* instantiated and array of those instances is returned.
|
||||
* <p/>
|
||||
* <p> Because it is possible for extensions to be installed into a running
|
||||
* Java virtual machine, this method may return different results each time
|
||||
* it is invoked. <p>
|
||||
*
|
||||
* @param serviceClass The service's abstract service class. Must not be {@code null}.
|
||||
* @param loader The class loader to be used to load provider-configuration files
|
||||
* and instantiate provider classes, or <tt>null</tt> if the system
|
||||
* class loader (or, failing that the bootstrap class loader) is to
|
||||
* be used
|
||||
* @throws NullPointerException in case {@code service} input parameter is {@code null}.
|
||||
* @throws ServiceConfigurationError If a provider-configuration file violates the specified format
|
||||
* or names a provider class that cannot be found and instantiated
|
||||
* @see #load(Class)
|
||||
*/
|
||||
public static <T> T[] load(final Class<T> serviceClass, final ClassLoader loader) {
|
||||
return ServiceFinder.find(serviceClass, loader).toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Locates and incrementally instantiates the available providers of a
|
||||
* given service using the context class loader. This convenience method
|
||||
* is equivalent to
|
||||
* <p/>
|
||||
* <pre>
|
||||
* ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||
* return PolicyUtils.ServiceProvider.load(service, cl);
|
||||
* </pre>
|
||||
*
|
||||
* @param serviceClass The service's abstract service class. Must not be {@code null}.
|
||||
*
|
||||
* @throws NullPointerException in case {@code service} input parameter is {@code null}.
|
||||
* @throws ServiceConfigurationError If a provider-configuration file violates the specified format
|
||||
* or names a provider class that cannot be found and instantiated
|
||||
* @see #load(Class, ClassLoader)
|
||||
*/
|
||||
public static <T> T[] load(final Class<T> serviceClass) {
|
||||
return ServiceFinder.find(serviceClass).toArray();
|
||||
}
|
||||
}
|
||||
|
||||
public static class Rfc2396 {
|
||||
|
||||
private static final PolicyLogger LOGGER = PolicyLogger.getLogger(PolicyUtils.Reflection.class);
|
||||
|
||||
// converts "hello%20world" into "hello world"
|
||||
public static String unquote(final String quoted) {
|
||||
if (null == quoted) {
|
||||
return null;
|
||||
}
|
||||
final byte[] unquoted = new byte[quoted.length()]; // result cannot be longer than original string
|
||||
int newLength = 0;
|
||||
char c;
|
||||
int hi, lo;
|
||||
for (int i=0; i < quoted.length(); i++) { // iterarate over all chars in the input
|
||||
c = quoted.charAt(i);
|
||||
if ('%' == c) { // next escape sequence found
|
||||
if ((i + 2) >= quoted.length()) {
|
||||
throw LOGGER.logSevereException(new RuntimePolicyUtilsException(LocalizationMessages.WSP_0079_ERROR_WHILE_RFC_2396_UNESCAPING(quoted)), false);
|
||||
}
|
||||
hi = Character.digit(quoted.charAt(++i), 16);
|
||||
lo = Character.digit(quoted.charAt(++i), 16);
|
||||
if ((0 > hi) || (0 > lo)) {
|
||||
throw LOGGER.logSevereException(new RuntimePolicyUtilsException(LocalizationMessages.WSP_0079_ERROR_WHILE_RFC_2396_UNESCAPING(quoted)), false);
|
||||
}
|
||||
unquoted[newLength++] = (byte) (hi * 16 + lo);
|
||||
} else { // regular character found
|
||||
unquoted[newLength++] = (byte) c;
|
||||
}
|
||||
}
|
||||
try {
|
||||
return new String(unquoted, 0, newLength, "utf-8");
|
||||
} catch (UnsupportedEncodingException uee) {
|
||||
throw LOGGER.logSevereException(new RuntimePolicyUtilsException(LocalizationMessages.WSP_0079_ERROR_WHILE_RFC_2396_UNESCAPING(quoted), uee));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.ws.policy.privateutil;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Marek Potociar (marek.potociar at sun.com)
|
||||
*/
|
||||
public final class RuntimePolicyUtilsException extends RuntimeException {
|
||||
|
||||
RuntimePolicyUtilsException(final String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
RuntimePolicyUtilsException(final String message, final Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.ws.policy.privateutil;
|
||||
|
||||
/**
|
||||
* Error thrown when something goes wrong while looking up service providers.
|
||||
* In particular, this error will be thrown in the following situations:
|
||||
*
|
||||
* <ul>
|
||||
* <li> A concrete provider class cannot be found,
|
||||
* <li> A concrete provider class cannot be instantiated,
|
||||
* <li> The format of a provider-configuration file is illegal, or
|
||||
* <li> An IOException occurs while reading a provider-configuration file.
|
||||
* </ul>
|
||||
*
|
||||
* @author Mark Reinhold
|
||||
* @version 1.7, 03/12/19
|
||||
* @since 1.3
|
||||
*/
|
||||
public class ServiceConfigurationError extends Error {
|
||||
|
||||
/**
|
||||
* Constructs a new instance with the specified detail string.
|
||||
*/
|
||||
public ServiceConfigurationError(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new instance that wraps the specified throwable.
|
||||
*/
|
||||
public ServiceConfigurationError(Throwable throwable) {
|
||||
super(throwable);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,380 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.ws.policy.privateutil;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Array;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* A simple service-provider lookup mechanism. A <i>service</i> is a
|
||||
* well-known set of interfaces and (usually abstract) classes. A <i>service
|
||||
* provider</i> is a specific implementation of a service. The classes in a
|
||||
* provider typically implement the interfaces and subclass the classes defined
|
||||
* in the service itself. Service providers may be installed in an
|
||||
* implementation of the Java platform in the form of extensions, that is, jar
|
||||
* files placed into any of the usual extension directories. Providers may
|
||||
* also be made available by adding them to the applet or application class
|
||||
* path or by some other platform-specific means.
|
||||
* <p/>
|
||||
* <p> In this lookup mechanism a service is represented by an interface or an
|
||||
* abstract class. (A concrete class may be used, but this is not
|
||||
* recommended.) A provider of a given service contains one or more concrete
|
||||
* classes that extend this <i>service class</i> with data and code specific to
|
||||
* the provider. This <i>provider class</i> will typically not be the entire
|
||||
* provider itself but rather a proxy that contains enough information to
|
||||
* decide whether the provider is able to satisfy a particular request together
|
||||
* with code that can create the actual provider on demand. The details of
|
||||
* provider classes tend to be highly service-specific; no single class or
|
||||
* interface could possibly unify them, so no such class has been defined. The
|
||||
* only requirement enforced here is that provider classes must have a
|
||||
* zero-argument constructor so that they may be instantiated during lookup.
|
||||
* <p/>
|
||||
* <p> A service provider identifies itself by placing a provider-configuration
|
||||
* file in the resource directory <tt>META-INF/services</tt>. The file's name
|
||||
* should consist of the fully-qualified name of the abstract service class.
|
||||
* The file should contain a list of fully-qualified concrete provider-class
|
||||
* names, one per line. Space and tab characters surrounding each name, as
|
||||
* well as blank lines, are ignored. The comment character is <tt>'#'</tt>
|
||||
* (<tt>0x23</tt>); on each line all characters following the first comment
|
||||
* character are ignored. The file must be encoded in UTF-8.
|
||||
* <p/>
|
||||
* <p> If a particular concrete provider class is named in more than one
|
||||
* configuration file, or is named in the same configuration file more than
|
||||
* once, then the duplicates will be ignored. The configuration file naming a
|
||||
* particular provider need not be in the same jar file or other distribution
|
||||
* unit as the provider itself. The provider must be accessible from the same
|
||||
* class loader that was initially queried to locate the configuration file;
|
||||
* note that this is not necessarily the class loader that found the file.
|
||||
* <p/>
|
||||
* <p> <b>Example:</b> Suppose we have a service class named
|
||||
* <tt>java.io.spi.CharCodec</tt>. It has two abstract methods:
|
||||
* <p/>
|
||||
* <pre>
|
||||
* public abstract CharEncoder getEncoder(String encodingName);
|
||||
* public abstract CharDecoder getDecoder(String encodingName);
|
||||
* </pre>
|
||||
* <p/>
|
||||
* Each method returns an appropriate object or <tt>null</tt> if it cannot
|
||||
* translate the given encoding. Typical <tt>CharCodec</tt> providers will
|
||||
* support more than one encoding.
|
||||
* <p/>
|
||||
* <p> If <tt>sun.io.StandardCodec</tt> is a provider of the <tt>CharCodec</tt>
|
||||
* service then its jar file would contain the file
|
||||
* <tt>META-INF/services/java.io.spi.CharCodec</tt>. This file would contain
|
||||
* the single line:
|
||||
* <p/>
|
||||
* <pre>
|
||||
* sun.io.StandardCodec # Standard codecs for the platform
|
||||
* </pre>
|
||||
* <p/>
|
||||
* To locate an encoder for a given encoding name, the internal I/O code would
|
||||
* do something like this:
|
||||
* <p/>
|
||||
* <pre>
|
||||
* CharEncoder getEncoder(String encodingName) {
|
||||
* for( CharCodec cc : ServiceFinder.find(CharCodec.class) ) {
|
||||
* CharEncoder ce = cc.getEncoder(encodingName);
|
||||
* if (ce != null)
|
||||
* return ce;
|
||||
* }
|
||||
* return null;
|
||||
* }
|
||||
* </pre>
|
||||
* <p/>
|
||||
* The provider-lookup mechanism always executes in the security context of the
|
||||
* caller. Trusted system code should typically invoke the methods in this
|
||||
* class from within a privileged security context.
|
||||
*
|
||||
* @author Mark Reinhold
|
||||
* @version 1.11, 03/12/19
|
||||
* @since 1.3
|
||||
*/
|
||||
final class ServiceFinder<T> implements Iterable<T> {
|
||||
private static final PolicyLogger LOGGER = PolicyLogger.getLogger(ServiceFinder.class);
|
||||
|
||||
private static final String prefix = "META-INF/services/";
|
||||
|
||||
private final Class<T> serviceClass;
|
||||
private final ClassLoader classLoader;
|
||||
|
||||
/**
|
||||
* Locates and incrementally instantiates the available providers of a
|
||||
* given service using the given class loader.
|
||||
* <p/>
|
||||
* <p> This method transforms the name of the given service class into a
|
||||
* provider-configuration filename as described above and then uses the
|
||||
* <tt>getResources</tt> method of the given class loader to find all
|
||||
* available files with that name. These files are then read and parsed to
|
||||
* produce a list of provider-class names. The iterator that is returned
|
||||
* uses the given class loader to lookup and then instantiate each element
|
||||
* of the list.
|
||||
* <p/>
|
||||
* <p> Because it is possible for extensions to be installed into a running
|
||||
* Java virtual machine, this method may return different results each time
|
||||
* it is invoked. <p>
|
||||
*
|
||||
* @param service The service's abstract service class
|
||||
* @param loader The class loader to be used to load provider-configuration files
|
||||
* and instantiate provider classes, or <tt>null</tt> if the system
|
||||
* class loader (or, failing that the bootstrap class loader) is to
|
||||
* be used
|
||||
* @throws ServiceConfigurationError If a provider-configuration file violates the specified format
|
||||
* or names a provider class that cannot be found and instantiated
|
||||
* @see #find(Class)
|
||||
*/
|
||||
static <T> ServiceFinder<T> find(final Class<T> service, final ClassLoader loader) {
|
||||
if (null==service) {
|
||||
throw LOGGER.logSevereException(new NullPointerException(LocalizationMessages.WSP_0032_SERVICE_CAN_NOT_BE_NULL()));
|
||||
}
|
||||
return new ServiceFinder<T>(service,loader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Locates and incrementally instantiates the available providers of a
|
||||
* given service using the context class loader. This convenience method
|
||||
* is equivalent to
|
||||
* <p/>
|
||||
* <pre>
|
||||
* ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||
* return Service.providers(service, cl);
|
||||
* </pre>
|
||||
*
|
||||
* @param service The service's abstract service class
|
||||
*
|
||||
* @throws ServiceConfigurationError If a provider-configuration file violates the specified format
|
||||
* or names a provider class that cannot be found and instantiated
|
||||
* @see #find(Class, ClassLoader)
|
||||
*/
|
||||
public static <T> ServiceFinder<T> find(final Class<T> service) {
|
||||
return find(service,Thread.currentThread().getContextClassLoader());
|
||||
}
|
||||
|
||||
private ServiceFinder(Class<T> service, ClassLoader loader) {
|
||||
this.serviceClass = service;
|
||||
this.classLoader = loader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns discovered objects incrementally.
|
||||
*
|
||||
* @return An <tt>Iterator</tt> that yields provider objects for the given
|
||||
* service, in some arbitrary order. The iterator will throw a
|
||||
* <tt>ServiceConfigurationError</tt> if a provider-configuration
|
||||
* file violates the specified format or if a provider class cannot
|
||||
* be found and instantiated.
|
||||
*/
|
||||
public Iterator<T> iterator() {
|
||||
return new LazyIterator<T>(serviceClass,classLoader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns discovered objects all at once.
|
||||
*
|
||||
* @return
|
||||
* can be empty but never null.
|
||||
*
|
||||
* @throws ServiceConfigurationError
|
||||
*/
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public T[] toArray() {
|
||||
List<T> result = new ArrayList<T>();
|
||||
for (T t : this) {
|
||||
result.add(t);
|
||||
}
|
||||
return result.toArray((T[])Array.newInstance(serviceClass,result.size()));
|
||||
}
|
||||
|
||||
private static void fail(final Class service, final String msg, final Throwable cause)
|
||||
throws ServiceConfigurationError {
|
||||
final ServiceConfigurationError sce
|
||||
= new ServiceConfigurationError(LocalizationMessages.WSP_0025_SPI_FAIL_SERVICE_MSG(service.getName(), msg));
|
||||
if (null != cause) {
|
||||
sce.initCause(cause);
|
||||
}
|
||||
|
||||
throw LOGGER.logSevereException(sce);
|
||||
}
|
||||
|
||||
/* private static void fail(Class service, String msg)
|
||||
throws ServiceConfigurationError {
|
||||
throw new ServiceConfigurationError(LocalizationMessages.WSP_0025_SPI_FAIL_SERVICE_MSG(service.getName(), msg));
|
||||
}*/
|
||||
|
||||
private static void fail(final Class service, final URL u, final int line, final String msg, final Throwable cause)
|
||||
throws ServiceConfigurationError {
|
||||
fail(service, LocalizationMessages.WSP_0024_SPI_FAIL_SERVICE_URL_LINE_MSG(u , line, msg), cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a single line from the given configuration file, adding the name
|
||||
* on the line to both the names list and the returned set iff the name is
|
||||
* not already a member of the returned set.
|
||||
*/
|
||||
private static int parseLine(final Class service, final URL u, final BufferedReader r, final int lc,
|
||||
final List<String> names, final Set<String> returned)
|
||||
throws IOException, ServiceConfigurationError {
|
||||
String ln = r.readLine();
|
||||
if (ln == null) {
|
||||
return -1;
|
||||
}
|
||||
final int ci = ln.indexOf('#');
|
||||
if (ci >= 0) ln = ln.substring(0, ci);
|
||||
ln = ln.trim();
|
||||
final int n = ln.length();
|
||||
if (n != 0) {
|
||||
if ((ln.indexOf(' ') >= 0) || (ln.indexOf('\t') >= 0))
|
||||
fail(service, u, lc, LocalizationMessages.WSP_0067_ILLEGAL_CFG_FILE_SYNTAX(), null);
|
||||
int cp = ln.codePointAt(0);
|
||||
if (!Character.isJavaIdentifierStart(cp))
|
||||
fail(service, u, lc, LocalizationMessages.WSP_0066_ILLEGAL_PROVIDER_CLASSNAME(ln), null);
|
||||
for (int i = Character.charCount(cp); i < n; i += Character.charCount(cp)) {
|
||||
cp = ln.codePointAt(i);
|
||||
if (!Character.isJavaIdentifierPart(cp) && (cp != '.'))
|
||||
fail(service, u, lc, LocalizationMessages.WSP_0066_ILLEGAL_PROVIDER_CLASSNAME(ln), null);
|
||||
}
|
||||
if (!returned.contains(ln)) {
|
||||
names.add(ln);
|
||||
returned.add(ln);
|
||||
}
|
||||
}
|
||||
return lc + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the content of the given URL as a provider-configuration file.
|
||||
*
|
||||
* @param service The service class for which providers are being sought;
|
||||
* used to construct error detail strings
|
||||
* @param u The URL naming the configuration file to be parsed
|
||||
* @param returned A Set containing the names of provider classes that have already
|
||||
* been returned. This set will be updated to contain the names
|
||||
* that will be yielded from the returned <tt>Iterator</tt>.
|
||||
* @return A (possibly empty) <tt>Iterator</tt> that will yield the
|
||||
* provider-class names in the given configuration file that are
|
||||
* not yet members of the returned set
|
||||
* @throws ServiceConfigurationError If an I/O error occurs while reading from the given URL, or
|
||||
* if a configuration-file format error is detected
|
||||
*/
|
||||
@SuppressWarnings({"StatementWithEmptyBody"})
|
||||
private static Iterator<String> parse(Class service, URL u, Set<String> returned)
|
||||
throws ServiceConfigurationError {
|
||||
InputStream in = null;
|
||||
BufferedReader r = null;
|
||||
ArrayList<String> names = new ArrayList<String>();
|
||||
try {
|
||||
in = u.openStream();
|
||||
r = new BufferedReader(new InputStreamReader(in, "utf-8"));
|
||||
int lc = 1;
|
||||
while ((lc = parseLine(service, u, r, lc, names, returned)) >= 0) ;
|
||||
} catch (IOException x) {
|
||||
fail(service, ": " + x, x);
|
||||
} finally {
|
||||
try {
|
||||
if (r != null) r.close();
|
||||
if (in != null) in.close();
|
||||
} catch (IOException y) {
|
||||
fail(service, ": " + y, y);
|
||||
}
|
||||
}
|
||||
return names.iterator();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Private inner class implementing fully-lazy provider lookup
|
||||
*/
|
||||
private static class LazyIterator<T> implements Iterator<T> {
|
||||
Class<T> service;
|
||||
ClassLoader loader;
|
||||
Enumeration<URL> configs = null;
|
||||
Iterator<String> pending = null;
|
||||
Set<String> returned = new TreeSet<String>();
|
||||
String nextName = null;
|
||||
|
||||
private LazyIterator(Class<T> service, ClassLoader loader) {
|
||||
this.service = service;
|
||||
this.loader = loader;
|
||||
}
|
||||
|
||||
public boolean hasNext() throws ServiceConfigurationError {
|
||||
if (nextName != null) {
|
||||
return true;
|
||||
}
|
||||
if (configs == null) {
|
||||
try {
|
||||
final String fullName = prefix + service.getName();
|
||||
if (loader == null)
|
||||
configs = ClassLoader.getSystemResources(fullName);
|
||||
else
|
||||
configs = loader.getResources(fullName);
|
||||
} catch (IOException x) {
|
||||
fail(service, ": " + x, x);
|
||||
}
|
||||
}
|
||||
while ((pending == null) || !pending.hasNext()) {
|
||||
if (!configs.hasMoreElements()) {
|
||||
return false;
|
||||
}
|
||||
pending = parse(service, configs.nextElement(), returned);
|
||||
}
|
||||
nextName = pending.next();
|
||||
return true;
|
||||
}
|
||||
|
||||
public T next() throws ServiceConfigurationError {
|
||||
if (!hasNext()) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
final String cn = nextName;
|
||||
nextName = null;
|
||||
try {
|
||||
return service.cast(Class.forName(cn, true, loader).newInstance());
|
||||
} catch (ClassNotFoundException x) {
|
||||
fail(service, LocalizationMessages.WSP_0027_SERVICE_PROVIDER_NOT_FOUND(cn), x);
|
||||
} catch (Exception x) {
|
||||
fail(service, LocalizationMessages.WSP_0028_SERVICE_PROVIDER_COULD_NOT_BE_INSTANTIATED(cn), x);
|
||||
}
|
||||
return null; /* This cannot happen */
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This package contains utility classes that are not part of the public Policy API. None of the classes contained in this
|
||||
* package should be used outside the Policy API implementation. The creators of the Policy API will not provide any support
|
||||
* concerning usage of the classes in this package. I should be also clear that any method signatures, classes and interfaces
|
||||
* may be changed or even removed without a prior notice.
|
||||
* <p/>
|
||||
* To put it simple: <b>Do not use classes in this package, unless you are member of the WS policy implementation team!!!</b>
|
||||
*/
|
||||
package com.sun.xml.internal.ws.policy.privateutil;
|
||||
Reference in New Issue
Block a user