*/
public ComponentModel scan(Class<?> rulesClass, SwitchYardNamespace switchyardNamespace) throws IOException {
if (switchyardNamespace == null) {
switchyardNamespace = SwitchYardNamespace.DEFAULT;
}
Rules rules = rulesClass.getAnnotation(Rules.class);
Class<?> rulesInterface = rules.value();
if (Rules.UndefinedRulesInterface.class.equals(rulesInterface)) {
rulesInterface = rulesClass;
}
if (!rulesInterface.isInterface()) {
throw RulesMessages.MESSAGES.rulesInterfaceGetNameIsAClassRulesOnlyAllowedOnInterfaces(rulesInterface.getName());
}
String rulesName = Strings.trimToNull(rules.name());
if (rulesName == null) {
rulesName = rulesInterface.getSimpleName();
}
ComponentModel componentModel = new V1ComponentModel();
componentModel.setName(rulesName);
RulesNamespace rulesNamespace = RulesNamespace.fromUri(rules.namespace());
if (rulesNamespace == null) {
rulesNamespace = RulesNamespace.DEFAULT;
for (RulesNamespace value : RulesNamespace.values()) {
if (value.versionMatches(switchyardNamespace)) {
rulesNamespace = value;
break;
}
}
}
RulesComponentImplementationModel componentImplementationModel = new V1RulesComponentImplementationModel(rulesNamespace.uri());
OperationsModel operationsModel = new V1OperationsModel(rulesNamespace.uri());
JavaService javaService = JavaService.fromClass(rulesInterface);
for (Method method : rulesClass.getDeclaredMethods()) {
RulesOperationType operationType = null;
String eventId = null;
Global[] globalMappingAnnotations = null;
Input[] inputMappingAnnotations = null;
Output[] outputMappingAnnotations = null;
Fault[] faultMappingAnnotations = null;
if (EXECUTE_FILTER.matches(method)) {
operationType = RulesOperationType.EXECUTE;
Execute executeAnnotation = method.getAnnotation(Execute.class);
globalMappingAnnotations = executeAnnotation.globals();
inputMappingAnnotations = executeAnnotation.inputs();
outputMappingAnnotations = executeAnnotation.outputs();
faultMappingAnnotations = executeAnnotation.faults();
} else if (INSERT_FILTER.matches(method)) {
operationType = RulesOperationType.INSERT;
Insert insertAnnotation = method.getAnnotation(Insert.class);
globalMappingAnnotations = insertAnnotation.globals();
inputMappingAnnotations = insertAnnotation.inputs();
outputMappingAnnotations = insertAnnotation.outputs();
faultMappingAnnotations = insertAnnotation.faults();
} else if (FIRE_ALL_RULES_FILTER.matches(method)) {
operationType = RulesOperationType.FIRE_ALL_RULES;
FireAllRules fireAllRulesAnnotation = method.getAnnotation(FireAllRules.class);
globalMappingAnnotations = fireAllRulesAnnotation.globals();
inputMappingAnnotations = fireAllRulesAnnotation.inputs();
outputMappingAnnotations = fireAllRulesAnnotation.outputs();
faultMappingAnnotations = fireAllRulesAnnotation.faults();
} else if (FIRE_UNTIL_HALT_FILTER.matches(method)) {
operationType = RulesOperationType.FIRE_UNTIL_HALT;
FireUntilHalt fireUntilHaltAnnotation = method.getAnnotation(FireUntilHalt.class);
eventId = Strings.trimToNull(fireUntilHaltAnnotation.eventId());
globalMappingAnnotations = fireUntilHaltAnnotation.globals();
inputMappingAnnotations = fireUntilHaltAnnotation.inputs();
outputMappingAnnotations = fireUntilHaltAnnotation.outputs();
faultMappingAnnotations = fireUntilHaltAnnotation.faults();
}
if (operationType != null) {
ServiceOperation serviceOperation = javaService.getOperation(method.getName());
if (serviceOperation != null) {
OperationModel operationModel = new V1RulesOperationModel(rulesNamespace.uri());
operationModel.setEventId(eventId);
operationModel.setName(serviceOperation.getName());
operationModel.setType(operationType);
operationModel.setGlobals(toGlobalsModel(globalMappingAnnotations, rulesNamespace));
operationModel.setInputs(toInputsModel(inputMappingAnnotations, rulesNamespace));
operationModel.setOutputs(toOutputsModel(outputMappingAnnotations, rulesNamespace));
operationModel.setFaults(toFaultsModel(faultMappingAnnotations, rulesNamespace));
operationsModel.addOperation(operationModel);
}
}
}
if (!operationsModel.getOperations().isEmpty()) {
componentImplementationModel.setOperations(operationsModel);
}
componentImplementationModel.setChannels(toChannelsModel(rules.channels(), rulesNamespace, componentModel, switchyardNamespace));
componentImplementationModel.setListeners(toListenersModel(rules.listeners(), rulesNamespace));
componentImplementationModel.setLoggers(toLoggersModel(rules.loggers(), rulesNamespace));
componentImplementationModel.setManifest(toManifestModel(rules.manifest(), rulesNamespace));
componentImplementationModel.setProperties(toPropertiesModel(rules.properties(), rulesNamespace));
componentModel.setImplementation(componentImplementationModel);
ComponentServiceModel componentServiceModel = new V1ComponentServiceModel(switchyardNamespace.uri());
InterfaceModel interfaceModel = new V1InterfaceModel(InterfaceModel.JAVA);
interfaceModel.setInterface(rulesInterface.getName());
componentServiceModel.setInterface(interfaceModel);