Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source
   * Copyright 2008, Red Hat, Inc., 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.weld.resolution;
 
 import static org.jboss.weld.util.cache.LoadingCacheUtils.getCacheValue;
 import static org.jboss.weld.util.reflection.Reflections.cast;
 
 import java.util.List;
 import java.util.Set;
 
 
Implementation of type safe bean resolution

Author(s):
Pete Muir
Marius Bogoevici
Ales Justin
 
 public abstract class TypeSafeResolver<R extends Resolvable, T, C extends Collection<T>> {
 
     private static class ResolvableToBeanCollection<R extends Resolvable, T, C extends Collection<T>> extends CacheLoader<R, C> {
 
         private final TypeSafeResolver<R, T, C> resolver;
 
         private ResolvableToBeanCollection(TypeSafeResolver<R, T, C> resolver) {
             this. = resolver;
         }
 
         public C load(R from) {
         }
 
     }
 
     /*
      * https://issues.jboss.org/browse/WELD-1323
      */
     private static final long RESOLVED_CACHE_UPPER_BOUND;
     private static final long DEFAULT_RESOLVED_CACHE_UPPER_BOUND = 0x100000L;
 
     static {
          = Long.getLong("org.jboss.weld.resolution.cacheSize");
     }
 
     // The resolved injection points
     private final LoadingCache<R, C> resolved;
     // The beans to search
     private final Iterable<? extends T> allBeans;
     private final ResolvableToBeanCollection<R, T, C> resolverFunction;


    
Constructor
 
     public TypeSafeResolver(Iterable<? extends T> allBeans) {
         this. = new ResolvableToBeanCollection<R, T, C>(this);
         this. = allBeans;
     }

    
Reset all cached resolutions
 
     public void clear() {
         this..invalidateAll();
         this..cleanUp();
     }

    
Get the possible beans for the given element

Parameters:
resolvable The resolving criteria
Returns:
An unmodifiable set of matching beans
 
     public C resolve(R resolvableboolean cache) {
         R wrappedResolvable = wrap(resolvable);
         if (cache) {
             return getCacheValue(wrappedResolvable);
        } else {
            return .load(wrappedResolvable);
        }
    }

    
Gets the matching beans for binding criteria from a list of beans

Parameters:
resolvable the resolvable
Returns:
A set of filtered beans
    private Set<T> findMatching(R resolvable) {
        Set<T> result = new HashSet<T>();
        for (T bean : getAllBeans(resolvable)) {
            if (matches(resolvablebean)) {
                result.add(bean);
            }
        }
        return result;
    }
    protected Iterable<? extends T> getAllBeans(R resolvable) {
        return ;
    }
    protected Iterable<? extends T> getAllBeans() {
        return ;
    }
    protected abstract Set<T> filterResult(Set<T> matched);
    protected abstract C sortResult(Set<T> matched);
    protected abstract boolean matches(R resolvable, T t);
    protected C makeResultImmutable(C result) {
        if (result instanceof List<?>) {
            return cast(WeldCollections.immutableList((List<?>) result));
        }
        if (result instanceof Set<?>) {
            return cast(WeldCollections.immutableSet((Set<?>) result));
        }
        throw new IllegalArgumentException("result");
    }

    
allows subclasses to wrap a resolvable before it is resolved
    protected R wrap(R resolvable) {
        return resolvable;
    }
    public boolean isCached(R resolvable) {
        return .getIfPresent(wrap(resolvable)) != null;
    }

    
Gets a string representation

Returns:
A string representation
    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("Resolver\n");
        sb.append("Resolved injection points: ").append(.size()).append('\n');
        return sb.toString();
    }
New to GrepCode? Check out our FAQ X