In this example, we will create a namespace and then make it READ ONLY for every one, so no one can tamper with it.
package nsReadOnly; import javax.rmi.PortableRemoteObject; import com.sssw.jbroker.api.naming.Access; import com.sssw.jbroker.api.naming.NameService; import com.sssw.jbroker.api.naming.AccessPolicy; import com.sssw.jbroker.api.naming.NameServiceFactory; import org.omg.CORBA.ORB; import org.omg.CORBA.Object; import org.omg.CosNaming.NameComponent; import org.omg.CosNaming.NamingContext; import org.omg.PortableServer.POA; import org.omg.PortableServer.LifespanPolicyValue; import com.sssw.jbroker.api.bootstrap.InitialReferencesService; import helloWorld2.Hello; import helloWorld2.HelloImpl; public class MyNameServer { public static void main(String[] args) { | try { | | // create the ORB | | ORB orb = (ORB) org.omg.CORBA.ORB.init(args, null); | | | | // get the NameService Factory | | NameServiceFactory factory = (NameServiceFactory) orb. | | resolve_initial_references("NameServiceFactory"); | | | | // get the root POA and activate it | | POA rootPOA = (POA) orb.resolve_initial_references("RootPOA"); | | rootPOA.the_POAManager().activate(); | | | | // create a transient in-process NameService | | NameService nameService = factory.createNameService( | | rootPOA, "ns1", LifespanPolicyValue.TRANSIENT, null, null); | | | | // print the root naming context | | NamingContext rootCtx = nameService.getRootNamingContext(); | | System.out.println(orb.object_to_string(rootCtx)); | | | | // publish some objects in it | | Hello hello = new HelloImpl(); | | NameComponent nc = new NameComponent("hello", ""); | | NameComponent[] name = new NameComponent[] { nc }; | | rootCtx.bind(name, (Object) PortableRemoteObject.toStub(hello)); | | | | // make the namespace READ ONLY | | AccessPolicy accessPolicy = new AccessPolicy(); | | accessPolicy.write_binding = Access.NONE; | | accessPolicy.delete_binding = Access.NONE; | | accessPolicy.add_binding = Access.NONE; | | accessPolicy.create_context = Access.NONE; | | accessPolicy.delete_context = Access.NONE; | | accessPolicy.add_context = Access.NONE; | | nameService.setAccessPolicy(accessPolicy); | | | | // publish root naming context in initial naming | | InitialReferencesService irs = (InitialReferencesService) orb. | | resolve_initial_references("InitialReferencesService"); | | irs.bind("NameService", rootCtx, false); | | | | // wait for invocations | | orb.run(); | | | } catch (Exception ex) { | | ex.printStackTrace(); | } } }
Copyright © 2003, 2004 Novell, Inc. All rights reserved. Copyright © 2001, 2002, 2003 SilverStream Software, LLC. All rights reserved.