1 6 7 package SOFA.Connector.EEG.EEM.Elements; 8 9 import SOFA.Connector.EEG.CodeWriter.CDL2IDL2JavaMapping; 10 import SOFA.Connector.EEG.CodeWriter.CodeWriterException; 11 import SOFA.Connector.EEG.CodeWriter.JWriterDirectorException; 12 import SOFA.Connector.EEG.EEM.Actions.JIfaceCN; 13 import SOFA.Connector.EEG.EEM.Actions.JIfaceCNCORBA; 14 import SOFA.Connector.EEG.EEM.Actions.JImplWriterDirectorBase; 15 import SOFA.SOFAnode.Made.TIR.OperationDef; 16 import SOFA.SOFAnode.Made.TIR.ParamDescr; 17 import SOFA.SOFAnode.Made.TIR.ParamMode; 18 import SOFA.SOFAnode.Made.TIR.TIRExceptLock; 19 20 25 public class CORBAStubGen extends JImplWriterDirectorBase { 26 27 28 public CORBAStubGen(String provIfaceCDL, SOFA.Connector.Property[] params) { 29 super(provIfaceCDL,params); 30 } 31 32 public String [] getImplements() { 33 return new String [] {"SOFA.Connector.EEG.Types.Stub"}; 34 } 35 36 public String getClassBody() { 37 String reqIfaceMapped=SOFA.Connector.Property.findFirst(params,"reqIfaceMapped"); 38 return managerTieImpl() + "\n" + 39 "\tprotected "+reqIfaceMapped+" target;\n\n"+ 40 "\tpublic void link(SOFA.Connector.TaggedProfile target) throws SOFA.Connector.LinkException {\n"+ 41 "\t\ttry {\n"+ 42 "\t\t\torg.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init((String[])null, null);\n"+ 43 "\t\t\tthis.target = "+reqIfaceMapped+"Helper.narrow(orb.string_to_object(((SOFA.Connector.ECG.Profiles.CORBAProfile)target).IOR));\n"+ 44 "\t\t} catch (Exception e) {\n"+ 45 "\t\t\tthrow new SOFA.Connector.LinkException(\"Can't link to '\"+((SOFA.Connector.ECG.Profiles.CORBAProfile)target).IOR+\"'.\",e);\n"+ 46 "\t\t}\n"+ 47 "\t}\n\n"+ 48 "\tpublic String[] getSupportedProfiles() {\n"+ 49 "\t\treturn new String[] {\"CORBA\"};\n"+ 50 "\t}\n"; 51 } 52 53 public String getMethodDef(OperationDef mt) throws JWriterDirectorException { 54 return JIfaceCN.getMethodDef(mt); 55 } 56 57 public String getMethodBody(OperationDef method) throws JWriterDirectorException { 58 try { 59 String ret="\t\ttry {\n"; 60 61 int i; 62 ParamDescr[] params=method.params(); 63 64 for (i=0;i<params.length;i++) { 65 int mode=params[i].mode().value(); 66 if (mode==ParamMode.PARAM_INOUT || mode==ParamMode.PARAM_OUT) { 67 String holderName=CDL2IDL2JavaMapping.getTypeName(params[i].type(),mode); 68 ret+="\t\t\t"+holderName+" _corbaholder_"+params[i].name()+"=new "+holderName+"(); _corbaholder_"+params[i].name()+".value="+params[i].name()+".value;\n"; 69 } 70 } 71 72 ret+="\t\t\t"+declareRet(method,"ret")+"\n"+ 73 "\t\t\t"+assignRet(method,"ret")+targetCall(method,JIfaceCNCORBA.targetCallParams(method))+";\n"; 74 75 for (i=0;i<params.length;i++) { 76 int mode=params[i].mode().value(); 77 if (mode==ParamMode.PARAM_INOUT || mode==ParamMode.PARAM_OUT) { 78 ret+="\t\t\t"+params[i].name()+".value=_corbaholder_"+params[i].name()+".value;\n"; 79 } 80 } 81 82 ret+="\t\t\t"+returnRet(method,"ret")+"\n"+ 83 "\t\t} catch (org.omg.CORBA.SystemException e) {\n"+ 84 "\t\t\tthrow new SOFA.Connector.ConnectorTransportException(\"Can't call method '"+method.get_identification().absolute_name().name()+"'.\",e);\n"+ 85 "\t\t}\n"; 86 87 return ret; 88 89 } catch (java.rmi.RemoteException e) { 90 throw new JWriterDirectorException("Cannot access TIR.",e); 91 } catch (TIRExceptLock e) { 92 throw new JWriterDirectorException("Cannot access TIR.",e); 93 } catch (CodeWriterException e) { 94 throw new JWriterDirectorException("Cannot map operation to Java.",e); 95 } 96 97 } 98 } 99 | Popular Tags |