1 /* Demo.java -- Shows how to use Classpath transient naming service.
2 Copyright (C) 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package gnu.classpath.examples.CORBA.NamingService;
43 import org.omg.CORBA.ORB;
44 import org.omg.CORBA.Object;
45 import org.omg.CosNaming.Binding;
46 import org.omg.CosNaming.BindingHolder;
47 import org.omg.CosNaming.BindingIterator;
48 import org.omg.CosNaming.BindingIteratorHolder;
49 import org.omg.CosNaming.BindingListHolder;
50 import org.omg.CosNaming.NameComponent;
51 import org.omg.CosNaming.NamingContext;
52 import org.omg.CosNaming.NamingContextExt;
53 import org.omg.CosNaming.NamingContextExtHelper;
54 import org.omg.CosNaming.NamingContextHelper;
57 * A simple test of the naming service.
59 * The main class of the GNU Classpath transient naming service is
60 * {@link gnu.CORBA.NamingService}. This class must be started
61 * before starting this example.
63 * This example should interoperate as with GNU Classpath naming
64 * service, as with Sun Microsystems transient and persistent
65 * naming services, included in releases 1.3 and 1.4 (tnameserv and
66 * orbd). To work with this example, the naming service must
67 * be started on the local host, at the port 900.
69 * The persistent naming service is currently under development.
71 * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
75 public static void main(String[] an_args)
77 // We create the following naming graph:
86 // Where both obj and xobj are CORBA objects, representing the
87 // default naming service.
89 System.out.println("Starting the GNU Classpath " +
90 "built-in transient naming service"
93 final String[] args = an_args;
99 gnu.classpath.tools.tnameserv.Main.main(args);
103 System.out.println("Waiting for three seconds for naming service to start:");
108 catch (InterruptedException ex)
114 ORB orb = ORB.init(args, null);
116 Object no = orb.resolve_initial_references("NameService");
118 System.out.println("Naming service IOR:" + orb.object_to_string(no));
120 System.out.println(IOR.parse(orb.object_to_string(no)));
122 NamingContextExt namer = NamingContextExtHelper.narrow(no);
124 System.out.println("Naming service: " + namer.getClass().getName());
126 NamingContext second = namer.new_context();
128 namer.rebind_context(namer.to_name("c.d"), second);
129 namer.rebind(namer.to_name("xobj"), no);
131 second.rebind(namer.to_name("obj"), no);
134 NamingContextHelper.narrow(namer.resolve_str("c.d"));
136 System.out.println(namer.resolve(namer.to_name("c.d/obj")));
138 // In all cases, this must be the same object (the naming
140 System.out.println(nsec.resolve(new NameComponent[]
142 new NameComponent("obj", "")
146 System.out.println(namer.resolve_str("xobj"));
148 // In all cases, this must be the same object (the naming
150 System.out.println(namer.resolve(new NameComponent[]
152 new NameComponent("c", "d"),
153 new NameComponent("obj", "")
158 System.out.println(namer.resolve_str("c.d/obj"));
160 System.out.println("Test binding list iterator:");
162 BindingListHolder lh = new BindingListHolder();
163 BindingIteratorHolder lih = new BindingIteratorHolder();
165 namer.list(0, lh, lih);
167 BindingIterator iter = lih.value;
168 BindingHolder binding = new BindingHolder();
170 while (iter.next_one(binding))
172 Binding b = binding.value;
173 System.out.println("NAME: " + namer.to_string(b.binding_name) +
174 " TYPE " + b.binding_type.value()
178 System.out.println("Testing binding list:");
182 namer.list(Integer.MAX_VALUE, lh, lih);
184 for (int i = 0; i < lh.value.length; i++)
186 Binding b = lh.value [ i ];
187 System.out.println("NAME: " + namer.to_string(b.binding_name) +
188 " TYPE " + b.binding_type.value()
194 ex.printStackTrace();