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 test.implementation.modelmbean.support;
023:
024: /**
025: * @jmx:mbean description="sample for jboss xmbean.dtd"
026: * persistPolicy="Never"
027: * persistPeriod="10"
028: * persistLocation="pl1"
029: * persistName="JBossXMLExample1"
030: * currencyTimeLimit="10"
031: * descriptor="name=\"testdescriptor\" value=\"testvalue\""
032: * state-action-on-update="RESTART"
033: *
034: *
035: * @jmx:notification description="first notification"
036: * name="javax.management.SomeEvent"
037: * notificationType="xd.example.first,xd.example.second"
038: * persistPolicy="Never"
039: * persistPeriod="20"
040: * persistLocation="pl2"
041: * persistName="JBossXMLExample2"
042: * currencyTimeLimit="20"
043: *
044: **/
045: public class User {
046:
047: private long id = System.currentTimeMillis();
048: private String name = "";
049: private String address = "";
050: private String password = null;
051: private String[] numbers = new String[3];
052:
053: /**
054: * Creates a new <code>User</code> instance using constructor with one argument.
055: *
056: * @param id a <code>long</code> value
057: * @jmx:managed-constructor
058: */
059: public User(long id) {
060: this .id = id;
061: }
062:
063: /**
064: * Creates a new <code>User</code> using constructor with no argument
065: * @jmx:managed-constructor
066: *
067: */
068: public User() {
069: }
070:
071: /**
072: * Describe <code>getID</code> method here.
073: * read-only attribute
074: * @return a <code>long</code> value
075: * @jmx:managed-attribute persistPolicy="Never"
076: * persistPeriod="30"
077: * currencyTimeLimit="30"
078: */
079: public long getID() {
080: return id;
081: }
082:
083: /**
084: * Describe <code>setID</code> method here.
085: * application method, not exposed to management
086: *
087: * @param id a <code>long</code> value
088: */
089: public void setID(long id) {
090: this .id = id;
091: }
092:
093: /**
094: * Describe <code>getName</code> method here.
095: * read-write attribute
096: * @return a <code>String</code> value
097: * @jmx:managed-attribute persistPolicy="Never"
098: * persistPeriod="30"
099: * currencyTimeLimit="30"
100: */
101: public String getName() {
102: return name;
103: }
104:
105: /**
106: * Describe <code>setName</code> method here.
107: *
108: * @param name a <code>String</code> value
109: * @jmx:managed-attribute
110: */
111: public void setName(String name) {
112:
113: //System.out.println("SetNAME");
114:
115: this .name = name;
116: }
117:
118: /**
119: * Describe <code>getAddress</code> method here.
120: * read-write attribute
121: * @return a <code>String</code> value
122: * @jmx:managed-attribute persistPolicy="Never"
123: * persistPeriod="30"
124: * currencyTimeLimit="30"
125: */
126: public String getAddress() {
127: return address;
128: }
129:
130: /**
131: * Describe <code>setAddress</code> method here.
132: *
133: * @param address a <code>String</code> value
134: * @jmx:managed-attribute
135: */
136: public void setAddress(String address) {
137: this .address = address;
138: }
139:
140: /**
141: * Describe <code>getPhoneNumbers</code> method here.
142: * read-write attribute
143: * @return a <code>String[]</code> value
144: * @jmx:managed-attribute persistPolicy="Never"
145: * persistPeriod="30"
146: * currencyTimeLimit="30"
147: */
148: public String[] getPhoneNumbers() {
149: return numbers;
150: }
151:
152: /**
153: * Describe <code>setPhoneNumbers</code> method here.
154: *
155: * @param numbers a <code>String[]</code> value
156: * @jmx:managed-attribute
157: */
158: public void setPhoneNumbers(String[] numbers) {
159: this .numbers = numbers;
160: }
161:
162: /**
163: * Describe <code>setPassword</code> method here.
164: * write only attribute
165: * @param passwd a <code>String</code> value
166: * @jmx:managed-attribute persistPolicy="Never"
167: * persistPeriod="30"
168: * currencyTimeLimit="30"
169: */
170: public void setPassword(String passwd) {
171: this .password = passwd;
172: }
173:
174: // management operations
175:
176: /**
177: * Describe <code>printInfo</code> method here.
178: * prints info
179: * @return a <code>String</code> value
180: * @jmx:managed-operation
181: */
182: public String printInfo() {
183: return "User: " + getName() + "\n" + "Address: " + getAddress()
184: + "\n" + "Phone #: " + getPhoneNumbers()[0] + "\n"
185: + "Phone #: " + getPhoneNumbers()[1] + "\n"
186: + "Phone #: " + getPhoneNumbers()[2] + "\n";
187: }
188:
189: /**
190: * Describe <code>addPhoneNumber</code> method here.
191: *
192: * @param number a <code>String</code> value, the phone number to add
193: * @jmx:managed-operation
194: */
195: public void addPhoneNumber(String number) {
196: for (int i = 0; i < numbers.length; ++i)
197: if (numbers[i] == null) {
198: numbers[i] = number;
199: break;
200: }
201: }
202:
203: /**
204: * Describe <code>removePhoneNumber</code> method here.
205: *
206: * @param index an <code>int</code> value, the index of phone number to remove
207: * @jmx:managed-operation
208: */
209: public void removePhoneNumber(int index) {
210: if (index < 0 || index >= numbers.length)
211: return;
212:
213: numbers[index] = null;
214: }
215: }
|