/** * Validate if all required fields are present. * * @throws StorageException Thrown if the validation failed due to missing field values. */ @Validate public final void validateRequiredFields() throws StorageException { logger.log(Level.FINE, "Validating required fields"); try { Field[] elementFields = ReflectionUtil.getAllFieldsWithAnnotation(this.getClass(), Element.class); for (Field field : elementFields) { field.setAccessible(true); if (field.getAnnotation(Element.class).required() && field.get(this) == null) { logger.log(Level.WARNING, "Missing mandatory field {0}#{1}", new Object[] { this.getClass().getSimpleName(), field.getName() }); throw new StorageException("Missing mandatory field " + this.getClass().getSimpleName() + "#" + field.getName()); } } } catch (IllegalAccessException e) { throw new RuntimeException("IllegalAccessException when validating required fields: ", e); } }
private static TransferPluginOption getOptionFromField(Field field, Class<? extends TransferSettings> transferSettingsClass, int level) { Element elementAnnotation = field.getAnnotation(Element.class); Setup setupAnnotation = field.getAnnotation(Setup.class); boolean hasName = !elementAnnotation.name().equalsIgnoreCase(""); boolean hasDescription = setupAnnotation != null && !setupAnnotation.description().equals(""); boolean hasCallback = setupAnnotation != null && !setupAnnotation.callback().isInterface(); boolean hasConverter = setupAnnotation != null && !setupAnnotation.converter().isInterface(); boolean hasFileType = setupAnnotation != null && setupAnnotation.fileType() != null; String name = (hasName) ? elementAnnotation.name() : field.getName(); String description = (hasDescription) ? setupAnnotation.description() : field.getName(); FileType fileType = (hasFileType) ? setupAnnotation.fileType() : null; boolean required = elementAnnotation.required(); boolean sensitive = setupAnnotation != null && setupAnnotation.sensitive(); boolean singular = setupAnnotation != null && setupAnnotation.singular(); boolean visible = setupAnnotation != null && setupAnnotation.visible(); boolean encrypted = field.getAnnotation(Encrypted.class) != null; Class<? extends TransferPluginOptionCallback> callback = (hasCallback) ? setupAnnotation.callback() : null; Class<? extends TransferPluginOptionConverter> converter = (hasConverter) ? setupAnnotation.converter() : null; boolean isNestedOption = TransferSettings.class.isAssignableFrom(field.getType()); if (isNestedOption) { return createNestedOption(field, level, name, description, fileType, encrypted, sensitive, singular, visible, required, callback, converter); } else { return createNormalOption(field, transferSettingsClass, name, description, fileType, encrypted, sensitive, singular, visible, required, callback, converter); } }
/** * Constructor for the <code>ElementLabel</code> object. This is * used to create a label that can convert a XML node into a * composite object or a primitive type from an XML element. * * @param contact this is the field that this label represents * @param label this is the annotation for the contact * @param format this is the format used to style this element */ public ElementLabel(Contact contact, Element label, Format format) { this.detail = new Introspector(contact, this, format); this.decorator = new Qualifier(contact); this.required = label.required(); this.type = contact.getType(); this.override = label.name(); this.expect = label.type(); this.data = label.data(); this.format = format; this.label = label; }
/** * Constructor for the <code>ElementLabel</code> object. This is * used to create a label that can convert a XML node into a * composite object or a primitive type from an XML element. * * @param contact this is the field that this label represents * @param label this is the annotation for the contact * @param format this is the format used to style this element */ public ElementLabel(Contact contact, Element label, Format format) { this.detail = new Introspector(contact, this, format); this.decorator = new Qualifier(contact); this.required = label.required(); this.type = contact.getType(); this.override = label.name(); this.expect = label.type(); this.data = label.data(); this.format = format; this.label = label; }
/** * Constructor for the <code>ElementLabel</code> object. This is * used to create a label that can convert a XML node into a * composite object or a primitive type from an XML element. * * @param contact this is the field that this label represents * @param label this is the annotation for the contact * @param format this is the format used to style this element */ public ElementLabel(Contact contact, Element label, Format format) { this.detail = new Introspector(contact, this, format); this.decorator = new Qualifier(contact); this.required = label.required(); this.type = contact.getType(); this.override = label.name(); this.expect = label.type(); this.data = label.data(); this.format = format; this.label = label; }