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

Tue, 09 Apr 2013 14:51:13 +0100

author
alanb
date
Tue, 09 Apr 2013 14:51:13 +0100
changeset 368
0989ad8c0860
child 384
8f2986ff0235
permissions
-rw-r--r--

8010393: Update JAX-WS RI to 2.2.9-b12941
Reviewed-by: alanb, erikj
Contributed-by: miroslav.kos@oracle.com, martin.grebac@oracle.com

     1 /*
     2  * Copyright (c) 1997, 2012, 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         try {
    49             Class<?> factoryClass = Class.forName(config.getClassName(), true, tubeFactoryClassLoader);
    50             if (TubeFactory.class.isAssignableFrom(factoryClass)) {
    51                 @SuppressWarnings("unchecked")
    52                 // We can suppress "unchecked" warning here as we are checking for the correct type in the if statement above
    53                 Class<TubeFactory> typedClass = (Class<TubeFactory>) factoryClass;
    54                 this.factory = typedClass.newInstance();
    55                 this.msgDumpPropertyBase = this.factory.getClass().getName() + ".dump";
    56             } else {
    57                 throw new RuntimeException(TubelineassemblyMessages.MASM_0015_CLASS_DOES_NOT_IMPLEMENT_INTERFACE(factoryClass.getName(), TubeFactory.class.getName()));
    58             }
    59         } catch (InstantiationException ex) {
    60             throw LOGGER.logSevereException(new RuntimeException(TubelineassemblyMessages.MASM_0016_UNABLE_TO_INSTANTIATE_TUBE_FACTORY(config.getClassName()), ex), true);
    61         } catch (IllegalAccessException ex) {
    62             throw LOGGER.logSevereException(new RuntimeException(TubelineassemblyMessages.MASM_0016_UNABLE_TO_INSTANTIATE_TUBE_FACTORY(config.getClassName()), ex), true);
    63         } catch (ClassNotFoundException ex) {
    64             throw LOGGER.logSevereException(new RuntimeException(TubelineassemblyMessages.MASM_0017_UNABLE_TO_LOAD_TUBE_FACTORY_CLASS(config.getClassName()), ex), true);
    65         }
    66     }
    68     Tube createTube(DefaultClientTubelineAssemblyContext context) {
    69         // TODO implement passing init parameters (if any) to the factory
    70         return factory.createTube(context);
    71     }
    73     Tube createTube(DefaultServerTubelineAssemblyContext context) {
    74         // TODO implement passing init parameters (if any) to the factory
    75         return factory.createTube(context);
    76     }
    78     void updateContext(ClientTubelineAssemblyContext context) {
    79         if (factory instanceof TubelineAssemblyContextUpdater) {
    80             ((TubelineAssemblyContextUpdater) factory).prepareContext(context);
    81         }
    82     }
    84     void updateContext(DefaultServerTubelineAssemblyContext context) {
    85         if (factory instanceof TubelineAssemblyContextUpdater) {
    86             ((TubelineAssemblyContextUpdater) factory).prepareContext(context);
    87         }
    88     }
    90     String getMessageDumpPropertyBase() {
    91         return msgDumpPropertyBase;
    92     }
    93 }

mercurial