package test.implementation.modelmbean.support;
/**
* @jmx:mbean description="sample for jboss xmbean.dtd"
* persistPolicy="Never"
* persistPeriod="10"
* persistLocation="pl1"
* persistName="JBossXMLExample1"
* currencyTimeLimit="10"
* descriptor="name=\"testdescriptor\" value=\"testvalue\""
* state-action-on-update="RESTART"
*
*
* @jmx:notification description="first notification"
* name="javax.management.SomeEvent"
* notificationType="xd.example.first,xd.example.second"
* persistPolicy="Never"
* persistPeriod="20"
* persistLocation="pl2"
* persistName="JBossXMLExample2"
* currencyTimeLimit="20"
*
**/
public class User {
private long id = System.currentTimeMillis();
private String name = "";
private String address = "";
private String password = null;
private String[] numbers = new String[3];
/**
* Creates a new User instance using constructor with one argument.
*
* @param id a long value
* @jmx:managed-constructor
*/
public User(long id)
{
this.id = id;
}
/**
* Creates a new User using constructor with no argument
* @jmx:managed-constructor
*
*/
public User()
{
}
/**
* Describe getID method here.
* read-only attribute
* @return a long value
* @jmx:managed-attribute persistPolicy="Never"
* persistPeriod="30"
* currencyTimeLimit="30"
*/
public long getID() {
return id;
}
/**
* Describe setID method here.
* application method, not exposed to management
*
* @param id a long value
*/
public void setID(long id) {
this.id = id;
}
/**
* Describe getName method here.
* read-write attribute
* @return a String value
* @jmx:managed-attribute persistPolicy="Never"
* persistPeriod="30"
* currencyTimeLimit="30"
*/
public String getName() {
return name;
}
/**
* Describe setName method here.
*
* @param name a String value
* @jmx:managed-attribute
*/
public void setName(String name) {
//System.out.println("SetNAME");
this.name = name;
}
/**
* Describe getAddress method here.
* read-write attribute
* @return a String value
* @jmx:managed-attribute persistPolicy="Never"
* persistPeriod="30"
* currencyTimeLimit="30"
*/
public String getAddress() {
return address;
}
/**
* Describe setAddress method here.
*
* @param address a String value
* @jmx:managed-attribute
*/
public void setAddress(String address) {
this.address = address;
}
/**
* Describe getPhoneNumbers method here.
* read-write attribute
* @return a String[] value
* @jmx:managed-attribute persistPolicy="Never"
* persistPeriod="30"
* currencyTimeLimit="30"
*/
public String[] getPhoneNumbers() {
return numbers;
}
/**
* Describe setPhoneNumbers method here.
*
* @param numbers a String[] value
* @jmx:managed-attribute
*/
public void setPhoneNumbers(String[] numbers) {
this.numbers = numbers;
}
/**
* Describe setPassword method here.
* write only attribute
* @param passwd a String value
* @jmx:managed-attribute persistPolicy="Never"
* persistPeriod="30"
* currencyTimeLimit="30"
*/
public void setPassword(String passwd) {
this.password = passwd;
}
// management operations
/**
* Describe printInfo method here.
* prints info
* @return a String value
* @jmx:managed-operation
*/
public String printInfo() {
return
"User: " + getName() +"\n"+
"Address: " + getAddress() +"\n"+
"Phone #: " + getPhoneNumbers()[0] +"\n"+
"Phone #: " + getPhoneNumbers()[1] +"\n"+
"Phone #: " + getPhoneNumbers()[2] +"\n";
}
/**
* Describe addPhoneNumber method here.
*
* @param number a String value, the phone number to add
* @jmx:managed-operation
*/
public void addPhoneNumber(String number) {
for (int i = 0; i < numbers.length; ++i)
if (numbers[i] == null) {
numbers[i] = number;
break;
}
}
/**
* Describe removePhoneNumber method here.
*
* @param index an int value, the index of phone number to remove
* @jmx:managed-operation
*/
public void removePhoneNumber(int index) {
if (index < 0 || index >= numbers.length)
return;
numbers[index] = null;
}
}