Return-Path: Delivered-To: apmail-cocoon-cvs-archive@www.apache.org Received: (qmail 57909 invoked from network); 30 Mar 2004 16:18:24 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 30 Mar 2004 16:18:24 -0000 Received: (qmail 79269 invoked by uid 500); 30 Mar 2004 16:17:57 -0000 Delivered-To: apmail-cocoon-cvs-archive@cocoon.apache.org Received: (qmail 79194 invoked by uid 500); 30 Mar 2004 16:17:56 -0000 Mailing-List: contact cvs-help@cocoon.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@cocoon.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list cvs@cocoon.apache.org Received: (qmail 79136 invoked by uid 500); 30 Mar 2004 16:17:56 -0000 Delivered-To: apmail-cocoon-2.2-cvs@apache.org Received: (qmail 79099 invoked from network); 30 Mar 2004 16:17:56 -0000 Received: from unknown (HELO minotaur.apache.org) (209.237.227.194) by daedalus.apache.org with SMTP; 30 Mar 2004 16:17:56 -0000 Received: (qmail 57394 invoked by uid 1023); 30 Mar 2004 16:17:58 -0000 Date: 30 Mar 2004 16:17:58 -0000 Message-ID: <20040330161758.57393.qmail@minotaur.apache.org> From: pier@apache.org To: cocoon-2.2-cvs@apache.org Subject: cvs commit: cocoon-2.2/src/kernel/org/apache/cocoon/kernel/resolution CompoundResolver.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N pier 2004/03/30 08:17:58 Added: src/kernel/org/apache/cocoon/kernel/resolution CompoundResolver.java Log: The "CompoundResolver" will be used to recursively resolve a resource in an instance dependancy tree. Revision Changes Path 1.1 cocoon-2.2/src/kernel/org/apache/cocoon/kernel/resolution/CompoundResolver.java Index: CompoundResolver.java =================================================================== /* ========================================================================== * * * * Copyright 2004 The Apache Software Foundation. * * * * Licensed 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.apache.cocoon.kernel.resolution; import java.util.AbstractSet; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; /** *

A {@link CompoundResolver} is an implementation of the {@link Resolver} * interface delegating resource resolution to other {@link Resolver}s.

* *

This instance is backed up by an {@link ArrayList}.

* * @author Pier Fumagalli * @author VNU Business Publications * @version 1.0 (CVS $Revision: 1.1 $) */ public class CompoundResolver extends AbstractSet implements Resolver { /**

Our {@link List}.

*/ private List list = new ArrayList(); /** *

Create a new {@link CompoundResolver} instance backed up by another * {@link Resolver} instance.

*/ public CompoundResolver() { super(); } /** *

Resolve a specified name into a {@link Resource}.

* * @param name a non null {@link String} identifying the resource name. * @return a {@link Resource} instance or null if not found. */ public Resource resolve(String name) { Resolver r[] = (Resolver[])list.toArray(new Resolver[list.size()]); for (int x = 0; x < r.length; x ++) { Resource s = r[x].resolve(name); if (s != null) return(s); } return(null); } /** *

Returns an {@link Iterator} over all {@link Resolver} elements * contained in this {@link CompoundResolver}.

* * @return a non null {@link Iterator} instance. */ public Iterator iterator() { return(this.list.iterator()); } /** *

Returns the number of all {@link Resolver} elements contained in this * {@link CompoundResolver}.

* * @return a non negative number. */ public int size() { return(this.list.size()); } /** *

Checks whether this {@link CompoundResolver} contains the specified * object instance.

* *

Note that this implementation does not check on sub-elements * implementing the {@link Collection} iterface, it is therefore non * recursive.

* * @see #add(Object) * @return true if this {@link CompoundResolver} contains the * specified {@link Object} directly, false otherwise. */ public boolean contains(Object object) { return(this.list.contains(object)); } /** *

Return a {@link Resolver} array of all elements contained in this * {@link CompoundResolver}.

* * @return an non null array castable to a {@link Resolver} array. */ public Object[] toArray() { return(this.list.toArray(new Resolver[this.list.size()])); } /** *

Return an array of all elements contained in this * {@link CompoundResolver}.

* * @param array the array into which the elements of the collection are to * be stored, if it is big enough; otherwise, a new array of * the same runtime type is allocated for this purpose. * @return an non null array castable to a {@link Resolver} array. * @throws ArrayStoreException if the runtime type of the specified array * is not a supertype of the runtime type of every element in this * collection. */ public Object[] toArray(Object array[]) { return(this.list.toArray(array)); } /** *

Ensures that this {@link CompoundResolver} contains the specified * element.

* *

Note that this method will check all {@link Resolver}s contained in * this {@link CompoundResolver}, and recursively the contents of all those * elements also implementing the {@link Collection} interface. * * @param object a {@link Object} castable to {@link Resolver}. * @return true if this instance changed in result of the call. * @throws ClassCastException if the specified {@link Object} is not an * instance of {@link Resolver}. */ public boolean add(Object object) { if (object == null) return(false); Resolver resolver = (Resolver) object; Iterator iterator = this.list.iterator(); while (iterator.hasNext()) { Resolver current = (Resolver) iterator.next(); if (current == resolver) return(false); if (!(current instanceof Collection)) continue; if (((Collection)current).contains(resolver)) return(false); } return(this.list.add(resolver)); } /** *

Ensures that this {@link CompoundResolver} does not contain the * specified element.

* *

Note that this implementation does not check on sub-elements * implementing the {@link Collection} iterface, it is therefore non * recursive.

* * @param object a {@link Object} to check. * @return true if this instance changed in result of the call. */ public boolean remove(Object object) { if (object == null) return(false); return(this.list.remove(object)); } /** *

Removes all of the elements from this {@link CompoundResolver}.

*/ public void clear() { this.list.clear(); } }