Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 2474 invoked from network); 14 Feb 2005 07:15:15 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 14 Feb 2005 07:15:15 -0000 Received: (qmail 34843 invoked by uid 500); 14 Feb 2005 07:15:13 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 34816 invoked by uid 500); 14 Feb 2005 07:15:13 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 34803 invoked by uid 500); 14 Feb 2005 07:15:13 -0000 Received: (qmail 34799 invoked by uid 99); 14 Feb 2005 07:15:13 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Sun, 13 Feb 2005 23:15:13 -0800 Received: (qmail 2428 invoked by uid 65534); 14 Feb 2005 07:15:12 -0000 Message-ID: <20050214071512.2427.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mailer: svnmailer-1.0.0-dev Date: Mon, 14 Feb 2005 07:15:11 -0000 Subject: svn commit: r153729 - jakarta/commons/proper/digester/branches/digester2/src/java/org/apache/commons/digester2/SupplementaryRuleManager.java To: commons-cvs@jakarta.apache.org From: ozeigermann@apache.org X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Author: ozeigermann Date: Sun Feb 13 23:15:11 2005 New Revision: 153729 URL: http://svn.apache.org/viewcvs?view=3Drev&rev=3D153729 Log: - Takes account of the explicitely unmodifiable list=20 returned by DefaultRuleManager and does a wild mixture=20 of caching and concatenating the list returned from=20 DefaultRuleManager and its own list of supplementary actions. - Inherits from FallbackRuleManager Modified: jakarta/commons/proper/digester/branches/digester2/src/java/org/apache/= commons/digester2/SupplementaryRuleManager.java Modified: jakarta/commons/proper/digester/branches/digester2/src/java/org/a= pache/commons/digester2/SupplementaryRuleManager.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/digester/branches= /digester2/src/java/org/apache/commons/digester2/SupplementaryRuleManager.j= ava?view=3Ddiff&r1=3D153728&r2=3D153729 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/proper/digester/branches/digester2/src/java/org/apache/= commons/digester2/SupplementaryRuleManager.java (original) +++ jakarta/commons/proper/digester/branches/digester2/src/java/org/apache/= commons/digester2/SupplementaryRuleManager.java Sun Feb 13 23:15:11 2005 @@ -19,17 +19,19 @@ package org.apache.commons.digester2; =20 =20 +import java.util.AbstractList; +import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; -import java.util.ArrayList; +import java.util.Map; =20 =20 /** * @see DefaultRuleManager */ =20 -public class SupplementaryRuleManager extends DefaultRuleManager { +public class SupplementaryRuleManager extends FallbackRuleManager { =20 public static boolean matches(String path, String pathToMatch) { if (pathToMatch.charAt(0) =3D=3D '/') { @@ -57,39 +59,25 @@ return false; } =20 - protected final Action supplementaryAction; - protected final Action fallbackAction; + protected final List supplementaryActions; + protected final Map path2ActionsMap =3D new HashMap(); =20 - protected final List fallbackList =3D new ArrayList(); + public SupplementaryRuleManager(List supplementaryActions) { + this.supplementaryActions =3D supplementaryActions; + } =20 - public SupplementaryRuleManager(Action supplementaryAction) { - this(supplementaryAction, null); + public SupplementaryRuleManager(List supplementaryActions, List fallba= ckActions) { + super(fallbackActions); + this.supplementaryActions =3D supplementaryActions; } =20 - public SupplementaryRuleManager(Action supplementaryAction, Action fal= lbackAction) { - =20 - if (fallbackAction =3D=3D null && supplementaryAction =3D=3D null)= { - throw new IllegalArgumentException( - "Both parameters set to null makes no sense. Use Defau= ltRuleManager instead."); - } - - this.supplementaryAction =3D supplementaryAction; - this.fallbackAction =3D fallbackAction; - - if (fallbackAction !=3D null) { - fallbackList.add(fallbackAction); - } - - if (supplementaryAction !=3D null) { - fallbackList.add(supplementaryAction); - } + public SupplementaryRuleManager() { + this(new ArrayList()); } =20 public SupplementaryRuleManager(SupplementaryRuleManager manager) { - this(manager.supplementaryAction, manager.fallbackAction); - this.namespaces =3D (HashMap) manager.namespaces.clone(); - this.actions =3D (ArrayList) manager.actions.clone(); - this.rules =3D (MultiHashMap) manager.rules.clone(); + super(manager); + this.supplementaryActions =3D manager.supplementaryActions; } =20 /** @@ -99,31 +87,73 @@ return new SupplementaryRuleManager(this); } =20 + public void addRule(String pattern, Action action) throws InvalidRuleE= xception { + super.addRule(pattern, action); + invalidateCache(); + } + + public void addFallbackAction(Action action) { + super.addFallbackAction(action); + invalidateCache(); + } + + public void addSupplementaryAction(Action action) { + supplementaryActions.add(action); + invalidateCache(); + } + /** * @see DefaultRuleManager#getMatchingActions(String) */ public List getMatchingActions(String path) { + =20 + List completeList =3D (List) path2ActionsMap.get(path); + if (completeList !=3D null) { + return completeList; + }=20 + =20 List actionList =3D super.getMatchingActions(path); - if (actionList =3D=3D Collections.EMPTY_LIST) { - return fallbackList; - } - if (supplementaryAction !=3D null) { - actionList.add(supplementaryAction); + if (supplementaryActions.size() !=3D 0) { + if (actionList =3D=3D Collections.EMPTY_LIST) { + completeList =3D Collections.unmodifiableList(supplementar= yActions); + } else { + completeList =3D new ReadOnlyConcatList(actionList, supple= mentaryActions); + } + } else { + completeList =3D actionList; } - return actionList; + + path2ActionsMap.put(path, completeList); + return completeList; } =20 - /** - * @return Returns the fallbackAction. - */ - public Action getFallbackAction() { - return fallbackAction; + protected void invalidateCache() { + path2ActionsMap.clear(); } + =20 + protected static class ReadOnlyConcatList extends AbstractList { + + final List left; + final List right; + final int border; + + ReadOnlyConcatList(List left, List right) { + this.left =3D left; + this.right =3D right; + this.border =3D left.size(); + } + + public Object get(int index) { + if (index >=3D border) { + return right.get(index - border); + } else { + return left.get(index); + } + } + + public int size() { + return left.size() + right.size(); + } =20 - /** - * @return Returns the supplementaryAction. - */ - public Action getSupplementaryAction() { - return supplementaryAction; } -} +} \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org