KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > ir3 > ValueDef_impl


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2004 INRIA & 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): Philippe Merle.
23 Contributor(s): Mathieu Vadet, Christophe Demarey.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.ir3;
28
29 // Package dependencies
30
import org.omg.CORBA.*;
31 import org.omg.CORBA.ValueDefPackage.FullValueDescription;
32
33 /**
34  * Implementation of the CORBA::ValueDef interface.
35  *
36  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
37  * <a HREF="mailto:Mathieu.Vadet@lifl.fr">Mathieu Vadet</a>
38  *
39  * @version 0.5
40  */

41
42 public class ValueDef_impl
43      extends Container_impl
44   implements ValueDefOperations
45 {
46     // ==================================================================
47
//
48
// Internal state.
49
//
50
// ==================================================================
51

52     /** The supported interfaces. */
53     protected InterfaceDef_ref[] supported_interfaces_;
54
55     /** The initializers. */
56     protected Initializer_impl[] initializers_;
57
58     /** The base value. */
59     protected ValueDef_ref base_value_;
60
61     /** The abstract base values. */
62     protected ValueDef_ref[] abstract_base_values_;
63
64     /** Is abstract. */
65     protected boolean is_abstract_;
66
67     /** Is custom. */
68     protected boolean is_custom_;
69
70     /** Is truncatable. */
71     protected boolean is_truncatable_;
72
73     // ==================================================================
74
//
75
// Constructor.
76
//
77
// ==================================================================
78

79     /** TODO */
80     public
81     ValueDef_impl(IFR ifr,
82                   Container_impl container)
83     {
84         // Calls the Container_impl contructor.
85
super(ifr, container);
86
87         // Sets the tie servant object.
88
setServant(new ValueDefPOATie(this));
89
90     // Inits internal state.
91
supported_interfaces_ = null;
92         initializers_ = new Initializer_impl[0];
93         base_value_ = new ValueDef_ref(this);
94         abstract_base_values_ = null;
95         is_abstract_ = false;
96         is_custom_ = false;
97         is_truncatable_ = false;
98     }
99
100     // ==================================================================
101
//
102
// Internal methods.
103
//
104
// ==================================================================
105

106     /**
107      * To obtain the list of abstract base values.
108      */

109     protected ValueDef_ref[]
110     getAbstractBaseValues()
111     {
112         return abstract_base_values_;
113     }
114
115     /**
116      * To obtain the base value.
117      */

118     protected ValueDef_ref
119     getBaseValue()
120     {
121         return base_value_;
122     }
123
124     // ==================================================================
125
//
126
// Internal methods inherited from IROject_impl.
127
//
128
// ==================================================================
129

130     /**
131      * Warning : this operation must be implemented by subclasses.
132      * It allows us to avoid some casts while creating ::CORBA::TypeCode
133      */

134     protected TypeCode
135     recursiveType(java.util.List JavaDoc idSeq)
136     {
137         int idx = idSeq.indexOf(id());
138         if (idx!=-1)
139             return getIFR().getTCF().create_recursive_tc(id());
140
141         idSeq.add(id());
142
143         short mode = (short)0;
144         if(is_custom())
145             mode = (short)1;
146         else if(is_abstract())
147             mode = (short)2;
148         else if(is_truncatable())
149             mode = (short)3;
150         else
151             mode = (short)0;
152  
153     // Compute the base TypeCode.
154
org.omg.CORBA.TypeCode JavaDoc tc = getBaseValue().recursiveType(idSeq);
155
156     // for JavaORB ?
157
if(tc == null)
158          tc = org.objectweb.openccm.corba.TheORB.get_null_valuebase_tc();
159
160         ValueMember[] members = getValueMemberSeq(idSeq);
161         idSeq.remove(id());
162
163      // delegate to the TypeCodeFactory.
164
return getIFR().getTCF().
165               create_value_tc(id(), name(), mode,
166                               tc, members);
167     }
168
169     // ==================================================================
170
//
171
// Public methods.
172
//
173
// ==================================================================
174

175     /**
176      * Obtain its CORBA::ValueDef object reference.
177      */

178     public ValueDef
179     asValueDef()
180     {
181         return ValueDefHelper.narrow(asObject());
182     }
183
184     /**
185      * Compute its CORBA::OpDescriptionSeq.
186      */

187     public ValueMember[]
188     getValueMemberSeq(java.util.List JavaDoc idSeq)
189     {
190         java.util.List JavaDoc selection = new java.util.ArrayList JavaDoc();
191
192         selectContained(selection, DefinitionKind.dk_ValueMember, true);
193
194         ValueMember[] result = new ValueMember[selection.size()];
195
196         for(int i=0; i<selection.size(); i++)
197             result[i] = ((ValueMemberDef_impl)selection.get(i))
198                         .getValueMember(idSeq);
199
200         return result;
201     }
202
203     /**
204      * Compute its CORBA::OpDescriptionSeq.
205      */

206     public ValueMember[]
207     getValueMemberSeq()
208     {
209         java.util.List JavaDoc selection = new java.util.ArrayList JavaDoc();
210
211         selectContained(selection, DefinitionKind.dk_ValueMember, true);
212
213         ValueMember[] result = new ValueMember[selection.size()];
214
215         for(int i=0; i<selection.size(); i++)
216             result[i] = ((ValueMemberDef_impl)selection.get(i))
217                         .getValueMember();
218
219         return result;
220     }
221
222     /**
223      * Check name redefinition.
224      */

225     public void
226     checkNameInit(String JavaDoc name,
227                   boolean exclude_inherited,
228                   boolean in_inherited,
229                   boolean check_init)
230     {
231         // calls the Container_impl::validateName operations.
232
super.checkName(name, exclude_inherited, in_inherited);
233
234         //
235
// Check name against initializers.
236
//
237
if(check_init)
238         {
239             for(int i=0; i<initializers_.length; i++)
240             {
241                 if(name.equalsIgnoreCase(initializers_[i].getName()))
242                 {
243                     if(in_inherited)
244                         throw exceptionNameClashInInheritedContext(name);
245                     else
246                         throw exceptionNameAlreadyUsed(name);
247                 }
248             }
249         }
250  
251         if(!exclude_inherited)
252         {
253             //
254
// Check name against base value.
255
//
256
if(getBaseValue().getImpl() != null)
257                 getBaseValue().getImpl().checkNameInit(name, false, true, check_init);
258
259             //
260
// Check name against abstract base values.
261
//
262
ValueDef_ref[] abs_refs = getAbstractBaseValues();
263             for(int i=0; i<abs_refs.length; i++)
264                 abs_refs[i].getImpl().checkNameInit(name, false,
265                                                    true, check_init);
266
267             //
268
// Check name against supported interfaces.
269
//
270
for(int i=0; i<supported_interfaces_.length; i++)
271                 supported_interfaces_[i].getImpl().checkName(name, false, true);
272         }
273     }
274
275     /**
276      * Obtain the CORBA::ComponentIR::ValueDescription of the declaration.
277      */

278     public ValueDescription
279     getValueDescription()
280     {
281         // create the CORBA::ValueDescription.
282
ValueDescription description = new ValueDescription();
283         description.name = name();
284         description.id = id();
285         description.is_abstract = is_abstract();
286         description.is_custom = is_custom();
287         description.defined_in = getContainerID();
288         description.version = version();
289         description.supported_interfaces = InterfaceDef_ref.
290                          computeRepositoryIdSeq(supported_interfaces_);
291         description.abstract_base_values = ValueDef_ref.
292                          computeRepositoryIdSeq(getAbstractBaseValues());
293         description.is_truncatable = is_truncatable();
294         description.base_value = getBaseValue().getId();
295
296         return description;
297     }
298
299     // ==================================================================
300
//
301
// For Contained_impl class.
302
//
303
// ==================================================================
304

305     /**
306      * To set the value field of the CORBA::Contained::Description struct.
307      */

308     public void
309     setDescriptionValue(Any any)
310     {
311         // insert it into the any.
312
ValueDescriptionHelper.insert(any, getValueDescription());
313     }
314
315     // ==================================================================
316
//
317
// For Container_impl class.
318
//
319
// ==================================================================
320

321     /**
322      * Check if this kind of objects is accepted by the container.
323      */

324     public boolean
325     checkDefinitionKind(DefinitionKind dk)
326     {
327         return (dk == DefinitionKind.dk_Attribute)
328             || (dk == DefinitionKind.dk_Constant)
329             || (dk == DefinitionKind.dk_Exception)
330             || (dk == DefinitionKind.dk_Operation)
331             || (dk == DefinitionKind.dk_Alias)
332             || (dk == DefinitionKind.dk_Struct)
333             || (dk == DefinitionKind.dk_Union)
334             || (dk == DefinitionKind.dk_Enum)
335             || (dk == DefinitionKind.dk_Native)
336             || (dk == DefinitionKind.dk_ValueMember);
337     }
338
339     /**
340      * Check a new name according to already contained names.
341      */

342     public void
343     checkName(String JavaDoc name,
344               boolean exclude_inherited,
345               boolean in_inherited)
346     {
347         checkNameInit(name, exclude_inherited, in_inherited, true);
348     }
349
350     /**
351      * Select named contained objects.
352      */

353     public java.util.List JavaDoc
354     selectNamedContained(java.util.List JavaDoc selection,
355                          String JavaDoc search_name,
356                          int levels_to_search,
357                          DefinitionKind limit_type,
358                          boolean exclude_inherited)
359     {
360         // call the Container_impl::selectContained operation.
361
super.selectNamedContained(selection, search_name, levels_to_search,
362                                    limit_type, exclude_inherited);
363
364         if(!exclude_inherited)
365         {
366             for(int i=0; i<supported_interfaces_.length; i++)
367             {
368                 supported_interfaces_[i].getImpl().selectNamedContained(selection,
369                                               search_name, levels_to_search,
370                                               limit_type, false);
371             }
372
373             if(getBaseValue().getImpl() != null)
374                 getBaseValue().getImpl().selectNamedContained(selection,
375                                               search_name, levels_to_search,
376                                               limit_type, false);
377
378             ValueDef_ref[] abs_refs = getAbstractBaseValues();
379             for(int i=0; i<abs_refs.length; i++)
380             {
381                 abs_refs[i].getImpl().selectNamedContained(selection,
382                                               search_name, levels_to_search,
383                                               limit_type, false);
384             }
385
386         }
387
388         return selection;
389     }
390
391     /**
392         Select contained objects.
393      */

394     public java.util.List JavaDoc
395     selectContained(java.util.List JavaDoc selection,
396                     DefinitionKind limit_type,
397                     boolean exclude_inherited)
398     {
399         // call the Container_impl::selectContained operation.
400
super.selectContained(selection, limit_type, exclude_inherited);
401
402         if(!exclude_inherited)
403         {
404             for(int i=0; i<supported_interfaces_.length; i++)
405             {
406                 supported_interfaces_[i].getImpl().selectContained(
407                                            selection, limit_type, false);
408             }
409
410             if(getBaseValue().getImpl() != null)
411                 getBaseValue().getImpl().selectContained(
412                                            selection, limit_type, false);
413
414             ValueDef_ref[] abs_refs = getAbstractBaseValues();
415             for(int i=0; i<abs_refs.length; i++)
416             {
417                 abs_refs[i].getImpl().selectContained(
418                                            selection, limit_type, false);
419             }
420
421         }
422
423         return selection;
424     }
425
426     // ==================================================================
427
//
428
// Internal methods for managing dependencies.
429
//
430
// ==================================================================
431

432     /**
433      * Cuts dependencies to other objects.
434      */

435     protected void
436     cutDependencies()
437     {
438         // Cuts the dependency to supported interfaces.
439
InterfaceDef_ref.cutDependencies(supported_interfaces_);
440         supported_interfaces_ = null;
441
442         // Cuts the dependency to initializers.
443
for(int i=0; i<initializers_.length; i++)
444             initializers_[i].cutDependencies();
445         initializers_ = null;
446
447         // Cuts the dependency to the base value.
448
base_value_.cutDependency();
449         base_value_ = null;
450
451         // Cuts the dependency to abstract base values.
452
ValueDef_ref.cutDependencies(abstract_base_values_);
453         abstract_base_values_ = null;
454
455         // Calls the Container_impl::cutDependencies operation.
456
super.cutDependencies();
457     }
458
459     // ==================================================================
460
//
461
// For CORBA::IRObject interface.
462
//
463
// ==================================================================
464

465     /**
466      * IDL:omg.org/CORBA/IRObject/def_kind:1.0
467      */

468     public DefinitionKind
469     def_kind()
470     {
471         return DefinitionKind.dk_Value;
472     }
473
474     // ==================================================================
475
//
476
// For CORBA::IDLType interface.
477
//
478
// ==================================================================
479

480     /**
481      * IDL:omg.org/CORBA/IDLType/type:1.0
482      */

483     public TypeCode
484     type()
485     {
486         // check for recursion.
487
java.util.List JavaDoc idSeq = new java.util.ArrayList JavaDoc();
488         return recursiveType(idSeq);
489     }
490
491     // ==================================================================
492
//
493
// For CORBA::Container interface.
494
//
495
// ==================================================================
496

497     /**
498      * IDL:omg.org/CORBA/Container/lookup:1.0
499      */

500     public Contained
501     lookup(String JavaDoc search_name)
502     {
503         // call the Container_impl::lookup operation.
504
Contained contained = super.lookup(search_name);
505
506         if (contained == null)
507         {
508             for(int i=0; i<supported_interfaces_.length; i++)
509             {
510                 contained = supported_interfaces_[i].getImpl().
511                                            lookup(search_name);
512                 if(contained != null)
513                     break;
514             }
515         }
516
517         if (contained == null)
518         {
519             if(getBaseValue().getImpl() != null)
520                 contained = getBaseValue().getImpl().lookup(search_name);
521         }
522
523         if (contained == null)
524         {
525             ValueDef_ref[] abs_refs = getAbstractBaseValues();
526             for(int i=0; i<abs_refs.length; i++)
527             {
528                 Contained contained2 = abs_refs[i].getImpl().lookup(search_name);
529                 if(contained2 != null)
530                 {
531                     if(contained != null)
532                     {
533                         String JavaDoc id1 = contained.id();
534                         String JavaDoc id2 = contained2.id();
535                         if(!id1.equals(id2))
536                             throw exceptionAmbiguousLookup(id1, id2);
537                     }
538
539                     contained = contained2;
540                 }
541             }
542         }
543
544         return contained;
545     }
546
547     // ==================================================================
548
//
549
// For CORBA::ValueDef interface.
550
//
551
// ==================================================================
552

553     /**
554      * IDL:omg.org/CORBA/ValueDef/supported_interfaces:1.0
555      */

556     public InterfaceDef[]
557     supported_interfaces()
558     {
559         return InterfaceDef_ref.computeInterfaceDefSeq(supported_interfaces_);
560     }
561
562     /**
563      * IDL:omg.org/CORBA/ValueDef/supported_interfaces:1.0
564      */

565     public void
566     supported_interfaces(InterfaceDef[] val)
567     {
568         InterfaceDef_impl[] itfs = new InterfaceDef_impl[val.length];
569         for (int i=0; i<val.length; i++)
570             itfs[i] = castToLocal(val[i]);
571
572         // TODO: check inheritance
573

574         InterfaceDef_ref[] refs = new InterfaceDef_ref[val.length];
575         for (int i=0; i<val.length; i++)
576             refs[i] = new InterfaceDef_ref( this, itfs[i] );
577
578         // cut the previous dependency to base interfaces.
579
InterfaceDef_ref.cutDependencies(supported_interfaces_);
580
581         supported_interfaces_ = refs;
582     }
583
584     /**
585      * IDL:omg.org/CORBA/ValueDef/initializers:1.0
586      */

587     public Initializer[]
588     initializers()
589     {
590         Initializer[] result = new Initializer[initializers_.length];
591
592         for(int i=0; i<result.length; i++)
593             result[i] = initializers_[i].getInitializer();
594
595         return result;
596     }
597
598     /**
599      * IDL:omg.org/CORBA/ValueDef/initializers:1.0
600      */

601     public void
602     initializers(Initializer[] val)
603     {
604         Initializer_impl[] tmp = new Initializer_impl[val.length];
605         for(int i=0; i<tmp.length; i++)
606         {
607             tmp[i] = new Initializer_impl(this);
608             tmp[i].setInitializer(val[i]);
609         }
610         initializers_ = tmp;
611     }
612
613     /**
614      * IDL:omg.org/CORBA/ValueDef/base_value:1.0
615      */

616     public ValueDef
617     base_value()
618     {
619         // delegate to the ValueDef reference.
620
return getBaseValue().asValueDef();
621     }
622
623     /**
624      * IDL:omg.org/CORBA/ValueDef/base_value:1.0
625      */

626     public void
627     base_value(ValueDef val)
628     {
629         if (val == null)
630             getBaseValue().setDependency(null);
631         else
632         {
633             // try to cast val to a local object
634
// and delegate to the ValueDef reference.
635
getBaseValue().setDependency( castToLocal(val) );
636         }
637     }
638
639     /**
640      * IDL:omg.org/CORBA/ValueDef/abstract_base_values:1.0
641      */

642     public ValueDef[]
643     abstract_base_values()
644     {
645         ValueDef_ref[] abs_refs = getAbstractBaseValues();
646         ValueDef[] result = new ValueDef[abs_refs.length];
647
648         for(int i=0; i<abs_refs.length; i++)
649              result[i] = abs_refs[i].asValueDef();
650
651         return result;
652     }
653
654     /**
655      * IDL:omg.org/CORBA/ValueDef/abstract_base_values:1.0
656      */

657     public void
658     abstract_base_values(ValueDef[] val)
659     {
660         ValueDef_impl[] values = new ValueDef_impl[val.length];
661         for (int i=0; i<val.length; i++)
662             values[i] = castToLocal(val[i]);
663
664         // TODO: check inheritance
665

666         ValueDef_ref[] refs = new ValueDef_ref[val.length];
667         for (int i=0; i<val.length; i++)
668             refs[i] = new ValueDef_ref( this, values[i] );
669
670         // cut the previous dependency to abstract base values.
671
ValueDef_ref.cutDependencies(abstract_base_values_);
672
673         abstract_base_values_ = refs;
674     }
675
676     /**
677      * IDL:omg.org/CORBA/ValueDef/is_abstract:1.0
678      */

679     public boolean
680     is_abstract()
681     {
682         return is_abstract_;
683     }
684
685     /**
686      * IDL:omg.org/CORBA/ValueDef/is_abstract:1.0
687      */

688     public void
689     is_abstract(boolean val)
690     {
691         // TODO: check
692
is_abstract_ = val;
693     }
694
695     /**
696      * IDL:omg.org/CORBA/ValueDef/is_custom:1.0
697      */

698     public boolean
699     is_custom()
700     {
701         return is_custom_;
702     }
703
704     /**
705      * IDL:omg.org/CORBA/ValueDef/is_custom:1.0
706      */

707     public void
708     is_custom(boolean val)
709     {
710         // TODO: check
711
is_custom_ = val;
712     }
713
714     /**
715      * IDL:omg.org/CORBA/ValueDef/is_truncatable:1.0
716      */

717     public boolean
718     is_truncatable()
719     {
720         return is_truncatable_;
721     }
722
723     /**
724      * IDL:omg.org/CORBA/ValueDef/is_truncatable:1.0
725      */

726     public void
727     is_truncatable(boolean val)
728     {
729         // TODO: check
730
is_truncatable_ = val;
731     }
732
733     /**
734      * IDL:omg.org/CORBA/ValueDef/is_a:1.0
735      */

736     public boolean
737     is_a(String JavaDoc the_id)
738     {
739         if(the_id.equals(id()))
740             return true;
741
742         for(int i=0; i<supported_interfaces_.length; i++)
743             if (supported_interfaces_[i].getImpl().is_a(the_id))
744                 return true;
745
746         if(getBaseValue().getImpl() != null
747            && getBaseValue().getImpl().is_a(the_id))
748             return true;
749
750         ValueDef_ref[] abs_refs = getAbstractBaseValues();
751         for(int i=0; i<abs_refs.length; i++)
752             if (abs_refs[i].getImpl().is_a(the_id))
753                 return true;
754
755         return false;
756     }
757
758     /**
759      * IDL:omg.org/CORBA/ValueDef/describe_value:1.0
760      */

761     public FullValueDescription
762     describe_value()
763     {
764         FullValueDescription description = new FullValueDescription();
765         description.name = name();
766         description.id = id();
767         description.is_abstract = is_abstract();
768         description.is_custom = is_custom();
769         description.defined_in = getContainerID();
770         description.version = version();
771         description.operations = getOpDescriptionSeq();
772         description.attributes = getAttrDescriptionSeq();
773         description.members = getValueMemberSeq();
774         description.initializers = initializers();
775         description.supported_interfaces = InterfaceDef_ref.
776                          computeRepositoryIdSeq(supported_interfaces_);
777         description.abstract_base_values = ValueDef_ref.
778                          computeRepositoryIdSeq(getAbstractBaseValues());
779         description.is_truncatable = is_truncatable();
780         description.base_value = getBaseValue().getId();
781         description.type = type();
782         return description;
783     }
784
785     /**
786      * IDL:omg.org/CORBA/ValueDef/create_value_member:1.0
787      */

788     public ValueMemberDef
789     create_value_member(String JavaDoc id,
790                         String JavaDoc name,
791                         String JavaDoc version,
792                         IDLType type,
793                         short access)
794     {
795         ValueMemberDef_impl vm = new ValueMemberDef_impl(getIFR(), this);
796
797         try
798         {
799             addContained(vm, id, name, version);
800             vm.type_def(type);
801             vm.access(access);
802         }
803         catch(SystemException exc)
804         {
805             vm.destroy();
806             throw exc;
807         }
808
809         return vm.asValueMemberDef();
810     }
811
812     /**
813      * IDL:omg.org/CORBA/ValueDef/create_attribute:1.0
814      */

815     public AttributeDef
816     create_attribute(String JavaDoc id,
817                      String JavaDoc name,
818                      String JavaDoc version,
819                      IDLType type,
820                      AttributeMode mode)
821     {
822         AttributeDef_impl attr = new AttributeDef_impl(getIFR(), this);
823
824         try
825         {
826             addContained(attr, id, name, version);
827             attr.type_def(type);
828             attr.mode(mode);
829         }
830         catch(SystemException exc)
831         {
832             attr.destroy();
833             throw exc;
834         }
835
836         return attr.asAttributeDef();
837     }
838
839     /**
840      * IDL:omg.org/CORBA/ValueDef/create_operation:1.0
841      */

842     public OperationDef
843     create_operation(String JavaDoc id,
844                      String JavaDoc name,
845                      String JavaDoc version,
846                      IDLType result,
847                      OperationMode mode,
848                      ParameterDescription[] params,
849                      ExceptionDef[] exceptions,
850                      String JavaDoc[] contexts)
851     {
852         OperationDef_impl op = new OperationDef_impl(getIFR(), this);
853
854         try
855         {
856             addContained(op, id, name, version);
857             op.result_def(result);
858             op.mode(mode);
859             op.params(params);
860             op.exceptions(exceptions);
861             op.contexts(contexts);
862         }
863         catch(SystemException exc)
864         {
865             op.destroy();
866             throw exc;
867         }
868
869         return op.asOperationDef();
870     }
871 }
872
Popular Tags