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