Removed unnecessary synchronized blocks; made UtilCache objects private and final.
git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@1352592 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -47,8 +47,8 @@ import org.xml.sax.SAXException;
|
||||
public class FormFactory {
|
||||
|
||||
public static final String module = FormFactory.class.getName();
|
||||
public static final UtilCache<String, ModelForm> formLocationCache = UtilCache.createUtilCache("widget.form.locationResource", 0, 0, false);
|
||||
public static final UtilCache<String, ModelForm> formWebappCache = UtilCache.createUtilCache("widget.form.webappResource", 0, 0, false);
|
||||
private static final UtilCache<String, ModelForm> formLocationCache = UtilCache.createUtilCache("widget.form.locationResource", 0, 0, false);
|
||||
private static final UtilCache<String, ModelForm> formWebappCache = UtilCache.createUtilCache("widget.form.webappResource", 0, 0, false);
|
||||
|
||||
public static Map<String, ModelForm> getFormsFromLocation(String resourceName, ModelReader entityModelReader, DispatchContext dispatchContext)
|
||||
throws IOException, SAXException, ParserConfigurationException {
|
||||
@@ -68,24 +68,19 @@ public class FormFactory {
|
||||
String cacheKey = resourceName + "#" + formName;
|
||||
ModelForm modelForm = formLocationCache.get(cacheKey);
|
||||
if (modelForm == null) {
|
||||
synchronized (formLocationCache) {
|
||||
modelForm = formLocationCache.get(cacheKey);
|
||||
if (modelForm == null) {
|
||||
/*
|
||||
ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
||||
if (loader == null) {
|
||||
loader = FormFactory.class.getClassLoader();
|
||||
}
|
||||
*/
|
||||
URL formFileUrl = FlexibleLocation.resolveLocation(resourceName); //, loader);
|
||||
Document formFileDoc = UtilXml.readXmlDocument(formFileUrl, true, true);
|
||||
if (formFileDoc == null) {
|
||||
throw new IllegalArgumentException("Could not find resource [" + resourceName + "]");
|
||||
}
|
||||
modelForm = createModelForm(formFileDoc, entityModelReader, dispatchContext, resourceName, formName);
|
||||
formLocationCache.put(cacheKey, modelForm);
|
||||
}
|
||||
/*
|
||||
ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
||||
if (loader == null) {
|
||||
loader = FormFactory.class.getClassLoader();
|
||||
}
|
||||
*/
|
||||
URL formFileUrl = FlexibleLocation.resolveLocation(resourceName); //, loader);
|
||||
Document formFileDoc = UtilXml.readXmlDocument(formFileUrl, true, true);
|
||||
if (formFileDoc == null) {
|
||||
throw new IllegalArgumentException("Could not find resource [" + resourceName + "]");
|
||||
}
|
||||
modelForm = createModelForm(formFileDoc, entityModelReader, dispatchContext, resourceName, formName);
|
||||
modelForm = formLocationCache.putIfAbsentAndGet(cacheKey, modelForm);
|
||||
}
|
||||
if (modelForm == null) {
|
||||
throw new IllegalArgumentException("Could not find form with name [" + formName + "] in class resource [" + resourceName + "]");
|
||||
@@ -99,20 +94,15 @@ public class FormFactory {
|
||||
String cacheKey = webappName + "::" + resourceName + "::" + formName;
|
||||
ModelForm modelForm = formWebappCache.get(cacheKey);
|
||||
if (modelForm == null) {
|
||||
synchronized (formWebappCache) {
|
||||
modelForm = formWebappCache.get(cacheKey);
|
||||
if (modelForm == null) {
|
||||
ServletContext servletContext = (ServletContext) request.getAttribute("servletContext");
|
||||
Delegator delegator = (Delegator) request.getAttribute("delegator");
|
||||
LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
|
||||
URL formFileUrl = servletContext.getResource(resourceName);
|
||||
Document formFileDoc = UtilXml.readXmlDocument(formFileUrl, true, true);
|
||||
Element formElement = UtilXml.firstChildElement(formFileDoc.getDocumentElement(), "form", "name", formName);
|
||||
modelForm = new ModelForm(formElement, delegator.getModelReader(), dispatcher.getDispatchContext());
|
||||
modelForm.setFormLocation(resourceName);
|
||||
formWebappCache.put(cacheKey, modelForm);
|
||||
}
|
||||
}
|
||||
ServletContext servletContext = (ServletContext) request.getAttribute("servletContext");
|
||||
Delegator delegator = (Delegator) request.getAttribute("delegator");
|
||||
LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
|
||||
URL formFileUrl = servletContext.getResource(resourceName);
|
||||
Document formFileDoc = UtilXml.readXmlDocument(formFileUrl, true, true);
|
||||
Element formElement = UtilXml.firstChildElement(formFileDoc.getDocumentElement(), "form", "name", formName);
|
||||
modelForm = new ModelForm(formElement, delegator.getModelReader(), dispatcher.getDispatchContext());
|
||||
modelForm.setFormLocation(resourceName);
|
||||
modelForm = formWebappCache.putIfAbsentAndGet(cacheKey, modelForm);
|
||||
}
|
||||
if (modelForm == null) {
|
||||
throw new IllegalArgumentException("Could not find form with name [" + formName + "] in webapp resource [" + resourceName + "] in the webapp [" + webappName + "]");
|
||||
@@ -131,13 +121,8 @@ public class FormFactory {
|
||||
String cacheKey = formLocation + "#" + formName;
|
||||
ModelForm modelForm = formLocationCache.get(cacheKey);
|
||||
if (modelForm == null) {
|
||||
synchronized (formLocationCache) {
|
||||
modelForm = formLocationCache.get(cacheKey);
|
||||
if (modelForm == null) {
|
||||
modelForm = createModelForm(formElement, entityModelReader, dispatchContext, formLocation, formName);
|
||||
formLocationCache.put(cacheKey, modelForm);
|
||||
}
|
||||
}
|
||||
modelForm = createModelForm(formElement, entityModelReader, dispatchContext, formLocation, formName);
|
||||
modelForm = formLocationCache.putIfAbsentAndGet(cacheKey, modelForm);
|
||||
}
|
||||
modelFormMap.put(formName, modelForm);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user