Perhaps now is a good time to create a Jira issue. The implementation
details can be discussed there, POC code can be submitted as patches, etc.
https://cwiki.apache.org/confluence/display/OFBADMIN/OFBiz+Contributors+Best+Practices
-Adrian
On 4/2/2011 11:25 PM, Paul Ray wrote:
Would be more than happy to contribute if relevant. Thanks for the offer!
Let me summarize again what we are looking to achieve and how I am
planning to go about doing it.
UtilProperties being in base gets complied and loaded first ahead of
both entity and service modules. So, as such the service and entity
classes won't be available there directly. Now the attempt is to have
a call embedded service call within the
UtilProperties.getBundle(.....) method right after the lines below
Properties newProps = getProperties(resource, candidateLocale);
if (UtilValidate.isNotEmpty(newProps)) {
// The last bundle we found becomes
the parent of the new bundle
The idea is that by default a set of properties would be loaded from
the UiLabels.xml files. However, right after we should be able to
call a service to override any labels (in newProps) passing the
newProps as an argument.
So far, so good ?
Next the problem... How to configure a service call? Find the below
usage in base module
ClassLoader loader = Thread.currentThread().getContextClassLoader();
Iterator<Init> cachedClassLoaders =
ServiceLoader.load(Init.class, loader).iterator();
while (cachedClassLoaders.hasNext()) {
Init cachedClassLoader = cachedClassLoaders.next();
try {
cachedClassLoader.loadClasses(loader);
} catch (Exception e) {
Debug.logError(e, "Could not pre-initialize
dynamically loaded class: ", module);
}
}
So, can we write a class say UtilTenantProperties under webtools and
load that dynamically? This class can then be used to load the
appropriate delegator to query properties to override and return an
updated newProps and rest continues as before? The reason thinking of
webtools is to eventually use the webtools label manager to manage and
update the override fields into the database.
If this approach looks reasonable, I will give it a shot. I am still
unclear how the delegator behaves in a multitenant scenario but hoping
the first iteration can avoid that complexity. Welcome hints and
suggestions.
-PR
If it's something you intend to contribute to the project, then it
would be best if the current artifacts are left where they are and
then come up with some kind of configurable properties loader.
Something along the lines of using the ServiceLoader class to locate
classes that implement code to create/update Properties objects. The
UtilProperties.getProperties(String resource, Locale locale) method
could then delegate to those classes.
-Adrian
On 4/2/2011 7:20 PM, Paul Ray wrote:
Thanks Adrian. Tried adding org.ofbiz.entity.DelegatorFactory under
META-INF/services in base but still get the ClassNotFoundException
for DelegatorFactory. Reckon it is still something to do with the
classpath.
As an alternative explored if I could move the UtilProperties
relevant methods under entity module. Still working on it but wanted
to check if this is right approach. To be specific looking to move
public static ResourceBundleMapWrapper getResourceBundleMap(String
resource, Locale locale, Map<String, Object> context)
under a new Utility Class within entity module.
PR
The factory code uses the Java ServiceLoader class, so you will need
to create a service properties file for it to load. Look in the
META-INF folder of the entity component.
-Adrian
On 4/1/2011 5:03 PM, Paul Ray wrote:
Hello Ofbiz user community,
I am trying to avoid file base properties files and uilabels and
rather load them from Database. Reason, support configuration
without touching the code and eventually multi-tenant. As part of
the attempt, trying to load a few properties entries from DB in
org.ofbiz.base.util.UtilProperties class. The trouble is delegator
is not available here. As work around initialized for "default"
using DelegatorFactory after adding entity module classes in the
build path. The build goes through , however, at runtime get
classnotfound exception for Delegator Factory. Not sure if this is a
classloader issue since adding the entity/lib directly to the
classpath didn't help either. What am I missing?
Also alternatively is there a better way to query DB (need to be
multi-tenent aware since eventually all property file entries would
need to move there) as part of base module?
Thanks
PR