src/share/jaxws_classes/com/sun/xml/internal/ws/assembler/TubeCreator.java

Thu, 31 Aug 2017 15:18:52 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:18:52 +0800
changeset 637
9c07ef4934dd
parent 384
8f2986ff0235
parent 0
373ffda63c9a
permissions
-rw-r--r--

merge

     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
    23  * questions.
    24  */
    26 package com.sun.xml.internal.ws.assembler;
    28 import com.sun.istack.internal.logging.Logger;
    29 import com.sun.xml.internal.ws.api.pipe.Tube;
    30 import com.sun.xml.internal.ws.assembler.dev.ClientTubelineAssemblyContext;
    31 import com.sun.xml.internal.ws.assembler.dev.TubeFactory;
    32 import com.sun.xml.internal.ws.assembler.dev.TubelineAssemblyContextUpdater;
    33 import com.sun.xml.internal.ws.resources.TubelineassemblyMessages;
    34 import com.sun.xml.internal.ws.runtime.config.TubeFactoryConfig;
    36 /**
    37  * Utility class that encapsulates logic of loading TubeFactory
    38  * instances and creating Tube instances.
    39  *
    40  * @author m_potociar
    41  */
    42 final class TubeCreator {
    43     private static final Logger LOGGER = Logger.getLogger(TubeCreator.class);
    44     private final TubeFactory factory;
    45     private final String msgDumpPropertyBase;
    47     TubeCreator(TubeFactoryConfig config, ClassLoader tubeFactoryClassLoader) {
    48         String className = config.getClassName();
    49         try {
    50             Class<?> factoryClass;
    51             if (isJDKInternal(className)) {
    52                 factoryClass = Class.forName(className, true, null);
    53             } else {
    54                 factoryClass = Class.forName(className, true, tubeFactoryClassLoader);
    55             }
    56             if (TubeFactory.class.isAssignableFrom(factoryClass)) {
    57                 // We can suppress "unchecked" warning here as we are checking for the correct type in the if statement above
    58                 @SuppressWarnings("unchecked")
    59                 Class<TubeFactory> typedClass = (Class<TubeFactory>) factoryClass;
    60                 this.factory = typedClass.newInstance();
    61                 this.msgDumpPropertyBase = this.factory.getClass().getName() + ".dump";
    62             } else {
    63                 throw new RuntimeException(TubelineassemblyMessages.MASM_0015_CLASS_DOES_NOT_IMPLEMENT_INTERFACE(factoryClass.getName(), TubeFactory.class.getName()));
    64             }
    65         } catch (InstantiationException ex) {
    66             throw LOGGER.logSevereException(new RuntimeException(TubelineassemblyMessages.MASM_0016_UNABLE_TO_INSTANTIATE_TUBE_FACTORY(className), ex), true);
    67         } catch (IllegalAccessException ex) {
    68             throw LOGGER.logSevereException(new RuntimeException(TubelineassemblyMessages.MASM_0016_UNABLE_TO_INSTANTIATE_TUBE_FACTORY(className), ex), true);
    69         } catch (ClassNotFoundException ex) {
    70             throw LOGGER.logSevereException(new RuntimeException(TubelineassemblyMessages.MASM_0017_UNABLE_TO_LOAD_TUBE_FACTORY_CLASS(className), ex), true);
    71         }
    72     }
    74     Tube createTube(DefaultClientTubelineAssemblyContext context) {
    75         // TODO implement passing init parameters (if any) to the factory
    76         return factory.createTube(context);
    77     }
    79     Tube createTube(DefaultServerTubelineAssemblyContext context) {
    80         // TODO implement passing init parameters (if any) to the factory
    81         return factory.createTube(context);
    82     }
    84     void updateContext(ClientTubelineAssemblyContext context) {
    85         if (factory instanceof TubelineAssemblyContextUpdater) {
    86             ((TubelineAssemblyContextUpdater) factory).prepareContext(context);
    87         }
    88     }
    90     void updateContext(DefaultServerTubelineAssemblyContext context) {
    91         if (factory instanceof TubelineAssemblyContextUpdater) {
    92             ((TubelineAssemblyContextUpdater) factory).prepareContext(context);
    93         }
    94     }
    96     String getMessageDumpPropertyBase() {
    97         return msgDumpPropertyBase;
    98     }
   100     private boolean isJDKInternal(String className) {
   101         // avoid repackaging
   102         return className.startsWith("com." + "sun.xml.internal.ws");
   103     }
   105 }

mercurial