diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-11 23:26:33 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-11 23:26:33 +0000 |
commit | a40e527938d76ba71f211da7e327adb50384ba69 (patch) | |
tree | cb8f99f1727122b040a3f0fbb6649292b6a74302 /sca-java-1.x/tags/0.91-incubating/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/binding | |
parent | 968721109881107520d7aefa91d7fcc0519d7739 (diff) |
Moving 1.x tags
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835157 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-1.x/tags/0.91-incubating/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/binding')
7 files changed, 394 insertions, 0 deletions
diff --git a/sca-java-1.x/tags/0.91-incubating/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/binding/resource/DefaultHTTPResourceBindingFactory.java b/sca-java-1.x/tags/0.91-incubating/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/binding/resource/DefaultHTTPResourceBindingFactory.java new file mode 100644 index 0000000000..7de2c3a2ca --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/binding/resource/DefaultHTTPResourceBindingFactory.java @@ -0,0 +1,33 @@ +/* + * 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.sca.binding.resource; + +import org.apache.tuscany.sca.binding.resource.impl.HTTPResourceBindingImpl; + +/** + * A factory for the sample Echo binding model. + */ +public class DefaultHTTPResourceBindingFactory implements HTTPResourceBindingFactory { + + public HTTPResourceBinding createHTTPResourceBinding() { + return new HTTPResourceBindingImpl(); + } + +} diff --git a/sca-java-1.x/tags/0.91-incubating/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/binding/resource/HTTPResourceBinding.java b/sca-java-1.x/tags/0.91-incubating/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/binding/resource/HTTPResourceBinding.java new file mode 100644 index 0000000000..8679f0cf84 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/binding/resource/HTTPResourceBinding.java @@ -0,0 +1,28 @@ +/* + * 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.sca.binding.resource; + +import org.apache.tuscany.sca.assembly.Binding; + +/** + * A model for the HTTP resource binding. + */ +public interface HTTPResourceBinding extends Binding { +} diff --git a/sca-java-1.x/tags/0.91-incubating/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/binding/resource/HTTPResourceBindingFactory.java b/sca-java-1.x/tags/0.91-incubating/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/binding/resource/HTTPResourceBindingFactory.java new file mode 100644 index 0000000000..b2fb2eae1d --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/binding/resource/HTTPResourceBindingFactory.java @@ -0,0 +1,33 @@ +/* + * 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.sca.binding.resource; + +/** + * A factory for the HTTP resource binding model. + */ +public interface HTTPResourceBindingFactory { + + /** + * Creates a new HTTP resource binding. + * + * @return a new HTTP resource binding + */ + HTTPResourceBinding createHTTPResourceBinding(); +} diff --git a/sca-java-1.x/tags/0.91-incubating/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/binding/resource/impl/HTTPResourceBindingImpl.java b/sca-java-1.x/tags/0.91-incubating/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/binding/resource/impl/HTTPResourceBindingImpl.java new file mode 100644 index 0000000000..247041d47f --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/binding/resource/impl/HTTPResourceBindingImpl.java @@ -0,0 +1,77 @@ +/* + * 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.sca.binding.resource.impl; + +import java.util.Collections; +import java.util.List; + +import org.apache.tuscany.sca.binding.resource.HTTPResourceBinding; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.PolicySet; + + +/** + * Implementation of the HTTP resource binding model. + */ +public class HTTPResourceBindingImpl implements HTTPResourceBinding { + + private String name; + private String uri; + + public String getName() { + return name; + } + + public String getURI() { + return uri; + } + + public void setName(String name) { + this.name = name; + } + + public void setURI(String uri) { + this.uri = uri; + } + + public List<PolicySet> getPolicySets() { + // The sample binding does not support policies + return Collections.emptyList(); + } + + public List<Intent> getRequiredIntents() { + // The sample binding does not support policies + return Collections.emptyList(); + } + + public List<Object> getExtensions() { + // The sample binding does not support extensions + return Collections.emptyList(); + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + // The sample binding is always resolved + } + +} diff --git a/sca-java-1.x/tags/0.91-incubating/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/binding/resource/impl/HTTPResourceBindingProcessor.java b/sca-java-1.x/tags/0.91-incubating/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/binding/resource/impl/HTTPResourceBindingProcessor.java new file mode 100644 index 0000000000..80162fa77f --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/binding/resource/impl/HTTPResourceBindingProcessor.java @@ -0,0 +1,73 @@ +/* + * 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.sca.binding.resource.impl; + +import static org.osoa.sca.Constants.SCA_NS; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.binding.resource.HTTPResourceBinding; +import org.apache.tuscany.sca.binding.resource.HTTPResourceBindingFactory; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; + + +/** + * A processor for <binding.resource> elements. + */ +public class HTTPResourceBindingProcessor implements StAXArtifactProcessor<HTTPResourceBinding> { + + private QName BINDING_RESOURCE = new QName(SCA_NS, "binding.resource"); + + private final HTTPResourceBindingFactory factory; + + public HTTPResourceBindingProcessor(HTTPResourceBindingFactory factory) { + this.factory = factory; + } + + public QName getArtifactType() { + return BINDING_RESOURCE; + } + + public Class<HTTPResourceBinding> getModelType() { + return HTTPResourceBinding.class; + } + + public HTTPResourceBinding read(XMLStreamReader reader) throws ContributionReadException { + String uri = reader.getAttributeValue(null, "uri"); + HTTPResourceBinding echoBinding = factory.createHTTPResourceBinding(); + if (uri != null) { + echoBinding.setURI(uri.trim()); + } + return echoBinding; + } + + public void write(HTTPResourceBinding echoBinding, XMLStreamWriter writer) throws ContributionWriteException { + } + + public void resolve(HTTPResourceBinding echoBinding, ModelResolver resolver) throws ContributionResolveException { + } + +} diff --git a/sca-java-1.x/tags/0.91-incubating/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/binding/resource/provider/HTTPResourceBindingProviderFactory.java b/sca-java-1.x/tags/0.91-incubating/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/binding/resource/provider/HTTPResourceBindingProviderFactory.java new file mode 100644 index 0000000000..0c2221a6b2 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/binding/resource/provider/HTTPResourceBindingProviderFactory.java @@ -0,0 +1,54 @@ +/* + * 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.sca.binding.resource.provider; + +import org.apache.tuscany.sca.binding.resource.HTTPResourceBinding; +import org.apache.tuscany.sca.http.ServletHost; +import org.apache.tuscany.sca.provider.BindingProviderFactory; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + + +/** + * Implementation of the Echo binding model. + */ +public class HTTPResourceBindingProviderFactory implements BindingProviderFactory<HTTPResourceBinding> { + + private ServletHost servletHost; + + public HTTPResourceBindingProviderFactory(ServletHost servletHost) { + this.servletHost = servletHost; + } + + public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, RuntimeComponentReference reference, HTTPResourceBinding binding) { + return null; + } + + public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component, RuntimeComponentService service, HTTPResourceBinding binding) { + return new HTTPResourceServiceBindingProvider(component, service, binding, servletHost); + } + + public Class<HTTPResourceBinding> getModelType() { + return HTTPResourceBinding.class; + } +} diff --git a/sca-java-1.x/tags/0.91-incubating/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/binding/resource/provider/HTTPResourceServiceBindingProvider.java b/sca-java-1.x/tags/0.91-incubating/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/binding/resource/provider/HTTPResourceServiceBindingProvider.java new file mode 100644 index 0000000000..9564175df4 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/binding/resource/provider/HTTPResourceServiceBindingProvider.java @@ -0,0 +1,96 @@ +/* + * 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.sca.binding.resource.provider; + +import java.net.URL; + +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.binding.resource.HTTPResourceBinding; +import org.apache.tuscany.sca.http.DefaultResourceServlet; +import org.apache.tuscany.sca.http.ServletHost; +import org.apache.tuscany.sca.implementation.resource.ResourceImplementation; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * Implementation of the Echo binding provider. + */ +public class HTTPResourceServiceBindingProvider implements ServiceBindingProvider { + + private RuntimeComponent component; + private RuntimeComponentService service; + private HTTPResourceBinding binding; + private ServletHost servletHost; + private String uri; + + public HTTPResourceServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + HTTPResourceBinding binding, + ServletHost servletHost) { + this.component = component; + this.service = service; + this.binding = binding; + this.servletHost = servletHost; + + if (binding.getURI() != null) { + uri = binding.getURI(); + if (!uri.endsWith("/")) { + uri += "/"; + } + if (!uri.endsWith("*")) { + uri += "*"; + } + } else { + uri = "/" + this.component.getName() + "/*"; + } + } + + public InterfaceContract getBindingInterfaceContract() { + return service.getInterfaceContract(); + } + + public void start() { + + // Get the target component implementation, for now we are assuming + // that it's an implementation.resource + RuntimeComponentService componentService = (RuntimeComponentService) service; + RuntimeWire wire = componentService.getRuntimeWire(binding); + Implementation implementation = wire.getTarget().getComponent().getImplementation(); + ResourceImplementation resourceImplementation = (ResourceImplementation)implementation; + + // Get the resource location URL + URL locationURL = resourceImplementation.getLocationURL(); + + // Register the default resource servlet with the servlet host + DefaultResourceServlet resourceServlet = new DefaultResourceServlet(locationURL.toString()); + servletHost.addServletMapping(uri, resourceServlet); + + } + + public void stop() { + + // Unregister from the hosting server + servletHost.removeServletMapping(uri); + } + +} |