You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by ad...@apache.org on 2008/04/16 10:52:27 UTC

svn commit: r648628 [1/2] - in /incubator/tuscany/sandbox/mobile-android: contribution-impl/ contribution-impl/src/ contribution-impl/src/main/ contribution-impl/src/main/java/ contribution-impl/src/main/java/org/ contribution-impl/src/main/java/org/ap...

Author: adrianocrestani
Date: Wed Apr 16 01:52:20 2008
New Revision: 648628

URL: http://svn.apache.org/viewvc?rev=648628&view=rev
Log:
-adding contribution-impl module to Android test sandbox

Added:
    incubator/tuscany/sandbox/mobile-android/contribution-impl/
    incubator/tuscany/sandbox/mobile-android/contribution-impl/DISCLAIMER
    incubator/tuscany/sandbox/mobile-android/contribution-impl/LICENSE
    incubator/tuscany/sandbox/mobile-android/contribution-impl/NOTICE
    incubator/tuscany/sandbox/mobile-android/contribution-impl/pom.xml
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/main/
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/main/java/
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/main/java/org/
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/main/java/org/apache/
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/main/java/org/apache/tuscany/
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/main/java/org/apache/tuscany/sca/
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/FolderContributionProcessor.java
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/JarContributionProcessor.java
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionRepositoryImpl.java
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionServiceImpl.java
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/PackageTypeDescriberImpl.java
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/util/
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/util/FileHelper.java
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/util/IOHelper.java
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/main/resources/
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/main/resources/META-INF/
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/main/resources/META-INF/services/
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.PackageProcessor
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/test/
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/test/java/
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/test/java/org/
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/test/java/org/apache/
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/test/java/org/apache/tuscany/
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/test/java/org/apache/tuscany/sca/
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/impl/
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/processor/
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/processor/FolderContributionPackageProcessorTestCase.java
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/processor/JarContributionPackageProcessorTestCase.java
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/processor/URLartifactProcessorExtensionPointTestCase.java
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/resolver/
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverTestCase.java
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolverTestCase.java
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/resolver/TestModelResolver.java
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/services/
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/services/ContributionRepositoryTestCase.java
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/services/PackageTypeDescriberImplTestCase.java
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/test/resources/
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/test/resources/deployables/
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/test/resources/deployables/sample-calculator.jar   (with props)
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/test/resources/repository/
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/test/resources/repository/sample-calculator.jar   (with props)
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/test/resources/test.composite
    incubator/tuscany/sandbox/mobile-android/contribution-impl/src/test/resources/test.ext
Modified:
    incubator/tuscany/sandbox/mobile-android/host-android/src/main/java/org/apache/tuscany/sca/host/embedded/SCADomain.java
    incubator/tuscany/sandbox/mobile-android/host-android/src/main/java/org/apache/tuscany/sca/host/embedded/impl/DefaultSCADomain.java

Added: incubator/tuscany/sandbox/mobile-android/contribution-impl/DISCLAIMER
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/contribution-impl/DISCLAIMER?rev=648628&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/contribution-impl/DISCLAIMER (added)
+++ incubator/tuscany/sandbox/mobile-android/contribution-impl/DISCLAIMER Wed Apr 16 01:52:20 2008
@@ -0,0 +1,8 @@
+Apache Tuscany is an effort undergoing incubation at The Apache Software
+Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is
+required of all newly accepted projects until a further review indicates that
+the infrastructure, communications, and decision making process have stabilized
+in a manner consistent with other successful ASF projects. While incubation
+status is not necessarily a reflection of the completeness or stability of the
+code, it does indicate that the project has yet to be fully endorsed by the ASF.
+

Added: incubator/tuscany/sandbox/mobile-android/contribution-impl/LICENSE
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/contribution-impl/LICENSE?rev=648628&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/contribution-impl/LICENSE (added)
+++ incubator/tuscany/sandbox/mobile-android/contribution-impl/LICENSE Wed Apr 16 01:52:20 2008
@@ -0,0 +1,205 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed 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.
+
+
+

Added: incubator/tuscany/sandbox/mobile-android/contribution-impl/NOTICE
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/contribution-impl/NOTICE?rev=648628&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/contribution-impl/NOTICE (added)
+++ incubator/tuscany/sandbox/mobile-android/contribution-impl/NOTICE Wed Apr 16 01:52:20 2008
@@ -0,0 +1,6 @@
+${pom.name}
+Copyright (c) 2005 - 2008 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+

Added: incubator/tuscany/sandbox/mobile-android/contribution-impl/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/contribution-impl/pom.xml?rev=648628&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/contribution-impl/pom.xml (added)
+++ incubator/tuscany/sandbox/mobile-android/contribution-impl/pom.xml Wed Apr 16 01:52:20 2008
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.    
+-->
+<project>
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.tuscany.sca</groupId>
+        <artifactId>tuscany-modules</artifactId>
+        <version>2.0-incubating-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+    <artifactId>tuscany-contribution-impl</artifactId>
+    <name>Apache Tuscany SCA Contribution Model Implementation</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-contribution</artifactId>
+            <version>2.0-incubating-SNAPSHOT</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-contribution-xml</artifactId>
+            <version>2.0-incubating-SNAPSHOT</version>
+        </dependency>
+        
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-contribution-java</artifactId>
+            <version>2.0-incubating-SNAPSHOT</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-contribution-namespace</artifactId>
+            <version>2.0-incubating-SNAPSHOT</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-contribution-resource</artifactId>
+            <version>2.0-incubating-SNAPSHOT</version>
+        </dependency>
+        
+        <dependency>
+            <groupId>org.codehaus.woodstox</groupId>
+            <artifactId>wstx-asl</artifactId>
+            <version>3.2.1</version>
+            <scope>runtime</scope>
+        </dependency>
+    </dependencies>
+</project>

Added: incubator/tuscany/sandbox/mobile-android/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/FolderContributionProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/FolderContributionProcessor.java?rev=648628&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/FolderContributionProcessor.java (added)
+++ incubator/tuscany/sandbox/mobile-android/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/FolderContributionProcessor.java Wed Apr 16 01:52:20 2008
@@ -0,0 +1,156 @@
+/*
+ * 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.contribution.processor.impl;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.sca.contribution.PackageType;
+import org.apache.tuscany.sca.contribution.processor.PackageProcessor;
+import org.apache.tuscany.sca.contribution.service.ContributionException;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+
+/**
+ * Folder contribution package processor.
+ * 
+ * @version $Rev: 641645 $ $Date: 2008-03-26 15:37:28 -0800 (Wed, 26 Mar 2008) $
+ */
+public class FolderContributionProcessor implements PackageProcessor {
+
+    public FolderContributionProcessor() {
+    }
+
+    public String getPackageType() {
+        return PackageType.FOLDER;
+    }
+
+    /**
+     * Recursively traverse a root directory
+     * 
+     * @param fileList
+     * @param file
+     * @param root
+     * @throws IOException
+     */
+    private static void traverse(List<URI> fileList, final File file, final File root) throws IOException {
+        // Allow privileged access to test file. Requires FilePermissions in security policy file.
+        Boolean isFile = AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
+            public Boolean run() {
+                return file.isFile();
+            }
+        });
+        if (isFile) {
+            fileList.add(AccessController.doPrivileged(new PrivilegedAction<URI>() {
+                public URI run() {
+                    return root.toURI().relativize(file.toURI());
+                }
+            }));
+        } else {
+            // Allow privileged access to test file. Requires FilePermissions in security policy
+            // file.
+            Boolean isDirectory = AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
+                public Boolean run() {
+                    return file.isDirectory();
+                }
+            });
+            if (isDirectory) {
+                String uri = AccessController.doPrivileged(new PrivilegedAction<URI>() {
+                    public URI run() {
+                        return root.toURI().relativize(file.toURI());
+                    }
+                }).toString();
+
+                if (uri.endsWith("/")) {
+                    uri = uri.substring(0, uri.length() - 1);
+                }
+                fileList.add(URI.create(uri));
+
+                // Allow privileged access to list files. Requires FilePermission in security
+                // policy.
+                File[] files = AccessController.doPrivileged(new PrivilegedAction<File[]>() {
+                    public File[] run() {
+                        return file.listFiles();
+                    }
+                });
+                for (File f : files) {
+                    if (!f.getName().startsWith(".")) {
+                        traverse(fileList, f, root);
+                    }
+                }
+            }
+        }
+    }
+    
+    public URL getArtifactURL(URL sourceURL, URI artifact) throws MalformedURLException {
+        return new URL(sourceURL, artifact.toString());
+    }
+
+    public List<URI> getArtifacts(URL packageSourceURL, InputStream inputStream) throws ContributionException,
+        IOException {
+        if (packageSourceURL == null) {
+            throw new IllegalArgumentException("Invalid null package source URL.");
+        }
+
+        List<URI> artifacts = new ArrayList<URI>();
+
+        try {
+            // Assume the root is a jar file
+            final File rootFolder = new File(packageSourceURL.toURI());
+            // Allow privileged access to test file. Requires FilePermissions in security policy
+            // file.
+            Boolean isDirectory = AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
+                public Boolean run() {
+                    return rootFolder.isDirectory();
+                }
+            });
+            if (isDirectory) {
+                // Allow privileged access to test file. Requires FilePermissions in security policy
+                // file.
+                Boolean folderExists = AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
+                    public Boolean run() {
+                        return rootFolder.exists();
+                    }
+                });
+                if (!folderExists) {
+                    throw new ContributionReadException(rootFolder.getAbsolutePath());
+                }
+
+                // Security consideration. This method gathers URIs of enclosed
+                // artifacts. The URIs are protected by the policy when a user
+                // yries to open those URLs.
+                traverse(artifacts, rootFolder, rootFolder);
+            }
+
+        } catch (URISyntaxException e) {
+            throw new ContributionReadException(packageSourceURL.toExternalForm(), e);
+        }
+
+        return artifacts;
+    }
+}

Added: incubator/tuscany/sandbox/mobile-android/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/JarContributionProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/JarContributionProcessor.java?rev=648628&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/JarContributionProcessor.java (added)
+++ incubator/tuscany/sandbox/mobile-android/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/JarContributionProcessor.java Wed Apr 16 01:52:20 2008
@@ -0,0 +1,123 @@
+/*
+ * 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.contribution.processor.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.jar.JarEntry;
+import java.util.jar.JarInputStream;
+
+import org.apache.tuscany.sca.contribution.PackageType;
+import org.apache.tuscany.sca.contribution.processor.PackageProcessor;
+import org.apache.tuscany.sca.contribution.service.ContributionException;
+
+/**
+ * Jar Contribution package processor.
+ * 
+ * @version $Rev: 616194 $ $Date: 2008-01-28 23:49:21 -0800 (Mon, 28 Jan 2008) $
+ */
+public class JarContributionProcessor implements PackageProcessor {
+
+    public JarContributionProcessor() {
+    }
+
+    public String getPackageType() {
+        return PackageType.JAR;
+    }
+
+    public URL getArtifactURL(URL sourceURL, URI artifact) throws MalformedURLException {
+        if (sourceURL.toString().startsWith("jar:")) {
+            return new URL(sourceURL, artifact.toString());
+        } else {
+            return new URL("jar:" + sourceURL.toExternalForm() + "!/" + artifact);
+        }
+    }
+
+    public List<URI> getArtifacts(URL packageSourceURL, InputStream inputStream) throws ContributionException,
+        IOException {
+        if (packageSourceURL == null) {
+            throw new IllegalArgumentException("Invalid null package source URL.");
+        }
+
+        if (inputStream == null) {
+            throw new IllegalArgumentException("Invalid null source inputstream.");
+        }
+
+        // Assume the root is a jar file
+        JarInputStream jar = new JarInputStream(inputStream);
+        try {
+            Set<String> names = new HashSet<String>();
+            while (true) {
+                JarEntry entry = jar.getNextJarEntry();
+                if (entry == null) {
+                    // EOF
+                    break;
+                }
+
+                // FIXME: Maybe we should externalize the filter as a property
+                String name = entry.getName(); 
+                if (!name.startsWith(".")) {
+                    
+                    // Trim trailing /
+                    if (name.endsWith("/")) {
+                        name = name.substring(0, name.length() - 1);
+                    }
+
+                    // Add the entry name
+                    if (!names.contains(name)) {
+                        names.add(name);
+                        
+                        // Add parent folder names to the list too
+                        for (;;) {
+                            int s = name.lastIndexOf('/');
+                            if (s == -1) {
+                                name = "";
+                            } else {
+                                name = name.substring(0, s);
+                            }
+                            if (!names.contains(name)) {
+                                names.add(name);
+                            } else {
+                                break;
+                            }
+                        }
+                    }
+                }
+            }
+            
+            // Return list of URIs
+            List<URI> artifacts = new ArrayList<URI>();
+            for (String name: names) {
+                artifacts.add(URI.create(name));
+            }
+            return artifacts;
+            
+        } finally {
+            jar.close();
+        }
+    }
+}

Added: incubator/tuscany/sandbox/mobile-android/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionRepositoryImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionRepositoryImpl.java?rev=648628&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionRepositoryImpl.java (added)
+++ incubator/tuscany/sandbox/mobile-android/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionRepositoryImpl.java Wed Apr 16 01:52:20 2008
@@ -0,0 +1,333 @@
+/*
+ * 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.contribution.service.impl;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+import java.net.URLConnection;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.service.ContributionRepository;
+import org.apache.tuscany.sca.contribution.service.util.FileHelper;
+import org.apache.tuscany.sca.contribution.service.util.IOHelper;
+
+/**
+ * The default implementation of ContributionRepository
+ * 
+ * @version $Rev: 641645 $ $Date: 2008-03-26 15:37:28 -0800 (Wed, 26 Mar 2008) $
+ */
+public class ContributionRepositoryImpl implements ContributionRepository {
+    private static final String NS = "http://tuscany.apache.org/xmlns/1.0-SNAPSHOT";
+    private static final String DOMAIN_INDEX_FILENAME = "sca-domain.xml";
+    private final File rootFile;
+    private Map<String, String> contributionLocations = new HashMap<String, String>();
+    
+    private Map<String, Contribution> contributionMap = new HashMap<String, Contribution>();
+    private List<Contribution> contributions = new ArrayList<Contribution>();
+
+    private URI domain;
+    private XMLInputFactory factory;
+
+    /**
+     * Constructor with repository root
+     * 
+     * @param repository
+     * @param factory
+     */
+    public ContributionRepositoryImpl(final String repository, XMLInputFactory factory) throws IOException {
+        String root = repository;
+        if (repository == null) {
+            root = AccessController.doPrivileged(new PrivilegedAction<String>() {
+                public String run() {
+                    // Default to <user.home>/.tuscany/domains/local/
+                    String userHome = System.getProperty("user.home");
+                    String slash = File.separator;
+                    return userHome + slash + ".tuscany" + slash + "domains" + slash + "local" + slash;
+                }
+            });
+        }
+
+        // Allow privileged access to File. Requires FilePermission in security policy file.
+        final String finalRoot = root;
+        this.rootFile = AccessController.doPrivileged(new PrivilegedAction<File>() {
+            public File run() {
+                return new File(finalRoot);
+            }
+        });           
+
+        // Allow privileged access to File. Requires FilePermission in security policy file.
+        this.domain = AccessController.doPrivileged(new PrivilegedAction<URI>() {
+            public URI run() {
+                return rootFile.toURI();
+            }
+        });           
+
+        // Allow privileged access to mkdir. Requires FilePermission in security policy file.
+        try {
+            AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
+                public Object run() throws IOException {
+                    FileHelper.forceMkdir(rootFile);
+                    return null;
+                }
+            });
+        } catch (PrivilegedActionException e) {
+            throw (IOException)e.getException();
+        }
+            
+        // Allow privileged access to test file. Requires FilePermissions in security policy file.
+        Boolean notDirectory = AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
+            public Boolean run() {
+                return (!rootFile.exists() || !rootFile.isDirectory() || !rootFile.canRead());
+            }
+        });           
+        if (notDirectory) {
+            throw new IOException("The root is not a directory: " + repository);
+        }
+        this.factory = factory;
+    }
+
+    public URI getDomain() {
+        return domain;
+    }
+
+    /**
+     * Resolve contribution location in the repository -> root repository /
+     * contribution file -> contribution group id / artifact id / version
+     * 
+     * @param contribution
+     * @return
+     */
+    private File mapToFile(URL sourceURL) {
+        String fileName = FileHelper.toFile(sourceURL).getName();
+        return new File(rootFile, "contributions" + File.separator + fileName);
+    }
+
+    /**
+     * Write a specific source InputStream to a file on disk
+     * 
+     * @param source contents of the file to be written to disk
+     * @param target file to be written
+     * @throws IOException
+     */
+    public static void copy(InputStream source, File target) throws IOException {
+        BufferedOutputStream out = null;
+        BufferedInputStream in = null;
+
+        try {
+            out = new BufferedOutputStream(new FileOutputStream(target));
+            in = new BufferedInputStream(source);
+            IOHelper.copy(in, out);
+        } finally {
+            IOHelper.closeQuietly(out);
+            IOHelper.closeQuietly(in);
+        }
+    }
+
+    public URL store(String contribution, URL sourceURL, InputStream contributionStream) throws IOException {
+        // where the file should be stored in the repository
+        File location = mapToFile(sourceURL);
+        FileHelper.forceMkdir(location.getParentFile());
+
+        copy(contributionStream, location);
+
+        // add contribution to repositoryContent
+        URL contributionURL = location.toURL();
+        URI relative = rootFile.toURI().relativize(location.toURI());
+        contributionLocations.put(contribution, relative.toString());
+        saveMap();
+
+        return contributionURL;
+    }
+
+    public URL store(String contribution, URL sourceURL) throws IOException {
+        // where the file should be stored in the repository
+        File location = mapToFile(sourceURL);
+        File source = FileHelper.toFile(sourceURL);
+        if (source == null || source.isFile()) {
+            URLConnection connection = sourceURL.openConnection();
+            connection.setUseCaches(false);
+            InputStream is = connection.getInputStream();
+            try {
+                return store(contribution, sourceURL, is);
+            } finally {
+                IOHelper.closeQuietly(is);
+            }
+        }
+
+        FileHelper.forceMkdir(location);
+        FileHelper.copyDirectory(source, location);
+
+        // add contribution to repositoryContent
+        URI relative = rootFile.toURI().relativize(location.toURI());
+        contributionLocations.put(contribution, relative.toString());
+        saveMap();
+
+        return location.toURL();
+    }
+
+    public URL find(String contribution) {
+        if (contribution == null) {
+            return null;
+        }
+        String location = contributionLocations.get(contribution);
+        if (location == null) {
+            return null;
+        }
+        try {
+            return new File(rootFile, location).toURL();
+        } catch (MalformedURLException e) {
+            // Should not happen
+            throw new AssertionError(e);
+        }
+    }
+
+    public void remove(String contribution) {
+        URL contributionURL = this.find(contribution);
+        if (contributionURL != null) {
+            // remove
+            try {
+                FileHelper.forceDelete(FileHelper.toFile(contributionURL));
+                this.contributionLocations.remove(contribution);
+                saveMap();
+            } catch (IOException ioe) {
+                // handle file could not be removed
+            }
+        }
+    }
+
+    public List<String> list() {
+        return new ArrayList<String>(contributionLocations.keySet());
+    }
+
+    public void init() {
+        File domainFile = new File(rootFile, "sca-domain.xml");
+        if (!domainFile.isFile()) {
+            return;
+        }
+        FileInputStream is;
+        try {
+            is = new FileInputStream(domainFile);
+        } catch (FileNotFoundException e) {
+            return;
+        }
+        try {
+            XMLStreamReader reader = factory.createXMLStreamReader(new InputStreamReader(is, "UTF-8"));
+            while (reader.hasNext()) {
+                switch (reader.getEventType()) {
+                    case XMLStreamConstants.START_ELEMENT:
+                        String name = reader.getName().getLocalPart();
+                        if ("domain".equals(name)) {
+                            String uri = reader.getAttributeValue(null, "uri");
+                            if (uri != null) {
+                                domain = URI.create(uri);
+                            }
+                        }
+                        if ("contribution".equals(name)) {
+                            String uri = reader.getAttributeValue(null, "uri");
+                            String location = reader.getAttributeValue(null, "location");
+                            contributionLocations.put(uri, location);
+                        }
+                        break;
+                    default:
+                        break;
+                }
+                reader.next();
+            }
+        } catch (Exception e) {
+            // Ignore
+        } finally {
+            IOHelper.closeQuietly(is);
+        }
+    }
+
+    private void saveMap() {
+        File domainFile = new File(rootFile, DOMAIN_INDEX_FILENAME);
+        FileOutputStream os = null;
+        try {
+            os = new FileOutputStream(domainFile);
+            PrintWriter writer = new PrintWriter(new OutputStreamWriter(os, "UTF-8"));
+            writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
+            writer.println("<domain uri=\"" + getDomain() + "\" xmlns=\"" + NS + "\">");
+            for (Map.Entry<String, String> e : contributionLocations.entrySet()) {
+                writer.println("    <contribution uri=\"" + e.getKey() + "\" location=\"" + e.getValue() + "\"/>");
+            }
+            writer.println("</domain>");
+            writer.flush();
+        } catch (IOException e) {
+            throw new IllegalArgumentException(e);
+        } finally {
+            IOHelper.closeQuietly(os);
+        }
+    }
+
+    public void destroy() {
+    }
+    
+    public void addContribution(Contribution contribution) {
+        contributionMap.put(contribution.getURI(), contribution);
+        contributions.add(contribution);
+    }
+    
+    public void removeContribution(Contribution contribution) {
+        contributionMap.remove(contribution.getURI());
+        contributions.remove(contribution);
+    }
+    
+    public void updateContribution(Contribution contribution) {
+        Contribution oldContribution = contributionMap.remove(contribution.getURI());
+        contributions.remove(oldContribution);
+        contributionMap.put(contribution.getURI(), contribution);
+        contributions.add(contribution);
+    }
+    
+    public Contribution getContribution(String uri) {
+        return contributionMap.get(uri);
+    }
+    
+    public List<Contribution> getContributions() {
+        return Collections.unmodifiableList(contributions);
+    }
+    
+}

Added: incubator/tuscany/sandbox/mobile-android/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionServiceImpl.java?rev=648628&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionServiceImpl.java (added)
+++ incubator/tuscany/sandbox/mobile-android/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionServiceImpl.java Wed Apr 16 01:52:20 2008
@@ -0,0 +1,508 @@
+/*
+ * 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.contribution.service.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.net.URLConnection;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.contribution.Artifact;
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.ContributionFactory;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.PackageProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ExtensibleModelResolver;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint;
+import org.apache.tuscany.sca.contribution.service.ContributionException;
+import org.apache.tuscany.sca.contribution.service.ContributionRepository;
+import org.apache.tuscany.sca.contribution.service.ContributionService;
+import org.apache.tuscany.sca.contribution.service.ExtensibleContributionListener;
+import org.apache.tuscany.sca.contribution.service.util.IOHelper;
+import org.apache.tuscany.sca.contribution.xml.ContributionMetadataDocumentProcessor;
+
+/**
+ * Service interface that manages artifacts contributed to a Tuscany runtime.
+ * 
+ * @version $Rev: 641645 $ $Date: 2008-03-26 15:37:28 -0800 (Wed, 26 Mar 2008) $
+ */
+/**
+ * 
+ */
+public class ContributionServiceImpl implements ContributionService {
+
+    /**
+     * Repository where contributions are stored. Usually set by injection.
+     */
+    private ContributionRepository contributionRepository;
+
+    /**
+     * Registry of available package processors.
+     */
+    private PackageProcessor packageProcessor;
+
+    /**
+     * Registry of available artifact processors
+     */
+
+    private URLArtifactProcessor artifactProcessor;
+
+    /**
+     * Registry of available StAX processors,
+     * used for loading contribution metadata in a extensible way
+     */
+    private StAXArtifactProcessor staxProcessor;
+
+    /**
+     * Event listener for contribution operations
+     */
+    private ExtensibleContributionListener contributionListener;
+
+    /**
+     * Registry of available model resolvers
+     */
+
+    private ModelResolverExtensionPoint modelResolvers;
+
+    /**
+     * Model factory extension point
+     */
+
+    private ModelFactoryExtensionPoint modelFactories;
+
+    /**
+     * XML factory used to create reader instance to load contribution metadata
+     */
+    private XMLInputFactory xmlFactory;
+
+    /**
+     * Assembly factory
+     */
+    private AssemblyFactory assemblyFactory;
+
+    /**
+     * Contribution model factory
+     */
+    private ContributionFactory contributionFactory;
+    
+    
+    private ModelResolver domainResolver;
+
+
+    private List scaDefinitionsSink = null; 
+    
+    private String COMPOSITE_FILE_EXTN = ".composite";    
+
+    public ContributionServiceImpl(ContributionRepository repository,
+                                   PackageProcessor packageProcessor,
+                                   URLArtifactProcessor documentProcessor,
+                                   StAXArtifactProcessor staxProcessor,
+                                   ExtensibleContributionListener contributionListener,
+                                   ModelResolver domainResolver,
+                                   ModelResolverExtensionPoint modelResolvers,
+                                   ModelFactoryExtensionPoint modelFactories,
+                                   AssemblyFactory assemblyFactory,
+                                   ContributionFactory contributionFactory,
+                                   XMLInputFactory xmlFactory,
+                                   List scaDefnSink) {
+        super();
+        this.contributionRepository = repository;
+        this.packageProcessor = packageProcessor;
+        this.artifactProcessor = documentProcessor;
+        this.staxProcessor = staxProcessor;
+        this.contributionListener = contributionListener;
+        this.modelResolvers = modelResolvers;
+        this.modelFactories = modelFactories;
+        this.xmlFactory = xmlFactory;
+        this.assemblyFactory = assemblyFactory;
+        this.contributionFactory = contributionFactory;
+        this.domainResolver = domainResolver;
+        this.scaDefinitionsSink = scaDefnSink;
+    }
+
+    public Contribution contribute(String contributionURI, URL sourceURL, boolean storeInRepository)
+        throws ContributionException, IOException {
+        if (contributionURI == null) {
+            throw new IllegalArgumentException("URI for the contribution is null");
+        }
+        if (sourceURL == null) {
+            throw new IllegalArgumentException("Source URL for the contribution is null");
+        }
+
+        return addContribution(contributionURI, sourceURL, null, null, storeInRepository);
+    }
+
+    public Contribution contribute(String contributionURI,
+                                   URL sourceURL,
+                                   ModelResolver modelResolver,
+                                   boolean storeInRepository) throws ContributionException, IOException {
+        if (contributionURI == null) {
+            throw new IllegalArgumentException("URI for the contribution is null");
+        }
+        if (sourceURL == null) {
+            throw new IllegalArgumentException("Source URL for the contribution is null");
+        }
+
+        return addContribution(contributionURI, sourceURL, null, modelResolver, storeInRepository);
+    }
+
+    public Contribution contribute(String contributionURI, URL sourceURL, InputStream input)
+        throws ContributionException, IOException {
+
+        return addContribution(contributionURI, sourceURL, input, null, true);
+    }
+
+    public Contribution contribute(String contributionURI, URL sourceURL, InputStream input, ModelResolver modelResolver)
+        throws ContributionException, IOException {
+
+        return addContribution(contributionURI, sourceURL, input, modelResolver, true);
+    }
+
+    public Contribution getContribution(String uri) {
+        return this.contributionRepository.getContribution(uri);
+    }
+
+    /**
+     * Remove a contribution and notify listener that contribution was removed
+     */
+    public void remove(String uri) throws ContributionException {
+        Contribution contribution = contributionRepository.getContribution(uri);
+        this.contributionRepository.removeContribution(contribution);
+        this.contributionListener.contributionRemoved(this.contributionRepository, contribution);
+    }
+
+    /**
+     * Add a composite model to the contribution
+     */
+    public void addDeploymentComposite(Contribution contribution, Composite composite) throws ContributionException {
+        Artifact artifact = this.contributionFactory.createArtifact();
+        artifact.setURI(composite.getURI());
+        artifact.setModel(composite);
+
+        contribution.getArtifacts().add(artifact);
+
+        contribution.getDeployables().add(composite);
+    }
+
+    /**
+     * Utility/Helper methods for contribution service
+     */
+
+    /**
+     * Perform read of the contribution metadata loader (sca-contribution.xml and sca-contribution-generated.xml)
+     * When the two metadata files are available, the information provided are merged, and the sca-contribution has priorities
+     * 
+     * @param sourceURL
+     * @return Contribution
+     * @throws ContributionException
+     */
+    private Contribution readContributionMetadata(URL sourceURL) throws ContributionException {
+        Contribution contributionMetadata = contributionFactory.createContribution();
+
+        ContributionMetadataDocumentProcessor metadataDocumentProcessor =
+            new ContributionMetadataDocumentProcessor(staxProcessor, xmlFactory);
+        
+       /* final URL[] urls = {sourceURL};
+        // Allow access to create classloader. Requires RuntimePermission in security policy.
+        URLClassLoader cl = AccessController.doPrivileged(new PrivilegedAction<URLClassLoader>() {
+            public URLClassLoader run() {
+                return new URLClassLoader(urls, null);
+            }
+        });           
+        for (String path: new String[]{
+                                       Contribution.SCA_CONTRIBUTION_GENERATED_META,
+                                       Contribution.SCA_CONTRIBUTION_META}) {
+            URL url = cl.getResource(path);
+            if (url != null) {
+                Contribution contribution = metadataDocumentProcessor.read(sourceURL, URI.create(path), url);
+                contributionMetadata.getImports().addAll(contribution.getImports());
+                contributionMetadata.getExports().addAll(contribution.getExports());
+                contributionMetadata.getDeployables().addAll(contribution.getDeployables());
+            }
+        }*/
+        
+        // For debugging purposes, write it back to XML
+        //        if (contributionMetadata != null) {
+        //            try {
+        //                ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        //                XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
+        //                outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
+        //                staxProcessor.write(contributionMetadata, outputFactory.createXMLStreamWriter(bos));
+        //                Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(bos.toByteArray()));
+        //                OutputFormat format = new OutputFormat();
+        //                format.setIndenting(true);
+        //                format.setIndent(2);
+        //                XMLSerializer serializer = new XMLSerializer(System.out, format);
+        //                serializer.serialize(document);
+        //            } catch (Exception e) {
+        //                e.printStackTrace();
+        //            }
+        //        }
+
+        return contributionMetadata;
+    }
+
+    /**
+     * Note:
+     * 
+     * @param contributionURI ContributionID
+     * @param sourceURL contribution location
+     * @param contributionStream contribution content
+     * @param storeInRepository flag if we store the contribution into the
+     *            repository or not
+     * @return the contribution model representing the contribution 
+     * @throws IOException
+     * @throws DeploymentException
+     */
+    private Contribution addContribution(String contributionURI,
+                                         URL sourceURL,
+                                         InputStream contributionStream,
+                                         ModelResolver modelResolver,
+                                         boolean storeInRepository) throws IOException, ContributionException {
+
+        if (contributionStream == null && sourceURL == null) {
+            throw new IllegalArgumentException("The content of the contribution is null.");
+        }
+
+        // store the contribution in the contribution repository
+        URL locationURL = sourceURL;
+        if (contributionRepository != null && storeInRepository) {
+            if (contributionStream == null) {
+                locationURL = contributionRepository.store(contributionURI, sourceURL);
+            } else {
+                locationURL = contributionRepository.store(contributionURI, sourceURL, contributionStream);
+            }
+        }
+
+        //initialize contribution based on it's metadata if available
+        Contribution contribution = readContributionMetadata(locationURL);
+
+        // Create contribution model resolver
+        if (modelResolver == null) {
+            //FIXME Remove this domain resolver, visibility of policy declarations should be handled by
+            // the contribution import/export mechanism instead of this domainResolver hack.
+            modelResolver = new ExtensibleModelResolver(contribution, modelResolvers, modelFactories, domainResolver);
+        }
+
+        //set contribution initial information
+        contribution.setURI(contributionURI.toString());
+        contribution.setLocation(locationURL.toString());
+        contribution.setModelResolver(modelResolver);
+        
+        List<URI> contributionArtifacts = null;
+
+        //NOTE: if a contribution is stored on the repository
+        //the stream would be consumed at this point
+        if (storeInRepository || contributionStream == null) {
+            URLConnection connection = sourceURL.openConnection();
+            connection.setUseCaches(false);
+            // Allow access to open URL stream. Add FilePermission to added to security policy file.
+            final URLConnection finalConnection = connection;
+            try {
+                contributionStream = AccessController.doPrivileged(new PrivilegedExceptionAction<InputStream>() {
+                    public InputStream run() throws IOException {
+                        return finalConnection.getInputStream();
+                    }
+                });
+            } catch (PrivilegedActionException e) {
+                throw (IOException)e.getException();
+            }
+            
+            try {
+                // process the contribution
+                contributionArtifacts = this.packageProcessor.getArtifacts(locationURL, contributionStream);
+            } finally {
+                IOHelper.closeQuietly(contributionStream);
+                contributionStream = null;
+            }
+        } else {
+            // process the contribution
+            contributionArtifacts = this.packageProcessor.getArtifacts(locationURL, contributionStream);
+        }
+        
+        // Read all artifacts in the contribution
+        try {
+        	// Allow access to read system properties. Requires PropertyPermission in security policy.
+        	// Any security exceptions are caught and wrapped as ContributionException.
+            processReadPhase(contribution, contributionArtifacts);
+        } catch ( Exception e ) {
+            throw new ContributionException(e);
+        }
+
+        //
+        this.contributionListener.contributionAdded(this.contributionRepository, contribution);
+
+        // Resolve them
+        processResolvePhase(contribution);
+
+        // Add all composites under META-INF/sca-deployables to the
+        // list of deployables
+        String prefix = Contribution.SCA_CONTRIBUTION_DEPLOYABLES;
+        for (Artifact artifact : contribution.getArtifacts()) {
+            if (artifact.getModel() instanceof Composite) {
+                if (artifact.getURI().startsWith(prefix)) {
+                    Composite composite = (Composite)artifact.getModel();
+                    if (!contribution.getDeployables().contains(composite)) {
+                        contribution.getDeployables().add(composite);
+                    }
+                }
+            }
+        }
+
+        // store the contribution on the registry
+        this.contributionRepository.addContribution(contribution);
+
+        return contribution;
+    }
+
+    /**
+     * This utility method process each artifact and delegates to proper 
+     * artifactProcessor to read the model and generate the in-memory representation
+     *  
+     * @param contribution
+     * @param artifacts
+     * @throws ContributionException
+     * @throws MalformedURLException
+     */
+    private void processReadPhase(Contribution contribution, List<URI> artifacts) throws ContributionException,
+        MalformedURLException, XMLStreamException {
+
+        ModelResolver modelResolver = contribution.getModelResolver();
+        URL contributionURL = new URL(contribution.getLocation());
+        
+        List<URI> compositeUris = new ArrayList<URI>();
+        
+        Object model = null;
+        for (URI anArtifactUri : artifacts) {
+            if ( anArtifactUri.toString().endsWith(COMPOSITE_FILE_EXTN)) {
+                compositeUris.add(anArtifactUri);
+            } else {
+                URL artifactURL = packageProcessor.getArtifactURL(new URL(contribution.getLocation()), anArtifactUri);
+
+                // Add the deployed artifact model to the resolver
+                Artifact artifact = this.contributionFactory.createArtifact();
+                artifact.setURI(anArtifactUri.toString());
+                artifact.setLocation(artifactURL.toString());
+                contribution.getArtifacts().add(artifact);
+                modelResolver.addModel(artifact);
+                
+                model = this.artifactProcessor.read(contributionURL, anArtifactUri, artifactURL);
+                
+                if (model != null) {
+                    artifact.setModel(model);
+
+                    // Add the loaded model to the model resolver
+                    modelResolver.addModel(model);
+                    
+                    if ( isSCADefnsFile(anArtifactUri) ) {
+                        scaDefinitionsSink.add(model);
+                    }
+                }
+            }
+        }
+        
+        for (URI anArtifactUri : compositeUris) {
+            URL artifactURL = packageProcessor.getArtifactURL(new URL(contribution.getLocation()), anArtifactUri);
+
+            // Add the deployed artifact model to the resolver
+            Artifact artifact = this.contributionFactory.createArtifact();
+            artifact.setURI(anArtifactUri.toString());
+            artifact.setLocation(artifactURL.toString());
+            contribution.getArtifacts().add(artifact);
+            modelResolver.addModel(artifact);
+            
+            model = this.artifactProcessor.read(contributionURL, anArtifactUri, artifactURL);
+            if (model != null) {
+                artifact.setModel(model);
+                // Add the loaded model to the model resolver
+                modelResolver.addModel(model);
+            }
+        }
+    }
+
+    /**
+     * This utility method process each artifact and delegates to proper 
+     * artifactProcessor to resolve the model references
+     * 
+     * @param contribution
+     * @throws ContributionException
+     */
+    @SuppressWarnings("unchecked")
+    private void processResolvePhase(Contribution contribution) throws ContributionException {
+        List<Artifact> composites = new ArrayList<Artifact>();
+
+        // for each artifact that was processed on the contribution
+        for (Artifact artifact : contribution.getArtifacts()) {
+            //leave the composites to be resolved at the end
+            if (artifact.getURI().endsWith(".composite")) {
+                composites.add(artifact);
+            } else {
+                // resolve the model object
+                if (artifact.getModel() != null) {
+                    this.artifactProcessor.resolve(artifact.getModel(), contribution.getModelResolver());
+                }
+            }
+        }
+
+        //process each composite file
+        for (Artifact artifact : composites) {
+            // resolve the model object
+            if (artifact.getModel() != null) {
+                // System.out.println("Processing Resolve Phase : " + artifact.getURI());
+                this.artifactProcessor.resolve(artifact.getModel(), contribution.getModelResolver());
+            }
+        }
+
+        //resolve deployables from contribution metadata
+        List<Composite> resolvedDeployables = new ArrayList<Composite>();
+        for (Composite deployableComposite : contribution.getDeployables()) {
+            Composite resolvedDeployable =
+                contribution.getModelResolver().resolveModel(Composite.class, deployableComposite);
+
+            resolvedDeployables.add(resolvedDeployable);
+        }
+        contribution.getDeployables().clear();
+        contribution.getDeployables().addAll(resolvedDeployables);
+    }
+
+    private boolean isSCADefnsFile(URI uri) {
+        int index = uri.toString().lastIndexOf("/");
+
+        index = (index != -1) ? index + 1 : 0;
+
+        return uri.toString().substring(index).equals("definitions.xml");
+    }
+}

Added: incubator/tuscany/sandbox/mobile-android/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/PackageTypeDescriberImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/PackageTypeDescriberImpl.java?rev=648628&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/PackageTypeDescriberImpl.java (added)
+++ incubator/tuscany/sandbox/mobile-android/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/PackageTypeDescriberImpl.java Wed Apr 16 01:52:20 2008
@@ -0,0 +1,119 @@
+/*
+ * 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.contribution.service.impl;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.sca.contribution.PackageType;
+import org.apache.tuscany.sca.contribution.service.TypeDescriber;
+import org.apache.tuscany.sca.contribution.service.util.FileHelper;
+
+/**
+ * Implementation of the content describer for contribution packages
+ * 
+ * @version $Rev: 641645 $ $Date: 2008-03-26 15:37:28 -0800 (Wed, 26 Mar 2008) $
+ */
+public class PackageTypeDescriberImpl implements TypeDescriber {
+    private final Map<String, String> contentTypeRegistry = new HashMap<String, String>();
+
+    public PackageTypeDescriberImpl() {
+        super();
+        init();
+    }
+
+    /**
+     * Initialize contentType registry with know types based on known file extensions
+     */
+    private void init() {
+        contentTypeRegistry.put("JAR", PackageType.JAR);
+        contentTypeRegistry.put("WAR", PackageType.JAR);
+    }
+
+    protected String resolveContentyTypeByExtension(URL resourceURL) {
+        String artifactExtension = FileHelper.getExtension(resourceURL.getPath());
+        if (artifactExtension == null) {
+            return null;
+        }
+        return contentTypeRegistry.get(artifactExtension.toUpperCase());
+    }
+
+    /**
+     * Build contentType for a specific resource. We first check if the file is a supported one
+     * (looking into our registry based on resource extension) If not found, we try to check file
+     * contentType Or we return defaultContentType provided
+     * 
+     * @param resourceURL The artifact URL
+     * @param defaultContentType The default content type if we can't find the correct one
+     * @return The content type
+     */
+    public String getType(URL resourceURL, String defaultContentType) {
+        URLConnection connection = null;
+        String contentType = defaultContentType;
+        final String urlProtocol = resourceURL.getProtocol();
+
+        if (urlProtocol.equals("file")) {
+            final File fileOrDir = FileHelper.toFile(resourceURL);
+            // Allow privileged access to test file. Requires FilePermissions in security policy.
+            Boolean isDirectory = AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
+                public Boolean run() {
+                    return fileOrDir.isDirectory();
+                }
+            });
+            if (isDirectory) {
+                // Special case : contribution is a folder
+                contentType = PackageType.FOLDER;
+            }
+            String fileName = resourceURL.toString();
+            String fileExt = fileName.substring(fileName.lastIndexOf('.')+1, fileName.length());
+            if ( fileExt.equalsIgnoreCase( "JAR" ) )
+                return PackageType.JAR;
+        } else if (urlProtocol.equals("bundle") || urlProtocol.equals("bundleresource")) {
+            contentType = PackageType.BUNDLE;
+        } else {
+            contentType = resolveContentyTypeByExtension(resourceURL);
+            if (contentType == null) {
+                try {
+                    connection = resourceURL.openConnection();
+                    connection.setUseCaches(false);
+                    contentType = connection.getContentType();
+
+                    if (contentType == null || contentType.equals("content/unknown")) {
+                        // here we couldn't figure out from our registry or from URL and it's not a
+                        // special file
+                        // return defaultContentType if provided
+                        contentType = defaultContentType;
+                    }
+                } catch (IOException io) {
+                    // could not access artifact, just ignore and we will return
+                    // null contentType
+                }
+            }
+        }
+        return contentType == null ? defaultContentType : contentType;
+    }
+
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org