/home/kosta/dev/java/ria_test/web/java/KGIRiaTest/impl/RiaServerImpl.java

1    /* 
2    * Copyright (c) 2004 Your Corporation. All Rights Reserved. 
3    */ 
4    package KGIRiaTest.impl; 
5     
6    import KGIRiaTest.*; 
7    import org.omg.PortableServer.POAHelper; 
8    import org.omg.PortableServer.POA; 
9    import org.omg.CORBA.ORB; 
10   import org.omg.CosNaming.NamingContextExt; 
11   import org.omg.CosNaming.NamingContextExtHelper; 
12   import org.omg.CosNaming.NameComponent; 
13    
14   /** 
15    * Created by 
16    * User: kosta 
17    * Date: Oct 5, 2004 
18    * Time: 5:10:23 PM 
19    */ 
20   public class RiaServerImpl extends RiaServerPOA{ 
21    
22    
23     public UserVO getUser(String login) { 
24       return createUser( login ); 
25     } 
26    
27     /** 
28      * 
29      * @return 13 users 
30      */ 
31     public UserVO[] listUsers() { 
32       return users; 
33     } 
34    
35    
36     public static UserVO createUser( String v ){ 
37       UserVO userVO = new UserVO(); 
38       userVO.login = v; 
39       userVO.fullName = v + " " + v; 
40       userVO.contacts = new ContactVO[]{ 
41        new ContactVO( "email", v +"@" +v ) 
42       }; 
43       return userVO; 
44     } 
45    
46     public static UserVO[] users = new UserVO[]{ 
47       createUser( "A"), 
48       createUser( "B"), 
49       createUser( "C"), 
50       createUser( "D"), 
51       createUser( "E"), 
52       createUser( "F"), 
53       createUser( "G"), 
54       createUser( "H"), 
55       createUser( "I"), 
56       createUser( "J"), 
57       createUser( "K"), 
58       createUser( "L"), 
59       createUser( "M"), 
60     }; 
61    
62     public static void main(String[] args) { 
63       try{ 
64         ORB orb = ORB.init(args, null); 
65    
66         // get reference to rootpoa & activate the POAManager 
67         POA rootpoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA")); 
68         rootpoa.the_POAManager().activate(); 
69         RiaServerImpl impl = new RiaServerImpl(); 
70         org.omg.CORBA.Object ref = rootpoa.servant_to_reference( impl ); 
71        ; 
72    
73         RiaServer href = RiaServerHelper.narrow(ref); 
74    
75         // get the root naming context 
76         // NameService invokes the name service 
77         org.omg.CORBA.Object objRef = 
78             orb.resolve_initial_references("NameService"); 
79         // Use NamingContextExt which is part of the Interoperable 
80         // Naming Service (INS) specification. 
81         NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef); 
82    
83         // bind the Object Reference in Naming 
84         NameComponent path[] = ncRef.to_name( RiaServer.SERVER_NAME ); 
85         ncRef.rebind(path, href); 
86         System.out.println( RiaServer.SERVER_NAME + " has started"); 
87         orb.run(); 
88    
89       }catch( Exception e ){ 
90         e.printStackTrace(); 
91       } 
92     } 
93    
94   } 
95