Author: jboynes
Date: Wed Jan 3 10:04:35 2007
New Revision: 492240
URL: http://svn.apache.org/viewvc?view=rev&rev=492240
Log:
more work on contribution service
Added:
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/ContributionServiceImpl.java
(with props)
incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContributionProcessor.java
(with props)
incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContributionProcessorRegistry.java
(with props)
Modified:
incubator/tuscany/java/sca/kernel/host-api/src/main/java/org/apache/tuscany/host/deployment/ContributionService.java
Added:
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/ContributionServiceImpl.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/ContributionServiceImpl.java?view=auto&rev=492240
==============================================================================
---
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/ContributionServiceImpl.java
(added)
+++
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/ContributionServiceImpl.java
Wed Jan 3 10:04:35 2007
@@ -0,0 +1,90 @@
+/*
+ * 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.services.deployment;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.host.deployment.ContributionService;
+import org.apache.tuscany.host.deployment.DeploymentException;
+import org.apache.tuscany.host.deployment.UnsupportedContentTypeException;
+import org.apache.tuscany.spi.deployer.ContributionProcessor;
+import org.apache.tuscany.spi.deployer.ContributionProcessorRegistry;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ContributionServiceImpl implements ContributionService,
ContributionProcessorRegistry {
+ private Map<String, ContributionProcessor> registry = new HashMap<String,
ContributionProcessor>();
+
+ public void register(ContributionProcessor processor) {
+ registry.put(processor.getContentType(), processor);
+ }
+
+ public URI contribute(URL contribution) throws DeploymentException,
IOException {
+ if (contribution == null) {
+ throw new IllegalArgumentException("contribution is null");
+ }
+
+ URI source;
+ try {
+ source = contribution.toURI();
+ } catch (URISyntaxException e) {
+ throw new IllegalArgumentException("contribution cannot be
converted to a URI", e);
+ }
+
+ URLConnection connection = contribution.openConnection();
+ String contentType = connection.getContentType();
+ //todo try and figure out content type from the URL
+ if (contentType == null) {
+ throw new UnsupportedContentTypeException(null,
contribution.toString());
+ }
+
+ InputStream is = connection.getInputStream();
+ try {
+ return contribute(source, is, contentType);
+ } finally {
+ try {
+ is.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ }
+
+ public URI contribute(URI source, InputStream contribution, String
contentType)
+ throws DeploymentException, IOException {
+ if (contentType == null) {
+ throw new IllegalArgumentException("contentType was null");
+ }
+
+ ContributionProcessor processor = registry.get(contentType);
+ if (processor == null) {
+ throw new UnsupportedContentTypeException(contentType,
source.toString());
+ }
+
+ return null;
+ }
+}
Propchange:
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/ContributionServiceImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/ContributionServiceImpl.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
incubator/tuscany/java/sca/kernel/host-api/src/main/java/org/apache/tuscany/host/deployment/ContributionService.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/host-api/src/main/java/org/apache/tuscany/host/deployment/ContributionService.java?view=diff&rev=492240&r1=492239&r2=492240
==============================================================================
---
incubator/tuscany/java/sca/kernel/host-api/src/main/java/org/apache/tuscany/host/deployment/ContributionService.java
(original)
+++
incubator/tuscany/java/sca/kernel/host-api/src/main/java/org/apache/tuscany/host/deployment/ContributionService.java
Wed Jan 3 10:04:35 2007
@@ -45,14 +45,14 @@
/**
* Contribute an artifact to the SCA Domain.
*
+ * @param source an identifier for the source of this contribution
* @param contribution a stream containing the resource being contributed;
the stream will not be closed
* but the read position after the call is undefined
* @param contentType the type of contribution being made; must be a
valid Content-Type value
* as specified by <a
href="http://www.ietf.org/rfc/rfc2045.txt">RFC2045</a>
- * and must not be null
- * @return a URI that uniquely identifies this contribution within the SCA
Domain
+ * and must not be null @return a URI that uniquely
identifies this contribution within the SCA Domain
* @throws DeploymentException if there was a problem with the contribution
* @throws IOException if there was a problem reading the stream
*/
- URI contribute(InputStream contribution, String contentType) throws
DeploymentException, IOException;
+ URI contribute(URI source, InputStream contribution, String contentType)
throws DeploymentException, IOException;
}
Added:
incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContributionProcessor.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContributionProcessor.java?view=auto&rev=492240
==============================================================================
---
incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContributionProcessor.java
(added)
+++
incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContributionProcessor.java
Wed Jan 3 10:04:35 2007
@@ -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.spi.deployer;
+
+/**
+ * Interface for services that can process contributions.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ContributionProcessor {
+ /**
+ * Returns the content type that this implementation can handle.
+ *
+ * @return the content type that this implementation can handle
+ */
+ String getContentType();
+}
Propchange:
incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContributionProcessor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContributionProcessor.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContributionProcessorRegistry.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContributionProcessorRegistry.java?view=auto&rev=492240
==============================================================================
---
incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContributionProcessorRegistry.java
(added)
+++
incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContributionProcessorRegistry.java
Wed Jan 3 10:04:35 2007
@@ -0,0 +1,26 @@
+/*
+ * 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.spi.deployer;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface ContributionProcessorRegistry {
+ void register(ContributionProcessor processor);
+}
Propchange:
incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContributionProcessorRegistry.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContributionProcessorRegistry.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]