001/** 002 * GRANITE DATA SERVICES 003 * Copyright (C) 2006-2013 GRANITE DATA SERVICES S.A.S. 004 * 005 * This file is part of the Granite Data Services Platform. 006 * 007 * Granite Data Services is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * Granite Data Services is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 015 * General Public License for more details. 016 * 017 * You should have received a copy of the GNU Lesser General Public 018 * License along with this library; if not, write to the Free Software 019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 020 * USA, or see <http://www.gnu.org/licenses/>. 021 */ 022package org.granite.messaging.jmf; 023 024import java.io.IOException; 025import java.io.ObjectOutputStream; 026import java.lang.reflect.InvocationTargetException; 027 028import org.granite.messaging.reflect.ClassDescriptor; 029import org.granite.messaging.reflect.Property; 030 031@SuppressWarnings("deprecation") 032/** 033 * @author Franck WOLFF 034 */ 035public class JMFObjectOutputStream extends ObjectOutputStream { 036 037 private final OutputContext out; 038 private final ClassDescriptor desc; 039 private final Object v; 040 041 public JMFObjectOutputStream(OutputContext out, ClassDescriptor desc, Object v) throws IOException { 042 super(); 043 044 this.out = out; 045 this.desc = desc; 046 this.v = v; 047 } 048 049 @Override 050 protected void writeObjectOverride(Object obj) throws IOException { 051 out.writeObject(obj); 052 } 053 054 @Override 055 public void useProtocolVersion(int version) throws IOException { 056 throw new UnsupportedOperationException(); 057 } 058 059 @Override 060 public void writeUnshared(Object obj) throws IOException { 061 throw new UnsupportedOperationException(); 062 } 063 064 @Override 065 public void defaultWriteObject() throws IOException { 066 for (Property property : desc.getSerializableProperties()) { 067 try { 068 out.getAndWriteProperty(v, property); 069 } 070 catch (IllegalAccessException e) { 071 throw new IOException(e); 072 } 073 catch (InvocationTargetException e) { 074 throw new IOException(e); 075 } 076 } 077 } 078 079 @Override 080 public PutField putFields() throws IOException { 081 throw new UnsupportedOperationException(); 082 } 083 084 @Override 085 public void writeFields() throws IOException { 086 throw new UnsupportedOperationException(); 087 } 088 089 @Override 090 public void reset() throws IOException { 091 throw new UnsupportedOperationException(); 092 } 093 094 @Override 095 public void write(int val) throws IOException { 096 out.write(val); 097 } 098 099 @Override 100 public void write(byte[] buf) throws IOException { 101 out.write(buf); 102 } 103 104 @Override 105 public void write(byte[] buf, int off, int len) throws IOException { 106 out.write(buf, off, len); 107 } 108 109 @Override 110 public void flush() throws IOException { 111 out.flush(); 112 } 113 114 @Override 115 public void close() throws IOException { 116 out.close(); 117 } 118 119 @Override 120 public void writeBoolean(boolean val) throws IOException { 121 out.writeBoolean(val); 122 } 123 124 @Override 125 public void writeByte(int val) throws IOException { 126 out.writeByte(val); 127 } 128 129 @Override 130 public void writeShort(int val) throws IOException { 131 out.writeShort(val); 132 } 133 134 @Override 135 public void writeChar(int val) throws IOException { 136 out.writeChar(val); 137 } 138 139 @Override 140 public void writeInt(int val) throws IOException { 141 out.writeInt(val); 142 } 143 144 @Override 145 public void writeLong(long val) throws IOException { 146 out.writeLong(val); 147 } 148 149 @Override 150 public void writeFloat(float val) throws IOException { 151 out.writeFloat(val); 152 } 153 154 @Override 155 public void writeDouble(double val) throws IOException { 156 out.writeDouble(val); 157 } 158 159 @Override 160 public void writeBytes(String str) throws IOException { 161 out.writeBytes(str); 162 } 163 164 @Override 165 public void writeChars(String str) throws IOException { 166 out.writeChars(str); 167 } 168 169 @Override 170 public void writeUTF(String str) throws IOException { 171 out.writeUTF(str); 172 } 173}