01: /*
02: * JacORB - a free Java ORB
03: *
04: * Copyright (C) 1999-2004 Gerald Brose
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Library General Public
08: * License as published by the Free Software Foundation; either
09: * version 2 of the License, or (at your option) any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Library General Public License for more details.
15: *
16: * You should have received a copy of the GNU Library General Public
17: * License along with this library; if not, write to the Free
18: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19: *
20: */
21: package org.jacorb.orb.portableInterceptor;
22:
23: import org.omg.PortableInterceptor.*;
24: import org.omg.CORBA.*;
25:
26: /**
27: * This is the current object for the portable
28: * interceptors. It is merely a slot table, but
29: * can be bound to a thread scope.
30: *
31: * See PI Spec p. 6-55ff
32: *
33: * @author Nicolas Noffke
34: * @version $Id: PICurrentImpl.java,v 1.11 2006/07/07 10:55:57 alphonse.bendt Exp $
35: */
36:
37: public class PICurrentImpl extends org.omg.CORBA.LocalObject implements
38: org.omg.PortableInterceptor.Current {
39: private final Any[] m_slots;
40: private final ORB m_orb;
41:
42: /**
43: * Create an empty current object.
44: * All slots will contain an empty Any.
45: */
46: public PICurrentImpl(ORB orb, int no_of_anys) {
47: m_orb = orb;
48: m_slots = new Any[no_of_anys];
49:
50: for (int _i = 0; _i < m_slots.length; _i++) {
51: m_slots[_i] = m_orb.create_any();
52: }
53: }
54:
55: /**
56: * Make a deep copy of an existing PICurrent.
57: */
58: public PICurrentImpl(PICurrentImpl source) {
59: m_orb = source.m_orb;
60: m_slots = new Any[source.m_slots.length];
61:
62: for (int _i = 0; _i < m_slots.length; _i++) {
63: m_slots[_i] = m_orb.create_any();
64: ((org.jacorb.orb.Any) m_slots[_i]).insert_object(
65: source.m_slots[_i].type(),
66: ((org.jacorb.orb.Any) source.m_slots[_i]).value());
67: }
68: }
69:
70: // implementation of org.omg.PortableInterceptor.CurrentOperations interface
71: public Any get_slot(int id) throws InvalidSlot {
72: if ((id >= m_slots.length) || (id < 0)) {
73: throw new InvalidSlot();
74: }
75:
76: return m_slots[id];
77: }
78:
79: public void set_slot(int id, Any data) throws InvalidSlot {
80: if ((id >= m_slots.length) || (id < 0)) {
81: throw new InvalidSlot();
82: }
83:
84: m_slots[id] = data;
85: }
86: } // PICurrentImpl
|