001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.geronimo.corba.transaction;
018
019 import org.apache.commons.logging.Log;
020 import org.apache.commons.logging.LogFactory;
021 import org.omg.CORBA.LocalObject;
022 import org.omg.PortableInterceptor.ORBInitInfo;
023 import org.omg.PortableInterceptor.ORBInitInfoPackage.DuplicateName;
024 import org.omg.PortableInterceptor.ORBInitializer;
025
026
027 /**
028 * @version $Revision: 451417 $ $Date: 2006-09-29 13:13:22 -0700 (Fri, 29 Sep 2006) $
029 */
030 public class TransactionInitializer extends LocalObject implements ORBInitializer {
031
032 private final Log log = LogFactory.getLog(TransactionInitializer.class);
033
034 public TransactionInitializer() {
035 if (log.isDebugEnabled()) log.debug("TransactionInitializer.<init>");
036 }
037
038 /**
039 * Called during ORB initialization. If it is expected that initial
040 * services registered by an interceptor will be used by other
041 * interceptors, then those initial services shall be registered at
042 * this point via calls to
043 * <code>ORBInitInfo.register_initial_reference</code>.
044 *
045 * @param orbInitInfo provides initialization attributes and operations by
046 * which Interceptors can be registered.
047 */
048 public void pre_init(ORBInitInfo orbInitInfo) {
049
050 }
051
052 /**
053 * Called during ORB initialization. If a service must resolve initial
054 * references as part of its initialization, it can assume that all
055 * initial references will be available at this point.
056 * <p/>
057 * Calling the <code>post_init</code> operations is not the final
058 * task of ORB initialization. The final task, following the
059 * <code>post_init</code> calls, is attaching the lists of registered
060 * interceptors to the ORB. Therefore, the ORB does not contain the
061 * interceptors during calls to <code>post_init</code>. If an
062 * ORB-mediated call is made from within <code>post_init</code>, no
063 * request interceptors will be invoked on that call.
064 * Likewise, if an operation is performed which causes an IOR to be
065 * created, no IOR interceptors will be invoked.
066 *
067 * @param orbInitInfo provides initialization attributes and
068 * operations by which Interceptors can be registered.
069 */
070 public void post_init(ORBInitInfo orbInitInfo) {
071 try {
072 if (log.isDebugEnabled()) log.debug("Registering interceptors and policy factories");
073
074 try {
075 orbInitInfo.add_client_request_interceptor(new ClientTransactionInterceptor());
076 orbInitInfo.add_server_request_interceptor(new ServerTransactionInterceptor());
077 orbInitInfo.add_ior_interceptor(new IORTransactionInterceptor());
078 } catch (DuplicateName duplicateName) {
079 log.error("Duplicate name", duplicateName);
080 }
081
082 orbInitInfo.register_policy_factory(ClientTransactionPolicyFactory.POLICY_TYPE, new ClientTransactionPolicyFactory());
083 orbInitInfo.register_policy_factory(ServerTransactionPolicyFactory.POLICY_TYPE, new ServerTransactionPolicyFactory());
084 } catch (RuntimeException re) {
085 log.error("Error registering interceptor", re);
086 throw re;
087 }
088 }
089
090 }