## 3 Pattern Repository
### Pattern Representation  
The patterns in the repository are software components. In particular, the repository patterns are represented as Java classes implementing the SimplifiablePattern interface shown on the Listing 1. This interface includes the methods necessary to search and replace a simplifiable pattern in the original model with a simplified one:  
* **searchPattern** This method has to look for the reducible pattern in the model to simplify. If the pattern is found, it returns the point in the model in which the pattern has been identified. * **reducePattern** This method has to simplify a pattern in a model (found previously by the previous method) by replacing the reducible pattern with the simplified pattern associated (that contains less elements). ```
1 publicinterfaceSimplifiablePattern{
2 publicBpmnIdsearchPattern(Bpmnmodel);
3 publicBpmnreducePattern(Bpmnmodel,BpmnIdstartElmnt);
4}
```  
Listing 1: Interface SimplifiablePattern. Thus, the Java classes intended to contain the information about the pair of patterns will play a central role as they will include not just the graph models but also the artifacts to support the operations required in the simplification process (described in the next section). The population of the repository begins with the identification of the pair of patterns: the simplifiable pattern and its simplified version (cf. Figures 2-6). From the analysis of both versions, the code must be developed in order to transform the BPMN fragments information into a Java class that contains the behaviour of the simplifiable pattern and the actions that must be performed on the BPMN to apply the simplification. As an example, the patterns pair shown in Figure 2 is implemented on the Listing 2. ```
1 publicclassPamimplementsSimplifiablePattern{
2@Override
3 publicBpmnIdsearchPattern(Bpmnmodel){
4 ArrayList<BpmnExGateway>exGateways=model.getExclusiveGateways();
5 for(BpmnExGatewaygateway:exGateways)
6{
7 ArrayList<BpmnId>outSequencesIds=gateway.getOutSequencesIds();
8 for(BpmnIdseqId:outSequencesIds)
9{//checkifsomesequencereturnstogateway
10 BpmnIdnextElmnt=model.getSequenceById(seqId).target();
11 if(nextElmnt.equals(gateway.getId()))
12{//Elementfound
13 returnnewBpmnId(gateway.getId());
14}
15}
16}
17 returnnull;
18}
19
20@Override
21 publicBpmnreducePattern(Bpmnmodel,BpmnIdstart){12 BpmIndgIdd = startElement;
13 BpmnExGateway gateway = model.getGatewayById(gId);
14 ArrayList<BpmId>outSequencesIds = gateway.getOutSequencesIds();
15 for(BpmnIdseqId:outSequencesIds)
16{//searchallsequencereturningtogateway
17 BpmnIdnextElmnt=model.getSequenceById(seqId).getTarget();
18 if(nextElmnt.equals(gateway.getId()))
19//Elementfound
20 model.deleteSequence(seqId);
21 gateway.deleteOutgoing(seqId);
22 gateway.deleteIncoming(seqId);
23}
24}
25 returnmodel;
26}
```  
Listing 2: First pair of patterns implemented as a Java class. The first method of the interface, _searchPattern_, consists mainly in a loop along all the exclusive gateways in the model to find out if one of them matches with Figure 1(a). For each gateway, it looks for a sequence that exits and returns to it (i.e., doing nothing). If a gateway with these conditions is found, the method returns it. Conversely, the second method, _reducePattern_, receives as input parameter the starting element of the pattern found by the previously described method (if the case). The objective now is to convert the original pattern into its simplified version (cf. Figure 1(a),b) inside the whole BPMN process model. In this case, it looks for all the sequences that are not necessary and deletes them. The reader may note the use of the Java class \(Bpmn\). This class is intended to parse an XML file describing a BPMN compliant document into a set of data structures representing the BPMN process model. Also, it offers a collection of high level operations to operate on the model facilitating the implementation of the patterns as previously described (cf. Figure 7).