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.idl;
022:
023: import java.io.PrintWriter;
024: import java.util.*;
025:
026: /**
027: * @author Gerald Brose
028: * @version $Id: AttrDecl.java,v 1.18 2006/10/13 19:59:25 andre.spiegel Exp $
029: */
030:
031: public class AttrDecl extends Declaration {
032: public boolean readOnly;
033: public TypeSpec param_type_spec;
034: public SymbolList declarators;
035:
036: public RaisesExpr getRaisesExpr;
037: public RaisesExpr setRaisesExpr;
038:
039: private Vector operations = new Vector();
040:
041: public AttrDecl(int num) {
042: super (num);
043: }
044:
045: public void setPackage(String s) {
046: s = parser.pack_replace(s);
047: if (pack_name.length() > 0)
048: pack_name = s + "." + pack_name;
049: else
050: pack_name = s;
051: declarators.setPackage(s);
052: param_type_spec.setPackage(s);
053: getRaisesExpr.setPackage(s);
054: setRaisesExpr.setPackage(s);
055: }
056:
057: public void setEnclosingSymbol(IdlSymbol s) {
058: if (logger.isDebugEnabled())
059: logger.debug("opDecl.setEnclosingSymbol " + s);
060:
061: if (enclosing_symbol != null && enclosing_symbol != s)
062: throw new RuntimeException(
063: "Compiler Error: trying to reassign container for "
064: + name);
065: if (s == null)
066: throw new RuntimeException(
067: "Compiler Error: enclosing symbol is null!");
068:
069: enclosing_symbol = s;
070: getRaisesExpr.setEnclosingSymbol(s);
071: setRaisesExpr.setEnclosingSymbol(s);
072: }
073:
074: public void parse() {
075: IdlSymbol myInterface = enclosing_symbol;
076:
077: if (param_type_spec.typeSpec() instanceof ScopedName) {
078: TypeSpec ts = ((ScopedName) param_type_spec.typeSpec())
079: .resolvedTypeSpec();
080: if (ts != null)
081: param_type_spec = ts;
082:
083: myInterface.addImportedName(ts.typeName());
084: }
085:
086: // declarator names can be left unparsed to tolerate buggy
087: // IDL generated by rmic
088: if (parser.strict_attributes) {
089: declarators.parse();
090: }
091:
092: getRaisesExpr.parse();
093: setRaisesExpr.parse();
094:
095: for (Enumeration e = declarators.v.elements(); e
096: .hasMoreElements();) {
097: operations.addElement(new Method(param_type_spec, null,
098: ((SimpleDeclarator) e.nextElement()).name(),
099: getRaisesExpr, is_pseudo));
100: }
101:
102: if (!readOnly) {
103: for (Enumeration e = declarators.v.elements(); e
104: .hasMoreElements();) {
105: SimpleDeclarator d = (SimpleDeclarator) e.nextElement();
106: operations.addElement(new Method(null, param_type_spec,
107: d.name(), setRaisesExpr, is_pseudo));
108: }
109: }
110: }
111:
112: public void print(PrintWriter ps) {
113: }
114:
115: public Enumeration getOperations() {
116: return operations.elements();
117: }
118:
119: /**
120: * collect Interface Repository information in the argument hashtable
121: */
122:
123: public void getIRInfo(Hashtable irInfoTable) {
124: for (Enumeration e = declarators.v.elements(); e
125: .hasMoreElements();) {
126: String fullName = param_type_spec.full_name();
127: irInfoTable.put(
128: ((SimpleDeclarator) e.nextElement()).name(),
129: "attribute"
130: + (readOnly ? "" : "-w")
131: + ";"
132: + (fullName != null ? fullName
133: : param_type_spec.typeName()));
134: }
135: }
136:
137: }
|