
org.ow2.bonita.identity.impl.GroupImpl Maven / Gradle / Ivy
/**
* Copyright (C) 2007 Bull S. A. S.
* Bull, Rue Jean Jaures, B.P.68, 78340, Les Clayes-sous-Bois
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation
* version 2.1 of the License.
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
* Floor, Boston, MA 02110-1301, USA.
**/
package org.ow2.bonita.identity.impl;
import java.security.Permission;
import java.util.Collections;
import java.util.HashSet;
import java.util.Properties;
import java.util.Set;
import org.ow2.bonita.identity.GroupOp;
import org.ow2.bonita.identity.Membership;
import org.ow2.bonita.identity.UserOp;
/**
* @author "Pierre Vigneras"
* @date Nov 23, 2007
*/
public class GroupImpl implements GroupOp {
/**
*
*/
private static final long serialVersionUID = -92055174610253039L;
// private static final Preferences GLOBAL_PREFERENCES =
// Preferences.userNodeForPackage(GroupImpl.class);
private static GroupImpl root;
protected static void setRoot(final String rootId) {
root = new GroupImpl();
root.setId(rootId);
root.setParent(root);
}
protected static GroupImpl root() {
return root;
}
private Properties properties;
// private Preferences preferences;
private Set permissions;
private GroupOp parent;
private String id;
private Set memberships;
private Set children;
protected GroupImpl() {
init();
} // Required for ROOT creation and persistence.
public GroupImpl(final String id) {
this(id, root);
}
public GroupImpl(final String id, final GroupOp parent) {
init();
// IdentityServiceOp should set the root id using setRoot() before creating
// any instances.
if (root() == null) {
throw new IllegalStateException("Root is undefined! Use setRoot()!");
}
setId(id);
setParent(parent);
}
protected void setId(final String id) {
if (id == null) {
throw new IllegalArgumentException("Null id!");
}
this.id = id;
}
/**
* @param id
*/
private void init() {
this.properties = new Properties();
// this.preferences = GLOBAL_PREFERENCES.node(id);
this.permissions = new HashSet();
this.memberships = new HashSet();
this.children = new HashSet();
}
/*
* (non-Javadoc)
*
* @see org.ow2.bonita.identity.GroupOp#getChildren()
*/
public Set getChildren() {
return children;
}
/*
* (non-Javadoc)
*
* @see org.ow2.bonita.identity.GroupOp#getMemberships()
*/
public Set getMemberships() {
return Collections.unmodifiableSet(memberships);
}
protected void setMemberships(final Set memberships) {
if (memberships == null) {
throw new IllegalArgumentException("Memberships is null!");
}
this.memberships = memberships;
}
/*
* (non-Javadoc)
*
* @see org.ow2.bonita.identity.GroupOp#getId()
*/
public String getId() {
return id;
}
/*
* (non-Javadoc)
*
* @see org.ow2.bonita.identity.GroupOp#getParent()
*/
public GroupOp getParent() {
return parent;
}
/*
* (non-Javadoc)
*
* @see org.ow2.bonita.identity.GroupOp#getPermissions()
*/
public Set getPermissions() {
return new HashSet(permissions);
}
/*
* (non-Javadoc)
*
* @see org.ow2.bonita.identity.GroupOp#getPreferences()
*/
// public Preferences getPreferences() {
// return preferences;
// }
/*
* (non-Javadoc)
*
* @see org.ow2.bonita.identity.GroupOp#getProperties()
*/
public Properties getProperties() {
final Properties result = new Properties();
result.putAll(properties);
return result;
}
/*
* (non-Javadoc)
*
* @see org.ow2.bonita.identity.GroupOp#getRoot()
*/
public GroupOp getRoot() {
return root();
}
protected void setChildren(Set children) {
if (children == null) {
throw new IllegalArgumentException("Children is null!");
}
this.children = children;
}
protected void setParent(GroupOp parent) {
if (parent == null) {
throw new IllegalArgumentException("Parent is null!");
}
this.parent = parent;
parent.getChildren().add(this);
}
public void setPermissions(final Set permissions) {
if (permissions == null) {
throw new IllegalArgumentException("Permissions is null!");
}
this.permissions = permissions;
}
public void setProperties(Properties properties) {
if (properties == null) {
throw new IllegalArgumentException("Properties is null!");
}
this.properties = properties;
}
/*
* (non-Javadoc)
*
* @see
* org.ow2.bonita.identity.GroupOp#hasMember(org.ow2.bonita.identity.UserOp)
*/
public boolean hasMember(UserOp userOp) {
return memberships.contains(new MembershipImpl(userOp, this));
}
public int hashcode() {
return id.hashCode();
}
public boolean equals(Object o) {
if (!(o instanceof GroupImpl)) {
return false;
}
if (id == null) {
return true;
}
return id.equals(((GroupImpl) o).getId());
}
public String toString() {
return this.getClass().getName() + "(" + getId() + ")";
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy