You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by re...@apache.org on 2012/05/01 18:30:27 UTC

svn commit: r1332743 - in /incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans: membership/MAttr.java role/RAttr.java user/UAttr.java

Author: rene
Date: Tue May  1 16:30:26 2012
New Revision: 1332743

URL: http://svn.apache.org/viewvc?rev=1332743&view=rev
Log:
sonar: fix unchecked casts

Modified:
    incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/membership/MAttr.java
    incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/role/RAttr.java
    incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/user/UAttr.java

Modified: incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/membership/MAttr.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/membership/MAttr.java?rev=1332743&r1=1332742&r2=1332743&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/membership/MAttr.java (original)
+++ incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/membership/MAttr.java Tue May  1 16:30:26 2012
@@ -38,21 +38,16 @@ import org.apache.syncope.core.persisten
 public class MAttr extends AbstractAttr {
 
     private static final long serialVersionUID = 3755864809152866489L;
-
     @Id
     private Long id;
-
     @ManyToOne(fetch = FetchType.EAGER)
     private Membership owner;
-
     @ManyToOne(fetch = FetchType.EAGER)
     @JoinColumn(name = "schema_name")
     private MSchema schema;
-
     @OneToMany(cascade = CascadeType.MERGE, orphanRemoval = true, mappedBy = "attribute")
     @Valid
     private List<MAttrValue> values;
-
     @OneToOne(cascade = CascadeType.ALL, mappedBy = "attribute")
     @Valid
     private MAttrUniqueValue uniqueValue;
@@ -74,6 +69,9 @@ public class MAttr extends AbstractAttr 
 
     @Override
     public <T extends AbstractAttributable> void setOwner(T owner) {
+        if (!(owner instanceof Membership)) {
+            throw new ClassCastException("owner is expected to be typed Membership: " + owner.getClass().getName());
+        }
         this.owner = (Membership) owner;
     }
 
@@ -84,19 +82,26 @@ public class MAttr extends AbstractAttr 
 
     @Override
     public <T extends AbstractSchema> void setSchema(T schema) {
+        if (!(schema instanceof MSchema)) {
+            throw new ClassCastException("schema is expected to be typed MSchema: " + schema.getClass().getName());
+        }
         this.schema = (MSchema) schema;
     }
 
     @Override
     public <T extends AbstractAttrValue> boolean addValue(final T attributeValue) {
-
+        if (!(attributeValue instanceof MAttrValue)) {
+            throw new ClassCastException("attributeValue is expected to be typed MAttrValue: " + attributeValue.getClass().getName());
+        }
         attributeValue.setAttribute(this);
         return values.add((MAttrValue) attributeValue);
     }
 
     @Override
     public <T extends AbstractAttrValue> boolean removeValue(final T attributeValue) {
-
+        if (!(attributeValue instanceof MAttrValue)) {
+            throw new ClassCastException("attributeValue is expected to be typed MAttrValue: " + attributeValue.getClass().getName());
+        }
         boolean result = values.remove((MAttrValue) attributeValue);
         attributeValue.setAttribute(null);
         return result;
@@ -126,7 +131,9 @@ public class MAttr extends AbstractAttr 
 
     @Override
     public <T extends AbstractAttrValue> void setUniqueValue(final T uniqueAttributeValue) {
-
+        if (!(uniqueAttributeValue instanceof MAttrUniqueValue)) {
+            throw new ClassCastException("uniqueAttributeValue is expected to be typed MAttrUniqueValue: " + uniqueAttributeValue.getClass().getName());
+        }
         this.uniqueValue = (MAttrUniqueValue) uniqueAttributeValue;
     }
 }

Modified: incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/role/RAttr.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/role/RAttr.java?rev=1332743&r1=1332742&r2=1332743&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/role/RAttr.java (original)
+++ incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/role/RAttr.java Tue May  1 16:30:26 2012
@@ -38,21 +38,16 @@ import org.apache.syncope.core.persisten
 public class RAttr extends AbstractAttr {
 
     private static final long serialVersionUID = 2848159565890995780L;
-
     @Id
     private Long id;
-
     @ManyToOne(fetch = FetchType.EAGER)
     private SyncopeRole owner;
-
     @ManyToOne(fetch = FetchType.EAGER)
     @JoinColumn(name = "schema_name")
     private RSchema schema;
-
     @OneToMany(cascade = CascadeType.MERGE, orphanRemoval = true, mappedBy = "attribute")
     @Valid
     private List<RAttrValue> values;
-
     @OneToOne(cascade = CascadeType.ALL, mappedBy = "attribute")
     @Valid
     private RAttrUniqueValue uniqueValue;
@@ -74,6 +69,9 @@ public class RAttr extends AbstractAttr 
 
     @Override
     public <T extends AbstractAttributable> void setOwner(T owner) {
+        if (!(owner instanceof SyncopeRole)) {
+            throw new ClassCastException("owner is expected to be typed SyncopeRole: " + owner.getClass().getName());
+        }
         this.owner = (SyncopeRole) owner;
     }
 
@@ -84,18 +82,25 @@ public class RAttr extends AbstractAttr 
 
     @Override
     public <T extends AbstractSchema> void setSchema(T schema) {
+        if (!(schema instanceof RSchema)) {
+            throw new ClassCastException("schema is expected to be typed RSchema: " + schema.getClass().getName());
+        }
         this.schema = (RSchema) schema;
     }
 
     @Override
     public <T extends AbstractAttrValue> boolean addValue(final T attributeValue) {
-
+        if (!(attributeValue instanceof RAttrValue)) {
+            throw new ClassCastException("attributeValue is expected to be typed RAttrValue: " + attributeValue.getClass().getName());
+        }
         return values.add((RAttrValue) attributeValue);
     }
 
     @Override
     public <T extends AbstractAttrValue> boolean removeValue(final T attributeValue) {
-
+        if (!(attributeValue instanceof RAttrValue)) {
+            throw new ClassCastException("attributeValue is expected to be typed RAttrValue: " + attributeValue.getClass().getName());
+        }
         return values.remove((RAttrValue) attributeValue);
     }
 
@@ -123,7 +128,9 @@ public class RAttr extends AbstractAttr 
 
     @Override
     public <T extends AbstractAttrValue> void setUniqueValue(final T uniqueAttributeValue) {
-
+        if (!(uniqueAttributeValue instanceof RAttrUniqueValue)) {
+            throw new ClassCastException("uniqueAttributeValue is expected to be typed RAttrUniqueValue: " + uniqueAttributeValue.getClass().getName());
+        }
         this.uniqueValue = (RAttrUniqueValue) uniqueAttributeValue;
     }
 }

Modified: incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/user/UAttr.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/user/UAttr.java?rev=1332743&r1=1332742&r2=1332743&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/user/UAttr.java (original)
+++ incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/user/UAttr.java Tue May  1 16:30:26 2012
@@ -41,33 +41,28 @@ import org.apache.syncope.core.persisten
 public class UAttr extends AbstractAttr {
 
     private static final long serialVersionUID = 6333601983691157406L;
-
     /**
      * Auto-generated id for this table.
      */
     @Id
     private Long id;
-
     /**
      * The owner of this attribute.
      */
     @ManyToOne(fetch = FetchType.EAGER)
     private SyncopeUser owner;
-
     /**
      * The schema of this attribute.
      */
     @ManyToOne(fetch = FetchType.EAGER)
     @JoinColumn(name = "schema_name")
     private USchema schema;
-
     /**
      * Values of this attribute (if schema is not UNIQUE).
      */
     @OneToMany(cascade = CascadeType.MERGE, orphanRemoval = true, mappedBy = "attribute")
     @Valid
     private List<UAttrValue> values;
-
     /**
      * Value of this attribute (if schema is UNIQUE).
      */
@@ -95,6 +90,9 @@ public class UAttr extends AbstractAttr 
 
     @Override
     public <T extends AbstractAttributable> void setOwner(final T owner) {
+        if (!(owner instanceof SyncopeUser)) {
+            throw new ClassCastException("owner is expected to be typed SyncopeUser: " + owner.getClass().getName());
+        }
         this.owner = (SyncopeUser) owner;
     }
 
@@ -105,18 +103,25 @@ public class UAttr extends AbstractAttr 
 
     @Override
     public <T extends AbstractSchema> void setSchema(final T schema) {
+        if (!(schema instanceof USchema)) {
+            throw new ClassCastException("schema is expected to be typed USchema: " + schema.getClass().getName());
+        }
         this.schema = (USchema) schema;
     }
 
     @Override
     public <T extends AbstractAttrValue> boolean addValue(final T attributeValue) {
-
+        if (!(attributeValue instanceof UAttrValue)) {
+            throw new ClassCastException("attributeValue is expected to be typed UAttrValue: " + attributeValue.getClass().getName());
+        }
         return values.add((UAttrValue) attributeValue);
     }
 
     @Override
     public <T extends AbstractAttrValue> boolean removeValue(final T attributeValue) {
-
+        if (!(attributeValue instanceof UAttrValue)) {
+            throw new ClassCastException("attributeValue is expected to be typed UAttrValue: " + attributeValue.getClass().getName());
+        }
         return values.remove((UAttrValue) attributeValue);
     }
 
@@ -144,7 +149,9 @@ public class UAttr extends AbstractAttr 
 
     @Override
     public <T extends AbstractAttrValue> void setUniqueValue(final T uniqueAttributeValue) {
-
+        if (!(uniqueAttributeValue instanceof UAttrUniqueValue)) {
+            throw new ClassCastException("uniqueAttributeValue is expected to be typed UAttrUniqueValue: " + uniqueAttributeValue.getClass().getName());
+        }
         this.uniqueValue = (UAttrUniqueValue) uniqueAttributeValue;
     }
 }