KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > ir > AttributeDef


1 /*
2  * JacORB - a free Java ORB
3  *
4  * Copyright (C) 1997-2004 Gerald Brose.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */

20
21 package org.jacorb.ir;
22
23 import java.lang.reflect.*;
24 import java.util.*;
25
26 import org.omg.CORBA.INTF_REPOS JavaDoc;
27 import org.omg.CORBA.TypeCode JavaDoc;
28 import org.omg.PortableServer.POA JavaDoc;
29
30 import org.apache.avalon.framework.logger.Logger;
31
32 public class AttributeDef
33     extends Contained
34     implements org.omg.CORBA.AttributeDefOperations JavaDoc
35 {
36     private org.omg.CORBA.TypeCode JavaDoc typeCode = null;
37     private org.omg.CORBA.IDLType JavaDoc type_def = null;
38     private org.omg.CORBA.AttributeMode JavaDoc mode = null;
39     private Method method = null;
40     private boolean defined = false;
41     private Logger logger;
42     private POA JavaDoc poa;
43
44     public AttributeDef( java.lang.reflect.Method JavaDoc m,
45                          String JavaDoc attrTypeName,
46                          org.omg.CORBA.AttributeMode JavaDoc mode,
47                          org.omg.CORBA.Container JavaDoc _defined_in,
48                          org.omg.CORBA.Repository JavaDoc _containing_repository,
49                          Logger logger ,
50                          ClassLoader JavaDoc loader,
51                          POA JavaDoc poa)
52     {
53         this.logger = logger;
54         this.poa = poa;
55         def_kind = org.omg.CORBA.DefinitionKind.dk_Attribute;
56         method = m;
57         this.mode = mode;
58         name( m.getName() );
59         version( "1.0" );
60
61         try
62         {
63             typeCode =
64                 TypeCodeUtil.getTypeCode( m.getReturnType(),
65                                           loader,
66                                           null,
67                                           attrTypeName,
68                                           this.logger);
69         }
70         catch( ClassNotFoundException JavaDoc cnfe )
71         {
72             this.logger.error("Error: TypeCode for AttributeDef could not be created!",
73                               cnfe);
74         }
75
76         defined_in = _defined_in;
77         containing_repository = _containing_repository;
78
79         if (containing_repository == null)
80         {
81             throw new INTF_REPOS JavaDoc ("containing_repository null");
82         }
83         if (defined_in == null)
84         {
85             throw new INTF_REPOS JavaDoc ("defined_in null");
86         }
87
88         org.omg.CORBA.Contained JavaDoc myContainer =
89             org.omg.CORBA.ContainedHelper.narrow( defined_in );
90         String JavaDoc interface_id = myContainer.id();
91
92         id = interface_id.substring(interface_id.lastIndexOf(':')-1) +
93             name() + ":" + version();
94         absolute_name = myContainer.absolute_name() + "::" + name();
95
96         if (this.logger.isDebugEnabled())
97         {
98             this.logger.debug("New AttributeDef, name: " + name() +
99                               " " + absolute_name);
100         }
101     }
102
103     public org.omg.CORBA.TypeCode JavaDoc type()
104     {
105         return typeCode;
106     }
107
108     public org.omg.CORBA.IDLType JavaDoc type_def()
109     {
110         return type_def;
111     }
112
113     public void type_def(org.omg.CORBA.IDLType JavaDoc a)
114     {
115         if (defined == false)
116         {
117             throw new INTF_REPOS JavaDoc ("Attribute not defined" );
118         }
119         type_def = a;
120     }
121
122     public org.omg.CORBA.AttributeMode JavaDoc mode()
123     {
124         return mode;
125     }
126
127     public void mode(org.omg.CORBA.AttributeMode JavaDoc a)
128     {
129         mode = a;
130     }
131
132     org.omg.CORBA.AttributeDescription JavaDoc describe_attribute()
133     {
134         return new org.omg.CORBA.AttributeDescription JavaDoc(
135                                         name(),
136                                         id(),
137                                         org.omg.CORBA.ContainedHelper.narrow(defined_in).id(),
138                                         version(),
139                                         type(),
140                                         mode());
141     }
142
143     public void define()
144     {
145         type_def = IDLType.create(typeCode, containing_repository,
146                                   this.logger, this.poa );
147         defined = true;
148     }
149
150     // from Contained
151

152     public org.omg.CORBA.ContainedPackage.Description describe()
153     {
154         org.omg.CORBA.Any JavaDoc a = orb.create_any();
155         org.omg.CORBA.AttributeDescriptionHelper.insert( a, describe_attribute() );
156         return new org.omg.CORBA.ContainedPackage.Description(
157               org.omg.CORBA.DefinitionKind.dk_Attribute, a);
158     }
159
160     // from IRObject
161

162     public void destroy()
163     {}
164
165
166 }
167
Popular Tags