KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > Containers > MetaInformation > HomeInstanceImpl


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

28
29 package org.objectweb.openccm.Containers.MetaInformation;
30
31 import org.omg.Components.CCMHome;
32
33 /**
34  * @author hameau
35  */

36 public class HomeInstanceImpl
37 extends InstanceImpl
38 implements HomeInstance {
39   
40   protected HomeType _home_type;
41   protected ComponentInstanceList _component_instances;
42   protected CCMHome _home_ref;
43   protected String JavaDoc _home_instance_factory_entrypt;
44   protected OperationInstanceList _operation_instance_list;
45   protected InterfaceInstance _equivalent_interface;
46   
47   public HomeInstanceImpl()
48   {
49     _home_instance_factory_entrypt = null;
50     _component_instances = new ComponentInstanceListImpl();
51     _equivalent_interface = null;
52     _home_ref = null;
53     _home_type = null;
54     _operation_instance_list = new OperationInstanceListImpl();
55   }
56   
57   /* (non-Javadoc)
58    * @see org.objectweb.openccm.Containers.HomeInstanceOperations#home_ref()
59    */

60   public CCMHome home_ref()
61   {
62     return _home_ref;
63   }
64   /* (non-Javadoc)
65    * @see org.objectweb.openccm.Containers.HomeInstanceOperations#home_ref(org.omg.Components.CCMHome)
66    */

67   public void home_ref(CCMHome value)
68   {
69     _home_ref = value;
70   }
71   /* (non-Javadoc)
72    * @see org.objectweb.openccm.Containers.HomeInstanceOperations#home_instance_factory_entrypt()
73    */

74   public String JavaDoc home_instance_factory_entrypt()
75   {
76     return _home_instance_factory_entrypt;
77   }
78   /* (non-Javadoc)
79    * @see org.objectweb.openccm.Containers.HomeInstanceOperations#home_instance_factory_entrypt(java.lang.String)
80    */

81   public void home_instance_factory_entrypt(String JavaDoc value)
82   {
83     _home_instance_factory_entrypt = value;
84   }
85   
86   public ComponentInstanceList component_instance_list()
87   {
88     return _component_instances;
89   }
90   /* (non-Javadoc)
91    * @see org.objectweb.openccm.Containers.MetaInformation.HomeInstanceOperations#component_instance_list(org.objectweb.openccm.Containers.MetaInformation.ComponentInstanceList)
92    */

93   public void component_instance_list(ComponentInstanceList value)
94   {
95     _component_instances = value;
96   }
97   /* (non-Javadoc)
98    * @see org.objectweb.openccm.Containers.MetaInformation.HomeInstanceOperations#equivalent_interface()
99    */

100   public InterfaceInstance equivalent_interface()
101   {
102     return _equivalent_interface;
103   }
104   /* (non-Javadoc)
105    * @see org.objectweb.openccm.Containers.MetaInformation.HomeInstanceOperations#equivalent_interface(org.objectweb.openccm.Containers.MetaInformation.InterfaceInstance)
106    */

107   public void equivalent_interface(InterfaceInstance value)
108   {
109     _equivalent_interface = value;
110   }
111   /* (non-Javadoc)
112    * @see org.objectweb.openccm.Containers.MetaInformation.InterfaceInstanceOperations#operation_instance_list()
113    */

114   public OperationInstanceList operation_instance_list()
115   {
116     return _operation_instance_list;
117   }
118   /* (non-Javadoc)
119    * @see org.objectweb.openccm.Containers.MetaInformation.InterfaceInstanceOperations#operation_instance_list(org.objectweb.openccm.Containers.MetaInformation.OperationInstanceList)
120    */

121   public void operation_instance_list(OperationInstanceList value)
122   {
123     _operation_instance_list = value;
124   }
125   /* (non-Javadoc)
126    * @see org.objectweb.openccm.Containers.MetaInformation.HomeInstanceOperations#create_component_instance()
127    */

128   public ComponentInstance create_component_instance()
129   {
130     ComponentInstance result = new ComponentInstanceImpl();
131     ComponentType _ctype;
132     HomeType _htype;
133     // getting the associated home type
134
try
135     {
136       _htype = (HomeType) this.type_reference();
137     }
138     catch (ClassCastException JavaDoc e)
139     {
140       System.err.println("Cannot convert type -> home type !!!");
141       return null;
142     }
143     // getting the associated component type
144
try
145     {
146       _ctype = (ComponentType) _htype.type_reference();
147     }
148     catch (ClassCastException JavaDoc e)
149     {
150       System.err.println("Cannot convert type -> component type !!!");
151       return null;
152     }
153     
154     // filling the component instance properties
155
// setting the MI instance properties
156

157     result.related_instance_kind(instance_kind.HOME_INSTANCE);
158     result.instance_reference(this);
159     result.type_reference(_ctype);
160  
161     //// for attributes
162

163     AttributeType[] _catts = _ctype.attribute_type_list().get_all_attribute_types();
164     if (_catts.length != 0)
165     {
166       AttributeInstanceImpl _cints;
167       
168       for (int i = 0; i < _catts.length; i++)
169       {
170         _cints = new AttributeInstanceImpl();
171         _cints.type_reference(_catts[i]);
172         _cints.related_instance_kind(instance_kind.COMPONENT_INSTANCE);
173         _cints.instance_reference(this);
174         _cints.object_ref(null);
175         result.attribute_instance_list().add_attribute_instance(_cints);
176       }
177     }
178     // for supported interfaces
179

180     InterfaceType[] _sit =
181       _ctype.supported_interfaces().get_all_interface_types();
182     if (_sit.length != 0)
183     {
184       InterfaceInstance _sii;
185       for (int i = 0; i < _sit.length; i++)
186       {
187         _sii = create_interface_instance(_sit[i]);
188         _sii.related_instance_kind(instance_kind.COMPONENT_INSTANCE);
189         _sii.instance_reference(this);
190         _sii.object_ref(null);
191         result.supported_interface().add_interface_instance(
192           create_interface_instance(_sit[i]));
193       }
194     }
195     // for equivalent interface
196

197     InterfaceInstance _eii =
198       create_interface_instance(_ctype.equivalent_interface());
199     _eii.related_instance_kind(instance_kind.COMPONENT_INSTANCE);
200     _eii.instance_reference(this);
201     result.equivalent_interface(_eii);
202     
203     
204     // component instance entity fullfilled, ready to be used
205

206     this.component_instance_list().add_component_instance(result);
207     
208     return result;
209   }
210   
211   
212   private InterfaceInstance create_interface_instance(InterfaceType it)
213   {
214   // System.err.println("### Debug : creating interface instance");
215

216     InterfaceInstance result = new InterfaceInstanceImpl();
217     OperationInstance tmp_opi;
218     result.type_reference(it);
219     OperationType[] tmp_ops = it.operation_type_list().get_all_operation_types();
220     for (int i = 0; i < tmp_ops.length; i++)
221     {
222       tmp_opi = new OperationInstanceImpl();
223       tmp_opi.related_instance_kind(instance_kind.INTERFACE_INSTANCE);
224       tmp_opi.type_reference(tmp_ops[i]);
225       tmp_opi.instance_reference(result);
226       tmp_opi.object_ref(null);
227       result.operation_instance_list().add_operation_instance(tmp_opi);
228     }
229     return result;
230   }
231
232 }
233
Popular Tags