001    /**
002     * <copyright>
003     * </copyright>
004     *
005     * $Id$
006     */
007    package com.hammurapi.party.impl;
008    
009    import com.hammurapi.party.EMail;
010    import com.hammurapi.party.Party;
011    import com.hammurapi.party.PartyPackage;
012    import com.hammurapi.party.Tag;
013    
014    import java.util.Collection;
015    import java.util.Date;
016    
017    import org.eclipse.emf.common.notify.Notification;
018    import org.eclipse.emf.common.notify.NotificationChain;
019    
020    import org.eclipse.emf.common.util.EList;
021    
022    import org.eclipse.emf.ecore.EClass;
023    import org.eclipse.emf.ecore.InternalEObject;
024    
025    import org.eclipse.emf.ecore.impl.ENotificationImpl;
026    import org.eclipse.emf.ecore.impl.EObjectImpl;
027    
028    import org.eclipse.emf.ecore.util.EObjectContainmentEList;
029    import org.eclipse.emf.ecore.util.EcoreUtil;
030    import org.eclipse.emf.ecore.util.InternalEList;
031    
032    /**
033     * <!-- begin-user-doc -->
034     * An implementation of the model object '<em><b>EMail</b></em>'.
035     * <!-- end-user-doc -->
036     * <p>
037     * The following features are implemented:
038     * <ul>
039     *   <li>{@link com.hammurapi.party.impl.EMailImpl#getTags <em>Tags</em>}</li>
040     *   <li>{@link com.hammurapi.party.impl.EMailImpl#getComment <em>Comment</em>}</li>
041     *   <li>{@link com.hammurapi.party.impl.EMailImpl#getStart <em>Start</em>}</li>
042     *   <li>{@link com.hammurapi.party.impl.EMailImpl#getEnd <em>End</em>}</li>
043     *   <li>{@link com.hammurapi.party.impl.EMailImpl#getCategory <em>Category</em>}</li>
044     *   <li>{@link com.hammurapi.party.impl.EMailImpl#getOwner <em>Owner</em>}</li>
045     *   <li>{@link com.hammurapi.party.impl.EMailImpl#getAddress <em>Address</em>}</li>
046     * </ul>
047     * </p>
048     *
049     * @generated
050     */
051    public class EMailImpl extends EObjectImpl implements EMail {
052            /**
053             * The cached value of the '{@link #getTags() <em>Tags</em>}' containment reference list.
054             * <!-- begin-user-doc -->
055             * <!-- end-user-doc -->
056             * @see #getTags()
057             * @generated
058             * @ordered
059             */
060            protected EList<Tag> tags;
061    
062            /**
063             * The default value of the '{@link #getComment() <em>Comment</em>}' attribute.
064             * <!-- begin-user-doc -->
065             * <!-- end-user-doc -->
066             * @see #getComment()
067             * @generated
068             * @ordered
069             */
070            protected static final String COMMENT_EDEFAULT = null;
071    
072            /**
073             * The cached value of the '{@link #getComment() <em>Comment</em>}' attribute.
074             * <!-- begin-user-doc -->
075             * <!-- end-user-doc -->
076             * @see #getComment()
077             * @generated
078             * @ordered
079             */
080            protected String comment = COMMENT_EDEFAULT;
081    
082            /**
083             * The default value of the '{@link #getStart() <em>Start</em>}' attribute.
084             * <!-- begin-user-doc -->
085             * <!-- end-user-doc -->
086             * @see #getStart()
087             * @generated
088             * @ordered
089             */
090            protected static final Date START_EDEFAULT = null;
091    
092            /**
093             * The cached value of the '{@link #getStart() <em>Start</em>}' attribute.
094             * <!-- begin-user-doc -->
095             * <!-- end-user-doc -->
096             * @see #getStart()
097             * @generated
098             * @ordered
099             */
100            protected Date start = START_EDEFAULT;
101    
102            /**
103             * The default value of the '{@link #getEnd() <em>End</em>}' attribute.
104             * <!-- begin-user-doc -->
105             * <!-- end-user-doc -->
106             * @see #getEnd()
107             * @generated
108             * @ordered
109             */
110            protected static final Date END_EDEFAULT = null;
111    
112            /**
113             * The cached value of the '{@link #getEnd() <em>End</em>}' attribute.
114             * <!-- begin-user-doc -->
115             * <!-- end-user-doc -->
116             * @see #getEnd()
117             * @generated
118             * @ordered
119             */
120            protected Date end = END_EDEFAULT;
121    
122            /**
123             * The default value of the '{@link #getCategory() <em>Category</em>}' attribute.
124             * <!-- begin-user-doc -->
125             * <!-- end-user-doc -->
126             * @see #getCategory()
127             * @generated
128             * @ordered
129             */
130            protected static final String CATEGORY_EDEFAULT = null;
131    
132            /**
133             * The cached value of the '{@link #getCategory() <em>Category</em>}' attribute.
134             * <!-- begin-user-doc -->
135             * <!-- end-user-doc -->
136             * @see #getCategory()
137             * @generated
138             * @ordered
139             */
140            protected String category = CATEGORY_EDEFAULT;
141    
142            /**
143             * The default value of the '{@link #getAddress() <em>Address</em>}' attribute.
144             * <!-- begin-user-doc -->
145             * <!-- end-user-doc -->
146             * @see #getAddress()
147             * @generated
148             * @ordered
149             */
150            protected static final String ADDRESS_EDEFAULT = null;
151    
152            /**
153             * The cached value of the '{@link #getAddress() <em>Address</em>}' attribute.
154             * <!-- begin-user-doc -->
155             * <!-- end-user-doc -->
156             * @see #getAddress()
157             * @generated
158             * @ordered
159             */
160            protected String address = ADDRESS_EDEFAULT;
161    
162            /**
163             * <!-- begin-user-doc -->
164             * <!-- end-user-doc -->
165             * @generated
166             */
167            protected EMailImpl() {
168                    super();
169            }
170    
171            /**
172             * <!-- begin-user-doc -->
173             * <!-- end-user-doc -->
174             * @generated
175             */
176            @Override
177            protected EClass eStaticClass() {
178                    return PartyPackage.Literals.EMAIL;
179            }
180    
181            /**
182             * <!-- begin-user-doc -->
183             * <!-- end-user-doc -->
184             * @generated
185             */
186            public EList<Tag> getTags() {
187                    if (tags == null) {
188                            tags = new EObjectContainmentEList<Tag>(Tag.class, this, PartyPackage.EMAIL__TAGS);
189                    }
190                    return tags;
191            }
192    
193            /**
194             * <!-- begin-user-doc -->
195             * <!-- end-user-doc -->
196             * @generated
197             */
198            public String getComment() {
199                    return comment;
200            }
201    
202            /**
203             * <!-- begin-user-doc -->
204             * <!-- end-user-doc -->
205             * @generated
206             */
207            public void setComment(String newComment) {
208                    String oldComment = comment;
209                    comment = newComment;
210                    if (eNotificationRequired())
211                            eNotify(new ENotificationImpl(this, Notification.SET, PartyPackage.EMAIL__COMMENT, oldComment, comment));
212            }
213    
214            /**
215             * <!-- begin-user-doc -->
216             * <!-- end-user-doc -->
217             * @generated
218             */
219            public Date getStart() {
220                    return start;
221            }
222    
223            /**
224             * <!-- begin-user-doc -->
225             * <!-- end-user-doc -->
226             * @generated
227             */
228            public void setStart(Date newStart) {
229                    Date oldStart = start;
230                    start = newStart;
231                    if (eNotificationRequired())
232                            eNotify(new ENotificationImpl(this, Notification.SET, PartyPackage.EMAIL__START, oldStart, start));
233            }
234    
235            /**
236             * <!-- begin-user-doc -->
237             * <!-- end-user-doc -->
238             * @generated
239             */
240            public Date getEnd() {
241                    return end;
242            }
243    
244            /**
245             * <!-- begin-user-doc -->
246             * <!-- end-user-doc -->
247             * @generated
248             */
249            public void setEnd(Date newEnd) {
250                    Date oldEnd = end;
251                    end = newEnd;
252                    if (eNotificationRequired())
253                            eNotify(new ENotificationImpl(this, Notification.SET, PartyPackage.EMAIL__END, oldEnd, end));
254            }
255    
256            /**
257             * <!-- begin-user-doc -->
258             * <!-- end-user-doc -->
259             * @generated
260             */
261            public String getCategory() {
262                    return category;
263            }
264    
265            /**
266             * <!-- begin-user-doc -->
267             * <!-- end-user-doc -->
268             * @generated
269             */
270            public void setCategory(String newCategory) {
271                    String oldCategory = category;
272                    category = newCategory;
273                    if (eNotificationRequired())
274                            eNotify(new ENotificationImpl(this, Notification.SET, PartyPackage.EMAIL__CATEGORY, oldCategory, category));
275            }
276    
277            /**
278             * <!-- begin-user-doc -->
279             * <!-- end-user-doc -->
280             * @generated
281             */
282            public Party getOwner() {
283                    if (eContainerFeatureID() != PartyPackage.EMAIL__OWNER) return null;
284                    return (Party)eContainer();
285            }
286    
287            /**
288             * <!-- begin-user-doc -->
289             * <!-- end-user-doc -->
290             * @generated
291             */
292            public NotificationChain basicSetOwner(Party newOwner, NotificationChain msgs) {
293                    msgs = eBasicSetContainer((InternalEObject)newOwner, PartyPackage.EMAIL__OWNER, msgs);
294                    return msgs;
295            }
296    
297            /**
298             * <!-- begin-user-doc -->
299             * <!-- end-user-doc -->
300             * @generated
301             */
302            public void setOwner(Party newOwner) {
303                    if (newOwner != eInternalContainer() || (eContainerFeatureID() != PartyPackage.EMAIL__OWNER && newOwner != null)) {
304                            if (EcoreUtil.isAncestor(this, newOwner))
305                                    throw new IllegalArgumentException("Recursive containment not allowed for " + toString());
306                            NotificationChain msgs = null;
307                            if (eInternalContainer() != null)
308                                    msgs = eBasicRemoveFromContainer(msgs);
309                            if (newOwner != null)
310                                    msgs = ((InternalEObject)newOwner).eInverseAdd(this, PartyPackage.PARTY__CONTACT_INFO, Party.class, msgs);
311                            msgs = basicSetOwner(newOwner, msgs);
312                            if (msgs != null) msgs.dispatch();
313                    }
314                    else if (eNotificationRequired())
315                            eNotify(new ENotificationImpl(this, Notification.SET, PartyPackage.EMAIL__OWNER, newOwner, newOwner));
316            }
317    
318            /**
319             * <!-- begin-user-doc -->
320             * <!-- end-user-doc -->
321             * @generated
322             */
323            public String getAddress() {
324                    return address;
325            }
326    
327            /**
328             * <!-- begin-user-doc -->
329             * <!-- end-user-doc -->
330             * @generated
331             */
332            public void setAddress(String newAddress) {
333                    String oldAddress = address;
334                    address = newAddress;
335                    if (eNotificationRequired())
336                            eNotify(new ENotificationImpl(this, Notification.SET, PartyPackage.EMAIL__ADDRESS, oldAddress, address));
337            }
338    
339            /**
340             * <!-- begin-user-doc -->
341             * <!-- end-user-doc -->
342             * @generated NOT
343             */
344            public boolean isEffectiveNow() {
345                    return isEffective(new Date());
346            }
347    
348            /**
349             * <!-- begin-user-doc -->
350             * <!-- end-user-doc -->
351             * @generated NOT
352             */
353            public boolean isEffective(Date date) {
354                    if (getStart()!=null && getStart().after(date)) {
355                            return false;
356                    }
357                    
358                    if (getEnd()!=null && getEnd().before(date)) {
359                            return false;
360                    }
361                    
362                    return true;
363            }
364    
365            /**
366             * <!-- begin-user-doc -->
367             * <!-- end-user-doc -->
368             * @generated
369             */
370            @Override
371            public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
372                    switch (featureID) {
373                            case PartyPackage.EMAIL__OWNER:
374                                    if (eInternalContainer() != null)
375                                            msgs = eBasicRemoveFromContainer(msgs);
376                                    return basicSetOwner((Party)otherEnd, msgs);
377                    }
378                    return super.eInverseAdd(otherEnd, featureID, msgs);
379            }
380    
381            /**
382             * <!-- begin-user-doc -->
383             * <!-- end-user-doc -->
384             * @generated
385             */
386            @Override
387            public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
388                    switch (featureID) {
389                            case PartyPackage.EMAIL__TAGS:
390                                    return ((InternalEList<?>)getTags()).basicRemove(otherEnd, msgs);
391                            case PartyPackage.EMAIL__OWNER:
392                                    return basicSetOwner(null, msgs);
393                    }
394                    return super.eInverseRemove(otherEnd, featureID, msgs);
395            }
396    
397            /**
398             * <!-- begin-user-doc -->
399             * <!-- end-user-doc -->
400             * @generated
401             */
402            @Override
403            public NotificationChain eBasicRemoveFromContainerFeature(NotificationChain msgs) {
404                    switch (eContainerFeatureID()) {
405                            case PartyPackage.EMAIL__OWNER:
406                                    return eInternalContainer().eInverseRemove(this, PartyPackage.PARTY__CONTACT_INFO, Party.class, msgs);
407                    }
408                    return super.eBasicRemoveFromContainerFeature(msgs);
409            }
410    
411            /**
412             * <!-- begin-user-doc -->
413             * <!-- end-user-doc -->
414             * @generated
415             */
416            @Override
417            public Object eGet(int featureID, boolean resolve, boolean coreType) {
418                    switch (featureID) {
419                            case PartyPackage.EMAIL__TAGS:
420                                    return getTags();
421                            case PartyPackage.EMAIL__COMMENT:
422                                    return getComment();
423                            case PartyPackage.EMAIL__START:
424                                    return getStart();
425                            case PartyPackage.EMAIL__END:
426                                    return getEnd();
427                            case PartyPackage.EMAIL__CATEGORY:
428                                    return getCategory();
429                            case PartyPackage.EMAIL__OWNER:
430                                    return getOwner();
431                            case PartyPackage.EMAIL__ADDRESS:
432                                    return getAddress();
433                    }
434                    return super.eGet(featureID, resolve, coreType);
435            }
436    
437            /**
438             * <!-- begin-user-doc -->
439             * <!-- end-user-doc -->
440             * @generated
441             */
442            @SuppressWarnings("unchecked")
443            @Override
444            public void eSet(int featureID, Object newValue) {
445                    switch (featureID) {
446                            case PartyPackage.EMAIL__TAGS:
447                                    getTags().clear();
448                                    getTags().addAll((Collection<? extends Tag>)newValue);
449                                    return;
450                            case PartyPackage.EMAIL__COMMENT:
451                                    setComment((String)newValue);
452                                    return;
453                            case PartyPackage.EMAIL__START:
454                                    setStart((Date)newValue);
455                                    return;
456                            case PartyPackage.EMAIL__END:
457                                    setEnd((Date)newValue);
458                                    return;
459                            case PartyPackage.EMAIL__CATEGORY:
460                                    setCategory((String)newValue);
461                                    return;
462                            case PartyPackage.EMAIL__OWNER:
463                                    setOwner((Party)newValue);
464                                    return;
465                            case PartyPackage.EMAIL__ADDRESS:
466                                    setAddress((String)newValue);
467                                    return;
468                    }
469                    super.eSet(featureID, newValue);
470            }
471    
472            /**
473             * <!-- begin-user-doc -->
474             * <!-- end-user-doc -->
475             * @generated
476             */
477            @Override
478            public void eUnset(int featureID) {
479                    switch (featureID) {
480                            case PartyPackage.EMAIL__TAGS:
481                                    getTags().clear();
482                                    return;
483                            case PartyPackage.EMAIL__COMMENT:
484                                    setComment(COMMENT_EDEFAULT);
485                                    return;
486                            case PartyPackage.EMAIL__START:
487                                    setStart(START_EDEFAULT);
488                                    return;
489                            case PartyPackage.EMAIL__END:
490                                    setEnd(END_EDEFAULT);
491                                    return;
492                            case PartyPackage.EMAIL__CATEGORY:
493                                    setCategory(CATEGORY_EDEFAULT);
494                                    return;
495                            case PartyPackage.EMAIL__OWNER:
496                                    setOwner((Party)null);
497                                    return;
498                            case PartyPackage.EMAIL__ADDRESS:
499                                    setAddress(ADDRESS_EDEFAULT);
500                                    return;
501                    }
502                    super.eUnset(featureID);
503            }
504    
505            /**
506             * <!-- begin-user-doc -->
507             * <!-- end-user-doc -->
508             * @generated
509             */
510            @Override
511            public boolean eIsSet(int featureID) {
512                    switch (featureID) {
513                            case PartyPackage.EMAIL__TAGS:
514                                    return tags != null && !tags.isEmpty();
515                            case PartyPackage.EMAIL__COMMENT:
516                                    return COMMENT_EDEFAULT == null ? comment != null : !COMMENT_EDEFAULT.equals(comment);
517                            case PartyPackage.EMAIL__START:
518                                    return START_EDEFAULT == null ? start != null : !START_EDEFAULT.equals(start);
519                            case PartyPackage.EMAIL__END:
520                                    return END_EDEFAULT == null ? end != null : !END_EDEFAULT.equals(end);
521                            case PartyPackage.EMAIL__CATEGORY:
522                                    return CATEGORY_EDEFAULT == null ? category != null : !CATEGORY_EDEFAULT.equals(category);
523                            case PartyPackage.EMAIL__OWNER:
524                                    return getOwner() != null;
525                            case PartyPackage.EMAIL__ADDRESS:
526                                    return ADDRESS_EDEFAULT == null ? address != null : !ADDRESS_EDEFAULT.equals(address);
527                    }
528                    return super.eIsSet(featureID);
529            }
530    
531            /**
532             * <!-- begin-user-doc -->
533             * <!-- end-user-doc -->
534             * @generated
535             */
536            @Override
537            public String toString() {
538                    if (eIsProxy()) return super.toString();
539    
540                    StringBuffer result = new StringBuffer(super.toString());
541                    result.append(" (comment: ");
542                    result.append(comment);
543                    result.append(", start: ");
544                    result.append(start);
545                    result.append(", end: ");
546                    result.append(end);
547                    result.append(", category: ");
548                    result.append(category);
549                    result.append(", address: ");
550                    result.append(address);
551                    result.append(')');
552                    return result.toString();
553            }
554    
555    } //EMailImpl