[webbeans-commits] Webbeans SVN: r2953 - in ri/trunk: impl/src/main/java/org/jboss/webbeans/util/collections and 1 other directories.
webbeans-commits at lists.jboss.org
webbeans-commits at lists.jboss.org
Thu Jul 2 11:27:33 EDT 2009
Author: pete.muir at jboss.org
Date: 2009-07-02 11:27:32 -0400 (Thu, 02 Jul 2009)
New Revision: 2953
Added:
ri/trunk/impl/src/main/java/org/jboss/webbeans/ManagerAttachedIterable.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/util/collections/AbstractIterator.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/util/collections/ForwardingIterable.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/util/collections/ForwardingIterator.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/util/collections/Iterables.java
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/deployment/structure/Cat.java
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/deployment/structure/Horse.java
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/util/collections/Iterators.java
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/deployment/structure/AccessibleManagerResolutionTest.java
Log:
Support ignoring cyclic dependencies in accessible archives
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java 2009-07-02 03:53:41 UTC (rev 2952)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java 2009-07-02 15:27:32 UTC (rev 2953)
@@ -29,6 +29,7 @@
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -97,6 +98,8 @@
import org.jboss.webbeans.util.Observers;
import org.jboss.webbeans.util.Proxies;
import org.jboss.webbeans.util.Reflections;
+import org.jboss.webbeans.util.collections.ForwardingIterable;
+import org.jboss.webbeans.util.collections.Iterables;
import org.jboss.webbeans.util.collections.Iterators;
import org.jboss.webbeans.util.collections.multi.ConcurrentListHashMultiMap;
import org.jboss.webbeans.util.collections.multi.ConcurrentListMultiMap;
@@ -243,14 +246,10 @@
private transient final List<EventObserver<?>> observers;
/*
- * These data structures represent the beans, decorators, interceptors,
- * namespaces and observers *accessible* from this bean deployment archive
- * activity
+ * These data structures represent the managers *accessible* from this bean
+ * deployment archive activity
*/
- private transient final Set<Iterable<Iterable<Bean<?>>>> accessibleBeans;
- private transient final Set<Iterable<Iterable<DecoratorBean<?>>>> accessibleDecorators;
- private transient final Set<Iterable<Iterable<String>>> accessibleNamespaces;
- private transient final Set<Iterable<Iterable<EventObserver<?>>>> accessibleObservers;
+ private transient final HashSet<BeanManagerImpl> accessibleManagers;
/*
* This data structures represents child activities for this activity, it is
@@ -367,23 +366,16 @@
this.ids = ids;
this.id = ids.incrementAndGet();
- // Set up the structures to store accessible beans etc.
+ // Set up the structure to store accessible managers in
+ this.accessibleManagers = new HashSet<BeanManagerImpl>();
- this.accessibleBeans = new HashSet<Iterable<Iterable<Bean<?>>>>();
- this.accessibleDecorators = new HashSet<Iterable<Iterable<DecoratorBean<?>>>>();
- this.accessibleNamespaces = new HashSet<Iterable<Iterable<String>>>();
- this.accessibleObservers = new HashSet<Iterable<Iterable<EventObserver<?>>>>();
- // Add this bean deployment archvies beans etc. to the accessible
- add(accessibleBeans, beans);
- add(accessibleDecorators, decorators);
- add(accessibleNamespaces, namespaces);
- add(accessibleObservers, observers);
- this.beanResolver = new TypeSafeBeanResolver<Bean<?>>(this, Iterators.concat(getAccessibleBeans()));
- this.decoratorResolver = new TypeSafeDecoratorResolver(this, Iterators.concat(getAccessibleDecorators()));
- this.observerResolver = new TypeSafeObserverResolver(this, Iterators.concat(getAccessibleObservers()));
- this.nameBasedResolver = new NameBasedResolver(this, Iterators.concat(getAccessibleBeans()));
+ // TODO Currently we build the accessible bean list on the fly, we need to set it in stone once bootstrap is finished...
+ this.beanResolver = new TypeSafeBeanResolver<Bean<?>>(this, createDynamicAccessibleIterable(Transform.BEAN));
+ this.decoratorResolver = new TypeSafeDecoratorResolver(this, createDynamicAccessibleIterable(Transform.DECORATOR_BEAN));
+ this.observerResolver = new TypeSafeObserverResolver(this, createDynamicAccessibleIterable(Transform.EVENT_OBSERVER));
+ this.nameBasedResolver = new NameBasedResolver(this, createDynamicAccessibleIterable(Transform.BEAN));
this.webbeansELResolver = new WebBeansELResolverImpl(this);
this.childActivities = new CopyOnWriteArraySet<BeanManagerImpl>();
@@ -397,40 +389,123 @@
};
}
- private static <X> void add(Collection<Iterable<Iterable<X>>> collection, Iterable<X> instance)
+ private <T> Set<Iterable<T>> buildAccessibleClosure(Collection<BeanManagerImpl> hierarchy, Transform<T> transform)
{
- Collection<Iterable<X>> c = new ArrayList<Iterable<X>>();
- c.add(instance);
- collection.add(c);
+ Set<Iterable<T>> result = new HashSet<Iterable<T>>();
+ hierarchy.add(this);
+ result.add(transform.transform(this));
+ for (BeanManagerImpl beanManager : accessibleManagers)
+ {
+ // Only add if we aren't already in the tree (remove cycles)
+ if (!hierarchy.contains(beanManager))
+ {
+ result.addAll(beanManager.buildAccessibleClosure(new ArrayList<BeanManagerImpl>(hierarchy), transform));
+ }
+ }
+ return result;
}
- public void addAccessibleBeanManager(BeanManagerImpl accessibleBeanManager)
+ private <T> Iterable<T> createDynamicAccessibleIterable(final Transform<T> transform)
{
- accessibleBeans.add(accessibleBeanManager.getAccessibleBeans());
- accessibleDecorators.add(accessibleBeanManager.getAccessibleDecorators());
- accessibleNamespaces.add(accessibleBeanManager.getAccessibleNamespaces());
- accessibleObservers.add(accessibleBeanManager.getAccessibleObservers());
+ return new Iterable<T>()
+ {
+
+ public Iterator<T> iterator()
+ {
+ Set<Iterable<T>> iterable = buildAccessibleClosure(new ArrayList<BeanManagerImpl>(), transform);
+ return Iterators.concat(Iterators.transform(iterable.iterator(), Iterables.<T>iteratorTransform()));
+ }
+
+ };
}
- protected Iterable<Iterable<Bean<?>>> getAccessibleBeans()
+ private <T> Iterable<T> createStaticAccessibleIterable(final Transform<T> transform)
{
- return Iterators.concat(accessibleBeans);
+ Set<Iterable<T>> iterable = buildAccessibleClosure(new ArrayList<BeanManagerImpl>(), transform);
+ return Iterables.concat(iterable);
}
- protected Iterable<Iterable<String>> getAccessibleNamespaces()
+ private static interface Transform<T>
{
- return Iterators.concat(accessibleNamespaces);
+
+ public static Transform<Bean<?>> BEAN = new Transform<Bean<?>>()
+ {
+
+ public Iterable<Bean<?>> transform(BeanManagerImpl beanManager)
+ {
+ return beanManager.getBeans();
+ }
+
+ };
+
+ public static Transform<DecoratorBean<?>> DECORATOR_BEAN = new Transform<DecoratorBean<?>>()
+ {
+
+ public Iterable<DecoratorBean<?>> transform(BeanManagerImpl beanManager)
+ {
+ return beanManager.getDecorators();
+ }
+
+ };
+
+ public static Transform<EventObserver<?>> EVENT_OBSERVER = new Transform<EventObserver<?>>()
+ {
+
+ public Iterable<EventObserver<?>> transform(BeanManagerImpl beanManager)
+ {
+ return beanManager.getObservers();
+ }
+
+ };
+
+ public static Transform<String> NAMESPACE = new Transform<String>()
+ {
+
+ public Iterable<String> transform(BeanManagerImpl beanManager)
+ {
+ return beanManager.getNamespaces();
+ }
+
+ };
+
+ public Iterable<T> transform(BeanManagerImpl beanManager);
+
}
- protected Iterable<Iterable<DecoratorBean<?>>> getAccessibleDecorators()
+ public void addAccessibleBeanManager(BeanManagerImpl accessibleBeanManager)
{
- return Iterators.concat(accessibleDecorators);
+ accessibleManagers.add(accessibleBeanManager);
}
- protected Iterable<Iterable<EventObserver<?>>> getAccessibleObservers()
+ private static class ManagerAttachedIterable<X> extends ForwardingIterable<X>
{
- return Iterators.concat(accessibleObservers);
+
+ private final BeanManagerImpl beanManager;
+ private final Iterable<X> iterable;
+
+ public ManagerAttachedIterable(BeanManagerImpl beanManager, Iterable<X> iterable)
+ {
+ this.beanManager = beanManager;
+ this.iterable = iterable;
+ }
+
+ public BeanManagerImpl getBeanManager()
+ {
+ return beanManager;
+ }
+
+ @Override
+ protected Iterable<X> delegate()
+ {
+ return iterable;
+ }
+
}
+
+ protected Set<BeanManagerImpl> getAccessibleManagers()
+ {
+ return accessibleManagers;
+ }
/**
* Set up the enabled deployment types, if none are specified by the user,
@@ -1179,7 +1254,7 @@
// TODO I don't like this lazy init
if (rootNamespace == null)
{
- rootNamespace = new Namespace(Iterators.concat(getAccessibleNamespaces()));
+ rootNamespace = new Namespace(createDynamicAccessibleIterable(Transform.NAMESPACE));
}
return rootNamespace;
}
Added: ri/trunk/impl/src/main/java/org/jboss/webbeans/ManagerAttachedIterable.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/ManagerAttachedIterable.java (rev 0)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/ManagerAttachedIterable.java 2009-07-02 15:27:32 UTC (rev 2953)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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.jboss.webbeans;
+
+import org.jboss.webbeans.util.collections.ForwardingIterable;
+
+class ManagerAttachedIterable<X> extends ForwardingIterable<X>
+{
+
+ private final BeanManagerImpl beanManager;
+ private final Iterable<X> iterable;
+
+ public ManagerAttachedIterable(BeanManagerImpl beanManager, Iterable<X> iterable)
+ {
+ this.beanManager = beanManager;
+ this.iterable = iterable;
+ }
+
+ public BeanManagerImpl getBeanManager()
+ {
+ return beanManager;
+ }
+
+ @Override
+ protected Iterable<X> delegate()
+ {
+ return iterable;
+ }
+
+}
\ No newline at end of file
Property changes on: ri/trunk/impl/src/main/java/org/jboss/webbeans/ManagerAttachedIterable.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/impl/src/main/java/org/jboss/webbeans/util/collections/AbstractIterator.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/util/collections/AbstractIterator.java (rev 0)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/util/collections/AbstractIterator.java 2009-07-02 15:27:32 UTC (rev 2953)
@@ -0,0 +1,184 @@
+/*
+ * Copyright (C) 2007 Google Inc.
+ *
+ * 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.jboss.webbeans.util.collections;
+
+import java.util.NoSuchElementException;
+
+/**
+ * This class provides a skeletal implementation of the {@code Iterator}
+ * interface, to make this interface easier to implement for certain types of
+ * data sources.
+ *
+ * <p>
+ * {@code Iterator} requires its implementations to support querying the
+ * end-of-data status!
without changing the iterator's state, using the
+ * {@link #hasNext} method. But many data sources, such as
+ * {@link java.io.Reader#read()}), do not expose this information; the only way
+ * to discover whether there is any data left is by trying to retrieve it. These
+ * types of data sources are ordinarily difficult to write iterators for. But
+ * using this class, one must implement only the {@link #computeNext} method,
+ * and invoke the {@link #endOfData} method when appropriate.
+ *
+ * <p>
+ * Another example is an iterator that skips over null elements in a backing
+ * iterator. This could be implemented as:
+ *
+ * <pre>
+ * @code
+ * public static Iterator<String> skipNulls(final Iterator<String> in) {
+ * return new AbstractIterator<String>() {
+ * protected String computeNext() {
+ * while (in.hasNext()) {
+ * String s = in.next();
+ * if (s != null) {
+ * return s;
+ * }
!
+ * }
+ * return endOfData();
+ * }
+ * !
};
+
* }}
+ * </pre>
+ *
+ * This class supports iterators that include null elements.
+ *
+ * @author Kevin Bourrillion
+ */
+public abstract class AbstractIterator<T> extends UnmodifiableIterator<T>
+{
+ private State state = State.NOT_READY;
+
+ private enum State
+ {
+ /** We have computed the next element and haven't returned it yet. */
+ READY,
+
+ /** We haven't yet computed or have already returned the element. */
+ NOT_READY,
+
+ /** We have reached the end of the data and are finished. */
+ DONE,
+
+ /** We've suffered an exception and are kaput. */
+ FAILED,
+ }
+
+ private T next;
+
+ /**
+ * Returns the next element. <b>Note:</b> the implementation must call
+ * {@link #endOfData()} when there are no elements left in the iteration.
+ * Failure to do so could result in an infinite loop.
+ *
+ * <p>
+ * The initial invocation of {@link #hasNext()} or {@link #next()} calls this
+ * method, as!
does the first invocation of {@code hasNext} or {@code next}
+ * following each successful call to {@code next}. Once the implementation
+ * either invokes {@code endOfData} or throws an exception, {@code
+ * computeNext} is guaranteed to never be called again.
+ *
+ * <p>
+ * If this method throws an exception, it will propagate outward to the
+ * {@code hasNext} or {@code next} invocation that invoked this method. Any
+ * further attempts to use the iterator will result in an
+ * {@link IllegalStateException}.
+ *
+ * <p>
+ * The implementation of this method many not invoke the {@code hasNext},
+ * {@code next}, or {@link #peek()} methods on this instance; if it does, an
+ * {@code IllegalStateException} will result.
+ *
+ * @return the next element if there was one. If {@code endOfData} was called
+ * during execution, the return value will be ignored.
+ * @throws RuntimeException if any unrecoverable err!
or happens. This
+ * exception will propagate ou!
tward to
the {@code hasNext()},
+ * {@code next()}, or {@code peek()} invocation that invoked this
+ * method. Any further attempts to use the iterator will result in
+ * an {@link IllegalStateException}.
+ */
+ protected abstract T computeNext();
+
+ /**
+ * Implementations of {@code computeNext} <b>must</b> invoke this method when
+ * there are no elements left in the iteration.
+ *
+ * @return {@code null}; a convenience so your {@link #computeNext}
+ * implementation can use the simple statement {@code return
+ * endOfData();}
+ */
+ protected final T endOfData()
+ {
+ state = State.DONE;
+ return null;
+ }
+
+ public final boolean hasNext()
+ {
+ if (state == State.FAILED)
+ {
+ throw new IllegalStateException();
+ }
+ switch (state)
+ {
+ case DONE:
+ return false;
+ case READY:
+ return true;
+ default:
+ !
}
+ return tryToComputeNext();
+ }
+
+ private boolean tryToComputeNext()
+ {
+ state = State.FAILED; // temporary pessimism
+ next = computeNext();
+ if (state != State.DONE)
+ {
+ state = State.READY;
+ return true;
+ }
+ return false;
+ }
+
+ public final T next()
+ {
+ if (!hasNext())
+ {
+ throw new NoSuchElementException();
+ }
+ state = State.NOT_READY;
+ return next;
+ }
+
+ /**
+ * Returns the next element in the iteration without advancing the iteration,
+ * according to the contract of {@link PeekingIterator#peek()}.
+ *
+ * <p>
+ * Implementations of {@code AbstractIterator} that wish to expose this
+ * functionality should implement {@code PeekingIterator}.
+ */
+ public final T peek()
+ {
+ if (!hasNext())
+ {
+ throw new NoSuchElementException();
+ }
+ return next;
+ }
+}
Property changes on: ri/trunk/impl/src/main/java/org/jboss/webbeans/util/collections/AbstractIterator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/impl/src/main/java/org/jboss/webbeans/util/collections/ForwardingIterable.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/util/collections/ForwardingIterable.java (rev 0)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/util/collections/ForwardingIterable.java 2009-07-02 15:27:32 UTC (rev 2953)
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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.jboss.webbeans.util.collections;
+
+import java.util.Iterator;
+
+/**
+ * @author pmuir
+ *
+ */
+public abstract class ForwardingIterable<T> implements java.lang.Iterable<T>
+{
+
+ public Iterator<T> iterator()
+ {
+ return delegate().iterator();
+ }
+
+ protected abstract Iterable<T> delegate();
+
+}
Property changes on: ri/trunk/impl/src/main/java/org/jboss/webbeans/util/collections/ForwardingIterable.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/impl/src/main/java/org/jboss/webbeans/util/collections/ForwardingIterator.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/util/collections/ForwardingIterator.java (rev 0)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/util/collections/ForwardingIterator.java 2009-07-02 15:27:32 UTC (rev 2953)
@@ -0,0 +1,63 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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.jboss.webbeans.util.collections;
+
+import java.util.Iterator;
+
+/**
+ * @author pmuir
+ *
+ */
+public abstract class ForwardingIterator<E> implements Iterator<E>
+{
+
+ protected abstract Iterator<E> delegate();
+
+ public boolean hasNext()
+ {
+ return hasNext();
+ }
+
+ public E next()
+ {
+ return next();
+ }
+
+ public void remove()
+ {
+ remove();
+ }
+
+ @Override
+ public String toString()
+ {
+ return delegate().toString();
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return delegate().hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ return delegate().equals(obj);
+ }
+
+}
Property changes on: ri/trunk/impl/src/main/java/org/jboss/webbeans/util/collections/ForwardingIterator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/impl/src/main/java/org/jboss/webbeans/util/collections/Iterables.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/util/collections/Iterables.java (rev 0)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/util/collections/Iterables.java 2009-07-02 15:27:32 UTC (rev 2953)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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.jboss.webbeans.util.collections;
+
+import java.util.Iterator;
+
+/**
+ * @author pmuir
+ *
+ */
+public class Iterables
+{
+
+ private Iterables() {}
+
+ public static <T> Iterators.Function<Iterable<? extends T>, Iterator<? extends T>> iteratorTransform()
+ {
+ return new Iterators.Function<Iterable<? extends T>, Iterator<? extends T>>()
+ {
+
+ public Iterator<? extends T> apply(Iterable<? extends T> from)
+ {
+ return from.iterator();
+ }
+
+ };
+ }
+
+ public static <T> Iterable<T> concat(final Iterable<? extends Iterable<? extends T>> inputs)
+ {
+ return new Iterable<T>()
+ {
+
+ public Iterator<T> iterator()
+ {
+ return Iterators.concat(Iterators.transform(inputs.iterator(), Iterables.<T>iteratorTransform()));
+ }
+
+ };
+ }
+
+}
Property changes on: ri/trunk/impl/src/main/java/org/jboss/webbeans/util/collections/Iterables.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/util/collections/Iterators.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/util/collections/Iterators.java 2009-07-02 03:53:41 UTC (rev 2952)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/util/collections/Iterators.java 2009-07-02 15:27:32 UTC (rev 2953)
@@ -51,20 +51,7 @@
{
return (UnmodifiableIterator<T>) EMPTY_ITERATOR;
}
-
- public static <T> Iterable<T> concat(final Iterable<? extends Iterable<? extends T>> inputs)
- {
- return new Iterable<T>()
- {
- public Iterator<T> iterator()
- {
- return concat(inputs.iterator());
- }
-
- };
- }
-
/**
* Combines multiple iterators into a single iterator. The returned iterator
* iterates across the elements of each iterator in {@code inputs}. The input
@@ -75,29 +62,29 @@
* input iterator supports it. The methods of the returned iterator may throw
* {@code NullPointerException} if any of the input iterators are null.
*/
- public static <T> Iterator<T> concat(final Iterator<? extends Iterable<? extends T>> inputs)
+ public static <E> Iterator<E> concat(final Iterator<? extends Iterator<? extends E>> inputs)
{
if (inputs == null)
{
throw new NullPointerException();
}
- return new Iterator<T>()
+ return new Iterator<E>()
{
- Iterator<? extends T> current = emptyIterator();
- Iterator<? extends T> removeFrom;
+ Iterator<? extends E> current = emptyIterator();
+ Iterator<? extends E> removeFrom;
public boolean hasNext()
{
boolean currentHasNext;
while (!(currentHasNext = current.hasNext()) && inputs.hasNext())
{
- current = inputs.next().iterator();
+ current = inputs.next();
}
return currentHasNext;
}
- public T next()
+ public E next()
{
if (!hasNext())
{
@@ -119,4 +106,35 @@
};
}
+ public static interface Function<F, T>
+ {
+ public T apply(F from);
+ }
+
+ public static <F, T> Iterator<T> transform(final Iterator<F> fromIterator, final Function<? super F, ? extends T> function)
+ {
+ if (function == null)
+ {
+ throw new IllegalStateException();
+ }
+ return new Iterator<T>()
+ {
+ public boolean hasNext()
+ {
+ return fromIterator.hasNext();
+ }
+
+ public T next()
+ {
+ F from = fromIterator.next();
+ return function.apply(from);
+ }
+
+ public void remove()
+ {
+ fromIterator.remove();
+ }
+ };
+ }
+
}
Modified: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/deployment/structure/AccessibleManagerResolutionTest.java
===================================================================
--- ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/deployment/structure/AccessibleManagerResolutionTest.java 2009-07-02 03:53:41 UTC (rev 2952)
+++ ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/deployment/structure/AccessibleManagerResolutionTest.java 2009-07-02 15:27:32 UTC (rev 2953)
@@ -55,25 +55,44 @@
}
@Test
- public void testAccessibleTwoLevels()
+ public void testAccessibleThreeLevelsWithMultiple()
{
BeanManagerImpl root = BeanManagerImpl.newRootManager(services);
BeanManagerImpl child = BeanManagerImpl.newRootManager(services);
+ BeanManagerImpl child1 = BeanManagerImpl.newRootManager(services);
BeanManagerImpl grandchild = BeanManagerImpl.newRootManager(services);
+ BeanManagerImpl greatGrandchild = BeanManagerImpl.newRootManager(services);
+ child.addAccessibleBeanManager(root);
+ grandchild.addAccessibleBeanManager(child1);
grandchild.addAccessibleBeanManager(child);
- child.addAccessibleBeanManager(root);
+ addBean(greatGrandchild, Cat.class);
+ greatGrandchild.addAccessibleBeanManager(grandchild);
addBean(root, Cow.class);
addBean(child, Chicken.class);
addBean(grandchild, Pig.class);
+ addBean(child1, Horse.class);
assert root.getBeans(Pig.class).size() == 0;
assert root.getBeans(Chicken.class).size() == 0;
assert root.getBeans(Cow.class).size() == 1;
+ assert root.getBeans(Horse.class).size() == 0;
+ assert root.getBeans(Cat.class).size() == 0;
assert child.getBeans(Pig.class).size() == 0;
assert child.getBeans(Chicken.class).size() == 1;
assert child.getBeans(Cow.class).size() == 1;
+ assert child.getBeans(Horse.class).size() == 0;
+ assert child.getBeans(Cat.class).size() == 0;
+ assert child1.getBeans(Cow.class).size() == 0;
+ assert child1.getBeans(Horse.class).size() == 1;
assert grandchild.getBeans(Pig.class).size() == 1;
assert grandchild.getBeans(Chicken.class).size() == 1;
assert grandchild.getBeans(Cow.class).size() == 1;
+ assert grandchild.getBeans(Horse.class).size() ==1;
+ assert grandchild.getBeans(Cat.class).size() == 0;
+ assert greatGrandchild.getBeans(Pig.class).size() == 1;
+ assert greatGrandchild.getBeans(Chicken.class).size() == 1;
+ assert greatGrandchild.getBeans(Cow.class).size() == 1;
+ assert greatGrandchild.getBeans(Horse.class).size() ==1;
+ assert greatGrandchild.getBeans(Cat.class).size() == 1;
}
@Test
@@ -99,4 +118,28 @@
assert grandchild.getBeans(Cow.class).size() == 1;
}
+ @Test
+ public void testCircular()
+ {
+ BeanManagerImpl root = BeanManagerImpl.newRootManager(services);
+ BeanManagerImpl child = BeanManagerImpl.newRootManager(services);
+ BeanManagerImpl grandchild = BeanManagerImpl.newRootManager(services);
+ grandchild.addAccessibleBeanManager(child);
+ child.addAccessibleBeanManager(root);
+ grandchild.addAccessibleBeanManager(root);
+ root.addAccessibleBeanManager(grandchild);
+ addBean(root, Cow.class);
+ addBean(child, Chicken.class);
+ addBean(grandchild, Pig.class);
+ assert root.getBeans(Pig.class).size() == 1;
+ assert root.getBeans(Chicken.class).size() == 1;
+ assert root.getBeans(Cow.class).size() == 1;
+ assert child.getBeans(Pig.class).size() == 1;
+ assert child.getBeans(Chicken.class).size() == 1;
+ assert child.getBeans(Cow.class).size() == 1;
+ assert grandchild.getBeans(Pig.class).size() == 1;
+ assert grandchild.getBeans(Chicken.class).size() == 1;
+ assert grandchild.getBeans(Cow.class).size() == 1;
+ }
+
}
Added: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/deployment/structure/Cat.java
===================================================================
--- ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/deployment/structure/Cat.java (rev 0)
+++ ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/deployment/structure/Cat.java 2009-07-02 15:27:32 UTC (rev 2953)
@@ -0,0 +1,26 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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.jboss.webbeans.test.unit.deployment.structure;
+
+/**
+ * @author pmuir
+ *
+ */
+public class Cat
+{
+
+}
Property changes on: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/deployment/structure/Cat.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/deployment/structure/Horse.java
===================================================================
--- ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/deployment/structure/Horse.java (rev 0)
+++ ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/deployment/structure/Horse.java 2009-07-02 15:27:32 UTC (rev 2953)
@@ -0,0 +1,26 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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.jboss.webbeans.test.unit.deployment.structure;
+
+/**
+ * @author pmuir
+ *
+ */
+public class Horse
+{
+
+}
Property changes on: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/deployment/structure/Horse.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
More information about the weld-commits
mailing list