当前位置: 首页>>代码示例>>Java>>正文


Java Matcher类代码示例

本文整理汇总了Java中com.google.inject.matcher.Matcher的典型用法代码示例。如果您正苦于以下问题:Java Matcher类的具体用法?Java Matcher怎么用?Java Matcher使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Matcher类属于com.google.inject.matcher包,在下文中一共展示了Matcher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: bindInterceptor

import com.google.inject.matcher.Matcher; //导入依赖的package包/类
/**
 * Variant of {@link #bindInterceptor(Class, Class...) bindInterceptor} that
 * allows constructor-injection of interceptors described by class, each
 * wrapped by a method interceptor wrapper.
 * @param classMatcher matches classes the interception should apply to.
 *   For example: {@code only(Runnable.class)}.
 * @param methodMatcher matches methods the interception should apply to.
 *   For example: {@code annotatedWith(Transactional.class)}.
 * @param methodInterceptorWrapper a wrapper applied to each of the specified interceptors.
 * @param methodInterceptorClasses chain of
 *   {@link org.aopalliance.intercept.MethodInterceptor MethodInterceptor}s
 *   used to intercept calls, specified by class.
 */
public void bindInterceptor(Matcher<? super Class<?>> classMatcher,
                            Matcher<? super Method> methodMatcher,
                            MethodInterceptorWrapper methodInterceptorWrapper,
                            Class<?>... methodInterceptorClasses)
{
    if (methodInterceptorClasses != null)
    {
        MethodInterceptor[] interceptors = new MethodInterceptor[methodInterceptorClasses.length];
        int i = 0;
        for (Class<?> cls : methodInterceptorClasses)
        {
            if (!MethodInterceptor.class.isAssignableFrom(cls))
            {
                addError("bindInterceptor: %s does not implement MethodInterceptor", cls.getName());
            }
            else
            {
                @SuppressWarnings("unchecked")
                Class<? extends MethodInterceptor> c = (Class<? extends MethodInterceptor>) cls;
                interceptors[i++] = wrap(methodInterceptorWrapper, c);
            }
        }
        bindInterceptor(classMatcher, methodMatcher, interceptors);
    }
}
 
开发者ID:directwebremoting,项目名称:dwr,代码行数:39,代码来源:AbstractModule.java

示例2: interfaceMatcher

import com.google.inject.matcher.Matcher; //导入依赖的package包/类
/**
 * Creates a matcher that will match methods of an interface, optionally excluding inherited
 * methods.
 *
 * @param matchInterface The interface to match.
 * @param declaredMethodsOnly if {@code true} only methods directly declared in the interface
 *                            will be matched, otherwise all methods on the interface are matched.
 * @return A new matcher instance.
 */
public static Matcher<Method> interfaceMatcher(
    Class<?> matchInterface,
    boolean declaredMethodsOnly) {

  Method[] methods =
      declaredMethodsOnly ? matchInterface.getDeclaredMethods() : matchInterface.getMethods();
  final Set<Pair<String, Class<?>[]>> interfaceMethods =
      ImmutableSet.copyOf(Iterables.transform(ImmutableList.copyOf(methods), CANONICALIZE));
  final LoadingCache<Method, Pair<String, Class<?>[]>> cache = CacheBuilder.newBuilder()
      .build(CacheLoader.from(CANONICALIZE));

  return new AbstractMatcher<Method>() {
    @Override
    public boolean matches(Method method) {
      return interfaceMethods.contains(cache.getUnchecked(method));
    }
  };
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:28,代码来源:GuiceUtils.java

示例3: bindExceptionTrap

import com.google.inject.matcher.Matcher; //导入依赖的package包/类
/**
 * Binds an exception trap on all interface methods of all classes bound against an interface.
 * Individual methods may opt out of trapping by annotating with {@link AllowUnchecked}.
 * Only void methods are allowed, any non-void interface methods must explicitly opt out.
 *
 * @param binder The binder to register an interceptor with.
 * @param wrapInterface Interface whose methods should be wrapped.
 * @throws IllegalArgumentException If any of the non-whitelisted interface methods are non-void.
 */
public static void bindExceptionTrap(Binder binder, Class<?> wrapInterface)
    throws IllegalArgumentException {

  Set<Method> disallowed = ImmutableSet.copyOf(Iterables.filter(
      ImmutableList.copyOf(wrapInterface.getMethods()),
      Predicates.and(Predicates.not(IS_WHITELISTED), Predicates.not(VOID_METHOD))));
  Preconditions.checkArgument(disallowed.isEmpty(),
      "Non-void methods must be explicitly whitelisted with @AllowUnchecked: " + disallowed);

  Matcher<Method> matcher =
      Matchers.not(WHITELIST_MATCHER).and(interfaceMatcher(wrapInterface, false));
  binder.bindInterceptor(Matchers.subclassesOf(wrapInterface), matcher,
      new MethodInterceptor() {
        @Override
        public Object invoke(MethodInvocation invocation) throws Throwable {
          try {
            return invocation.proceed();
          } catch (RuntimeException e) {
            LOG.warn("Trapped uncaught exception: " + e, e);
            return null;
          }
        }
      });
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:34,代码来源:GuiceUtils.java

示例4: getInstancesOf

import com.google.inject.matcher.Matcher; //导入依赖的package包/类
/**
 * Returns a collection of all instances matching the given matcher
 * 
 * @param matcher
 *            matches the types to return instances
 * @return a set of objects returned from this injector
 */
public static <T> Set<T> getInstancesOf(Injector injector,
        Matcher<Class> matcher) {
    Set<T> answer = Sets.newHashSet();
    Set<Entry<Key<?>, Binding<?>>> entries = injector.getBindings()
            .entrySet();
    for (Entry<Key<?>, Binding<?>> entry : entries) {
        Key<?> key = entry.getKey();
        Class<?> keyType = getKeyType(key);
        if (keyType != null && matcher.matches(keyType)) {
            Binding<?> binding = entry.getValue();
            Object value = binding.getProvider().get();
            answer.add((T) value);
        }
    }
    return answer;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:24,代码来源:Injectors.java

示例5: getProvidersOf

import com.google.inject.matcher.Matcher; //导入依赖的package包/类
/**
 * Returns a collection of all of the providers matching the given matcher
 * 
 * @param matcher
 *            matches the types to return instances
 * @return a set of objects returned from this injector
 */
public static <T> Set<Provider<T>> getProvidersOf(Injector injector,
        Matcher<Class> matcher) {
    Set<Provider<T>> answer = Sets.newHashSet();
    Set<Entry<Key<?>, Binding<?>>> entries = injector.getBindings()
            .entrySet();
    for (Entry<Key<?>, Binding<?>> entry : entries) {
        Key<?> key = entry.getKey();
        Class<?> keyType = getKeyType(key);
        if (keyType != null && matcher.matches(keyType)) {
            Binding<?> binding = entry.getValue();
            answer.add((Provider<T>) binding.getProvider());
        }
    }
    return answer;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:Injectors.java

示例6: convertToClasses

import com.google.inject.matcher.Matcher; //导入依赖的package包/类
private static void convertToClasses(
    InjectorImpl injector, final Matcher<? super Class<?>> typeMatcher, TypeConverter converter) {
  internalConvertToTypes(
      injector,
      new AbstractMatcher<TypeLiteral<?>>() {
        @Override
        public boolean matches(TypeLiteral<?> typeLiteral) {
          Type type = typeLiteral.getType();
          if (!(type instanceof Class)) {
            return false;
          }
          Class<?> clazz = (Class<?>) type;
          return typeMatcher.matches(clazz);
        }

        @Override
        public String toString() {
          return typeMatcher.toString();
        }
      },
      converter);
}
 
开发者ID:google,项目名称:guice,代码行数:23,代码来源:TypeConverterBindingProcessor.java

示例7: testBindListener

import com.google.inject.matcher.Matcher; //导入依赖的package包/类
public void testBindListener() {
  final Matcher<Object> typeMatcher = Matchers.only(TypeLiteral.get(String.class));
  final TypeListener listener =
      new TypeListener() {
        @Override
        public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) {
          throw new UnsupportedOperationException();
        }
      };

  checkModule(
      new AbstractModule() {
        @Override
        protected void configure() {
          bindListener(typeMatcher, listener);
        }
      },
      new FailingElementVisitor() {
        @Override
        public Void visit(TypeListenerBinding binding) {
          assertSame(typeMatcher, binding.getTypeMatcher());
          assertSame(listener, binding.getListener());
          return null;
        }
      });
}
 
开发者ID:google,项目名称:guice,代码行数:27,代码来源:ElementsTest.java

示例8: convertToClasses

import com.google.inject.matcher.Matcher; //导入依赖的package包/类
private static void convertToClasses(InjectorImpl injector,
    final Matcher<? super Class<?>> typeMatcher, TypeConverter converter) {
  internalConvertToTypes(injector, new AbstractMatcher<TypeLiteral<?>>() {
    public boolean matches(TypeLiteral<?> typeLiteral) {
      Type type = typeLiteral.getType();
      if (!(type instanceof Class)) {
        return false;
      }
      Class<?> clazz = (Class<?>) type;
      return typeMatcher.matches(clazz);
    }

    @Override public String toString() {
      return typeMatcher.toString();
    }
  }, converter);
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:18,代码来源:TypeConverterBindingProcessor.java

示例9: testBindListener

import com.google.inject.matcher.Matcher; //导入依赖的package包/类
public void testBindListener() {
  final Matcher<Object> typeMatcher = Matchers.only(TypeLiteral.get(String.class));
  final TypeListener listener = new TypeListener() {
    public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) {
      throw new UnsupportedOperationException();
    }
  };
  
  checkModule(
      new AbstractModule() {
        protected void configure() {
          bindListener(typeMatcher, listener);
        }
      },

      new FailingElementVisitor() {
        @Override public Void visit(TypeListenerBinding binding) {
          assertSame(typeMatcher, binding.getTypeMatcher());
          assertSame(listener, binding.getListener());
          return null;
        }
      }
  );
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:25,代码来源:ElementsTest.java

示例10: testAddingInterceptors

import com.google.inject.matcher.Matcher; //导入依赖的package包/类
public void testAddingInterceptors() throws NoSuchMethodException {
  final Matcher<Object> buzz = only(C.class.getMethod("buzz"));

  Injector injector = Guice.createInjector(new AbstractModule() {
    @Override protected void configure() {
      bindInterceptor(any(), buzz, prefixInterceptor("ka"));
      bindInterceptor(any(), any(), prefixInterceptor("fe"));

      bindListener(onlyAbcd, new TypeListener() {
        public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) {
          encounter.bindInterceptor(any(), prefixInterceptor("li"));
          encounter.bindInterceptor(buzz, prefixInterceptor("no"));
        }
      });
    }
  });

  // interceptors must be invoked in the order they're bound.
  C c = injector.getInstance(C.class);
  assertEquals("kafelinobuzz", c.buzz());
  assertEquals("felibeep", c.beep());
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:23,代码来源:TypeListenerTest.java

示例11: configure

import com.google.inject.matcher.Matcher; //导入依赖的package包/类
@Override
protected void configure()
{
	// Use interceptor that checks CurrentUser and calls AccessRefuser to deny access
	final MethodInterceptor interceptor = new AuthConstraintMethodInterceptor(getProvider(CurrentUser.class),
	                                                                          config,
	                                                                          calls,
	                                                                          granted,
	                                                                          denied,
	                                                                          authenticatedDenied);


	// Collect all REST service interfaces we implement
	Set<Class<?>> restIfaces = RestResourceRegistry.getResources().stream().map(RestResource:: getResourceClass).collect(
			Collectors.toSet());

	Matcher<Method> matcher = new WebMethodMatcher(restIfaces);

	bindInterceptor(Matchers.any(), matcher, interceptor);
}
 
开发者ID:petergeneric,项目名称:stdlib,代码行数:21,代码来源:AuthConstraintInterceptorModule.java

示例12: convertToClasses

import com.google.inject.matcher.Matcher; //导入依赖的package包/类
private void convertToClasses(final Matcher<? super Class<?>> typeMatcher,
    TypeConverter converter) {
  internalConvertToTypes(new AbstractMatcher<TypeLiteral<?>>() {
    public boolean matches(TypeLiteral<?> typeLiteral) {
      Type type = typeLiteral.getType();
      if (!(type instanceof Class)) {
        return false;
      }
      Class<?> clazz = (Class<?>) type;
      return typeMatcher.matches(clazz);
    }

    @Override public String toString() {
      return typeMatcher.toString();
    }
  }, converter);
}
 
开发者ID:utopiazh,项目名称:google-guice,代码行数:18,代码来源:TypeConverterBindingProcessor.java

示例13: testAddingInterceptors

import com.google.inject.matcher.Matcher; //导入依赖的package包/类
public void testAddingInterceptors() throws NoSuchMethodException {
  final Matcher<Object> buzz = only(C.class.getMethod("buzz"));

  Injector injector = Guice.createInjector(new AbstractModule() {
    protected void configure() {
      bindInterceptor(any(), buzz, prefixInterceptor("ka"));
      bindInterceptor(any(), any(), prefixInterceptor("fe"));

      bindListener(onlyAbcd, new TypeListener() {
        public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) {
          encounter.bindInterceptor(any(), prefixInterceptor("li"));
          encounter.bindInterceptor(buzz, prefixInterceptor("no"));
        }
      });
    }
  });

  // interceptors must be invoked in the order they're bound.
  C c = injector.getInstance(C.class);
  assertEquals("kafelinobuzz", c.buzz());
  assertEquals("felibeep", c.beep());
}
 
开发者ID:utopiazh,项目名称:google-guice,代码行数:23,代码来源:TypeListenerTest.java

示例14: getTransactionClasses

import com.google.inject.matcher.Matcher; //导入依赖的package包/类
private static Set<Class<?>> getTransactionClasses(InjectorConfig config) {
    Set<Class<?>> ret = new HashSet<>();
    {
        Set<String> packages = getPackageNames(config.getTransactionPackages());
        if (isNotNoSize(packages)) {
            final Filter<Class<?>> filter = config.getTransactionClassFilter();
            for (String pkg : packages) {
                final String regex = getPackageRegex(pkg);
                ret.addAll(ResolverUtils.find(new com.brightgenerous.resolver.Matcher() {

                    @Override
                    public boolean matches(Class<?> arg0) {
                        if (arg0.isAnnotation() || arg0.isEnum()) {
                            return false;
                        }
                        if ((filter != null) && !filter.filter(arg0)) {
                            return false;
                        }
                        return arg0.getName().matches(regex);
                    }
                }, pkg));
            }
        }
    }
    return ret;
}
 
开发者ID:brightgenerous,项目名称:brigen-base,代码行数:27,代码来源:InjectorFactory.java

示例15: getMapperClasses

import com.google.inject.matcher.Matcher; //导入依赖的package包/类
private static Set<Class<?>> getMapperClasses(InjectorConfig config) {
    Set<Class<?>> ret = new HashSet<>();
    {
        Set<String> packages = getPackageNames(config.getMapperPackages());
        if (isNotNoSize(packages)) {
            final Filter<Class<?>> filter = config.getMapperClassFilter();
            for (String pkg : packages) {
                final String regex = getPackageRegex(pkg);
                ret.addAll(ResolverUtils.find(new com.brightgenerous.resolver.Matcher() {

                    @Override
                    public boolean matches(Class<?> arg0) {
                        if (arg0.isAnnotation() || arg0.isEnum()) {
                            return false;
                        }
                        if ((filter != null) && !filter.filter(arg0)) {
                            return false;
                        }
                        return arg0.getName().matches(regex);
                    }
                }, pkg));
            }
        }
    }
    return ret;
}
 
开发者ID:brightgenerous,项目名称:brigen-base,代码行数:27,代码来源:InjectorFactory.java


注:本文中的com.google.inject.matcher.Matcher类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。