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.graph.component;
18 import org.wamblee.system.graph.Edge;
19 import org.wamblee.system.graph.EdgeFilter;
23 * Filter used to explicitly connect required and provided interfaces
26 * @author Erik Brakkee
28 public class ConnectRequiredProvidedEdgeFilter implements EdgeFilter {
32 private String client;
37 private String required;
42 private String server;
47 private String provided;
50 * Creates a new ConnectRequiredProvidedEdgeFilter object.
52 * @param aClient DOCUMENT ME!
53 * @param aRequired DOCUMENT ME!
54 * @param aServer DOCUMENT ME!
55 * @param aProvided DOCUMENT ME!
57 public ConnectRequiredProvidedEdgeFilter(String aClient, String aRequired,
58 String aServer, String aProvided) {
65 throw new IllegalArgumentException(
66 "Client component must be specified");
73 * @param aEdge DOCUMENT ME!
75 * @return DOCUMENT ME!
78 public boolean isViolated(Edge aEdge) {
79 if (aEdge.getFrom() instanceof RequiredInterfaceNode
80 && aEdge.getTo() instanceof ProvidedInterfaceNode) {
81 return isViolated((RequiredInterfaceNode) aEdge.getFrom(),
82 (ProvidedInterfaceNode) aEdge.getTo());
91 * @param aFrom DOCUMENT ME!
92 * @param aTo DOCUMENT ME!
94 * @return DOCUMENT ME!
96 private boolean isViolated(RequiredInterfaceNode aFrom,
97 ProvidedInterfaceNode aTo) {
98 if (client.equals(aFrom.getComponent().getName())
99 && ((required == null)
100 || required.equals(aFrom.getRequired().getName()))) {
101 // From part matches.
102 if (server == null) {
103 return true; // all connections are eliminated
106 if (server.equals(aTo.getComponent().getName())
107 && ((provided == null)
108 || provided.equals(aTo.getProvided().getName()))) {
109 // to part matches also
112 // From matches and to doesn't so edgefilter is violated.
116 // From part does not match, restriction does not apply.