Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/activemq/message/PacketFacade.java


1   /** 
2    * 
3    * Copyright 2004 Protique Ltd
4    * 
5    * Licensed under the Apache License, Version 2.0 (the "License"); 
6    * you may not use this file except in compliance with the License. 
7    * You may obtain a copy of the License at 
8    * 
9    * http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS, 
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
14   * See the License for the specific language governing permissions and 
15   * limitations under the License. 
16   * 
17   **/
18  
19  package org.activemq.message;
20  
21  import java.io.Externalizable;
22  import java.io.IOException;
23  import java.io.ObjectInput;
24  import java.io.ObjectOutput;
25  
26  import javax.jms.JMSException;
27  
28  import org.activemq.io.WireFormat;
29  import org.activemq.io.impl.DefaultWireFormat;
30  import org.activemq.util.JMSExceptionHelper;
31  
32  /**
33   * A helper class for using Packet instances with object serialization
34   * 
35   * @version $Revision: 1.1.1.1 $
36   */
37  public class PacketFacade implements Externalizable {
38  
39      private static final long serialVersionUID = -4687188386605805496L;
40  
41      private static final WireFormat wireFormat = new DefaultWireFormat();
42  
43      private transient Packet packet;
44  
45      public PacketFacade() {
46      }
47  
48      public PacketFacade(Packet packet) {
49          this.packet = packet;
50      }
51  
52      public Packet getPacket() {
53          return packet;
54      }
55  
56      public void writeExternal(ObjectOutput out) throws IOException {
57          try {
58              wireFormat.writePacket(packet, out);
59          }
60          catch (JMSException e) {
61              throw JMSExceptionHelper.newIOException(e);
62          }
63      }
64  
65      public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
66          int type = in.readByte();
67          packet = wireFormat.readPacket(type, in);
68      }
69  }