Skip to main content
summaryrefslogtreecommitdiffstats
blob: 1a207b6da08f6916dd260b53dee90c47f719a9df (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
/*******************************************************************************
 * Copyright (c) 2001, 2007 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 Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.j2ee.ejb.internal.impl;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

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.common.util.Enumerator;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.EObjectContainmentWithInverseEList;
import org.eclipse.emf.ecore.util.EObjectResolvingEList;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.util.InternalEList;
import org.eclipse.jem.java.Field;
import org.eclipse.jem.java.JavaClass;
import org.eclipse.jem.java.JavaRefFactory;
import org.eclipse.jst.j2ee.ejb.CMPAttribute;
import org.eclipse.jst.j2ee.ejb.CMRField;
import org.eclipse.jst.j2ee.ejb.CommonRelationshipRole;
import org.eclipse.jst.j2ee.ejb.ContainerManagedEntity;
import org.eclipse.jst.j2ee.ejb.EJBExtensionFilter;
import org.eclipse.jst.j2ee.ejb.EJBRelation;
import org.eclipse.jst.j2ee.ejb.EJBRelationshipRole;
import org.eclipse.jst.j2ee.ejb.EjbFactory;
import org.eclipse.jst.j2ee.ejb.EjbPackage;
import org.eclipse.jst.j2ee.ejb.MethodElementKind;
import org.eclipse.jst.j2ee.ejb.Query;
import org.eclipse.jst.j2ee.ejb.internal.util.CMPKeySynchronizationAdapter;
import org.eclipse.jst.j2ee.internal.J2EEVersionConstants;
import org.eclipse.jst.j2ee.internal.common.J2EEVersionResource;


/**
 * @generated
 */
public class ContainerManagedEntityImpl extends EntityImpl implements ContainerManagedEntity {

	/**
	 * The default value of the '{@link #getVersion() <em>Version</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getVersion()
	 * 
	 * @ordered
	 */
	protected static final String VERSION_EDEFAULT = "1.x"; //$NON-NLS-1$

	protected EClassifier fGeneratedIdType = null;
	protected static final String PERS_FEATURE_CHNG_NOTIFIER = "PersistentFeatureChangeNotificationAdapter";	 //$NON-NLS-1$
	protected static final String QUERY_METHOD_NAME = "QueryMethod"; //$NON-NLS-1$
	protected static final String FIND_BY_PRIM_KEY_METHOD_NAME = "findByPrimaryKey"; //$NON-NLS-1$
	
	/**
	 * @generated This field/method will be replaced during code generation.
	 */
	/**
	 * @generated This field/method will be replaced during code generation.
	 */
	protected String version = VERSION_EDEFAULT;
	/**
	 * The default value of the '{@link #getAbstractSchemaName() <em>Abstract Schema Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getAbstractSchemaName()
	 * @generated
	 * @ordered
	 */
	protected static final String ABSTRACT_SCHEMA_NAME_EDEFAULT = null;

	/**
	 * @generated This field/method will be replaced during code generation.
	 */
	protected String abstractSchemaName = ABSTRACT_SCHEMA_NAME_EDEFAULT;
	/**
	 * @generated This field/method will be replaced during code generation.
	 */
	protected EList persistentAttributes = null;
	/**
	 * @generated This field/method will be replaced during code generation.
	 */
	protected EList keyAttributes = null;
	/**
	 * The cached value of the '{@link #getQueries() <em>Queries</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getQueries()
	 * @generated
	 * @ordered
	 */
	protected EList queries = null;

	/**
	 * The cached value of the '{@link #getCMPAttribute() <em>CMP Attribute</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getCMPAttribute()
	 * @generated
	 * @ordered
	 */
	protected EList cmpAttribute = null;

	/**
	 * The cached value of the '{@link #getPrimKeyField() <em>Prim Key Field</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPrimKeyField()
	 * @generated
	 * @ordered
	 */
	protected CMPAttribute primKeyField = null;

	/**
	 * @generated
	 */
	protected ContainerManagedEntityImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return EjbPackage.Literals.CONTAINER_MANAGED_ENTITY;
	}

/**
 * Create a new instance of AttributeExtn with aName and add it to the keyFeatures.
 * Creation date: (8/2/2000 9:11:13 PM)
 * @param aName java.lang.String
 * @return CMPAttribute
 */
public CMPAttribute addKeyAttributeName(String aName) {
	CMPAttribute attribute = getPersistentAttribute(aName);
	if (attribute != null) {
		List keys = getKeyAttributes();
		CMPAttribute key;
		for (int i = 0; i < keys.size(); i++) {
			key = (CMPAttribute) keys.get(i);
			if (aName.equals(key.getName()))
				return attribute;
		}
		keys.add(attribute);
	}
	return attribute;
}
/**
 * Return a List of one of the properties using aFilter.
*/
public List getFilteredFeatures(EJBExtensionFilter aFilter) {
		return aFilter.filter(this);
	}
/**
 * Add a persistent attribute with the same name as the name for aField.
 * Creation date: (8/3/2000 8:30:42 AM)
 * @param aField org.eclipse.jem.internal.java.Field
 * @return CMPAttribute
 */
public CMPAttribute addPersistentAttribute(Field aField) {
	if (aField == null)
		return null;
	return addPersistentAttributeName(aField.getName());
}
/**
 * Create a new instance of AttributeExtn with aName and add it to the persistentFeatures.
 * Creation date: (8/2/2000 9:11:13 PM)
 * @param aName java.lang.String
 * @return CMPAttribute
 */
public CMPAttribute addPersistentAttributeName(String aName) {
	CMPAttribute attribute = getPersistentAttribute(aName);
	if (attribute == null) {
		attribute = createPersistentAttribute(aName);
		getPersistentAttributes().add(attribute);
	}
	return attribute;
}
protected CMPAttribute createPersistentAttribute(String aName) {
	CMPAttribute attribute = ((EjbPackage)EPackage.Registry.INSTANCE.getEPackage(EjbPackage.eNS_URI)).getEjbFactory().createCMPAttribute();
	attribute.setName(aName);
	return attribute;
}
public List getAllAvailableQueryMethods() {
	Set sigs = new HashSet();
	List javaMethods = getAvailableSelectQueryJavaMethods();
	sigs.addAll(getMethodElementSignatures(javaMethods));
	javaMethods = getAvailableLocalQueryJavaMethods();
	sigs.addAll(getMethodElementSignatures(javaMethods));
	javaMethods = getAvailableRemoteQueryJavaMethods();
	sigs.addAll(getMethodElementSignatures(javaMethods));
	List signatures = new ArrayList(sigs);
	return createQueryMethods(signatures);
}
protected List createQueryMethods(List signatures) {
	Collections.sort(signatures);
	Enumerator enumerator = MethodElementKind.UNSPECIFIED_LITERAL;
	return createMethodElements(QUERY_METHOD_NAME, signatures, enumerator);
}

public List getAvailableSelectQueryMethods() {
	List methods = getAvailableSelectQueryJavaMethods();
	List sigs = getMethodElementSignatures(methods);
	return createQueryMethods(sigs);
}
protected List getAvailableSelectQueryJavaMethods() {
	JavaClass bean = getEjbClass();
	if (bean == null)
		return Collections.EMPTY_LIST;
	return bean.getOnlySpecificMethods("ejbSelect", Collections.EMPTY_LIST);	 //$NON-NLS-1$
}

public List getAvailableFindQueryMethods() {
	Set sigs = new HashSet();
	List javaMethods = getAvailableRemoteQueryJavaMethods();
	sigs.addAll(getMethodElementSignatures(javaMethods));
	javaMethods = getAvailableLocalQueryJavaMethods();
	sigs.addAll(getMethodElementSignatures(javaMethods));
	List signatures = new ArrayList(sigs);
	return createQueryMethods(signatures);
}
protected List getAvailableLocalQueryJavaMethods() {
	return getAvailableQueryJavaMethods(getLocalHomeInterface());
}
/**
* This returns the CMP version id by using the module id and the <cmp-version>. 
* Compare with J2EEVersionConstants to determine CMP level
* This will help differentiate between 2.0,2.1,...   rather than "2.x"
*/
public int getCMPVersionID() throws IllegalStateException {
	J2EEVersionResource res = (J2EEVersionResource) eResource();
	/* If resource is null we will return based on CMP version....*/
	if (res == null) {
		if (getVersion().equals(ContainerManagedEntity.VERSION_1_X))
			return J2EEVersionConstants.EJB_1_1_ID;
		return J2EEVersionConstants.EJB_2_0_ID;
	}
	int cmpVersion;
	switch (res.getModuleVersionID()) {
		case J2EEVersionConstants.EJB_2_0_ID :
			if (getVersion().equalsIgnoreCase(VERSION_2_X))
				cmpVersion = J2EEVersionConstants.EJB_2_0_ID;
			else
				cmpVersion = J2EEVersionConstants.EJB_1_1_ID;
			break;
		case J2EEVersionConstants.EJB_2_1_ID :
					if (getVersion().equalsIgnoreCase(VERSION_2_X))
						cmpVersion = J2EEVersionConstants.EJB_2_1_ID;
					else
						cmpVersion = J2EEVersionConstants.EJB_1_1_ID;
					break;

		default :
			cmpVersion = res.getModuleVersionID();
	}
	return cmpVersion;
}

/* (non-Javadoc)
 * @see org.eclipse.jst.j2ee.internal.ejb.EnterpriseBean#getVersionID()
 */
@Override
public int getVersionID() {
	return getCMPVersionID();
}protected List getAvailableRemoteQueryJavaMethods() {
	return getAvailableQueryJavaMethods(getHomeInterface());
}

protected List getAvailableQueryJavaMethods(JavaClass home) {
	if (home == null) return Collections.EMPTY_LIST;
	List excluded = new ArrayList(1);
	excluded.add("findByPrimaryKey"); //$NON-NLS-1$
	return home.getOnlySpecificMethods("find", excluded); //$NON-NLS-1$
}

protected EClassifier getGeneratedIdType() {
	if (fGeneratedIdType == null) {
		fGeneratedIdType = JavaRefFactory.eINSTANCE.reflectType(JAVA_LANG_STRING, this);
	}
	return fGeneratedIdType;
}
/**
 * Return the keyAttribute with aName.
 * Creation date: (8/8/2000 9:25:27 PM)
 * @return EStructuralFeature
 * @param aName java.lang.String
 */
public CMPAttribute getKeyAttribute(String aName) {
	if (aName != null) {
		Iterator it = getKeyAttributes().iterator();
		CMPAttribute next;
		while (it.hasNext()) {
			next = (CMPAttribute) it.next();
			if (aName.equals(next.getName()))
				return next;
		}
	}
	return null;
}
/**
 * Return the persistentAttribute with aName.
 * Creation date: (8/8/2000 9:25:27 PM)
 * @return EStructuralFeature
 * @param aName java.lang.String
 */
public CMPAttribute getPersistentAttribute(String aName) {
	if (aName != null) {
		Iterator it = getPersistentAttributes().iterator();
		CMPAttribute next;
		while (it.hasNext()) {
			next = (CMPAttribute) it.next();
			if (aName.equals(next.getName()))
				return next;
		}
	}
	return null;
}

/**
 * If a primary key exists, return the persistent attribute; the primary key is defined as one and only one
 * key attribute, whose type is the same as the key class
 * @deprecated use getPrimKeyField()
 */
public CMPAttribute getPrimaryKeyAttribute() {
	return getPrimKeyField();
}


/**
 * isContainerManagedEntity method comment.
 */
@Override
public boolean isContainerManagedEntity() {
	return true;
}
public boolean isKeyAttribute(CMPAttribute anAttribute) {
	java.util.List attributes = getKeyAttributes();
	for (int i = 0; i < attributes.size(); i++){
		if (attributes.get(i) == anAttribute)
			return true;
	}
	return false;
}
/*
 * Return whether this bean represents an instance of the "unknown primary key" case
 * described in the specification.  This is identified by the primary key class
 * being specified as "java.lang.Object".
 * In order to deploy an unknown primary key bean, we must substitute a real key,
 * and add a corresponding field.
 */
public boolean isUnknownPrimaryKey() {
	String keyName = getPrimaryKeyName();
	if (keyName == null) return false;
	//test whether it is unknown or we have the WAS generated key for the unknown prim key
	boolean genTest = keyName.equals(UNKNOWN_PRIMARY_KEY) || keyName.equals(WAS_GENERATED_STRING_KEY);
	if (genTest) return true;
	//Lastly, test for the findByPrimaryKey(Object) method on the home.
	JavaClass home = getHomeInterface();
	if (home == null)
		home = getLocalHomeInterface();
	if (home == null) return false;
	List parmType = new ArrayList(1);
    parmType.add(UNKNOWN_PRIMARY_KEY);
   	return home.getMethodExtended(FIND_BY_PRIM_KEY_METHOD_NAME, parmType) != null;
}
/**
 * isVersion1_X method comment.
 */
@Override
public boolean isVersion1_X() {
	return getVersion().equals(ContainerManagedEntity.VERSION_1_X);
}
/**
 * isVersion2_X method comment.
 */
@Override
public boolean isVersion2_X() {
	return getVersion().equals(ContainerManagedEntity.VERSION_2_X);
}
/* 
 * listPersistentFieldNames - return the names of our CMP fields. derived from persistentFeatures
 */
public String[] listPersistentFieldNames() {
	java.util.List attributes = getPersistentAttributes();
	String[] names = new String[attributes.size()];
	for (int i = 0; i < attributes.size(); i++) {
		names[i] = ((CMPAttribute) attributes.get(i)).getName();
	}
	return names;
}

/**
 * Remove the persistentAttribute with the same name as the Field's name.
 * Creation date: (8/3/2000 8:33:01 AM)
 * @param aField org.eclipse.jem.internal.java.Field
 */
public CMPAttribute removePersistentAttribute(Field aField) {
	if (aField != null)
		return removePersistentAttribute(aField.getName());
	return null;
}
/**
 * Remove the persistentAttribute named aName.
 * Creation date: (8/2/2000 8:59:32 PM)
 * @param aName java.lang.String
 */
public CMPAttribute removePersistentAttribute(String aName) {
	if (aName != null) {
		Iterator it = getPersistentAttributes().iterator();
		CMPAttribute next;
		while (it.hasNext()) {
			next = (CMPAttribute) it.next();
			if (aName.equals(next.getName())) {
				getPersistentAttributes().remove(next);
				return next;
			}
		}
	}
	return null;
}
/**
	 * @generated This field/method will be replaced during code generation 
	 * Specifies the version of an entity bean with container-managed persistence.
	 * 
	 * @invariant The cmp-version element must be one of the two following: 1.x , 2.x
	 * @default 2.x
	 * Returns "1.x" if in a 1.1 Jar (For compatibility)
	 */
	public String getVersion() {
		return version;
	}

	/**
	 * @generated This field/method will be replaced during code generation.
	 */
	public void setVersion(String newVersion) {
		String oldVersion = version;
		version = newVersion;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, EjbPackage.CONTAINER_MANAGED_ENTITY__VERSION, oldVersion, version));
	}

	/**
	 * @generated This field/method will be replaced during code generation 
	 * The abstract-schema-name element specifies the name of the abstract schema type of an entity bean with cmp-version 2.x. It is used in EJB QL queries.
	 * 
	 * For example, the abstract-schema-name for an entity bean whose local interface is com.acme.commerce.Order might be Order.
	 * 

	 */
	public String getAbstractSchemaName() {
		return abstractSchemaName;
	}

	/**
	 * @generated This field/method will be replaced during code generation.
	 */
	public void setAbstractSchemaName(String newAbstractSchemaName) {
		String oldAbstractSchemaName = abstractSchemaName;
		abstractSchemaName = newAbstractSchemaName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, EjbPackage.CONTAINER_MANAGED_ENTITY__ABSTRACT_SCHEMA_NAME, oldAbstractSchemaName, abstractSchemaName));
	}

	/**
	 * @generated This field/method will be replaced during code generation 
	 */
	public EList getPersistentAttributes() {
		if (persistentAttributes == null) {
			persistentAttributes = new EObjectContainmentEList(CMPAttribute.class, this, EjbPackage.CONTAINER_MANAGED_ENTITY__PERSISTENT_ATTRIBUTES);
		}
		return persistentAttributes;
	}

	/**
	 * @generated This field/method will be replaced during code generation.
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (version: "); //$NON-NLS-1$
		result.append(version);
		result.append(", abstractSchemaName: "); //$NON-NLS-1$
		result.append(abstractSchemaName);
		result.append(')');
		return result.toString();
	}

	/**
	 * @generated This field/method will be replaced during code generation 
	 */
	public EList getKeyAttributesGen() {
		if (keyAttributes == null) {
			keyAttributes = new EObjectResolvingEList(CMPAttribute.class, this, EjbPackage.CONTAINER_MANAGED_ENTITY__KEY_ATTRIBUTES);
		}
		return keyAttributes;
	}

	public EList getKeyAttributes() {
	    if(keyAttributes == null) {
		    CMPKeySynchronizationAdapter syncAdapter = (CMPKeySynchronizationAdapter)  EcoreUtil.getExistingAdapter(this, CMPKeySynchronizationAdapter.ADAPTER_TYPE);
			if(syncAdapter != null) 
			    syncAdapter.initializeKeyAttributes(); 
	    }
		return getKeyAttributesGen();
	}

	/**
	 * <p>Change for bugzilla 177397.  Provide access to the
	 * initialization state of the key attributes attribute.</p>
	 * 
	 * <p>The initialization state is used while copying the
	 * receiver.  If the key attributes attribute has not been
	 * initialized, then the copy does not need to descend into the
	 * key attributes.</p>
	 * 
	 * @return True if the key attributes have been initialized.
	 *         Otherwise, false.
	 * 
	 * @generated NOT
	 */
	public boolean getIsInitializedKeyAttributes() {
		return (keyAttributes == null);
	}
	
	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList getQueries() {
		if (queries == null) {
			queries = new EObjectContainmentWithInverseEList(Query.class, this, EjbPackage.CONTAINER_MANAGED_ENTITY__QUERIES, EjbPackage.QUERY__ENTITY);
		}
		return queries;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList getCMPAttribute() {
		if (cmpAttribute == null) {
			cmpAttribute = new EObjectResolvingEList(CMPAttribute.class, this, EjbPackage.CONTAINER_MANAGED_ENTITY__CMP_ATTRIBUTE);
		}
		return cmpAttribute;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public CMPAttribute getPrimKeyField() {
		if (primKeyField != null && primKeyField.eIsProxy()) {
			InternalEObject oldPrimKeyField = (InternalEObject)primKeyField;
			primKeyField = (CMPAttribute)eResolveProxy(oldPrimKeyField);
			if (primKeyField != oldPrimKeyField) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, EjbPackage.CONTAINER_MANAGED_ENTITY__PRIM_KEY_FIELD, oldPrimKeyField, primKeyField));
			}
		}
		return primKeyField;
	}

	public void makePrimKeyFieldProxy() {
		if (primKeyField == null) return;
		String fieldName = primKeyField.getName();
		if (fieldName == null) fieldName = ""; //$NON-NLS-1$
		primKeyField = EjbFactory.eINSTANCE.createCMPAttribute();
		((InternalEObject)primKeyField).eSetProxyURI(URI.createURI(fieldName));
		
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public CMPAttribute basicGetPrimKeyField() {
		return primKeyField;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setPrimKeyField(CMPAttribute newPrimKeyField) {
		CMPAttribute oldPrimKeyField = primKeyField;
		primKeyField = newPrimKeyField;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, EjbPackage.CONTAINER_MANAGED_ENTITY__PRIM_KEY_FIELD, oldPrimKeyField, primKeyField));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case EjbPackage.CONTAINER_MANAGED_ENTITY__QUERIES:
				return ((InternalEList)getQueries()).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 EjbPackage.CONTAINER_MANAGED_ENTITY__PERSISTENT_ATTRIBUTES:
				return ((InternalEList)getPersistentAttributes()).basicRemove(otherEnd, msgs);
			case EjbPackage.CONTAINER_MANAGED_ENTITY__QUERIES:
				return ((InternalEList)getQueries()).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 EjbPackage.CONTAINER_MANAGED_ENTITY__VERSION:
				return getVersion();
			case EjbPackage.CONTAINER_MANAGED_ENTITY__ABSTRACT_SCHEMA_NAME:
				return getAbstractSchemaName();
			case EjbPackage.CONTAINER_MANAGED_ENTITY__PERSISTENT_ATTRIBUTES:
				return getPersistentAttributes();
			case EjbPackage.CONTAINER_MANAGED_ENTITY__KEY_ATTRIBUTES:
				return getKeyAttributes();
			case EjbPackage.CONTAINER_MANAGED_ENTITY__QUERIES:
				return getQueries();
			case EjbPackage.CONTAINER_MANAGED_ENTITY__CMP_ATTRIBUTE:
				return getCMPAttribute();
			case EjbPackage.CONTAINER_MANAGED_ENTITY__PRIM_KEY_FIELD:
				if (resolve) return getPrimKeyField();
				return basicGetPrimKeyField();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case EjbPackage.CONTAINER_MANAGED_ENTITY__VERSION:
				setVersion((String)newValue);
				return;
			case EjbPackage.CONTAINER_MANAGED_ENTITY__ABSTRACT_SCHEMA_NAME:
				setAbstractSchemaName((String)newValue);
				return;
			case EjbPackage.CONTAINER_MANAGED_ENTITY__PERSISTENT_ATTRIBUTES:
				getPersistentAttributes().clear();
				getPersistentAttributes().addAll((Collection)newValue);
				return;
			case EjbPackage.CONTAINER_MANAGED_ENTITY__KEY_ATTRIBUTES:
				getKeyAttributes().clear();
				getKeyAttributes().addAll((Collection)newValue);
				return;
			case EjbPackage.CONTAINER_MANAGED_ENTITY__QUERIES:
				getQueries().clear();
				getQueries().addAll((Collection)newValue);
				return;
			case EjbPackage.CONTAINER_MANAGED_ENTITY__CMP_ATTRIBUTE:
				getCMPAttribute().clear();
				getCMPAttribute().addAll((Collection)newValue);
				return;
			case EjbPackage.CONTAINER_MANAGED_ENTITY__PRIM_KEY_FIELD:
				setPrimKeyField((CMPAttribute)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case EjbPackage.CONTAINER_MANAGED_ENTITY__VERSION:
				setVersion(VERSION_EDEFAULT);
				return;
			case EjbPackage.CONTAINER_MANAGED_ENTITY__ABSTRACT_SCHEMA_NAME:
				setAbstractSchemaName(ABSTRACT_SCHEMA_NAME_EDEFAULT);
				return;
			case EjbPackage.CONTAINER_MANAGED_ENTITY__PERSISTENT_ATTRIBUTES:
				getPersistentAttributes().clear();
				return;
			case EjbPackage.CONTAINER_MANAGED_ENTITY__KEY_ATTRIBUTES:
				getKeyAttributes().clear();
				return;
			case EjbPackage.CONTAINER_MANAGED_ENTITY__QUERIES:
				getQueries().clear();
				return;
			case EjbPackage.CONTAINER_MANAGED_ENTITY__CMP_ATTRIBUTE:
				getCMPAttribute().clear();
				return;
			case EjbPackage.CONTAINER_MANAGED_ENTITY__PRIM_KEY_FIELD:
				setPrimKeyField((CMPAttribute)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case EjbPackage.CONTAINER_MANAGED_ENTITY__VERSION:
				return VERSION_EDEFAULT == null ? version != null : !VERSION_EDEFAULT.equals(version);
			case EjbPackage.CONTAINER_MANAGED_ENTITY__ABSTRACT_SCHEMA_NAME:
				return ABSTRACT_SCHEMA_NAME_EDEFAULT == null ? abstractSchemaName != null : !ABSTRACT_SCHEMA_NAME_EDEFAULT.equals(abstractSchemaName);
			case EjbPackage.CONTAINER_MANAGED_ENTITY__PERSISTENT_ATTRIBUTES:
				return persistentAttributes != null && !persistentAttributes.isEmpty();
			case EjbPackage.CONTAINER_MANAGED_ENTITY__KEY_ATTRIBUTES:
				return keyAttributes != null && !keyAttributes.isEmpty();
			case EjbPackage.CONTAINER_MANAGED_ENTITY__QUERIES:
				return queries != null && !queries.isEmpty();
			case EjbPackage.CONTAINER_MANAGED_ENTITY__CMP_ATTRIBUTE:
				return cmpAttribute != null && !cmpAttribute.isEmpty();
			case EjbPackage.CONTAINER_MANAGED_ENTITY__PRIM_KEY_FIELD:
				return primKeyField != null;
		}
		return super.eIsSet(featureID);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jst.j2ee.internal.ejb.ContainerManagedEntity#getCMRFields()
	 */
	public List getCMRFields() {
		List myRoles = getRoles();
		List cmrFields = Collections.EMPTY_LIST;
		if (myRoles != null && !myRoles.isEmpty()) {
			cmrFields = new ArrayList();
			Iterator i = myRoles.iterator();
			while (i.hasNext()) {
				EJBRelationshipRole role = (EJBRelationshipRole) i.next();
				CMRField field = role.getCmrField();
				if (field != null)
					cmrFields.add(field);
			}
		}
		return cmrFields;
	}

	public boolean isSelfReferencing(EJBRelation rel) {
		if (rel.getSecondRole() == null)
			return false;
		return (rel.getFirstRole().getSourceEntity() == this) &&
			(rel.getSecondRole().getSourceEntity() == this);
	}

	
	/* (non-Javadoc)
	 * @see org.eclipse.jst.j2ee.internal.ejb.ContainerManagedEntity#getRoles()
	 */
	public List getRoles() {
		if (getEjbJar() == null)
			return Collections.EMPTY_LIST;
		List allRoles = getEjbJar().getEjbRelations();
		List myRoles = Collections.EMPTY_LIST;
		if (allRoles != null && !allRoles.isEmpty()) {
			myRoles = new ArrayList();
			Iterator i = allRoles.iterator();
			while (i.hasNext()) {
				EJBRelation rel = (EJBRelation) i.next();
				EJBRelationshipRole role = rel.getFirstRole();
				if (isSelfReferencing(rel)) {
					myRoles.add(rel.getFirstRole());
					myRoles.add(rel.getSecondRole());
				}
				else if ((role != null) && role.getSourceEntity() == this) {
					myRoles.add(role);
				} else {
					role = rel.getSecondRole();
					if ((role != null) && (role.getSourceEntity() == this))
						myRoles.add(role);
				}
			}
		}
		return myRoles;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jst.j2ee.internal.ejb.ContainerManagedEntity#getRole(java.lang.String)
	 */
	public CommonRelationshipRole getRole(String roleName) {
		List roles = getRoles();
		for (int i=0; i<roles.size(); i++) {
			CommonRelationshipRole role = (CommonRelationshipRole)roles.get(i);
			if (role.getName().equals(roleName))
				return role;
		}
		return null;
	}

}






Back to the top