KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > exchange > simple > SerializableMetaData


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 1993-2005 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.cms.exchange.simple;
14
15 import info.magnolia.cms.core.MetaData;
16
17 import java.io.Serializable JavaDoc;
18 import java.util.ArrayList JavaDoc;
19 import java.util.Calendar JavaDoc;
20 import java.util.List JavaDoc;
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 /**
31  * @author Sameer Charles
32  * @version 2.0
33  */

34 public class SerializableMetaData implements Serializable JavaDoc {
35
36     /**
37      * Stable serialVersionUID.
38      */

39     private static final long serialVersionUID = 222L;
40
41     /**
42      * Logger.
43      */

44     private static Logger log = Logger.getLogger(SerializableMetaData.class);
45
46     /**
47      * meta properties.
48      */

49     private List JavaDoc metaProperties = new ArrayList JavaDoc();
50
51     public SerializableMetaData(MetaData metaData) {
52         this.makeSerializable(metaData);
53     }
54
55     public List JavaDoc 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 JavaDoc {
98
99     /**
100      * Stable serialVersionUID.
101      */

102     private static final long serialVersionUID = 222L;
103
104     private String JavaDoc name;
105
106     private Object JavaDoc value;
107
108     /* JCR property type */
109     private int type;
110
111     private String JavaDoc stringValue;
112
113     private long longValue;
114
115     private double doubleValue;
116
117     private boolean booleanValue;
118
119     private Calendar JavaDoc dateValue;
120
121     MetaDataProperty(String JavaDoc name, int type) {
122         this.name = name;
123         this.type = type;
124     }
125
126     MetaDataProperty(String JavaDoc name, int type, Object JavaDoc value) {
127         this.name = name;
128         this.type = type;
129         this.value = value;
130     }
131
132     public String JavaDoc getName() {
133         return this.name;
134     }
135
136     public int getType() {
137         return this.type;
138     }
139
140     Object JavaDoc getValue() {
141         return this.value;
142     }
143
144     public void setValue(String JavaDoc 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 JavaDoc value) {
161         this.dateValue = value;
162     }
163
164     public String JavaDoc 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 JavaDoc getDate() {
181         return this.dateValue;
182     }
183 }
184
Popular Tags