package org.eclipse.equinox.log;
import java.security.Permission;
import java.security.PermissionCollection;
import java.util.Enumeration;
import java.util.NoSuchElementException;
public final class LogPermissionCollection extends PermissionCollection {
private static final long serialVersionUID = -1955409691185916778L;
LogPermission logPermission;
@Override
public void add(Permission permission) {
if (!(permission instanceof LogPermission))
throw new IllegalArgumentException("invalid permission: " + permission);
if (isReadOnly())
throw new SecurityException("attempt to add a LogPermission to a readonly LogPermissionCollection");
if (permission != null)
logPermission = (LogPermission) permission;
}
@Override
public Enumeration<Permission> elements() {
return new Enumeration<Permission>() {
private boolean hasMore = (logPermission != null);
@Override
public boolean hasMoreElements() {
return hasMore;
}
@Override
public Permission nextElement() {
if (hasMore) {
hasMore = false;
return logPermission;
}
throw new NoSuchElementException();
}
};
}
@Override
public boolean implies(Permission permission) {
return logPermission != null && logPermission.implies(permission);
}
}