* initial commit
git-svn-id: svn+ssh://svn.synyx.de/var/svn/synyx/opensource/synyx-plugin/trunk@2910 5a64d73e-33d6-4ccc-9058-23f8668ecac9
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
package org.synyx.plugin.metadata;
|
||||
|
||||
import org.synyx.plugin.core.Plugin;
|
||||
|
||||
|
||||
/**
|
||||
* Abstract base class for plugins based on {@code PluginMetadata}. Plugins
|
||||
* based on this class can be selected from the {@code PluginRegistry} via an
|
||||
* instance of {@code PluginMetadata}. Therefore you can regard this as a role
|
||||
* model implementation of a base class for certain delimiter implmentations.
|
||||
*
|
||||
* @author Oliver Gierke - gierke@synyx.de
|
||||
*/
|
||||
public abstract class AbstractMetadataBasedPlugin implements
|
||||
Plugin<PluginMetadata>, MetadataProvider {
|
||||
|
||||
private PluginMetadata metadata;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new instance of {@code AbstractMetadataBasedPlugin}.
|
||||
*
|
||||
* @param name
|
||||
* @param version
|
||||
*/
|
||||
public AbstractMetadataBasedPlugin(String name, String version) {
|
||||
|
||||
this.metadata = new SimplePluginMetadata(name, version);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.synyx.minos.core.plugin.Plugin#supports(java.lang.Object)
|
||||
*/
|
||||
public boolean supports(PluginMetadata delimiter) {
|
||||
|
||||
return getMetadata().equals(delimiter);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.synyx.minos.core.plugin.MetadataProvider#getMetadata()
|
||||
*/
|
||||
public PluginMetadata getMetadata() {
|
||||
|
||||
return metadata;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.synyx.plugin.metadata;
|
||||
|
||||
/**
|
||||
* Interface for plugins providing metadata information. Usually the plugins
|
||||
* will implement this interface themselves.
|
||||
*
|
||||
* @author Oliver Gierke - gierke@synyx.de
|
||||
*/
|
||||
public interface MetadataProvider {
|
||||
|
||||
/**
|
||||
* Returns the plugins metadata.
|
||||
*
|
||||
* @return the plugins metadata
|
||||
*/
|
||||
public PluginMetadata getMetadata();
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.synyx.plugin.metadata;
|
||||
|
||||
/**
|
||||
* Basic interface to define a set of metadata information for plugins.
|
||||
*
|
||||
* @author Oliver Gierke - gierke@synyx.de
|
||||
*/
|
||||
public interface PluginMetadata {
|
||||
|
||||
/**
|
||||
* Returns a unique plugin name. Plugins return a metadata implementation
|
||||
* have to ensure uniqueness of this name.
|
||||
*
|
||||
* @return the name of the plugin
|
||||
*/
|
||||
String getName();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the plugin version. This allows rudimentary versioning
|
||||
* possibilities.
|
||||
*
|
||||
* @return the version of the plugin
|
||||
*/
|
||||
String getVersion();
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package org.synyx.plugin.metadata;
|
||||
|
||||
import org.apache.commons.lang.ObjectUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
|
||||
/**
|
||||
* Value object style implementation of {@code PluginMetadata}.
|
||||
*
|
||||
* @author Oliver Gierke - gierke@synyx.de
|
||||
*/
|
||||
public class SimplePluginMetadata implements PluginMetadata {
|
||||
|
||||
private String name;
|
||||
private String version;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new instance of {@code SimplePluginMetadata}.
|
||||
*
|
||||
* @param name
|
||||
* @param version
|
||||
*/
|
||||
public SimplePluginMetadata(String name, String version) {
|
||||
|
||||
this.name = name;
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.synyx.minos.core.plugin.PluginMetadata#getName()
|
||||
*/
|
||||
public String getName() {
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.synyx.minos.core.plugin.PluginMetadata#getVersion()
|
||||
*/
|
||||
public String getVersion() {
|
||||
|
||||
return version;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
return String.format("%s:%s", getName(), getVersion());
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
|
||||
if (!(obj instanceof PluginMetadata)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
PluginMetadata that = (PluginMetadata) obj;
|
||||
|
||||
boolean sameName = StringUtils.equals(this.getName(), that.getName());
|
||||
boolean sameVersion =
|
||||
StringUtils.equals(this.getName(), that.getName());
|
||||
|
||||
return sameName && sameVersion;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return ObjectUtils.hashCode(name) + ObjectUtils.hashCode(version);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user