Author: lektran
Date: Wed May 5 07:17:12 2010 New Revision: 941181 URL: http://svn.apache.org/viewvc?rev=941181&view=rev Log: ModelMenu objects were being instantiated with (and then keeping references to) Delegator and LocalDispatcher objects. Obviously not ideal for multi-tenanting and the like. To fix: - Deprecated the ModelMenu constructor and replaced it with one that doesn't take a delegator/dispatcher - Removed ModelMenu's dispatcher/delegator fields and deprecated the get methods for them - Took the getDispatcher and getDelegator methods from ModelForm and pushed them down to ModelWidget so that they can be used by ModelMenu as well - Deprecated the MenuFactory methods that take delegator/dispatcher and replaced them with ones that don't - Altered any code that was using the newly deprecated methods Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/ModelWidget.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/MenuFactory.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ModelMenu.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ModelMenuAction.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ModelMenuItem.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenWidget.java Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/ModelWidget.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/ModelWidget.java?rev=941181&r1=941180&r2=941181&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/ModelWidget.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/ModelWidget.java Wed May 5 07:17:12 2010 @@ -24,6 +24,8 @@ import org.w3c.dom.Element; import org.ofbiz.base.util.UtilGenerics; import org.ofbiz.base.util.UtilProperties; import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.entity.Delegator; +import org.ofbiz.service.LocalDispatcher; /** * Widget Library - Widget model class. ModelWidget is a base class that is @@ -141,4 +143,15 @@ public class ModelWidget implements Seri } } + public LocalDispatcher getDispatcher(Map<String, Object> context) { + LocalDispatcher dispatcher = (LocalDispatcher) context.get("dispatcher"); + return dispatcher; + } + + public Delegator getDelegator(Map<String, Object> context) { + Delegator delegator = (Delegator) context.get("delegator"); + return delegator; + } + + } Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java?rev=941181&r1=941180&r2=941181&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java Wed May 5 07:17:12 2010 @@ -1805,17 +1805,6 @@ public class ModelForm extends ModelWidg return fieldListByPosition; } - - public LocalDispatcher getDispatcher(Map<String, Object> context) { - LocalDispatcher dispatcher = (LocalDispatcher) context.get("dispatcher"); - return dispatcher; - } - - public Delegator getDelegator(Map<String, Object> context) { - Delegator delegator = (Delegator) context.get("delegator"); - return delegator; - } - public String getTargetType() { return this.targetType; } Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/MenuFactory.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/MenuFactory.java?rev=941181&r1=941180&r2=941181&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/MenuFactory.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/MenuFactory.java Wed May 5 07:17:12 2010 @@ -83,13 +83,13 @@ public class MenuFactory { return modelMenu; } - public static Map<String, ModelMenu> readMenuDocument(Document menuFileDoc, Delegator delegator, LocalDispatcher dispatcher, String menuLocation) { + public static Map<String, ModelMenu> readMenuDocument(Document menuFileDoc, String menuLocation) { Map<String, ModelMenu> modelMenuMap = new HashMap<String, ModelMenu>(); if (menuFileDoc != null) { // read document and construct ModelMenu for each menu element Element rootElement = menuFileDoc.getDocumentElement(); for (Element menuElement: UtilXml.childElementList(rootElement, "menu")){ - ModelMenu modelMenu = new ModelMenu(menuElement, delegator, dispatcher); + ModelMenu modelMenu = new ModelMenu(menuElement); modelMenu.setMenuLocation(menuLocation); modelMenuMap.put(modelMenu.getName(), modelMenu); } @@ -97,8 +97,12 @@ public class MenuFactory { return modelMenuMap; } - public static ModelMenu getMenuFromLocation(String resourceName, String menuName, Delegator delegator, LocalDispatcher dispatcher) - throws IOException, SAXException, ParserConfigurationException { + @Deprecated + public static Map<String, ModelMenu> readMenuDocument(Document menuFileDoc, Delegator delegator, LocalDispatcher dispatcher, String menuLocation) { + return readMenuDocument(menuFileDoc, menuLocation); + } + + public static ModelMenu getMenuFromLocation(String resourceName, String menuName) throws IOException, SAXException, ParserConfigurationException { Map<String, ModelMenu> modelMenuMap = menuLocationCache.get(resourceName); if (modelMenuMap == null) { synchronized (MenuFactory.class) { @@ -112,7 +116,7 @@ public class MenuFactory { URL menuFileUrl = null; menuFileUrl = FlexibleLocation.resolveLocation(resourceName); //, loader); Document menuFileDoc = UtilXml.readXmlDocument(menuFileUrl, true); - modelMenuMap = readMenuDocument(menuFileDoc, delegator, dispatcher, resourceName); + modelMenuMap = readMenuDocument(menuFileDoc, resourceName); menuLocationCache.put(resourceName, modelMenuMap); } } @@ -129,4 +133,10 @@ public class MenuFactory { return modelMenu; } + @Deprecated + public static ModelMenu getMenuFromLocation(String resourceName, String menuName, Delegator delegator, LocalDispatcher dispatcher) + throws IOException, SAXException, ParserConfigurationException { + return getMenuFromLocation(resourceName, menuName); + } + } Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ModelMenu.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ModelMenu.java?rev=941181&r1=941180&r2=941181&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ModelMenu.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ModelMenu.java Wed May 5 07:17:12 2010 @@ -46,9 +46,6 @@ public class ModelMenu extends ModelWidg public static final String module = ModelMenu.class.getName(); - protected Delegator delegator; - protected LocalDispatcher dispatcher; - protected String menuLocation; protected String type; protected String target; @@ -102,10 +99,8 @@ public class ModelMenu extends ModelWidg public ModelMenu() {} /** XML Constructor */ - public ModelMenu(Element menuElement, Delegator delegator, LocalDispatcher dispatcher) { + public ModelMenu(Element menuElement) { super(menuElement); - this.delegator = delegator; - this.dispatcher = dispatcher; // check if there is a parent menu to inherit from String parentResource = menuElement.getAttribute("extends-resource"); @@ -115,7 +110,7 @@ public class ModelMenu extends ModelWidg // check if we have a resource name (part of the string before the ?) if (UtilValidate.isNotEmpty(parentResource)) { try { - parent = MenuFactory.getMenuFromLocation(parentResource, parentMenu, delegator, dispatcher); + parent = MenuFactory.getMenuFromLocation(parentResource, parentMenu); } catch (Exception e) { Debug.logError(e, "Failed to load parent menu definition '" + parentMenu + "' at resource '" + parentResource + "'", module); } @@ -127,7 +122,7 @@ public class ModelMenu extends ModelWidg //menuElements.addAll(UtilXml.childElementList(rootElement, "abstract-menu")); for (Element menuElementEntry : menuElements) { if (menuElementEntry.getAttribute("name").equals(parentMenu)) { - parent = new ModelMenu(menuElementEntry, delegator, dispatcher); + parent = new ModelMenu(menuElementEntry); break; } } @@ -250,6 +245,11 @@ public class ModelMenu extends ModelWidg modelMenuItem = this.addUpdateMenuItem(modelMenuItem); } } + + @Deprecated + public ModelMenu(Element menuElement, Delegator delegator, LocalDispatcher dispatcher) { + this(menuElement); + } /** * add/override modelMenuItem using the menuItemList and menuItemMap * @@ -357,13 +357,20 @@ public class ModelMenu extends ModelWidg menuStringRenderer.renderMenuClose(writer, context, this); } - + /** + * @deprecated Use getDispatcher(Map<String, Object>) instead, this method will throw an {@link UnsupportedOperationException} if used + */ + @Deprecated public LocalDispatcher getDispacher() { - return this.dispatcher; + throw new UnsupportedOperationException("This method is no longer supported, use getDispatcher(Map<String, Object>) instead."); } + /** + * @deprecated Use getDelegator(Map<String, Object>) instead, this method will throw an {@link UnsupportedOperationException} if used + */ + @Deprecated public Delegator getDelegator() { - return this.delegator; + throw new UnsupportedOperationException("This method is no longer supported, use getDelegator(Map<String, Object>) instead."); } public String getDefaultEntityName() { Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ModelMenuAction.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ModelMenuAction.java?rev=941181&r1=941180&r2=941181&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ModelMenuAction.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ModelMenuAction.java Wed May 5 07:17:12 2010 @@ -404,7 +404,7 @@ public abstract class ModelMenuAction { try { Map<String, Object> serviceContext = null; if (autoFieldMapBool) { - serviceContext = this.modelMenu.getDispacher().getDispatchContext().makeValidContext(serviceNameExpanded, ModelService.IN_PARAM, context); + serviceContext = this.modelMenu.getDispatcher(context).getDispatchContext().makeValidContext(serviceNameExpanded, ModelService.IN_PARAM, context); } else { serviceContext = FastMap.newInstance(); } @@ -417,7 +417,7 @@ public abstract class ModelMenuAction { } } - Map<String, Object> result = this.modelMenu.getDispacher().runSync(serviceNameExpanded, serviceContext); + Map<String, Object> result = this.modelMenu.getDispatcher(context).runSync(serviceNameExpanded, serviceContext); if (!this.resultMapNameAcsr.isEmpty()) { this.resultMapNameAcsr.put(context, result); @@ -443,7 +443,7 @@ public abstract class ModelMenuAction { @Override public void runAction(Map<String, Object> context) { try { - finder.runFind(context, this.modelMenu.getDelegator()); + finder.runFind(context, this.modelMenu.getDelegator(context)); } catch (GeneralException e) { String errMsg = "Error doing entity query by condition: " + e.toString(); Debug.logError(e, errMsg, module); @@ -463,7 +463,7 @@ public abstract class ModelMenuAction { @Override public void runAction(Map<String, Object> context) { try { - finder.runFind(context, this.modelMenu.getDelegator()); + finder.runFind(context, this.modelMenu.getDelegator(context)); } catch (GeneralException e) { String errMsg = "Error doing entity query by condition: " + e.toString(); Debug.logError(e, errMsg, module); @@ -483,7 +483,7 @@ public abstract class ModelMenuAction { @Override public void runAction(Map<String, Object> context) { try { - finder.runFind(context, this.modelMenu.getDelegator()); + finder.runFind(context, this.modelMenu.getDelegator(context)); } catch (GeneralException e) { String errMsg = "Error doing entity query by condition: " + e.toString(); Debug.logError(e, errMsg, module); Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ModelMenuItem.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ModelMenuItem.java?rev=941181&r1=941180&r2=941181&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ModelMenuItem.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ModelMenuItem.java Wed May 5 07:17:12 2010 @@ -148,7 +148,7 @@ public class ModelMenuItem { String subMenuLocation = subMenuElement.getAttribute("location"); String subMenuName = subMenuElement.getAttribute("name"); try { - this.subMenu = MenuFactory.getMenuFromLocation(subMenuLocation, subMenuName, modelMenu.getDelegator(), modelMenu.getDispacher()); + this.subMenu = MenuFactory.getMenuFromLocation(subMenuLocation, subMenuName); } catch (IOException e) { String errMsg = "Error getting subMenu in menu named [" + this.modelMenu.getName() + "]: " + e.toString(); Debug.logError(e, errMsg, module); @@ -406,7 +406,7 @@ public class ModelMenuItem { List<GenericValue> portalPages = null; String parentPortalPageId = this.getParentPortalPageId(context); if (UtilValidate.isNotEmpty(parentPortalPageId)) { - Delegator delegator = modelMenu.getDelegator(); + Delegator delegator = modelMenu.getDelegator(context); try { // first get public pages EntityCondition cond = Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenWidget.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenWidget.java?rev=941181&r1=941180&r2=941181&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenWidget.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenWidget.java Wed May 5 07:17:12 2010 @@ -1342,7 +1342,7 @@ public abstract class ModelScreenWidget String location = this.getLocation(context); ModelMenu modelMenu = null; try { - modelMenu = MenuFactory.getMenuFromLocation(location, name, this.modelScreen.getDelegator(context), this.modelScreen.getDispatcher(context)); + modelMenu = MenuFactory.getMenuFromLocation(location, name); } catch (Exception e) { String errMsg = "Error rendering included menu named [" + name + "] at location [" + location + "]: "; Debug.logError(e, errMsg, module); |
Free forum by Nabble | Edit this page |