use of org.ballerinalang.siddhi.annotation.Extension in project ballerina by ballerina-lang.
the class SiddhiExtensionLoader method addExtensionToMap.
/**
* Adding extensions to Siddhi siddhiExtensionsMap.
*
* @param extensionClass extension class
* @param siddhiExtensionsMap reference map for the Siddhi extension
*/
private static void addExtensionToMap(Class extensionClass, Map<String, Class> siddhiExtensionsMap) {
Extension siddhiExtensionAnnotation = (Extension) extensionClass.getAnnotation(Extension.class);
if (siddhiExtensionAnnotation != null) {
if (!siddhiExtensionAnnotation.name().isEmpty()) {
Class previousClass = null;
if (!siddhiExtensionAnnotation.namespace().isEmpty()) {
String key = siddhiExtensionAnnotation.namespace() + SiddhiConstants.EXTENSION_SEPARATOR + siddhiExtensionAnnotation.name();
Class existingValue = siddhiExtensionsMap.get(key);
if (existingValue == null) {
previousClass = siddhiExtensionsMap.put(key, extensionClass);
}
if (previousClass != null) {
log.warn("Dropping extension '" + extensionClass + "' as '" + previousClass + "' was already " + "loaded with the same namespace and name '" + siddhiExtensionAnnotation.namespace() + SiddhiConstants.EXTENSION_SEPARATOR + siddhiExtensionAnnotation.name() + "'");
}
} else {
previousClass = siddhiExtensionsMap.put(siddhiExtensionAnnotation.name(), extensionClass);
if (previousClass != null) {
log.warn("Dropping extension '" + extensionClass + "' as '" + previousClass + "' was already " + "loaded with the " + "same name '" + siddhiExtensionAnnotation.name() + "'");
}
}
} else {
log.error("Unable to load extension " + extensionClass.getName() + ", missing Extension annotation.");
}
} else {
log.error("Unable to load extension " + extensionClass.getName() + ", empty name element given in " + "Extension annotation.");
}
}
use of org.ballerinalang.siddhi.annotation.Extension in project ballerina by ballerina-lang.
the class SiddhiAnnotationProcessor method process.
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
// Iterate over all @Extension annotated elements.
for (Element element : roundEnv.getElementsAnnotatedWith(Extension.class)) {
// Check if a class has been annotated with @Extension.
if (element.getKind() == ElementKind.CLASS) {
String superClass = getMatchingSuperClass(element, new String[] { AnnotationConstants.SINK_MAPPER_SUPER_CLASS, AnnotationConstants.SINK_SUPER_CLASS, AnnotationConstants.FUNCTION_EXECUTOR_SUPER_CLASS, AnnotationConstants.AGGREGATION_ATTRIBUTE_SUPER_CLASS, AnnotationConstants.DISTRIBUTION_STRATEGY_SUPER_CLASS, AnnotationConstants.STREAM_PROCESSOR_SUPER_CLASS, AnnotationConstants.STREAM_FUNCTION_PROCESSOR_SUPER_CLASS, AnnotationConstants.STORE_SUPER_CLASS, AnnotationConstants.SOURCE_SUPER_CLASS, AnnotationConstants.SOURCE_MAPPER_SUPER_CLASS, AnnotationConstants.WINDOW_PROCESSOR_CLASS, AnnotationConstants.SCRIPT_SUPER_CLASS, AnnotationConstants.INCREMENTAL_ATTRIBUTE_AGGREGATOR_SUPER_CLASS });
AbstractAnnotationProcessor abstractAnnotationProcessor = null;
Extension annotation = element.getAnnotation(Extension.class);
String name = annotation.name();
String description = annotation.description();
String namespace = annotation.namespace();
Parameter[] parameters = annotation.parameters();
ReturnAttribute[] returnAttributes = annotation.returnAttributes();
SystemParameter[] systemParameters = annotation.systemParameter();
Example[] examples = annotation.examples();
String extensionClassFullName = element.asType().toString();
if (superClass != null) {
switch(superClass) {
case AnnotationConstants.DISTRIBUTION_STRATEGY_SUPER_CLASS:
abstractAnnotationProcessor = new DistributionStrategyValidationAnnotationProcessor(extensionClassFullName);
break;
case AnnotationConstants.SINK_MAPPER_SUPER_CLASS:
abstractAnnotationProcessor = new SinkMapperValidationAnnotationProcessor(extensionClassFullName);
break;
case AnnotationConstants.SINK_SUPER_CLASS:
abstractAnnotationProcessor = new SinkValidationAnnotationProcessor(extensionClassFullName);
break;
case AnnotationConstants.FUNCTION_EXECUTOR_SUPER_CLASS:
abstractAnnotationProcessor = new FunctionExecutorValidationAnnotationProcessor(extensionClassFullName);
break;
case AnnotationConstants.AGGREGATION_ATTRIBUTE_SUPER_CLASS:
abstractAnnotationProcessor = new AggregationAttributeValidationAnnotationProcessor(extensionClassFullName);
break;
case AnnotationConstants.STREAM_PROCESSOR_SUPER_CLASS:
abstractAnnotationProcessor = new StreamProcessorValidationAnnotationProcessor(extensionClassFullName);
break;
case AnnotationConstants.SOURCE_SUPER_CLASS:
abstractAnnotationProcessor = new SourceValidationAnnotationProcessor(extensionClassFullName);
break;
case AnnotationConstants.SOURCE_MAPPER_SUPER_CLASS:
abstractAnnotationProcessor = new SourceMapperValidationAnnotationProcessor(extensionClassFullName);
break;
case AnnotationConstants.STORE_SUPER_CLASS:
abstractAnnotationProcessor = new StoreValidationAnnotationProcessor(extensionClassFullName);
break;
case AnnotationConstants.STREAM_FUNCTION_PROCESSOR_SUPER_CLASS:
abstractAnnotationProcessor = new StreamFunctionProcessorValidationAnnotationProcessor(extensionClassFullName);
break;
case AnnotationConstants.WINDOW_PROCESSOR_CLASS:
abstractAnnotationProcessor = new WindowProcessorValidationAnnotationProcessor(extensionClassFullName);
break;
case AnnotationConstants.SCRIPT_SUPER_CLASS:
abstractAnnotationProcessor = new ScriptValidationAnnotationProcessor(extensionClassFullName);
break;
case AnnotationConstants.INCREMENTAL_ATTRIBUTE_AGGREGATOR_SUPER_CLASS:
abstractAnnotationProcessor = new IncrementalAggregationAttributeValidationAnnotationProcessor(extensionClassFullName);
break;
default:
// Throw error if no matching super class.
showBuildError(MessageFormat.format("Default switch case executed as there is no " + "matching super class option for @{0}.", superClass), element);
break;
}
if (abstractAnnotationProcessor != null) {
try {
abstractAnnotationProcessor.basicParameterValidation(name, description, namespace);
abstractAnnotationProcessor.parameterValidation(parameters);
abstractAnnotationProcessor.returnAttributesValidation(returnAttributes);
abstractAnnotationProcessor.systemParametersValidation(systemParameters);
abstractAnnotationProcessor.examplesValidation(examples);
} catch (AnnotationValidationException e) {
showBuildError(e.getMessage(), element);
}
} else {
showBuildError(MessageFormat.format("Error while validation, " + "abstractAnnotationProcessor cannot be null.", superClass), element);
}
} else {
// Throw error if no matching super class.
showBuildError("Class does not have a matching Siddhi Extension super class.", element);
}
} else {
// Throw error if the element returned is method or package.
showBuildError(MessageFormat.format("Only classes can be annotated with @{0}.", Extension.class.getCanonicalName()), element);
}
}
// Returning false since this processor only validates.
return false;
}
Aggregations