Main Page   Packages   Class Hierarchy   Compound List   File List   Compound Members  

JRMITSHandler.java

Go to the documentation of this file.
00001 /***
00002  * Jonathan: an Open Distributed Processing Environment 
00003  * Copyright (C) 1999-2000 France Telecom R&D
00004  * 
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Lesser General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2 of the License, or (at your option) any later version.
00009  * 
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Lesser General Public License for more details.
00014  * 
00015  * You should have received a copy of the GNU Lesser General Public
00016  * License along with this library; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  * 
00019  * Release: 3.0
00020  *
00021  * Contact: jonathan@objectweb.org
00022  *
00023  * Author: Bruno Dumant
00024  *
00025  * with contributions from:
00026  *   Alexis Chemin
00027  *   Kathleen Milsted
00028  *   Guy Vachet
00029  * 
00030  */
00031 package org.objectweb.jeremie.libs.services.CosTransactions.handler;
00032 
00033 import org.objectweb.jonathan.apis.kernel.Context;
00034 import org.objectweb.jonathan.apis.kernel.Element;
00035 import org.objectweb.jonathan.apis.kernel.JonathanException;
00036 import org.objectweb.jonathan.apis.kernel.InternalException;
00037 import org.objectweb.jonathan.apis.presentation.MarshallerFactory;
00038 import org.objectweb.jonathan.apis.presentation.Marshaller;
00039 import org.objectweb.jonathan.apis.presentation.UnMarshaller;
00040 import org.objectweb.jonathan.apis.resources.Chunk;
00041 import org.objectweb.jonathan.libs.helpers.MessageHelpers;
00042 
00043 import org.objectweb.david.apis.services.handler.Service;
00044 import org.objectweb.david.libs.services.CosTransactions.handler.TSHandler;
00045 
00046 import org.omg.IOP.ServiceContext;
00047 import org.omg.CosTransactions.PropagationContext;
00048 import org.omg.CosTSPortability.Sender;
00049 import org.omg.CosTSPortability.Receiver;
00050 
00051 import java.io.ByteArrayInputStream;
00052 import java.io.ObjectInputStream;
00053 import java.io.ByteArrayOutputStream;
00054 import java.io.ObjectOutputStream;
00055 
00056 import java.util.Properties;
00057 import java.util.Enumeration;
00058 import java.util.Vector;
00059 
00065 public class JRMITSHandler extends TSHandler {
00066 
00068    protected MarshallerFactory mf;
00069 
00084    protected JRMITSHandler(Context c,Object[] used_components)
00085       throws JonathanException {
00086       initialize(used_components);
00087    }
00088    
00089    private void initialize(Object[] used_components) 
00090       throws JonathanException {
00091       int sid = ((Integer) used_components[0]).intValue();
00092       if (sid != Integer.MAX_VALUE) {
00093          service_id = sid;
00094       }
00095    
00096       try {
00097          Sender sender = (Sender) used_components[1];
00098          if (sender !=  null) {
00099             identify_sender(sender);
00100          }
00101          Receiver receiver = (Receiver) used_components[2];
00102          if (receiver !=  null) {
00103             identify_receiver(receiver);
00104          }
00105          mf = (MarshallerFactory) used_components[3];
00106       } catch (Exception e) {
00107          throw new JonathanException(e);
00108       }
00109    }
00110    
00118    protected ServiceContext encodeContext(PropagationContext ctx) {
00119       if (ctx == null) {
00120          return null;
00121       }
00122       Marshaller marshaller = mf.newMarshaller();
00123       byte[] byteArray = null;
00124       try {
00125          marshaller.writeValue(ctx);
00126          byteArray = MessageHelpers.copy(marshaller);
00127          marshaller.close();
00128       } catch (Exception e) {
00129          System.err.println("JRMITSHandler.encodeContext: exception");
00130          e.printStackTrace();
00131       }
00132       return new ServiceContext(service_id, byteArray);
00133    }
00134    
00143    protected PropagationContext decodeContext(ServiceContext sc) {
00144       if ((sc==null) || (sc.context_data==null) || (sc.context_data.length==0)) {
00145          return null;
00146       }
00147       PropagationContext ctx = null;
00148       byte[] byteArray = sc.context_data;
00149       UnMarshaller unmarshaller = 
00150          mf.newUnMarshaller(new Chunk(byteArray, 0, byteArray.length), 0);
00151       try {
00152          ctx = (PropagationContext) unmarshaller.readValue();
00153          unmarshaller.close();
00154       } catch (Exception e) {
00155          System.err.println("JRMITSHandler.decodeContext: exception");
00156          System.err.println(e.toString() + "\n");
00157       }
00158       return ctx;
00159    }
00160    
00161 }

Generated at Fri May 31 19:23:33 2002 for Jonathan by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001