Added basic graph functionality as a first step towards simplifying the container...
[utils] / system / general / src / main / java / org / wamblee / system / core / CompositeInterfaceRestriction.java
1 /*
2  * Copyright 2008 the original author or authors.
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  * 
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  * 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */ 
16 package org.wamblee.system.core;
17
18 import java.util.ArrayList;
19 import java.util.Collection;
20 import java.util.List;
21
22
23 /**
24  * Composite restriction that wraps a number of other restrictions. The restriction is 
25  * violated if one of the contained restrictions is violated. 
26  * 
27  * @author Erik Brakkee
28  *
29  */
30 public class CompositeInterfaceRestriction implements InterfaceRestriction {
31     
32     private List<InterfaceRestriction> _restrictions; 
33     
34     /**
35      * Constructs the restriction. 
36      */
37     public CompositeInterfaceRestriction() { 
38         _restrictions = new ArrayList<InterfaceRestriction>();
39     }
40     
41     /**
42      * Constructs the restriction. 
43      * @param aRestrictions List of contained restrictions. 
44      */
45     public CompositeInterfaceRestriction(Collection<InterfaceRestriction> aRestrictions) { 
46         this(); 
47         _restrictions.addAll(aRestrictions);
48     }
49     
50     /**
51      * Adds a restriction. 
52      * @param aRestriction Restriction. 
53      * @return Reference to this composite restriction to allow call chaining. 
54      */
55     public CompositeInterfaceRestriction add(InterfaceRestriction aRestriction) { 
56         _restrictions.add(aRestriction);
57         return this; 
58     }
59
60     @Override
61     public boolean isViolated(Component aClient, RequiredInterface aRequired,
62             Component aServer, ProvidedInterface aProvided) {
63         for (InterfaceRestriction restriction: _restrictions) { 
64             if ( restriction.isViolated(aClient, aRequired, aServer, aProvided)) { 
65                 return true; 
66             }
67         }
68         return false; 
69     }
70
71 }