/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.tuscany.core.wire; import java.net.URI; import java.util.Collections; import java.util.HashMap; import java.util.Map; import javax.xml.namespace.QName; import org.apache.tuscany.spi.component.AtomicComponent; import org.apache.tuscany.spi.component.TargetResolutionException; import org.apache.tuscany.spi.model.Operation; import org.apache.tuscany.spi.model.ServiceContract; import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition; import org.apache.tuscany.spi.wire.InvocationChain; import org.apache.tuscany.spi.wire.Wire; /** * Default implementation of a Wire * * @version $Rev$ $Date$ */ public class WireImpl implements Wire { private URI sourceUri; private URI targetUri; private QName bindingType; private ServiceContract sourceContract; private ServiceContract targetContract; private boolean optimizable; private Map, InvocationChain> chains = new HashMap, InvocationChain>(); private Map, InvocationChain> callbackChains = new HashMap, InvocationChain>(); private Map pChains = new HashMap(); private Map pCallbackChains = new HashMap(); private AtomicComponent target; /** * Creates a wire with a local binding */ public WireImpl() { } /** * Creates a wire with the given binding type * * @param bindingType the binding type */ public WireImpl(QName bindingType) { this.bindingType = bindingType; } public URI getSourceUri() { return sourceUri; } public void setSourceUri(URI sourceUri) { this.sourceUri = sourceUri; } public URI getTargetUri() { return targetUri; } public void setTargetUri(URI targetUri) { this.targetUri = targetUri; } public QName getBindingType() { return bindingType; } public ServiceContract getSourceContract() { return sourceContract; } public void setSourceContract(ServiceContract contract) { this.sourceContract = contract; } public ServiceContract getTargetContract() { return targetContract; } public void setTargetContract(ServiceContract contract) { this.targetContract = contract; } public boolean isOptimizable() { return optimizable; } public void setOptimizable(boolean optimizable) { this.optimizable = optimizable; } public Object getTargetInstance() throws TargetResolutionException { if (target == null) { return null; } return target.getTargetInstance(); } public void setTarget(AtomicComponent target) { this.target = target; } public Map, InvocationChain> getInvocationChains() { return Collections.unmodifiableMap(chains); } public void addInvocationChain(Operation operation, InvocationChain chain) { chains.put(operation, chain); } public void addInvocationChain(PhysicalOperationDefinition operation, InvocationChain chain) { pChains.put(operation, chain); } public Map getPhysicalInvocationChains() { return Collections.unmodifiableMap(pChains); } public Map, InvocationChain> getCallbackInvocationChains() { return Collections.unmodifiableMap(callbackChains); } public void addCallbackInvocationChain(Operation operation, InvocationChain chain) { callbackChains.put(operation, chain); } public Map getCallbackPhysicalInvocationChains() { return Collections.unmodifiableMap(pCallbackChains); } public void addCallbackInvocationChain(PhysicalOperationDefinition operation, InvocationChain chain) { pCallbackChains.put(operation, chain); } }