001 /** 002 * 003 * Copyright 2004 Protique Ltd 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 * 017 **/ 018 019 package org.activemq.message; 020 021 import java.io.Externalizable; 022 import java.io.IOException; 023 import java.io.ObjectInput; 024 import java.io.ObjectOutput; 025 026 import javax.jms.JMSException; 027 028 import org.activemq.io.WireFormat; 029 import org.activemq.io.impl.DefaultWireFormat; 030 import org.activemq.util.JMSExceptionHelper; 031 032 /** 033 * A helper class for using Packet instances with object serialization 034 * 035 * @version $Revision: 1.1.1.1 $ 036 */ 037 public class PacketFacade implements Externalizable { 038 039 private static final long serialVersionUID = -4687188386605805496L; 040 041 private static final WireFormat wireFormat = new DefaultWireFormat(); 042 043 private transient Packet packet; 044 045 public PacketFacade() { 046 } 047 048 public PacketFacade(Packet packet) { 049 this.packet = packet; 050 } 051 052 public Packet getPacket() { 053 return packet; 054 } 055 056 public void writeExternal(ObjectOutput out) throws IOException { 057 try { 058 wireFormat.writePacket(packet, out); 059 } 060 catch (JMSException e) { 061 throw JMSExceptionHelper.newIOException(e); 062 } 063 } 064 065 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { 066 int type = in.readByte(); 067 packet = wireFormat.readPacket(type, in); 068 } 069 }