/*******************************************************************************
 * Copyright (c) 2011 David A Carlson.
 * 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:
 *     David A Carlson (XMLmodeling.com) - initial API and implementation
 *     
 *******************************************************************************/
package org.openhealthtools.mdht.uml.common.notation;

import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Property;

/**
 * @author dcarlson
 * 
 */
public class NotationUtil {

	public static String getPrintString(Element element) {
		String text = null;
		INotationProvider provider = NotationRegistry.INSTANCE.getNotationProvider(element);
		if (provider != null) {
			text = provider.getPrintString(element);
		}

		if (text == null) {
			// return default UML standard annotations, if no extensions found
			if (element instanceof Class) {
				text = ClassNotationUtil.getCustomLabel((Class) element, IUMLNotation.DEFAULT_UML_CLASS);
			} else if (element instanceof Property) {
				text = PropertyNotationUtil.getCustomLabel((Property) element, IUMLNotation.DEFAULT_UML_PROPERTY);
			}

			// TODO else, get from UML adapter provider
		}

		return text;
	}

	public static Object getElementImage(Element element) {
		INotationProvider provider = NotationRegistry.INSTANCE.getNotationProvider(element);
		if (provider != null) {
			return provider.getElementImage(element);
		}

		return null;
	}

	public static String getAnnotation(Element element) {
		String annotation = null;

		INotationProvider provider = NotationRegistry.INSTANCE.getNotationProvider(element);
		if (provider != null) {
			annotation = provider.getAnnotation(element);
		}

		if (annotation == null) {
			// return default UML standard annotations, if no extensions found
			if (element instanceof Class) {
				annotation = ClassNotationUtil.getCustomLabel(
					(Class) element, IUMLNotation.DEFAULT_UML_CLASS_ANNOTATIONS);
			} else if (element instanceof Property) {
				annotation = PropertyNotationUtil.getCustomLabel(
					(Property) element, IUMLNotation.DEFAULT_UML_PROPERTY_ANNOTATIONS);
			}
		}

		return annotation;
	}

	public static Object getAnnotationImage(Element element) {
		INotationProvider provider = NotationRegistry.INSTANCE.getNotationProvider(element);
		if (provider != null) {
			return provider.getAnnotationImage(element);
		}

		return null;
	}

}

@@ -874,16 +874,43 @@
  null;%0D%0A
+%09%09if (element != null) %7B%0D%0A%09
 %09%09INotat
@@ -983,32 +983,33 @@
 er(element);%0D%0A%09%09
+%09
 if (provider != 
@@ -1017,16 +1017,17 @@
 ull) %7B%0D%0A
+%09
 %09%09%09text 
@@ -1055,32 +1055,38 @@
 ring(element);%0D%0A
+%09%09%09%7D%0D%0A
 %09%09%7D%0D%0A%0D%0A%09%09if (tex
@@ -1586,32 +1586,59 @@
 ent element) %7B%0D%0A
+%09%09if (element != null) %7B%0D%0A%09
 %09%09INotationProvi
@@ -1703,32 +1703,33 @@
 er(element);%0D%0A%09%09
+%09
 if (provider != 
@@ -1729,32 +1729,33 @@
 der != null) %7B%0D%0A
+%09
 %09%09%09return provid
@@ -1776,32 +1776,38 @@
 mage(element);%0D%0A
+%09%09%09%7D%0D%0A
 %09%09%7D%0D%0A%0D%0A%09%09return 
@@ -1906,16 +1906,43 @@
 ull;%0D%0A%0D%0A
+%09%09if (element != null) %7B%0D%0A%09
 %09%09INotat
@@ -2015,32 +2015,33 @@
 er(element);%0D%0A%09%09
+%09
 if (provider != 
@@ -2049,16 +2049,17 @@
 ull) %7B%0D%0A
+%09
 %09%09%09annot
@@ -2092,32 +2092,38 @@
 tion(element);%0D%0A
+%09%09%09%7D%0D%0A
 %09%09%7D%0D%0A%0D%0A%09%09if (ann
@@ -2646,16 +2646,43 @@
 ent) %7B%0D%0A
+%09%09if (element != null) %7B%0D%0A%09
 %09%09INotat
@@ -2759,24 +2759,25 @@
 lement);%0D%0A%09%09
+%09
 if (provider
@@ -2789,16 +2789,17 @@
 ull) %7B%0D%0A
+%09
 %09%09%09retur
@@ -2839,16 +2839,22 @@
 ment);%0D%0A
+%09%09%09%7D%0D%0A
 %09%09%7D%0D%0A%0D%0A%09

Add test for null element.