use of org.openmrs.customdatatype.CustomDatatype in project openmrs-core by openmrs.
the class DatatypeServiceTest method getHandler_shouldReturnAHandlerForTheSpecifiedDatatype.
/**
* @see DatatypeService#getHandler(CustomDatatype,String)
*/
@Test
public void getHandler_shouldReturnAHandlerForTheSpecifiedDatatype() {
DatatypeService service = Context.getDatatypeService();
CustomDatatype dateDatatype = CustomDatatypeUtil.getDatatype(DateDatatype.class.getName(), null);
Assert.assertEquals(DateDatatypeHandler.class, service.getHandler(dateDatatype, null).getClass());
}
use of org.openmrs.customdatatype.CustomDatatype in project openmrs-core by openmrs.
the class ModuleFileParser method createGlobalPropertyWithDatatype.
private GlobalProperty createGlobalPropertyWithDatatype(String property, String defaultValue, String description, String datatypeClassname, String datatypeConfig) {
GlobalProperty globalProperty = null;
try {
Class<CustomDatatype<?>> datatypeClazz = (Class<CustomDatatype<?>>) Class.forName(datatypeClassname).asSubclass(CustomDatatype.class);
globalProperty = new GlobalProperty(property, defaultValue, description, datatypeClazz, datatypeConfig);
} catch (ClassCastException ex) {
log.error("The class specified by 'datatypeClassname' (" + datatypeClassname + ") must be a subtype of 'org.openmrs.customdatatype.CustomDatatype<?>'.", ex);
} catch (ClassNotFoundException ex) {
log.error("The class specified by 'datatypeClassname' (" + datatypeClassname + ") could not be found.", ex);
}
return globalProperty;
}
use of org.openmrs.customdatatype.CustomDatatype in project openmrs-core by openmrs.
the class DatatypeServiceImpl method datatypeClassHandled.
/**
* @param t
* @return the generic type of t or an interface it implements that is a CustomDatatype
*/
private Class datatypeClassHandled(Type t) {
if (t instanceof ParameterizedType) {
ParameterizedType pt = (ParameterizedType) t;
Type first = pt.getActualTypeArguments()[0];
if (first instanceof Class && CustomDatatype.class.isAssignableFrom((Class) first)) {
return (Class) first;
} else {
return datatypeClassHandled(pt.getRawType());
}
} else if (t instanceof Class) {
Type genericSuperclass = ((Class) t).getGenericSuperclass();
if (genericSuperclass != null) {
Class ret = datatypeClassHandled(genericSuperclass);
if (ret != null) {
return ret;
}
}
for (Type candidate : ((Class) t).getGenericInterfaces()) {
Class ret = datatypeClassHandled(candidate);
if (ret != null) {
return ret;
}
}
}
return null;
}
use of org.openmrs.customdatatype.CustomDatatype in project openmrs-core by openmrs.
the class DatatypeServiceTest method getHandler_shouldReturnAHandlerForADatatypeThatExtendsAGenericSuperclass.
/**
* @see DatatypeService#getHandler(CustomDatatype,String)
*/
@Test
public void getHandler_shouldReturnAHandlerForADatatypeThatExtendsAGenericSuperclass() {
DatatypeService service = Context.getDatatypeService();
CustomDatatype locationDatatype = CustomDatatypeUtil.getDatatype(LocationDatatype.class.getName(), null);
Assert.assertEquals(LocationDatatypeHandler.class, service.getHandler(locationDatatype, null).getClass());
}
Aggregations