aboutsummaryrefslogtreecommitdiff
path: root/id/server/stork2-commons/src/main/java/eu/stork/peps/auth/commons/AttributeSource.java
diff options
context:
space:
mode:
Diffstat (limited to 'id/server/stork2-commons/src/main/java/eu/stork/peps/auth/commons/AttributeSource.java')
-rw-r--r--id/server/stork2-commons/src/main/java/eu/stork/peps/auth/commons/AttributeSource.java81
1 files changed, 75 insertions, 6 deletions
diff --git a/id/server/stork2-commons/src/main/java/eu/stork/peps/auth/commons/AttributeSource.java b/id/server/stork2-commons/src/main/java/eu/stork/peps/auth/commons/AttributeSource.java
index 4b9dc33e9..846f54f67 100644
--- a/id/server/stork2-commons/src/main/java/eu/stork/peps/auth/commons/AttributeSource.java
+++ b/id/server/stork2-commons/src/main/java/eu/stork/peps/auth/commons/AttributeSource.java
@@ -1,17 +1,31 @@
package eu.stork.peps.auth.commons;
+import java.io.Serializable;
+
+import org.apache.log4j.Logger;
+
/**
* This class is a bean used to store the information relative to the Attribute Source (either AttributeProvider or Country).
*
* @author Stelios Lelis (stelios.lelis@aegean.gr), Elias Pastos (ilias@aegean.gr)
*
- * @version $Revision: 1.00 $, $Date: 2013-09-19 $
+ * @version $Revision: 1.10 $, $Date: 2013-11-29 $
*/
-public final class AttributeSource {
+public final class AttributeSource implements Serializable {
+ /**
+ * Unique identifier.
+ */
+ private static final long serialVersionUID = 432243595968469014L;
+
public static final int SOURCE_LOCAL_APROVIDER = 1;
public static final int SOURCE_REMOTE_COUNTRY = 2;
/**
+ * Logger object.
+ */
+ private static final Logger LOG = Logger.getLogger(AttributeSource.class.getName());
+
+ /**
* Provider source.
*/
private int sourceType;
@@ -60,7 +74,7 @@ public final class AttributeSource {
/**
* @param sourceType the sourceType to set
*/
- public void setSourceType(int sourceType) {
+ public void setSourceType(final int sourceType) {
this.sourceType = sourceType;
}
@@ -74,7 +88,7 @@ public final class AttributeSource {
/**
* @param providerURL the providerURL to set
*/
- public void setProviderURL(String providerURL) {
+ public void setProviderURL(final String providerURL) {
this.providerURL = providerURL;
}
@@ -88,7 +102,7 @@ public final class AttributeSource {
/**
* @param provider the provider to set
*/
- public void setProvider(AttributeProvider provider) {
+ public void setProvider(final AttributeProvider provider) {
this.setSourceType(SOURCE_LOCAL_APROVIDER);
this.provider = provider;
@@ -104,7 +118,7 @@ public final class AttributeSource {
/**
* @param country the country to set
*/
- public void setCountry(Country country) {
+ public void setCountry(final Country country) {
this.setSourceType(SOURCE_REMOTE_COUNTRY);
this.country = country;
@@ -116,4 +130,59 @@ public final class AttributeSource {
public Country getCountry() {
return country;
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean equals(Object obj) {
+ boolean outcome = false;
+
+ LOG.debug("Calling equals with Object.");
+ if ( obj instanceof AttributeSource ) {
+ LOG.debug("Calling equals with AttributeSource.");
+ outcome = this.equals((AttributeSource)obj);
+ }
+
+ LOG.debug("Object equals outcome: " + outcome);
+ return outcome;
+ }
+
+ /**
+ * Compare the given AttributeSource with the current object in order to determinine
+ * if they are equal.
+ *
+ * @param obj The AttributeSource to compare to
+ *
+ * @return true if the two objects are equal
+ */
+ public boolean equals(AttributeSource obj) {
+ boolean outcome = false;
+
+ if ( this.sourceType==obj.getSourceType() ) {
+ if ( this.sourceType==AttributeSource.SOURCE_LOCAL_APROVIDER ) {
+ if ( this.provider.getProviderId().equals(obj.getProvider().getProviderId()) )
+ outcome = true;
+ }
+ else if ( this.sourceType==AttributeSource.SOURCE_REMOTE_COUNTRY ) {
+ if ( this.country.getCountryId().equals(obj.getCountry().getCountryId()) )
+ outcome = true;
+ }
+ }
+
+ LOG.debug("AttributeSource equals outcome: " + outcome);
+ return outcome;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int hashCode() {
+ int hash = 1;
+ hash = hash * 17 + this.sourceType;
+ if ( this.sourceType==AttributeSource.SOURCE_LOCAL_APROVIDER )
+ hash = hash * 31 + this.provider.getProviderName().hashCode();
+ else
+ hash = hash * 31 + this.country.getCountryName().hashCode();
+ return hash;
+ }
}