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

com.google.security.fences.config.NamedFence Maven / Gradle / Ivy

Go to download

Augments Java's access control by checking that a Maven Project and all its dependencies conform to a policy that specifies which classes/packages can link to which others.

There is a newer version: 1.9-beta
Show newest version
package com.google.security.fences.config;

import java.util.Locale;

import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

import com.google.common.base.Preconditions;

abstract class NamedFence extends Fence {
  private String name;

  public String getName() { return name; }

  public void setName(String newName) {
    this.name = Preconditions.checkNotNull(newName);
  }

  @Override
  String getKey() {
    return name;
  }

  @Override
  public void check() throws EnforcerRuleException {
    super.check();
    if (name == null) {
      throw new EnforcerRuleException(
          getClass().getSimpleName().replaceFirst("Fence$", "")
          .toLowerCase(Locale.ENGLISH)
          + " is missing a name");
    }
  }

  @Override
  public String toString() {
    String type = getClass().getSimpleName().replaceFirst("Fence$", "")
        .toLowerCase(Locale.ENGLISH);
    return "{" + type + " " + name + "}";
  }

  @Override
  void fleshOutEffectiveConfiguration(Element el) {
    Document doc = el.getOwnerDocument();
    Element nameElement = doc.createElement("name");
    nameElement.appendChild(doc.createTextNode(name));
    el.appendChild(nameElement);
    super.fleshOutEffectiveConfiguration(el);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy