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

toothpick.configuration.MultipleRootScopeCheckOnConfiguration Maven / Gradle / Ivy

There is a newer version: 3.1.0
Show newest version
package toothpick.configuration;

import toothpick.Scope;

/**
 * Checks that TP scope forest is actually a tree.
 * If a new created scope is a new root outside of the first created tree,
 * it will throw a {@link MultipleRootException}.
 */
class MultipleRootScopeCheckOnConfiguration implements MultipleRootScopeCheckConfiguration {
  private Scope rootScope;

  @Override public synchronized void checkMultipleRootScopes(Scope scope) {
    if (rootScope == null && scope != null) {
      rootScope = scope;
      return;
    }

    if (scope == rootScope) {
      return;
    }

    if (scope.getParentScope() != null) {
      return;
    }

    throw new MultipleRootException(scope);
  }

  @Override public synchronized void onScopeForestReset() {
    rootScope = null;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy