KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > framework > core > TargetRef


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
20 package sync4j.framework.core;
21
22
23 /**
24  * This class represents the <TargetRef> element as defined by the SyncML
25  * representation specifications
26  *
27  * @author Stefano Fornari @ Funambol
28  *
29  * @version $Id: TargetRef.java,v 1.4 2005/03/02 20:57:37 harrie Exp $
30  */

31 public final class TargetRef
32 implements java.io.Serializable JavaDoc {
33
34     // ------------------------------------------------------------ Private data
35

36     private String JavaDoc value;
37     private String JavaDoc query;
38     private Target target;
39     
40     // ------------------------------------------------------------ Constructors
41

42     /**
43      * For serialization purposes
44      */

45     protected TargetRef() {}
46     
47     /**
48      * Creates a new TargetRef object given the referenced value. A null value
49      * is considered an empty string
50      *
51      * @param value the referenced value - NULL ALLOWED
52      *
53      * @throws IllegalArgumentException if value is null
54      */

55     public TargetRef(final String JavaDoc value) {
56         setValue(value);
57     }
58     
59     /**
60      * Creates a new TargetRef object from an existing target.
61      *
62      * @param target the target to extract the reference from - NOT NULL
63      *
64      * @throws IllegalArgumentException if target is null
65      *
66      */

67     public TargetRef(final Target target) {
68         setTarget(target);
69         setValue(target.getLocURI());
70     }
71     
72     // ---------------------------------------------------------- Public methods
73

74     /**
75      * Returns the value
76      *
77      * @return the value
78      */

79     public String JavaDoc getValue() {
80         return value;
81     }
82     
83     /**
84      * Sets the reference value. If value is null, the empty string is adopted.
85      *
86      * @param value the reference value - NULL
87      */

88     public void setValue(String JavaDoc value) {
89         if (value == null) {
90             this.value = "";
91             this.query = "";
92         } else {
93             int qMark = value.indexOf('?');
94             if (qMark == -1) {
95                 this.value = value;
96                 this.query = "";
97             } else {
98                 this.value = value.substring(0, qMark);
99                 this.query = value.substring(qMark);
100             }
101         }
102     }
103     
104     /**
105      * Gets the Target property
106      *
107      * @return target the Target property
108      */

109     public Target getTarget() {
110         return this.target;
111     }
112
113     /**
114      * Sets the Target property
115      *
116      * @param target the Target property
117      */

118     public void setTarget(Target target) {
119         if (target == null) {
120             throw new IllegalArgumentException JavaDoc("target cannot be null");
121         }
122         this.target = target;
123     }
124 }
125
Popular Tags