diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/KernelModelElementUtils.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/KernelModelElementUtils.java index 94d136c2107571308d928b54746ec9796d3c3e5d..9394ecb8d5b9047f68b2539478cd8176ec78352e 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/KernelModelElementUtils.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/KernelModelElementUtils.java @@ -22,6 +22,7 @@ import java.util.Iterator; import org.eclipse.emf.ecore.EObject; import org.fortiss.tooling.kernel.model.IIdLabeled; import org.fortiss.tooling.kernel.model.IIdLabeledReference; +import org.fortiss.tooling.kernel.model.INamedElement; import org.fortiss.tooling.kernel.model.IProjectRootElement; import org.fortiss.tooling.kernel.service.IPersistencyService; @@ -31,7 +32,7 @@ import org.fortiss.tooling.kernel.service.IPersistencyService; * @author hoelzl * @author $Author$ * @version $Rev$ - * @ConQAT.Rating YELLOW Hash: BFAEE573B73BEA35ED5EC160F4015FB5 + * @ConQAT.Rating YELLOW Hash: E77DC792D810E6886DD06EC35AB21D0D */ public final class KernelModelElementUtils { @@ -112,4 +113,29 @@ public final class KernelModelElementUtils { } return false; } + + /** + * Iterates the content of the given root element and finds a contained + * element with the given name and the given class. + * + * @param root + * the root element to be searched + * @param name + * the name of the element to find + * @param clazz + * the class of the element to find + * @return the element found or <code>null</code> if none was found + */ + @SuppressWarnings("unchecked") + public static <T extends INamedElement> T findContentElementByNameAndClass( + EObject root, String name, Class<T> clazz) { + Iterator<EObject> iter = root.eAllContents(); + while (iter.hasNext()) { + EObject nxt = iter.next(); + if (clazz.isInstance(nxt) && ((T) nxt).getName().equals(name)) { + return (T) nxt; + } + } + return null; + } }