Commit fbdf2a96 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gaston

Code modified to take advantage of Generics and new "for" format.


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@223 b35dd754-fafc-0310-a699-88a17e54d16e
parent 97aea9cc
......@@ -125,7 +125,7 @@ public interface FormField {
*
* @return an Iterator for the default values or answered values of the question.
*/
public abstract Iterator getValues();
public abstract Iterator<String> getValues();
/**
* Returns an indicative of the format for the data to answer. Valid formats are:
......
......@@ -36,8 +36,8 @@ public class XFormFieldImpl implements XMPPFragment, FormField {
private String label;
private String variable;
private String type;
private List options = new ArrayList();
private List values = new ArrayList();
private List<Option> options = new ArrayList<Option>();
private List<String> values = new ArrayList<String>();
private ConcurrentHashSet fragments = new ConcurrentHashSet();
public XFormFieldImpl() {
......@@ -90,18 +90,18 @@ public class XFormFieldImpl implements XMPPFragment, FormField {
}
// Loop through all the values and append them to the stream writer
if (values.size() > 0) {
Iterator valuesItr = getValues();
Iterator<String> valuesItr = getValues();
while (valuesItr.hasNext()) {
xmlSerializer.writeStartElement("jabber:x:data", "value");
xmlSerializer.writeCharacters((String)valuesItr.next());
xmlSerializer.writeCharacters(valuesItr.next());
xmlSerializer.writeEndElement();
}
}
// Loop through all the options and append them to the stream writer
if (options.size() > 0) {
Iterator optionsItr = getOptions();
Iterator<Option> optionsItr = getOptions();
while (optionsItr.hasNext()) {
((Option)optionsItr.next()).send(xmlSerializer, version);
(optionsItr.next()).send(xmlSerializer, version);
}
}
Iterator frags = fragments.iterator();
......@@ -132,16 +132,16 @@ public class XFormFieldImpl implements XMPPFragment, FormField {
}
// Loop through all the values and append them to the stream writer
if (values.size() > 0) {
Iterator valuesItr = getValues();
Iterator<String> valuesItr = getValues();
while (valuesItr.hasNext()) {
field.addElement("value").addText((String)valuesItr.next());
field.addElement("value").addText(valuesItr.next());
}
}
// Loop through all the options and append them to the stream writer
if (options.size() > 0) {
Iterator optionsItr = getOptions();
Iterator<Option> optionsItr = getOptions();
while (optionsItr.hasNext()) {
field.add(((Option)optionsItr.next()).asXMLElement());
field.add((optionsItr.next()).asXMLElement());
}
}
......@@ -161,8 +161,8 @@ public class XFormFieldImpl implements XMPPFragment, FormField {
copy.required = this.required;
copy.label = this.label;
copy.type = this.type;
copy.options = (List)((ArrayList)this.options).clone();
copy.values = (List)((ArrayList)this.values).clone();
copy.options = (List<Option>)((ArrayList)this.options).clone();
copy.values = (List<String>)((ArrayList)this.values).clone();
Iterator fragmentIter = getFragments();
while (fragmentIter.hasNext()) {
......@@ -247,9 +247,9 @@ public class XFormFieldImpl implements XMPPFragment, FormField {
return variable;
}
public Iterator getValues() {
public Iterator<String> getValues() {
synchronized (values) {
return Collections.unmodifiableList(new ArrayList(values)).iterator();
return Collections.unmodifiableList(new ArrayList<String>(values)).iterator();
}
}
......@@ -263,9 +263,9 @@ public class XFormFieldImpl implements XMPPFragment, FormField {
*
* @return Iterator for the available options.
*/
private Iterator getOptions() {
private Iterator<Option> getOptions() {
synchronized (options) {
return Collections.unmodifiableList(new ArrayList(options)).iterator();
return Collections.unmodifiableList(new ArrayList<Option>(options)).iterator();
}
}
......
......@@ -256,19 +256,19 @@ public class IQRegisterHandler extends IQHandler implements ServerFeaturesProvid
registrationForm = new XDataFormImpl();
registrationForm.parse(formElement);
// Get the username sent in the form
Iterator values = registrationForm.getField("username").getValues();
username = (values.hasNext() ? (String)values.next() : " ");
Iterator<String> values = registrationForm.getField("username").getValues();
username = (values.hasNext() ? values.next() : " ");
// Get the password sent in the form
field = registrationForm.getField("password");
if (field != null) {
values = field.getValues();
password = (values.hasNext() ? (String)values.next() : " ");
password = (values.hasNext() ? values.next() : " ");
}
// Get the email sent in the form
field = registrationForm.getField("email");
if (field != null) {
values = field.getValues();
email = (values.hasNext() ? (String)values.next() : " ");
email = (values.hasNext() ? values.next() : " ");
}
}
else {
......@@ -316,21 +316,21 @@ public class IQRegisterHandler extends IQHandler implements ServerFeaturesProvid
}
// Set and save the extra user info (e.g. Full name, name visible, etc.)
if (newUser != null && registrationForm != null) {
Iterator values;
Iterator<String> values;
// Get the full name sent in the form
field = registrationForm.getField("name");
if (field != null) {
values = field.getValues();
String name = (values.hasNext() ? (String)values.next() : " ");
String name = (values.hasNext() ? values.next() : " ");
newUser.getInfo().setName(name);
}
// Get the name visible flag sent in the form
values = registrationForm.getField("x-nameVisible").getValues();
String visible = (values.hasNext() ? (String)values.next() : "1");
String visible = (values.hasNext() ? values.next() : "1");
boolean nameVisible = ("1".equals(visible) ? true : false);
// Get the email visible flag sent in the form
values = registrationForm.getField("x-emailVisible").getValues();
visible = (values.hasNext() ? (String)values.next() : "0");
visible = (values.hasNext() ? values.next() : "0");
boolean emailVisible = ("1".equals(visible) ? true : false);
// Save the extra user info
newUser.getInfo().setNameVisible(nameVisible);
......
......@@ -222,7 +222,7 @@ public interface MUCRoom extends ChatDeliverer {
* join the room.
* @throws ForbiddenException If the user is not allowed to modify the owner list.
*/
public List addOwner(String bareJID, MUCRole senderRole) throws ForbiddenException;
public List<Presence> addOwner(String bareJID, MUCRole senderRole) throws ForbiddenException;
/**
* Adds a list of users to the list of owners.
......@@ -233,7 +233,8 @@ public interface MUCRoom extends ChatDeliverer {
* join the room.
* @throws ForbiddenException If the user is not allowed to modify the owner list.
*/
public List addOwners(List newOwners, MUCRole senderRole) throws ForbiddenException;
public List<Presence> addOwners(List<String> newOwners, MUCRole senderRole)
throws ForbiddenException;
/**
* Adds a list of users to the list of admins.
......@@ -245,8 +246,8 @@ public interface MUCRoom extends ChatDeliverer {
* @throws ForbiddenException If the user is not allowed to modify the admin list.
* @throws ConflictException If the room was going to lose all its owners.
*/
public List addAdmins(List newAdmins, MUCRole senderRole) throws ForbiddenException,
ConflictException;
public List<Presence> addAdmins(List<String> newAdmins, MUCRole senderRole)
throws ForbiddenException, ConflictException;
/**
* Adds a new user to the list of admins.
......@@ -258,7 +259,7 @@ public interface MUCRoom extends ChatDeliverer {
* @throws ForbiddenException If the user is not allowed to modify the admin list.
* @throws ConflictException If the room was going to lose all its owners.
*/
public List addAdmin(String bareJID, MUCRole senderRole) throws ForbiddenException,
public List<Presence> addAdmin(String bareJID, MUCRole senderRole) throws ForbiddenException,
ConflictException;
/**
......@@ -273,7 +274,7 @@ public interface MUCRoom extends ChatDeliverer {
* @throws ConflictException If the desired room nickname is already reserved for the room or if
* the room was going to lose all its owners.
*/
public List addMember(String bareJID, String nickname, MUCRole senderRole)
public List<Presence> addMember(String bareJID, String nickname, MUCRole senderRole)
throws ForbiddenException, ConflictException;
/**
......@@ -288,7 +289,7 @@ public interface MUCRoom extends ChatDeliverer {
* @throws ForbiddenException If the user is not allowed to modify the outcast list.
* @throws ConflictException If the room was going to lose all its owners.
*/
public List addOutcast(String bareJID, String reason, MUCRole senderRole)
public List<Presence> addOutcast(String bareJID, String reason, MUCRole senderRole)
throws NotAllowedException, ForbiddenException, ConflictException;
/**
......@@ -301,7 +302,7 @@ public interface MUCRoom extends ChatDeliverer {
* @throws ForbiddenException If the user is not allowed to modify the none list.
* @throws ConflictException If the room was going to lose all its owners.
*/
public List addNone(String bareJID, MUCRole senderRole) throws ForbiddenException,
public List<Presence> addNone(String bareJID, MUCRole senderRole) throws ForbiddenException,
ConflictException;
/**
......
......@@ -102,8 +102,8 @@ public class IQAdminHandler {
throw new ForbiddenException();
}
String jid;
for (Iterator it = room.getOutcasts(); it.hasNext();) {
jid = (String)it.next();
for (Iterator<String> it = room.getOutcasts(); it.hasNext();) {
jid = it.next();
metaData = new MetaDataFragment("http://jabber.org/protocol/muc#admin",
"item");
metaData.setProperty("item:affiliation", "outcast");
......@@ -123,15 +123,15 @@ public class IQAdminHandler {
throw new ForbiddenException();
}
String jid;
for (Iterator it = room.getMembers(); it.hasNext();) {
jid = (String)it.next();
for (Iterator<String> it = room.getMembers(); it.hasNext();) {
jid = it.next();
metaData = new MetaDataFragment("http://jabber.org/protocol/muc#admin",
"item");
metaData.setProperty("item:affiliation", "member");
metaData.setProperty("item:jid", jid);
try {
List roles = room.getOccupantsByBareJID(jid);
role = (MUCRole)roles.get(0);
List<MUCRole> roles = room.getOccupantsByBareJID(jid);
role = roles.get(0);
metaData.setProperty("item:role", role.getRoleAsString());
metaData.setProperty("item:nick", role.getNickname());
}
......@@ -150,8 +150,8 @@ public class IQAdminHandler {
&& MUCRole.OWNER != senderRole.getAffiliation()) {
throw new ForbiddenException();
}
for (Iterator roles = room.getModerators(); roles.hasNext();) {
role = (MUCRole)roles.next();
for (Iterator<MUCRole> roles = room.getModerators(); roles.hasNext();) {
role = roles.next();
metaData = new MetaDataFragment("http://jabber.org/protocol/muc#admin",
"item");
metaData.setProperty("item:role", "moderator");
......@@ -170,8 +170,8 @@ public class IQAdminHandler {
if (MUCRole.MODERATOR != senderRole.getRole()) {
throw new ForbiddenException();
}
for (Iterator roles = room.getParticipants(); roles.hasNext();) {
role = (MUCRole)roles.next();
for (Iterator<MUCRole> roles = room.getParticipants(); roles.hasNext();) {
role = roles.next();
metaData = new MetaDataFragment("http://jabber.org/protocol/muc#admin",
"item");
metaData.setProperty("item:role", "participant");
......@@ -195,10 +195,11 @@ public class IQAdminHandler {
String jid = null;
String nick;
String target = null;
boolean hasAffiliation = ((Element) itemsList.get(0)).attributeValue("affiliation") != null;
boolean hasAffiliation = ((Element) itemsList.get(0)).attributeValue("affiliation") !=
null;
// Keep a registry of the updated presences
List presences = new ArrayList(itemsList.size());
List<Presence> presences = new ArrayList<Presence>(itemsList.size());
// Collect the new affiliations or roles for the specified jids
for (Iterator items = itemsList.iterator(); items.hasNext();) {
......@@ -288,8 +289,8 @@ public class IQAdminHandler {
// Send the updated presences to the room occupants
try {
for (Iterator it = presences.iterator(); it.hasNext();) {
room.send((Presence)it.next());
for (Presence presence : presences) {
room.send(presence);
}
}
catch (UnauthorizedException e) {
......
......@@ -151,7 +151,7 @@ public class IQMUCRegisterHandler extends IQHandler {
else if (IQ.SET.equals(packet.getType())) {
try {
// Keep a registry of the updated presences
List presences = new ArrayList();
List<Presence> presences = new ArrayList<Presence>();
reply = packet.createResult();
XMPPFragment iq = packet.getChildFragment();
......@@ -171,9 +171,9 @@ public class IQMUCRegisterHandler extends IQHandler {
XDataFormImpl registrationForm = new XDataFormImpl();
registrationForm.parse(formElement);
// Get the desired nickname sent in the form
Iterator values = registrationForm.getField("muc#register_roomnick")
Iterator<String> values = registrationForm.getField("muc#register_roomnick")
.getValues();
String nickname = (values.hasNext() ? (String)values.next() : null);
String nickname = (values.hasNext() ? values.next() : null);
// TODO The rest of the fields of the form are ignored. If we have a
// requirement in the future where we need those fields we'll have to change
......@@ -190,8 +190,8 @@ public class IQMUCRegisterHandler extends IQHandler {
}
// Send the updated presences to the room occupants
try {
for (Iterator it = presences.iterator(); it.hasNext();) {
room.send((Presence)it.next());
for (Presence presence : presences) {
room.send(presence);
}
}
catch (UnauthorizedException e) {
......
......@@ -237,26 +237,26 @@ class MUCPersistentRoomSurrogate implements MUCRoom, Cacheable {
throw new UnsupportedOperationException();
}
public List addOwner(String bareJID, MUCRole sendRole) throws ForbiddenException {
public List<Presence> addOwner(String bareJID, MUCRole sendRole) throws ForbiddenException {
throw new UnsupportedOperationException();
}
public List addAdmin(String bareJID, MUCRole sendRole) throws ForbiddenException,
public List<Presence> addAdmin(String bareJID, MUCRole sendRole) throws ForbiddenException,
ConflictException {
throw new UnsupportedOperationException();
}
public List addMember(String bareJID, String nickname, MUCRole sendRole)
public List<Presence> addMember(String bareJID, String nickname, MUCRole sendRole)
throws ForbiddenException, ConflictException {
throw new UnsupportedOperationException();
}
public List addOutcast(String bareJID, String reason, MUCRole sendRole)
public List<Presence> addOutcast(String bareJID, String reason, MUCRole sendRole)
throws NotAllowedException, ForbiddenException, ConflictException {
throw new UnsupportedOperationException();
}
public List addNone(String bareJID, MUCRole sendRole) throws ForbiddenException,
public List<Presence> addNone(String bareJID, MUCRole sendRole) throws ForbiddenException,
ConflictException {
throw new UnsupportedOperationException();
}
......@@ -470,12 +470,13 @@ class MUCPersistentRoomSurrogate implements MUCRoom, Cacheable {
throw new UnsupportedOperationException();
}
public List addAdmins(List newAdmins, MUCRole sendRole) throws ForbiddenException,
ConflictException {
public List<Presence> addAdmins(List<String> newAdmins, MUCRole sendRole)
throws ForbiddenException, ConflictException {
throw new UnsupportedOperationException();
}
public List addOwners(List newOwners, MUCRole sendRole) throws ForbiddenException {
public List<Presence> addOwners(List<String> newOwners, MUCRole sendRole)
throws ForbiddenException {
throw new UnsupportedOperationException();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment