KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > test > common > ORBSetup


1 package org.jacorb.test.common;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1997-2001 Gerald Brose.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */

22
23 import java.util.*;
24 import junit.framework.*;
25 import junit.extensions.TestSetup;
26 import org.omg.CORBA.ORB JavaDoc;
27
28 /**
29  * ORB setup for JacORB JUnit tests.
30  *
31  */

32
33 public class ORBSetup extends TestSetup
34 {
35    private static ORB JavaDoc orb = null;
36    private static int count = 0;
37
38    public ORBSetup (Test test)
39    {
40       super (test);
41    }
42
43    public void setUp ()
44    {
45       init (this);
46    }
47
48    public void tearDown ()
49    {
50       destroy ();
51    }
52
53    public static ORB JavaDoc getORB ()
54    {
55       return orb;
56    }
57
58    private static synchronized void init (ORBSetup obj)
59    {
60       if (count == 0)
61       {
62          String JavaDoc [] args = new String JavaDoc [0];;
63          Properties props = new Properties ();
64
65          props.setProperty
66             ("org.omg.CORBA.ORBClass", "org.jacorb.orb.ORB");
67          props.setProperty
68             ("org.omg.CORBA.ORBSingletonClass", "org.jacorb.orb.ORBSingleton");
69
70          orb = ORB.init (args, props);
71       }
72       count++;
73    }
74
75    private static synchronized void destroy ()
76    {
77       if (count == 1)
78       {
79          orb = null;
80       }
81       count--;
82    }
83 }
84
Popular Tags