1 6 7 package SOFA.Connector.EEG.EEM.Elements; 8 9 import SOFA.Connector.EEG.CodeWriter.JWriterDirectorException; 10 import SOFA.Connector.EEG.EEM.Actions.JImplWriterDirectorBase; 11 import SOFA.SOFAnode.Made.TIR.OperationDef; 12 13 18 public class DataStreamLocalSenderGen extends JImplWriterDirectorBase { 19 20 protected String is, os, bh, isPackage, osPackage; 21 22 protected static final int pullMode=0; 23 protected static final int pushMode=1; 24 25 protected int sMode, rMode; 26 27 28 public DataStreamLocalSenderGen(String provIfaceCDL, SOFA.Connector.Property[] params) throws JWriterDirectorException { 29 super(provIfaceCDL,params); 30 isPackage=SOFA.Connector.Property.findFirst(params,"isPackage"); 31 osPackage=SOFA.Connector.Property.findFirst(params,"osPackage"); 32 is=isPackage+".CNInterface"; 33 os=osPackage+".CNInterface"; 34 bh="SOFA.Connector.EEG.Types.DataStream.bytesHolder"; 35 36 String mode=SOFA.Connector.Property.findFirst(params,"senderMode"); 37 if (mode!=null) { 38 if (mode.equals("push")) { 39 sMode=pushMode; 40 } else if (mode.equals("pull")) { 41 sMode=pullMode; 42 } else { 43 throw new JWriterDirectorException("Parameter senderMode is incorrect '"+mode+"'."); 44 } 45 } else { 46 throw new JWriterDirectorException("Parameter senderMode is not specified"); 47 } 48 49 mode=SOFA.Connector.Property.findFirst(params,"receiverMode"); 50 if (mode!=null) { 51 if (mode.equals("push")) { 52 rMode=pushMode; 53 } else if (mode.equals("pull")) { 54 rMode=pullMode; 55 } else { 56 throw new JWriterDirectorException("Parameter receiverMode is incorrect '"+mode+"'."); 57 } 58 } else { 59 throw new JWriterDirectorException("Parameter receiverMode is not specified"); 60 } 61 62 if (sMode==pullMode && rMode==pushMode) { 63 throw new JWriterDirectorException("Mode sender-push/receiver-pull is not supported."); 64 } 65 } 66 67 public String [] getImplements() { 68 if (sMode==pullMode) { 69 return new String [] {"SOFA.Connector.EEG.Types.Sender",is,"SOFA.Connector.Linkable"}; 70 } else { 71 return new String [] {"SOFA.Connector.EEG.Types.Sender",os}; 72 } 73 } 74 75 public String getClassBody() throws JWriterDirectorException { 76 String methods; 77 if (sMode==pushMode) { 78 methods= 79 "\tpublic void write(byte[] buffer, int len, String thr_id) {\n"+ 80 "\t\treceiverWriteParams[0]=buffer;\n"+ 81 "\t\treceiverWriteParams[1]=new Integer(len);\n"+ 82 "\t\treceiverWriteParams[2]=thr_id;\n"+ 83 "\t\ttry {\n"+ 84 "\t\t\treceiverWrite.invoke(receiver,receiverWriteParams);\n"+ 85 "\t\t} catch (IllegalAccessException _e) {\n"+ 86 "\t\t\tthrow new SOFA.Connector.ConnectorTransportException(\"IllegalAccessException\", _e);\n"+ 87 "\t\t} catch (java.lang.reflect.InvocationTargetException _e) {\n"+ 88 "\t\t\tthrow new SOFA.Connector.ConnectorTransportException(\"InvocationTargetException\", _e);\n"+ 89 "\t\t}\n"+ 90 "\t}\n\n"; 91 } else if (sMode==pullMode && rMode==pullMode) { 92 methods= 93 "\tpublic int read("+bh+" bufferHolder, int len, String thr_id) {"+ 94 "\t\treturn client.read(bufferHolder,len,thr_id);\n"+ 95 "\t}\n\n"; 96 } else { 97 throw new JWriterDirectorException("Mode sender-push/receiver-pull is not supported."); 98 } 99 100 return managerTieImpl() + "\n" + 101 (sMode==pushMode ? "\tprotected java.lang.reflect.Method receiverWrite;\n"+ 102 "\tprotected Object receiverWriteParams[]=new Object[3];\n" : "" ) + 103 "\tprotected Object receiver;\n"+ 104 "\tprotected "+is+" client;\n\n"+ 105 "\tpublic void link(Object target) throws SOFA.Connector.LinkException {\n"+ 106 "\t\tif (target instanceof SOFA.Connector.TaggedProfile) {\n"+ 107 "\t\t\treceiver=((SOFA.Connector.ECG.Profiles.LocalProfile)target).link;\n"+ 108 (sMode==pushMode ? "\t\t\ttry {\n"+ 109 "\t\t\t\treceiverWrite=receiver.getClass().getMethod(\"write\",new Class[] {byte[].class, Integer.TYPE, String.class});\n"+ 110 "\t\t\t} catch (NoSuchMethodException e) {\n"+ 111 "\t\t\t\tthrow new SOFA.Connector.LinkException(\"Cannot create dynamic local binding\",e);\n"+ 112 "\t\t\t}\n" : "" ) + 113 (sMode==pullMode && rMode==pullMode ? "\t\t\t((SOFA.Connector.EEG.EEM.Elements.DataStreamLocalNotifiable)receiver).linkNotification(this);\n" : "")+ 114 "\t\t} else {\n"+ 115 "\t\t\tclient=("+is+")target;\n"+ 116 "\t\t}\n"+ 117 "\t}\n\n"+ 118 "\tpublic String[] getSupportedProfiles() {\n"+ 119 "\t\treturn new String[] {\"LOCAL\"};\n"+ 120 "\t}\n\n"+methods+"\n\n"+ 121 "\tpublic org.objectweb.fractal.api.Type getFcItfType() { return null; }\n"+ 122 "\tpublic boolean isFcInternalItf() { return false; }\n"+ 123 "\tpublic String getFcItfName() { throw new SOFA.Connector.ConnectorTransportException(\"Interconection via EventPassing connector - getFcItfName is not supported.\"); }\n"+ 124 "\tpublic org.objectweb.fractal.api.Component getFcItfOwner() { throw new SOFA.Connector.ConnectorTransportException(\"Interconection via EventPassing connector - getFcItfOwner is not supported.\"); }\n\n"; 125 } 126 127 public String getMethodDef(OperationDef mt) throws JWriterDirectorException { 128 return null; 129 } 130 131 public boolean defaultImplements() { 132 return false; 133 } 134 } 135 | Popular Tags |