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