All Downloads are FREE. Search and download functionalities are using the official Maven repository.

shaded.com.google.inject.spi.ProvisionListenerBinding Maven / Gradle / Ivy

There is a newer version: 4.1.3
Show newest version
/*
 * Copyright (C) 2011 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 shaded.shaded.com.google.inject.spi;

import shaded.shaded.com.google.common.collect.ImmutableList;
import shaded.shaded.com.google.inject.Binder;
import shaded.shaded.com.google.inject.Binding;
import shaded.shaded.com.google.inject.matcher.Matcher;
import java.util.List;

/**
 * Binds keys (picked using a Matcher) to a provision listener. Listeners are created explicitly in
 * a module using {@link Binder#bindListener(Matcher, ProvisionListener...)} statements:
 *
 * @author [email protected] (Sam Berlin)
 * @since 4.0
 */
public final class ProvisionListenerBinding implements Element {

  private final Object source;
  private final Matcher> bindingMatcher;
  private final List listeners;

  ProvisionListenerBinding(
      Object source, Matcher> bindingMatcher, ProvisionListener[] listeners) {
    this.source = source;
    this.bindingMatcher = bindingMatcher;
    this.listeners = ImmutableList.copyOf(listeners);
  }

  /** Returns the registered listeners. */
  public List getListeners() {
    return listeners;
  }

  /**
   * Returns the binding matcher which chooses which bindings the listener should be notified of.
   */
  public Matcher> getBindingMatcher() {
    return bindingMatcher;
  }

  @Override
  public Object getSource() {
    return source;
  }

  @Override
  public  R acceptVisitor(ElementVisitor visitor) {
    return visitor.visit(this);
  }

  @Override
  public void applyTo(Binder binder) {
    binder
        .withSource(getSource())
        .bindListener(bindingMatcher, listeners.toArray(new ProvisionListener[listeners.size()]));
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy