001: package org.jacorb.idl;
002:
003: /*
004: * JacORB - a free Java ORB
005: *
006: * Copyright (C) 1997-2004 Gerald Brose.
007: *
008: * This library is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU Library General Public
010: * License as published by the Free Software Foundation; either
011: * version 2 of the License, or (at your option) any later version.
012: *
013: * This library is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * Library General Public License for more details.
017: *
018: * You should have received a copy of the GNU Library General Public
019: * License along with this library; if not, write to the Free
020: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021: */
022:
023: import java.io.PrintWriter;
024: import java.util.*;
025:
026: /**
027: * @author Gerald Brose
028: * @version $Id: RaisesExpr.java,v 1.17 2006/10/13 20:01:48 andre.spiegel Exp $
029: */
030:
031: public class RaisesExpr extends IdlSymbol {
032: public Vector nameList;
033:
034: public RaisesExpr(int num) {
035: super (num);
036: nameList = new Vector();
037: }
038:
039: /**
040: * Constructs an empty RaisesExpr
041: */
042: public RaisesExpr() {
043: this (new_num());
044: }
045:
046: /**
047: * Constructs a
048: * @param nameList
049: */
050: public RaisesExpr(Vector nameList) {
051: super (new_num());
052: this .nameList = (Vector) nameList.clone();
053: }
054:
055: public void setPackage(String s) {
056: s = parser.pack_replace(s);
057: for (Enumeration e = nameList.elements(); e.hasMoreElements(); ((ScopedName) e
058: .nextElement()).setPackage(s))
059: ;
060: }
061:
062: public boolean empty() {
063: return (nameList.size() == 0);
064: }
065:
066: public String[] getExceptionNames() {
067: String[] result = new String[nameList.size()];
068: Enumeration e = nameList.elements();
069: for (int i = 0; i < result.length; i++) {
070: result[i] = ((ScopedName) e.nextElement()).toString();
071: }
072: return result;
073: }
074:
075: public String[] getExceptionIds() {
076: String[] result = new String[nameList.size()];
077: Enumeration e = nameList.elements();
078: for (int i = 0; i < result.length; i++) {
079: result[i] = ((ScopedName) e.nextElement()).id();
080: }
081: return result;
082: }
083:
084: public String[] getExceptionClassNames() {
085: String[] result = new String[nameList.size()];
086: Enumeration e = nameList.elements();
087: for (int i = 0; i < result.length; i++) {
088: result[i] = ((ScopedName) e.nextElement()).toString();
089: }
090: return result;
091: }
092:
093: public void parse() {
094: Hashtable h = new Hashtable(); // for removing duplicate exception names
095: for (Enumeration e = nameList.elements(); e.hasMoreElements();) {
096: ScopedName name = null;
097: try {
098: name = (ScopedName) e.nextElement();
099: TypeSpec ts = name.resolvedTypeSpec();
100: if (((StructType) ((ConstrTypeSpec) ts).declaration())
101: .isException()) {
102: h.put(name.resolvedName(), name);
103: continue; // ok
104: }
105: // else: go to the exception
106: } catch (Exception ex) {
107: // any type cast errors
108: }
109: parser.fatal_error("Illegal type in raises clause: "
110: + name.toString(), token);
111: }
112: // remove duplicate exceptions, i.e. ScopedNames that, when
113: // fully qualified, point to the same exception declaration
114: nameList = new Vector();
115: for (Enumeration e = h.keys(); e.hasMoreElements();) {
116: nameList.addElement(h.get(e.nextElement()));
117: }
118: h.clear();
119: String[] classes = getExceptionClassNames();
120:
121: IdlSymbol myInterface = enclosing_symbol;
122:
123: for (int i = 0; i < classes.length; i++) {
124: myInterface.addImportedName(classes[i]);
125: }
126: }
127:
128: public void print(PrintWriter ps) {
129: Enumeration e = nameList.elements();
130: if (e.hasMoreElements()) {
131: ps.print(" throws " + e.nextElement());
132: }
133: for (; e.hasMoreElements();) {
134: ps.print("," + e.nextElement());
135: }
136: }
137: }
|