KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > tm > iiop > TxIORInterceptor


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.tm.iiop;
23
24 import org.jboss.util.NestedRuntimeException;
25 import org.omg.CORBA.Any JavaDoc;
26 import org.omg.CORBA.LocalObject JavaDoc;
27 import org.omg.CORBA.ORB JavaDoc;
28 import org.omg.IOP.Codec JavaDoc;
29 import org.omg.IOP.TaggedComponent JavaDoc;
30 import org.omg.IOP.CodecPackage.InvalidTypeForEncoding JavaDoc;
31 import org.omg.PortableInterceptor.IORInfo JavaDoc;
32 import org.omg.PortableInterceptor.IORInterceptor JavaDoc;
33 /**
34  * Implements an <code>org.omg.PortableInterceptor.IORInterceptor</code>
35  * that adds spec defined COSTransaction entries to an IOR.
36  *
37  * @author <a HREF="mailto:adrian@jboss.com">Adrian Brock</a>
38  * @version $Revision: 37459 $
39  */

40 public class TxIORInterceptor extends LocalObject JavaDoc implements IORInterceptor JavaDoc
41 {
42    /** @since 4.0.1 */
43    static final long serialVersionUID = -1165643346307852265L;
44    
45    public static final int TAG_OTS_POLICY = 31;
46    public static final int TAG_INV_POLICY = 32;
47    public static final short EITHER = 0;
48    public static final short ADAPTS = 3;
49    
50    private Codec JavaDoc codec;
51
52    public TxIORInterceptor(Codec JavaDoc codec)
53    {
54       this.codec = codec;
55    }
56
57    // org.omg.PortableInterceptor.IORInterceptor operations -------------------
58

59    public String JavaDoc name()
60    {
61       return TxIORInterceptor.class.getName();
62    }
63
64    public void destroy()
65    {
66    }
67
68    public void establish_components(IORInfo JavaDoc info)
69    {
70       try
71       {
72          // Invocation Policy = EITHER
73
Any JavaDoc any = ORB.init().create_any();
74          any.insert_short(EITHER);
75          byte[] taggedComponentData = codec.encode_value(any);
76          info.add_ior_component(new TaggedComponent JavaDoc(TAG_INV_POLICY, taggedComponentData));
77          // OTS Policy = ADAPTS
78
any = ORB.init().create_any();
79          any.insert_short(ADAPTS);
80          taggedComponentData = codec.encode_value(any);
81          info.add_ior_component(new TaggedComponent JavaDoc(TAG_OTS_POLICY, taggedComponentData));
82       }
83       catch (InvalidTypeForEncoding JavaDoc e)
84       {
85          throw new NestedRuntimeException("Exception during encoding", e);
86       }
87    }
88 }
89
Popular Tags