001: /*
002: * JacORB - a free Java ORB
003: *
004: * Copyright (C) 1997-2004 Gerald Brose.
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Library General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Library General Public License for more details.
015: *
016: * You should have received a copy of the GNU Library General Public
017: * License along with this library; if not, write to the Free
018: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
019: */
020:
021: package org.jacorb.ir;
022:
023: import java.lang.reflect.*;
024: import java.util.*;
025:
026: import org.omg.CORBA.INTF_REPOS;
027: import org.omg.CORBA.TypeCode;
028: import org.omg.PortableServer.POA;
029:
030: import org.apache.avalon.framework.logger.Logger;
031:
032: public class AttributeDef extends Contained implements
033: org.omg.CORBA.AttributeDefOperations {
034: private org.omg.CORBA.TypeCode typeCode = null;
035: private org.omg.CORBA.IDLType type_def = null;
036: private org.omg.CORBA.AttributeMode mode = null;
037: private Method method = null;
038: private boolean defined = false;
039: private Logger logger;
040: private POA poa;
041:
042: public AttributeDef(java.lang.reflect.Method m,
043: String attrTypeName, org.omg.CORBA.AttributeMode mode,
044: org.omg.CORBA.Container _defined_in,
045: org.omg.CORBA.Repository _containing_repository,
046: Logger logger, ClassLoader loader, POA poa) {
047: this .logger = logger;
048: this .poa = poa;
049: def_kind = org.omg.CORBA.DefinitionKind.dk_Attribute;
050: method = m;
051: this .mode = mode;
052: name(m.getName());
053: version("1.0");
054:
055: try {
056: typeCode = TypeCodeUtil.getTypeCode(m.getReturnType(),
057: loader, null, attrTypeName, this .logger);
058: } catch (ClassNotFoundException cnfe) {
059: this .logger
060: .error(
061: "Error: TypeCode for AttributeDef could not be created!",
062: cnfe);
063: }
064:
065: defined_in = _defined_in;
066: containing_repository = _containing_repository;
067:
068: if (containing_repository == null) {
069: throw new INTF_REPOS("containing_repository null");
070: }
071: if (defined_in == null) {
072: throw new INTF_REPOS("defined_in null");
073: }
074:
075: org.omg.CORBA.Contained myContainer = org.omg.CORBA.ContainedHelper
076: .narrow(defined_in);
077: String interface_id = myContainer.id();
078:
079: id = interface_id.substring(interface_id.lastIndexOf(':') - 1)
080: + name() + ":" + version();
081: absolute_name = myContainer.absolute_name() + "::" + name();
082:
083: if (this .logger.isDebugEnabled()) {
084: this .logger.debug("New AttributeDef, name: " + name() + " "
085: + absolute_name);
086: }
087: }
088:
089: public org.omg.CORBA.TypeCode type() {
090: return typeCode;
091: }
092:
093: public org.omg.CORBA.IDLType type_def() {
094: return type_def;
095: }
096:
097: public void type_def(org.omg.CORBA.IDLType a) {
098: if (defined == false) {
099: throw new INTF_REPOS("Attribute not defined");
100: }
101: type_def = a;
102: }
103:
104: public org.omg.CORBA.AttributeMode mode() {
105: return mode;
106: }
107:
108: public void mode(org.omg.CORBA.AttributeMode a) {
109: mode = a;
110: }
111:
112: org.omg.CORBA.AttributeDescription describe_attribute() {
113: return new org.omg.CORBA.AttributeDescription(name(), id(),
114: org.omg.CORBA.ContainedHelper.narrow(defined_in).id(),
115: version(), type(), mode());
116: }
117:
118: public void define() {
119: type_def = IDLType.create(typeCode, containing_repository,
120: this .logger, this .poa);
121: defined = true;
122: }
123:
124: // from Contained
125:
126: public org.omg.CORBA.ContainedPackage.Description describe() {
127: org.omg.CORBA.Any a = orb.create_any();
128: org.omg.CORBA.AttributeDescriptionHelper.insert(a,
129: describe_attribute());
130: return new org.omg.CORBA.ContainedPackage.Description(
131: org.omg.CORBA.DefinitionKind.dk_Attribute, a);
132: }
133:
134: // from IRObject
135:
136: public void destroy() {
137: }
138:
139: }
|