diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-11 23:06:50 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-11 23:06:50 +0000 |
commit | 0f3f9b59b310833f31ba234ee4aefa808649833c (patch) | |
tree | 4f8b3354beb0643151424eb978eece9e55038c90 /sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java | |
parent | f860c2f35b2f94e379d2ff7d5c13f54cd4a3132a (diff) |
Moving 1.x branches
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835120 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java')
13 files changed, 820 insertions, 0 deletions
diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/DefaultFeedBindingFactory.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/DefaultFeedBindingFactory.java new file mode 100644 index 0000000000..a4e2861aba --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/DefaultFeedBindingFactory.java @@ -0,0 +1,32 @@ +/* + * 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.feed; + +import org.apache.tuscany.sca.binding.feed.impl.FeedBindingImpl; + +/** + * A factory for the Feed binding model. + */ +public class DefaultFeedBindingFactory implements FeedBindingFactory { + + public FeedBinding createFeedBinding() { + return new FeedBindingImpl(); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/Feed.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/Feed.java new file mode 100644 index 0000000000..3a0763bd93 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/Feed.java @@ -0,0 +1,42 @@ +/* + * 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.feed; + +import org.osoa.sca.annotations.Remotable; + +import com.sun.syndication.feed.synd.SyndFeed; + +/** + * The business interface used on services and references that provide and + * consume feeds. + * + * @version $Rev$ $Date$ + */ +@Remotable +public interface Feed { + + /** + * Get an RSS or Atom feed. + * + * @param uri the uri of the feed + * @return the RSS or Atom feed + */ + SyndFeed get(String uri); +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/FeedBinding.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/FeedBinding.java new file mode 100644 index 0000000000..bec56404cd --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/FeedBinding.java @@ -0,0 +1,41 @@ +/* + * 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.feed; + +import org.apache.tuscany.sca.assembly.Binding; + +/** + * A model for the Feed binding. + */ +public interface FeedBinding extends Binding { + + /** + * Returns the feed type. + * @return the feed type + */ + String getFeedType(); + + /** + * Sets the feed type. + * @param value the feed type + */ + void setFeedType(String value); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/FeedBindingFactory.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/FeedBindingFactory.java new file mode 100644 index 0000000000..e98aefe2c9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/FeedBindingFactory.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.feed; + +/** + * A factory for the Feed binding model. + */ +public interface FeedBindingFactory { + + /** + * Creates a new Feed binding. + * + * @return a new Feed binding + */ + FeedBinding createFeedBinding(); +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/FeedBindingImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/FeedBindingImpl.java new file mode 100644 index 0000000000..5e0dea223c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/FeedBindingImpl.java @@ -0,0 +1,85 @@ +/* + * 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.feed.impl; + +import java.util.Collections; +import java.util.List; + +import org.apache.tuscany.sca.binding.feed.FeedBinding; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.PolicySet; + +/** + * Implementation of the Feed binding model. + */ +public class FeedBindingImpl implements FeedBinding { + + private String name; + private String uri; + private String feedType; + + 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 binding does not support policies + return Collections.emptyList(); + } + + public List<Object> getExtensions() { + // The binding does not support extensions + return Collections.emptyList(); + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + // The binding is always resolved + } + + public String getFeedType() { + return feedType; + } + + public void setFeedType(String value) { + feedType = value; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/module/FeedModuleActivator.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/module/FeedModuleActivator.java new file mode 100644 index 0000000000..e91f184339 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/module/FeedModuleActivator.java @@ -0,0 +1,64 @@ +/* + * 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.feed.module; + +import org.apache.tuscany.sca.binding.feed.DefaultFeedBindingFactory; +import org.apache.tuscany.sca.binding.feed.FeedBindingFactory; +import org.apache.tuscany.sca.binding.feed.provider.FeedBindingProviderFactory; +import org.apache.tuscany.sca.binding.feed.xml.AtomBindingProcessor; +import org.apache.tuscany.sca.binding.feed.xml.RssBindingProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.ModuleActivator; +import org.apache.tuscany.sca.http.ServletHost; +import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint; + +/** + * A module activator for the Feed binding extension. + */ +public class FeedModuleActivator implements ModuleActivator { + + public Object[] getExtensionPoints() { + // No extensionPoints being contributed here + return null; + } + + public void start(ExtensionPointRegistry registry) { + + // Create the Feed model factory + FeedBindingFactory factory = new DefaultFeedBindingFactory(); + + // Add the AtomBindingProcessor and RSSBindingProcessor extensions + StAXArtifactProcessorExtensionPoint processors = + registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + AtomBindingProcessor atomBindingProcessor = new AtomBindingProcessor(factory); + processors.addArtifactProcessor(atomBindingProcessor); + RssBindingProcessor rssBindingProcessor = new RssBindingProcessor(factory); + processors.addArtifactProcessor(rssBindingProcessor); + + // Add the Feed binding provider factory extension + ProviderFactoryExtensionPoint providerFactories = registry.getExtensionPoint(ProviderFactoryExtensionPoint.class); + ServletHost servletHost = registry.getExtensionPoint(ServletHost.class); + providerFactories.addProviderFactory(new FeedBindingProviderFactory(servletHost)); + } + + public void stop(ExtensionPointRegistry registry) { + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedBindingInvoker.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedBindingInvoker.java new file mode 100644 index 0000000000..63bbe7a9fd --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedBindingInvoker.java @@ -0,0 +1,79 @@ +/* + * 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.feed.provider; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; + +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; + +import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.io.FeedException; +import com.sun.syndication.io.SyndFeedInput; +import com.sun.syndication.io.XmlReader; + +/** + * Invoker for the Feed binding. + */ +public class FeedBindingInvoker implements Invoker { + + private String uri; + + public FeedBindingInvoker(String uri, String feedType) { + this.uri = uri; + } + + public Message invoke(Message msg) { + try { + URL feedURL; + Object[] args = msg.getBody(); + if (args[0] != null) { + URI arg = URI.create((String)args[0]); + if (arg.isAbsolute()) { + feedURL = arg.toURL(); + } else { + feedURL = new URL(uri + "/" + arg.toString()); + } + } else { + feedURL = new URL(uri); + } + + // Read the configured feed into a Feed object + SyndFeedInput input = new SyndFeedInput(); + SyndFeed feed = input.build(new XmlReader(feedURL)); + msg.setBody(feed); + + System.out.println(">>> FeedBindingInvoker (" + feed.getFeedType() + ") " + uri); + + } catch (MalformedURLException e) { + msg.setFaultBody(e); + } catch (IllegalArgumentException e) { + msg.setFaultBody(e); + } catch (FeedException e) { + msg.setFaultBody(e); + } catch (IOException e) { + msg.setFaultBody(e); + } + return msg; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedBindingListener.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedBindingListener.java new file mode 100644 index 0000000000..0ceb1f9064 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedBindingListener.java @@ -0,0 +1,89 @@ +/* + * 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.feed.provider; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintWriter; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.tuscany.sca.binding.feed.Feed; + +import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.io.FeedException; +import com.sun.syndication.io.SyndFeedOutput; + +/** + * A Feed binding listener, implemented as a servlet and register in a + * servlet host provided by the SCA hosting runtime. + */ +public class FeedBindingListener extends HttpServlet { + private static final long serialVersionUID = 1L; + + String serviceName; + Class<?> serviceInterface; + Object serviceInstance; + String feedType; + + public FeedBindingListener(String serviceName, Class<?> serviceInterface, Object serviceInstance, String feedType) { + this.serviceName = serviceName; + this.serviceInterface = serviceInterface; + this.serviceInstance = serviceInstance; + this.feedType = feedType; + } + + @Override + public void init(ServletConfig config) { + } + + @Override + public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { + + // The feedType parameter is used to override what type of feed is going to + // be produced + String requestFeedType = request.getParameter("feedType"); + if (requestFeedType == null) + requestFeedType = feedType; + + System.out.println(">>> FeedEndPointServlet (" + requestFeedType + ") " + request.getRequestURI()); + + // Assuming that the service provided by this binding implements the Feed + // service interface, get the Feed from the service + String uri = request.getRequestURL().toString(); + SyndFeed syndFeed = ((Feed)serviceInstance).get(uri); + syndFeed.setFeedType(requestFeedType); + + // Write the Feed to the servlet output + OutputStream output = response.getOutputStream(); + SyndFeedOutput syndOutput = new SyndFeedOutput(); + try { + syndOutput.output(syndFeed, new PrintWriter(output)); + } catch (FeedException e) { + throw new ServletException(e); + } + + output.flush(); + output.close(); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedBindingProviderFactory.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedBindingProviderFactory.java new file mode 100644 index 0000000000..9e855b7b2f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedBindingProviderFactory.java @@ -0,0 +1,57 @@ +/* + * 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.feed.provider; + +import org.apache.tuscany.sca.binding.feed.FeedBinding; +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 Feed binding provider factory. + */ +public class FeedBindingProviderFactory implements BindingProviderFactory<FeedBinding> { + + ServletHost servletHost; + + public FeedBindingProviderFactory(ServletHost servletHost) { + this.servletHost = servletHost; + } + + public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + FeedBinding binding) { + return new FeedReferenceBindingProvider(component, reference, binding); + } + + public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + FeedBinding binding) { + return new FeedServiceBindingProvider(component, service, binding, servletHost); + } + + public Class<FeedBinding> getModelType() { + return FeedBinding.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedReferenceBindingProvider.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedReferenceBindingProvider.java new file mode 100644 index 0000000000..2e14d49e52 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedReferenceBindingProvider.java @@ -0,0 +1,63 @@ +/* + * 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.feed.provider; + +import org.apache.tuscany.sca.binding.feed.FeedBinding; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; + +/** + * Implementation of the Feed binding provider. + */ +public class FeedReferenceBindingProvider implements ReferenceBindingProvider { + + private RuntimeComponentReference reference; + private FeedBinding binding; + + public FeedReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + FeedBinding binding) { + this.reference = reference; + this.binding = binding; + } + + public Invoker createInvoker(Operation operation, boolean isCallback) { + if (isCallback) { + throw new UnsupportedOperationException(); + } else { + return new FeedBindingInvoker(binding.getURI(), binding.getFeedType()); + } + } + + public InterfaceContract getBindingInterfaceContract() { + return reference.getInterfaceContract(); + } + + public void start() { + } + + public void stop() { + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedServiceBindingProvider.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedServiceBindingProvider.java new file mode 100644 index 0000000000..64b4807998 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedServiceBindingProvider.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.feed.provider; + +import org.apache.tuscany.sca.binding.feed.FeedBinding; +import org.apache.tuscany.sca.http.ServletHost; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * Implementation of the Feed binding provider. + */ +public class FeedServiceBindingProvider implements ServiceBindingProvider { + + private RuntimeComponent component; + private RuntimeComponentService service; + private FeedBinding binding; + private ServletHost servletHost; + private String uri; + + public FeedServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + FeedBinding binding, + ServletHost servletHost) { + this.component = component; + this.service = service; + this.binding = binding; + this.servletHost = servletHost; + uri = binding.getURI(); + if (uri == null) { + uri = "/" + component.getName(); + } + } + + public InterfaceContract getBindingInterfaceContract() { + return service.getInterfaceContract(); + } + + public void start() { + Class<?> aClass = getTargetJavaClass(service.getInterfaceContract().getInterface()); + Object instance = component.createSelfReference(aClass).getService(); + + FeedBindingListener servlet = + new FeedBindingListener(binding.getName(), aClass, instance, binding.getFeedType()); + + servletHost.addServletMapping(uri, servlet); + } + + public void stop() { + servletHost.removeServletMapping(uri); + } + + private Class<?> getTargetJavaClass(Interface targetInterface) { + return ((JavaInterface)targetInterface).getJavaClass(); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/xml/AtomBindingProcessor.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/xml/AtomBindingProcessor.java new file mode 100644 index 0000000000..800acba9ed --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/xml/AtomBindingProcessor.java @@ -0,0 +1,79 @@ +/* + * 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.feed.xml; + +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.feed.FeedBinding; +import org.apache.tuscany.sca.binding.feed.FeedBindingFactory; +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.atom> elements. + */ +public class AtomBindingProcessor implements StAXArtifactProcessor<FeedBinding> { + + private final static QName BINDING_ATOM = new QName(SCA_NS, "binding.atom"); + + private final FeedBindingFactory factory; + + /** + * Constructs a new binding processor. + * @param factory + */ + public AtomBindingProcessor(FeedBindingFactory factory) { + this.factory = factory; + } + + public QName getArtifactType() { + return BINDING_ATOM; + } + + public Class<FeedBinding> getModelType() { + return FeedBinding.class; + } + + public FeedBinding read(XMLStreamReader reader) throws ContributionReadException { + + // Read a <binding.atom> element + String uri = reader.getAttributeValue(null, "uri"); + FeedBinding binding = factory.createFeedBinding(); + binding.setFeedType("atom_1.0"); + if (uri != null) { + binding.setURI(uri.trim()); + } + return binding; + } + + public void write(FeedBinding binding, XMLStreamWriter writer) throws ContributionWriteException { + } + + public void resolve(FeedBinding binding, ModelResolver resolver) throws ContributionResolveException { + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/xml/RssBindingProcessor.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/xml/RssBindingProcessor.java new file mode 100644 index 0000000000..abdfcf0bff --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/xml/RssBindingProcessor.java @@ -0,0 +1,79 @@ +/* + * 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.feed.xml; + +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.feed.FeedBinding; +import org.apache.tuscany.sca.binding.feed.FeedBindingFactory; +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.rss> elements. + */ +public class RssBindingProcessor implements StAXArtifactProcessor<FeedBinding> { + + private final static QName BINDING_RSS = new QName(SCA_NS, "binding.rss"); + + private final FeedBindingFactory factory; + + /** + * Constructs a new binding processor. + * @param factory + */ + public RssBindingProcessor(FeedBindingFactory factory) { + this.factory = factory; + } + + public QName getArtifactType() { + return BINDING_RSS; + } + + public Class<FeedBinding> getModelType() { + return FeedBinding.class; + } + + public FeedBinding read(XMLStreamReader reader) throws ContributionReadException { + + // Read the <binding.rss> element + String uri = reader.getAttributeValue(null, "uri"); + FeedBinding binding = factory.createFeedBinding(); + binding.setFeedType("rss_2.0"); + if (uri != null) { + binding.setURI(uri.trim()); + } + return binding; + } + + public void write(FeedBinding binding, XMLStreamWriter writer) throws ContributionWriteException { + } + + public void resolve(FeedBinding binding, ModelResolver resolver) throws ContributionResolveException { + } + +} |