2 * Copyright 2008 the original author or authors.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.wamblee.system.container;
18 import org.wamblee.system.core.Component;
19 import org.wamblee.system.core.ProvidedInterface;
20 import org.wamblee.system.core.RequiredInterface;
23 * An interface restriction on the required interface of a component.
25 * @author Erik Brakkee
28 public class DefaultInterfaceRestriction implements InterfaceRestriction {
30 private String _client;
31 private String _required;
32 private String _server;
33 private String _provided;
36 * Constructs the restriction. If the client name and required interface
37 * name match, then the server name and interface name must also match.
38 * Otherwise the restriction is violated.
40 * This can be used to explicitly connect required and provided interfaces
44 * Client or null if no restriction on the client.
46 * Required interface name or null if no restriction on the
49 * Server or null if no restriction on the server.
51 * Provided interface name or null if no restriction on the
54 public DefaultInterfaceRestriction(String aClient, String aRequired,
55 String aServer, String aProvided) {
57 if ( aClient == null && aRequired == null ) {
58 throw new IllegalArgumentException("No restriction on the required interface");
60 if ( aServer == null && aProvided == null ) {
61 throw new IllegalArgumentException("No restriction on the provided interface");
64 _required = aRequired;
66 _provided = aProvided;
70 public boolean isViolated(Component aClient, RequiredInterface aRequired,
71 Component aServer, ProvidedInterface aProvided) {
73 if ( _client != null && !aClient.getName().equals(_client)) {
76 if ( _required != null && !aRequired.getName().equals(_required)) {
80 // The required interface matches
82 if ( _server != null && !aServer.getName().equals(_server)) {
83 // Server was specified and does not match.
86 if ( _provided != null && !aProvided.getName().equals(_provided)) {
87 // provided interface was specified and doe not match.
91 // The required and provided interfaces match so this is not a violation.