Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 0a486ce715c93352aa0bcc44e05f91fb98084434 (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
/**
 * <copyright>
 *
 * Copyright (c) 2005, 2006 Springsite BV (The Netherlands) 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:
 *   Martin Taal - Initial API and implementation
 *
 * </copyright>
 *
 * $Id: NonLoadingEContentsEList.java,v 1.1 2006/11/13 19:55:40 mtaal Exp $
 */

package org.eclipse.emf.teneo.resource;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.util.EContentsEList;
import org.eclipse.emf.teneo.mapping.elist.PersistableEList;
import org.eclipse.emf.teneo.mapping.elist.PersistableFeatureMap;

/**
 * Is a contents elist which will only iterate over loaded efeatures.
 * 
 * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
 * @version $Revision: 1.1 $
 */

public class NonLoadingEContentsEList extends EContentsEList {

	/** Creates an instance of a NonResolvingEContentsEList for the EObject */
	public static EContentsEList create(EObject eObject, boolean forValidation) {
		final ArrayList result = new ArrayList();
		for (Iterator it = eObject.eClass().getEAllReferences().iterator(); it.hasNext();) {
			final EReference eref = (EReference)it.next();
			if (!eref.isContainment()) continue;
			if (eref.isMany()) {
				List list = (List) eObject.eGet(eref);
				if ((list instanceof PersistableEList) && ((PersistableEList) list).isLoaded()) {
					result.add(eref);
				} else if ((list instanceof PersistableFeatureMap) && ((PersistableFeatureMap) list).isLoaded()) {
					result.add(eref);
				} else if (eref.getLowerBound() > 0 && forValidation) {
					result.add(eref);
				}
				
			} else {
				result.add(eref);
			}
		}
		return new NonLoadingEContentsEList(eObject, result);
	}

	private NonLoadingEContentsEList(EObject eObject, List eStructuralFeatures) {
		super(eObject, eStructuralFeatures);
	}
}

Back to the top