/** Get the Plugin annotation for the class */ static Plugin getPluginMetadata(final Class<?> cls) throws PluginException { // try to get plugin provider name final String pluginname; if (!cls.isAnnotationPresent(Plugin.class)) { throw new PluginException("No Plugin annotation was found for the class: " + cls.getName()); } final Plugin annotation = (Plugin) cls.getAnnotation(Plugin.class); pluginname = annotation.name(); if (null == pluginname || "".equals(pluginname)) { throw new PluginException( "Plugin annotation 'name' cannot be empty for the class: " + cls.getName()); } // get service name from annotation final String servicename = annotation.service(); if (null == servicename || "".equals(servicename)) { throw new PluginException( "Plugin annotation 'service' cannot be empty for the class: " + cls.getName()); } return annotation; }
/** Return true if the ident matches the Plugin annotation for the class */ static ProviderIdent getProviderDeclaration(final Class<?> cls) throws PluginException { final Plugin annotation = getPluginMetadata(cls); return new ProviderIdent(annotation.service(), annotation.name()); }
/** Return true if the ident matches the Plugin annotation for the class */ static boolean matchesProviderDeclaration(final ProviderIdent ident, final Class<?> cls) throws PluginException { final Plugin annotation = getPluginMetadata(cls); return ident.getFirst().equals(annotation.service()) && ident.getSecond().equals(annotation.name()); }