001/* 002 * (C) Copyright 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Nuxeo - initial API and implementation 018 * 019 * $Id$ 020 */ 021 022package org.nuxeo.ecm.core.api.impl; 023 024import java.util.ArrayList; 025import java.util.List; 026 027import org.nuxeo.ecm.core.api.NuxeoGroup; 028 029/** 030 * @author <a href="mailto:glefter@nuxeo.com">George Lefter</a> 031 */ 032public class NuxeoGroupImpl implements NuxeoGroup { 033 034 private static final long serialVersionUID = -69828664399387083L; 035 036 private final List<String> users; 037 038 private final List<String> groups; 039 040 private final List<String> parentGroups; 041 042 private String name; 043 044 private String label; 045 046 public NuxeoGroupImpl(String name) { 047 if (name == null) { 048 throw new IllegalArgumentException("group name cannot be null"); 049 } 050 this.name = name.trim(); 051 label = name.trim(); 052 users = new ArrayList<String>(); 053 groups = new ArrayList<String>(); 054 parentGroups = new ArrayList<String>(); 055 } 056 057 public NuxeoGroupImpl(String name, String label) { 058 this(name); 059 this.label = label; 060 } 061 062 @Override 063 public List<String> getMemberUsers() { 064 return users; 065 } 066 067 @Override 068 public List<String> getMemberGroups() { 069 return groups; 070 } 071 072 @Override 073 public List<String> getParentGroups() { 074 return parentGroups; 075 } 076 077 @Override 078 public void setMemberUsers(List<String> users) { 079 if (users == null) { 080 throw new IllegalArgumentException("member users list cannot be null"); 081 } 082 this.users.clear(); 083 this.users.addAll(users); 084 } 085 086 @Override 087 public void setMemberGroups(List<String> groups) { 088 if (groups == null) { 089 throw new IllegalArgumentException("member groups list cannot be null"); 090 } 091 this.groups.clear(); 092 this.groups.addAll(groups); 093 } 094 095 @Override 096 public void setParentGroups(List<String> groups) { 097 if (groups == null) { 098 throw new IllegalArgumentException("parent groups list cannot be null"); 099 } 100 parentGroups.clear(); 101 parentGroups.addAll(groups); 102 } 103 104 @Override 105 public String getName() { 106 return name; 107 } 108 109 @Override 110 public void setName(String name) { 111 this.name = name; 112 } 113 114 @Override 115 public String getLabel() { 116 return this.label; 117 } 118 119 @Override 120 public void setLabel(String label) { 121 this.label = label; 122 } 123 124 @Override 125 public boolean equals(Object other) { 126 if (other == this) { 127 return true; 128 } 129 if (other instanceof NuxeoGroupImpl) { 130 return name.equals(((NuxeoGroupImpl) other).name); 131 } 132 return false; 133 } 134 135 @Override 136 public int hashCode() { 137 return name.hashCode(); 138 } 139 140 @Override 141 public String toString() { 142 return name; 143 } 144 145}