use of org.apache.ofbiz.entity.GenericEntityConfException in project ofbiz-framework by apache.
the class EntityDataLoader method getUrlList.
public static <E> List<URL> getUrlList(String helperName, String componentName, List<E> readerNames) {
String paths = getPathsString(helperName);
List<URL> urlList = new LinkedList<URL>();
// first get files from resources
if (readerNames != null) {
for (Object readerInfo : readerNames) {
String readerName = null;
if (readerInfo instanceof String) {
readerName = (String) readerInfo;
} else if (readerInfo instanceof ReadData) {
readerName = ((ReadData) readerInfo).getReaderName();
} else if (readerInfo instanceof Element) {
readerName = ((Element) readerInfo).getAttribute("reader-name");
} else {
throw new IllegalArgumentException("Reader name list does not contain String(s) or Element(s)");
}
readerName = readerName.trim();
// ignore the "tenant" reader if multitenant is disabled
if ("tenant".equals(readerName) && !EntityUtil.isMultiTenantEnabled()) {
continue;
}
// get all of the main resource model stuff, ie specified in the entityengine.xml file
EntityDataReader entityDataReaderInfo = null;
try {
entityDataReaderInfo = EntityConfig.getInstance().getEntityDataReader(readerName);
if (entityDataReaderInfo == null) {
// create a reader name defined at runtime
Debug.logInfo("Could not find entity-data-reader named: " + readerName + ". Creating a new reader with this name. ", module);
entityDataReaderInfo = new EntityDataReader(readerName);
}
} catch (GenericEntityConfException e) {
Debug.logWarning(e, "Exception thrown while getting entity data reader config: ", module);
}
if (entityDataReaderInfo != null) {
for (Resource resourceElement : entityDataReaderInfo.getResourceList()) {
ResourceHandler handler = new MainResourceHandler(EntityConfig.ENTITY_ENGINE_XML_FILENAME, resourceElement.getLoader(), resourceElement.getLocation());
try {
urlList.add(handler.getURL());
} catch (GenericConfigException e) {
String errorMsg = "Could not get URL for Main ResourceHandler: " + e.toString();
Debug.logWarning(errorMsg, module);
}
}
// get all of the component resource model stuff, ie specified in each ofbiz-component.xml file
for (ComponentConfig.EntityResourceInfo componentResourceInfo : ComponentConfig.getAllEntityResourceInfos("data", componentName)) {
if (readerName.equals(componentResourceInfo.readerName)) {
ResourceHandler handler = componentResourceInfo.createResourceHandler();
try {
urlList.add(handler.getURL());
} catch (GenericConfigException e) {
String errorMsg = "Could not get URL for Component ResourceHandler: " + e.toString();
Debug.logWarning(errorMsg, module);
}
}
}
} else {
String errorMsg = "Could not find entity-data-reader named: " + readerName;
Debug.logWarning(errorMsg, module);
}
}
} else {
String errorMsg = "Could not find datasource named: " + helperName;
Debug.logWarning(errorMsg, module);
}
// get files from the paths string
if (UtilValidate.isNotEmpty(paths)) {
StringTokenizer tokenizer = new StringTokenizer(paths, ";");
while (tokenizer.hasMoreTokens()) {
String path = tokenizer.nextToken().toLowerCase(Locale.getDefault());
File loadDir = new File(path);
if (loadDir.exists() && loadDir.isDirectory()) {
File[] files = loadDir.listFiles();
List<File> tempFileList = new LinkedList<File>();
if (files != null) {
for (File file : files) {
if (file.getName().toLowerCase(Locale.getDefault()).endsWith(".xml")) {
tempFileList.add(file);
}
}
}
Collections.sort(tempFileList);
for (File dataFile : tempFileList) {
if (dataFile.exists()) {
URL url = null;
try {
url = dataFile.toURI().toURL();
urlList.add(url);
} catch (java.net.MalformedURLException e) {
String xmlError = "Error loading XML file \"" + dataFile.getAbsolutePath() + "\"; Error was: " + e.getMessage();
Debug.logError(xmlError, module);
}
} else {
String errorMsg = "Could not find file: \"" + dataFile.getAbsolutePath() + "\"";
Debug.logError(errorMsg, module);
}
}
}
}
}
return urlList;
}
use of org.apache.ofbiz.entity.GenericEntityConfException in project ofbiz-framework by apache.
the class ModelGroupReader method getModelGroupReader.
public static ModelGroupReader getModelGroupReader(String delegatorName) throws GenericEntityConfException {
DelegatorElement delegatorInfo = EntityConfig.getInstance().getDelegator(delegatorName);
if (delegatorInfo == null) {
throw new GenericEntityConfException("Could not find a delegator with the name " + delegatorName);
}
String tempModelName = delegatorInfo.getEntityGroupReader();
ModelGroupReader reader = readers.get(tempModelName);
if (reader == null) {
reader = readers.putIfAbsentAndGet(tempModelName, new ModelGroupReader(delegatorName, tempModelName));
}
return reader;
}
use of org.apache.ofbiz.entity.GenericEntityConfException in project ofbiz-framework by apache.
the class ModelReader method getModelReader.
public static ModelReader getModelReader(String delegatorName) throws GenericEntityException {
DelegatorElement delegatorInfo = EntityConfig.getInstance().getDelegator(delegatorName);
if (delegatorInfo == null) {
throw new GenericEntityConfException("Could not find a delegator with the name " + delegatorName);
}
String tempModelName = delegatorInfo.getEntityModelReader();
ModelReader reader = readers.get(tempModelName);
if (reader == null) {
reader = new ModelReader(tempModelName);
// preload caches...
reader.getEntityCache();
reader = readers.putIfAbsentAndGet(tempModelName, reader);
}
return reader;
}
use of org.apache.ofbiz.entity.GenericEntityConfException 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;
}
use of org.apache.ofbiz.entity.GenericEntityConfException in project ofbiz-framework by apache.
the class ModelGroupReader method getEntityGroupName.
/**
* Gets a group name based on a definition from the specified XML Entity Group descriptor file.
* @param entityName The entityName of the Entity Group definition to use.
* @return A group name
*/
public String getEntityGroupName(String entityName, String delegatorBaseName) {
Map<String, String> gc = getGroupCache(delegatorBaseName);
if (gc != null) {
String groupName = gc.get(entityName);
if (groupName == null) {
DelegatorElement delegatorInfo = null;
try {
delegatorInfo = EntityConfig.getInstance().getDelegator(delegatorBaseName);
} catch (GenericEntityConfException e) {
Debug.logWarning(e, "Exception thrown while getting delegator config: ", module);
}
if (delegatorInfo == null) {
throw new RuntimeException("Could not find DelegatorInfo for delegatorBaseName [" + delegatorBaseName + "]");
}
groupName = delegatorInfo.getDefaultGroupName();
}
return groupName;
} else {
return null;
}
}
Aggregations