use of org.apache.ofbiz.entity.config.model.FieldType in project ofbiz-framework by apache.
the class ModelFieldTypeReader method getModelFieldTypeReader.
public static ModelFieldTypeReader getModelFieldTypeReader(String helperName) {
Datasource datasourceInfo = EntityConfig.getDatasource(helperName);
if (datasourceInfo == null) {
throw new IllegalArgumentException("Could not find a datasource/helper with the name " + helperName);
}
String tempModelName = datasourceInfo.getFieldTypeName();
ModelFieldTypeReader reader = readers.get(tempModelName);
while (reader == null) {
FieldType fieldTypeInfo = null;
try {
fieldTypeInfo = EntityConfig.getInstance().getFieldType(tempModelName);
} catch (GenericEntityConfException e) {
Debug.logWarning(e, "Exception thrown while getting field type config: ", module);
}
if (fieldTypeInfo == null) {
throw new IllegalArgumentException("Could not find a field-type definition with name \"" + tempModelName + "\"");
}
ResourceHandler fieldTypeResourceHandler = new MainResourceHandler(EntityConfig.ENTITY_ENGINE_XML_FILENAME, fieldTypeInfo.getLoader(), fieldTypeInfo.getLocation());
UtilTimer utilTimer = new UtilTimer();
utilTimer.timerString("[ModelFieldTypeReader.getModelFieldTypeReader] Reading field types from " + fieldTypeResourceHandler.getLocation());
Document document = null;
try {
document = fieldTypeResourceHandler.getDocument();
} catch (GenericConfigException e) {
Debug.logError(e, module);
throw new IllegalStateException("Error loading field type file " + fieldTypeResourceHandler.getLocation());
}
Map<String, ModelFieldType> fieldTypeMap = createFieldTypeCache(document.getDocumentElement(), fieldTypeResourceHandler.getLocation());
reader = readers.putIfAbsentAndGet(tempModelName, new ModelFieldTypeReader(fieldTypeMap));
utilTimer.timerString("[ModelFieldTypeReader.getModelFieldTypeReader] Read " + fieldTypeMap.size() + " field types");
}
return reader;
}
Aggregations