本文整理汇总了Java中com.haulmont.chile.core.annotations.NamePattern类的典型用法代码示例。如果您正苦于以下问题:Java NamePattern类的具体用法?Java NamePattern怎么用?Java NamePattern使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NamePattern类属于com.haulmont.chile.core.annotations包,在下文中一共展示了NamePattern类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseNamePattern
import com.haulmont.chile.core.annotations.NamePattern; //导入依赖的package包/类
/**
* Parse a name pattern defined by {@link NamePattern} annotation.
* @param metaClass entity meta-class
* @return record containing the name pattern properties, or null if the @NamePattern is not defined for the meta-class
*/
@Nullable
public static NamePatternRec parseNamePattern(MetaClass metaClass) {
Map attributes = (Map) metaClass.getAnnotations().get(NamePattern.class.getName());
if (attributes == null)
return null;
String pattern = (String) attributes.get("value");
if (StringUtils.isBlank(pattern))
return null;
int pos = pattern.indexOf("|");
if (pos < 0)
throw new DevelopmentException("Invalid name pattern: " + pattern);
String format = StringUtils.substring(pattern, 0, pos);
String trimmedFormat = format.trim();
String methodName = trimmedFormat.startsWith("#") ? trimmedFormat.substring(1) : null;
String fieldsStr = StringUtils.substring(pattern, pos + 1);
String[] fields = INSTANCE_NAME_SPLIT_PATTERN.split(fieldsStr);
return new NamePatternRec(format, methodName, fields);
}
示例2: getNamePatternProperties
import com.haulmont.chile.core.annotations.NamePattern; //导入依赖的package包/类
/**
* Return a collection of properties included into entity's name pattern (see {@link NamePattern}).
*
* @param metaClass entity metaclass
* @param useOriginal if true, and if the given metaclass doesn't define a {@link NamePattern} and if it is an
* extended entity, this method tries to find a name pattern in an original entity
* @return collection of the name pattern properties
*/
@Nonnull
public Collection<MetaProperty> getNamePatternProperties(MetaClass metaClass, boolean useOriginal) {
Collection<MetaProperty> properties = new ArrayList<>();
String pattern = (String) getMetaAnnotationAttributes(metaClass.getAnnotations(), NamePattern.class).get("value");
if (pattern == null && useOriginal) {
MetaClass original = metadata.getExtendedEntities().getOriginalMetaClass(metaClass);
if (original != null) {
pattern = (String) getMetaAnnotationAttributes(original.getAnnotations(), NamePattern.class).get("value");
}
}
if (!StringUtils.isBlank(pattern)) {
String value = StringUtils.substringAfter(pattern, "|");
String[] fields = StringUtils.splitPreserveAllTokens(value, ",");
for (String field : fields) {
String fieldName = StringUtils.trim(field);
MetaProperty property = metaClass.getProperty(fieldName);
if (property != null) {
properties.add(metaClass.getProperty(fieldName));
} else {
throw new DevelopmentException(
String.format("Property '%s' is not found in %s", field, metaClass.toString()),
"NamePattern", pattern);
}
}
}
return properties;
}