public code v1

This commit is contained in:
Francisco Jesús Martínez Mimbrera
2026-05-23 00:32:57 +02:00
commit 759a8968a2
4357 changed files with 163763 additions and 0 deletions
@@ -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>
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>flintstones.group</groupId>
<artifactId>flintstones.bundles</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>flintstones.helper.extensionpoint</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<name>[bundle] Service</name>
</project>
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>flintstones.helper.extensionpoint</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.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>
<filteredResources>
<filter>
<id>1779484362610</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
@@ -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,13 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Service
Bundle-SymbolicName: flintstones.helper.extensionpoint
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.eclipse.e4.core.di;visibility:=reexport,
org.eclipse.e4.core.contexts;visibility:=reexport,
org.eclipse.core.runtime;visibility:=reexport,
flintstones.entity.extensionenum;visibility:=reexport,
flintstones.helper.locale
Export-Package: flintstones.helper.extensionpoint
Automatic-Module-Name: flintstones.helper.extensionpoint
@@ -0,0 +1,4 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
@@ -0,0 +1,405 @@
package flintstones.helper.extensionpoint;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;
import flintstones.entity.extensionenum.ExtensionEnum;
/**
* The Class BaseRegistry.
*/
public class BaseRegistry {
/** The registers. */
private final ArrayList<ExtensionRegistry> registers;
/** The extension point. */
private final String extensionPoint;
/** The label id. */
private String label_id = "uid"; //$NON-NLS-1$
/** The label implementation. */
private String label_implementation = "implementation"; //$NON-NLS-1$
/**
* Instantiates a new domain service provider.
* @param extensionPoint The extensionPoint
*/
public BaseRegistry(String extensionPoint) {
this.extensionPoint = extensionPoint;
this.registers = new ArrayList<>();
this.loadRegisters();
}
/**
* Gets the registry id.
*
* @return the registry id
*/
public String getRegistryId() {
return this.extensionPoint;
}
/**
* Load registers.
*/
private void loadRegisters() {
IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry();
IConfigurationElement[] extensionElements = extensionRegistry.getConfigurationElementsFor(this.extensionPoint); // Domain.EXTENSION_POINT
Arrays.stream(extensionElements)
.forEach(this::loadRegistry);
}
/**
* Load registry.
*
* @param extensionElement the extension element
*/
private void loadRegistry(IConfigurationElement extensionElement) {
ExtensionRegistry registry = new ExtensionRegistry(extensionElement);
this.registers.add(registry);
}
/**
* Gets the first registry where.
*
* @param key The key of the item you are looking for
* @param value The value of the key.
* @return The first ExtensionRegistry with the given key,value, null if the value does not exists for the given key. If the ke
*/
public ExtensionRegistry getFirstRegistryWhere(ExtensionEnum key, String value) {
return this.getFirstRegistryWhere(key.toString(), value);
}
/**
* Gets the first registry where.
*
* @param key The key of the item you are looking for
* @param value The value of the key.
* @return The first ExtensionRegistry with the given key,value, null if the value does not exists for the given key. If the ke
*/
public ExtensionRegistry getFirstRegistryWhere(String key, String value) {
for (ExtensionRegistry er : this.registers) {
if (er.getAttribute(key) == null)
throw new InvalidKeyIdentifier(key,value);
if (er.getAttribute(key)
.equals(value))
return er;
}
return null;
}
/**
* Gets the all registries where.
*
* @param key The key of the item you are looking for
* @param value The value of the key.
* @return all the ExtensionRegistry with the given key
*/
public ExtensionRegistry[] getAllRegistriesWhere(ExtensionEnum key, String value) {
return this.getAllRegistriesWhere(key.toString(), value);
}
/**
* Gets the all registries where.
*
* @param key The key of the item you are looking for
* @param value The value of the key.
* @return all the ExtensionRegistry with the given key
*/
public ExtensionRegistry[] getAllRegistriesWhere(String key, String value) {
ArrayList<ExtensionRegistry> erl = new ArrayList<>();
for (ExtensionRegistry er : this.registers)
if (er.getAttribute(key)
.equals(value))
erl.add(er);
return erl.toArray(new ExtensionRegistry[erl.size()]);
}
/**
* Gets the all attributes where.
*
* @param key The key of the item you are looking for
* @param value The value of the key.
* @param attribute The attribute to get from the obtained registers
* @return An array with the wanted attribute from the registers where key=value.
*/
public String[] getAllAttributesWhere(ExtensionEnum key, String value, ExtensionEnum attribute) {
return this.getAllAttributesWhere(key.toString(), value, attribute.toString());
}
/**
* Gets the all attributes where.
*
* @param key The key of the item you are looking for
* @param value The value of the key.
* @param attribute The attribute to get from the obtained registers
* @return An array with the wanted attribute from the registers where key=value.
*/
public String[] getAllAttributesWhere(String key, String value, String attribute) {
ExtensionRegistry[] arr = this.getAllRegistriesWhere(key, value);
return Arrays.asList(arr)
.stream()
.map(k -> k.getAttribute(attribute))
.toArray(String[]::new);
}
/**
* Gets the all registries.
*
* @return Every ExtensionRegistry available.
*/
public ExtensionRegistry[] getAllRegistries() {
return this.registers.toArray(new ExtensionRegistry[this.registers.size()]);
}
/**
* Gets the all attributes.
*
* @param attr The attribute of the ExtensionRegistry you are looking for
* @return The value for the given attribute of every ExtensionRegistry.
*/
public String[] getAllAttributes(ExtensionEnum attr) {
return this.getAllAttributes(attr.toString());
}
/**
* Gets the all attributes.
*
* @param attr The attribute of the ExtensionRegistry you are looking for
* @return The value for the given attribute of every ExtensionRegistry.
*/
public String[] getAllAttributes(String attr) {
ArrayList<String> attrs = new ArrayList<>();
for (ExtensionRegistry er : this.registers) {
String val = er.getAttribute(attr);
if (val != null)
attrs.add(val);
}
return attrs.toArray(new String[attrs.size()]);
}
/**
* Gets the all attributes unique.
*
* @param attr The attribute of the ExtensionRegistry you are looking for
* @return The value for the given attribute of every ExtensionRegistry, deleting the duplicated ones.
*/
public String[] getAllAttributesUnique(ExtensionEnum attr) {
return this.getAllAttributesUnique(attr.toString());
}
/**
* Gets the all attributes unique.
*
* @param attr The attribute of the ExtensionRegistry you are looking for
* @return The value for the given attribute of every ExtensionRegistry, deleting the duplicated ones.
*/
public String[] getAllAttributesUnique(String attr) {
return this.unique(this.getAllAttributes(attr));
}
/**
* Gets the attribute from an ExtensionRegistry id
* @param attrId The ExtensionRegistry id
* @param attr The attribute you are looking for
* @return
*/
public String getAttributeFromId(String attrId, ExtensionEnum attr) {
ExtensionRegistry extensionRegistry = this.getFirstRegistryWhere(this.getLabel_id(), attrId);
return extensionRegistry.getAttribute(attr);
}
/**
* Unique.
*
* @param arr An array of items
* @return The same items without repeats
*/
private String[] unique(String[] arr) {
int end = arr.length;
Set<String> set = new HashSet<>();
for (int i = 0; i < end; i++)
set.add(arr[i]);
return set.toArray(new String[set.size()]);
}
/**
* Instantiate.
*
* @param id The ID of the extension registry to instantiate
* @return The instantiated item
*/
public Object instantiate(String id) {
return this.instantiate(id, null);
}
/**
* Instantiate using the extension Registry directy. Pretty usefull for creating child items.
* @param extensionRegistry The extension registry to instantiate
* @return The instantiated item
*/
public Object instantiate(ExtensionRegistry extensionRegistry) {
return this.instantiate(extensionRegistry, null);
}
/**
* Instantiate.
*
* @param id The ID of the extension registry to instantiate
* @param context The context to register the object in. If it is null, it won't be registered.
* @return The instantiated item
*/
public Object instantiate(String id, IEclipseContext context) {
// Grab
ExtensionRegistry extensionRegistry = this.getFirstRegistryWhere(this.getLabel_id(), id);
if (extensionRegistry == null) {
System.err.println("Extensión no encontrada: ID: " + id); //$NON-NLS-1$
System.err.println("Extensiones disponibles para el punto de extension " + this.extensionPoint); //$NON-NLS-1$
System.err.println(this.toString());
throw new InvalidExtensionIdentifier(id);
}
return this.instantiate(extensionRegistry, context);
}
/**
* Instantiate using the extension Registry directy. Pretty usefull for creating child items.
* @param extensionRegistry The extension registry to instantiate
* @param context The context to register the object in. If it is null, it won't be registered.
* @return The instantiated item
*/
public Object instantiate(ExtensionRegistry extensionRegistry, IEclipseContext context) {
// Grab
IConfigurationElement conf = extensionRegistry.getConfiguration();
try {
Object item = conf.createExecutableExtension(this.getLabel_implementation());
if (context != null)
ContextInjectionFactory.inject(item, context);
return item;
} catch (CoreException e) {
e.printStackTrace();
return null;
}
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
for (ExtensionRegistry de : this.getAllRegistries()) {
sb.append(de.toString());
sb.append("\n"); //$NON-NLS-1$
}
return sb.toString();
}
/**
* Gets the label id.
*
* @return The label for the extension point ID. The default value is "id".
*/
public String getLabel_id() {
return this.label_id;
}
/**
* Sets the label id.
*
* @param label_id The new label for the extension point ID. The default value is "id".
*/
public void setLabel_id(String label_id) {
this.label_id = label_id;
}
/**
* Gets the label implementation.
*
* @return The label for the extension point implementation. The default value is "implementation".
*/
public String getLabel_implementation() {
return this.label_implementation;
}
/**
* Sets the label implementation.
*
* @param label_implementation The new label for the extension point implementation. The default value is "implementation".
*/
public void setLabel_implementation(ExtensionEnum label_implementation) {
this.setLabel_implementation(label_implementation.toString());
}
/**
* Sets the label implementation.
*
* @param label_implementation The new label for the extension point implementation. The default value is "implementation".
*/
public void setLabel_implementation(String label_implementation) {
this.label_implementation = label_implementation;
}
/**
* The Class InvalidExtensionIdentifier.
*/
public class InvalidExtensionIdentifier extends RuntimeException {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = -517005676614953393L;
/**
* Instantiates a new invalid extension identifier.
*
* @param text the text
*/
private InvalidExtensionIdentifier(String text) {
super("Identificador de extensión no encontrado: " + text); //$NON-NLS-1$
}
}
/**
* The Class InvalidKeyIdentifier.
*/
private class InvalidKeyIdentifier extends RuntimeException {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = 924357389433409796L;
/**
* Instantiates a new invalid key identifier.
*
* @param text the text
*/
private InvalidKeyIdentifier(String text) {
super("Clave no encontrada en el punto de extensión: " + text); //$NON-NLS-1$
}
private InvalidKeyIdentifier(String text, String t2) {
super("Clave no encontrada en el punto de extensión: " + text + "// " + t2); //$NON-NLS-1$
}
}
}
@@ -0,0 +1,133 @@
package flintstones.helper.extensionpoint;
import java.text.MessageFormat;
import java.util.Arrays;
import org.eclipse.core.runtime.IConfigurationElement;
import flintstones.entity.extensionenum.ExtensionEnum;
import flintstones.helper.locale.LocaleHelper;
/**
* The Class ExtensionRegistry.
*
* @author Sinbad2
* Generic IConfigurationElement Wrapper
*/
public class ExtensionRegistry {
/** The configuration. */
private final IConfigurationElement configuration;
/**
* Builder.
*
* @param element Domain configuration element
*/
public ExtensionRegistry(IConfigurationElement element) {
this.configuration = element;
}
/**
* Gets the attribute.
*
* @param element the element
* @return the attribute
*/
public String getAttribute(ExtensionEnum element) {
return this.getAttribute(element.toString());
}
/**
* Return Element attribute value.
*
* @param element ENUM, element key
* @return element value
*/
public String getAttribute(String element) {
String result = null;
String locale = LocaleHelper.getLocale();
if (this.configuration != null) {
try {
result = this.configuration.getAttribute(element, locale);
} catch(java.lang.IllegalArgumentException ex) {
result = configuration.getAttribute(element);
}
}
return result;
}
/**
* Return Element value as boolean.
*
* @param element ENUM, element key
* @return element value
*/
public boolean getAttributeBoolean(ExtensionEnum element) {
return this.getAttributeBoolean(element.toString());
}
/**
* Return Element value as Boolean.
*
* @param element ENUM, element key
* @return element value
*/
public boolean getAttributeBoolean(String element) {
return this.getAttribute(element)
.equals("true"); //$NON-NLS-1$
}
/**
* Gets the attribute references.
*
* @param element the element
* @return the attribute references
*/
public ExtensionRegistry[] getAttributeReferences(ExtensionEnum element) {
return this.getAttributeReferences(element.toString());
}
/**
* Gets the attribute referenced ExtensionRegistry for the given field.
*
* @param element the element
* @return the attribute references
*/
public ExtensionRegistry[] getAttributeReferences(String element) {
IConfigurationElement[] config = this.configuration.getChildren(element);
return Arrays.stream(config)
.map(ExtensionRegistry::new)
.toArray(ExtensionRegistry[]::new);
}
/* (non-Javadoc)
*
* @see java.lang.Object#toString() */
@Override
public String toString() {
String template = "ExtensionRegistry: {0}"; //$NON-NLS-1$
String arg = ""; //$NON-NLS-1$
if (this.getAttribute("id") != null) //$NON-NLS-1$
arg = arg + this.configuration.getAttribute("id"); //$NON-NLS-1$
if (this.getAttribute("uid") != null) //$NON-NLS-1$
arg = arg + this.configuration.getAttribute("uid"); //$NON-NLS-1$
if (this.getAttribute("name") != null) //$NON-NLS-1$
arg = arg + ", " + this.configuration.getAttribute("name"); //$NON-NLS-1$ //$NON-NLS-2$
return MessageFormat.format(template, arg);
}
/**
* Gets the configuration.
*
* @return the IConfigurationElement
*/
public IConfigurationElement getConfiguration() {
return this.configuration;
}
}