184 * @param description A human readable description of the Notification. |
184 * @param description A human readable description of the Notification. |
185 * Optional. |
185 * Optional. |
186 * @param descriptor An instance of Descriptor containing the |
186 * @param descriptor An instance of Descriptor containing the |
187 * appropriate metadata for this instance of the |
187 * appropriate metadata for this instance of the |
188 * MBeanNotificationInfo. If it is null a default descriptor |
188 * MBeanNotificationInfo. If it is null a default descriptor |
189 * will be created. If the descriptor does not contain all the |
189 * will be created. If the descriptor does not contain the |
190 * fields "name", "descriptorType", "displayName" and "severity", |
190 * fields "displayName" or "severity", |
191 * the missing ones are added with their default values. |
191 * the missing ones are added with their default values. |
192 * |
192 * |
193 * @exception RuntimeOperationsException Wraps an |
193 * @exception RuntimeOperationsException Wraps an |
194 * {@link IllegalArgumentException}. The descriptor is invalid, or |
194 * {@link IllegalArgumentException}. The descriptor is invalid, or |
195 * descriptor field "name" is present but not equal to parameter name, or |
195 * descriptor field "name" is not equal to parameter name, or |
196 * descriptor field "descriptorType" is present but not equal to "notification". |
196 * descriptor field "descriptorType" is not equal to "notification". |
197 * |
197 * |
198 **/ |
198 **/ |
199 public ModelMBeanNotificationInfo(String[] notifTypes, |
199 public ModelMBeanNotificationInfo(String[] notifTypes, |
200 String name, |
200 String name, |
201 String description, |
201 String description, |
339 * empty Descriptor. |
339 * empty Descriptor. |
340 * @exception RuntimeOperationsException if Descriptor is invalid |
340 * @exception RuntimeOperationsException if Descriptor is invalid |
341 */ |
341 */ |
342 private Descriptor validDescriptor(final Descriptor in) throws RuntimeOperationsException { |
342 private Descriptor validDescriptor(final Descriptor in) throws RuntimeOperationsException { |
343 Descriptor clone; |
343 Descriptor clone; |
344 if (in == null) { |
344 boolean defaulted = (in == null); |
|
345 if (defaulted) { |
345 clone = new DescriptorSupport(); |
346 clone = new DescriptorSupport(); |
346 MODELMBEAN_LOGGER.finer("Null Descriptor, creating new."); |
347 MODELMBEAN_LOGGER.finer("Null Descriptor, creating new."); |
347 } else { |
348 } else { |
348 clone = (Descriptor) in.clone(); |
349 clone = (Descriptor) in.clone(); |
349 } |
350 } |
350 |
351 |
351 //Setting defaults. |
352 //Setting defaults. |
352 if (clone.getFieldValue("name")==null) { |
353 if (defaulted && clone.getFieldValue("name")==null) { |
353 clone.setField("name", this.getName()); |
354 clone.setField("name", this.getName()); |
354 MODELMBEAN_LOGGER.finer("Defaulting Descriptor name to " + this.getName()); |
355 MODELMBEAN_LOGGER.finer("Defaulting Descriptor name to " + this.getName()); |
355 } |
356 } |
356 if (clone.getFieldValue("descriptorType")==null) { |
357 if (defaulted && clone.getFieldValue("descriptorType")==null) { |
357 clone.setField("descriptorType", "notification"); |
358 clone.setField("descriptorType", "notification"); |
358 MODELMBEAN_LOGGER.finer("Defaulting descriptorType to \"notification\""); |
359 MODELMBEAN_LOGGER.finer("Defaulting descriptorType to \"notification\""); |
359 } |
360 } |
360 if (clone.getFieldValue("displayName") == null) { |
361 if (clone.getFieldValue("displayName") == null) { |
361 clone.setField("displayName",this.getName()); |
362 clone.setField("displayName",this.getName()); |
370 if (!clone.isValid()) { |
371 if (!clone.isValid()) { |
371 throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"), |
372 throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"), |
372 "The isValid() method of the Descriptor object itself returned false,"+ |
373 "The isValid() method of the Descriptor object itself returned false,"+ |
373 "one or more required fields are invalid. Descriptor:" + clone.toString()); |
374 "one or more required fields are invalid. Descriptor:" + clone.toString()); |
374 } |
375 } |
375 if (! ((String)clone.getFieldValue("name")).equalsIgnoreCase(this.getName())) { |
376 if (!getName().equalsIgnoreCase((String) clone.getFieldValue("name"))) { |
376 throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"), |
377 throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"), |
377 "The Descriptor \"name\" field does not match the object described. " + |
378 "The Descriptor \"name\" field does not match the object described. " + |
378 " Expected: "+ this.getName() + " , was: " + clone.getFieldValue("name")); |
379 " Expected: "+ this.getName() + " , was: " + clone.getFieldValue("name")); |
379 } |
380 } |
380 if (! ((String)clone.getFieldValue("descriptorType")).equalsIgnoreCase("notification")) { |
381 if (!"notification".equalsIgnoreCase((String) clone.getFieldValue("descriptorType"))) { |
381 throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"), |
382 throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"), |
382 "The Descriptor \"descriptorType\" field does not match the object described. " + |
383 "The Descriptor \"descriptorType\" field does not match the object described. " + |
383 " Expected: \"notification\" ," + " was: " + clone.getFieldValue("descriptorType")); |
384 " Expected: \"notification\" ," + " was: " + clone.getFieldValue("descriptorType")); |
384 } |
385 } |
385 |
386 |