syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject svn commit: r1332734 - /incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/PolicyDataBinder.java
Date Tue, 01 May 2012 16:16:59 GMT
Author: rene
Date: Tue May  1 16:16:58 2012
New Revision: 1332734

URL: http://svn.apache.org/viewvc?rev=1332734&view=rev
Log:
sonar - fix unconfirmed casts

Modified:
    incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/PolicyDataBinder.java

Modified: incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/PolicyDataBinder.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/PolicyDataBinder.java?rev=1332734&r1=1332733&r2=1332734&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/PolicyDataBinder.java
(original)
+++ incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/PolicyDataBinder.java
Tue May  1 16:16:58 2012
@@ -41,37 +41,43 @@ public class PolicyDataBinder {
      */
     public <T extends PolicyTO> T getPolicyTO(final Policy policy) {
         final PolicyTO policyTO;
+
+        boolean isGlobal = Boolean.FALSE;
         switch (policy.getType()) {
             case GLOBAL_PASSWORD:
-                policyTO = new PasswordPolicyTO(true);
-                ((PasswordPolicyTO) policyTO).setSpecification((PasswordPolicySpec) policy.getSpecification());
-                break;
+            case GLOBAL_ACCOUNT:
+            case GLOBAL_SYNC:
+                isGlobal = Boolean.TRUE;
+            default:
+        }
 
+        switch (policy.getType()) {
+            case GLOBAL_PASSWORD:
             case PASSWORD:
-                policyTO = new PasswordPolicyTO();
+                if (!(policy.getSpecification() instanceof PasswordPolicySpec)) {
+                    throw new ClassCastException("policy is expected to be typed PasswordPolicySpec:
" + policy.getSpecification().getClass().getName());
+                }
+                policyTO = new PasswordPolicyTO(isGlobal);
                 ((PasswordPolicyTO) policyTO).setSpecification((PasswordPolicySpec) policy.getSpecification());
                 break;
 
             case GLOBAL_ACCOUNT:
-                policyTO = new AccountPolicyTO(true);
-                ((AccountPolicyTO) policyTO).setSpecification((AccountPolicySpec) policy.getSpecification());
-                break;
-
             case ACCOUNT:
-                policyTO = new AccountPolicyTO();
+                if (!(policy.getSpecification() instanceof AccountPolicySpec)) {
+                    throw new ClassCastException("policy is expected to be typed AccountPolicySpec:
" + policy.getSpecification().getClass().getName());
+                }
+                policyTO = new AccountPolicyTO(isGlobal);
                 ((AccountPolicyTO) policyTO).setSpecification((AccountPolicySpec) policy.getSpecification());
                 break;
 
             case GLOBAL_SYNC:
-                policyTO = new SyncPolicyTO(true);
-                ((SyncPolicyTO) policyTO).setSpecification((SyncPolicySpec) policy.getSpecification());
-                break;
-
             case SYNC:
             default:
-                policyTO = new SyncPolicyTO();
+                if (!(policy.getSpecification() instanceof SyncPolicySpec)) {
+                    throw new ClassCastException("policy is expected to be typed SyncPolicySpec:
" + policy.getSpecification().getClass().getName());
+                }
+                policyTO = new SyncPolicyTO(isGlobal);
                 ((SyncPolicyTO) policyTO).setSpecification((SyncPolicySpec) policy.getSpecification());
-
         }
 
         policyTO.setId(policy.getId());
@@ -83,8 +89,7 @@ public class PolicyDataBinder {
     public <T extends Policy> T getPolicy(T policy, final PolicyTO policyTO) {
 
         if (policy != null && policy.getType() != policyTO.getType()) {
-            throw new IllegalArgumentException(String.format("Cannot update %s from %s",
policy.getType(), policyTO
-                    .getType()));
+            throw new IllegalArgumentException(String.format("Cannot update %s from %s",
policy.getType(), policyTO.getType()));
         }
 
         switch (policyTO.getType()) {



Mime
View raw message