Skip to content
Snippets Groups Projects
Commit 1b47683a authored by Nils Christian Ehmke's avatar Nils Christian Ehmke
Browse files

Refactoring

parent 7811c56b
No related branches found
No related tags found
No related merge requests found
Showing
with 285 additions and 411 deletions
...@@ -45,6 +45,9 @@ import org.eclipse.emf.ecore.resource.Resource; ...@@ -45,6 +45,9 @@ import org.eclipse.emf.ecore.resource.Resource;
*/ */
public abstract class AbstractAnalysisComponentDecorator<T extends MIAnalysisComponent> implements MIAnalysisComponent { public abstract class AbstractAnalysisComponentDecorator<T extends MIAnalysisComponent> implements MIAnalysisComponent {
/** The singleton factory to create components. */
protected static final MIAnalysisMetaModelFactory FACTORY = MIAnalysisMetaModelFactory.eINSTANCE;
/** The component wrapped by this decorator. */ /** The component wrapped by this decorator. */
protected final T analysisComponent; protected final T analysisComponent;
...@@ -103,15 +106,12 @@ public abstract class AbstractAnalysisComponentDecorator<T extends MIAnalysisCom ...@@ -103,15 +106,12 @@ public abstract class AbstractAnalysisComponentDecorator<T extends MIAnalysisCom
/** /**
* Delivers a new copy of the wrapped component. * Delivers a new copy of the wrapped component.
* *
* @param factory
* The factory which is used to create the component.
*
* @return A (deep) copy of the wrapped component. * @return A (deep) copy of the wrapped component.
*/ */
public final T newCopy(final MIAnalysisMetaModelFactory factory) { public final T newCopy() {
final T componentCopy = this.createComponent(factory); final T componentCopy = this.createComponent();
this.refineComponentCopy(factory, componentCopy); this.refineComponentCopy(componentCopy);
return componentCopy; return componentCopy;
} }
...@@ -119,26 +119,21 @@ public abstract class AbstractAnalysisComponentDecorator<T extends MIAnalysisCom ...@@ -119,26 +119,21 @@ public abstract class AbstractAnalysisComponentDecorator<T extends MIAnalysisCom
/** /**
* Inheriting classes should implement this method to deliver the actual copy (without further properties) of the wrapped component. * Inheriting classes should implement this method to deliver the actual copy (without further properties) of the wrapped component.
* *
* @param factory
* The factory which should be used to create the component.
*
* @return A (non-deep) copy of the wrapped component. * @return A (non-deep) copy of the wrapped component.
*/ */
protected abstract T createComponent(final MIAnalysisMetaModelFactory factory); protected abstract T createComponent();
/** /**
* Inheriting classes should overwrite this method in order to refine the copy of the wrapped component. The new method should call * Inheriting classes should overwrite this method in order to refine the copy of the wrapped component. The new method should call
* {@code super.refineComponentCopy(factory, componentCopy)} though, in order to make sure that the other properties will be copied as well. * {@code super.refineComponentCopy(factory, componentCopy)} though, in order to make sure that the other properties will be copied as well.
* *
* @param factory
* The factory which should be used to create the new sub components.
* @param componentCopy * @param componentCopy
* The copy of the wrapped component, which can be refined by inheriting classes. * The copy of the wrapped component, which can be refined by inheriting classes.
*/ */
protected void refineComponentCopy(final MIAnalysisMetaModelFactory factory, final T componentCopy) { protected void refineComponentCopy(final T componentCopy) {
// Copy the properties // Copy the properties
for (final MIProperty property : this.analysisComponent.getProperties()) { for (final MIProperty property : this.analysisComponent.getProperties()) {
final MIProperty propertyCopy = factory.createProperty(); final MIProperty propertyCopy = FACTORY.createProperty();
propertyCopy.setName(property.getName()); propertyCopy.setName(property.getName());
propertyCopy.setValue(property.getValue()); propertyCopy.setValue(property.getValue());
componentCopy.getProperties().add(propertyCopy); componentCopy.getProperties().add(propertyCopy);
......
...@@ -18,7 +18,6 @@ package kieker.webgui.domain.pluginDecorators; ...@@ -18,7 +18,6 @@ package kieker.webgui.domain.pluginDecorators;
import java.util.Map; import java.util.Map;
import kieker.analysis.model.analysisMetaModel.MIAnalysisMetaModelFactory;
import kieker.analysis.model.analysisMetaModel.MIDisplay; import kieker.analysis.model.analysisMetaModel.MIDisplay;
import kieker.analysis.model.analysisMetaModel.MIOutputPort; import kieker.analysis.model.analysisMetaModel.MIOutputPort;
import kieker.analysis.model.analysisMetaModel.MIPlugin; import kieker.analysis.model.analysisMetaModel.MIPlugin;
...@@ -75,12 +74,12 @@ public abstract class AbstractPluginDecorator<T extends MIPlugin> extends Abstra ...@@ -75,12 +74,12 @@ public abstract class AbstractPluginDecorator<T extends MIPlugin> extends Abstra
} }
@Override @Override
protected void refineComponentCopy(final MIAnalysisMetaModelFactory factory, final T componentCopy) { protected void refineComponentCopy(final T componentCopy) {
super.refineComponentCopy(factory, componentCopy); super.refineComponentCopy(componentCopy);
// Copy the output ports of the plugin instance // Copy the output ports of the plugin instance
for (final MIOutputPort outputPort : super.analysisComponent.getOutputPorts()) { for (final MIOutputPort outputPort : super.analysisComponent.getOutputPorts()) {
final MIOutputPort outputPortCopy = factory.createOutputPort(); final MIOutputPort outputPortCopy = FACTORY.createOutputPort();
outputPortCopy.setName(outputPort.getName()); outputPortCopy.setName(outputPort.getName());
outputPortCopy.setParent(componentCopy); outputPortCopy.setParent(componentCopy);
componentCopy.getOutputPorts().add(outputPortCopy); componentCopy.getOutputPorts().add(outputPortCopy);
...@@ -88,14 +87,14 @@ public abstract class AbstractPluginDecorator<T extends MIPlugin> extends Abstra ...@@ -88,14 +87,14 @@ public abstract class AbstractPluginDecorator<T extends MIPlugin> extends Abstra
// Copy the repository "ports" // Copy the repository "ports"
for (final MIRepositoryConnector repositoryConnector : super.analysisComponent.getRepositories()) { for (final MIRepositoryConnector repositoryConnector : super.analysisComponent.getRepositories()) {
final MIRepositoryConnector repositoryConnectorCopy = factory.createRepositoryConnector(); final MIRepositoryConnector repositoryConnectorCopy = FACTORY.createRepositoryConnector();
repositoryConnectorCopy.setName(repositoryConnector.getName()); repositoryConnectorCopy.setName(repositoryConnector.getName());
componentCopy.getRepositories().add(repositoryConnectorCopy); componentCopy.getRepositories().add(repositoryConnectorCopy);
} }
// Copy the displays // Copy the displays
for (final MIDisplay display : super.analysisComponent.getDisplays()) { for (final MIDisplay display : super.analysisComponent.getDisplays()) {
final MIDisplay displayCopy = factory.createDisplay(); final MIDisplay displayCopy = FACTORY.createDisplay();
displayCopy.setName(display.getName()); displayCopy.setName(display.getName());
displayCopy.setParent(componentCopy); displayCopy.setParent(componentCopy);
componentCopy.getDisplays().add(displayCopy); componentCopy.getDisplays().add(displayCopy);
......
...@@ -18,7 +18,6 @@ package kieker.webgui.domain.pluginDecorators; ...@@ -18,7 +18,6 @@ package kieker.webgui.domain.pluginDecorators;
import java.util.Map; import java.util.Map;
import kieker.analysis.model.analysisMetaModel.MIAnalysisMetaModelFactory;
import kieker.analysis.model.analysisMetaModel.MIFilter; import kieker.analysis.model.analysisMetaModel.MIFilter;
import kieker.analysis.model.analysisMetaModel.MIInputPort; import kieker.analysis.model.analysisMetaModel.MIInputPort;
...@@ -54,17 +53,17 @@ public class FilterDecorator extends AbstractPluginDecorator<MIFilter> implement ...@@ -54,17 +53,17 @@ public class FilterDecorator extends AbstractPluginDecorator<MIFilter> implement
} }
@Override @Override
protected final MIFilter createComponent(final MIAnalysisMetaModelFactory factory) { protected final MIFilter createComponent() {
return factory.createFilter(); return FACTORY.createFilter();
} }
@Override @Override
protected final void refineComponentCopy(final MIAnalysisMetaModelFactory factory, final MIFilter componentCopy) { protected final void refineComponentCopy(final MIFilter componentCopy) {
super.refineComponentCopy(factory, componentCopy); super.refineComponentCopy(componentCopy);
// Copy the input ports of the plugin instance // Copy the input ports of the plugin instance
for (final MIInputPort inputPort : super.analysisComponent.getInputPorts()) { for (final MIInputPort inputPort : super.analysisComponent.getInputPorts()) {
final MIInputPort inputPortCopy = factory.createInputPort(); final MIInputPort inputPortCopy = FACTORY.createInputPort();
inputPortCopy.setName(inputPort.getName()); inputPortCopy.setName(inputPort.getName());
inputPortCopy.setParent(componentCopy); inputPortCopy.setParent(componentCopy);
componentCopy.getInputPorts().add(inputPortCopy); componentCopy.getInputPorts().add(inputPortCopy);
......
...@@ -18,7 +18,6 @@ package kieker.webgui.domain.pluginDecorators; ...@@ -18,7 +18,6 @@ package kieker.webgui.domain.pluginDecorators;
import java.util.Map; import java.util.Map;
import kieker.analysis.model.analysisMetaModel.MIAnalysisMetaModelFactory;
import kieker.analysis.model.analysisMetaModel.MIReader; import kieker.analysis.model.analysisMetaModel.MIReader;
/** /**
...@@ -51,8 +50,8 @@ public class ReaderDecorator extends AbstractPluginDecorator<MIReader> implement ...@@ -51,8 +50,8 @@ public class ReaderDecorator extends AbstractPluginDecorator<MIReader> implement
} }
@Override @Override
protected final MIReader createComponent(final MIAnalysisMetaModelFactory factory) { protected final MIReader createComponent() {
return factory.createReader(); return FACTORY.createReader();
} }
} }
...@@ -18,7 +18,6 @@ package kieker.webgui.domain.pluginDecorators; ...@@ -18,7 +18,6 @@ package kieker.webgui.domain.pluginDecorators;
import java.util.Map; import java.util.Map;
import kieker.analysis.model.analysisMetaModel.MIAnalysisMetaModelFactory;
import kieker.analysis.model.analysisMetaModel.MIRepository; import kieker.analysis.model.analysisMetaModel.MIRepository;
/** /**
...@@ -49,8 +48,8 @@ public class RepositoryDecorator extends AbstractAnalysisComponentDecorator<MIRe ...@@ -49,8 +48,8 @@ public class RepositoryDecorator extends AbstractAnalysisComponentDecorator<MIRe
} }
@Override @Override
protected final MIRepository createComponent(final MIAnalysisMetaModelFactory factory) { protected final MIRepository createComponent() {
return factory.createRepository(); return FACTORY.createRepository();
} }
} }
...@@ -23,7 +23,6 @@ import java.util.Collections; ...@@ -23,7 +23,6 @@ import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import kieker.analysis.analysisComponent.AbstractAnalysisComponent;
import kieker.analysis.model.analysisMetaModel.MIAnalysisComponent; import kieker.analysis.model.analysisMetaModel.MIAnalysisComponent;
import kieker.analysis.model.analysisMetaModel.MIAnalysisMetaModelFactory; import kieker.analysis.model.analysisMetaModel.MIAnalysisMetaModelFactory;
import kieker.analysis.model.analysisMetaModel.MIDisplay; import kieker.analysis.model.analysisMetaModel.MIDisplay;
...@@ -35,10 +34,6 @@ import kieker.analysis.model.analysisMetaModel.MIProperty; ...@@ -35,10 +34,6 @@ import kieker.analysis.model.analysisMetaModel.MIProperty;
import kieker.analysis.model.analysisMetaModel.MIReader; import kieker.analysis.model.analysisMetaModel.MIReader;
import kieker.analysis.model.analysisMetaModel.MIRepository; import kieker.analysis.model.analysisMetaModel.MIRepository;
import kieker.analysis.model.analysisMetaModel.MIRepositoryConnector; import kieker.analysis.model.analysisMetaModel.MIRepositoryConnector;
import kieker.analysis.plugin.AbstractPlugin;
import kieker.analysis.plugin.filter.AbstractFilterPlugin;
import kieker.analysis.plugin.reader.AbstractReaderPlugin;
import kieker.analysis.repository.AbstractRepository;
import kieker.common.logging.Log; import kieker.common.logging.Log;
import kieker.common.logging.LogFactory; import kieker.common.logging.LogFactory;
import kieker.webgui.common.ClassAndMethodContainer; import kieker.webgui.common.ClassAndMethodContainer;
...@@ -72,7 +67,7 @@ public class Class2ModelInstanceConverter { ...@@ -72,7 +67,7 @@ public class Class2ModelInstanceConverter {
} }
/** /**
* Converts the given {@link AbstractReaderPlugin} instance into a model instance using the given parameters. * Converts the given {@link kieker.analysis.plugin.reader.AbstractReaderPlugin} class instance into a model instance using the given parameters.
* *
* @param clazz * @param clazz
* The class to convert. * The class to convert.
...@@ -81,12 +76,12 @@ public class Class2ModelInstanceConverter { ...@@ -81,12 +76,12 @@ public class Class2ModelInstanceConverter {
* *
* @return A model instance representing the given class as a meta model component. * @return A model instance representing the given class as a meta model component.
*/ */
public ReaderDecorator convertReaderClass2ModelInstance(final Class<AbstractReaderPlugin> clazz, final ClassAndMethodContainer classAndMethodContainer) { public ReaderDecorator convertReaderClass2ModelInstance(final Class<?> clazz, final ClassAndMethodContainer classAndMethodContainer) {
return (ReaderDecorator) this.convertComponentClass2ModelInstance(clazz, classAndMethodContainer, Type.Reader); return (ReaderDecorator) this.convertComponentClass2ModelInstance(clazz, classAndMethodContainer, Type.Reader);
} }
/** /**
* Converts the given {@link AbstractFilterPlugin} instance into a model instance using the given parameters. * Converts the given {@link kieker.analysis.plugin.filter.AbstractFilterPlugin} instance into a model instance using the given parameters.
* *
* @param clazz * @param clazz
* The class to convert. * The class to convert.
...@@ -95,12 +90,12 @@ public class Class2ModelInstanceConverter { ...@@ -95,12 +90,12 @@ public class Class2ModelInstanceConverter {
* *
* @return A model instance representing the given class as a meta model component. * @return A model instance representing the given class as a meta model component.
*/ */
public FilterDecorator convertFilterClass2ModelInstance(final Class<AbstractFilterPlugin> clazz, final ClassAndMethodContainer classAndMethodContainer) { public FilterDecorator convertFilterClass2ModelInstance(final Class<?> clazz, final ClassAndMethodContainer classAndMethodContainer) {
return (FilterDecorator) this.convertComponentClass2ModelInstance(clazz, classAndMethodContainer, Type.Filter); return (FilterDecorator) this.convertComponentClass2ModelInstance(clazz, classAndMethodContainer, Type.Filter);
} }
/** /**
* Converts the given {@link AbstractRepository} instance into a model instance using the given parameters. * Converts the given {@link kieker.analysis.repository.AbstractRepository} instance into a model instance using the given parameters.
* *
* @param clazz * @param clazz
* The class to convert. * The class to convert.
...@@ -109,14 +104,12 @@ public class Class2ModelInstanceConverter { ...@@ -109,14 +104,12 @@ public class Class2ModelInstanceConverter {
* *
* @return A model instance representing the given class as a meta model component. * @return A model instance representing the given class as a meta model component.
*/ */
public RepositoryDecorator convertRepositoryClass2ModelInstance(final Class<AbstractRepository> clazz, final ClassAndMethodContainer classAndMethodContainer) { public RepositoryDecorator convertRepositoryClass2ModelInstance(final Class<?> clazz, final ClassAndMethodContainer classAndMethodContainer) {
return (RepositoryDecorator) this.convertComponentClass2ModelInstance(clazz, classAndMethodContainer, Type.Repository); return (RepositoryDecorator) this.convertComponentClass2ModelInstance(clazz, classAndMethodContainer, Type.Repository);
} }
@SuppressWarnings("unchecked") private AbstractAnalysisComponentDecorator<?> convertComponentClass2ModelInstance(final Class<?> clazz, final ClassAndMethodContainer classAndMethodContainer,
private AbstractAnalysisComponentDecorator<? extends MIAnalysisComponent> convertComponentClass2ModelInstance( final Type type) {
final Class<? extends AbstractAnalysisComponent> clazz,
final ClassAndMethodContainer classAndMethodContainer, final Type type) {
final MIAnalysisComponent plugin = this.createSuitableModelInstance(clazz, classAndMethodContainer); final MIAnalysisComponent plugin = this.createSuitableModelInstance(clazz, classAndMethodContainer);
final Collection<MIProperty> properties = new ArrayList<MIProperty>(); final Collection<MIProperty> properties = new ArrayList<MIProperty>();
...@@ -126,6 +119,7 @@ public class Class2ModelInstanceConverter { ...@@ -126,6 +119,7 @@ public class Class2ModelInstanceConverter {
final Collection<MIRepositoryConnector> repositories = new ArrayList<MIRepositoryConnector>(); final Collection<MIRepositoryConnector> repositories = new ArrayList<MIRepositoryConnector>();
final Map<String, String> propertyDescriptions = new HashMap<String, String>(); final Map<String, String> propertyDescriptions = new HashMap<String, String>();
final Map<String, String> displayDescriptions = new HashMap<String, String>(); final Map<String, String> displayDescriptions = new HashMap<String, String>();
String description = ""; String description = "";
String dependency = ""; String dependency = "";
boolean fullyInitialized = true; boolean fullyInitialized = true;
...@@ -136,19 +130,19 @@ public class Class2ModelInstanceConverter { ...@@ -136,19 +130,19 @@ public class Class2ModelInstanceConverter {
this.fillProperties(clazz, classAndMethodContainer, properties, propertyDescriptions); this.fillProperties(clazz, classAndMethodContainer, properties, propertyDescriptions);
plugin.getProperties().addAll(properties); plugin.getProperties().addAll(properties);
if ((type == Type.Filter) || (type == Type.Reader)) { if ((type == Type.Filter) || (type == Type.Reader)) {
this.fillOutputPorts((Class<AbstractPlugin>) clazz, classAndMethodContainer, outputPorts, (MIPlugin) plugin); this.fillOutputPorts(clazz, classAndMethodContainer, outputPorts, (MIPlugin) plugin);
this.fillDisplays((Class<AbstractPlugin>) clazz, classAndMethodContainer, displays, displayDescriptions); this.fillDisplays(clazz, classAndMethodContainer, displays, displayDescriptions);
this.fillRepositories((Class<AbstractPlugin>) clazz, classAndMethodContainer, repositories); this.fillRepositories(clazz, classAndMethodContainer, repositories);
((MIPlugin) plugin).getOutputPorts().addAll(outputPorts); ((MIPlugin) plugin).getOutputPorts().addAll(outputPorts);
((MIPlugin) plugin).getDisplays().addAll(displays); ((MIPlugin) plugin).getDisplays().addAll(displays);
((MIPlugin) plugin).getRepositories().addAll(repositories); ((MIPlugin) plugin).getRepositories().addAll(repositories);
if (type == Type.Filter) { if (type == Type.Filter) {
this.fillInputPorts((Class<AbstractFilterPlugin>) clazz, classAndMethodContainer, inputPorts, (MIFilter) plugin); this.fillInputPorts(clazz, classAndMethodContainer, inputPorts, (MIFilter) plugin);
((MIFilter) plugin).getInputPorts().addAll(inputPorts); ((MIFilter) plugin).getInputPorts().addAll(inputPorts);
} }
} }
} catch (final Throwable ex) { // NOCS NOPMD (Throwable) } catch (final Throwable ex) { // NOCS NOPMD (Throwable)
Class2ModelInstanceConverter.LOG.info("A component with the classname '" + clazz.getCanonicalName() + "' could not be initialized.", ex); Class2ModelInstanceConverter.LOG.warn("A component with the classname '" + clazz.getCanonicalName() + "' could not be initialized.", ex);
plugin.getProperties().clear(); plugin.getProperties().clear();
if ((type == Type.Filter) || (type == Type.Reader)) { if ((type == Type.Filter) || (type == Type.Reader)) {
...@@ -186,8 +180,7 @@ public class Class2ModelInstanceConverter { ...@@ -186,8 +180,7 @@ public class Class2ModelInstanceConverter {
return result; return result;
} }
private void fillInputPorts(final Class<AbstractFilterPlugin> clazz, final ClassAndMethodContainer classAndMethodContainer, private void fillInputPorts(final Class<?> clazz, final ClassAndMethodContainer classAndMethodContainer, final Collection<MIInputPort> inputPorts,
final Collection<MIInputPort> inputPorts,
final MIFilter parent) { final MIFilter parent) {
final Collection<Method> methods = this.getInputPortMethods(clazz, classAndMethodContainer); final Collection<Method> methods = this.getInputPortMethods(clazz, classAndMethodContainer);
for (final Method method : methods) { for (final Method method : methods) {
...@@ -199,8 +192,7 @@ public class Class2ModelInstanceConverter { ...@@ -199,8 +192,7 @@ public class Class2ModelInstanceConverter {
} }
} }
private void fillDisplays(final Class<? extends AbstractPlugin> clazz, final ClassAndMethodContainer classAndMethodContainer, private void fillDisplays(final Class<?> clazz, final ClassAndMethodContainer classAndMethodContainer, final Collection<MIDisplay> displays,
final Collection<MIDisplay> displays,
final Map<String, String> displayDescriptions) { final Map<String, String> displayDescriptions) {
final Collection<Method> methods = this.getDisplayMethods(clazz, classAndMethodContainer); final Collection<Method> methods = this.getDisplayMethods(clazz, classAndMethodContainer);
for (final Method method : methods) { for (final Method method : methods) {
...@@ -212,7 +204,7 @@ public class Class2ModelInstanceConverter { ...@@ -212,7 +204,7 @@ public class Class2ModelInstanceConverter {
} }
} }
private Collection<Method> getAnnotatedMethods(final Class<? extends AbstractPlugin> clazz, final Class<? extends Annotation> annotation) { private Collection<Method> getAnnotatedMethods(final Class<?> clazz, final Class<? extends Annotation> annotation) {
final Collection<Method> result = new ArrayList<Method>(); final Collection<Method> result = new ArrayList<Method>();
final Method[] methods = clazz.getMethods(); final Method[] methods = clazz.getMethods();
...@@ -225,18 +217,19 @@ public class Class2ModelInstanceConverter { ...@@ -225,18 +217,19 @@ public class Class2ModelInstanceConverter {
return result; return result;
} }
private Collection<Method> getInputPortMethods(final Class<AbstractFilterPlugin> clazz, final ClassAndMethodContainer classAndMethodContainer) { private Collection<Method> getInputPortMethods(final Class<?> clazz, final ClassAndMethodContainer classAndMethodContainer) {
return this.getAnnotatedMethods(clazz, classAndMethodContainer.getInputPortAnnotationClass()); return this.getAnnotatedMethods(clazz, classAndMethodContainer.getInputPortAnnotationClass());
} }
private Collection<Method> getDisplayMethods(final Class<? extends AbstractPlugin> clazz, final ClassAndMethodContainer classAndMethodContainer) { private Collection<Method> getDisplayMethods(final Class<?> clazz, final ClassAndMethodContainer classAndMethodContainer) {
return this.getAnnotatedMethods(clazz, classAndMethodContainer.getDisplayAnnotationClass()); return this.getAnnotatedMethods(clazz, classAndMethodContainer.getDisplayAnnotationClass());
} }
private void fillOutputPorts(final Class<? extends AbstractPlugin> clazz, final ClassAndMethodContainer classAndMethodContainer, private void fillOutputPorts(final Class<?> clazz, final ClassAndMethodContainer classAndMethodContainer, final Collection<MIOutputPort> outputPorts,
final Collection<MIOutputPort> outputPorts, final MIPlugin parent) { final MIPlugin parent) {
final Annotation annotation = this.getSuitableAnnotation(clazz, classAndMethodContainer); final Annotation annotation = this.getSuitableAnnotation(clazz, classAndMethodContainer);
final Annotation[] outputPortAnnotations = (Annotation[]) new Mirror().on(annotation).invoke().method("outputPorts").withoutArgs(); final Annotation[] outputPortAnnotations = (Annotation[]) new Mirror().on(annotation).invoke().method("outputPorts").withoutArgs();
for (final Annotation outputPortAnnotation : outputPortAnnotations) { for (final Annotation outputPortAnnotation : outputPortAnnotations) {
final MIOutputPort newPort = Class2ModelInstanceConverter.FACTORY.createOutputPort(); final MIOutputPort newPort = Class2ModelInstanceConverter.FACTORY.createOutputPort();
newPort.setName((String) new Mirror().on(outputPortAnnotation).invoke().method("name").withoutArgs()); newPort.setName((String) new Mirror().on(outputPortAnnotation).invoke().method("name").withoutArgs());
...@@ -245,10 +238,11 @@ public class Class2ModelInstanceConverter { ...@@ -245,10 +238,11 @@ public class Class2ModelInstanceConverter {
} }
} }
private void fillProperties(final Class<? extends AbstractAnalysisComponent> clazz, final ClassAndMethodContainer classAndMethodContainer, private void fillProperties(final Class<?> clazz, final ClassAndMethodContainer classAndMethodContainer, final Collection<MIProperty> properties,
final Collection<MIProperty> properties, final Map<String, String> propertyDescriptions) { final Map<String, String> propertyDescriptions) {
final Annotation annotation = this.getSuitableAnnotation(clazz, classAndMethodContainer); final Annotation annotation = this.getSuitableAnnotation(clazz, classAndMethodContainer);
final Annotation[] propertyAnnotations = (Annotation[]) new Mirror().on(annotation).invoke().method("configuration").withoutArgs(); final Annotation[] propertyAnnotations = (Annotation[]) new Mirror().on(annotation).invoke().method("configuration").withoutArgs();
for (final Annotation propertyAnnotation : propertyAnnotations) { for (final Annotation propertyAnnotation : propertyAnnotations) {
final MIProperty newProperty = Class2ModelInstanceConverter.FACTORY.createProperty(); final MIProperty newProperty = Class2ModelInstanceConverter.FACTORY.createProperty();
newProperty.setName((String) new Mirror().on(propertyAnnotation).invoke().method("name").withoutArgs()); newProperty.setName((String) new Mirror().on(propertyAnnotation).invoke().method("name").withoutArgs());
...@@ -258,7 +252,7 @@ public class Class2ModelInstanceConverter { ...@@ -258,7 +252,7 @@ public class Class2ModelInstanceConverter {
} }
} }
private void fillRepositories(final Class<? extends AbstractPlugin> clazz, final ClassAndMethodContainer classAndMethodContainer, private void fillRepositories(final Class<?> clazz, final ClassAndMethodContainer classAndMethodContainer,
final Collection<MIRepositoryConnector> repositories) { final Collection<MIRepositoryConnector> repositories) {
final Annotation annotation = this.getSuitableAnnotation(clazz, classAndMethodContainer); final Annotation annotation = this.getSuitableAnnotation(clazz, classAndMethodContainer);
final Annotation[] repositoryPortAnnotations = (Annotation[]) new Mirror().on(annotation).invoke().method("repositoryPorts").withoutArgs(); final Annotation[] repositoryPortAnnotations = (Annotation[]) new Mirror().on(annotation).invoke().method("repositoryPorts").withoutArgs();
...@@ -271,17 +265,17 @@ public class Class2ModelInstanceConverter { ...@@ -271,17 +265,17 @@ public class Class2ModelInstanceConverter {
} }
} }
private String fillDependency(final Class<? extends AbstractAnalysisComponent> clazz, final ClassAndMethodContainer classAndMethodContainer) { private String fillDependency(final Class<?> clazz, final ClassAndMethodContainer classAndMethodContainer) {
final Annotation annotation = this.getSuitableAnnotation(clazz, classAndMethodContainer); final Annotation annotation = this.getSuitableAnnotation(clazz, classAndMethodContainer);
return (String) new Mirror().on(annotation).invoke().method("dependencies").withoutArgs(); return (String) new Mirror().on(annotation).invoke().method("dependencies").withoutArgs();
} }
private String fillDescription(final Class<? extends AbstractAnalysisComponent> clazz, final ClassAndMethodContainer classAndMethodContainer) { private String fillDescription(final Class<?> clazz, final ClassAndMethodContainer classAndMethodContainer) {
final Annotation annotation = this.getSuitableAnnotation(clazz, classAndMethodContainer); final Annotation annotation = this.getSuitableAnnotation(clazz, classAndMethodContainer);
return (String) new Mirror().on(annotation).invoke().method("description").withoutArgs(); return (String) new Mirror().on(annotation).invoke().method("description").withoutArgs();
} }
private Annotation getSuitableAnnotation(final Class<? extends AbstractAnalysisComponent> clazz, final ClassAndMethodContainer classAndMethodContainer) { private Annotation getSuitableAnnotation(final Class<?> clazz, final ClassAndMethodContainer classAndMethodContainer) {
// Get the two potential annotations // Get the two potential annotations
final Annotation annotationPlugin = clazz.getAnnotation(classAndMethodContainer.getPluginAnnotationClass()); final Annotation annotationPlugin = clazz.getAnnotation(classAndMethodContainer.getPluginAnnotationClass());
final Annotation annotationRepository = clazz.getAnnotation(classAndMethodContainer.getRepositoryAnnotationClass()); final Annotation annotationRepository = clazz.getAnnotation(classAndMethodContainer.getRepositoryAnnotationClass());
...@@ -294,8 +288,7 @@ public class Class2ModelInstanceConverter { ...@@ -294,8 +288,7 @@ public class Class2ModelInstanceConverter {
} }
} }
private MIAnalysisComponent createSuitableModelInstance(final Class<? extends AbstractAnalysisComponent> clazz, private MIAnalysisComponent createSuitableModelInstance(final Class<?> clazz, final ClassAndMethodContainer classAndMethodContainer) {
final ClassAndMethodContainer classAndMethodContainer) {
if (classAndMethodContainer.getAbstractReaderPluginClass().isAssignableFrom(clazz)) { if (classAndMethodContainer.getAbstractReaderPluginClass().isAssignableFrom(clazz)) {
return Class2ModelInstanceConverter.FACTORY.createReader(); return Class2ModelInstanceConverter.FACTORY.createReader();
} else if (classAndMethodContainer.getAbstractFilterPluginClass().isAssignableFrom(clazz)) { } else if (classAndMethodContainer.getAbstractFilterPluginClass().isAssignableFrom(clazz)) {
...@@ -315,7 +308,7 @@ public class Class2ModelInstanceConverter { ...@@ -315,7 +308,7 @@ public class Class2ModelInstanceConverter {
* *
* @return The state of the programmaticOnly flag of the plugin or repository. * @return The state of the programmaticOnly flag of the plugin or repository.
*/ */
public boolean isProgrammaticOnly(final Class<? extends AbstractAnalysisComponent> clazz, final ClassAndMethodContainer classAndMethodContainer) { public boolean isProgrammaticOnly(final Class<?> clazz, final ClassAndMethodContainer classAndMethodContainer) {
final Annotation annotation = this.getSuitableAnnotation(clazz, classAndMethodContainer); final Annotation annotation = this.getSuitableAnnotation(clazz, classAndMethodContainer);
return (Boolean) new Mirror().on(annotation).invoke().method("programmaticOnly").withoutArgs(); return (Boolean) new Mirror().on(annotation).invoke().method("programmaticOnly").withoutArgs();
} }
......
...@@ -17,9 +17,11 @@ package kieker.webgui.persistence.impl.util; ...@@ -17,9 +17,11 @@ package kieker.webgui.persistence.impl.util;
import java.io.Closeable; import java.io.Closeable;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Field;
import java.net.URL; import java.net.URL;
import java.net.URLClassLoader; import java.net.URLClassLoader;
import java.util.Collection; import java.util.Collection;
import java.util.jar.JarFile;
/** /**
* A class loader which extends the {@link URLClassLoader} with a close-method using a hack. This will probably only work for a Sun VM. The class itself will * A class loader which extends the {@link URLClassLoader} with a close-method using a hack. This will probably only work for a Sun VM. The class itself will
...@@ -52,21 +54,22 @@ public class CloseableURLClassLoader extends URLClassLoader implements Closeable ...@@ -52,21 +54,22 @@ public class CloseableURLClassLoader extends URLClassLoader implements Closeable
try { try {
final Class<URLClassLoader> clazz = URLClassLoader.class; final Class<URLClassLoader> clazz = URLClassLoader.class;
final java.lang.reflect.Field ucp = clazz.getDeclaredField("ucp"); final Field ucp = clazz.getDeclaredField("ucp");
ucp.setAccessible(true); ucp.setAccessible(true);
final Object sunMiscURLClassPath = ucp.get(this); final Object sunMiscURLClassPath = ucp.get(this);
final java.lang.reflect.Field loaders = sunMiscURLClassPath.getClass().getDeclaredField("loaders"); final Field loaders = sunMiscURLClassPath.getClass().getDeclaredField("loaders");
loaders.setAccessible(true); loaders.setAccessible(true);
// Run through all available loaders and try to close them // Run through all available loaders and try to close them
final Object javaUtilCollection = loaders.get(sunMiscURLClassPath); final Object javaUtilCollection = loaders.get(sunMiscURLClassPath);
for (final Object sunMiscURLClassPathJarLoader : ((Collection<?>) javaUtilCollection).toArray()) { for (final Object sunMiscURLClassPathJarLoader : ((Collection<?>) javaUtilCollection).toArray()) {
try { try {
final java.lang.reflect.Field loader = sunMiscURLClassPathJarLoader.getClass().getDeclaredField("jar"); final Field loader = sunMiscURLClassPathJarLoader.getClass().getDeclaredField("jar");
loader.setAccessible(true); loader.setAccessible(true);
final Object javaUtilIarJarFile = loader.get(sunMiscURLClassPathJarLoader); final Object javaUtilIarJarFile = loader.get(sunMiscURLClassPathJarLoader);
((java.util.jar.JarFile) javaUtilIarJarFile).close(); ((JarFile) javaUtilIarJarFile).close();
} catch (final Throwable t) { // NOCS, NOPMD (Catch of Throwable) } catch (final Throwable t) { // NOCS, NOPMD (Catch of Throwable)
// if we got this far, this is probably not a JAR loader so skip it // if we got this far, this is probably not a JAR loader so skip it
} }
......
...@@ -29,21 +29,22 @@ import javax.annotation.Nullable; ...@@ -29,21 +29,22 @@ import javax.annotation.Nullable;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.Collections2; import com.google.common.collect.Collections2;
import kieker.analysis.plugin.filter.AbstractFilterPlugin; import kieker.common.logging.Log;
import kieker.analysis.plugin.reader.AbstractReaderPlugin; import kieker.common.logging.LogFactory;
import kieker.analysis.repository.AbstractRepository;
import kieker.webgui.common.ClassAndMethodContainer; import kieker.webgui.common.ClassAndMethodContainer;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
/** /**
* This tool class can be used to find all plugins and repositories within a given jar file - assuming that the given class loader knows these jars. * This tool class can be used to find all plugins and repositories within a given jar file - assume that the given class loader knows these jars.
* *
* @author Nils Christian Ehmke * @author Nils Christian Ehmke
*/ */
@Service @Service
public class PluginFinder { public class PluginFinder {
private static final Log LOG = LogFactory.getLog(PluginFinder.class);
/** /**
* Default constructor. <b>Do not use this constructor. This bean is Spring managed.</b> * Default constructor. <b>Do not use this constructor. This bean is Spring managed.</b>
*/ */
...@@ -52,7 +53,8 @@ public class PluginFinder { ...@@ -52,7 +53,8 @@ public class PluginFinder {
} }
/** /**
* This method delivers all classes which are available in the given jar and are compatible with <code>AbstractRepository</code>. None of them is abstract. * This method delivers all classes which are available in the given jar and are compatible with {@link kieker.analysis.repository.AbstractRepository}. None of
* them is abstract.
* *
* @param url * @param url
* The URL for the jar. * The URL for the jar.
...@@ -66,15 +68,16 @@ public class PluginFinder { ...@@ -66,15 +68,16 @@ public class PluginFinder {
* @throws IOException * @throws IOException
* If something went wrong during the opening of the jar file. * If something went wrong during the opening of the jar file.
*/ */
public Collection<Class<AbstractRepository>> getAllRepositoriesWithinJar(final URL url, final ClassLoader classLoader, public Collection<Class<?>> getAllRepositoriesWithinJar(final URL url, final ClassLoader classLoader, final ClassAndMethodContainer classAndMethodContainer)
final ClassAndMethodContainer classAndMethodContainer) throws IOException { throws IOException {
return Collections2.transform(Collections2.filter(Collections2.filter(this.getAllClassesWithinJar(url, classLoader), // Get all classes within the Jar. Filter the classes which are not repositories. Filter the abstract classes.
new IsRepositoryPredicate(classAndMethodContainer)), new IsNotAbstractPredicate()), new SimpleCastFunction<Class<?>, Class<AbstractRepository>>()); return Collections2.filter(Collections2.filter(this.getAllClassesWithinJar(url, classLoader), new IsRepositoryPredicate(classAndMethodContainer)),
new IsNotAbstractPredicate());
} }
/** /**
* This method delivers all classes which are available in the given jar and have the Plugin-Annotation from the Kieker framework (And are correctly compatible * This method delivers all classes which are available in the given jar and have the Plugin-Annotation from the Kieker framework (And are correctly compatible
* with <code>AbstractReaderPlugin</code>). None of them is abstract. * with {@link kieker.analysis.plugin.reader.AbstractReaderPlugin}). None of them is abstract.
* *
* @param url * @param url
* The URL for the jar. * The URL for the jar.
...@@ -88,15 +91,16 @@ public class PluginFinder { ...@@ -88,15 +91,16 @@ public class PluginFinder {
* @throws IOException * @throws IOException
* If something went wrong during the opening of the jar file. * If something went wrong during the opening of the jar file.
*/ */
public Collection<Class<AbstractReaderPlugin>> getAllReadersWithinJar(final URL url, final ClassLoader classLoader, public Collection<Class<?>> getAllReadersWithinJar(final URL url, final ClassLoader classLoader, final ClassAndMethodContainer classAndMethodContainer)
final ClassAndMethodContainer classAndMethodContainer) throws IOException { throws IOException {
return Collections2.transform(Collections2.filter(Collections2.filter(this.getAllClassesWithinJar(url, classLoader), // Get all classes within the Jar. Filter the classes which are not readers. Filter the abstract classes.
new IsReaderPredicate(classAndMethodContainer)), new IsNotAbstractPredicate()), new SimpleCastFunction<Class<?>, Class<AbstractReaderPlugin>>()); return Collections2.filter(Collections2.filter(this.getAllClassesWithinJar(url, classLoader), new IsReaderPredicate(classAndMethodContainer)),
new IsNotAbstractPredicate());
} }
/** /**
* This method delivers all classes which are available in the given jar and have the Plugin-Annotation from the Kieker framework (And are correctly compatible * This method delivers all classes which are available in the given jar and have the Plugin-Annotation from the Kieker framework (And are correctly compatible
* with <code>AbstractFilterPlugin</code>). None of them is abstract. * with {@link kieker.analysis.plugin.filter.AbstractFilterPlugin}). None of them is abstract.
* *
* @param url * @param url
* The URL for the jar. * The URL for the jar.
...@@ -110,10 +114,11 @@ public class PluginFinder { ...@@ -110,10 +114,11 @@ public class PluginFinder {
* @throws IOException * @throws IOException
* If something went wrong during the opening of the jar file. * If something went wrong during the opening of the jar file.
*/ */
public Collection<Class<AbstractFilterPlugin>> getAllFiltersWithinJar(final URL url, final ClassLoader classLoader, public Collection<Class<?>> getAllFiltersWithinJar(final URL url, final ClassLoader classLoader, final ClassAndMethodContainer classAndMethodContainer)
final ClassAndMethodContainer classAndMethodContainer) throws IOException { throws IOException {
return Collections2.transform(Collections2.filter(Collections2.filter(this.getAllClassesWithinJar(url, classLoader), // Get all classes within the Jar. Filter the classes which are not filters. Filter the abstract classes.
new IsFilterPredicate(classAndMethodContainer)), new IsNotAbstractPredicate()), new SimpleCastFunction<Class<?>, Class<AbstractFilterPlugin>>()); return Collections2.filter(Collections2.filter(this.getAllClassesWithinJar(url, classLoader), new IsFilterPredicate(classAndMethodContainer)),
new IsNotAbstractPredicate());
} }
/** /**
...@@ -140,11 +145,10 @@ public class PluginFinder { ...@@ -140,11 +145,10 @@ public class PluginFinder {
while ((jarEntry = stream.getNextJarEntry()) != null) { while ((jarEntry = stream.getNextJarEntry()) != null) {
try { try {
// Assemble the correct name // Assemble the correct name
String name = jarEntry.toString(); final String className = jarEntry.toString().replace('/', '.').replace(".class", "");
name = name.replace('/', '.');
name = name.replace(".class", "");
// Try to find a class with the same name and put it into our list // Try to find a class with the same name and put it into our list
final Class<?> c = classLoader.loadClass(name); final Class<?> c = classLoader.loadClass(className);
result.add(c); result.add(c);
} catch (final Throwable ex) { // NOPMD (Generic throwable and empty catch block) NOCS (IllegalCatchCheck) } catch (final Throwable ex) { // NOPMD (Generic throwable and empty catch block) NOCS (IllegalCatchCheck)
// Ignore error. // Ignore error.
...@@ -158,8 +162,8 @@ public class PluginFinder { ...@@ -158,8 +162,8 @@ public class PluginFinder {
try { try {
stream.close(); stream.close();
} catch (final IOException ex1) { } catch (final IOException ex1) {
// Ignore this // Log but ignore this fail.
ex1.printStackTrace(); LOG.warn("Could not close stream.", ex1);
} }
} }
} }
......
/***************************************************************************
* Copyright 2013 Kieker Project (http://kieker-monitoring.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
package kieker.webgui.persistence.impl.util;
import javax.annotation.Nullable;
import com.google.common.base.Function;
/**
* A function which simply casts from the source type to the target type.
*
* @author Nils Christian Ehmke
*
* @param <S>
* The source type.
* @param <T>
* The target type.
*/
public class SimpleCastFunction<S, T> implements Function<S, T> {
/**
* Default constructor.
*/
public SimpleCastFunction() {
// No code necessary
}
@SuppressWarnings("unchecked")
@Override
@Nullable
public T apply(@Nullable final S elem) {
return (T) elem;
}
}
...@@ -336,7 +336,7 @@ public class CurrentAnalysisEditorBean { ...@@ -336,7 +336,7 @@ public class CurrentAnalysisEditorBean {
*/ */
public void addRepository(final RepositoryDecorator container) { public void addRepository(final RepositoryDecorator container) {
// Create a new instance for the model // Create a new instance for the model
final MIRepository repository = container.newCopy(CurrentAnalysisEditorBean.MODEL_FACTORY); final MIRepository repository = container.newCopy();
// Add it to the project - and to the graph // Add it to the project - and to the graph
this.project.getRepositories().add(repository); this.project.getRepositories().add(repository);
...@@ -353,7 +353,7 @@ public class CurrentAnalysisEditorBean { ...@@ -353,7 +353,7 @@ public class CurrentAnalysisEditorBean {
*/ */
public void addReader(final ReaderDecorator container) { public void addReader(final ReaderDecorator container) {
// Create a new instance for the model // Create a new instance for the model
final MIPlugin plugin = container.newCopy(CurrentAnalysisEditorBean.MODEL_FACTORY); final MIPlugin plugin = container.newCopy();
// Add it to the project - and to the graph // Add it to the project - and to the graph
this.project.getPlugins().add(plugin); this.project.getPlugins().add(plugin);
...@@ -370,7 +370,7 @@ public class CurrentAnalysisEditorBean { ...@@ -370,7 +370,7 @@ public class CurrentAnalysisEditorBean {
*/ */
public void addFilter(final FilterDecorator container) { public void addFilter(final FilterDecorator container) {
// Create a new instance for the model // Create a new instance for the model
final MIPlugin plugin = container.newCopy(CurrentAnalysisEditorBean.MODEL_FACTORY); final MIPlugin plugin = container.newCopy();
// Add it to the project - and to the graph // Add it to the project - and to the graph
this.project.getPlugins().add(plugin); this.project.getPlugins().add(plugin);
......
...@@ -23,9 +23,6 @@ import java.util.Collection; ...@@ -23,9 +23,6 @@ import java.util.Collection;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import kieker.analysis.plugin.filter.AbstractFilterPlugin;
import kieker.analysis.plugin.reader.AbstractReaderPlugin;
import kieker.analysis.repository.AbstractRepository;
import kieker.webgui.common.ClassAndMethodContainer; import kieker.webgui.common.ClassAndMethodContainer;
import kieker.webgui.common.exception.ReflectionException; import kieker.webgui.common.exception.ReflectionException;
...@@ -59,9 +56,9 @@ public class PluginFinderTest { ...@@ -59,9 +56,9 @@ public class PluginFinderTest {
final ClassAndMethodContainer classAndMethodContainer = new ClassAndMethodContainer(classLoader); final ClassAndMethodContainer classAndMethodContainer = new ClassAndMethodContainer(classLoader);
try { try {
final Collection<Class<AbstractFilterPlugin>> filters = pluginFinder.getAllFiltersWithinJar(kiekerURL, classLoader, classAndMethodContainer); final Collection<Class<?>> filters = pluginFinder.getAllFiltersWithinJar(kiekerURL, classLoader, classAndMethodContainer);
final Collection<Class<AbstractReaderPlugin>> readers = pluginFinder.getAllReadersWithinJar(kiekerURL, classLoader, classAndMethodContainer); final Collection<Class<?>> readers = pluginFinder.getAllReadersWithinJar(kiekerURL, classLoader, classAndMethodContainer);
final Collection<Class<AbstractRepository>> repositories = pluginFinder.getAllRepositoriesWithinJar(kiekerURL, classLoader, classAndMethodContainer); final Collection<Class<?>> repositories = pluginFinder.getAllRepositoriesWithinJar(kiekerURL, classLoader, classAndMethodContainer);
// There should be at least one element of both types // There should be at least one element of both types
Assert.assertFalse("No filters found.", filters.isEmpty()); Assert.assertFalse("No filters found.", filters.isEmpty());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment