KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > implementation > modelmbean > support > 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 test.implementation.modelmbean.support;
23 /**
24  * @jmx:mbean description="sample for jboss xmbean.dtd"
25  * persistPolicy="Never"
26  * persistPeriod="10"
27  * persistLocation="pl1"
28  * persistName="JBossXMLExample1"
29  * currencyTimeLimit="10"
30  * descriptor="name=\"testdescriptor\" value=\"testvalue\""
31  * state-action-on-update="RESTART"
32  *
33  *
34  * @jmx:notification description="first notification"
35  * name="javax.management.SomeEvent"
36  * notificationType="xd.example.first,xd.example.second"
37  * persistPolicy="Never"
38  * persistPeriod="20"
39  * persistLocation="pl2"
40  * persistName="JBossXMLExample2"
41  * currencyTimeLimit="20"
42  *
43  **/

44 public class User {
45
46     private long id = System.currentTimeMillis();
47     private String JavaDoc name = "";
48     private String JavaDoc address = "";
49     private String JavaDoc password = null;
50     private String JavaDoc[] numbers = new String JavaDoc[3];
51     
52    /**
53     * Creates a new <code>User</code> instance using constructor with one argument.
54     *
55     * @param id a <code>long</code> value
56     * @jmx:managed-constructor
57     */

58    public User(long id)
59    {
60       this.id = id;
61    }
62
63    /**
64     * Creates a new <code>User</code> using constructor with no argument
65     * @jmx:managed-constructor
66     *
67     */

68    public User()
69    {
70    }
71
72
73    /**
74     * Describe <code>getID</code> method here.
75     * read-only attribute
76     * @return a <code>long</code> value
77     * @jmx:managed-attribute persistPolicy="Never"
78     * persistPeriod="30"
79     * currencyTimeLimit="30"
80     */

81    public long getID() {
82         return id;
83     }
84
85
86
87     /**
88      * Describe <code>setID</code> method here.
89      * application method, not exposed to management
90      *
91      * @param id a <code>long</code> value
92      */

93    public void setID(long id) {
94         this.id = id;
95     }
96     
97
98
99    /**
100     * Describe <code>getName</code> method here.
101     * read-write attribute
102     * @return a <code>String</code> value
103     * @jmx:managed-attribute persistPolicy="Never"
104     * persistPeriod="30"
105     * currencyTimeLimit="30"
106     */

107    public String JavaDoc getName() {
108         return name;
109     }
110    /**
111     * Describe <code>setName</code> method here.
112     *
113     * @param name a <code>String</code> value
114     * @jmx:managed-attribute
115     */

116    public void setName(String JavaDoc name) {
117         
118       //System.out.println("SetNAME");
119

120       this.name = name;
121    }
122
123     
124
125    /**
126     * Describe <code>getAddress</code> method here.
127     * read-write attribute
128     * @return a <code>String</code> value
129     * @jmx:managed-attribute persistPolicy="Never"
130     * persistPeriod="30"
131     * currencyTimeLimit="30"
132     */

133    public String JavaDoc getAddress() {
134         return address;
135     }
136
137    /**
138     * Describe <code>setAddress</code> method here.
139     *
140     * @param address a <code>String</code> value
141     * @jmx:managed-attribute
142     */

143    public void setAddress(String JavaDoc address) {
144         this.address = address;
145     }
146
147     
148
149    /**
150     * Describe <code>getPhoneNumbers</code> method here.
151     * read-write attribute
152     * @return a <code>String[]</code> value
153     * @jmx:managed-attribute persistPolicy="Never"
154     * persistPeriod="30"
155     * currencyTimeLimit="30"
156     */

157    public String JavaDoc[] getPhoneNumbers() {
158         return numbers;
159     }
160    /**
161     * Describe <code>setPhoneNumbers</code> method here.
162     *
163     * @param numbers a <code>String[]</code> value
164     * @jmx:managed-attribute
165     */

166    public void setPhoneNumbers(String JavaDoc[] numbers) {
167         this.numbers = numbers;
168     }
169
170     
171
172     /**
173      * Describe <code>setPassword</code> method here.
174      * write only attribute
175      * @param passwd a <code>String</code> value
176     * @jmx:managed-attribute persistPolicy="Never"
177     * persistPeriod="30"
178     * currencyTimeLimit="30"
179      */

180    public void setPassword(String JavaDoc passwd) {
181         this.password = passwd;
182     }
183
184     
185     // management operations
186

187     /**
188      * Describe <code>printInfo</code> method here.
189      * prints info
190      * @return a <code>String</code> value
191     * @jmx:managed-operation
192      */

193    public String JavaDoc printInfo() {
194         return
195           "User: " + getName() +"\n"+
196           "Address: " + getAddress() +"\n"+
197           "Phone #: " + getPhoneNumbers()[0] +"\n"+
198           "Phone #: " + getPhoneNumbers()[1] +"\n"+
199           "Phone #: " + getPhoneNumbers()[2] +"\n";
200     }
201     
202    /**
203     * Describe <code>addPhoneNumber</code> method here.
204     *
205     * @param number a <code>String</code> value, the phone number to add
206     * @jmx:managed-operation
207     */

208    public void addPhoneNumber(String JavaDoc number) {
209         for (int i = 0; i < numbers.length; ++i)
210             if (numbers[i] == null) {
211                 numbers[i] = number;
212                 break;
213             }
214     }
215
216    /**
217     * Describe <code>removePhoneNumber</code> method here.
218     *
219     * @param index an <code>int</code> value, the index of phone number to remove
220     * @jmx:managed-operation
221     */

222    public void removePhoneNumber(int index) {
223         if (index < 0 || index >= numbers.length)
224             return;
225             
226         numbers[index] = null;
227     }
228 }
229
230
231
Popular Tags