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

org.jresearch.flexess.client.impl.SimpleCheckerFlow Maven / Gradle / Ivy

The newest version!
package org.jresearch.flexess.client.impl;

import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.jresearch.flexess.client.UamClientException;
import org.jresearch.flexess.client.mappers.IInstanceMapper;
import org.jresearch.flexess.client.mappers.impl.CustomObjectMapper;
import org.jresearch.flexess.client.mappers.impl.DefaultMapper;
import org.jresearch.flexess.client.mappers.impl.GenericMapper;
import org.jresearch.flexess.client.mappers.impl.JavaInstanceMapper;
import org.jresearch.flexess.client.mappers.impl.LegacyJavaInstanceMapper;
import org.jresearch.flexess.core.model.uam.IPObjectConstant;
import org.jresearch.flexess.core.model.uam.PObject;
import org.jresearch.flexess.core.model.uam.UamPackage;

public class SimpleCheckerFlow implements ICheckerFlow {

	// TODO UAM-740

	private static Map mappers = new HashMap();

	static {
		IInstanceMapper mapper = new CustomObjectMapper();
		mappers.put(mapper.getMapperId(), mapper);
		mapper = new DefaultMapper();
		mappers.put(mapper.getMapperId(), mapper);
		mapper = new GenericMapper();
		mappers.put(mapper.getMapperId(), mapper);
		mapper = new JavaInstanceMapper();
		mappers.put(mapper.getMapperId(), mapper);
		mapper = new LegacyJavaInstanceMapper();
		mappers.put(mapper.getMapperId(), mapper);
	}

	private final Object object;

	public SimpleCheckerFlow(Object object) {
		assert object != null;
		this.object = object;
	}

	@Override
	public Class getObjectClass() {
		return object.getClass();
	}

	@Override
	public EObject getPOInstance(PObject po) {
		assert po != null;
		String mapperId = EcoreUtil.getAnnotation(po, UamPackage.eNS_URI, IPObjectConstant.MAPPER_CLASS_NAME_ATTR);
		if (mapperId == null) {
			throw new UamClientException("Mapper is not specified");
		}
		IInstanceMapper mapper = mappers.get(mapperId);
		if (mapper == null) {
			throw new UamClientException(MessageFormat.format("Unable to create EObject: can''t find {0} mapper ", mapperId));
		}
		try {
			return mapper.createPObjectInstance(object, po);
		} catch (Exception e) {
			throw new UamClientException("Unable to create EObject", e);
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy