本文整理了Java中org.simpleframework.xml.Element.required()
方法的一些代码示例,展示了Element.required()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element.required()
方法的具体详情如下:
包路径:org.simpleframework.xml.Element
类名称:Element
方法名:required
暂无
代码示例来源:origin: syncany/syncany
/**
* 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);
}
}
代码示例来源:origin: syncany/syncany
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);
}
}
代码示例来源:origin: org.simpleframework/simple-xml
/**
* 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;
}
代码示例来源:origin: org.restlet.lib/org.simpleframework.simple-xml
/**
* 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;
}
代码示例来源:origin: ngallagher/simplexml
/**
* 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;
}
内容来源于网络,如有侵权,请联系作者删除!