--- /dev/null
+/*
+ * Copyright 2008 the original author or authors.
+ *
+ * Licensed 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.wamblee.system.graph.component;
+
+import org.wamblee.system.graph.Edge;
+import org.wamblee.system.graph.EdgeFilter;
+import org.wamblee.system.graph.EdgeSelector;
+import org.wamblee.system.graph.Node;
+
+/**
+ * Filter used to explicitly connect required and provided interfaces within a
+ * container.
+ *
+ * @author Erik Brakkee
+ *
+ */
+public class ConnectExternalProvidedProvidedFilter implements EdgeFilter {
+
+ private String _externalProvided;
+ private String _component;
+ private String _provided;
+
+ public ConnectExternalProvidedProvidedFilter(String aExternalProvided, String aComponent,
+ String aProvided) {
+ _externalProvided = aExternalProvided;
+ _component = aComponent;
+ _provided = aProvided;
+ if ( _externalProvided == null ) {
+ throw new IllegalArgumentException("External provided interface name must be specified.");
+ }
+ if ( _component == null ) {
+ throw new IllegalArgumentException("Component name must be specified");
+ }
+ if ( _provided == null ) {
+ throw new IllegalArgumentException("Provided interface name of internal component must be specified");
+ }
+ }
+
+ @Override
+ public boolean isViolated(Edge aEdge) {
+ if (aEdge.getFrom() instanceof ExternalProvidedInterfaceNode
+ && aEdge.getTo() instanceof ProvidedInterfaceNode) {
+ return isViolated((ExternalProvidedInterfaceNode) aEdge.getFrom(),
+ (ProvidedInterfaceNode) aEdge.getTo());
+ }
+ return false;
+ }
+
+ private boolean isViolated(ExternalProvidedInterfaceNode aFrom,
+ ProvidedInterfaceNode aTo) {
+ if ( !aFrom.getName().equals(_externalProvided)) {
+ return false; // wrong provided interface.
+ }
+ if ( aTo.getComponent().getName().equals(_component) &&
+ aTo.getProvided().getName().equals(_provided) ) {
+ return false; // ok
+ }
+ return true;
+ }
+}