Skip to main content
summaryrefslogtreecommitdiffstats
blob: dfbcdd8ad0145710fd7d29df0605d4013d6aedad (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
/*******************************************************************************
 * Copyright (c) 2001, 2005 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.common.internal.util;

import java.util.List;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.wst.common.internal.emf.utilities.IDUtil;


/**
 * Utility class for generating and setting unique id's for ref objects contained within a resource.  This is needed
 * sometimes when a refobject is referenced by an object in a separate resource.  This utility will force the refobject 
 * to notify after the id gets set, using the static feature on this class.  The object must be contained in a resource
 * for the utility methods to work.
 */
public class IDUtility {

/**
 * IDUtility constructor comment.
 */
public IDUtility() {
	super();
}
/**
 * Generate a default id and notify.
 */
protected static String primSetDefaultID(EObject object) {
	return IDUtil.getOrAssignID(object);
}
	
/**
 * Generate a default id and notify.
 * Helper for default id generation to support cross document references to non xmi resources
 * (eg, xml deployment descriptors); called from overriden accessors in selected objects;  
 */
public static String setDefaultID(EObject object) {
	if (object == null || object.eResource() == null)
		return null;
	return primSetDefaultID(object);
}
	
/**
 * Generate a default id and notify, for this object and for all referenced objects that are contained
 * within the same resource.  Helper for default id generation to support cross document references to non xmi resources
 * (eg, xml deployment descriptors); useful for post copy/add  
 */
public static String setDefaultID(EObject object, boolean recurseChildren) {
	if (object == null || object.eResource() == null)
		return null;
		
	String result = primSetDefaultID(object);

	if (recurseChildren)
		setDefaultIDForChildren(object);

	return result;
}
	
protected static void setDefaultIDForChildren(EObject object) {

	List objects = object.eContents();
	for (int i = 0; i < objects.size(); i++){
		EObject o = (EObject)objects.get(i);
		primSetDefaultID(o);
	}
}
}

Back to the top