KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > Deployment > AssemblyFactoryImpl


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2002 USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Briclet Frederic
23 Contributor(s): ___________________________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.Deployment;
28
29 import java.net.URL JavaDoc;
30 import java.util.Hashtable JavaDoc;
31 import org.omg.Components.Cookie;
32 import org.omg.Components.Deployment.Assembly;
33
34
35 /**
36  * Class AssemblyFactory in charge to provide assembly with a CAD
37  * tree reprensation already load in memory
38  * @author Briclet Frederic
39  */

40 public class AssemblyFactoryImpl extends org.omg.Components.Deployment.AssemblyFactoryPOA
41 {
42     //hashtable of created assembly
43
private Hashtable JavaDoc assemblies ;
44     
45     public AssemblyFactoryImpl()
46     {
47         assemblies=new java.util.Hashtable JavaDoc();
48     }
49     
50     /**
51      * Operation create_assembly return a cookie for retriving later the assembly.
52      * if @param is not an valide location an InvalidLocation exception is thrown
53      */

54     public Cookie
55     create_assembly(String JavaDoc assembly_loc)
56     throws org.omg.Components.Deployment.InvalidLocation,
57            org.omg.Components.CreateFailure
58     {
59         org.objectweb.openccm.Components.CookieImpl c=
60             new org.objectweb.openccm.Components.CookieImpl(""+System.currentTimeMillis());
61         URL JavaDoc url=null;
62         try{
63            url=new URL JavaDoc(assembly_loc);
64         }
65         catch(Exception JavaDoc e){
66             e.printStackTrace();
67             throw new org.omg.Components.Deployment.InvalidLocation();
68         }
69         AssemblyImpl ass=new AssemblyImpl(url);
70         ass._this(org.objectweb.openccm.corba.TheORB.getORB());
71         assemblies.put(c,ass);
72         return c;
73     }
74
75     /**
76      * Operation lookup return the assembly which match with the @param c cookie given in
77      * parameter. If c is not a valide cookie a InvalidAssemblyException is thrown
78      */

79     public Assembly lookup(org.omg.Components.Cookie c)
80         throws org.omg.Components.Deployment.InvalidAssembly
81     {
82         if(!assemblies.containsKey(c))//The cookie don't match with valid assembly
83
throw new org.omg.Components.Deployment.InvalidAssembly();//throw exception
84
return ((AssemblyImpl)assemblies.get(c))._this();
85     }
86     
87     /**
88      * Operation destroy tear_down the assembly matching with @param c cookie given in
89      * parameter and remove the instance from memory
90      */

91     public void destroy(org.omg.Components.Cookie c)
92     throws org.omg.Components.Deployment.InvalidAssembly, org.omg.Components.RemoveFailure
93     {
94         if(!assemblies.containsKey(c))
95             throw new org.omg.Components.Deployment.InvalidAssembly();
96         
97          AssemblyImpl ass=(AssemblyImpl)assemblies.remove(c);
98          ass.unregisterAssembly();
99          ass.tear_down();
100     }
101     
102 }
103
Popular Tags