Commit aae675b6be703da26ef4e1640737bdfe465b22e5

Authored by Luciano Borges
2 parents ea199d55 9fe4174c
Exists in master

Merge branch '2.4.0' of git@github.com:demoiselle/framework.git into 2.4.0

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 +}
... ...
impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/DynamicMBeanProxy.java
... ... @@ -58,6 +58,8 @@ import br.gov.frameworkdemoiselle.internal.management.ManagedType.FieldDetail;
58 58 import br.gov.frameworkdemoiselle.internal.management.ManagedType.MethodDetail;
59 59 import br.gov.frameworkdemoiselle.internal.management.ManagedType.ParameterDetail;
60 60 import br.gov.frameworkdemoiselle.internal.management.Management;
  61 +import br.gov.frameworkdemoiselle.management.ManagedAttributeNotFoundException;
  62 +import br.gov.frameworkdemoiselle.management.ManagedInvokationException;
61 63 import br.gov.frameworkdemoiselle.stereotype.ManagementController;
62 64 import br.gov.frameworkdemoiselle.util.Beans;
63 65 import br.gov.frameworkdemoiselle.util.ResourceBundle;
... ... @@ -95,7 +97,21 @@ public class DynamicMBeanProxy implements DynamicMBean {
95 97 }
96 98  
97 99 Management manager = Beans.getReference(Management.class);
98   - return manager.getProperty(managedType, attribute);
  100 +
  101 + try{
  102 + return manager.getProperty(managedType, attribute);
  103 + }
  104 + catch(DemoiselleException de){
  105 + if (ManagedAttributeNotFoundException.class.isInstance(de)){
  106 + throw new AttributeNotFoundException(de.getMessage());
  107 + }
  108 + else if (ManagedInvokationException.class.isInstance(de)){
  109 + throw new MBeanException(new Exception(de.getMessage()));
  110 + }
  111 + else{
  112 + throw de;
  113 + }
  114 + }
99 115 }
100 116  
101 117 @Override
... ... @@ -108,7 +124,21 @@ public class DynamicMBeanProxy implements DynamicMBean {
108 124 }
109 125  
110 126 Management manager = Beans.getReference(Management.class);
111   - manager.setProperty(managedType, attribute.getName(), attribute.getValue());
  127 +
  128 + try{
  129 + manager.setProperty(managedType, attribute.getName(), attribute.getValue());
  130 + }
  131 + catch(DemoiselleException de){
  132 + if (ManagedAttributeNotFoundException.class.isInstance(de)){
  133 + throw new AttributeNotFoundException(de.getMessage());
  134 + }
  135 + else if (ManagedInvokationException.class.isInstance(de)){
  136 + throw new MBeanException(new Exception(de.getMessage()));
  137 + }
  138 + else{
  139 + throw de;
  140 + }
  141 + }
112 142 }
113 143  
114 144 @Override
... ... @@ -161,7 +191,13 @@ public class DynamicMBeanProxy implements DynamicMBean {
161 191 }
162 192  
163 193 Management manager = Beans.getReference(Management.class);
164   - return manager.invoke(managedType, actionName, params);
  194 +
  195 + try{
  196 + return manager.invoke(managedType, actionName, params);
  197 + }
  198 + catch(DemoiselleException de){
  199 + throw new MBeanException(new Exception(de.getMessage()));
  200 + }
165 201 }
166 202  
167 203 /**
... ...
parent/bom/pom.xml
... ... @@ -107,7 +107,7 @@
107 107 <dependency>
108 108 <groupId>br.gov.frameworkdemoiselle</groupId>
109 109 <artifactId>demoiselle-jmx</artifactId>
110   - <version>2.4.0-BETA2-SNAPSHOT</version>
  110 + <version>2.4.0-BETA4-SNAPSHOT</version>
111 111 </dependency>
112 112 <!--
113 113 <dependency>
... ...