1 13 package info.magnolia.cms.exchange.simple; 14 15 import info.magnolia.cms.core.NodeData; 16 17 import java.io.IOException ; 18 import java.io.InputStream ; 19 import java.io.Serializable ; 20 import java.util.Calendar ; 21 22 import javax.jcr.PropertyType; 23 import javax.jcr.Value; 24 25 26 31 public class SerializableNodeData implements Serializable { 32 33 36 private static final long serialVersionUID = 222L; 37 38 41 Value value; 42 43 String stringValue; 44 45 long longValue; 46 47 double doubleValue; 48 49 boolean booleanValue; 50 51 Calendar dateValue; 52 53 56 byte[] byteArrayValue; 57 58 private String name; 59 60 private int type; 61 62 private transient NodeData baseNodeData; 63 64 public SerializableNodeData(NodeData nodeData) throws SerializationException { 65 this.baseNodeData = nodeData; 66 this.makeSerializable(); 67 this.baseNodeData = null; 68 } 69 70 75 private void makeSerializable() throws SerializationException { 76 this.setName(this.baseNodeData.getName()); 77 this.setType(this.baseNodeData.getType()); 78 this.setData(); 79 } 80 81 86 private void setData() throws SerializationException { 87 switch (this.getType()) { 88 case PropertyType.STRING: 89 this.setValue(this.baseNodeData.getString()); 90 break; 91 case PropertyType.LONG: 92 this.setValue(this.baseNodeData.getLong()); 93 break; 94 case PropertyType.DOUBLE: 95 this.setValue(this.baseNodeData.getDouble()); 96 break; 97 case PropertyType.BOOLEAN: 98 this.setValue(this.baseNodeData.getBoolean()); 99 break; 100 case PropertyType.DATE: 101 this.setValue(this.baseNodeData.getDate()); 102 break; 103 case PropertyType.BINARY: 104 this.setBinaryAsLink(this.baseNodeData.getHandle()); 105 109 break; 110 default: 111 throw new SerializationException("Unsupported property type"); } 113 } 114 115 public void setName(String name) { 116 this.name = name; 117 } 118 119 public String getName() { 120 return this.name; 121 } 122 123 public void setType(int type) { 124 this.type = type; 125 } 126 127 public int getType() { 128 return this.type; 129 } 130 131 public void setValue(Value value) { 132 this.value = value; 133 } 134 135 public Value getValue() { 136 return this.value; 137 } 138 139 public void setValue(String value) { 140 this.stringValue = value; 141 } 142 143 public String getString() { 144 return this.stringValue; 145 } 146 147 public void setValue(long value) { 148 this.longValue = value; 149 } 150 151 public long getLong() { 152 return this.longValue; 153 } 154 155 public void setValue(double value) { 156 this.doubleValue = value; 157 } 158 159 public double getDouble() { 160 return this.doubleValue; 161 } 162 163 public void setValue(boolean value) { 164 this.booleanValue = value; 165 } 166 167 public boolean getBoolean() { 168 return this.booleanValue; 169 } 170 171 public void setValue(Calendar value) { 172 this.dateValue = value; 173 } 174 175 public Calendar getDate() { 176 return this.dateValue; 177 } 178 179 public void setValue(InputStream value, int size) throws IOException { 180 value.read(this.byteArrayValue, 0, size); 181 } 182 183 public void setValue(InputStream value) throws IOException { 184 int nextByte; 185 int index = 0; 186 while ((nextByte = value.read()) != -1) { 187 this.byteArrayValue[index] = (byte) nextByte; 188 index++; 189 } 190 } 191 192 public void setBinaryAsLink(String value) { 193 this.stringValue = value; 194 } 195 196 public String getBinaryAsLink() { 197 return this.stringValue; 198 } 199 200 public byte[] getByteArray() { 201 return this.byteArrayValue; 202 } 203 } 204
| Popular Tags
|