ofbiz-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adri...@apache.org
Subject svn commit: r897746 - in /ofbiz/branches/executioncontext20091231/framework: api/src/org/ofbiz/api/context/ context/src/org/ofbiz/context/
Date Mon, 11 Jan 2010 03:39:08 GMT
Author: adrianc
Date: Mon Jan 11 03:39:08 2010
New Revision: 897746

URL: http://svn.apache.org/viewvc?rev=897746&view=rev
Log:
Code cleanups, reorganization, no functional change.

Added:
    ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/TreeBuilder.java
  (with props)
    ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/TreeWalker.java
  (with props)
Modified:
    ofbiz/branches/executioncontext20091231/framework/api/src/org/ofbiz/api/context/AbstractExecutionContext.java
    ofbiz/branches/executioncontext20091231/framework/api/src/org/ofbiz/api/context/ExecutionContext.java
    ofbiz/branches/executioncontext20091231/framework/api/src/org/ofbiz/api/context/ThreadContext.java
    ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/AccessControllerImpl.java
    ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/ArtifactPath.java
    ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/AuthorizationManagerImpl.java
    ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/PermissionTreeBuilder.java
    ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/PermissionsGatherer.java
    ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/TreeStringBuilder.java

Modified: ofbiz/branches/executioncontext20091231/framework/api/src/org/ofbiz/api/context/AbstractExecutionContext.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/executioncontext20091231/framework/api/src/org/ofbiz/api/context/AbstractExecutionContext.java?rev=897746&r1=897745&r2=897746&view=diff
==============================================================================
--- ofbiz/branches/executioncontext20091231/framework/api/src/org/ofbiz/api/context/AbstractExecutionContext.java
(original)
+++ ofbiz/branches/executioncontext20091231/framework/api/src/org/ofbiz/api/context/AbstractExecutionContext.java
Mon Jan 11 03:39:08 2010
@@ -32,6 +32,8 @@
 public abstract class AbstractExecutionContext implements ExecutionContext {
 
     public static final String module = AbstractExecutionContext.class.getName();
+    public static final String PATH_ROOT_NODE_NAME = "ofbiz";
+    public static final String PATH_ELEMENT_SEPARATOR = "/";
 
     protected final FastList<ExecutionArtifact> artifactStack = FastList.newInstance();
 	protected String currencyUom = null;
@@ -66,14 +68,25 @@
     }
 
 	public String getExecutionPath() {
-		StringBuilder sb = new StringBuilder("ofbiz");
+		StringBuilder sb = new StringBuilder(PATH_ROOT_NODE_NAME);
 		for (ExecutionArtifact artifact : this.artifactStack) {
-			sb.append("/");
+			sb.append(PATH_ELEMENT_SEPARATOR);
 			sb.append(artifact.getName() == null ? "null" : artifact.getName());
 		}
 		return sb.toString();
 	}
 
+    public String[] getExecutionPathAsArray() {
+        String[] strArray = new String[this.artifactStack.size() + 1];
+        strArray[0] = PATH_ROOT_NODE_NAME;
+        int index = 1;
+        for (ExecutionArtifact artifact : this.artifactStack) {
+            strArray[index] = artifact.getName();
+            index++;
+        }
+        return strArray;
+    }
+
 	public Locale getLocale() {
         return this.locale;
     }

Modified: ofbiz/branches/executioncontext20091231/framework/api/src/org/ofbiz/api/context/ExecutionContext.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/executioncontext20091231/framework/api/src/org/ofbiz/api/context/ExecutionContext.java?rev=897746&r1=897745&r2=897746&view=diff
==============================================================================
--- ofbiz/branches/executioncontext20091231/framework/api/src/org/ofbiz/api/context/ExecutionContext.java
(original)
+++ ofbiz/branches/executioncontext20091231/framework/api/src/org/ofbiz/api/context/ExecutionContext.java
Mon Jan 11 03:39:08 2010
@@ -64,13 +64,21 @@
      */
     public String getCurrencyUom();
 
-    /** Returns the current execution path. Artifacts in the path are separated
+    /** Returns the current execution path. Artifact names are separated
      * with a forward slash.
      * 
      * @return The current execution path
      */
     public String getExecutionPath();
 
+    /** Returns the current execution path as an array of strings.
+     * Each array element contains an Artifact name, with the
+     * first element containing the path root.
+     * 
+     * @return The current execution path as an array
+     */
+    public String[] getExecutionPathAsArray();
+
     /** Returns the current <code>Locale</code>.
      * 
      * @return The current <code>Locale</code>

Modified: ofbiz/branches/executioncontext20091231/framework/api/src/org/ofbiz/api/context/ThreadContext.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/executioncontext20091231/framework/api/src/org/ofbiz/api/context/ThreadContext.java?rev=897746&r1=897745&r2=897746&view=diff
==============================================================================
--- ofbiz/branches/executioncontext20091231/framework/api/src/org/ofbiz/api/context/ThreadContext.java
(original)
+++ ofbiz/branches/executioncontext20091231/framework/api/src/org/ofbiz/api/context/ThreadContext.java
Mon Jan 11 03:39:08 2010
@@ -64,6 +64,10 @@
         return executionContext.get().getExecutionPath();
     }
 
+    public static String[] getExecutionPathAsArray() {
+        return executionContext.get().getExecutionPathAsArray();
+    }
+
     public static Locale getLocale() {
         return executionContext.get().getLocale();
     }

Modified: ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/AccessControllerImpl.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/AccessControllerImpl.java?rev=897746&r1=897745&r2=897746&view=diff
==============================================================================
--- ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/AccessControllerImpl.java
(original)
+++ ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/AccessControllerImpl.java
Mon Jan 11 03:39:08 2010
@@ -31,9 +31,9 @@
 import org.ofbiz.base.util.UtilProperties;
 import org.ofbiz.entity.util.EntityListIterator;
 import org.ofbiz.service.DispatchContext;
-import org.ofbiz.service.ThreadContext;
 import org.ofbiz.service.LocalDispatcher;
 import org.ofbiz.service.ModelService;
+import org.ofbiz.service.ThreadContext;
 
 /** An implementation of the <code>AccessController</code> interface. */
 public class AccessControllerImpl implements AccessController {
@@ -47,8 +47,8 @@
     protected boolean disabled = false;
 
     protected AccessControllerImpl(PathNode node) {
-        this.permissionsGatherer = new PermissionsGatherer(node);
         this.permission = new OFBizPermission(ThreadContext.getUserLogin().getString("userLoginId"));
+        this.permissionsGatherer = new PermissionsGatherer(node, this.permission);
         this.verbose = "true".equals(UtilProperties.getPropertyValue("api.properties", "authorizationManager.verbose"));
         this.disabled = "true".equals(UtilProperties.getPropertyValue("api.properties", "authorizationManager.disabled"));
         if (this.verbose) {
@@ -56,26 +56,6 @@
         }
     }
 
-    public void checkPermission(Permission permission) throws AccessControlException {
-        if (this.verbose) {
-            Debug.logInfo("Checking permission: " + ThreadContext.getExecutionPath() + "["
+ permission + "]", module);
-        }
-        this.permission.reset();
-        this.permissionsGatherer.gatherPermissions(new ArtifactPath(ThreadContext.getExecutionPath()),
this.permission);
-        if (this.verbose) {
-            Debug.logInfo("Found permission(s): " + ThreadContext.getUserLogin().getString("userLoginId")
+
-                    "@" + ThreadContext.getExecutionPath() + "[" + this.permission + "]",
module);
-        }
-        if (this.disabled) {
-            return;
-        }
-        if (this.permission.implies(permission) && this.hasServicePermission()) {
-            return;
-        }
-        throw new AccessControlException(ThreadContext.getUserLogin().getString("userLoginId")
+
-                "@" + ThreadContext.getExecutionPath() + "[" + permission + "]");
-    }
-
     public <E> List<E> applyFilters(List<E> list) {
         if (this.permission.getFilterNames().size() > 0) {
             return new SecurityAwareList<E>(list, this.permission.getFilterNames());
@@ -94,6 +74,25 @@
         return listIterator;
     }
 
+    public void checkPermission(Permission permission) throws AccessControlException {
+        if (this.verbose) {
+            Debug.logInfo("Checking permission: " + ThreadContext.getExecutionPath() + "["
+ permission + "]", module);
+        }
+        this.permissionsGatherer.gatherPermissions(new ArtifactPath(ThreadContext.getExecutionPathAsArray()));
+        if (this.verbose) {
+            Debug.logInfo("Found permission(s): " + ThreadContext.getUserLogin().getString("userLoginId")
+
+                    "@" + ThreadContext.getExecutionPath() + "[" + this.permission + "]",
module);
+        }
+        if (this.disabled) {
+            return;
+        }
+        if (this.permission.implies(permission) && this.hasServicePermission()) {
+            return;
+        }
+        throw new AccessControlException(ThreadContext.getUserLogin().getString("userLoginId")
+
+                "@" + ThreadContext.getExecutionPath() + "[" + permission + "]");
+    }
+
     protected boolean hasServicePermission() {
         try {
             if (this.permission.getServiceNames().size() == 0) {

Modified: ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/ArtifactPath.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/ArtifactPath.java?rev=897746&r1=897745&r2=897746&view=diff
==============================================================================
--- ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/ArtifactPath.java
(original)
+++ ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/ArtifactPath.java
Mon Jan 11 03:39:08 2010
@@ -24,11 +24,12 @@
 import javolution.text.TextBuilder;
 import javolution.util.FastList;
 
+import org.ofbiz.api.context.AbstractExecutionContext;
+
 /** Artifact path class. */
 public class ArtifactPath implements Iterator<String> {
 
-    public static final ArtifactPath PATH_ROOT = new ArtifactPath("ofbiz");
-    public static final String ELEMENT_SEPARATOR = "/";
+    public static final ArtifactPath PATH_ROOT = new ArtifactPath(AbstractExecutionContext.PATH_ROOT_NODE_NAME);
 
     protected int currentIndex = 0;
     protected final String[] pathElementArray;
@@ -36,7 +37,7 @@
     protected final TextBuilder stringBuilder = TextBuilder.newInstance();
 
     public ArtifactPath(String artifactPath) {
-        this.pathElementArray = artifactPath.split(ELEMENT_SEPARATOR);
+        this.pathElementArray = artifactPath.split(AbstractExecutionContext.PATH_ELEMENT_SEPARATOR);
     }
     
     public ArtifactPath(String[] pathElementArray) {
@@ -50,7 +51,7 @@
         this.stringBuilder.clear();
         for (int i = this.currentIndex; i < this.pathElementArray.length; i++) {
             if (i != this.currentIndex) {
-                stringBuilder.append(ELEMENT_SEPARATOR);
+                stringBuilder.append(AbstractExecutionContext.PATH_ELEMENT_SEPARATOR);
             }
             stringBuilder.append(this.pathElementArray[i]);
         }

Modified: ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/AuthorizationManagerImpl.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/AuthorizationManagerImpl.java?rev=897746&r1=897745&r2=897746&view=diff
==============================================================================
--- ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/AuthorizationManagerImpl.java
(original)
+++ ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/AuthorizationManagerImpl.java
Mon Jan 11 03:39:08 2010
@@ -18,18 +18,21 @@
  *******************************************************************************/
 package org.ofbiz.context;
 
+import java.security.AccessControlException;
 import java.security.Permission;
+import java.sql.Timestamp;
 import java.util.List;
 
 import org.ofbiz.api.authorization.AccessController;
 import org.ofbiz.api.authorization.AuthorizationManagerException;
 import org.ofbiz.api.authorization.BasicPermissions;
 import org.ofbiz.api.authorization.AuthorizationManager;
+import org.ofbiz.entity.util.EntityUtil;
 import org.ofbiz.entity.Delegator;
 import org.ofbiz.entity.GenericEntityException;
 import org.ofbiz.entity.GenericValue;
 import org.ofbiz.entity.condition.EntityCondition;
-//import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.UtilMisc;
 import org.ofbiz.base.util.cache.UtilCache;
 import org.ofbiz.security.OFBizSecurity;
@@ -74,6 +77,7 @@
         }
 	    return accessController;
 	}
+
 	protected static void processGroupPermissions(String groupId, PathNode node, Delegator delegator)
throws AuthorizationManagerException {
         try {
             // Process this group's memberships first
@@ -90,7 +94,7 @@
     }
 
     protected static void setPermissions(String id, PathNode node, List<GenericValue>
permissionValues) throws AuthorizationManagerException {
-        PermissionTreeBuilder builder = new PermissionTreeBuilder();
+        PermissionTreeBuilder builder = new PermissionTreeBuilder(node);
         for (GenericValue value : permissionValues) {
             String artifactPathString = value.getString("artifactPath");
             OFBizPermission target = new OFBizPermission(id + "@" + artifactPathString);
@@ -111,7 +115,7 @@
                     throw new AuthorizationManagerException("Invalid permission: " + pair[0]);
                 }
             }
-            builder.buildPermissionTree(node, new ArtifactPath(artifactPathString), target);
+            builder.build(new ArtifactPath(artifactPathString), target);
         }
     }
 

Modified: ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/PermissionTreeBuilder.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/PermissionTreeBuilder.java?rev=897746&r1=897745&r2=897746&view=diff
==============================================================================
--- ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/PermissionTreeBuilder.java
(original)
+++ ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/PermissionTreeBuilder.java
Mon Jan 11 03:39:08 2010
@@ -18,34 +18,19 @@
  *******************************************************************************/
 package org.ofbiz.context;
 
-import javolution.util.FastMap;
-
 import org.ofbiz.context.PathNode.BranchNode;
-import org.ofbiz.context.PathNode.SubstitutionNode;
-import org.ofbiz.context.PathNode.WildCardNode;
 
-public class PermissionTreeBuilder implements PathNodeVisitor {
+public class PermissionTreeBuilder extends TreeBuilder {
 
-    protected ArtifactPath artifactPath;
     protected OFBizPermission permission;
 
-    public void buildPermissionTree(PathNode node, ArtifactPath artifactPath, OFBizPermission
permission) {
-        this.artifactPath = artifactPath;
-        this.permission = permission;
-        node.accept(this);
+    public PermissionTreeBuilder(PathNode node) {
+        super(node);
     }
 
-    protected void setChildNodePermissions(PathNode node, String key) {
-        if (node.childNodes == null) {
-            node.childNodes = FastMap.newInstance();
-        }
-        key = key.toUpperCase();
-        PathNode childNode = node.childNodes.get(key);
-        if (childNode == null) {
-            childNode = PathNode.getInstance(this.artifactPath);
-            node.childNodes.put(key, childNode);
-        }
-        childNode.accept(this);
+    public void build(ArtifactPath artifactPath, OFBizPermission permission) {
+        this.permission = permission;
+        super.build(artifactPath);
     }
 
     @Override
@@ -58,36 +43,6 @@
             }
             return;
         }
-        String key = this.artifactPath.next();
-        if (PathNode.SUBSTITUTION_CHARACTER.equals(key)) {
-            if (node.substitutionNode == null) {
-                node.substitutionNode = new SubstitutionNode();
-            }
-            node.substitutionNode.accept(this);
-            return;
-        }
-        if (PathNode.WILDCARD_CHARACTER.equals(key)) {
-            if (node.wildCardNode == null) {
-                node.wildCardNode = new WildCardNode();
-            }
-            node.wildCardNode.accept(this);
-            return;
-        }
-        this.setChildNodePermissions(node, key);
-    }
-
-    @Override
-    public void visit(SubstitutionNode node) {
-        if (this.artifactPath.hasNext()) {
-            this.setChildNodePermissions(node, this.artifactPath.next());
-        }
-    }
-
-    @Override
-    public void visit(WildCardNode node) {
-        if (this.artifactPath.hasNext()) {
-            this.artifactPath.next();
-            this.setChildNodePermissions(node, this.artifactPath.getCurrentPath());
-        }
+        super.visit(node);
     }
 }

Modified: ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/PermissionsGatherer.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/PermissionsGatherer.java?rev=897746&r1=897745&r2=897746&view=diff
==============================================================================
--- ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/PermissionsGatherer.java
(original)
+++ ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/PermissionsGatherer.java
Mon Jan 11 03:39:08 2010
@@ -18,74 +18,24 @@
  *******************************************************************************/
 package org.ofbiz.context;
 
-import java.util.Map;
-
 import org.ofbiz.context.PathNode.BranchNode;
-import org.ofbiz.context.PathNode.SubstitutionNode;
-import org.ofbiz.context.PathNode.WildCardNode;
-
-public class PermissionsGatherer implements PathNodeVisitor {
-    protected ArtifactPath artifactPath;
-    protected final PathNode node;
-    protected OFBizPermission permission;
 
-    public PermissionsGatherer(PathNode node) {
-        this.node = node;
-    }
+public class PermissionsGatherer extends TreeWalker {
+    protected final OFBizPermission permission;
 
-    public void gatherPermissions(ArtifactPath artifactPath, OFBizPermission permission)
{
-        this.artifactPath = artifactPath;
+    public PermissionsGatherer(PathNode node, OFBizPermission permission) {
+        super(node);
         this.permission = permission;
-        this.node.accept(this);
     }
 
-    protected void getChildNodePermissions(PathNode node, String key) {
-        if (node.childNodes != null) {
-            PathNode childNode = node.childNodes.get(key.toUpperCase());
-            if (childNode != null) {
-                childNode.accept(this);
-            }
-        }
+    public void gatherPermissions(ArtifactPath artifactPath) {
+        this.permission.reset();
+        super.walkTree(artifactPath);
     }
 
     @Override
     public void visit(BranchNode node) {
         this.permission.accumulatePermissions(node.permission);
-        if (this.artifactPath.hasNext()) {
-            String key = this.artifactPath.next();
-            if (node.substitutionNode != null) {
-                this.artifactPath.saveState();
-                node.substitutionNode.accept(this);
-                this.artifactPath.restoreState();
-            }
-            if (node.wildCardNode != null) {
-                this.artifactPath.saveState();
-                node.wildCardNode.accept(this);
-                this.artifactPath.restoreState();
-            }
-            this.getChildNodePermissions(node, key);
-        }
-    }
-
-    @Override
-    public void visit(SubstitutionNode node) {
-        if (this.artifactPath.hasNext()) {
-            this.getChildNodePermissions(node, this.artifactPath.next());
-        }
+        super.visit(node);
     }
-
-    @Override
-    public void visit(WildCardNode node) {
-        if (this.artifactPath.hasNext() && node.childNodes != null) {
-            this.artifactPath.next();
-            String currentPath = this.artifactPath.getCurrentPath().toUpperCase();
-            for (Map.Entry<String, PathNode> entry : node.childNodes.entrySet()) {
-                if (currentPath.endsWith(entry.getKey())) {
-                    entry.getValue().accept(this);
-                    return;
-                }
-            }
-        }
-    }
-
 }

Added: ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/TreeBuilder.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/TreeBuilder.java?rev=897746&view=auto
==============================================================================
--- ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/TreeBuilder.java
(added)
+++ ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/TreeBuilder.java
Mon Jan 11 03:39:08 2010
@@ -0,0 +1,91 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *******************************************************************************/
+package org.ofbiz.context;
+
+import javolution.util.FastMap;
+
+import org.ofbiz.context.PathNode.BranchNode;
+import org.ofbiz.context.PathNode.SubstitutionNode;
+import org.ofbiz.context.PathNode.WildCardNode;
+
+public class TreeBuilder implements PathNodeVisitor {
+
+    protected final PathNode node;
+    protected ArtifactPath artifactPath;
+
+    public TreeBuilder(PathNode node) {
+        this.node = node;
+    }
+
+    public void build(ArtifactPath artifactPath) {
+        this.artifactPath = artifactPath;
+        this.node.accept(this);
+    }
+
+    protected void addChildNode(PathNode node, String key) {
+        if (node.childNodes == null) {
+            node.childNodes = FastMap.newInstance();
+        }
+        key = key.toUpperCase();
+        PathNode childNode = node.childNodes.get(key);
+        if (childNode == null) {
+            childNode = PathNode.getInstance(this.artifactPath);
+            node.childNodes.put(key, childNode);
+        }
+        childNode.accept(this);
+    }
+
+    @Override
+    public void visit(BranchNode node) {
+        if (!this.artifactPath.hasNext()) {
+            return;
+        }
+        String key = this.artifactPath.next();
+        if (PathNode.SUBSTITUTION_CHARACTER.equals(key)) {
+            if (node.substitutionNode == null) {
+                node.substitutionNode = new SubstitutionNode();
+            }
+            node.substitutionNode.accept(this);
+            return;
+        }
+        if (PathNode.WILDCARD_CHARACTER.equals(key)) {
+            if (node.wildCardNode == null) {
+                node.wildCardNode = new WildCardNode();
+            }
+            node.wildCardNode.accept(this);
+            return;
+        }
+        this.addChildNode(node, key);
+    }
+
+    @Override
+    public void visit(SubstitutionNode node) {
+        if (this.artifactPath.hasNext()) {
+            this.addChildNode(node, this.artifactPath.next());
+        }
+    }
+
+    @Override
+    public void visit(WildCardNode node) {
+        if (this.artifactPath.hasNext()) {
+            this.artifactPath.next();
+            this.addChildNode(node, this.artifactPath.getCurrentPath());
+        }
+    }
+}

Propchange: ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/TreeBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/TreeBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Date Rev Author URL Id

Propchange: ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/TreeBuilder.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/TreeStringBuilder.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/TreeStringBuilder.java?rev=897746&r1=897745&r2=897746&view=diff
==============================================================================
--- ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/TreeStringBuilder.java
(original)
+++ ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/TreeStringBuilder.java
Mon Jan 11 03:39:08 2010
@@ -61,8 +61,7 @@
             }
             this.stringBuilder.append("[");
             this.stringBuilder.append(node.permission);
-            this.stringBuilder.append("]");
-            this.stringBuilder.append("\n");
+            this.stringBuilder.append("]\n");
         }
         if (node.substitutionNode != null) {
             node.substitutionNode.accept(this);

Added: ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/TreeWalker.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/TreeWalker.java?rev=897746&view=auto
==============================================================================
--- ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/TreeWalker.java
(added)
+++ ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/TreeWalker.java
Mon Jan 11 03:39:08 2010
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *******************************************************************************/
+package org.ofbiz.context;
+
+import java.util.Map;
+
+import org.ofbiz.context.PathNode.BranchNode;
+import org.ofbiz.context.PathNode.SubstitutionNode;
+import org.ofbiz.context.PathNode.WildCardNode;
+
+public class TreeWalker implements PathNodeVisitor {
+    protected ArtifactPath artifactPath;
+    protected final PathNode node;
+
+    public TreeWalker(PathNode node) {
+        this.node = node;
+    }
+
+    @Override
+    public void visit(BranchNode node) {
+        if (this.artifactPath.hasNext()) {
+            String key = this.artifactPath.next();
+            if (node.substitutionNode != null) {
+                this.artifactPath.saveState();
+                node.substitutionNode.accept(this);
+                this.artifactPath.restoreState();
+            }
+            if (node.wildCardNode != null) {
+                this.artifactPath.saveState();
+                node.wildCardNode.accept(this);
+                this.artifactPath.restoreState();
+            }
+            this.visitChildNode(node, key);
+        }
+    }
+
+    @Override
+    public void visit(SubstitutionNode node) {
+        if (this.artifactPath.hasNext()) {
+            this.visitChildNode(node, this.artifactPath.next());
+        }
+    }
+
+    @Override
+    public void visit(WildCardNode node) {
+        if (this.artifactPath.hasNext() && node.childNodes != null) {
+            this.artifactPath.next();
+            String currentPath = this.artifactPath.getCurrentPath().toUpperCase();
+            for (Map.Entry<String, PathNode> entry : node.childNodes.entrySet()) {
+                if (currentPath.endsWith(entry.getKey())) {
+                    entry.getValue().accept(this);
+                    return;
+                }
+            }
+        }
+    }
+
+    protected void visitChildNode(PathNode node, String key) {
+        if (node.childNodes != null) {
+            PathNode childNode = node.childNodes.get(key.toUpperCase());
+            if (childNode != null) {
+                childNode.accept(this);
+            }
+        }
+    }
+
+    public void walkTree(ArtifactPath artifactPath) {
+        this.artifactPath = artifactPath;
+        this.node.accept(this);
+    }
+
+}

Propchange: ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/TreeWalker.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/TreeWalker.java
------------------------------------------------------------------------------
    svn:keywords = Date Rev Author URL Id

Propchange: ofbiz/branches/executioncontext20091231/framework/context/src/org/ofbiz/context/TreeWalker.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message