Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/obs/client/domain/delegates/DomainControllerDelegate.java


1   /*
2    * Created on 2003-jul-03
3    *
4    * To change the template for this generated file go to
5    * Window>Preferences>Java>Code Generation>Code and Comments
6    */
7   package com.obs.client.domain.delegates;
8   
9   import java.rmi.RemoteException;
10  import java.util.ArrayList;
11  import java.util.Collection;
12  import java.util.Iterator;
13  import java.util.Properties;
14  
15  import javax.ejb.CreateException;
16  import javax.ejb.Handle;
17  import javax.naming.InitialContext;
18  import javax.naming.NamingException;
19  import javax.rmi.PortableRemoteObject;
20  
21  import com.obs.client.templates.EJBDelegate;
22  import com.obs.common.domain.views.DomainView;
23  import com.obs.common.exceptions.ServerContactException;
24  import com.obs.ejb.domain.interfaces.DomainController;
25  import com.obs.ejb.domain.interfaces.DomainControllerHome;
26  
27  /**
28   * @author Staffan B�cklin
29   *
30   * To change the template for this generated type comment go to
31   * Window>Preferences>Java>Code Generation>Code and Comments
32   */
33  public class DomainControllerDelegate implements EJBDelegate {
34    private InitialContext ictx = null;
35    private DomainController domainController = null;
36    private Handle handle = null;
37    private String currentDomainID = null;  
38    private Collection currentSubDomains;
39    private Collection domainList;
40    
41    
42    
43    public void test_getDomainList(){
44      
45      Iterator it = this.getDomainList().iterator();
46      System.out.println("Domain LIST");
47      while(it.hasNext()){
48        DomainView view = (DomainView)it.next();
49        
50        System.out.println("<" + view.getId() +
51                 "><" + view.getName() + 
52                "><" + view.getDescription() +
53                 "><" + view.getPath());
54      }
55    }
56    
57    
58    /**
59     * @return
60     */
61    public Collection getDomainList() {
62      Collection list = new ArrayList();
63      if(this.domainController != null){
64        try{
65          list = domainController.getDomainList();
66          return list;
67        }catch(Exception ex){
68          ex.printStackTrace();
69          return null;
70        }
71      }return list;    
72    }
73  
74    /**
75     * @return 
76     */
77    public Collection getCurrentSubDomains() {
78      Collection list = new ArrayList();
79      if(this.domainController != null){
80        try{
81          list = domainController.getSubDomains();
82          return list;
83        }catch(Exception ex){
84          ex.printStackTrace();
85          return null;
86        }
87      }return list;    
88    }
89  
90    /**
91     * @param currentSubDomains
92     */
93    public void setCurrentSubDomains(Collection currentSubDomains) {
94      this.currentSubDomains = currentSubDomains;
95    }
96  
97    /**
98     * @return
99     */
100   public DomainView getCurrentDomainView(){
101     System.out.println("DomainControllerDelegate.getCurrentDomainView()");
102     DomainView domainView = null;
103     if(this.domainController != null){
104     try{                
105       domainView = this.domainController.getCurrentDomain();          
106       }catch(RemoteException re){ 
107         re.printStackTrace();
108         return null;
109       }catch(Exception ex){ 
110         ex.printStackTrace();
111         return null;
112       }      
113     }
114     System.out.println("ID=" + domainView.getId() + ">Name=" + domainView.getName()
115         + ">Description=" + domainView.getDescription());
116     return domainView;
117   }
118 
119   /**
120    * @param DomainView newDomainView
121    */
122   public void setCurrentDomainView(DomainView newDomainView) {
123     System.out.println("DomainControllerDelegate.setCurrentDomainView()");
124     try{                
125       this.domainController.setCurrentDomainView(newDomainView);            
126     }catch(RemoteException re){ 
127       re.printStackTrace();
128       return;
129     }catch(Exception ex){ 
130       ex.printStackTrace();
131       return;
132     }
133   }
134 
135   /**
136    * Create Sub Domain when a current DomainID is set.
137    * @param newDomainView
138    */
139   public DomainView createSubDomain(DomainView newDomainView){
140     DomainView view = null;
141     if(this.domainController != null){
142       try{
143         view = this.domainController.createSubDomain(newDomainView);
144       }catch(CreateException ce){
145          ce.printStackTrace(); 
146          return null;
147       }catch(RemoteException re){
148          re.printStackTrace();
149         return null;
150       }catch(Exception ex){
151         ex.printStackTrace(); 
152         return null;
153       }
154       System.out.println("DomainControllerDelegate.createSubDomain()");
155     }return view;
156   }
157   
158   
159   
160   /**
161    * Create Root Domain when no current DomainID is set or available.
162    * @param view
163    */
164   public DomainView createRootDomain(DomainView newDomainView){
165     DomainView view = null;
166     if(this.domainController != null){
167       try{
168             view = null;currentDomainID = "" + this.domainController.createSubDomain(newDomainView);
169             this.setCurrentDomainID(view.getId());
170       }catch(CreateException ce){
171              ce.printStackTrace(); 
172              return null;
173       }catch(RemoteException re){
174              re.printStackTrace();
175              return null;
176       }catch(Exception ex){
177              ex.printStackTrace();
178              return null;
179       }
180       System.out.println("DomainControllerDelegate.createRootDomain()");          
181       //this.setCurrentDomainID(currentDomainID);
182     }
183     return view;
184   }  
185   
186 
187   /**
188    * @return
189    * 
190    */
191   public String getCurrentDomainID() {
192     System.out.println("DomainControllerDelegate.getCurrentDomainID()<" + 
193           currentDomainID + ">");
194     return currentDomainID;
195   }
196 
197   /**
198    * @param currentDomainID
199    */
200   public void setCurrentDomainID(String currentDomainID) {
201     this.currentDomainID = currentDomainID;
202     // TODO: Add controll of DomainController
203   }
204   /**
205    * 
206    * @param domainID
207    * @throws ServerContactException
208    */
209   public DomainControllerDelegate(String domainID) throws ServerContactException{
210       this.setCurrentDomainID(domainID);
211       this.activate();
212     }
213   /**
214    * 
215    * @throws ServerContactException
216    */
217   public DomainControllerDelegate() throws ServerContactException{
218     this.setCurrentDomainID(null);
219     this.activate();
220   }
221   
222   /*
223      * Interface Methods
224      */
225   /* (non-Javadoc)
226    * @see com.obs.client.templates.EJBDelegate#passivate()
227    */
228   public void passivate() throws ServerContactException {
229     // TODO Auto-generated method stub
230 
231   }
232 
233   /* (non-Javadoc)
234    * @see com.obs.client.templates.EJBDelegate#activate()
235    */
236   public void activate() throws ServerContactException {
237     // TODO Auto-generated method stub
238     System.out.println("DomainControllerDelegate.activate()");
239     if(handle != null) {
240           try {
241             domainController = (DomainController)handle.getEJBObject();
242           }
243           catch(RemoteException remote_ex) {
244             throw new ServerContactException();
245           }
246         }
247         else {
248           try {
249             // TODO : May need to change InitialContext setup
250             Properties props = new Properties();
251             props.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
252             props.setProperty("java.naming.provider.url", "localhost:1099");
253             ictx = new InitialContext(props);
254             //ictx = new InitialContext();
255             DomainControllerHome dcHome = (DomainControllerHome)
256                      PortableRemoteObject.narrow(
257                        ictx.lookup("com/obs/ejb/domain/DomainControllerEJB"),
258                       DomainControllerHome.class);
259           domainController = dcHome.create(this.getCurrentDomainID());
260           }
261           catch(NamingException naming_ex) {
262             naming_ex.printStackTrace();
263             throw new ServerContactException();
264           }
265           catch(RemoteException remote_ex) {
266             remote_ex.printStackTrace();
267             throw new ServerContactException();
268           }
269           catch(CreateException create_ex) {
270           }      
271         }
272 
273   }
274 
275   /* (non-Javadoc)
276    * @see com.obs.client.templates.EJBDelegate#destroy()
277    */
278   public void destroy() throws ServerContactException {
279     // TODO Auto-generated method stub
280 
281   }
282   /*
283    * For testing and debugging
284    */
285   public static void main(String[] args) {
286     System.out.println("DomainControllerDelegate.main()");
287     try{
288       DomainControllerDelegate delegate = new DomainControllerDelegate();
289       delegate.createRootDomain(new DomainView("obs3","Root of all cool stuff"));      
290       delegate.getCurrentDomainID();      
291       delegate.createSubDomain(new DomainView("sweden3","Nice little country"));
292       delegate.setCurrentDomainID("2");
293       delegate.activate();
294       delegate.setCurrentDomainView(new DomainView("scandinavia","the old north"));      
295       delegate.getCurrentDomainID();
296       delegate.getCurrentDomainView();
297       delegate.test_getDomainList();
298       
299     }catch(Exception e){
300       e.printStackTrace();
301     }
302   }
303 }