1 20 21 package org.jacorb.idl; 22 23 import java.io.PrintWriter ; 24 import java.util.*; 25 26 30 31 class InitDecl 32 extends Declaration 33 { 34 public Vector paramDecls; 35 public IdlSymbol myValue; 36 37 38 public RaisesExpr raisesExpr; 39 40 public InitDecl( int num ) 41 { 42 super( num ); 43 paramDecls = new Vector(); 44 } 45 46 public void setPackage( String s ) 47 { 48 s = parser.pack_replace( s ); 49 50 if( pack_name.length() > 0 ) 51 pack_name = s + "." + pack_name; 52 else 53 pack_name = s; 54 55 for( Enumeration e = paramDecls.elements(); 56 e.hasMoreElements(); 57 ( (ParamDecl)e.nextElement() ).setPackage( s ) 58 ) 59 ; 60 raisesExpr.setPackage( s ); 61 } 62 63 public void setEnclosingSymbol( IdlSymbol s ) 64 { 65 if( enclosing_symbol != null && enclosing_symbol != s ) 66 throw new RuntimeException ( "Compiler Error: trying to reassign container for " 67 + name ); 68 enclosing_symbol = s; 69 raisesExpr.setEnclosingSymbol( s ); 70 } 71 72 public void parse() 73 { 74 myValue = enclosing_symbol; 75 76 try 77 { 78 NameTable.define( full_name(), "factory" ); 79 } 80 catch( NameAlreadyDefined nad ) 81 { 82 parser.error( "Factory " + full_name() + " already defined", token ); 83 } 84 85 for( Enumeration e = paramDecls.elements(); e.hasMoreElements(); ) 86 { 87 ParamDecl param = (ParamDecl)e.nextElement(); 88 param.parse(); 89 try 90 { 91 NameTable.define( full_name() + "." + 92 param.simple_declarator.name(), 93 "argument" ); 94 } 95 catch( NameAlreadyDefined nad ) 96 { 97 parser.error( "Argument " + param.simple_declarator.name() + 98 " already defined in operation " + full_name(), 99 token ); 100 } 101 } 102 raisesExpr.parse(); 103 } 104 105 109 public void print( PrintWriter ps, String type_name ) 110 { 111 ps.print( "\t" + type_name + " " + name + "( " ); 112 113 Enumeration e = paramDecls.elements(); 114 115 if( e.hasMoreElements() ) 116 ( (ParamDecl)e.nextElement() ).print( ps ); 117 118 for( ; e.hasMoreElements(); ) 119 { 120 ps.print( ", " ); 121 ( (ParamDecl)e.nextElement() ).print( ps ); 122 } 123 ps.print( ")" ); 124 raisesExpr.print( ps ); 125 ps.println( ";" ); 126 } 127 128 131 public void printHelperMethod( PrintWriter ps, String type_name ) 132 { 133 ps.print( "\tpublic static " + type_name + " " + name + "( " ); 134 ps.print( "org.omg.CORBA.ORB orb" ); 135 136 for ( Enumeration e = paramDecls.elements(); 137 e.hasMoreElements(); ) 138 { 139 ps.print( ", " ); 140 ( (ParamDecl)e.nextElement() ).print( ps ); 141 } 142 ps.println (" )"); 143 144 ps.println ("\t{"); 145 ps.println ("\t\t" + type_name + "ValueFactory f = " 146 + "( " + type_name + "ValueFactory )" 147 + "((org.omg.CORBA_2_3.ORB)orb).lookup_value_factory(id());"); 148 ps.println ("\t\tif (f == null)"); 149 ps.println ("\t\t\tthrow new org.omg.CORBA.MARSHAL( " 150 + "1, org.omg.CORBA.CompletionStatus.COMPLETED_NO );"); 151 ps.print ("\t\treturn f." + name + "( "); 152 153 for ( Enumeration e = paramDecls.elements(); 154 e.hasMoreElements(); ) 155 { 156 ps.print (( (ParamDecl)e.nextElement() ).simple_declarator ); 157 if (e.hasMoreElements()) ps.print (", "); 158 } 159 160 ps.println (" );"); 161 162 ps.println ("\t}"); 163 } 164 165 public String name() 166 { 167 return name; 168 } 169 170 171 public String opName() 172 { 173 return name(); 174 } 175 176 177 } 178 179 180 181 182 183 184 185 | Popular Tags |