
pl.bristleback.server.bristle.config.PackageActionAnnotationsProcessor Maven / Gradle / Ivy
// Bristleback plugin - Copyright (c) 2010 bristleback.googlecode.com
// ---------------------------------------------------------------------------
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published by the
// Free Software Foundation; either version 3 of the License, or (at your
// option) any later version.
// This library is distributed in the hope that it will be useful,
// but without any warranty; without even the implied warranty of merchantability
// or fitness for a particular purpose.
// You should have received a copy of the GNU Lesser General Public License along
// with this program; if not, see .
// ---------------------------------------------------------------------------
package pl.bristleback.server.bristle.config;
import pl.bristleback.server.bristle.actions.RemoteAction;
import pl.bristleback.server.bristle.actions.RemoteActionInformation;
import pl.bristleback.server.bristle.exceptions.MissingPluginConfigurationElementException;
import pl.bristleback.server.bristle.utils.ResolverUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* Default implementation of {@link pl.bristleback.server.bristle.config.ActionAnnotationsProcessor} interface.
* If no annotation processor is specified by user, this implementation will be used to retrieve annotated actions.
* This processor checks every not abstract class in package named by given plugin configuration containing
* {@link pl.bristleback.server.bristle.config.BristleConstants#ACTION_PACKAGE_SETTING_NAME} setting.
*
* Created on: 2010-09-03 16:05:22
*
* @author Wojciech Niemiec
*/
public final class PackageActionAnnotationsProcessor implements ActionAnnotationsProcessor {
private static Logger log = Logger.getLogger(PackageActionAnnotationsProcessor.class.getName());
private String packageName;
private List actionsList;
private ActionInformationResolver actionInformationResolver;
public PackageActionAnnotationsProcessor() {
actionsList = new ArrayList();
actionInformationResolver = new ActionInformationResolver();
}
public List getAnnotatedActions(Map pluginSettings) {
packageName = pluginSettings.get(BristleConstants.ACTION_PACKAGE_SETTING_NAME);
if (StringUtils.isEmpty(packageName)) {
throw new MissingPluginConfigurationElementException(BristleConstants.ACTION_PACKAGE_SETTING_NAME);
}
for (Class extends RemoteAction> actionClass : getActionClasses()) {
initActionInformation(actionClass);
}
return actionsList;
}
private Set> getActionClasses() {
String[] packages = StringUtils.split(packageName, '.');
ResolverUtil resolver = new ResolverUtil();
resolver.findImplementations(RemoteAction.class, packages);
return resolver.getClasses();
}
private void initActionInformation(Class extends RemoteAction> actionClass) {
if (Modifier.isAbstract(actionClass.getModifiers())) {
return;
}
RemoteActionInformation information = actionInformationResolver.getActionInformation(actionClass);
if (information == null) {
return;
}
actionsList.add(information);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy