public code v1

This commit is contained in:
2026-05-22 11:14:29 +02:00
parent 427197ec5a
commit b8141736eb
28859 changed files with 575079 additions and 0 deletions
+7
View File
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
+1
View File
@@ -0,0 +1 @@
/bin/
+39
View File
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>afryca.structure</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ds.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
@@ -0,0 +1,7 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
@@ -0,0 +1,23 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-SymbolicName: afryca.structure;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Export-Package: afryca.structure,
afryca.structure.definition,
afryca.structure.pair,
afryca.structure.provider,
afryca.structure.ranking,
afryca.structure.service,
afryca.structure.service.provider
Require-Bundle: afryca.domain;visibility:=reexport,
afryca.cm;visibility:=reexport,
org.eclipse.core.runtime;bundle-version="3.12.0";visibility:=reexport,
org.eclipse.e4.core.contexts;bundle-version="1.5.1";visibility:=reexport,
org.eclipse.e4.ui.model.workbench;bundle-version="1.2.0";visibility:=reexport,
org.eclipse.e4.core.di;bundle-version="1.6.1";visibility:=reexport
Service-Component: OSGI-INF/structure_service_context_function.xml,
OSGI-INF/structure_provider_context_function.xml
Bundle-ActivationPolicy: lazy
Automatic-Module-Name: afryca.structure
@@ -0,0 +1,3 @@
#Properties file for afryca.domain
extension-point.name = Domain
Bundle-Name = Domain
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="IStructureProvider context function">
<implementation class="afryca.provider.structure.internal.StructureProviderContextFunction"/>
<property name="service.context.key" type="String" value="afryca.structure.provider.IStructureProvider"/>
<service>
<provide interface="org.eclipse.e4.core.contexts.IContextFunction"/>
</service>
</scr:component>
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="IStructureService context">
<implementation class="afryca.structure.service.provider.StructureServiceContextFunction"/>
<property name="service.context.key" type="String" value="afryca.structure.service.IStructureService"/>
<service>
<provide interface="org.eclipse.e4.core.contexts.IContextFunction"/>
</service>
</scr:component>
+11
View File
@@ -0,0 +1,11 @@
output.. = bin/
bin.includes = META-INF/,\
.,\
plugin.xml,\
OSGI-INF/l10n/bundle.properties,\
OSGI-INF/,\
OSGI-INF/structure_service_context_function.xml,\
OSGI-INF/structure_service_context_function.xml,\
OSGI-INF/structure_provider_context_function.xml,\
OSGI-INF/structure_provider_context_function.xml
source.. = src/
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension-point id="structure" name="%extension-point.name" schema="schema/structure.exsd"/>
</plugin>
@@ -0,0 +1,137 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="afryca.structure" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appinfo>
<meta.schema plugin="afryca.structure" id="structure" name="Structure"/>
</appinfo>
<documentation>
[Enter description of this extension point.]
</documentation>
</annotation>
<element name="extension">
<annotation>
<appinfo>
<meta.element />
</appinfo>
</annotation>
<complexType>
<choice minOccurs="1" maxOccurs="unbounded">
<element ref="structure_type"/>
</choice>
<attribute name="point" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="id" type="string">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="name" type="string">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute translatable="true"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>
<element name="structure_type">
<complexType>
<choice minOccurs="0" maxOccurs="unbounded">
<element ref="domain"/>
</choice>
<attribute name="id" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute kind="identifier"/>
</appinfo>
</annotation>
</attribute>
<attribute name="name" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="type" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute kind="java" basedOn="afryca.structure.Structure:"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>
<element name="domain">
<complexType>
<attribute name="id" type="string">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute kind="identifier" basedOn="afryca.domain.domain/domain/@id"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>
<annotation>
<appinfo>
<meta.section type="since"/>
</appinfo>
<documentation>
[Enter the first release in which this extension point appears.]
</documentation>
</annotation>
<annotation>
<appinfo>
<meta.section type="examples"/>
</appinfo>
<documentation>
[Enter extension point usage example here.]
</documentation>
</annotation>
<annotation>
<appinfo>
<meta.section type="apiinfo"/>
</appinfo>
<documentation>
[Enter API information here.]
</documentation>
</annotation>
<annotation>
<appinfo>
<meta.section type="implementation"/>
</appinfo>
<documentation>
[Enter information about supplied implementation of this extension point.]
</documentation>
</annotation>
</schema>
@@ -0,0 +1,31 @@
package afryca.provider.structure.internal;
import javax.inject.Inject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import afryca.structure.Structure;
import afryca.structure.definition.EElements;
import afryca.structure.definition.StructureRegistry;
import afryca.structure.provider.IStructureProvider;
import afryca.structure.service.IStructureService;
public class StructureDefaultProvider implements IStructureProvider {
@Inject
private IStructureService structureService;
@Override
public Structure createStructure(String structureId) {
StructureRegistry structureRegistry = structureService.getRegistry(structureId);
IConfigurationElement type = structureRegistry.getConfiguration();
try {
return (Structure) type.createExecutableExtension(EElements.type.toString());
} catch (CoreException e) {
e.printStackTrace();
return null;
}
}
}
@@ -0,0 +1,20 @@
package afryca.provider.structure.internal;
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 afryca.structure.provider.IStructureProvider;
public class StructureProviderContextFunction extends ContextFunction {
@Override
public Object compute(IEclipseContext context, String contextKey) {
IStructureProvider structureProvider = ContextInjectionFactory.make(StructureDefaultProvider.class, context);
MApplication application = context.get(MApplication.class);
IEclipseContext applicationContext = application.getContext();
applicationContext.set(IStructureProvider.class, structureProvider);
return structureProvider;
}
}
@@ -0,0 +1,79 @@
package afryca.structure;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.List;
import afryca.domain.Domain;
import afryca.structure.ranking.AbstractDominanceRanking;
public abstract class Structure implements Cloneable {
public static final String EXTENSION_POINT = "afryca.structure.structure";
protected PropertyChangeSupport changes = new PropertyChangeSupport(this);
public abstract void initialize();
public abstract Object getPreferences();
public abstract Object getPreferenceSize();
public abstract int getNumberOfAlternatives();
public abstract Object getValue(Object...indexes);
public abstract Object getDomain(Object...domain);
public abstract void setDomain(Object...domain);
public abstract void removeAlternativePreferences(int index);
public abstract void backwardAlternativePreferences(int index);
public abstract void forwardAlternativePreferences(int index);
public abstract Structure groupPreferences(int numberOfExperts, int numberOfAlternatives, int numberOfCriteria, Structure[] preferences);
public abstract Structure parseStructure(String readablePreference, String readableDomains, List<Domain> domains);
public abstract Object createDefaultStructure(Object...info);
public abstract AbstractDominanceRanking createRanking();
public abstract Object clone() throws CloneNotSupportedException;
public abstract String [] getRandomKeys();
public abstract String [] getPreferencesKeys();
public abstract Structure random(int n);
public abstract boolean hasDomain();
public abstract Float[][] obtainVisualizeValues();
/**
* Add property change listener
*
* @param listener
* Property change listener
*/
public void addPropertyChangeListener(PropertyChangeListener listener) {
changes.addPropertyChangeListener(listener);
}
/**
* Remove property change listener
*
* @param listener
* Property change listener
*/
public void removePropertyChangeListener(PropertyChangeListener listener) {
changes.removePropertyChangeListener(listener);
}
}
@@ -0,0 +1,23 @@
package afryca.structure.definition;
/**
* Consensus model elements
*
* @author Sinbad²
* @version 3.0
*/
public enum EElements {
// Domain id
id,
// Domain name
name,
// Domain
domain,
// Type of domain
type
}
@@ -0,0 +1,61 @@
package afryca.structure.definition;
import org.eclipse.core.runtime.IConfigurationElement;
/**
* Registry for the extension point of PR
*
* @author Sinbad²
* @version 3.0
*/
public class StructureRegistry {
private IConfigurationElement configuration;
/**
* Default builder
*/
private StructureRegistry() {
configuration = null;
}
/**
* Builder
*
* @param element
* Domain configuration element
*/
public StructureRegistry(IConfigurationElement element) {
this();
configuration = element;
}
/**
* Return Domain configuration
*
* @return Domain configuration
*/
public IConfigurationElement getConfiguration() {
return configuration;
}
/**
* Return Domain element value
*
* @param element
* element key
* @return element value
*/
public String getElement(EElements element) {
String result = null;
if (configuration != null) {
result = configuration.getAttribute(element.toString());
}
return result;
}
}
@@ -0,0 +1,58 @@
package afryca.structure.pair;
public class Pair<L, R> {
private L _left;
private R _right;
public Pair() {
_left = null;
_right = null;
}
public Pair(L left, R right) {
_left = left;
_right = right;
}
public L getLeft() {
return _left;
}
public R getRight() {
return _right;
}
public void add(L left, R right) {
_left = left;
_right = right;
}
@Override
public int hashCode() {
return _left.hashCode() ^ _right.hashCode();
}
@Override
public boolean equals(Object o) {
if (!(o instanceof Pair)) {
return false;
}
Pair<?, ?> pairo = (Pair<?, ?>) o;
return this._left.equals(pairo.getLeft()) && this._right.equals(pairo.getRight());
}
public boolean isEmpty() {
return (_left == null) && (_right == null);
}
public void clear() {
_left = null;
_right = null;
}
@Override
public String toString() {
return "(" + _left.toString() + ", " + _right.toString() + ")";
}
}
@@ -0,0 +1,77 @@
package afryca.structure.pair;
public class Quadruple<Q1, Q2, Q3, Q4> {
private Q1 q1;
private Q2 q2;
private Q3 q3;
private Q4 q4;
public Quadruple() {
q1 = null;
q2 = null;
q3 = null;
q4 = null;
}
public Quadruple(Q1 q1, Q2 q2, Q3 q3, Q4 q4) {
this.q1 = q1;
this.q2 = q2;
this.q3 = q3;
this.q4 = q4;
}
public Q1 getQ1() {
return q1;
}
public Q2 getQ2() {
return q2;
}
public Q3 getQ3() {
return q3;
}
public Q4 getQ4() {
return q4;
}
public void add(Q1 q1, Q2 q2, Q3 q3, Q4 q4) {
this.q1 = q1;
this.q2 = q2;
this.q3 = q3;
this.q4 = q4;
}
@Override
public int hashCode() {
return q1.hashCode() ^ q2.hashCode() ^ q3.hashCode() ^ q4.hashCode();
}
@Override
public boolean equals(Object o) {
if (!(o instanceof Quadruple)) {
return false;
}
Quadruple<?, ?, ?, ?> pairo = (Quadruple<?, ?, ?, ?>) o;
return this.q1.equals(pairo.getQ1()) && this.q2.equals(pairo.getQ2())
&& this.q3.equals(pairo.getQ3()) && this.q4.equals(pairo.getQ4());
}
public boolean isEmpty() {
return (q1 == null) && (q2 == null) && (q3 == null) && (q4 == null);
}
public void clear() {
q1 = null;
q2 = null;
q3 = null;
q4 = null;
}
@Override
public String toString() {
return "(" + q1.toString() + ", " + q2.toString() + ", " + q3.toString() + ", " + q4.toString() + ")";
}
}
@@ -0,0 +1,68 @@
package afryca.structure.pair;
public class Triplet<T1, T2, T3> {
private T1 t1;
private T2 t2;
private T3 t3;
public Triplet() {
t1 = null;
t2 = null;
t3 = null;
}
public Triplet(T1 t1, T2 t2, T3 t3) {
this.t1 = t1;
this.t2 = t2;
this.t3 = t3;
}
public T1 getT1() {
return t1;
}
public T2 getT2() {
return t2;
}
public T3 getT3() {
return t3;
}
public void add(T1 t1, T2 t2, T3 t3) {
this.t1 = t1;
this.t2 = t2;
this.t3 = t3;
}
@Override
public int hashCode() {
return t1.hashCode() ^ t2.hashCode() ^ t3.hashCode();
}
@Override
public boolean equals(Object o) {
if (!(o instanceof Triplet)) {
return false;
}
Triplet<?, ?, ?> pairo = (Triplet<?, ?, ?>) o;
return this.t1.equals(pairo.getT1()) && this.t2.equals(pairo.getT2())
&& this.t3.equals(pairo.getT3());
}
public boolean isEmpty() {
return (t1 == null) && (t2 == null) && (t3 == null);
}
public void clear() {
t1 = null;
t2 = null;
t3 = null;
}
@Override
public String toString() {
return "(" + t1.toString() + ", " + t2.toString() + ", " + t3.toString() + ")";
}
}
@@ -0,0 +1,16 @@
package afryca.structure.provider;
import afryca.structure.Structure;
public interface IStructureProvider {
/**
* Return structure
*
* @param structureID
* Structure id
* @return Structure
*/
Structure createStructure(String structureId);
}
@@ -0,0 +1,87 @@
package afryca.structure.ranking;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import afryca.cm.CM;
/**
* Abstract dominance ranking
*
* @author Sinbad²
* @version 3.0
*/
public abstract class AbstractDominanceRanking {
protected CM cm;
protected List<AlternativeRanking> alternativesRanking;
protected Float[] values;
/**
* Default builder
*/
public AbstractDominanceRanking() {
alternativesRanking = new ArrayList<>();
}
/**
* Return alternatives order
*
* @return Alternatives order
*/
public abstract Integer[] getAlternativesOrder();
/**
* Return alternatives values
*
* @return Alternatives values
*/
public Float[] getAlternativesValues() {
return values;
}
/**
* Return alternatives ranking
*
* @return Alternatives ranking
*/
public abstract AlternativeRanking[] getAlternativesRanking();
/**
* Compute values ranking
*
* @param values
* Values to compute ranking
*
* @return Ranking
*/
public static AlternativeRanking[] computeRanking(Float[] values) {
AlternativeRanking[] result = new AlternativeRanking[values.length];
List<Float> orderedValues = new ArrayList<>();
for (int i = 0; i < values.length; i++) {
orderedValues.add(values[i]);
}
Collections.sort(orderedValues);
Collections.reverse(orderedValues);
boolean find;
int pos;
for (int i = 0; i < values.length; i++) {
find = false;
pos = 0;
do {
if (orderedValues.get(pos).floatValue() == values[i]
.floatValue()) {
find = true;
} else {
pos++;
}
} while (!find);
result[i] = new AlternativeRanking(pos, values[i]);
}
return result;
}
}
@@ -0,0 +1,180 @@
package afryca.structure.ranking;
import java.text.MessageFormat;
import java.util.Collections;
import java.util.HashSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
/**
* Class for alternative ranking
*
* @author Sinbad²
* @version 3.0
*/
public class AlternativeRanking {
// {0} position - {1} value
private final static String STRING_FORMAT = "({0},{1})"; //$NON-NLS-1$
private Integer position;
private Object value;
/**
* AlternativeRanking builder
*
* @param position
* Position in ranking
* @param value
* Value
*/
public AlternativeRanking(Integer position, Object value) {
this.position = position;
this.value = value;
}
/**
* Return position in ranking
*
* @return Position in ranking
*/
public Integer getPosition() {
return position;
}
/**
* Return alternative value
*
* @return Value
*/
public Object getValue() {
return value;
}
@Override
public String toString() {
return MessageFormat.format(STRING_FORMAT, position, value);
}
/**
* Order alternatives ranking
*
* @param in
* Alternatives ranking order with position
* @return Alternatives ranking order with value
*/
public static AlternativeRanking[] orderRanking(AlternativeRanking[] in) {
AlternativeRanking[] result = new AlternativeRanking[in.length];
// Get all ranking positions
Integer position = 0;
for (Integer rankingPos : getRankingPositions(in)) {
for (Integer element : getAlternativesWithRankingPos(in, rankingPos)) {
result[position++] = new AlternativeRanking(element, in[element].getValue());
}
}
return result;
}
/**
* Generates string output from a ordered alternatives ranking
*
* @param ranking
* Ordered ranking
* @return String output
*/
public static String orderedAlternativesRankingToString(AlternativeRanking[] ranking) {
StringBuilder result = new StringBuilder();
for (int i = 0; i < ranking.length; i++) {
if (i > 0) {
if (alternativesHaveTheSameRanking(ranking[i - 1], ranking[i])) {
result.append(" \u223C "); //$NON-NLS-1$
} else {
result.append(" \u227B "); //$NON-NLS-1$ //$NON-NLS-2$
}
}
result.append(alternativeAbbreviation(ranking[i]));
}
return result.toString();
}
private static boolean alternativesHaveTheSameRanking(AlternativeRanking r1, AlternativeRanking r2) {
if(r1.getValue() instanceof Float) {
return ((Float) r1.getValue()).floatValue() == ((Float) r2.getValue()).floatValue();
} else {
return ((String) r1.getValue()).equals((String) r2.getValue());
}
}
private static String alternativeAbbreviation(AlternativeRanking ranking) {
return "x" + (ranking.getPosition() + 1); //$NON-NLS-1$
}
/**
* Get all positions in ranking
*
* @param in
* AlternativeRanking
* @return Positions show in ranking
*/
public static Integer[] getRankingPositions(AlternativeRanking[] in) {
Integer[] result;
// Search all different positions
Set<Integer> allPositionInRanking = new HashSet<>();
for (AlternativeRanking value : in) {
allPositionInRanking.add(Integer.valueOf(value.getPosition()));
}
// Make a list with positions
List<Integer> auxRanking = new ArrayList<>();
for (Integer value : allPositionInRanking) {
auxRanking.add(Integer.valueOf(value));
}
// Order the list
Collections.sort(auxRanking);
// Convert list to array
result = auxRanking.toArray(new Integer[0]);
return result;
}
/**
* Get all alternatives position with concrete ranking position
*
* @param ranking
* All alternatives
* @param rankingPos
* Ranking position
* @return Alternatives position with rankingPos
*/
public static Integer[] getAlternativesWithRankingPos(AlternativeRanking[] ranking, int rankingPos) {
Integer[] result;
// Search all alternatives with rankingPos
Set<Integer> alternativesPosition = new HashSet<>();
for (int i = 0; i < ranking.length; i++) {
if (ranking[i].getPosition() == rankingPos) {
alternativesPosition.add(Integer.valueOf(i));
}
}
// Return all alternatives position
result = new Integer[alternativesPosition.size()];
int element = 0;
for (Integer position : alternativesPosition) {
result[element++] = Integer.valueOf(position);
}
return result;
}
}
@@ -0,0 +1,50 @@
package afryca.structure.service;
import java.util.List;
import afryca.structure.definition.StructureRegistry;
public interface IStructureService {
public static final String CONTEXT = "structure.service.context"; //$NON-NLS-1$
// Selected structure
public static final String SELECTED_PR = "SELECTED "; //$NON-NLS-1$
/**
* Return all registers id
*
* @return Registers id
*/
String[] getIds();
/**
* Return a StructureRegistry
*
* @param id
* Id of the StructureRegistry
* @return StructureRegistry
*/
StructureRegistry getRegistry(String id);
/**
* Return a StructureRegistry id
*
* @param name
* Name of the StructureRegistry
* @return Registry id
*/
String getRegistryIdByName(String name);
/**
* Return a list of domains id
*
* @param id
* id of the StructureRegistry
* @return List of available domains id
*/
List<String> getDomains(String id);
}
@@ -0,0 +1,26 @@
package afryca.structure.service.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 afryca.structure.service.IStructureService;
/**
* Structure service context function
*
* @author Sinbad²
* @version 3.0
*/
public class StructureServiceContextFunction extends ContextFunction {
@Override
public Object compute(IEclipseContext context, String contextKey) {
IStructureService structureService = ContextInjectionFactory.make(StructureServiceProvider.class, context);
MApplication application = context.get(MApplication.class);
IEclipseContext applicationContext = application.getContext();
applicationContext.set(IStructureService.class, structureService);
return structureService;
}
}
@@ -0,0 +1,124 @@
package afryca.structure.service.provider;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.ui.model.application.MApplication;
import afryca.structure.Structure;
import afryca.structure.definition.EElements;
import afryca.structure.definition.StructureRegistry;
import afryca.structure.provider.IStructureProvider;
import afryca.structure.service.IStructureService;
/**
* Structure service provider
*
* @author Sinbad²
* @version 3.0
*/
public class StructureServiceProvider implements IStructureService {
private Map<String, StructureRegistry> registers;
private Map<String, List<String>> registersDomains;
@Inject
private IEclipseContext context;
@Inject
public StructureServiceProvider() {
registers = new HashMap<>();
registersDomains = new HashMap<>();
}
@PostConstruct
private void initialize() {
loadProviders();
loadRegisters();
setEclipseContext();
}
private void loadProviders() {
// It's not set until @PostConstruct does not end
context.set(IStructureService.class, this);
context.get(IStructureProvider.class);
}
private void loadRegisters() {
IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry();
IConfigurationElement[] extensionElements = extensionRegistry.getConfigurationElementsFor(Structure.EXTENSION_POINT);
Arrays.stream(extensionElements).forEach(this::loadRegistry);
}
private void loadRegistry(IConfigurationElement extensionElement) {
StructureRegistry registry = new StructureRegistry(extensionElement);
registers.put(registry.getElement(EElements.id), registry);
loadRegistryDomain(registry);
}
private void loadRegistryDomain(StructureRegistry registry) {
IConfigurationElement[] conf = registry.getConfiguration().getChildren(EElements.domain.toString());
String registryId = registry.getElement(EElements.id);
if(conf.length != 0) {
for(int d = 0; d < conf.length; d++) {
IConfigurationElement domain = conf[d];
List<String> domains;
if(registersDomains.get(registryId) != null) {
domains = registersDomains.get(registryId);
} else {
domains = new LinkedList<String>();
}
domains.add(domain.getAttribute(EElements.id.toString()));
registersDomains.put(registryId, domains);
}
}
}
private void setEclipseContext() {
getApplicationContext().set(CONTEXT, context);
}
@Override
public String[] getIds() {
return registers.keySet().toArray(new String[0]);
}
@Override
public StructureRegistry getRegistry(String id) {
return registers.get(id);
}
@Override
public String getRegistryIdByName(String name) {
for(String id: registers.keySet()) {
StructureRegistry registry = registers.get(id);
if(registry.getElement(EElements.name).equals(name)) {
return id;
}
}
return null;
}
@Override
public List<String> getDomains(String id) {
return registersDomains.get(id);
}
private IEclipseContext getApplicationContext() {
MApplication application = context.get(MApplication.class);
return application.getContext();
}
}
@@ -0,0 +1,20 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-SymbolicName: afryca.structure;singleton:=true
Bundle-Version: 1.0.0.202101221157
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Export-Package: afryca.structure,afryca.structure.definition,afryca.stru
cture.pair,afryca.structure.provider,afryca.structure.ranking,afryca.st
ructure.service,afryca.structure.service.provider
Require-Bundle: afryca.domain;visibility:=reexport,afryca.cm;visibility:
=reexport,org.eclipse.core.runtime;bundle-version="3.12.0";visibility:=
reexport,org.eclipse.e4.core.contexts;bundle-version="1.5.1";visibility
:=reexport,org.eclipse.e4.ui.model.workbench;bundle-version="1.2.0";vis
ibility:=reexport,org.eclipse.e4.core.di;bundle-version="1.6.1";visibil
ity:=reexport
Service-Component: OSGI-INF/structure_service_context_function.xml,OSGI-
INF/structure_provider_context_function.xml
Bundle-ActivationPolicy: lazy
Automatic-Module-Name: afryca.structure
@@ -0,0 +1,4 @@
#Fri Jan 22 12:59:18 CET 2021
artifact.main=C\:\\Users\\\u00C1lvaro\\Workspaces\\afryca_2020\\afryca\\plugins\\afryca.structure\\target\\afryca.structure-1.0.0-SNAPSHOT.jar
artifact.attached.p2artifacts=C\:\\Users\\\u00C1lvaro\\Workspaces\\afryca_2020\\afryca\\plugins\\afryca.structure\\target\\p2artifacts.xml
artifact.attached.p2metadata=C\:\\Users\\\u00C1lvaro\\Workspaces\\afryca_2020\\afryca\\plugins\\afryca.structure\\target\\p2content.xml
@@ -0,0 +1,3 @@
artifactId=afryca.structure
groupId=afryca.group
version=1.0.0-SNAPSHOT
@@ -0,0 +1,13 @@
<?xml version='1.0' encoding='UTF-8'?>
<?artifactRepository version='1.1.0'?>
<artifacts size='1'>
<artifact classifier='osgi.bundle' id='afryca.structure' version='1.0.0.202101221157'>
<properties size='5'>
<property name='artifact.size' value='20379'/>
<property name='download.size' value='20379'/>
<property name='maven-groupId' value='afryca.group'/>
<property name='maven-artifactId' value='afryca.structure'/>
<property name='maven-version' value='1.0.0-SNAPSHOT'/>
</properties>
</artifact>
</artifacts>
@@ -0,0 +1,55 @@
<?xml version='1.0' encoding='UTF-8'?>
<units size='1'>
<unit id='afryca.structure' version='1.0.0.202101221157' generation='2'>
<update id='afryca.structure' range='[0.0.0,1.0.0.202101221157)' severity='0'/>
<properties size='5'>
<property name='df_LT.Bundle-Name' value='Domain'/>
<property name='org.eclipse.equinox.p2.name' value='%Bundle-Name'/>
<property name='maven-groupId' value='afryca.group'/>
<property name='maven-artifactId' value='afryca.structure'/>
<property name='maven-version' value='1.0.0-SNAPSHOT'/>
</properties>
<provides size='12'>
<provided namespace='org.eclipse.equinox.p2.iu' name='afryca.structure' version='1.0.0.202101221157'/>
<provided namespace='osgi.bundle' name='afryca.structure' version='1.0.0.202101221157'/>
<provided namespace='java.package' name='afryca.structure' version='0.0.0'/>
<provided namespace='java.package' name='afryca.structure.definition' version='0.0.0'/>
<provided namespace='java.package' name='afryca.structure.pair' version='0.0.0'/>
<provided namespace='java.package' name='afryca.structure.provider' version='0.0.0'/>
<provided namespace='java.package' name='afryca.structure.ranking' version='0.0.0'/>
<provided namespace='java.package' name='afryca.structure.service' version='0.0.0'/>
<provided namespace='java.package' name='afryca.structure.service.provider' version='0.0.0'/>
<provided namespace='osgi.identity' name='afryca.structure' version='1.0.0.202101221157'>
<properties size='1'>
<property name='type' value='osgi.bundle'/>
</properties>
</provided>
<provided namespace='org.eclipse.equinox.p2.eclipse.type' name='bundle' version='1.0.0'/>
<provided namespace='org.eclipse.equinox.p2.localization' name='df_LT' version='1.0.0'/>
</provides>
<requires size='7'>
<required namespace='osgi.bundle' name='afryca.domain' range='0.0.0'/>
<required namespace='osgi.bundle' name='afryca.cm' range='0.0.0'/>
<required namespace='osgi.bundle' name='org.eclipse.core.runtime' range='3.12.0'/>
<required namespace='osgi.bundle' name='org.eclipse.e4.core.contexts' range='1.5.1'/>
<required namespace='osgi.bundle' name='org.eclipse.e4.ui.model.workbench' range='1.2.0'/>
<required namespace='osgi.bundle' name='org.eclipse.e4.core.di' range='1.6.1'/>
<requiredProperties namespace='osgi.ee' match='(&amp;(osgi.ee=JavaSE)(version=1.8))'>
<description>
afryca.structure
</description>
</requiredProperties>
</requires>
<artifacts size='1'>
<artifact classifier='osgi.bundle' id='afryca.structure' version='1.0.0.202101221157'/>
</artifacts>
<touchpoint id='org.eclipse.equinox.p2.osgi' version='1.0.0'/>
<touchpointData size='1'>
<instructions size='1'>
<instruction key='manifest'>
Bundle-SymbolicName: afryca.structure;singleton:=true&#xA;Bundle-Version: 1.0.0.202101221157&#xA;
</instruction>
</instructions>
</touchpointData>
</unit>
</units>