aboutsummaryrefslogtreecommitdiff
path: root/gnu/testlet/org/omg/PortableServer/POAOperations/communication/remotePoaControlServant.java
blob: e46b785db5d1679e561a78d22dbbc47014731a8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// Copyright (C) 2005 Audrius Meskauskas (AudriusA@Bioinformatics.org)

// Mauve is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2, or (at your option)
// any later version.

// Mauve is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Mauve; see the file COPYING.  If not, write to
// the Free Software Foundation, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.  */

package gnu.testlet.org.omg.PortableServer.POAOperations.communication;

import org.omg.CORBA.BAD_INV_ORDER;
import org.omg.CORBA.BAD_PARAM;
import org.omg.CORBA.CompletionStatus;
import org.omg.CORBA.OBJ_ADAPTER;
import org.omg.PortableServer.POA;
import org.omg.PortableServer.POAManager;
import org.omg.PortableServer.POAManagerPackage.AdapterInactive;
import org.omg.PortableServer.POAManagerPackage.State;
import org.omg.PortableServer.POAPackage.AdapterNonExistent;

/**
 * Implements the remote POA control servant.
 *
 * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
 */
public class remotePoaControlServant
  extends remotePoaControlPOA
{
  POA target;
  public byte[] target_object_id;

  /**
   * Finds the child target POA to control, by name.
   */
  public void setControlTarget(String child_poa_name)
  {
    try
      {
        target = _poa().find_POA(child_poa_name, false);
      }
    catch (AdapterNonExistent ex)
      {
        ex.printStackTrace();
        throw new BAD_PARAM();
      }
  }

  /**
   * Get the state of the target POA that must be previously set.
   */
  public int getPoaMode()
  {
    if (target == null)
      throw new BAD_INV_ORDER();
    return target.the_POAManager().get_state().value();
  }

  /**
   * Set the state of the target POA that must be previously set.
   *
   * @param mode the required POA mode plus:
   * 100 = deactivate default associated object.
   * 200 = activate default associated object.
   */
  public void setPoaMode(int mode)
  {
    if (target == null)
      throw new BAD_INV_ORDER();

    POAManager manager = target.the_POAManager();

    try
      {
        switch (mode)
          {
            case State._ACTIVE :
              manager.activate();
              break;

            case State._HOLDING :
              manager.hold_requests(false);
              break;

            case State._DISCARDING :
              manager.discard_requests(false);
              break;

            case State._INACTIVE :
              manager.deactivate(false, false);
              break;

            case 100 :
              try
                {
                  target.deactivate_object(target_object_id);
                }
              catch (Exception ex)
                {
                  System.err.println("Unable to deactivate");
                  ex.printStackTrace();
                }
              break;

            case 200 :
              try
                {
                  target.activate_object_with_id(target_object_id, null);
                }
              catch (Exception ex)
                {
                  throw new RuntimeException("Unable to activate", ex);
                }
              break;

            default :
              throw new BAD_PARAM();
          }
      }
    catch (AdapterInactive ex)
      {
        throw new OBJ_ADAPTER("Inactive", 0x5001, CompletionStatus.COMPLETED_YES);
      }
  }
}