diff options
Diffstat (limited to 'sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder')
16 files changed, 1124 insertions, 0 deletions
diff --git a/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder/BuilderRegistryImpl.java b/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder/BuilderRegistryImpl.java new file mode 100644 index 0000000000..33dd2175f9 --- /dev/null +++ b/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder/BuilderRegistryImpl.java @@ -0,0 +1,185 @@ +/* + * 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.builder; + +import java.net.URI; +import java.util.HashMap; +import java.util.Map; + +import org.osoa.sca.annotations.EagerInit; + +import org.apache.tuscany.spi.builder.BindingBuilder; +import org.apache.tuscany.spi.builder.BuilderException; +import org.apache.tuscany.spi.builder.BuilderRegistry; +import org.apache.tuscany.spi.builder.ComponentBuilder; +import org.apache.tuscany.spi.builder.ScopeNotFoundException; +import org.apache.tuscany.spi.component.Component; +import org.apache.tuscany.spi.component.Reference; +import org.apache.tuscany.spi.component.ReferenceBinding; +import org.apache.tuscany.spi.component.ScopeContainer; +import org.apache.tuscany.spi.component.ScopeRegistry; +import org.apache.tuscany.spi.component.Service; +import org.apache.tuscany.spi.component.ServiceBinding; +import org.apache.tuscany.spi.deployer.DeploymentContext; +import org.apache.tuscany.spi.model.BindingDefinition; +import org.apache.tuscany.spi.model.ComponentDefinition; +import org.apache.tuscany.spi.model.ComponentType; +import org.apache.tuscany.spi.model.Implementation; +import org.apache.tuscany.spi.model.ReferenceDefinition; +import org.apache.tuscany.spi.model.Scope; +import org.apache.tuscany.spi.model.ServiceContract; +import org.apache.tuscany.spi.model.ServiceDefinition; + +import org.apache.tuscany.core.binding.local.LocalBindingDefinition; +import org.apache.tuscany.core.implementation.composite.ReferenceImpl; +import org.apache.tuscany.core.implementation.composite.ServiceImpl; + +/** + * The default builder registry in the runtime + * + * @version $Rev$ $Date$ + */ +@EagerInit +public class BuilderRegistryImpl implements BuilderRegistry { + private ScopeRegistry scopeRegistry; + + private final Map<Class<? extends Implementation<?>>, ComponentBuilder<? extends Implementation<?>>> componentBuilders = + new HashMap<Class<? extends Implementation<?>>, ComponentBuilder<? extends Implementation<?>>>(); + private final Map<Class<? extends BindingDefinition>, BindingBuilder<? extends BindingDefinition>> bindingBuilders = + new HashMap<Class<? extends BindingDefinition>, BindingBuilder<? extends BindingDefinition>>(); + + public BuilderRegistryImpl(@org.osoa.sca.annotations.Reference ScopeRegistry scopeRegistry) { + this.scopeRegistry = scopeRegistry; + } + + public <I extends Implementation<?>> void register(Class<I> implClass, ComponentBuilder<I> builder) { + componentBuilders.put(implClass, builder); + } + + public <I extends Implementation<?>> void unregister(Class<I> implClass) { + componentBuilders.remove(implClass); + } + + public <B extends BindingDefinition> void register(Class<B> implClass, BindingBuilder<B> builder) { + bindingBuilders.put(implClass, builder); + } + + @SuppressWarnings("unchecked") + public <I extends Implementation<?>> Component build( + ComponentDefinition<I> componentDefinition, + DeploymentContext context) throws BuilderException { + Class<?> implClass = componentDefinition.getImplementation().getClass(); + // noinspection SuspiciousMethodCalls + ComponentBuilder<I> componentBuilder = (ComponentBuilder<I>) componentBuilders.get(implClass); + if (componentBuilder == null) { + String name = implClass.getName(); + throw new NoRegisteredBuilderException("No builder registered for implementation", name); + } + Component component = componentBuilder.build(componentDefinition, context); + assert component != null; + component.setDefaultPropertyValues(componentDefinition.getPropertyValues()); + Scope scope = componentDefinition.getImplementation().getComponentType().getImplementationScope(); + if (scope == Scope.SYSTEM || scope == Scope.COMPOSITE) { + component.setScopeContainer(context.getCompositeScope()); + } else { + // Check for conversational contract if conversational scope + if (scope == Scope.CONVERSATION) { + boolean hasConversationalContract = false; + ComponentType<ServiceDefinition, ReferenceDefinition, ?> componentType = + componentDefinition.getImplementation().getComponentType(); + Map<String, ServiceDefinition> services = componentType.getServices(); + for (ServiceDefinition serviceDef : services.values()) { + ServiceContract<?> contract = serviceDef.getServiceContract(); + if (contract.isConversational()) { + hasConversationalContract = true; + break; + } + } + if (!hasConversationalContract) { + String name = implClass.getName(); + throw new NoConversationalContractException( + "No conversational contract for conversational implementation", name); + } + } + // Now it's ok to set the scope container + ScopeContainer scopeContainer = scopeRegistry.getScopeContainer(scope); + if (scopeContainer == null) { + throw new ScopeNotFoundException(scope.toString()); + } + component.setScopeContainer(scopeContainer); + } + context.getComponents().put(component.getUri(), component); + ComponentType<?, ?, ?> componentType = componentDefinition.getImplementation().getComponentType(); + assert componentType != null : "Component type must be set"; + return component; + } + + @SuppressWarnings({"unchecked"}) + public Service build(ServiceDefinition serviceDefinition, DeploymentContext context) throws BuilderException { + URI uri = serviceDefinition.getUri(); + ServiceContract<?> serviceContract = serviceDefinition.getServiceContract(); + if (serviceDefinition.getBindings().isEmpty()) { + // if no bindings are configured, default to the local binding. + // this should be changed to allow runtime selection + if (serviceDefinition.getBindings().isEmpty()) { + // TODO JFM implement capability for the runtime to choose a binding + serviceDefinition.addBinding(new LocalBindingDefinition()); + } + } + URI targetUri = serviceDefinition.getTarget(); + Service service = new ServiceImpl(uri, serviceContract, targetUri); + for (BindingDefinition definition : serviceDefinition.getBindings()) { + Class<?> bindingClass = definition.getClass(); + // noinspection SuspiciousMethodCalls + BindingBuilder bindingBuilder = bindingBuilders.get(bindingClass); + if (bindingBuilder == null) { + throw new NoRegisteredBuilderException("No builder registered for type", bindingClass.getName()); + } + ServiceBinding binding = bindingBuilder.build(serviceDefinition, definition, context); + service.addServiceBinding(binding); + } + return service; + } + + @SuppressWarnings("unchecked") + public Reference build(ReferenceDefinition referenceDefinition, DeploymentContext context) throws BuilderException { + URI uri = referenceDefinition.getUri(); + ServiceContract<?> contract = referenceDefinition.getServiceContract(); + if (referenceDefinition.getBindings().isEmpty()) { + // if no bindings are configured, default to the local binding. + // this should be changed to allow runtime selection + if (referenceDefinition.getBindings().isEmpty()) { + // TODO JFM implement capability for the runtime to choose a binding + referenceDefinition.addBinding(new LocalBindingDefinition()); + } + } + + Reference reference = new ReferenceImpl(uri, contract); + for (BindingDefinition bindingDefinition : referenceDefinition.getBindings()) { + Class<?> bindingClass = bindingDefinition.getClass(); + // noinspection SuspiciousMethodCalls + BindingBuilder bindingBuilder = bindingBuilders.get(bindingClass); + ReferenceBinding binding = bindingBuilder.build(referenceDefinition, bindingDefinition, context); + reference.addReferenceBinding(binding); + + } + return reference; + } + +} diff --git a/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder/ComponentNotFoundException.java b/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder/ComponentNotFoundException.java new file mode 100644 index 0000000000..a46e038cb9 --- /dev/null +++ b/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder/ComponentNotFoundException.java @@ -0,0 +1,36 @@ +/* + * 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.builder; + +import java.net.URI; + +import org.apache.tuscany.spi.builder.WiringException; + +/** + * Indicates a component was not found during wiring + * + * @version $Rev$ $Date$ + */ +public class ComponentNotFoundException extends WiringException { + + public ComponentNotFoundException(String message, URI name) { + super(message, name, name); + } + +} diff --git a/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder/ConnectorImpl.java b/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder/ConnectorImpl.java new file mode 100644 index 0000000000..6923fb6837 --- /dev/null +++ b/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder/ConnectorImpl.java @@ -0,0 +1,385 @@ +/* + * 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.builder; + +import java.net.URI; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import javax.xml.namespace.QName; + +import org.osoa.sca.annotations.Constructor; + +import org.apache.tuscany.spi.builder.BuilderException; +import org.apache.tuscany.spi.builder.Connector; +import org.apache.tuscany.spi.builder.WiringException; +import org.apache.tuscany.spi.builder.interceptor.InterceptorBuilderRegistry; +import org.apache.tuscany.spi.builder.physical.WireAttacherRegistry; +import org.apache.tuscany.spi.component.AtomicComponent; +import org.apache.tuscany.spi.component.Component; +import org.apache.tuscany.spi.component.ComponentManager; +import org.apache.tuscany.spi.component.Invocable; +import org.apache.tuscany.spi.component.Reference; +import org.apache.tuscany.spi.component.ReferenceBinding; +import org.apache.tuscany.spi.component.Service; +import org.apache.tuscany.spi.component.ServiceBinding; +import org.apache.tuscany.spi.component.TargetInvokerCreationException; +import org.apache.tuscany.spi.component.WorkContext; +import org.apache.tuscany.spi.model.ComponentDefinition; +import org.apache.tuscany.spi.model.ComponentType; +import org.apache.tuscany.spi.model.CompositeComponentType; +import org.apache.tuscany.spi.model.Implementation; +import org.apache.tuscany.spi.model.Operation; +import org.apache.tuscany.spi.model.ReferenceDefinition; +import org.apache.tuscany.spi.model.ReferenceTarget; +import org.apache.tuscany.spi.model.Scope; +import org.apache.tuscany.spi.model.ServiceContract; +import org.apache.tuscany.spi.model.ServiceDefinition; +import org.apache.tuscany.spi.model.physical.PhysicalInterceptorDefinition; +import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition; +import org.apache.tuscany.spi.model.physical.PhysicalWireDefinition; +import org.apache.tuscany.spi.model.physical.PhysicalWireSourceDefinition; +import org.apache.tuscany.spi.model.physical.PhysicalWireTargetDefinition; +import org.apache.tuscany.spi.services.work.WorkScheduler; +import org.apache.tuscany.spi.util.UriHelper; +import org.apache.tuscany.spi.wire.Interceptor; +import org.apache.tuscany.spi.wire.InvocationChain; +import org.apache.tuscany.spi.wire.Wire; +import org.apache.tuscany.spi.wire.WirePostProcessorRegistry; + +import org.apache.tuscany.core.wire.InvocationChainImpl; +import org.apache.tuscany.core.wire.InvokerInterceptor; +import org.apache.tuscany.core.wire.NonBlockingInterceptor; +import org.apache.tuscany.core.wire.WireImpl; +import org.apache.tuscany.core.wire.WireUtils; + +/** + * The default connector implmentation + * + * @version $$Rev$$ $$Date$$ + */ +public class ConnectorImpl implements Connector { + private WirePostProcessorRegistry postProcessorRegistry; + private ComponentManager componentManager; + private WorkContext workContext; + private WorkScheduler scheduler; + private InterceptorBuilderRegistry interceptorBuilderRegistry; + private WireAttacherRegistry attacherRegistry; + + public ConnectorImpl(ComponentManager componentManager) { + this.componentManager = componentManager; + } + + @Constructor + public ConnectorImpl( + @org.osoa.sca.annotations.Reference InterceptorBuilderRegistry interceptorBuilderRegistry, + @org.osoa.sca.annotations.Reference WireAttacherRegistry attacherRegistry, + @org.osoa.sca.annotations.Reference WirePostProcessorRegistry processorRegistry, + @org.osoa.sca.annotations.Reference ComponentManager componentManager, + @org.osoa.sca.annotations.Reference WorkScheduler scheduler, + @org.osoa.sca.annotations.Reference WorkContext workContext) { + this.attacherRegistry = attacherRegistry; + this.interceptorBuilderRegistry = interceptorBuilderRegistry; + this.postProcessorRegistry = processorRegistry; + this.componentManager = componentManager; + this.scheduler = scheduler; + this.workContext = workContext; + } + + /** + * <strong>Note this method will not work yet</strong> + * <p/> + * Wires a source and target component based on a wire defintion + * + * @param definition the wire definition + * @throws WiringException + */ + public void connect(PhysicalWireDefinition definition) throws BuilderException { + URI sourceUri = definition.getSourceUri(); + assert sourceUri != null; + URI targetUri = definition.getTargetUri(); + assert targetUri != null; + URI baseSourceUri = UriHelper.getDefragmentedName(sourceUri); + URI baseTargetUri = UriHelper.getDefragmentedName(targetUri); + Component source = componentManager.getComponent(baseSourceUri); + if (source == null) { + throw new ComponentNotFoundException("Wire source component not found", baseSourceUri); + } + Wire wire = createWire(definition); + + PhysicalWireSourceDefinition sourceDefinition = definition.getSource(); + PhysicalWireTargetDefinition targetDefinition = definition.getTarget(); + Component target; + if (baseTargetUri != null) { + target = componentManager.getComponent(baseTargetUri); + if (target == null) { + throw new ComponentNotFoundException("Wire target component not found", baseTargetUri); + } + } else { + target = null; + } + attacherRegistry.attachToSource(source, sourceDefinition, target, targetDefinition, wire); + attacherRegistry.attachToTarget(source, sourceDefinition, target, targetDefinition, wire); + } + + public void connect(ComponentDefinition<? extends Implementation<?>> definition) throws WiringException { + URI sourceUri = definition.getUri(); + Component source = componentManager.getComponent(sourceUri); + if (source == null) { + throw new ComponentNotFoundException("Source not found", sourceUri); + } + ComponentType<?, ?, ?> type = definition.getImplementation().getComponentType(); + if (type instanceof CompositeComponentType) { + CompositeComponentType<?, ?, ?> compositeType = (CompositeComponentType<?, ?, ?>) type; + for (ComponentDefinition<? extends Implementation<?>> child : compositeType.getComponents().values()) { + connect(child); + } + for (ServiceDefinition child : compositeType.getServices().values()) { + connect(child); + } + for (ReferenceDefinition child : compositeType.getReferences().values()) { + connect(child); + } + } + Map<String, ReferenceTarget> targets = definition.getReferenceTargets(); + for (ReferenceTarget referenceTarget : targets.values()) { + List<Wire> wires = new ArrayList<Wire>(); + String refName = referenceTarget.getReferenceName().getFragment(); + ReferenceDefinition refDefinition = type.getReferences().get(refName); + assert refDefinition != null; + List<URI> uris = referenceTarget.getTargets(); + for (URI uri : uris) { + URI targetUri = UriHelper.getDefragmentedName(uri); + Component target = componentManager.getComponent(targetUri); + if (target == null && !refDefinition.isRequired()) { + // a non-required reference, just skip + continue; + } + if (target == null) { + throw new ComponentNotFoundException("Target not found", targetUri); + } + String fragment = uri.getFragment(); + URI sourceURI = refDefinition.getUri(); + Wire wire = createWire(sourceURI, uri, refDefinition.getServiceContract(), Wire.LOCAL_BINDING); + try { + attachInvokers(fragment, wire, source, target); + } catch (TargetInvokerCreationException e) { + throw new WireCreationException("Error creating invoker", sourceUri, targetUri, e); + } + if (postProcessorRegistry != null) { + postProcessorRegistry.process(wire); + } + optimize(source, target, wire); + wires.add(wire); + if (!wire.getCallbackInvocationChains().isEmpty()) { + target.attachCallbackWire(wire); + } + } + if (wires.size() > 1) { + // attach as a multiplicity + source.attachWires(wires); + } else if (wires.size() == 1) { + // attach as a single wire + Wire wire = wires.get(0); + source.attachWire(wire); + } + } + } + + /** + * @deprecated + */ + protected void connect(ServiceDefinition definition) throws WiringException { + URI uri = definition.getUri(); + URI sourceUri = UriHelper.getDefragmentedName(uri); + URI targetUri = definition.getTarget(); + URI baseTargetUri = UriHelper.getDefragmentedName(targetUri); + Component source = componentManager.getComponent(sourceUri); + if (source == null) { + throw new ComponentNotFoundException("Source not found", sourceUri); + } + Service service = source.getService(uri.getFragment()); + if (service == null) { + throw new SourceServiceNotFoundException("Service not found on composite", uri); + } + Component target = componentManager.getComponent(baseTargetUri); + if (target == null) { + throw new ComponentNotFoundException("Target not found", sourceUri); + } + ServiceContract<?> contract = definition.getServiceContract(); + // TODO if no binding, do local + for (ServiceBinding binding : service.getServiceBindings()) { + Wire wire = createWire(uri, targetUri, contract, binding.getBindingType()); + binding.setWire(wire); + if (postProcessorRegistry != null) { + postProcessorRegistry.process(wire); + } + try { + attachInvokers(definition.getTarget().getFragment(), wire, binding, target); + } catch (TargetInvokerCreationException e) { + throw new WireCreationException("Error creating invoker", sourceUri, baseTargetUri, e); + } + } + } + + /** + * @deprecated + */ + protected void connect(ReferenceDefinition definition) throws WiringException { + URI uri = definition.getUri(); + URI sourceUri = UriHelper.getDefragmentedName(uri); + Component source = componentManager.getComponent(sourceUri); + if (source == null) { + throw new ComponentNotFoundException("Source not found", sourceUri); + } + Reference reference = source.getReference(uri.getFragment()); + if (reference == null) { + throw new SourceServiceNotFoundException("Reference not found on composite", uri); + } + + for (ReferenceBinding binding : reference.getReferenceBindings()) { + // create wire + if (Wire.LOCAL_BINDING.equals(binding.getBindingType())) { + URI targetUri = binding.getTargetUri(); + ServiceContract<?> contract = binding.getBindingServiceContract(); + QName type = binding.getBindingType(); + Wire wire = createWire(sourceUri, targetUri, contract, type); + binding.setWire(wire); + // wire local bindings to their targets + Component target = componentManager.getComponent(UriHelper.getDefragmentedName(targetUri)); + if (target == null) { + throw new ComponentNotFoundException("Target not found", sourceUri); + } + try { + attachInvokers(targetUri.getFragment(), wire, binding, target); + } catch (TargetInvokerCreationException e) { + throw new WireCreationException("Error creating invoker", sourceUri, targetUri, e); + } + } else { + Wire wire = createWire(sourceUri, null, binding.getBindingServiceContract(), binding.getBindingType()); + if (postProcessorRegistry != null) { + postProcessorRegistry.process(wire); + } + binding.setWire(wire); + } + } + } + + protected Wire createWire(PhysicalWireDefinition definition) throws BuilderException { + URI sourceURI = definition.getSourceUri(); + URI targetUri = definition.getTargetUri(); + Wire wire = new WireImpl(); + wire.setSourceUri(sourceURI); + wire.setTargetUri(targetUri); + for (PhysicalOperationDefinition operation : definition.getOperations()) { + InvocationChain chain = new InvocationChainImpl(operation); + for (PhysicalInterceptorDefinition interceptorDefinition : operation.getInterceptors()) { + Interceptor interceptor = interceptorBuilderRegistry.build(interceptorDefinition); + chain.addInterceptor(interceptor); + } + wire.addInvocationChain(operation, chain); + } + return wire; + } + + protected Wire createWire(URI sourceURI, URI targetUri, ServiceContract<?> contract, QName bindingType) { + Wire wire = new WireImpl(bindingType); + wire.setSourceContract(contract); + wire.setTargetContract(contract); + wire.setSourceUri(sourceURI); + wire.setTargetUri(targetUri); + for (Operation<?> operation : contract.getOperations().values()) { + InvocationChain chain = new InvocationChainImpl(operation); + if (operation.isNonBlocking()) { + chain.addInterceptor(new NonBlockingInterceptor(scheduler, workContext)); + } + chain.addInterceptor(new InvokerInterceptor()); + wire.addInvocationChain(operation, chain); + + } + for (Operation<?> operation : contract.getCallbackOperations().values()) { + InvocationChain chain = new InvocationChainImpl(operation); + if (operation.isNonBlocking()) { + chain.addInterceptor(new NonBlockingInterceptor(scheduler, workContext)); + } + chain.addInterceptor(new InvokerInterceptor()); + wire.addCallbackInvocationChain(operation, chain); + } + return wire; + } + + /** + * @Deprecated + */ + private void attachInvokers(String name, Wire wire, Invocable source, Invocable target) + throws TargetInvokerCreationException { + // TODO section will deleted be replaced when we cut-over to the physical marshallers + for (InvocationChain chain : wire.getInvocationChains().values()) { + chain.setTargetInvoker(target.createTargetInvoker(name, chain.getOperation())); + } + for (InvocationChain chain : wire.getCallbackInvocationChains().values()) { + chain.setTargetInvoker(source.createTargetInvoker(null, chain.getOperation())); + } + } + + /** + * @Deprecated + */ + protected void optimize(Component source, Component target, Wire wire) { + boolean optimizableScopes = isOptimizable(source.getScope(), target.getScope()); + if (optimizableScopes && target.isOptimizable() && WireUtils.isOptimizable(wire)) { + wire.setOptimizable(true); + wire.setTarget((AtomicComponent) target); + } else { + wire.setOptimizable(false); + } + } + + protected boolean isOptimizable(Scope pReferrer, Scope pReferee) { + if (pReferrer == Scope.UNDEFINED + || pReferee == Scope.UNDEFINED + || pReferrer == Scope.CONVERSATION + || pReferee == Scope.CONVERSATION) { + return false; + } + if (pReferee == pReferrer) { + return true; + } else if (pReferrer == Scope.STATELESS) { + return true; + } else if (pReferee == Scope.STATELESS) { + return false; + } else if (pReferrer == Scope.REQUEST && pReferee == Scope.SESSION) { + return true; + } else if (pReferrer == Scope.REQUEST && pReferee == Scope.COMPOSITE) { + return true; + } else if (pReferrer == Scope.REQUEST && pReferee == Scope.SYSTEM) { + return true; + } else if (pReferrer == Scope.SESSION && pReferee == Scope.COMPOSITE) { + return true; + } else if (pReferrer == Scope.SESSION && pReferee == Scope.SYSTEM) { + return true; + } else //noinspection SimplifiableIfStatement + if (pReferrer == Scope.SYSTEM && pReferee == Scope.COMPOSITE) { + // case where a service context points to a composite scoped component + return true; + } else { + return pReferrer == Scope.COMPOSITE && pReferee == Scope.SYSTEM; + } + } +}
\ No newline at end of file diff --git a/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder/IllegalCallbackException.java b/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder/IllegalCallbackException.java new file mode 100644 index 0000000000..183ccea1b8 --- /dev/null +++ b/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder/IllegalCallbackException.java @@ -0,0 +1,36 @@ +/* + * 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.builder; + +import java.net.URI; + +import org.apache.tuscany.spi.builder.WiringException; + +/** + * Denotes an illegal callback + * + * @version $Rev$ $Date$ + */ +public class IllegalCallbackException extends WiringException { + + public IllegalCallbackException(String message, String identifier, URI sourceUri, URI targetUri) { + super(message, identifier, sourceUri, targetUri); + } + +} diff --git a/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder/IncompatibleInterfacesException.java b/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder/IncompatibleInterfacesException.java new file mode 100644 index 0000000000..1a9c74aa3b --- /dev/null +++ b/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder/IncompatibleInterfacesException.java @@ -0,0 +1,40 @@ +/* + * 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.builder; + +import java.net.URI; + +import org.apache.tuscany.spi.builder.WiringException; + +/** + * Denotes an attempt to wire incompatible interfaces + * + * @version $Rev$ $Date$ + */ +public class IncompatibleInterfacesException extends WiringException { + + public IncompatibleInterfacesException(URI source, URI target) { + super("Incompatible source and target interfaces", source, target); + } + + public IncompatibleInterfacesException(URI source, URI target, Throwable throwable) { + super("Incompatible source and target interfaces", source, target, throwable); + } + +} diff --git a/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder/InvalidSourceTypeException.java b/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder/InvalidSourceTypeException.java new file mode 100644 index 0000000000..d9df445530 --- /dev/null +++ b/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder/InvalidSourceTypeException.java @@ -0,0 +1,35 @@ +/* + * 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.builder; + +import java.net.URI; + +import org.apache.tuscany.spi.builder.WiringException; + +/** + * Denotes an invalid source type for a wire + * + * @version $Rev$ $Date$ + */ +public class InvalidSourceTypeException extends WiringException { + + public InvalidSourceTypeException(String message, URI sourceUri, URI targetUri) { + super(message, sourceUri, targetUri); + } +} diff --git a/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder/InvalidTargetTypeException.java b/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder/InvalidTargetTypeException.java new file mode 100644 index 0000000000..e3c26c75d2 --- /dev/null +++ b/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder/InvalidTargetTypeException.java @@ -0,0 +1,35 @@ +/* + * 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.builder; + +import java.net.URI; + +import org.apache.tuscany.spi.builder.WiringException; + +/** + * Denotes an invalid target service for a wire + * + * @version $Rev$ $Date$ + */ +public class InvalidTargetTypeException extends WiringException { + + public InvalidTargetTypeException(String message, URI sourceUri, URI targetUri) { + super(message, sourceUri, targetUri); + } +} diff --git a/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder/NoBindingException.java b/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder/NoBindingException.java new file mode 100644 index 0000000000..c351013297 --- /dev/null +++ b/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder/NoBindingException.java @@ -0,0 +1,35 @@ +/* + * 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.builder; + +import java.net.URI; + +import org.apache.tuscany.spi.builder.WiringException; + +/** + * Denotes no binding was specified for a wire + * + * @version $Rev$ $Date$ + */ +public class NoBindingException extends WiringException { + + public NoBindingException(String message, URI sourceUri, URI targetUri) { + super(message, sourceUri, targetUri); + } +} diff --git a/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder/NoCompatibleBindingsException.java b/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder/NoCompatibleBindingsException.java new file mode 100644 index 0000000000..3c49767333 --- /dev/null +++ b/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder/NoCompatibleBindingsException.java @@ -0,0 +1,34 @@ +/* + * 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.builder; + +import java.net.URI; + +import org.apache.tuscany.spi.builder.WiringException; + +/** + * @version $Rev$ $Date$ + */ +public class NoCompatibleBindingsException extends WiringException { + + public NoCompatibleBindingsException(URI sourceName, URI targetName) { + super("No compatible bindings for source and target", sourceName, targetName); + } + +} diff --git a/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder/NoConversationalContractException.java b/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder/NoConversationalContractException.java new file mode 100644 index 0000000000..71eb9ebd26 --- /dev/null +++ b/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder/NoConversationalContractException.java @@ -0,0 +1,37 @@ +/*
+ * 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.builder;
+
+import org.apache.tuscany.spi.builder.BuilderException;
+
+/**
+ * Raised when a component has conversational scope but no conversational contract
+ *
+ * @version $Rev: 487877 $ $Date: 2006-12-16 15:32:16 -0500 (Sat, 16 Dec 2006) $
+ */
+public class NoConversationalContractException extends BuilderException {
+
+ public NoConversationalContractException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+ public NoConversationalContractException(String message) {
+ super(message);
+ }
+}
diff --git a/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder/NoRegisteredBuilderException.java b/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder/NoRegisteredBuilderException.java new file mode 100644 index 0000000000..340a20f239 --- /dev/null +++ b/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder/NoRegisteredBuilderException.java @@ -0,0 +1,38 @@ +/* + * 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.builder; + +import org.apache.tuscany.spi.builder.BuilderException; + +/** + * Raised when a builder cannot be found for a SCDL entry type + * + * @version $Rev$ $Date$ + */ +public class NoRegisteredBuilderException extends BuilderException { + + public NoRegisteredBuilderException(String message, String identifier) { + super(message, identifier); + } + + public NoRegisteredBuilderException(String message) { + super(message); + } + +} diff --git a/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder/SourceServiceNotFoundException.java b/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder/SourceServiceNotFoundException.java new file mode 100644 index 0000000000..7d3d49b937 --- /dev/null +++ b/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder/SourceServiceNotFoundException.java @@ -0,0 +1,36 @@ +/* + * 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.builder; + +import java.net.URI; + +import org.apache.tuscany.spi.builder.WiringException; + +/** + * Indicates the source service of a wire was not found + * + * @version $Rev$ $Date$ + */ +public class SourceServiceNotFoundException extends WiringException { + + public SourceServiceNotFoundException(String message, URI sourceName) { + super(message, sourceName, null); + } + +} diff --git a/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder/TargetServiceNotFoundException.java b/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder/TargetServiceNotFoundException.java new file mode 100644 index 0000000000..f22b421aa7 --- /dev/null +++ b/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder/TargetServiceNotFoundException.java @@ -0,0 +1,36 @@ +/* + * 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.builder; + +import java.net.URI; + +import org.apache.tuscany.spi.builder.WiringException; + +/** + * Indicates the target service of a reference was not found + * + * @version $Rev$ $Date$ + */ +public class TargetServiceNotFoundException extends WiringException { + + public TargetServiceNotFoundException(String message, URI sourceName, URI targetName) { + super(message, sourceName, targetName); + } + +} diff --git a/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder/WireCreationException.java b/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder/WireCreationException.java new file mode 100644 index 0000000000..117bb23180 --- /dev/null +++ b/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder/WireCreationException.java @@ -0,0 +1,39 @@ +/* + * 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.builder; + +import java.net.URI; + +import org.apache.tuscany.spi.builder.WiringException; + +/** + * Denotes an error creating a wire + * + * @version $Rev$ $Date$ + */ +public class WireCreationException extends WiringException { + + public WireCreationException(String message, URI sourceUri, Throwable e) { + super(message, sourceUri, null, e); + } + + public WireCreationException(String message, URI sourceUri, URI targetUri, Throwable e) { + super(message, sourceUri, targetUri, e); + } +} diff --git a/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder/WirePostProcessorRegistryImpl.java b/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder/WirePostProcessorRegistryImpl.java new file mode 100644 index 0000000000..6f611956be --- /dev/null +++ b/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder/WirePostProcessorRegistryImpl.java @@ -0,0 +1,50 @@ +/* + * 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.builder; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.spi.wire.Wire; +import org.apache.tuscany.spi.wire.WirePostProcessor; +import org.apache.tuscany.spi.wire.WirePostProcessorRegistry; + +/** + * The default implementation of a <code>WirePostProcessor</code> + * + * @version $Rev$ $Date$ + */ +public class WirePostProcessorRegistryImpl implements WirePostProcessorRegistry { + + private final List<WirePostProcessor> processors = new ArrayList<WirePostProcessor>(); + + public void process(Wire wire) { + for (WirePostProcessor processor : processors) { + processor.process(wire); + } + } + + public void register(WirePostProcessor processor) { + processors.add(processor); + } + + public void unregister(WirePostProcessor processor) { + processors.remove(processor); + } +} diff --git a/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder/WiringExceptionFormatter.java b/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder/WiringExceptionFormatter.java new file mode 100644 index 0000000000..661dc8bfea --- /dev/null +++ b/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/builder/WiringExceptionFormatter.java @@ -0,0 +1,67 @@ +/* + * 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.builder; + +import java.io.PrintWriter; + +import org.osoa.sca.annotations.Destroy; +import org.osoa.sca.annotations.EagerInit; +import org.osoa.sca.annotations.Reference; + +import org.apache.tuscany.spi.builder.WiringException; + +import org.apache.tuscany.host.monitor.ExceptionFormatter; +import org.apache.tuscany.host.monitor.FormatterRegistry; + +/** + * Formats {@link WiringException}s + * + * @version $Rev$ $Date$ + */ +@EagerInit +public class WiringExceptionFormatter implements ExceptionFormatter { + private FormatterRegistry factory; + + public WiringExceptionFormatter(@Reference FormatterRegistry factory) { + this.factory = factory; + factory.register(this); + } + + public boolean canFormat(Class<?> type) { + return WiringException.class.isAssignableFrom(type); + } + + @Destroy + public void destroy() { + factory.unregister(this); + } + + public PrintWriter write(PrintWriter writer, Throwable exception) { + assert exception instanceof WiringException; + WiringException e = (WiringException) exception; + e.appendBaseMessage(writer); + if (e.getSourceUri() != null) { + writer.write("\nSource : " + e.getSourceUri()); + } + if (e.getTargetUri() != null) { + writer.write("\nTarget : " + e.getTargetUri()); + } + return writer; + } +} |