| /** |
| * <copyright> |
| * |
| * Copyright (c) 2005, 2013 IBM Corporation and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * IBM - Initial API and implementation |
| * |
| * </copyright> |
| * |
| * $Id: WriterImpl.java,v 1.4 2007/02/20 17:41:55 emerks Exp $ |
| */ |
| package org.eclipse.emf.parsley.examples.library.impl; |
| |
| |
| |
| import java.util.Collection; |
| |
| 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.util.EObjectWithInverseResolvingEList; |
| import org.eclipse.emf.ecore.util.InternalEList; |
| import org.eclipse.emf.parsley.examples.library.Book; |
| import org.eclipse.emf.parsley.examples.library.EXTLibraryPackage; |
| import org.eclipse.emf.parsley.examples.library.Writer; |
| |
| |
| |
| /** |
| * <!-- begin-user-doc --> |
| * An implementation of the model object '<em><b>Writer</b></em>'. |
| * <!-- end-user-doc --> |
| * <p> |
| * The following features are implemented: |
| * </p> |
| * <ul> |
| * <li>{@link org.eclipse.emf.parsley.examples.library.impl.WriterImpl#getName <em>Name</em>}</li> |
| * <li>{@link org.eclipse.emf.parsley.examples.library.impl.WriterImpl#getBooks <em>Books</em>}</li> |
| * </ul> |
| * |
| * @generated |
| */ |
| public class WriterImpl extends PersonImpl implements Writer |
| { |
| /** |
| * The default value of the '{@link #getName() <em>Name</em>}' attribute. |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @see #getName() |
| * @generated |
| * @ordered |
| */ |
| protected static final String NAME_EDEFAULT = null; |
| |
| /** |
| * The cached value of the '{@link #getBooks() <em>Books</em>}' reference list. |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @see #getBooks() |
| * @generated |
| * @ordered |
| */ |
| protected EList<Book> books; |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| protected WriterImpl() |
| { |
| super(); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| protected EClass eStaticClass() |
| { |
| return EXTLibraryPackage.Literals.WRITER; |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated NOT |
| */ |
| public String getName() |
| { |
| if (getFirstName() == null) |
| { |
| if (getLastName() == null) |
| { |
| return ""; //$NON-NLS-1$ |
| } |
| else |
| { |
| return getLastName(); |
| } |
| } |
| else if (getLastName() == null) |
| { |
| return getFirstName(); |
| } |
| else |
| { |
| StringBuffer result = new StringBuffer(); |
| |
| result.append(getFirstName()).append(' ').append(getLastName()); |
| |
| return result.toString(); |
| } |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated NOT |
| */ |
| public void setName(String newName) |
| { |
| if (newName == null || newName.length() == 0) |
| { |
| setFirstName(null); |
| setLastName(null); |
| } |
| else |
| { |
| int comma = newName.indexOf(','); |
| if (comma < 0) |
| { |
| comma = newName.indexOf(' '); |
| } |
| |
| if (comma >= 0) |
| { |
| setFirstName(newName.substring(0, comma).trim()); |
| setLastName(newName.substring(comma + 1).trim()); |
| } |
| else |
| { |
| setFirstName(newName); |
| setLastName(null); |
| } |
| } |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| public EList<Book> getBooks() |
| { |
| if (books == null) { |
| books = new EObjectWithInverseResolvingEList<Book>(Book.class, this, EXTLibraryPackage.WRITER__BOOKS, EXTLibraryPackage.BOOK__AUTHOR); |
| } |
| return books; |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @SuppressWarnings("unchecked") |
| @Override |
| public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) |
| { |
| switch (featureID) { |
| case EXTLibraryPackage.WRITER__BOOKS: |
| return ((InternalEList<InternalEObject>)(InternalEList<?>)getBooks()).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 EXTLibraryPackage.WRITER__BOOKS: |
| return ((InternalEList<?>)getBooks()).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 EXTLibraryPackage.WRITER__NAME: |
| return getName(); |
| case EXTLibraryPackage.WRITER__BOOKS: |
| return getBooks(); |
| } |
| 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 EXTLibraryPackage.WRITER__NAME: |
| setName((String)newValue); |
| return; |
| case EXTLibraryPackage.WRITER__BOOKS: |
| getBooks().clear(); |
| getBooks().addAll((Collection<? extends Book>)newValue); |
| return; |
| } |
| super.eSet(featureID, newValue); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| public void eUnset(int featureID) |
| { |
| switch (featureID) { |
| case EXTLibraryPackage.WRITER__NAME: |
| setName(NAME_EDEFAULT); |
| return; |
| case EXTLibraryPackage.WRITER__BOOKS: |
| getBooks().clear(); |
| return; |
| } |
| super.eUnset(featureID); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| public boolean eIsSet(int featureID) |
| { |
| switch (featureID) { |
| case EXTLibraryPackage.WRITER__NAME: |
| return NAME_EDEFAULT == null ? getName() != null : !NAME_EDEFAULT.equals(getName()); |
| case EXTLibraryPackage.WRITER__BOOKS: |
| return books != null && !books.isEmpty(); |
| } |
| return super.eIsSet(featureID); |
| } |
| |
| } //WriterImpl |