KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > framework > engine > dm > TreeNode


1 /**
2  * Copyright (C) 2003-2005 Funambol
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19 package sync4j.framework.engine.dm;
20
21 import org.apache.commons.lang.builder.ToStringBuilder;
22
23 /**
24  * Represents a node in dm tree.
25  *
26  * @author Stefano Nichele @ Funambol
27  *
28  * @version $Id: TreeNode.java,v 1.1 2005/05/16 17:32:55 nichele Exp $
29  */

30 public class TreeNode {
31
32     // --------------------------------------------------------------- Constants
33

34     public static final String JavaDoc FORMAT_BINARY = "b64";
35     public static final String JavaDoc FORMAT_CHR = "chr";
36     public static final String JavaDoc FORMAT_INT = "int";
37     public static final String JavaDoc FORMAT_BOOL = "bool";
38     public static final String JavaDoc FORMAT_NODE = "node";
39     public static final String JavaDoc FORMAT_XML = "xml";
40     public static final String JavaDoc FORMAT_NULL = "null";
41     public static final String JavaDoc FORMAT_DEFAULT_VALUE = FORMAT_CHR;
42
43     public static final String JavaDoc TYPE_DEFAULT_VALUE = "text/plain";
44
45
46     // -------------------------------------------------------------- Properties
47
private String JavaDoc name = null;
48     private String JavaDoc format = null;
49     private String JavaDoc type = null;
50     private Object JavaDoc value = null;
51
52     // ------------------------------------------------------------- Constructor
53

54     public TreeNode() {
55         this.type = TYPE_DEFAULT_VALUE;
56     }
57
58     public TreeNode(String JavaDoc name) {
59         this();
60         this.name = name;
61     }
62
63     public TreeNode(String JavaDoc name, Object JavaDoc value) {
64         this(name);
65         setValue(value);
66     }
67
68     public TreeNode(String JavaDoc name, Object JavaDoc value, String JavaDoc format) {
69         this(name, value);
70         this.format = format;
71     }
72
73     public TreeNode(String JavaDoc name, Object JavaDoc value, String JavaDoc format, String JavaDoc type) {
74         this(name, value, format);
75         this.type = type;
76     }
77
78     // ----------------------------------------------------------- Public Methods
79

80     /**
81      * Returns the name property
82      *
83      * @return the name property
84      */

85     public String JavaDoc getName() {
86         return name;
87     }
88
89     /**
90      * Set the name property
91      *
92      * @param name the new name
93      */

94     public void setName(String JavaDoc name) {
95         this.name = name;
96     }
97
98     /**
99      * Returns the value property
100      *
101      * @return the value property
102      */

103     public Object JavaDoc getValue() {
104         return value;
105     }
106
107     /**
108      * Set the value property
109      *
110      * @param value the new value
111      */

112     public void setValue(Object JavaDoc value) {
113         this.value = value;
114
115         if (value != null) {
116             if (value instanceof byte[]) {
117                 this.format = FORMAT_BINARY;
118             } else if (value instanceof Boolean JavaDoc) {
119                 this.format = FORMAT_BOOL;
120             } else if (value instanceof Integer JavaDoc) {
121                 this.format = FORMAT_INT;
122             } else {
123                 this.format = FORMAT_DEFAULT_VALUE;
124             }
125         }
126     }
127
128     /**
129      * Returns the format property
130      *
131      * @return the format property
132      */

133     public String JavaDoc getFormat() {
134         return format;
135     }
136
137     /**
138      * Set the format property
139      *
140      * @param format the new format
141      */

142     public void setFormat(String JavaDoc format) {
143         this.format = format;
144     }
145
146
147     /**
148      * Returns the type property
149      *
150      * @return the type property
151      */

152     public String JavaDoc getType() {
153         return type;
154     }
155
156     /**
157      * Set the type property
158      *
159      * @param type the new type
160      */

161     public void setType(String JavaDoc type) {
162         this.type = type;
163     }
164
165     /**
166      * Returns a String representation of this TreeNode
167      * @return String
168      */

169     public String JavaDoc toString() {
170         ToStringBuilder sb = new ToStringBuilder(this);
171
172         sb.append("name" , name);
173         sb.append("value" , value);
174         sb.append("format", format);
175         sb.append("type" , type);
176
177         return sb.toString();
178     }
179 }
Popular Tags