/* license-start * * Copyright (C) 2008 - 2013 Crispico, <http://www.crispico.com/>. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation version 3. * * This program 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 General Public License for more details, at <http://www.gnu.org/licenses/>. * * Contributors: * Crispico - Initial API and implementation * * license-end */ /** * <copyright> * </copyright> * * $Id$ */ package org.flowerplatform.web.entity.impl; import java.util.Collection; import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.common.notify.NotificationChain; import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EClass; import org.eclipse.emf.ecore.InternalEObject; import org.eclipse.emf.ecore.impl.ENotificationImpl; import org.eclipse.emf.ecore.util.EObjectWithInverseResolvingEList; import org.eclipse.emf.ecore.util.InternalEList; import org.flowerplatform.web.entity.EntityPackage; import org.flowerplatform.web.entity.Group; import org.flowerplatform.web.entity.GroupUser; import org.flowerplatform.web.entity.ISecurityEntity; import org.flowerplatform.web.entity.Organization; import org.flowerplatform.web.entity.User; /** * <!-- begin-user-doc --> * An implementation of the model object '<em><b>Group</b></em>'. * <!-- end-user-doc --> * <p> * The following features are implemented: * <ul> * <li>{@link org.flowerplatform.web.entity.impl.GroupImpl#getOrganization <em>Organization</em>}</li> * <li>{@link org.flowerplatform.web.entity.impl.GroupImpl#getGroupUsers <em>Group Users</em>}</li> * </ul> * </p> * * @generated */ public class GroupImpl extends NamedEntityImpl implements Group { /** * The cached value of the '{@link #getOrganization() <em>Organization</em>}' reference. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @see #getOrganization() * @generated * @ordered */ protected Organization organization; /** * The cached value of the '{@link #getGroupUsers() <em>Group Users</em>}' reference list. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @see #getGroupUsers() * @generated * @ordered */ protected EList<GroupUser> groupUsers; /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected GroupImpl() { super(); } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override protected EClass eStaticClass() { return EntityPackage.Literals.GROUP; } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public Organization getOrganization() { if (organization != null && organization.eIsProxy()) { InternalEObject oldOrganization = (InternalEObject)organization; organization = (Organization)eResolveProxy(oldOrganization); if (organization != oldOrganization) { if (eNotificationRequired()) eNotify(new ENotificationImpl(this, Notification.RESOLVE, EntityPackage.GROUP__ORGANIZATION, oldOrganization, organization)); } } return organization; } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public Organization basicGetOrganization() { return organization; } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public NotificationChain basicSetOrganization(Organization newOrganization, NotificationChain msgs) { Organization oldOrganization = organization; organization = newOrganization; if (eNotificationRequired()) { ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, EntityPackage.GROUP__ORGANIZATION, oldOrganization, newOrganization); if (msgs == null) msgs = notification; else msgs.add(notification); } return msgs; } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void setOrganization(Organization newOrganization) { if (newOrganization != organization) { NotificationChain msgs = null; if (organization != null) msgs = ((InternalEObject)organization).eInverseRemove(this, EntityPackage.ORGANIZATION__GROUPS, Organization.class, msgs); if (newOrganization != null) msgs = ((InternalEObject)newOrganization).eInverseAdd(this, EntityPackage.ORGANIZATION__GROUPS, Organization.class, msgs); msgs = basicSetOrganization(newOrganization, msgs); if (msgs != null) msgs.dispatch(); } else if (eNotificationRequired()) eNotify(new ENotificationImpl(this, Notification.SET, EntityPackage.GROUP__ORGANIZATION, newOrganization, newOrganization)); } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public EList<GroupUser> getGroupUsers() { if (groupUsers == null) { groupUsers = new EObjectWithInverseResolvingEList<GroupUser>(GroupUser.class, this, EntityPackage.GROUP__GROUP_USERS, EntityPackage.GROUP_USER__GROUP); } return groupUsers; } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated NOT * @author Mariana */ public boolean contains(final ISecurityEntity securityEntity) { boolean includes = false; if (securityEntity instanceof User) { User user = (User) securityEntity; if (ALL.equals(getName())) { includes = true; } else { for (GroupUser groupUser: getGroupUsers()) { if (user.equals(groupUser.getUser())) { includes = true; break; } } } } else if (securityEntity instanceof Group) { includes = GroupImpl.this.equals(securityEntity); } return includes; } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @SuppressWarnings("unchecked") @Override public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) { switch (featureID) { case EntityPackage.GROUP__ORGANIZATION: if (organization != null) msgs = ((InternalEObject)organization).eInverseRemove(this, EntityPackage.ORGANIZATION__GROUPS, Organization.class, msgs); return basicSetOrganization((Organization)otherEnd, msgs); case EntityPackage.GROUP__GROUP_USERS: return ((InternalEList<InternalEObject>)(InternalEList<?>)getGroupUsers()).basicAdd(otherEnd, msgs); } return super.eInverseAdd(otherEnd, featureID, msgs); } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) { switch (featureID) { case EntityPackage.GROUP__ORGANIZATION: return basicSetOrganization(null, msgs); case EntityPackage.GROUP__GROUP_USERS: return ((InternalEList<?>)getGroupUsers()).basicRemove(otherEnd, msgs); } return super.eInverseRemove(otherEnd, featureID, msgs); } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public Object eGet(int featureID, boolean resolve, boolean coreType) { switch (featureID) { case EntityPackage.GROUP__ORGANIZATION: if (resolve) return getOrganization(); return basicGetOrganization(); case EntityPackage.GROUP__GROUP_USERS: return getGroupUsers(); } return super.eGet(featureID, resolve, coreType); } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @SuppressWarnings("unchecked") @Override public void eSet(int featureID, Object newValue) { switch (featureID) { case EntityPackage.GROUP__ORGANIZATION: setOrganization((Organization)newValue); return; case EntityPackage.GROUP__GROUP_USERS: getGroupUsers().clear(); getGroupUsers().addAll((Collection<? extends GroupUser>)newValue); return; } super.eSet(featureID, newValue); } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public void eUnset(int featureID) { switch (featureID) { case EntityPackage.GROUP__ORGANIZATION: setOrganization((Organization)null); return; case EntityPackage.GROUP__GROUP_USERS: getGroupUsers().clear(); return; } super.eUnset(featureID); } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public boolean eIsSet(int featureID) { switch (featureID) { case EntityPackage.GROUP__ORGANIZATION: return organization != null; case EntityPackage.GROUP__GROUP_USERS: return groupUsers != null && !groupUsers.isEmpty(); } return super.eIsSet(featureID); } } //GroupImpl