public code v1
This commit is contained in:
+130
@@ -0,0 +1,130 @@
|
||||
package flintstones.operator.unification;
|
||||
|
||||
import flintstones.entity.domain.Domain;
|
||||
import flintstones.entity.extensionenum.ExtensionEnum;
|
||||
import flintstones.entity.valuation.Valuation;
|
||||
|
||||
public abstract class UnificationOperator {
|
||||
|
||||
/** The id. */
|
||||
protected String id;
|
||||
|
||||
/** The name. */
|
||||
protected String name;
|
||||
|
||||
/** The source valuation id. */
|
||||
protected String source_valuation_id;
|
||||
|
||||
/** The final valuation id. */
|
||||
protected String final_valuation_id;
|
||||
|
||||
/**
|
||||
* The Class Fields.
|
||||
*/
|
||||
public enum Fields implements ExtensionEnum {
|
||||
|
||||
/** The id. */
|
||||
id,
|
||||
/** The name. */
|
||||
name,
|
||||
/** The implementation. */
|
||||
implementation,
|
||||
/** The source valuation. */
|
||||
source_valuation,
|
||||
/** The final valuation. */
|
||||
final_valuation,
|
||||
/** The source valuation id. */
|
||||
source_valuation_type,
|
||||
/** The final valuation id. */
|
||||
final_valuation_type,
|
||||
/** The specific method id. */
|
||||
specific_method;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new aggregation operator.
|
||||
*/
|
||||
public UnificationOperator() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the id.
|
||||
*
|
||||
* @return the id
|
||||
*/
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the id.
|
||||
*
|
||||
* @param id the new id
|
||||
*/
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name.
|
||||
*
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name.
|
||||
*
|
||||
* @param name the new name
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the source valuation id.
|
||||
*
|
||||
* @return the source valuation id
|
||||
*/
|
||||
public String getSourceValuationId() {
|
||||
return this.source_valuation_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the source valuation id.
|
||||
*
|
||||
* @param name the new source valuation id
|
||||
*/
|
||||
public void setSourceValuationId(String source_valuation_id) {
|
||||
this.source_valuation_id = source_valuation_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the final valuation id.
|
||||
*
|
||||
* @return the final valuation id
|
||||
*/
|
||||
public String getFinalValuationId() {
|
||||
return this.final_valuation_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the final valuation id.
|
||||
*
|
||||
* @param name the new final valuation id
|
||||
*/
|
||||
public void setFinalValuationId(String final_valuation_id) {
|
||||
this.final_valuation_id = final_valuation_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unify valuation
|
||||
* @param valuation valuation to unify
|
||||
* @param unificationDomain unification domain
|
||||
* @return unified valuation
|
||||
*/
|
||||
public abstract Valuation unify(Domain unificationDomain, Valuation valuation);
|
||||
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package flintstones.operator.unification.exception;
|
||||
|
||||
/**
|
||||
* The Class AggregationOperatorNotFound.
|
||||
*/
|
||||
public class UnificationOperatorFinalValuationNotFound extends Error {
|
||||
|
||||
/** The Constant serialVersionUID. */
|
||||
private static final long serialVersionUID = 3486693795198966709L;
|
||||
|
||||
/**
|
||||
* Instantiates a new unification operator not found.
|
||||
*
|
||||
* @param operatorId the operator id
|
||||
*/
|
||||
public UnificationOperatorFinalValuationNotFound(String finalValuation) {
|
||||
super("No existe operador de unificación que pueda unificar a " + finalValuation); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package flintstones.operator.unification.exception;
|
||||
|
||||
/**
|
||||
* The Class AggregationOperatorNotImplementedForValuation.
|
||||
*/
|
||||
public class UnificationOperatorNotImplemented extends Exception {
|
||||
|
||||
/** The Constant serialVersionUID. */
|
||||
private static final long serialVersionUID = 8029363988701450857L;
|
||||
|
||||
/**
|
||||
* Instantiates a new aggregation operator not implemented for valuation.
|
||||
*
|
||||
* @param operatorId the operator id
|
||||
* @param valuationId the valuation id
|
||||
*/
|
||||
public UnificationOperatorNotImplemented(String sourceValuation, String finalValuation) {
|
||||
super("No existe operador de unificación que unifique la valoración " + sourceValuation + " a la valoración " + finalValuation + "." ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package flintstones.operator.unification.provider;
|
||||
|
||||
import org.eclipse.e4.core.contexts.ContextFunction;
|
||||
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
|
||||
import org.eclipse.e4.core.contexts.IEclipseContext;
|
||||
import org.eclipse.e4.ui.model.application.MApplication;
|
||||
|
||||
import flintstones.operator.unification.service.IUnificationOperatorService;
|
||||
|
||||
public class UnificationOperatorServiceContextFunction extends ContextFunction {
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* org.eclipse.e4.core.contexts.ContextFunction#compute(org.eclipse.e4.core.
|
||||
* contexts.IEclipseContext, java.lang.String) */
|
||||
@Override
|
||||
public Object compute(IEclipseContext context, String contextKey) {
|
||||
IUnificationOperatorService service = ContextInjectionFactory.make(UnificationOperatorServiceProvider.class, context);
|
||||
MApplication application = context.get(MApplication.class);
|
||||
IEclipseContext applicationContext = application.getContext();
|
||||
applicationContext.set(IUnificationOperatorService.class, service);
|
||||
return service;
|
||||
}
|
||||
|
||||
}
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
package flintstones.operator.unification.provider;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.e4.core.contexts.IEclipseContext;
|
||||
|
||||
import flintstones.entity.domain.Domain;
|
||||
import flintstones.entity.valuation.Valuation;
|
||||
import flintstones.helper.extensionpoint.BaseRegistry;
|
||||
import flintstones.helper.extensionpoint.ExtensionRegistry;
|
||||
import flintstones.operator.unification.UnificationOperator;
|
||||
import flintstones.operator.unification.exception.UnificationOperatorFinalValuationNotFound;
|
||||
import flintstones.operator.unification.exception.UnificationOperatorNotImplemented;
|
||||
import flintstones.operator.unification.service.IUnificationOperatorService;
|
||||
|
||||
public class UnificationOperatorServiceProvider implements IUnificationOperatorService {
|
||||
|
||||
/** The extension point. */
|
||||
private final String EXTENSION_POINT_UNIFICATION = "flintstones.operator.unification.extensionpoint"; //$NON-NLS-1$
|
||||
|
||||
/** The context. */
|
||||
@Inject
|
||||
IEclipseContext context;
|
||||
|
||||
/** The register. */
|
||||
private final BaseRegistry unificationReg;
|
||||
|
||||
/**
|
||||
* Instantiates a new unification operator service provider.
|
||||
*/
|
||||
public UnificationOperatorServiceProvider() {
|
||||
this.unificationReg = new BaseRegistry(this.EXTENSION_POINT_UNIFICATION);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.operator.unification.service.IUnificationOperatorService#
|
||||
* getAggregationOperator(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public UnificationOperator getUnificationOperator(String sourceValuation, String finalValuation, String methodId) {
|
||||
|
||||
// The ER of the operator_type, allow us to find in its children the right
|
||||
// implementation for the given valuations
|
||||
|
||||
ExtensionRegistry[] registries = unificationReg.getAllRegistriesWhere("final_valuation_type", finalValuation);
|
||||
|
||||
if (registries.length == 0)
|
||||
throw new UnificationOperatorFinalValuationNotFound(finalValuation);
|
||||
|
||||
// We need the registry of the unification operator to instance it
|
||||
ExtensionRegistry selectedOperator = getUnificationOperator(registries, sourceValuation, finalValuation, methodId);
|
||||
|
||||
if (selectedOperator == null) {
|
||||
try {
|
||||
throw new UnificationOperatorNotImplemented(sourceValuation, finalValuation);
|
||||
} catch (UnificationOperatorNotImplemented e) {
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
UnificationOperator operator = (UnificationOperator) unificationReg.instantiate(selectedOperator, context);
|
||||
operator.setId(selectedOperator.getAttribute(UnificationOperator.Fields.id));
|
||||
operator.setSourceValuationId(sourceValuation);
|
||||
operator.setFinalValuationId(finalValuation);
|
||||
|
||||
return operator;
|
||||
}
|
||||
|
||||
private ExtensionRegistry getUnificationOperator(ExtensionRegistry[] registries, String sourceValuation, String finalValuation, String methodId) {
|
||||
List<ExtensionRegistry> registriesByValuation = new ArrayList<>();
|
||||
|
||||
ExtensionRegistry selectedOperator = null;
|
||||
|
||||
//Get unification operators with the same source and final valuation
|
||||
for(ExtensionRegistry local: registries) {
|
||||
for(ExtensionRegistry sourceRegistry: local.getAttributeReferences(UnificationOperator.Fields.source_valuation)) {
|
||||
if(sourceRegistry.getAttribute(UnificationOperator.Fields.source_valuation_type).equals(sourceValuation))
|
||||
registriesByValuation.add(sourceRegistry);
|
||||
}
|
||||
}
|
||||
|
||||
//Get the unification operator for a specific method if necessary
|
||||
if(registriesByValuation.size() == 1)
|
||||
selectedOperator = registriesByValuation.get(0);//Default unification operator
|
||||
else {
|
||||
String methodIdAttribute;
|
||||
for(ExtensionRegistry local: registriesByValuation) {
|
||||
methodIdAttribute = local.getAttribute(UnificationOperator.Fields.specific_method);
|
||||
if(methodIdAttribute != null) {
|
||||
if(methodIdAttribute.equals(methodId))
|
||||
selectedOperator = local;//Unification operator for specific domain
|
||||
} else
|
||||
selectedOperator = local;//Default unification operator
|
||||
}
|
||||
}
|
||||
|
||||
return selectedOperator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Valuation unify(Domain unificationDomain, Valuation valuation, String finalValuationType, String methodId) {
|
||||
UnificationOperator operator = this.getUnificationOperator(valuation.getId(), finalValuationType, methodId);
|
||||
Valuation result = operator.unify(unificationDomain, valuation);
|
||||
result.setId(finalValuationType);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package flintstones.operator.unification.service;
|
||||
|
||||
import flintstones.entity.domain.Domain;
|
||||
import flintstones.entity.valuation.Valuation;
|
||||
import flintstones.operator.unification.UnificationOperator;
|
||||
|
||||
/**
|
||||
* The Interface IUnificationOperatorService.
|
||||
*/
|
||||
public interface IUnificationOperatorService {
|
||||
|
||||
/**
|
||||
* Gets an unification operator for a specific method by the type of the source valuation and the type of the unified valuation.
|
||||
*
|
||||
* @param sourceValuationId id of source valuation
|
||||
* @param finalValuationId id of valuation to unify
|
||||
* @param methodId id of the method
|
||||
* @return Instanced UnificationOperator
|
||||
*/
|
||||
UnificationOperator getUnificationOperator(String sourceValuationId, String finalValuationId, String methodId);
|
||||
|
||||
/**
|
||||
* Unify.
|
||||
*
|
||||
* @param unificationDomain unification domain
|
||||
* @param valuation valuation to unify
|
||||
* @param finalValuationId id of valuation to unify
|
||||
* @param methodId id of the method
|
||||
* @return Final unified valuation
|
||||
*/
|
||||
Valuation unify(Domain unificationDomain, Valuation valuation, String finalValuationId, String methodId);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user