001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.jmx.xmbean;
023:
024: import java.util.ArrayList;
025: import java.util.Collection;
026:
027: /**
028: * for some reason this doesn't work:
029: * descriptor="name=\"testdescriptor\" value=\"testvalue\""
030: *
031: * @jmx.mbean description="sample for jboss xmbean.dtd"
032: * persistPolicy="Never"
033: * persistPeriod="10"
034: * persistLocation="pl1"
035: * persistName="JBossXMLExample1"
036: * currencyTimeLimit="10"
037: * state-action-on-update="restart"
038: *
039: * @jmx.managed-attribute
040: * name="ArtificialAttribute"
041: * description="artificial attribute not impemeneted in class"
042: * type="java.lang.String"
043: * currencyTimeLimit="999999"
044: *
045: * @jmx.notification description="first notification"
046: * name="javax.management.SomeEvent"
047: * notificationType="xd.example.first,xd.example.second"
048: * persistPolicy="Never"
049: * persistPeriod="20"
050: * persistLocation="pl2"
051: * persistName="JBossXMLExample2"
052: * currencyTimeLimit="20"
053: *
054: * @jboss.xmbean
055: **/
056: public class User {
057:
058: private long id = System.currentTimeMillis();
059: private int number;
060: private String name = "";
061: private String address = "";
062: private String password = null;
063: //private String[] numbers = new String[3];
064: private Collection numbers = new ArrayList();
065:
066: /**
067: * Creates a new <code>User</code> instance using constructor with one argument.
068: *
069: * @param id a <code>long</code> value
070: * @jmx.managed-constructor
071: */
072: public User(long id) {
073: this .id = id;
074: }
075:
076: /**
077: * Creates a new <code>User</code> using constructor with no argument
078: * @jmx.managed-constructor
079: *
080: */
081: public User() {
082: }
083:
084: /**
085: * Describe <code>getID</code> method here.
086: * read-only attribute
087: * @return a <code>long</code> value
088: * @jmx.managed-attribute persistPolicy="Never"
089: * persistPeriod="30"
090: * currencyTimeLimit="30"
091: * access="read-only"
092: */
093: public long getID() {
094: return id;
095: }
096:
097: /**
098: * Describe <code>setID</code> method here.
099: * application method, not exposed to management
100: *
101: * @param id a <code>long</code> value
102: */
103: public void setID(long id) {
104: this .id = id;
105: }
106:
107: /**
108: * mbean get-set pair for field number
109: * Get the value of number
110: * @return value of number
111: *
112: * @jmx.managed-attribute persistPolicy="Never"
113: * persistPeriod="30"
114: * currencyTimeLimit="30"
115: * value="5"
116: */
117: public int getNumber() {
118: return number;
119: }
120:
121: /**
122: * Set the value of number
123: * @param number Value to assign to number
124: *
125: * @jmx.managed-attribute
126: */
127: public void setNumber(int number) {
128: this .number = number;
129: }
130:
131: /**
132: * Describe <code>getName</code> method here.
133: * read-write attribute
134: * @return a <code>String</code> value
135: * @jmx.managed-attribute persistPolicy="Never"
136: * persistPeriod="30"
137: * currencyTimeLimit="30"
138: * value="test name"
139: */
140: public String getName() {
141: return name;
142: }
143:
144: /**
145: * Describe <code>setName</code> method here.
146: *
147: * @param name a <code>String</code> value
148: * @jmx.managed-attribute
149: */
150: public void setName(String name) {
151: this .name = name;
152: }
153:
154: /**
155: * Describe <code>getAddress</code> method here.
156: * read-write attribute
157: * @return a <code>String</code> value
158: * @jmx.managed-attribute persistPolicy="Never"
159: * persistPeriod="30"
160: * currencyTimeLimit="30"
161: * value="somewhere"
162: */
163: public String getAddress() {
164: return address;
165: }
166:
167: /**
168: * Describe <code>setAddress</code> method here.
169: *
170: * @param address a <code>String</code> value
171: * @jmx.managed-attribute
172: */
173: public void setAddress(String address) {
174: this .address = address;
175: }
176:
177: /**
178: * Describe <code>getPhoneNumbers</code> method here.
179: * read-write attribute
180: * @return a <code>String[]</code> value
181: * @jmx.managed-attribute persistPolicy="Never"
182: * persistPeriod="30"
183: * currencyTimeLimit="30"
184: */
185: public Collection getPhoneNumbers() {
186: return numbers;
187: }
188:
189: /**
190: * Describe <code>setPhoneNumbers</code> method here.
191: *
192: * @param numbers a <code>String[]</code> value
193: * @jmx.managed-attribute
194: */
195: public void setPhoneNumbers(Collection numbers) {
196: this .numbers.clear();
197: this .numbers.addAll(numbers);
198: }
199:
200: /**
201: * Describe <code>setPassword</code> method here.
202: * write only attribute
203: * @param passwd a <code>String</code> value
204: * @jmx.managed-attribute persistPolicy="Never"
205: * persistPeriod="30"
206: * currencyTimeLimit="30"
207: */
208: public void setPassword(String passwd) {
209: this .password = passwd;
210: }
211:
212: // management operations
213:
214: /**
215: * Describe <code>printInfo</code> method here.
216: * prints info
217: * @return a <code>String</code> value
218: * @jmx.managed-operation
219: */
220: public String printInfo() {
221: return "User: " + getName() + "\n" + "Address: " + getAddress()
222: + "\n" + "Phone numbers: " + numbers;
223: }
224:
225: /**
226: * Describe <code>addPhoneNumber</code> method here.
227: *
228: * @param number a <code>String</code> value, the phone number to add
229: * @jmx.managed-operation
230: * @jmx.managed-parameter name="number" type="java.lang.String"
231: */
232: public void addPhoneNumber(String number) {
233: numbers.add(number);
234: }
235:
236: /**
237: * Describe <code>removePhoneNumber</code> method here.
238: *
239: * @param index an <code>int</code> value, the index of phone number to remove
240: * @jmx.managed-operation
241: * @jmx.managed-parameter name="number" type="java.lang.String"
242: */
243: public void removePhoneNumber(String number) {
244: numbers.remove(number);
245: }
246: }
|