KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jmx > xmbean > User


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.jmx.xmbean;
23
24 import java.util.ArrayList JavaDoc;
25 import java.util.Collection JavaDoc;
26
27 /**
28  * for some reason this doesn't work:
29  * descriptor="name=\"testdescriptor\" value=\"testvalue\""
30  *
31  * @jmx.mbean description="sample for jboss xmbean.dtd"
32  * persistPolicy="Never"
33  * persistPeriod="10"
34  * persistLocation="pl1"
35  * persistName="JBossXMLExample1"
36  * currencyTimeLimit="10"
37  * state-action-on-update="restart"
38  *
39  * @jmx.managed-attribute
40  * name="ArtificialAttribute"
41  * description="artificial attribute not impemeneted in class"
42  * type="java.lang.String"
43  * currencyTimeLimit="999999"
44  *
45  * @jmx.notification description="first notification"
46  * name="javax.management.SomeEvent"
47  * notificationType="xd.example.first,xd.example.second"
48  * persistPolicy="Never"
49  * persistPeriod="20"
50  * persistLocation="pl2"
51  * persistName="JBossXMLExample2"
52  * currencyTimeLimit="20"
53  *
54  * @jboss.xmbean
55  **/

56 public class User {
57
58    private long id = System.currentTimeMillis();
59    private int number;
60    private String JavaDoc name = "";
61    private String JavaDoc address = "";
62    private String JavaDoc password = null;
63    //private String[] numbers = new String[3];
64
private Collection JavaDoc numbers = new ArrayList JavaDoc();
65
66    /**
67     * Creates a new <code>User</code> instance using constructor with one argument.
68     *
69     * @param id a <code>long</code> value
70     * @jmx.managed-constructor
71     */

72    public User(long id)
73    {
74       this.id = id;
75    }
76
77    /**
78     * Creates a new <code>User</code> using constructor with no argument
79     * @jmx.managed-constructor
80     *
81     */

82    public User()
83    {
84    }
85
86
87    /**
88     * Describe <code>getID</code> method here.
89     * read-only attribute
90     * @return a <code>long</code> value
91     * @jmx.managed-attribute persistPolicy="Never"
92     * persistPeriod="30"
93     * currencyTimeLimit="30"
94     * access="read-only"
95     */

96    public long getID() {
97         return id;
98     }
99
100
101
102     /**
103      * Describe <code>setID</code> method here.
104      * application method, not exposed to management
105      *
106      * @param id a <code>long</code> value
107      */

108    public void setID(long id) {
109         this.id = id;
110     }
111
112
113
114
115    /**
116     * mbean get-set pair for field number
117     * Get the value of number
118     * @return value of number
119     *
120     * @jmx.managed-attribute persistPolicy="Never"
121     * persistPeriod="30"
122     * currencyTimeLimit="30"
123     * value="5"
124     */

125    public int getNumber()
126    {
127       return number;
128    }
129
130
131    /**
132     * Set the value of number
133     * @param number Value to assign to number
134     *
135     * @jmx.managed-attribute
136     */

137    public void setNumber(int number)
138    {
139       this.number = number;
140    }
141
142
143
144    /**
145     * Describe <code>getName</code> method here.
146     * read-write attribute
147     * @return a <code>String</code> value
148     * @jmx.managed-attribute persistPolicy="Never"
149     * persistPeriod="30"
150     * currencyTimeLimit="30"
151     * value="test name"
152     */

153    public String JavaDoc getName() {
154         return name;
155     }
156    /**
157     * Describe <code>setName</code> method here.
158     *
159     * @param name a <code>String</code> value
160     * @jmx.managed-attribute
161     */

162    public void setName(String JavaDoc name) {
163       this.name = name;
164    }
165
166
167
168    /**
169     * Describe <code>getAddress</code> method here.
170     * read-write attribute
171     * @return a <code>String</code> value
172     * @jmx.managed-attribute persistPolicy="Never"
173     * persistPeriod="30"
174     * currencyTimeLimit="30"
175     * value="somewhere"
176     */

177    public String JavaDoc getAddress() {
178         return address;
179     }
180
181    /**
182     * Describe <code>setAddress</code> method here.
183     *
184     * @param address a <code>String</code> value
185     * @jmx.managed-attribute
186     */

187    public void setAddress(String JavaDoc address) {
188         this.address = address;
189     }
190
191
192
193    /**
194     * Describe <code>getPhoneNumbers</code> method here.
195     * read-write attribute
196     * @return a <code>String[]</code> value
197     * @jmx.managed-attribute persistPolicy="Never"
198     * persistPeriod="30"
199     * currencyTimeLimit="30"
200     */

201    public Collection JavaDoc getPhoneNumbers() {
202       return numbers;
203    }
204    /**
205     * Describe <code>setPhoneNumbers</code> method here.
206     *
207     * @param numbers a <code>String[]</code> value
208     * @jmx.managed-attribute
209     */

210    public void setPhoneNumbers(Collection JavaDoc numbers) {
211       this.numbers.clear();
212       this.numbers.addAll(numbers);
213    }
214
215
216
217     /**
218      * Describe <code>setPassword</code> method here.
219      * write only attribute
220      * @param passwd a <code>String</code> value
221     * @jmx.managed-attribute persistPolicy="Never"
222     * persistPeriod="30"
223     * currencyTimeLimit="30"
224      */

225    public void setPassword(String JavaDoc passwd) {
226         this.password = passwd;
227     }
228
229
230     // management operations
231

232     /**
233      * Describe <code>printInfo</code> method here.
234      * prints info
235      * @return a <code>String</code> value
236     * @jmx.managed-operation
237      */

238    public String JavaDoc printInfo() {
239         return
240           "User: " + getName() +"\n"+
241           "Address: " + getAddress() +"\n"+
242            "Phone numbers: " + numbers;
243     }
244
245    /**
246     * Describe <code>addPhoneNumber</code> method here.
247     *
248     * @param number a <code>String</code> value, the phone number to add
249     * @jmx.managed-operation
250     * @jmx.managed-parameter name="number" type="java.lang.String"
251     */

252    public void addPhoneNumber(String JavaDoc number) {
253       numbers.add(number);
254    }
255
256    /**
257     * Describe <code>removePhoneNumber</code> method here.
258     *
259     * @param index an <code>int</code> value, the index of phone number to remove
260     * @jmx.managed-operation
261     * @jmx.managed-parameter name="number" type="java.lang.String"
262     */

263    public void removePhoneNumber(String JavaDoc number) {
264       numbers.remove(number);
265    }
266 }
267
268
269
Popular Tags