Commit 7f13c6f085a5389a855a17cf2032bcb7d2dd7ac1
1 parent
bac46fcf
Exists in
master
Implementadas exceções específicas para o módulo de monitoração.
Showing
3 changed files
with
76 additions
and
17 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/management/Management.java
| ... | ... | @@ -46,15 +46,14 @@ import java.util.Set; |
| 46 | 46 | import javax.enterprise.context.ApplicationScoped; |
| 47 | 47 | import javax.enterprise.context.RequestScoped; |
| 48 | 48 | import javax.inject.Inject; |
| 49 | -import javax.management.ReflectionException; | |
| 50 | 49 | import javax.validation.ConstraintViolation; |
| 50 | +import javax.validation.ConstraintViolationException; | |
| 51 | 51 | import javax.validation.Validation; |
| 52 | 52 | import javax.validation.ValidationException; |
| 53 | 53 | import javax.validation.Validator; |
| 54 | 54 | |
| 55 | 55 | import org.slf4j.Logger; |
| 56 | 56 | |
| 57 | -import br.gov.frameworkdemoiselle.DemoiselleException; | |
| 58 | 57 | import br.gov.frameworkdemoiselle.annotation.ManagedProperty; |
| 59 | 58 | import br.gov.frameworkdemoiselle.annotation.Name; |
| 60 | 59 | import br.gov.frameworkdemoiselle.internal.context.ContextManager; |
| ... | ... | @@ -62,6 +61,8 @@ import br.gov.frameworkdemoiselle.internal.context.ManagedContext; |
| 62 | 61 | import br.gov.frameworkdemoiselle.internal.management.ManagedType.MethodDetail; |
| 63 | 62 | import br.gov.frameworkdemoiselle.lifecycle.ManagementExtension; |
| 64 | 63 | import br.gov.frameworkdemoiselle.management.AttributeChangeNotification; |
| 64 | +import br.gov.frameworkdemoiselle.management.ManagedAttributeNotFoundException; | |
| 65 | +import br.gov.frameworkdemoiselle.management.ManagedInvokationException; | |
| 65 | 66 | import br.gov.frameworkdemoiselle.management.NotificationManager; |
| 66 | 67 | import br.gov.frameworkdemoiselle.stereotype.ManagementController; |
| 67 | 68 | import br.gov.frameworkdemoiselle.util.Beans; |
| ... | ... | @@ -124,7 +125,7 @@ public class Management implements Serializable { |
| 124 | 125 | * parameters. |
| 125 | 126 | * @return The return value of the original invoked operation. Methods of return type <code>void</code> will return |
| 126 | 127 | * the {@link Void} type. |
| 127 | - * @throws ReflectionException | |
| 128 | + * @throws ManagedInvokationException | |
| 128 | 129 | * In case the operation doesn't exist or have a different signature |
| 129 | 130 | */ |
| 130 | 131 | public Object invoke(ManagedType managedType, String actionName, Object[] params) { |
| ... | ... | @@ -141,16 +142,16 @@ public class Management implements Serializable { |
| 141 | 142 | .getType().getCanonicalName())); |
| 142 | 143 | return method.getMethod().invoke(delegate, params); |
| 143 | 144 | } catch (Exception e) { |
| 144 | - throw new DemoiselleException(bundle.getString("management-invoke-error", actionName), e); | |
| 145 | + throw new ManagedInvokationException(bundle.getString("management-invoke-error", actionName), e); | |
| 145 | 146 | } |
| 146 | 147 | } else { |
| 147 | - throw new DemoiselleException(bundle.getString("management-invoke-error", actionName)); | |
| 148 | + throw new ManagedInvokationException(bundle.getString("management-invoke-error", actionName)); | |
| 148 | 149 | } |
| 149 | 150 | } finally { |
| 150 | 151 | deactivateContexts(managedType.getType()); |
| 151 | 152 | } |
| 152 | 153 | } else { |
| 153 | - throw new DemoiselleException(bundle.getString("management-type-not-found")); | |
| 154 | + throw new ManagedInvokationException(bundle.getString("management-type-not-found")); | |
| 154 | 155 | } |
| 155 | 156 | } |
| 156 | 157 | |
| ... | ... | @@ -169,6 +170,8 @@ public class Management implements Serializable { |
| 169 | 170 | * @param propertyName |
| 170 | 171 | * The name of the property |
| 171 | 172 | * @return The current value of the property |
| 173 | + * @throws ManagedAttributeNotFoundException If the given property doesn't exist or there was a problem trying to read the property value. | |
| 174 | + * @throws ManagedInvokationException If there was an error trying to invoke the getter method to read the propery value. | |
| 172 | 175 | */ |
| 173 | 176 | public Object getProperty(ManagedType managedType, String propertyName) { |
| 174 | 177 | |
| ... | ... | @@ -186,16 +189,16 @@ public class Management implements Serializable { |
| 186 | 189 | |
| 187 | 190 | return getterMethod.invoke(delegate, (Object[]) null); |
| 188 | 191 | } catch (Exception e) { |
| 189 | - throw new DemoiselleException(bundle.getString("management-invoke-error", getterMethod.getName()), | |
| 192 | + throw new ManagedInvokationException(bundle.getString("management-invoke-error", getterMethod.getName()), | |
| 190 | 193 | e); |
| 191 | 194 | } finally { |
| 192 | 195 | deactivateContexts(managedType.getType()); |
| 193 | 196 | } |
| 194 | 197 | } else { |
| 195 | - throw new DemoiselleException(bundle.getString("management-read-value-error", propertyName)); | |
| 198 | + throw new ManagedAttributeNotFoundException(bundle.getString("management-read-value-error", propertyName)); | |
| 196 | 199 | } |
| 197 | 200 | } else { |
| 198 | - throw new DemoiselleException(bundle.getString("management-type-not-found")); | |
| 201 | + throw new ManagedInvokationException(bundle.getString("management-type-not-found")); | |
| 199 | 202 | } |
| 200 | 203 | } |
| 201 | 204 | |
| ... | ... | @@ -215,7 +218,11 @@ public class Management implements Serializable { |
| 215 | 218 | * The name of the property |
| 216 | 219 | * @param newValue |
| 217 | 220 | * The new value of the property |
| 221 | + * @throws ManagedInvokationException If there was an error trying to call the setter method for this property. | |
| 222 | + * @throws ManagedAttributeNotFoundException If the giver property doesn't exist or could'n be written to. | |
| 223 | + * @throws ConstraintViolationException If the property defined one or more validation constraints and setting this value violates some of those constraints. | |
| 218 | 224 | */ |
| 225 | + @SuppressWarnings("unchecked") | |
| 219 | 226 | public void setProperty(ManagedType managedType, String propertyName, Object newValue) { |
| 220 | 227 | |
| 221 | 228 | if (managedTypes.contains(managedType)) { |
| ... | ... | @@ -249,9 +256,9 @@ public class Management implements Serializable { |
| 249 | 256 | errorBuffer.insert(errorBuffer.length(), "\r\n"); |
| 250 | 257 | } |
| 251 | 258 | |
| 252 | - throw new DemoiselleException(bundle.getString( | |
| 253 | - "management-validation-constraint-violation", managedType.getType() | |
| 254 | - .getCanonicalName(), propertyName, errorBuffer.toString())); | |
| 259 | + throw new ConstraintViolationException(bundle.getString("management-validation-constraint-violation" | |
| 260 | + , managedType.getType().getCanonicalName(), propertyName, errorBuffer.toString()) | |
| 261 | + , (Set<ConstraintViolation<?>>) violations); | |
| 255 | 262 | } |
| 256 | 263 | } else { |
| 257 | 264 | logger.warn(bundle.getString("management-validation-validator-not-found")); |
| ... | ... | @@ -276,19 +283,19 @@ public class Management implements Serializable { |
| 276 | 283 | .getCanonicalName()), propertyName, attributeType, oldValue, newValue); |
| 277 | 284 | notificationManager.sendNotification(notification); |
| 278 | 285 | |
| 279 | - } catch (DemoiselleException de) { | |
| 280 | - throw de; | |
| 286 | + } catch (ConstraintViolationException ce) { | |
| 287 | + throw ce; | |
| 281 | 288 | } catch (Exception e) { |
| 282 | - throw new DemoiselleException(bundle.getString("management-invoke-error", method.getName()), e); | |
| 289 | + throw new ManagedInvokationException(bundle.getString("management-invoke-error", method.getName()), e); | |
| 283 | 290 | } finally { |
| 284 | 291 | deactivateContexts(managedType.getType()); |
| 285 | 292 | } |
| 286 | 293 | |
| 287 | 294 | } else { |
| 288 | - throw new DemoiselleException(bundle.getString("management-write-value-error", propertyName)); | |
| 295 | + throw new ManagedAttributeNotFoundException(bundle.getString("management-write-value-error", propertyName)); | |
| 289 | 296 | } |
| 290 | 297 | } else { |
| 291 | - throw new DemoiselleException(bundle.getString("management-type-not-found")); | |
| 298 | + throw new ManagedInvokationException(bundle.getString("management-type-not-found")); | |
| 292 | 299 | } |
| 293 | 300 | |
| 294 | 301 | } | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/management/ManagedAttributeNotFoundException.java
0 → 100644
| ... | ... | @@ -0,0 +1,29 @@ |
| 1 | +package br.gov.frameworkdemoiselle.management; | |
| 2 | + | |
| 3 | +import br.gov.frameworkdemoiselle.DemoiselleException; | |
| 4 | + | |
| 5 | +/** | |
| 6 | + * | |
| 7 | + * Thrown when a management client tries to read or write a property, but the | |
| 8 | + * management engine has no knowledge of an attribute with the given name. | |
| 9 | + * | |
| 10 | + * @author serpro | |
| 11 | + * | |
| 12 | + */ | |
| 13 | +public class ManagedAttributeNotFoundException extends DemoiselleException { | |
| 14 | + | |
| 15 | + private static final long serialVersionUID = 2554101387574235418L; | |
| 16 | + | |
| 17 | + public ManagedAttributeNotFoundException(String message, Throwable cause) { | |
| 18 | + super(message, cause); | |
| 19 | + } | |
| 20 | + | |
| 21 | + public ManagedAttributeNotFoundException(String message) { | |
| 22 | + super(message); | |
| 23 | + } | |
| 24 | + | |
| 25 | + public ManagedAttributeNotFoundException(Throwable cause) { | |
| 26 | + super(cause); | |
| 27 | + } | |
| 28 | + | |
| 29 | +} | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/management/ManagedInvokationException.java
0 → 100644
| ... | ... | @@ -0,0 +1,23 @@ |
| 1 | +package br.gov.frameworkdemoiselle.management; | |
| 2 | + | |
| 3 | +import br.gov.frameworkdemoiselle.DemoiselleException; | |
| 4 | + | |
| 5 | + | |
| 6 | +public class ManagedInvokationException extends DemoiselleException { | |
| 7 | + | |
| 8 | + private static final long serialVersionUID = -1542365184737242152L; | |
| 9 | + | |
| 10 | + public ManagedInvokationException(String message, Throwable cause) { | |
| 11 | + super(message, cause); | |
| 12 | + } | |
| 13 | + | |
| 14 | + public ManagedInvokationException(String message) { | |
| 15 | + super(message); | |
| 16 | + } | |
| 17 | + | |
| 18 | + public ManagedInvokationException(Throwable cause) { | |
| 19 | + super(cause); | |
| 20 | + } | |
| 21 | + | |
| 22 | + | |
| 23 | +} | ... | ... |