From f4e3e383071b6947d56794d9af5e9e6438aa3235 Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Mon, 15 Sep 2008 00:17:09 +0000 Subject: Temporarily renamed sca-android branch to pull a recent revision of trunk into sca-android. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@695316 13f79535-47bb-0310-9956-ffa450edef68 --- .../processor/impl/DexContributionProcessor.java | 124 +++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 branches/sca-android-r643746/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/DexContributionProcessor.java (limited to 'branches/sca-android-r643746/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/DexContributionProcessor.java') diff --git a/branches/sca-android-r643746/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/DexContributionProcessor.java b/branches/sca-android-r643746/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/DexContributionProcessor.java new file mode 100644 index 0000000000..83c209180d --- /dev/null +++ b/branches/sca-android-r643746/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/DexContributionProcessor.java @@ -0,0 +1,124 @@ +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.URISyntaxException; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; + +import javax.xml.namespace.QName; +import javax.xml.stream.FactoryConfigurationError; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.android.DexResource; +import org.apache.tuscany.sca.contribution.processor.PackageProcessor; +import org.apache.tuscany.sca.contribution.service.ContributionException; + +public class DexContributionProcessor implements PackageProcessor { + + public URL getArtifactURL(URL packageSourceURL, URI artifact) + throws MalformedURLException { + return new URL(artifact.toString()); + } + + public List getArtifacts(URL packageSourceURL, InputStream inputStream) + throws ContributionException, IOException { + + ArrayList uris = new ArrayList(); + DexResource res = new DexResource(packageSourceURL); + + URI[] contentFiles = res.getContentFiles(); + + for (URI uri : contentFiles) { + String fileName = DexResource.getFile(uri.getPath()); + URL url = uri.toURL(); + + if (fileName != null) { + + if (fileName.endsWith("_composite")) { + + url.openConnection(); + try { + XMLStreamReader r = XMLInputFactory.newInstance() + .createXMLStreamReader(url.openStream()); + + while (r.hasNext()) { + + if (r.isStartElement()) { + QName name = r.getName(); + + if ("implementation.java".equals(name + .getLocalPart())) { + int attributeCount = r.getAttributeCount(); + + for (int i = 0; i < attributeCount; i++) { + + if (r.getAttributeLocalName(i).equals( + "class")) { + StringBuffer sb = new StringBuffer( + "dex://"); + sb.append( + r.getAttributeValue(i) + .replace('.', '/')) + .append(".class"); + + try { + uris + .add(new URI(sb + .toString())); + } catch (URISyntaxException e) { + } + + break; + + } + + } + + } + + } + + r.next(); + + } + + } catch (XMLStreamException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } catch (FactoryConfigurationError e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + StringBuffer sb = new StringBuffer("dex://"); + sb.append(url.getHost()).append(url.getPath()); + sb.delete(sb.length() - 10, sb.length()).append( + ".composite"); + + try { + uris.add(new URI(sb.toString())); + } catch (URISyntaxException e) { + continue; + } + + } + + } + + } + + return uris; + + } + + public String getPackageType() { + return "application/x-dex"; + } + +} -- cgit v1.2.3