Exemple #1
0
 @Override
 public Project installFacet(final Facet facet) {
   facet.init(this);
   if (!facet.isInstalled() && !hasFacet(facet.getClass())) {
     facet.install();
     facets.add(facet);
   } else if (!hasFacet(facet.getClass())) {
     registerFacet(facet);
   }
   return this;
 }
Exemple #2
0
  @Override
  @SuppressWarnings("unchecked")
  public <F extends Facet> List<F> getFacets(final Class<F> type) {
    List<F> result = new ArrayList<F>();

    for (Facet facet : facets) {
      if ((facet != null) && facet.getClass().isAssignableFrom(type)) {
        result.add((F) facet);
      }
    }

    return result;
  }
Exemple #3
0
 @Override
 @SuppressWarnings("unchecked")
 public <F extends Facet> F getFacet(final Class<F> type) {
   Facet result = null;
   for (Facet facet : facets) {
     if ((facet != null) && type.isAssignableFrom(facet.getClass())) {
       result = facet;
       break;
     }
   }
   if (result == null) {
     throw new FacetNotFoundException(
         "The requested facet of type ["
             + type.getName()
             + "] was not found. The facet is not installed.");
   }
   return (F) result;
 }
Exemple #4
0
  @Override
  public Project registerFacet(final Facet facet) {
    if (facet == null) {
      throw new IllegalArgumentException(
          "Attempted to register 'null' as a Facet; Facets cannot be null.");
    }

    if (facet.getDependencies() != null) {
      for (Class<? extends Facet> type : facet.getDependencies()) {
        if (!hasFacet(type)) {
          throw new IllegalStateException(
              "Attempting to register a Facet that has missing dependencies: ["
                  + facet.getClass().getSimpleName()
                  + " requires -> "
                  + type.getSimpleName()
                  + "]");
        }
      }
    }

    facet.init(this);
    if (facet.isInstalled() && !hasFacet(facet.getClass())) {
      facets.add(facet);
    }
    return this;
  }