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.core;
19 * An interface restriction on the required interface of a component.
21 * @author Erik Brakkee
24 public class DefaultInterfaceRestriction implements InterfaceRestriction {
26 private String _client;
27 private String _required;
28 private String _server;
29 private String _provided;
32 * Constructs the restriction. If the client name and required interface
33 * name match, then the server name and interface name must also match.
34 * Otherwise the restriction is violated.
36 * This can be used to explicitly connect required and provided interfaces
40 * Client or null if no restriction on the client.
42 * Required interface name or null if no restriction on the
45 * Server or null if no restriction on the server.
47 * Provided interface name or null if no restriction on the
50 public DefaultInterfaceRestriction(String aClient, String aRequired,
51 String aServer, String aProvided) {
53 if ( aClient == null && aRequired == null ) {
54 throw new IllegalArgumentException("No restriction on the required interface");
56 if ( aServer == null && aProvided == null ) {
57 throw new IllegalArgumentException("No restriction on the provided interface");
60 _required = aRequired;
62 _provided = aProvided;
66 public boolean isViolated(Component aClient, RequiredInterface aRequired,
67 Component aServer, ProvidedInterface aProvided) {
69 if ( _client != null && !aClient.getName().equals(_client)) {
72 if ( _required != null && !aRequired.getName().equals(_required)) {
76 // The required interface matches
78 if ( _server != null && !aServer.getName().equals(_server)) {
79 // Server was specified and does not match.
82 if ( _provided != null && !aProvided.getName().equals(_provided)) {
83 // provided interface was specified and doe not match.
87 // The required and provided interfaces match so this is not a violation.