*/
public ComponentModel scan(Class<?> bpmClass, SwitchYardNamespace switchyardNamespace) throws IOException {
if (switchyardNamespace == null) {
switchyardNamespace = SwitchYardNamespace.DEFAULT;
}
BPM bpm = bpmClass.getAnnotation(BPM.class);
if (bpm == null) {
throw BPMMessages.MESSAGES.bpmClassGetNameIsMissingTheBPMAnnotation(bpmClass.getName());
}
Class<?> bpmInterface = bpm.value();
if (BPM.UndefinedBPMInterface.class.equals(bpmInterface)) {
bpmInterface = bpmClass;
}
if (!bpmInterface.isInterface()) {
throw BPMMessages.MESSAGES.bpmInterfaceGetNameIsAClassBPMOnlyAllowedOnInterfaces(bpmInterface.getName());
}
String bpmName = Strings.trimToNull(bpm.name());
if (bpmName == null) {
bpmName = bpmInterface.getSimpleName();
}
ComponentModel componentModel = new V1ComponentModel();
componentModel.setName(bpmName);
BPMNamespace bpmNamespace = BPMNamespace.fromUri(bpm.namespace());
if (bpmNamespace == null) {
bpmNamespace = BPMNamespace.DEFAULT;
for (BPMNamespace value : BPMNamespace.values()) {
if (value.versionMatches(switchyardNamespace)) {
bpmNamespace = value;
break;
}
}
}
BPMComponentImplementationModel componentImplementationModel = new V1BPMComponentImplementationModel(bpmNamespace.uri());
boolean persistent = bpm.persistent();
if (persistent) {
componentImplementationModel.setPersistent(persistent);
}
String processId = bpm.processId();
if (UNDEFINED.equals(processId)) {
processId = bpmName;
}
componentImplementationModel.setProcessId(processId);
OperationsModel operationsModel = new V1OperationsModel(bpmNamespace.uri());
JavaService javaService = JavaService.fromClass(bpmInterface);
for (Method method : bpmClass.getDeclaredMethods()) {
BPMOperationType operationType = null;
String eventId = null;
Global[] globalMappingAnnotations = null;
Input[] inputMappingAnnotations = null;
Output[] outputMappingAnnotations = null;
Fault[] faultMappingAnnotations = null;
if (START_PROCESS_FILTER.matches(method)) {
operationType = BPMOperationType.START_PROCESS;
StartProcess startProcessAnnotation = method.getAnnotation(StartProcess.class);
globalMappingAnnotations = startProcessAnnotation.globals();
inputMappingAnnotations = startProcessAnnotation.inputs();
outputMappingAnnotations = startProcessAnnotation.outputs();
faultMappingAnnotations = startProcessAnnotation.faults();
} else if (SIGNAL_EVENT_FILTER.matches(method)) {
operationType = BPMOperationType.SIGNAL_EVENT;
SignalEvent signalEventAnnotation = method.getAnnotation(SignalEvent.class);
eventId = Strings.trimToNull(signalEventAnnotation.eventId());
globalMappingAnnotations = signalEventAnnotation.globals();
inputMappingAnnotations = signalEventAnnotation.inputs();
outputMappingAnnotations = signalEventAnnotation.outputs();
faultMappingAnnotations = signalEventAnnotation.faults();
} else if (SIGNAL_EVENT_ALL_FILTER.matches(method)) {
operationType = BPMOperationType.SIGNAL_EVENT_ALL;
SignalEventAll signalEventAllAnnotation = method.getAnnotation(SignalEventAll.class);
eventId = Strings.trimToNull(signalEventAllAnnotation.eventId());
globalMappingAnnotations = signalEventAllAnnotation.globals();
inputMappingAnnotations = signalEventAllAnnotation.inputs();
outputMappingAnnotations = signalEventAllAnnotation.outputs();
faultMappingAnnotations = signalEventAllAnnotation.faults();
} else if (ABORT_PROCESS_INSTANCE_FILTER.matches(method)) {
operationType = BPMOperationType.ABORT_PROCESS_INSTANCE;
AbortProcessInstance abortProcessInstanceAnnotation = method.getAnnotation(AbortProcessInstance.class);
globalMappingAnnotations = new Global[]{};
inputMappingAnnotations = new Input[]{};
outputMappingAnnotations = abortProcessInstanceAnnotation.outputs();
faultMappingAnnotations = abortProcessInstanceAnnotation.faults();
}
if (operationType != null) {
ServiceOperation serviceOperation = javaService.getOperation(method.getName());
if (serviceOperation != null) {
OperationModel operationModel = new V1BPMOperationModel(bpmNamespace.uri());
operationModel.setEventId(eventId);
operationModel.setName(serviceOperation.getName());
operationModel.setType(operationType);
operationModel.setGlobals(toGlobalsModel(globalMappingAnnotations, bpmNamespace));
operationModel.setInputs(toInputsModel(inputMappingAnnotations, bpmNamespace));
operationModel.setOutputs(toOutputsModel(outputMappingAnnotations, bpmNamespace));
operationModel.setFaults(toFaultsModel(faultMappingAnnotations, bpmNamespace));
operationsModel.addOperation(operationModel);
}
}
}
if (!operationsModel.getOperations().isEmpty()) {
componentImplementationModel.setOperations(operationsModel);
}
componentImplementationModel.setChannels(toChannelsModel(bpm.channels(), bpmNamespace, componentModel, switchyardNamespace));
componentImplementationModel.setListeners(toListenersModel(bpm.listeners(), bpmNamespace));
componentImplementationModel.setLoggers(toLoggersModel(bpm.loggers(), bpmNamespace));
componentImplementationModel.setManifest(toManifestModel(bpm.manifest(), bpmNamespace));
componentImplementationModel.setProperties(toPropertiesModel(bpm.properties(), bpmNamespace));
componentImplementationModel.setUserGroupCallback(toUserGroupCallbackModel(bpm.userGroupCallback(), bpmNamespace));
componentImplementationModel.setWorkItemHandlers(toWorkItemHandlersModel(bpm.workItemHandlers(), bpmNamespace));
componentModel.setImplementation(componentImplementationModel);
ComponentServiceModel componentServiceModel = new V1ComponentServiceModel(switchyardNamespace.uri());
InterfaceModel interfaceModel = new V1InterfaceModel(InterfaceModel.JAVA);
interfaceModel.setInterface(bpmInterface.getName());
componentServiceModel.setInterface(interfaceModel);