KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > naming > pcosnaming > NameServer


1 /*
2  * @(#)NameServer.java 1.12 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.corba.se.impl.naming.pcosnaming;
9
10 import java.io.File JavaDoc;
11 import java.util.Properties JavaDoc;
12
13 import com.sun.corba.se.impl.orbutil.ORBConstants;
14 import com.sun.corba.se.impl.orbutil.CorbaResourceUtil;
15 import com.sun.corba.se.spi.orb.ORB;
16 import com.sun.corba.se.spi.activation.InitialNameService;
17 import com.sun.corba.se.spi.activation.InitialNameServiceHelper;
18 import org.omg.CosNaming.NamingContext JavaDoc;
19 /**
20  * Class NameServer is a standalone application which
21  * implements a persistent and a transient name service.
22  * It uses the PersistentNameService and TransientNameService
23  * classes for the name service implementation.
24  *
25  * @version 1.1, 99/10/07
26  * @author Hemanth Puttaswamy
27  * @since JDK1.2
28  */

29
30 public class NameServer
31 {
32     private ORB orb;
33
34     private File JavaDoc dbDir; // name server database directory
35

36     private final static String JavaDoc dbName = "names.db";
37
38     public static void main(String JavaDoc args[])
39     {
40     NameServer ns = new NameServer(args);
41     ns.run();
42     }
43
44     protected NameServer(String JavaDoc args[])
45     {
46         // create the ORB Object
47
java.util.Properties JavaDoc props = System.getProperties();
48     props.put( ORBConstants.SERVER_ID_PROPERTY, "1000" ) ;
49         props.put("org.omg.CORBA.ORBClass",
50           "com.sun.corba.se.impl.orb.ORBImpl");
51         orb = (ORB) org.omg.CORBA.ORB.init(args,props);
52
53     // set up the database directory
54
String JavaDoc dbDirName = props.getProperty( ORBConstants.DB_DIR_PROPERTY ) +
55         props.getProperty("file.separator") + dbName +
56         props.getProperty("file.separator");
57
58     dbDir = new File JavaDoc(dbDirName);
59     if (!dbDir.exists()) dbDir.mkdir();
60     }
61
62     protected void run()
63     {
64     try {
65
66         // create the persistent name service
67
NameService ns = new NameService(orb, dbDir);
68
69         // add root naming context to initial naming
70
NamingContext JavaDoc rootContext = ns.initialNamingContext();
71         InitialNameService ins = InitialNameServiceHelper.narrow(
72                      orb.resolve_initial_references(
73                      ORBConstants.INITIAL_NAME_SERVICE_NAME ));
74         ins.bind( "NameService", rootContext, true);
75         System.out.println(CorbaResourceUtil.getText("pnameserv.success"));
76
77         // wait for invocations
78
orb.run();
79
80     } catch (Exception JavaDoc ex) {
81
82         ex.printStackTrace(System.err);
83     }
84     }
85
86 }
87
Popular Tags