Author: adrianc
Date: Tue Jun 3 10:32:07 2008 New Revision: 662847 URL: http://svn.apache.org/viewvc?rev=662847&view=rev Log: Fixed thread-safe issues in the tree widget. Eliminated compiler warnings. Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlTreeRenderer.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/tree/ModelTree.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/tree/ModelTreeAction.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/tree/ModelTreeCondition.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/tree/TreeFactory.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/tree/TreeStringRenderer.java Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlTreeRenderer.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlTreeRenderer.java?rev=662847&r1=662846&r2=662847&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlTreeRenderer.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlTreeRenderer.java Tue Jun 3 10:32:07 2008 @@ -27,6 +27,7 @@ import javax.servlet.http.HttpServletResponse; import org.ofbiz.base.util.StringUtil; +import org.ofbiz.base.util.UtilGenerics; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.webapp.control.RequestHandler; import org.ofbiz.webapp.taglib.ContentUrlTag; @@ -60,7 +61,7 @@ String pathString = buildPathString(node.getModelTree(), depth); String currentNodeTrailPiped = null; - List<String> currentNodeTrail = node.getModelTree().getCurrentNodeTrail(); + List<String> currentNodeTrail = UtilGenerics.toList(context.get("currentNodeTrail")); String staticNodeTrailPiped = StringUtil.join(currentNodeTrail, "|"); context.put("staticNodeTrailPiped", staticNodeTrailPiped); context.put("nodePathString", pathString); @@ -88,7 +89,7 @@ // check to see if this node needs to be expanded. if (hasChildren && node.isExpandCollapse()) { String targetEntityId = null; - List targetNodeTrail = node.getModelTree().getTrailList(); + List<String> targetNodeTrail = UtilGenerics.toList(context.get("targetNodeTrail")); if (depth < targetNodeTrail.size()) { targetEntityId = (String)targetNodeTrail.get(depth); } @@ -103,7 +104,7 @@ int openDepth = node.getModelTree().getOpenDepth(); if (depth >= openDepth && (targetEntityId == null || !targetEntityId.equals(entityId))) { // Not on the trail - if( node.showPeers(depth)) { + if( node.showPeers(depth, context)) { context.put("processChildren", Boolean.FALSE); //expandCollapseLink.setText(" + "); currentNodeTrailPiped = StringUtil.join(currentNodeTrail, "|"); Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/tree/ModelTree.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/tree/ModelTree.java?rev=662847&r1=662846&r2=662847&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/tree/ModelTree.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/tree/ModelTree.java Tue Jun 3 10:32:07 2008 @@ -30,10 +30,13 @@ import javax.servlet.http.HttpServletRequest; import javax.xml.parsers.ParserConfigurationException; +import javolution.util.FastList; + import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.GeneralException; import org.ofbiz.base.util.StringUtil; import org.ofbiz.base.util.UtilFormatOut; +import org.ofbiz.base.util.UtilGenerics; import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.base.util.UtilXml; @@ -74,8 +77,6 @@ protected LocalDispatcher dispatcher; protected FlexibleStringExpander expandCollapseRequestExdr; protected FlexibleStringExpander trailNameExdr; - protected List trail = new ArrayList(); - protected List<String> currentNodeTrail; protected int openDepth; protected int postTrailOpenDepth; protected int [] nodeIndices = new int[20]; @@ -197,18 +198,6 @@ return this.trailNameExdr.expandString(context); } - public List getTrailList() { - return trail; - } - - public void setTrailList(List trailList) { - this.trail = trailList; - } - - public List getCurrentNodeTrail() { - return currentNodeTrail; - } - public String getBoundaryCommentName() { return treeLocation + "#" + name; } @@ -237,21 +226,13 @@ setWidgetBoundaryComments(context); ModelNode node = (ModelNode)nodeMap.get(rootNodeName); - /* - List parentNodeTrail = (List)context.get("currentNodeTrail"); - if (parentNodeTrail != null) - currentNodeTrail = new ArrayList(parentNodeTrail); - else - */ - currentNodeTrail = new ArrayList(); - - //Map requestParameters = (Map)context.get("requestParameters"); - //String treeString = (String)requestParameters.get("trail"); + String trailName = trailNameExdr.expandString(context); String treeString = (String)context.get(trailName); if (UtilValidate.isEmpty(treeString)) { treeString = (String)parameters.get(trailName); } + List<String> trail = null; if (UtilValidate.isNotEmpty(treeString)) { trail = StringUtil.split(treeString, "|"); if (trail == null || trail.size() == 0) @@ -259,10 +240,11 @@ context.put("rootEntityId", trail.get(0)); context.put(defaultPkName, trail.get(0)); - context.put("targetNodeTrail", trail); } else { - Debug.logError("Trail value is empty.", module); + trail = FastList.newInstance(); } + context.put("targetNodeTrail", trail); + context.put("currentNodeTrail", FastList.newInstance()); StringWriter writer = new StringWriter(); try { node.renderNodeString(writer, context, treeStringRenderer, 0, true); @@ -272,15 +254,6 @@ Debug.logError(e2, errMsg, module); throw new RuntimeException(errMsg); } -// try { -// FileOutputStream fw = new FileOutputStream(new File("/usr/local/agi/ofbiz/hot-deploy/ofbizdoc/misc/profile.data")); -// Profiler.print(fw); -// fw.close(); -// } catch (IOException e) { -// Debug.logError("[PROFILER] " + e.getMessage(),""); -// } - - } public LocalDispatcher getDispatcher() { @@ -304,11 +277,11 @@ protected Label label; protected Link link; protected Image image; - protected List subNodeList = new ArrayList(); - protected List actions = new ArrayList(); + protected List<ModelSubNode> subNodeList = new ArrayList<ModelSubNode>(); + protected List<ModelTreeAction> actions = new ArrayList<ModelTreeAction>(); protected String name; protected ModelTree modelTree; - protected List subNodeValues; + protected List<Object []> subNodeValues; protected String expandCollapseStyle; protected FlexibleStringExpander wrapStyleExdr; protected ModelTreeCondition condition; @@ -400,9 +373,7 @@ } //Debug.logInfo("in ModelMenu, name:" + this.getName(), module); if (passed) { - //this.subNodeValues = new ArrayList(); - //context.put("subNodeValues", new ArrayList()); - //if (Debug.infoOn()) Debug .logInfo(" renderNodeString, " + modelTree.getdefaultPkName() + " :" + context.get(modelTree.getdefaultPkName()), module); + List<String> currentNodeTrail = UtilGenerics.toList(context.get("currentNodeTrail")); context.put("processChildren", Boolean.TRUE); // this action will usually obtain the "current" entity ModelTreeAction.runSubActions(this.actions, context); @@ -415,10 +386,9 @@ id = (String) context.get(pkName); } if (id != null) { - modelTree.currentNodeTrail.add(id); + currentNodeTrail.add(id); } - context.put("currentNodeTrail", modelTree.currentNodeTrail); - String currentNodeTrailPiped = StringUtil.join(modelTree.currentNodeTrail, "|"); + String currentNodeTrailPiped = StringUtil.join(currentNodeTrail, "|"); context.put("currentNodeTrailPiped", currentNodeTrailPiped); treeStringRenderer.renderNodeBegin(writer, context, this, depth, isLast); //if (Debug.infoOn()) Debug.logInfo(" context:" + @@ -454,13 +424,13 @@ modelTree.setNodeIndexAtDepth(newDepth, nodeIndex); Object[] arr = (Object[]) nodeIter.next(); ModelNode node = (ModelNode) arr[0]; - Map val = (Map) arr[1]; + Map<String, Object> val = UtilGenerics.checkMap(arr[1]); //GenericPK pk = val.getPrimaryKey(); //if (Debug.infoOn()) Debug.logInfo(" pk:" + pk, // module); String thisPkName = node.getPkName(); String thisEntityId = (String) val.get(thisPkName); - Map newContext = ((MapStack) context) .standAloneChildStack(); + MapStack<String> newContext = MapStack.create(context); String nodeEntryName = node.getEntryName(); if (UtilValidate.isNotEmpty(nodeEntryName)) { newContext.put(nodeEntryName, val); @@ -469,11 +439,11 @@ } newContext.put("currentNodeIndex", new Integer(nodeIndex)); String targetEntityId = null; - List targetNodeTrail = this.modelTree .getTrailList(); + List targetNodeTrail = UtilGenerics.checkList(context.get("targetNodeTrail")); if (newDepth < targetNodeTrail.size()) { targetEntityId = (String) targetNodeTrail .get(newDepth); } - if ((targetEntityId != null && targetEntityId .equals(thisEntityId)) || this.showPeers(newDepth)) { + if ((targetEntityId != null && targetEntityId .equals(thisEntityId)) || this.showPeers(newDepth, context)) { boolean lastNode = !nodeIter.hasNext(); newContext.put("lastNode", new Boolean(lastNode)); node.renderNodeString(writer, newContext, treeStringRenderer, newDepth, lastNode); @@ -502,8 +472,8 @@ throw new RuntimeException(errMsg); } treeStringRenderer.renderNodeEnd(writer, context, this); - int removeIdx = modelTree.currentNodeTrail.size() - 1; - if (removeIdx >= 0) modelTree.currentNodeTrail.remove(removeIdx); + int removeIdx = currentNodeTrail.size() - 1; + if (removeIdx >= 0) currentNodeTrail.remove(removeIdx); } } @@ -586,7 +556,7 @@ } public void getChildren(Map<String, Object> context) { - this.subNodeValues = new ArrayList(); + this.subNodeValues = new ArrayList<Object []>(); Iterator nodeIter = subNodeList.iterator(); while (nodeIter.hasNext()) { ModelSubNode subNode = (ModelSubNode)nodeIter.next(); @@ -658,9 +628,9 @@ return name.equals(modelTree.getRootNodeName()); } - public boolean showPeers(int currentDepth) { + public boolean showPeers(int currentDepth, Map<String, Object> context) { int trailSize = 0; - List trail = modelTree.getTrailList(); + List trail = UtilGenerics.checkList(context.get("targetNodeTrail")); int openDepth = modelTree.getOpenDepth(); int postTrailOpenDepth = modelTree.getPostTrailOpenDepth(); if (trail != null) trailSize = trail.size(); @@ -736,8 +706,7 @@ protected ModelNode rootNode; protected FlexibleStringExpander nodeNameExdr; - protected List actions = new ArrayList(); - protected List outFieldMaps; + protected List<ModelTreeAction> actions = new ArrayList<ModelTreeAction>(); protected ListIterator listIterator; public ModelSubNode() {} Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/tree/ModelTreeAction.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/tree/ModelTreeAction.java?rev=662847&r1=662846&r2=662847&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/tree/ModelTreeAction.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/tree/ModelTreeAction.java Tue Jun 3 10:32:07 2008 @@ -32,6 +32,7 @@ import org.ofbiz.base.util.GeneralException; import org.ofbiz.base.util.ObjectType; import org.ofbiz.base.util.UtilFormatOut; +import org.ofbiz.base.util.UtilGenerics; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.base.util.UtilXml; import org.ofbiz.base.util.collections.FlexibleMapAccessor; @@ -213,7 +214,7 @@ protected FlexibleStringExpander resultMapListIteratorNameExdr; protected FlexibleStringExpander resultMapValueNameExdr; protected FlexibleStringExpander valueNameExdr; - protected Map fieldMap; + protected Map<FlexibleMapAccessor, Object> fieldMap; public Service(ModelTree.ModelNode modelNode, Element serviceElement) { super (modelNode, serviceElement); @@ -247,18 +248,18 @@ boolean autoFieldMapBool = !"false".equals(autoFieldMapString); try { - Map serviceContext = null; + Map<String, Object> serviceContext = null; if (autoFieldMapBool) { serviceContext = this.modelTree.getDispatcher().getDispatchContext().makeValidContext(serviceNameExpanded, ModelService.IN_PARAM, context); } else { - serviceContext = new HashMap(); + serviceContext = new HashMap<String, Object>(); } if (this.fieldMap != null) { EntityFinderUtil.expandFieldMapToContext(this.fieldMap, context, serviceContext); } - Map result = this.modelTree.getDispatcher().runSync(serviceNameExpanded, serviceContext); + Map<String, Object> result = this.modelTree.getDispatcher().runSync(serviceNameExpanded, serviceContext); if (this.resultMapNameAcsr != null) { this.resultMapNameAcsr.put(context, result); @@ -296,7 +297,8 @@ if (UtilValidate.isNotEmpty(valueName)) { context.put(valueName, result.get(resultMapValueName)); } else { - context.putAll((Map)result.get(resultMapValueName)); + Map<String, Object> resultMap = UtilGenerics.checkMap(result.get(resultMapValueName)); + context.putAll(resultMap); } } } Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/tree/ModelTreeCondition.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/tree/ModelTreeCondition.java?rev=662847&r1=662846&r2=662847&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/tree/ModelTreeCondition.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/tree/ModelTreeCondition.java Tue Jun 3 10:32:07 2008 @@ -79,7 +79,7 @@ } public static List readSubConditions(ModelTree modelTree, Element conditionElement) { - List condList = FastList.newInstance(); + List<TreeCondition> condList = FastList.newInstance(); List subElementList = UtilXml.childElementList(conditionElement); Iterator subElementIter = subElementList.iterator(); while (subElementIter.hasNext()) { @@ -326,7 +326,7 @@ fieldVal = ""; } - List messages = FastList.newInstance(); + List<String> messages = FastList.newInstance(); Boolean resultBool = BaseCompare.doRealCompare(fieldVal, value, operator, type, format, messages, null, null, true); if (messages.size() > 0) { messages.add(0, "Error with comparison in if-compare between field [" + fieldAcsr.toString() + "] with value [" + fieldVal + "] and value [" + value + "] with operator [" + operator + "] and type [" + type + "]: "); @@ -375,7 +375,7 @@ fieldVal = ""; } - List messages = FastList.newInstance(); + List<String> messages = FastList.newInstance(); Boolean resultBool = BaseCompare.doRealCompare(fieldVal, toFieldVal, operator, type, format, messages, null, null, false); if (messages.size() > 0) { messages.add(0, "Error with comparison in if-compare-field between field [" + fieldAcsr.toString() + "] with value [" + fieldVal + "] and to-field [" + toFieldVal.toString() + "] with value [" + toFieldVal + "] with operator [" + operator + "] and type [" + type + "]: "); Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/tree/TreeFactory.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/tree/TreeFactory.java?rev=662847&r1=662846&r2=662847&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/tree/TreeFactory.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/tree/TreeFactory.java Tue Jun 3 10:32:07 2008 @@ -47,15 +47,15 @@ public static final String module = TreeFactory.class.getName(); - public static final UtilCache treeLocationCache = new UtilCache("widget.tree.locationResource", 0, 0, false); - public static final UtilCache treeWebappCache = new UtilCache("widget.tree.webappResource", 0, 0, false); + public static final UtilCache<String, Map<String, ModelTree>> treeLocationCache = new UtilCache<String, Map<String, ModelTree>>("widget.tree.locationResource", 0, 0, false); + public static final UtilCache<String, Map<String, ModelTree>> treeWebappCache = new UtilCache<String, Map<String, ModelTree>>("widget.tree.webappResource", 0, 0, false); public static ModelTree getTreeFromLocation(String resourceName, String treeName, GenericDelegator delegator, LocalDispatcher dispatcher) throws IOException, SAXException, ParserConfigurationException { - Map modelTreeMap = (Map) treeLocationCache.get(resourceName); + Map<String, ModelTree> modelTreeMap = treeLocationCache.get(resourceName); if (modelTreeMap == null) { synchronized (TreeFactory.class) { - modelTreeMap = (Map) treeLocationCache.get(resourceName); + modelTreeMap = treeLocationCache.get(resourceName); if (modelTreeMap == null) { ClassLoader loader = Thread.currentThread().getContextClassLoader(); if (loader == null) { @@ -84,10 +84,10 @@ String cacheKey = webappName + "::" + resourceName; - Map modelTreeMap = (Map) treeWebappCache.get(cacheKey); + Map<String, ModelTree> modelTreeMap = treeWebappCache.get(cacheKey); if (modelTreeMap == null) { synchronized (TreeFactory.class) { - modelTreeMap = (Map) treeWebappCache.get(cacheKey); + modelTreeMap = treeWebappCache.get(cacheKey); if (modelTreeMap == null) { ServletContext servletContext = (ServletContext) request.getAttribute("servletContext"); GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator"); @@ -108,8 +108,8 @@ return modelTree; } - public static Map readTreeDocument(Document treeFileDoc, GenericDelegator delegator, LocalDispatcher dispatcher, String treeLocation) { - Map modelTreeMap = new HashMap(); + public static Map<String, ModelTree> readTreeDocument(Document treeFileDoc, GenericDelegator delegator, LocalDispatcher dispatcher, String treeLocation) { + Map<String, ModelTree> modelTreeMap = new HashMap<String, ModelTree>(); if (treeFileDoc != null) { // read document and construct ModelTree for each tree element Element rootElement = treeFileDoc.getDocumentElement(); Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/tree/TreeStringRenderer.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/tree/TreeStringRenderer.java?rev=662847&r1=662846&r2=662847&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/tree/TreeStringRenderer.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/tree/TreeStringRenderer.java Tue Jun 3 10:32:07 2008 @@ -19,7 +19,6 @@ package org.ofbiz.widget.tree; import java.io.IOException; -import java.io.Writer; import java.util.Map; import org.ofbiz.widget.screen.ScreenStringRenderer; |
Free forum by Nabble | Edit this page |