use of java.beans.BeanInfo in project coprhd-controller by CoprHD.
the class DbClientGeoVersionTest method setup.
@Before
public void setup() {
try {
BeanInfo beanInfo = Introspector.getBeanInfo(DummyGeoObject.class);
PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors();
for (PropertyDescriptor pd : pds) {
if (pd.getDisplayName().equals("dummyField1")) {
this.dummyPd1 = pd;
}
if (pd.getDisplayName().equals("dummyField2")) {
this.dummyPd2 = pd;
}
}
maxVersionMethod = DbClientImpl.class.getDeclaredMethod("getMaxGeoAllowedVersion", Class.class, PropertyDescriptor.class);
this.maxVersionMethod.setAccessible(true);
hasGeoVersionMethod = DbClientImpl.class.getDeclaredMethod("hasGeoVersionAnnotation", Class.class, PropertyDescriptor.class);
this.hasGeoVersionMethod.setAccessible(true);
client1 = new DbClientImpl();
client2 = new DbClientImpl();
} catch (Exception e) {
loger.error("setup failed ", e);
}
}
use of java.beans.BeanInfo in project coprhd-controller by CoprHD.
the class DataObjectType method init.
/**
* Initializes cf & all column metadata for this data type
*/
private void init() {
String cfName = _clazz.getAnnotation(Cf.class).value();
_cf = new ColumnFamily<String, CompositeColumnName>(cfName, StringSerializer.get(), CompositeColumnNameSerializer.get());
BeanInfo bInfo;
try {
bInfo = Introspector.getBeanInfo(_clazz);
} catch (IntrospectionException ex) {
throw DatabaseException.fatals.serializationFailedInitializingBeanInfo(_clazz, ex);
}
PropertyDescriptor[] pds = bInfo.getPropertyDescriptors();
for (int i = 0; i < pds.length; i++) {
PropertyDescriptor pd = pds[i];
// skip class property
if (!isColumnField(bInfo.getBeanDescriptor().getBeanClass().getName(), pd)) {
_log.info("Not column field, skip {}.{}", bInfo.getBeanDescriptor().getBeanClass().getName(), pd.getName());
continue;
}
ColumnField col = new ColumnField(this, pd);
if (col.getType() == ColumnField.ColumnType.Id) {
_idField = col;
continue;
}
_columnFieldMap.put(col.getName(), col);
if (col.isLazyLoaded()) {
_lazyLoadedFields.add(col);
}
}
// Need to resolve field cross references here....
Collection<ColumnField> fields = _columnFieldMap.values();
for (ColumnField field : fields) {
DbIndex index = field.getIndex();
if (index instanceof AggregateDbIndex) {
String[] groupByArr = ((AggregateDbIndex) index).getGroupBy();
for (String groupByName : groupByArr) {
ColumnField groupField = _columnFieldMap.get(groupByName);
// The index for this field will be cleared together with the index of the referenced field
if (groupField == null || groupField.getIndex() == null) {
DatabaseException.fatals.invalidAnnotation("AggregateIndex", "property " + groupByName + " does not have a valid value or referenced another indexed field");
}
((AggregateDbIndex) index).addGroupByField(_columnFieldMap.get(groupByName));
if (groupField != null && groupField.getDependentFields() != null) {
groupField.getDependentFields().add(field);
}
field.getRefFields().add(groupField);
}
if (!field.getRefFields().isEmpty()) {
_preprocessedFields.add(field);
}
}
}
// initialization for lazy loading
lazyLoadInit();
}
use of java.beans.BeanInfo in project coprhd-controller by CoprHD.
the class PropertyListDataObjectMapper method map.
public static <T> PropertyListDataObject map(T from, String type) {
if (from == null) {
return null;
}
PropertyListDataObject to = new PropertyListDataObject();
to.setResourceType(type);
try {
BeanInfo bInfo = Introspector.getBeanInfo(from.getClass());
PropertyDescriptor[] pds = bInfo.getPropertyDescriptors();
for (int i = 0; i < pds.length; i++) {
PropertyDescriptor pd = pds[i];
// skip class property
String pdName = pd.getName();
if (pd.getName().equals("class")) {
continue;
}
if (pdName.equals("Id")) {
if (URI.class.isAssignableFrom(pd.getPropertyType())) {
URI value = (URI) pd.getReadMethod().invoke(from);
to.setId(value);
}
}
if (pdName.equals("creationTime")) {
if (Calendar.class.isAssignableFrom(pd.getPropertyType())) {
Calendar value = (Calendar) pd.getReadMethod().invoke(from);
to.setCreationTime(value);
}
} else {
Object value = pd.getReadMethod().invoke(from);
to.getResourceData().put(pdName, value.toString());
}
}
return to;
} catch (Exception ex) {
throw DatabaseException.fatals.deserializationFailed(from.getClass(), ex);
}
}
use of java.beans.BeanInfo in project entando-core by entando.
the class AbstractObjectInfoTag method getPropertyValue.
protected Object getPropertyValue(Object masterObject, String propertyValue) {
try {
BeanInfo beanInfo = Introspector.getBeanInfo(masterObject.getClass());
PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors();
for (int i = 0; i < descriptors.length; i++) {
PropertyDescriptor descriptor = descriptors[i];
if (!descriptor.getName().equals(propertyValue)) {
continue;
}
Method method = descriptor.getReadMethod();
Object[] args = null;
return method.invoke(masterObject, args);
}
_logger.debug("Invalid required object property : Master Object '{}' - property '{}'", masterObject.getClass().getName(), propertyValue);
} catch (Throwable t) {
_logger.error("Error extracting property value : Master Object {} - property: '{}'", masterObject.getClass().getName(), propertyValue, t);
}
return null;
}
use of java.beans.BeanInfo in project coprhd-controller by CoprHD.
the class BeanTestUtils method testGettersAndSetters.
public static void testGettersAndSetters(Object bean) {
Assert.assertNotNull(bean);
try {
BeanInfo beanInfo = Introspector.getBeanInfo(bean.getClass());
PropertyDescriptor[] properties = beanInfo.getPropertyDescriptors();
Assert.assertNotNull("No properties for " + bean.getClass(), properties);
for (PropertyDescriptor property : properties) {
Class<?> type = property.getPropertyType();
if (isSupportedType(type)) {
boolean canRead = property.getReadMethod() != null;
boolean canWrite = property.getWriteMethod() != null;
if (canRead && canWrite) {
testGetterAndSetter(bean, property.getName(), type);
}
}
}
} catch (IntrospectionException e) {
throw new RuntimeException(e);
}
}
Aggregations