* @return array of plugin instances
*/
public synchronized Object[] getOrderedPlugins(Class<?> clazz, String xPointId,
String orderProperty) {
Object[] filters;
ObjectCache objectCache = ObjectCache.get(conf);
filters = (Object[]) objectCache.getObject(clazz.getName());
if (filters == null) {
String order = conf.get(orderProperty);
List<String> orderOfFilters = new ArrayList<String>();
boolean userDefinedOrder = false;
if (order != null && !order.trim().isEmpty()) {
orderOfFilters = Arrays.asList(order.trim().split("\\s+"));
userDefinedOrder = true;
}
try {
ExtensionPoint point = PluginRepository.get(conf).getExtensionPoint(
xPointId);
if (point == null)
throw new RuntimeException(xPointId + " not found.");
Extension[] extensions = point.getExtensions();
HashMap<String, Object> filterMap = new HashMap<String, Object>();
for (int i = 0; i < extensions.length; i++) {
Extension extension = extensions[i];
Object filter = extension.getExtensionInstance();
if (!filterMap.containsKey(filter.getClass().getName())) {
filterMap.put(filter.getClass().getName(), filter);
if (!userDefinedOrder)
orderOfFilters.add(filter.getClass().getName());
}
}
List<Object> sorted = new ArrayList<Object>();
for (String orderedFilter : orderOfFilters) {
Object f = filterMap.get(orderedFilter);
if (f == null) {
LOG.error(clazz.getSimpleName() + " : " + orderedFilter
+ " declared in configuration property " + orderProperty
+ " but not found in an active plugin - ignoring.");
continue;
}
sorted.add(f);
}
Object[] filter = (Object[]) Array.newInstance(clazz, sorted.size());
for (int i = 0; i < sorted.size(); i++) {
filter[i] = sorted.get(i);
if (LOG.isTraceEnabled()) {
LOG.trace(clazz.getSimpleName() + " : filters[" + i + "] = "
+ filter[i].getClass());
}
}
objectCache.setObject(clazz.getName(), filter);
} catch (PluginRuntimeException e) {
throw new RuntimeException(e);
}
filters = (Object[]) objectCache.getObject(clazz.getName());
}
return filters;
}