src/share/jaxws_classes/com/sun/xml/internal/ws/policy/privateutil/PolicyLogger.java

changeset 0
373ffda63c9a
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/policy/privateutil/PolicyLogger.java	Wed Apr 27 01:27:09 2016 +0800
     1.3 @@ -0,0 +1,94 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package com.sun.xml.internal.ws.policy.privateutil;
    1.30 +
    1.31 +import com.sun.istack.internal.logging.Logger;
    1.32 +import java.lang.reflect.Field;
    1.33 +
    1.34 +/**
    1.35 + * This is a helper class that provides some conveniece methods wrapped around the
    1.36 + * standard {@link java.util.logging.Logger} interface.
    1.37 + *
    1.38 + * @author Marek Potociar
    1.39 + * @author Fabian Ritzmann
    1.40 + */
    1.41 +public final class PolicyLogger extends Logger {
    1.42 +
    1.43 +    /**
    1.44 +     * If we run with JAX-WS, we are using its logging domain (appended with ".wspolicy").
    1.45 +     * Otherwise we default to "wspolicy".
    1.46 +     */
    1.47 +    private static final String POLICY_PACKAGE_ROOT = "com.sun.xml.internal.ws.policy";
    1.48 +
    1.49 +    /**
    1.50 +     * Make sure this class cannot be instantiated by client code.
    1.51 +     *
    1.52 +     * @param policyLoggerName The name of the subsystem to be logged.
    1.53 +     * @param className The fully qualified class name.
    1.54 +     */
    1.55 +    private PolicyLogger(final String policyLoggerName, final String className) {
    1.56 +        super(policyLoggerName, className);
    1.57 +    }
    1.58 +
    1.59 +    /**
    1.60 +     * The factory method returns preconfigured PolicyLogger wrapper for the class. Since there is no caching implemented,
    1.61 +     * it is advised that the method is called only once per a class in order to initialize a final static logger variable,
    1.62 +     * which is then used through the class to perform actual logging tasks.
    1.63 +     *
    1.64 +     * @param componentClass class of the component that will use the logger instance. Must not be {@code null}.
    1.65 +     * @return logger instance preconfigured for use with the component
    1.66 +     * @throws NullPointerException if the componentClass parameter is {@code null}.
    1.67 +     */
    1.68 +    public static PolicyLogger getLogger(final Class<?> componentClass) {
    1.69 +        final String componentClassName = componentClass.getName();
    1.70 +
    1.71 +        if (componentClassName.startsWith(POLICY_PACKAGE_ROOT)) {
    1.72 +            return new PolicyLogger(getLoggingSubsystemName() + componentClassName.substring(POLICY_PACKAGE_ROOT.length()),
    1.73 +                    componentClassName);
    1.74 +        } else {
    1.75 +            return new PolicyLogger(getLoggingSubsystemName() + "." + componentClassName, componentClassName);
    1.76 +        }
    1.77 +    }
    1.78 +
    1.79 +    private static String getLoggingSubsystemName() {
    1.80 +        String loggingSubsystemName = "wspolicy";
    1.81 +        try {
    1.82 +            // Looking up JAX-WS class at run-time, so that we don't need to depend
    1.83 +            // on it at compile-time.
    1.84 +            Class jaxwsConstants = Class.forName("com.sun.xml.internal.ws.util.Constants");
    1.85 +            Field loggingDomainField = jaxwsConstants.getField("LoggingDomain");
    1.86 +            Object loggingDomain = loggingDomainField.get(null);
    1.87 +            loggingSubsystemName = loggingDomain.toString().concat(".wspolicy");
    1.88 +        } catch (RuntimeException e) {
    1.89 +            // if we catch an exception, we stick with the default name
    1.90 +            // this catch is redundant but works around a Findbugs warning
    1.91 +        } catch (Exception e) {
    1.92 +            // if we catch an exception, we stick with the default name
    1.93 +        }
    1.94 +        return loggingSubsystemName;
    1.95 +    }
    1.96 +
    1.97 +}

mercurial