summaryrefslogtreecommitdiffstats
path: root/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianGroupImpl.java
blob: e21016b3f5a8f43cc3994b0ebff6a0b4cc50e081 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package org.apache.tuscany.sca.guardian;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import org.apache.axis2.jaxws.message.util.ResettableReader;
import org.osoa.sca.annotations.Property;
import org.osoa.sca.annotations.Scope;
import org.osoa.sca.annotations.Service;

@Service(GuardianGroup.class)
@Scope("COMPOSITE")
public class GuardianGroupImpl implements GuardianGroup {

    private List<GuardianMember> guardianList;
    private ResettableReader reader;

    public GuardianGroupImpl() {
        guardianList = new LinkedList<GuardianMember>();
    }

    @Property(name = "recovery_rules", required = true)
    public void setRecoveryRules(String recoveryRules) {
        try {
            FileInputStream fileInputStream = new FileInputStream(recoveryRules);
            XMLStreamReader xmlReader = XMLInputFactory.newInstance().createXMLStreamReader(fileInputStream);
            reader = new ResettableReader(xmlReader);
        } catch (XMLStreamException ex) {
            Logger.getLogger(GuardianGroupImpl.class.getName()).log(Level.SEVERE, null, ex);
        } catch (FileNotFoundException ex) {
            Logger.getLogger(GuardianGroupImpl.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void addGuardianMember(GuardianMember guardianMember) {
        guardianList.add(guardianMember);
        guardianMember.setUniqueParticipantID(guardianList.size() - 1);
    }

    public void enableContext(Context context) {
        System.out.println("Enable Context.. nothing to do!");
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    public void removeContext() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void gthrow(GlobalExceptionInterface ex, List<String> participantList) {

        //1)Ivoked by a GuardianMember instance through the gthrow method
        //2)Notify all participants about the exception (FIFO atomic broadcast model) - it will cause the suspension of all participants
        //  2.1)Invoke the gthrow of the guardian members associated with the participants on participantList

        //Sends a message representing the exception to the other guardian members
        if (participantList == null) {
            for (GuardianMember g : guardianList) {
                if (!g.getParticipantIdentifier().equals(ex.getSignalingParticipant())) {
                    //g.gthrow(ex, participantList);
                    g.gthrow(null, null);
                }
            }
        } else {
            for (GuardianMember g : guardianList) {
                if (participantList.contains(g.getCurrentContext())) {
                    //g.gthrow(ex, participantList);
                    g.gthrow(null, null);
                }
            }
        }

        //Check if the participants are blocked
        List<Integer> flags = new ArrayList<Integer>(guardianList.size());
        for (int i = 0; i < guardianList.size(); i++) {
            if (guardianList.get(i).getService().isBlocked()) {
                flags.add(i, 1);
            } else {
                flags.add(i, 0);
            }
        }

        //Wait until all participants are blocked
        while (flags.contains(0)) {
            try {
                Thread.sleep(5000);
            } catch (InterruptedException ex1) {
                Logger.getLogger(GuardianGroupImpl.class.getName()).log(Level.SEVERE, null, ex1);
            }
        }

        //3)Once ALL required participants are SUSPENDED (suspended point), invoke the defined Recovery Rules
        for (GuardianMember g : guardianList) {
            g.addException(new SuspendException());
        }
        //  3.1) recovery_rules < signaled exceptions + context information of all participant > target context + exception to raise

        //Simpleste Recovery Rule: broadcast the exception for all participants - FIXME: hardcoded
//        for (GuardianMemberImpl g : guardianMembers) {
//            ex.setTargetContext(Context.CURRENT_CONTEXT);
//            g.addException(ex);
//        }

        applyRecoveryRules(ex);

//        //HARDCODED - SERVER-BACKUP EXAMPLE
//        //Rule 1
//        if (ex instanceof JoinException) {
//            if (guardianMembers.size() > 1) {
//
//                PrimaryExistsException primaryExists = new PrimaryExistsException();
//                primaryExists.setTargetContext(new Context("MAIN"));
//
//                BackupJoinedException backupJoined = new BackupJoinedException();
//                backupJoined.setTargetContext(new Context("PRIMARY"));
//
//                for (GuardianMember g : guardianMembers) {
//                    //let p = JoinException.signaler
//                    if (g.getParticipantIdentifier().equals(ex.getSignalingParticipant())) {
//                        g.addException(primaryExists);
//                        System.out.println("adding PrimaryExistsException to " + g.getParticipantIdentifier());
//                    } else {
//                        g.addException(backupJoined);
//                        System.out.println("adding BackupJoinedException to " + g.getParticipantIdentifier());
//                    }
//                }
//            }
//        } //Rule 2
//        else if (ex instanceof PrimaryFailedException) {
//
//            PrimaryFailedException primaryFailedInit = new PrimaryFailedException();
//            primaryFailedInit.setTargetContext(Context.INIT_CONTEXT);
//
//            PrimaryFailedException primaryFailedMain = new PrimaryFailedException();
//            primaryFailedMain.setTargetContext(new Context("MAIN"));
//
//            for (GuardianMember g : guardianMembers) {
//                if (g.getCurrentContext().getName().equals("PRIMARY")) {
//                    System.out.println("adding PrimaryFailedException to " + g.getParticipantIdentifier());
//                    g.addException(primaryFailedInit);
//                } else if (g.getCurrentContext().getName().equals("BACKUP")) {
//                    System.out.println("adding PrimaryFailedException to " + g.getParticipantIdentifier());
//                    g.addException(primaryFailedMain);
//                }
//            }
//        } //Rule 3
//        else if (ex instanceof BackupFailedException) {
//
//            BackupFailedException backupFailedPrimary = new BackupFailedException();
//            backupFailedPrimary.setTargetContext(new Context("PRIMARY"));
//
//            BackupFailedException backupFailedInit = new BackupFailedException();
//            backupFailedInit.setTargetContext(Context.INIT_CONTEXT);
//
//            for (GuardianMember g : guardianMembers) {
//                if (g.getCurrentContext().getName().equals("PRIMARY")) {
//                    System.out.println("adding BackupFailedException to " + g.getParticipantIdentifier());
//                    g.addException(backupFailedPrimary);
//                } else if (g.getCurrentContext().getName().equals("BACKUP")) {
//                    System.out.println("adding BackupFailedException to " + g.getParticipantIdentifier());
//                    g.addException(backupFailedInit);
//                }
//            }
//
//        }

    }

    private void applyRecoveryRules(GlobalExceptionInterface ex) {
        reader.reset();
        ruleTag(ex);
    }

    private void ruleTag(GlobalExceptionInterface ex) {
        try {
            while (reader.hasNext()) {
                reader.next();
                //<rule name="" signaled_exception="">
                if (reader.isStartElement() && reader.getLocalName().equals("rule")) {
                    for (int i = 0; i < reader.getAttributeCount(); i++) {
                        //ex == signaled_exception
                        if (reader.getAttributeLocalName(i).equals("signaled_exception") && ex.getClass().getName().equals(reader.getAttributeValue(i))) {
                            participantExceptionTag(ex);
                            break;
                        }
                    }
                }
            }
        } catch (XMLStreamException exc) {
            Logger.getLogger(GuardianGroupImpl.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void participantExceptionTag(GlobalExceptionInterface ex) {
        List<GuardianMember> gmList;
        try {
            while (reader.hasNext() && !(reader.isEndElement() && reader.getLocalName().equals("rule"))) {
                reader.next();
                //<participant match="<REG_EXP> | SIGNALER">
                if (reader.isStartElement() && reader.getLocalName().equals("participant")) {
                    String participantMatch = reader.getAttributeValue(0).trim();

                    gmList = getMatchingParticipants(participantMatch, ex);

                    if (!gmList.isEmpty()) {
                        throwExceptionTag(gmList, ex);
                    }
                }
            }
        } catch (XMLStreamException exc) {
            Logger.getLogger(GuardianGroupImpl.class.getName()).log(Level.SEVERE, null, exc);
        }
    }

    private void throwExceptionTag(List<GuardianMember> gmList, GlobalExceptionInterface ex) {

        String exceptionClassName;
        String targetContextName;
        Integer min_participant_joined;
        Integer max_participant_joined;

        try {

            while (reader.hasNext() && !(reader.isEndElement() && reader.getLocalName().equals("participant"))) {
                reader.next();

                //<throw_exception class="<Exception>" target_context="<Context>"/>
                if (reader.isStartElement() && reader.getLocalName().equals("throw_exception")) {

                    exceptionClassName = null;
                    targetContextName = null;
                    min_participant_joined = null;
                    max_participant_joined = null;
                    for (int j = 0; j < reader.getAttributeCount(); j++) {
                        if (reader.getAttributeLocalName(j).equals("class")) {
                            //class value
                            exceptionClassName = reader.getAttributeValue(j);
                        } else if (reader.getAttributeLocalName(j).equals("target_context")) {
                            //target_context value
                            targetContextName = reader.getAttributeValue(j);
                        } else if (reader.getAttributeLocalName(j).equals("min_participant_joined")) {
                            //min_participant_joined value
                            min_participant_joined = Integer.parseInt(reader.getAttributeValue(j));
                        } else {
                            //max_participant_joined value
                            max_participant_joined = Integer.parseInt(reader.getAttributeValue(j));
                        }
                    }

                    //Test the min and max joined participants condition
                    if (min_participant_joined != null && max_participant_joined != null) {
                        if (!(guardianList.size() >= min_participant_joined && guardianList.size() < max_participant_joined)) {
                            break;
                        }
                    } else if (min_participant_joined != null) {
                        if (!(guardianList.size() >= min_participant_joined)) {
                            break;
                        }
                    } else if (max_participant_joined != null) {
                        if (!(guardianList.size() >= min_participant_joined)) {
                            break;
                        }
                    }

                    //<affected_participants>
                    String affectedParticipants = affectedParticipantsTag();
                    int index = -1;

                    //Verify if the parameter is an index
                    try {
                        index = Integer.parseInt(affectedParticipants);
                    } catch (NumberFormatException nexc) {
                        index = -1;
                    }

                    Class exceptionClass = Class.forName(exceptionClassName);
                    Context targetContext;
                    if (targetContextName.toUpperCase().equals(Context.CURRENT_CONTEXT.getName().toUpperCase())) {
                        targetContext = Context.CURRENT_CONTEXT;
                    } else if (targetContextName.toUpperCase().equals(Context.INIT_CONTEXT.getName().toUpperCase())) {
                        targetContext = Context.INIT_CONTEXT;
                    } else {
                        targetContext = new Context(targetContextName);
                    }
                    GlobalException newException = (GlobalException) exceptionClass.newInstance();
                    
                    newException.setTargetContext(targetContext);
                    newException.setSignalingContext(ex.getSignalingContext());
                    newException.setSignalingParticipant(ex.getSignalingParticipant());

                    //Add the exception to the participants matched
                    if (index != -1) {
                        gmList.get(index).addException(newException);
                    } else if (affectedParticipants != null && affectedParticipants.length() != 0) {
                        if (affectedParticipants.toUpperCase().equals("FIRST")) {
                            gmList.get(0).addException(newException);
                        } else if (affectedParticipants.toUpperCase().equals("LAST")) {
                            gmList.get(gmList.size() - 1).addException(newException);
                        } else if (affectedParticipants.toUpperCase().equals("ALL")) {
                            for (GuardianMember gm : gmList) {
                                gm.addException(newException);
                            }
                        }
                    } else {
                        for (GuardianMember gm : gmList) {
                            gm.addException(newException);
                        }
                    }
                }
            }
        } catch (XMLStreamException ex1) {
            Logger.getLogger(GuardianGroupImpl.class.getName()).log(Level.SEVERE, null, ex1);
        } catch (InstantiationException ex1) {
            Logger.getLogger(GuardianGroupImpl.class.getName()).log(Level.SEVERE, null, ex1);
        } catch (IllegalAccessException ex1) {
            Logger.getLogger(GuardianGroupImpl.class.getName()).log(Level.SEVERE, null, ex1);
        } catch (ClassNotFoundException ex1) {
            Logger.getLogger(GuardianGroupImpl.class.getName()).log(Level.SEVERE, null, ex1);
        }
    }

    private String affectedParticipantsTag() {
        String affectedParticipants = null;
        try {
            while (reader.hasNext() && !(reader.isEndElement() && reader.getLocalName().equals("throw_exception"))) {
                reader.next();
                //<affected_participants>
                if (reader.isStartElement() && reader.getLocalName().equals("affected_participants")) {
                    affectedParticipants = reader.getElementText();
                }
            }
        } catch (XMLStreamException ex) {
            Logger.getLogger(GuardianGroupImpl.class.getName()).log(Level.SEVERE, null, ex);
        }

        return affectedParticipants;
    }

    private void applyRecoveryRulesOriginal(GlobalExceptionInterface ex) {

        String exceptionClassName;
        String targetContextName;
        Integer min_participant_joined;
        Integer max_participant_joined;

        List<GuardianMember> gmList;

        try {

            reader.reset();

            while (reader.hasNext()) {
                reader.next();
                //<rule name="" signaled_exception="">
                if (reader.isStartElement() && reader.getLocalName().equals("rule")) {
                    for (int i = 0; i < reader.getAttributeCount(); i++) {
                        //ex == signaled_exception
                        if (reader.getAttributeLocalName(i).equals("signaled_exception") &&
                                ex.getClass().getName().equals(reader.getAttributeValue(i))) {

                            while (reader.hasNext() && !(reader.isEndElement() && reader.getLocalName().equals("rule"))) {
                                reader.next();

                                //<participant match="<REG_EXP> | SIGNALER">
                                if (reader.isStartElement() && reader.getLocalName().equals("participant")) {

                                    String participant_match = reader.getAttributeValue(0).trim();

                                    while (reader.hasNext() && !(reader.isEndElement() && reader.getLocalName().equals("participant"))) {
                                        reader.next();

                                        //<throw_exception class="<Exception>" target_context="<Context>"/>
                                        if (reader.isStartElement() && reader.getLocalName().equals("throw_exception")) {

                                            exceptionClassName = null;
                                            targetContextName = null;
                                            min_participant_joined = null;
                                            max_participant_joined = null;

                                            for (int j = 0; j < reader.getAttributeCount(); j++) {
                                                if (reader.getAttributeLocalName(j).equals("class")) {
                                                    //class value
                                                    exceptionClassName = reader.getAttributeValue(j);
                                                } else if (reader.getAttributeLocalName(j).equals("target_context")) {
                                                    //target_context value
                                                    targetContextName = reader.getAttributeValue(j);
                                                } else if (reader.getAttributeLocalName(j).equals("min_participant_joined")) {
                                                    //min_participant_joined value
                                                    min_participant_joined = Integer.parseInt(reader.getAttributeValue(j));
                                                } else {
                                                    //max_participant_joined value
                                                    max_participant_joined = Integer.parseInt(reader.getAttributeValue(j));
                                                }
                                            }

                                            //Test the min and max joined participants condition
                                            if (min_participant_joined != null && max_participant_joined != null) {
                                                if (!(guardianList.size() >= min_participant_joined && guardianList.size() < max_participant_joined)) {
                                                    break;
                                                }
                                            } else if (min_participant_joined != null) {
                                                if (!(guardianList.size() >= min_participant_joined)) {
                                                    break;
                                                }
                                            } else if (max_participant_joined != null) {
                                                if (!(guardianList.size() >= min_participant_joined)) {
                                                    break;
                                                }
                                            }

                                            //match value
                                            gmList = getMatchingParticipants(participant_match, ex);

                                            String affectedParticipants = null;
                                            int index = -1;
                                            while (reader.hasNext() && !(reader.isEndElement() && reader.getLocalName().equals("throw_exception"))) {
                                                reader.next();

                                                //<affected_participants>
                                                if (reader.isStartElement() && reader.getLocalName().equals("affected_participants")) {
                                                    affectedParticipants = reader.getElementText();

                                                    //Verify if the parameter is an index
                                                    try {
                                                        index = Integer.parseInt(affectedParticipants);
                                                    } catch (NumberFormatException nexc) {
                                                        index = -1;
                                                    }
                                                }
                                            }

                                            Class exceptionClass = Class.forName(exceptionClassName);

                                            Context targetContext;
                                            if (targetContextName.toUpperCase().equals(Context.CURRENT_CONTEXT.getName().toUpperCase())) {
                                                targetContext = Context.CURRENT_CONTEXT;
                                            } else if (targetContextName.toUpperCase().equals(Context.INIT_CONTEXT.getName().toUpperCase())) {
                                                targetContext = Context.INIT_CONTEXT;
                                            } else {
                                                targetContext = new Context(targetContextName);
                                            }

                                            GlobalException newException = (GlobalException) exceptionClass.newInstance();
                                            newException.setTargetContext(targetContext);

                                            //Add the exception to the participants matched
                                            if (index != -1) {
                                                gmList.get(index).addException(newException);
                                            } else if (affectedParticipants != null && affectedParticipants.length() != 0) {
                                                if (affectedParticipants.toUpperCase().equals("FIRST")) {
                                                    gmList.get(0).addException(newException);

                                                } else if (affectedParticipants.toUpperCase().equals("LAST")) {
                                                    gmList.get(gmList.size() - 1).addException(newException);
                                                } else if (affectedParticipants.toUpperCase().equals("ALL")) {
                                                    for (GuardianMember gm : gmList) {
                                                        gm.addException(newException);
                                                    }
                                                }
                                            } else {
                                                for (GuardianMember gm : gmList) {
                                                    gm.addException(newException);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            break;
                        }
                    }
                }
            }
        } catch (XMLStreamException ex1) {
            Logger.getLogger(GuardianGroupImpl.class.getName()).log(Level.SEVERE, null, ex1);
        } catch (Exception ex1) {
            Logger.getLogger(GuardianGroupImpl.class.getName()).log(Level.SEVERE, null, ex1);
        }
    }

    private List<GuardianMember> getMatchingParticipants(String regularExpression, GlobalExceptionInterface signaledException) {
        List<GuardianMember> matchingParticipants = new LinkedList();

        if (regularExpression.toUpperCase().equals("SIGNALER")) {
            for (GuardianMember gm : guardianList) {
                if (gm.getParticipantIdentifier().equals(signaledException.getSignalingParticipant())) {
                    matchingParticipants.add(gm);
                    break;
                }
            }
        } else if (regularExpression.toUpperCase().equals("!SIGNALER")) {
            for (GuardianMember gm : guardianList) {
                if (!gm.getParticipantIdentifier().equals(signaledException.getSignalingParticipant())) {
                    matchingParticipants.add(gm);
                }
            }

        } else {
            //Create an java regular expression
            String re = createJavaRegularExpression(regularExpression);

            for (GuardianMember gm : guardianList) {
                if (gm.getParticipantIdentifier().matches(re)) {
                    matchingParticipants.add(gm);
                }
            }
        }

        return matchingParticipants;
    }

    /* Valid expressions: *, <Context>.*, <Context>, *.<Context>, *.<Context>.*, 
     *                    *.<Context>.*.<Context>.*, <REG_EXP> || <REG_EXP>
     * 
     * Invalid expressions: *.*, **,
     *
     * Not supported yet: !<Context>, !<Context> || <Context>, !(<Context> || <Context>)
     */
    private String createJavaRegularExpression(String regularExpression) throws InvalidRegularExpression {
        StringBuffer re = new StringBuffer();

        String[] splitedByBar = regularExpression.split("\\|\\|");
        String[] splitedByPeriod;

        for (int i = 0; i < splitedByBar.length; i++) {

            splitedByPeriod = splitedByBar[i].split("\\.");

            if (i > 0) {
                re.append("|");
            }

            re.append("^");
            for (int j = 0; j < splitedByPeriod.length; j++) {

                //*
                if (splitedByPeriod[j].equals("*")) {

                    //Validate the regular expression
                    if (j + 1 != splitedByPeriod.length && splitedByPeriod[j + 1].equals("*")) {
                        throw new InvalidRegularExpression();
                    }

                    //*
                    if (splitedByPeriod.length == 1) {
                        re.append("(\\w+)");
                    } //*.<CONTEXT>

                    if (j == 0 && splitedByPeriod.length != 1) {
                        re.append("(\\w+\\");
                        re.append(".)*");
                    } //<CONTEXT>.*
                    else {
                        re.append("(\\");
                        re.append(".\\w+)*");
                    }
                } //<CONTEXT>
                else {

//                    //Validate the regular expression
//                    if (splitedByPeriod[j].matches("^(\\*)*$")) {
//                        throw new RuntimeException("Invalid name for a context");
//                    }

                    //<CONTEXT> || <CONTEXT>.<CONTEXT>.<CONTEXT> || *.<CONTEXT>
                    if (splitedByPeriod.length == 1) {
                        re.append("(\\w+\\");
                        re.append(".)*");
                    }

                    if (j == 0 || j - 1 == 0) {
                        re.append("(" + splitedByPeriod[j] + ")");
                    } else {
                        re.append("(\\." + splitedByPeriod[j] + ")");
                    }
                }
            }
            re.append("$");
        }
        return re.toString();
    }

    public boolean propagate(GlobalExceptionInterface ex) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void checkExceptionStatus() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public boolean removeGuardianMember(GuardianMember guardianMember) {
        return this.guardianList.remove(guardianMember);
    }
}