All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openxma.dsl.common.extensions.EObjectPropertiesAdapter Maven / Gradle / Ivy

There is a newer version: 6.0.2
Show newest version
package org.openxma.dsl.common.extensions;

import java.util.Map;

import org.eclipse.emf.common.notify.Notifier;
import org.eclipse.emf.common.notify.impl.AdapterImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;

import com.google.common.collect.Maps;

/**
 * Simple adapter replacement for the functionality provided by
 * ElementPropertiesExtensions from xtend.
 * 
 */
public class EObjectPropertiesAdapter extends AdapterImpl {
	private Map properties = Maps.newConcurrentHashMap();

	public EObjectPropertiesAdapter() {
	}

	public static void removeProperty(Notifier notifier, String key) {
		getAdapter(notifier).properties.remove(key);
	}

	public static void setProperty(Notifier notifier, String key, Object value) {
		getAdapter(notifier).properties.put(key, value);
	}

	public static Object getProperty(Notifier notifier, String key) {
		return getAdapter(notifier).properties.get(key);
	}

	public static boolean hasProperty(Notifier notifier, String key) {
		return getAdapter(notifier).properties.containsKey(key);
	}

	private static synchronized EObjectPropertiesAdapter getAdapter(Notifier notifier) {
		EObjectPropertiesAdapter adapter = (EObjectPropertiesAdapter) EcoreUtil.getAdapter(notifier.eAdapters(),
				EObjectPropertiesAdapter.class);
		if (adapter == null) {
			adapter = new EObjectPropertiesAdapter();
			notifier.eAdapters().add(adapter);
		}
		return adapter;
	}

	@Override
	public boolean isAdapterForType(Object type) {
		return type == getClass();
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy