1 13 package info.magnolia.cms.exchange.simple; 14 15 import info.magnolia.cms.core.MetaData; 16 17 import java.io.Serializable ; 18 import java.util.ArrayList ; 19 import java.util.Calendar ; 20 import java.util.List ; 21 22 import javax.jcr.Property; 23 import javax.jcr.PropertyIterator; 24 import javax.jcr.PropertyType; 25 import javax.jcr.RepositoryException; 26 27 import org.apache.log4j.Logger; 28 29 30 34 public class SerializableMetaData implements Serializable { 35 36 39 private static final long serialVersionUID = 222L; 40 41 44 private static Logger log = Logger.getLogger(SerializableMetaData.class); 45 46 49 private List metaProperties = new ArrayList (); 50 51 public SerializableMetaData(MetaData metaData) { 52 this.makeSerializable(metaData); 53 } 54 55 public List getMetaProperties() { 56 return this.metaProperties; 57 } 58 59 private void makeSerializable(MetaData metaData) { 60 PropertyIterator pi = metaData.getProperties(); 61 if (pi == null) { 62 return; 63 } 64 while (pi.hasNext()) { 65 try { 66 Property property = (Property) pi.next(); 67 68 int type = property.getValue().getType(); 69 MetaDataProperty metaProperty = new MetaDataProperty(property.getName(), type); 70 switch (type) { 71 case PropertyType.STRING: 72 metaProperty.setValue(property.getString()); 73 break; 74 case PropertyType.LONG: 75 metaProperty.setValue(property.getLong()); 76 break; 77 case PropertyType.DOUBLE: 78 metaProperty.setValue(property.getDouble()); 79 break; 80 case PropertyType.BOOLEAN: 81 metaProperty.setValue(property.getBoolean()); 82 break; 83 case PropertyType.DATE: 84 metaProperty.setValue(property.getDate()); 85 } 86 this.metaProperties.add(metaProperty); 87 property = null; 88 } 89 catch (RepositoryException re) { 90 log.error(re.getMessage(), re); 91 } 92 } 93 } 94 } 95 96 97 class MetaDataProperty implements Serializable { 98 99 102 private static final long serialVersionUID = 222L; 103 104 private String name; 105 106 private Object value; 107 108 109 private int type; 110 111 private String stringValue; 112 113 private long longValue; 114 115 private double doubleValue; 116 117 private boolean booleanValue; 118 119 private Calendar dateValue; 120 121 MetaDataProperty(String name, int type) { 122 this.name = name; 123 this.type = type; 124 } 125 126 MetaDataProperty(String name, int type, Object value) { 127 this.name = name; 128 this.type = type; 129 this.value = value; 130 } 131 132 public String getName() { 133 return this.name; 134 } 135 136 public int getType() { 137 return this.type; 138 } 139 140 Object getValue() { 141 return this.value; 142 } 143 144 public void setValue(String value) { 145 this.stringValue = value; 146 } 147 148 public void setValue(long value) { 149 this.longValue = value; 150 } 151 152 public void setValue(double value) { 153 this.doubleValue = value; 154 } 155 156 public void setValue(boolean value) { 157 this.booleanValue = value; 158 } 159 160 public void setValue(Calendar value) { 161 this.dateValue = value; 162 } 163 164 public String getString() { 165 return this.stringValue; 166 } 167 168 public long getLong() { 169 return this.longValue; 170 } 171 172 public double getDouble() { 173 return this.doubleValue; 174 } 175 176 public boolean getBoolean() { 177 return this.booleanValue; 178 } 179 180 public Calendar getDate() { 181 return this.dateValue; 182 } 183 } 184
| Popular Tags
|