ofbiz 之服务 实体api 积累

1:根据delegator 获取 LocalDispatcher

LocalDispatcher thisDispatcher = GenericDispatcher.getLocalDispatcher(delegator.getDelegatorName(), delegator);

 

2:根据dispatcher 获取 DispatcherContext

DispatchContext dctx =
dispatcher.getDispatchContext();

 

3:获取一个GenericValue对象的所有字段

GenericDelegator delegator = DelegatorFactory.getDelegator("default");
GenericValue tmp = delegator.makeValue("UserLogin");
String entityName = tmp.getEntityName();
ModelEntity entity = delegator.getModelEntity(entityName);
List fieldNameList = entity.getAllFieldNames();

 

4:----

ServiceDispatcher sd = ServiceDispatcher.getInstance(dispatcherName, delegator);

LocalDispatcher dispatcher = sd.getLocalDispatcher(dispatcherName);

dispatcher = new GenericDispatcher(dispatcherName, delegator, readerURLs, loader, sd);

DispatchContext dc = new DispatchContext(name, readerURLs, loader, null);

5:ofbiz URL

URL formFileUrl = FlexibleLocation.resolveLocation(resourceName);

resourceName:component://common/widget/LookupForms.xml

formFileUrl:file:/E:/workspace/cpsp20110819/framework/common/widget/LookupForms.xml

 

 

for (File screenFile: screenFiles) {
String screenFilePath = screenFile.getAbsolutePath();
screenFilePath = screenFilePath.replace('\\', '/');
String screenFileRelativePath = screenFilePath.substring(rootComponentPath.length());
String screenLocation = "component://" + componentName + "/" + screenFileRelativePath;

 

 

Set<String> groupNames = getModelGroupReader().getGroupNames(delegatorBaseName);
for (String groupName: groupNames) {
GenericHelperInfo helperInfo = this.getGroupHelperInfo(groupName);
String helperBaseName = helperInfo.getHelperBaseName();

if (Debug.infoOn()) Debug.logInfo("Delegator \"" + delegatorFullName + "\" initializing helper \"" +
helperBaseName + "\" for entity group \"" + groupName + "\".", module);
if (UtilValidate.isNotEmpty(helperInfo.getHelperFullName())) {
// pre-load field type defs, the return value is ignored
ModelFieldTypeReader.getModelFieldTypeReader(helperBaseName);
// get the helper and if configured, do the datasource check
GenericHelper helper = GenericHelperFactory.getHelper(helperInfo);

DatasourceInfo datasourceInfo = EntityConfigUtil.getDatasourceInfo(helperBaseName);
if (datasourceInfo.checkOnStart) {
if (Debug.infoOn()) Debug.logInfo("Doing database check as requested in entityengine.xml with addMissing=" + datasourceInfo.addMissingOnStart, module);
try {
helper.checkDataSource(this.getModelEntityMapByGroup(groupName), null, datasourceInfo.addMissingOnStart);
} catch (GenericEntityException e) {
Debug.logWarning(e, e.getMessage(), module);
}
}
}
}

6: 获取所有实体名称

Set<String> entitys = delegator.getModelReader().getEntityNames();
entityArr = delegator.getModelReader().getEntityNames().toArray(new String[entitys.size()]);

7:清除实体缓存

Cache entityCache = delegator.getCache();

entityCache.remove(entityName);

 

8 : xml 中取${}值

FlexibleStringExpander fse = FlexibleStringExpander.getInstance(expression);
return fse.expandString(context, timeZone, locale);

 

9: xml 获取多个 不同节点

Set<String> nameSet = UtilMisc.toSet("set", "action","log");
for (Element actionOrSetElementOrLog : UtilXml.childElementList(eca, nameSet)) {

 

10 : String 类型xml 与 Map 互相转换

XmlSerializer.deserialize

XmlSerializer.serialize

11:类型转化类的加载

Iterator<ConverterLoader> converterLoaders = ServiceLoader.load(ConverterLoader.class, loader).iterator();

 

 

Collections.unmodifiableList

getStrElems

 

 

12: private void initEngines(final ClassLoader loader) {
Iterator itr = null;
try {
if (loader != null) {
itr = Service.providers(ScriptEngineFactory.class, loader);
} else {
itr = Service.installedProviders(ScriptEngineFactory.class);
}
}

 

13: Map<String, ConditionalFactory<?>> factories = new HashMap<String, ConditionalFactory<?>>();
Iterator<ConditionalFactory<?>> it = UtilGenerics.cast(ServiceLoader.load(ConditionalFactory.class, ConditionalFactory.class.getClassLoader()).iterator());
while (it.hasNext()) {
ConditionalFactory<?> factory = it.next();
factories.put(factory.getName(), factory);
}
conditionalFactories = Collections.unmodifiableMap(factories);

你可能感兴趣的:(ofbiz)