1 26 27 package org.objectweb.fractal.rmi.stub; 28 29 import org.objectweb.fractal.api.Component; 30 import org.objectweb.fractal.api.Interface; 31 import org.objectweb.fractal.api.Type; 32 33 import org.objectweb.jonathan.apis.kernel.JonathanException; 34 import org.objectweb.jonathan.apis.presentation.Marshaller; 35 import org.objectweb.jonathan.apis.presentation.UnMarshaller; 36 import org.objectweb.jonathan.apis.protocols.ReplySession; 37 import org.objectweb.jonathan.apis.protocols.RequestSession; 38 39 48 49 public abstract class Skeleton implements RequestSession { 50 51 54 55 protected Object target; 56 57 60 61 public Skeleton () { 62 } 63 64 68 73 74 public Object getTarget () { 75 return target; 76 } 77 78 89 90 public abstract void send (UnMarshaller unmarshaller, ReplySession session) 91 throws JonathanException; 92 93 97 106 107 protected void handleInterfaceMethods ( 108 final UnMarshaller unmarshaller, 109 final ReplySession session, 110 final int methodIndex) throws JonathanException 111 { 112 Interface itf = (Interface)target; 113 Marshaller marshaller; 114 try { 115 switch (methodIndex) { 116 case -1: 117 unmarshaller.close(); 118 Component id = itf.getFcItfOwner(); 119 marshaller = session.prepareReply(); 120 marshaller.writeValue(id); 121 session.send(marshaller); 122 session.close(); 123 return; 124 case -2: 125 unmarshaller.close(); 126 String name = itf.getFcItfName(); 127 marshaller = session.prepareReply(); 128 marshaller.writeValue(name); 129 session.send(marshaller); 130 session.close(); 131 return; 132 case -3: 133 unmarshaller.close(); 134 Type type = itf.getFcItfType(); 135 marshaller = session.prepareReply(); 136 marshaller.writeValue(type); 137 session.send(marshaller); 138 session.close(); 139 return; 140 case -4: 141 unmarshaller.close(); 142 boolean internal = itf.isFcInternalItf(); 143 marshaller = session.prepareReply(); 144 marshaller.writeBoolean(internal); 145 session.send(marshaller); 146 session.close(); 147 return; 148 default: 149 throw new Exception ("No such method"); 150 } 151 } catch (Exception e) { 152 handleException(e, session); 153 } 154 } 155 156 165 166 protected void handleException (final Exception e, final ReplySession session) 167 throws JonathanException 168 { 169 try { 170 Marshaller marshaller = session.prepareExceptionReply(); 171 marshaller.writeValue(e); 172 session.send(marshaller); 173 } catch (Exception f) { 174 f.printStackTrace(); 175 throw new JonathanException( 176 "error during marshalling of exception by skeleton"); 177 } 178 session.close(); 179 } 180 181 protected Object replaceClassName (Object o) throws ClassNotFoundException { 182 if (o instanceof String ) { 183 return Class.forName((String )o); 184 } else if (o instanceof Object []) { 185 Object [] desc = (Object [])o; 186 if (desc.length == 2 && desc[1] instanceof String ) { 187 return new Object [] { desc[0], Class.forName((String )desc[1]) }; 188 } 189 } 190 return o; 191 } 192 193 protected Object replaceClassValue (Object o) { 194 if (o instanceof Class ) { 195 return ((Class )o).getName(); 196 } else if (o instanceof Object []) { 197 Object [] desc = (Object [])o; 198 if (desc.length == 2 && desc[1] instanceof Class ) { 199 return new Object [] { desc[0], ((Class )desc[1]).getName() }; 200 } 201 } 202 return o; 203 } 204 } 205 | Popular Tags |