• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2003,2004, Stefan Haustein, Oberhausen, Rhld., Germany
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
5  * associated documentation files (the "Software"), to deal in the Software without restriction, including
6  * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7  * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
8  * following conditions:
9  *
10  * The above copyright notice and this permission notice shall be included in all copies or substantial
11  * portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
14  * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
15  * EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
16  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
17  * USE OR OTHER DEALINGS IN THE SOFTWARE.
18  *
19  * Contributor(s): John D. Beatty, F. Hunter, Renaud Tognelli
20  */
21 
22 package org.ksoap2.serialization;
23 
24 import java.io.ByteArrayOutputStream;
25 import java.io.ByteArrayInputStream;
26 import java.io.ObjectOutputStream;
27 import java.io.ObjectInputStream;
28 
29 import java.io.IOException;
30 import java.io.NotSerializableException;
31 
32 /**
33  * This class is used to store information about each property an implementation of KvmSerializable exposes.
34  */
35 
36 public class PropertyInfo implements java.io.Serializable
37 {
38     public static final Class OBJECT_CLASS = new Object().getClass();
39     public static final Class STRING_CLASS = "".getClass();
40     public static final Class INTEGER_CLASS = new Integer(0).getClass();
41     public static final Class LONG_CLASS = new Long(0).getClass();
42     public static final Class BOOLEAN_CLASS = new Boolean(true).getClass();
43     public static final Class VECTOR_CLASS = new java.util.Vector().getClass();
44     public static final PropertyInfo OBJECT_TYPE = new PropertyInfo();
45     public static final int TRANSIENT = 1;
46     public static final int MULTI_REF = 2;
47     public static final int REF_ONLY = 4;
48 
49     /**
50      * Name of the property
51      */
52     public String name;
53 
54     /**
55      * Namespace of this property
56      */
57     public String namespace;
58 
59     /**
60      * Type of property, Transient, multi_ref, Ref_only *JHS* Note, not really used that effectively
61      */
62     public int flags;
63 
64     /**
65      * The current value of this property.
66      */
67     protected Object value;
68 
69     /**
70      * Type of the property/elements. Should usually be an instance of Class.
71      */
72     public Object type = OBJECT_CLASS;
73 
74     /**
75      * if a property is multi-referenced, set this flag to true.
76      */
77     public boolean multiRef;
78 
79     /**
80      * Element type for array properties, null if not array prop.
81      */
82     public PropertyInfo elementType;
83 
PropertyInfo()84     public PropertyInfo()
85     {
86     }
87 
clear()88     public void clear()
89     {
90         type = OBJECT_CLASS;
91         flags = 0;
92         name = null;
93         namespace = null;
94     }
95 
96     /**
97      * @return Returns the elementType.
98      */
getElementType()99     public PropertyInfo getElementType()
100     {
101         return elementType;
102     }
103 
104     /**
105      * @param elementType
106      *            The elementType to set.
107      */
setElementType(PropertyInfo elementType)108     public void setElementType(PropertyInfo elementType)
109     {
110         this.elementType = elementType;
111     }
112 
113     /**
114      * @return Returns the flags.
115      */
getFlags()116     public int getFlags()
117     {
118         return flags;
119     }
120 
121     /**
122      * @param flags
123      *            The flags to set.
124      */
setFlags(int flags)125     public void setFlags(int flags)
126     {
127         this.flags = flags;
128     }
129 
130     /**
131      * @return Returns the multiRef.
132      */
isMultiRef()133     public boolean isMultiRef()
134     {
135         return multiRef;
136     }
137 
138     /**
139      * @param multiRef
140      *            The multiRef to set.
141      */
setMultiRef(boolean multiRef)142     public void setMultiRef(boolean multiRef)
143     {
144         this.multiRef = multiRef;
145     }
146 
147     /**
148      * @return Returns the name.
149      */
getName()150     public String getName()
151     {
152         return name;
153     }
154 
155     /**
156      * @param name
157      *            The name to set.
158      */
setName(String name)159     public void setName(String name)
160     {
161         this.name = name;
162     }
163 
164     /**
165      * @return Returns the namespace.
166      */
getNamespace()167     public String getNamespace()
168     {
169         return namespace;
170     }
171 
172     /**
173      * @param namespace
174      *            The namespace to set.
175      */
setNamespace(String namespace)176     public void setNamespace(String namespace)
177     {
178         this.namespace = namespace;
179     }
180 
181     /**
182      * @return Returns the type.
183      */
getType()184     public Object getType()
185     {
186         return type;
187     }
188 
189     /**
190      * @param type
191      *            The type to set.
192      */
setType(Object type)193     public void setType(Object type)
194     {
195         this.type = type;
196     }
197 
198     /**
199      * @return Returns the value.
200      */
getValue()201     public Object getValue()
202     {
203         return value;
204     }
205 
206     /**
207      * @param value
208      *            The value to set.
209      */
setValue(Object value)210     public void setValue(Object value)
211     {
212         this.value = value;
213     }
214 
215     /**
216      * Show the name and value.
217      *
218      * @see java.lang.Object#toString()
219      */
toString()220     public String toString()
221     {
222         StringBuffer sb = new StringBuffer();
223         sb.append(name);
224         sb.append(" : ");
225         if (value != null)
226         {
227             sb.append(value);
228         }
229         else
230         {
231             sb.append("(not set)");
232         }
233         return sb.toString();
234     }
235 
236     /**
237      * Make a deep clone of the properties through Object serialization
238      *
239      * @see java.lang.Object#clone()
240      */
clone()241     public Object clone() {
242         Object obj = null;
243         try
244         {
245             // Write the object out to a byte array
246             ByteArrayOutputStream bos = new ByteArrayOutputStream();
247             ObjectOutputStream out = new ObjectOutputStream(bos);
248             out.writeObject(this);
249             out.flush();
250             out.close();
251 
252             // Make an input stream from the byte array and read
253             // a copy of the object back in.
254             ObjectInputStream in = new ObjectInputStream(
255                     new ByteArrayInputStream(bos.toByteArray()));
256             obj = in.readObject();
257         } catch (ClassNotFoundException cnfe)
258         {
259             cnfe.printStackTrace();
260         } catch (NotSerializableException nse)
261         {
262             nse.printStackTrace();
263         } catch (IOException e)
264         {
265             e.printStackTrace();
266         }
267         return obj;
268     }
269 }
270