aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From z..@apache.org
Subject svn commit: r1075132 [8/18] - in /aries/tags/application-0.3: ./ application-api/ application-api/src/ application-api/src/main/ application-api/src/main/java/ application-api/src/main/java/org/ application-api/src/main/java/org/apache/ application-api...
Date Sun, 27 Feb 2011 20:20:30 GMT
Added: aries/tags/application-0.3/application-management/src/main/java/org/apache/aries/application/management/impl/AriesApplicationManagerImpl.java
URL: http://svn.apache.org/viewvc/aries/tags/application-0.3/application-management/src/main/java/org/apache/aries/application/management/impl/AriesApplicationManagerImpl.java?rev=1075132&view=auto
==============================================================================
--- aries/tags/application-0.3/application-management/src/main/java/org/apache/aries/application/management/impl/AriesApplicationManagerImpl.java (added)
+++ aries/tags/application-0.3/application-management/src/main/java/org/apache/aries/application/management/impl/AriesApplicationManagerImpl.java Sun Feb 27 20:20:13 2011
@@ -0,0 +1,406 @@
+/*
+ * 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 WARRANTIESOR 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.aries.application.management.impl;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URL;
+import java.util.Collections;
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.jar.Manifest;
+
+import org.apache.aries.application.ApplicationMetadata;
+import org.apache.aries.application.ApplicationMetadataFactory;
+import org.apache.aries.application.DeploymentMetadata;
+import org.apache.aries.application.DeploymentMetadataFactory;
+import org.apache.aries.application.filesystem.IDirectory;
+import org.apache.aries.application.filesystem.IFile;
+import org.apache.aries.application.management.AriesApplication;
+import org.apache.aries.application.management.AriesApplicationContext;
+import org.apache.aries.application.management.AriesApplicationListener;
+import org.apache.aries.application.management.AriesApplicationManager;
+import org.apache.aries.application.management.BundleInfo;
+import org.apache.aries.application.management.ManagementException;
+import org.apache.aries.application.management.ResolveConstraint;
+import org.apache.aries.application.management.ResolverException;
+import org.apache.aries.application.management.UpdateException;
+import org.apache.aries.application.management.internal.MessageUtil;
+import org.apache.aries.application.management.repository.ApplicationRepository;
+import org.apache.aries.application.management.spi.convert.BundleConversion;
+import org.apache.aries.application.management.spi.convert.BundleConverter;
+import org.apache.aries.application.management.spi.convert.ConversionException;
+import org.apache.aries.application.management.spi.repository.BundleRepository;
+import org.apache.aries.application.management.spi.resolve.DeploymentManifestManager;
+import org.apache.aries.application.management.spi.runtime.AriesApplicationContextManager;
+import org.apache.aries.application.management.spi.runtime.LocalPlatform;
+import org.apache.aries.application.utils.AppConstants;
+import org.apache.aries.application.utils.filesystem.FileSystem;
+import org.apache.aries.application.utils.filesystem.IOUtils;
+import org.apache.aries.application.utils.management.SimpleBundleInfo;
+import org.apache.aries.application.utils.manifest.BundleManifest;
+import org.apache.aries.application.utils.manifest.ManifestDefaultsInjector;
+import org.apache.aries.application.utils.manifest.ManifestProcessor;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceException;
+import org.osgi.framework.ServiceReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class AriesApplicationManagerImpl implements AriesApplicationManager {
+
+  private ApplicationMetadataFactory _applicationMetadataFactory;
+  private DeploymentMetadataFactory _deploymentMetadataFactory;
+  private List<BundleConverter> _bundleConverters;
+
+  private LocalPlatform _localPlatform;
+  private AriesApplicationContextManager _applicationContextManager;
+  private BundleContext _bundleContext;
+
+  private DeploymentManifestManager deploymentManifestManager;
+  
+  private static final Logger _logger = LoggerFactory.getLogger("org.apache.aries.application.management.impl");
+
+  public void setApplicationMetadataFactory (ApplicationMetadataFactory amf) { 
+    _applicationMetadataFactory = amf;
+  }
+  
+  public void setDeploymentMetadataFactory (DeploymentMetadataFactory dmf) { 
+    _deploymentMetadataFactory = dmf;
+  }
+  
+  public void setBundleConverters (List<BundleConverter> bcs) { 
+    _bundleConverters = bcs;
+  }
+  
+  public void setDeploymentManifestManager(DeploymentManifestManager dm) {
+    this.deploymentManifestManager = dm;
+  }
+
+  public void setLocalPlatform (LocalPlatform lp) { 
+    _localPlatform = lp;
+  }
+  
+  public void setApplicationContextManager (AriesApplicationContextManager acm) { 
+    _applicationContextManager = acm;
+  }
+  
+  public void setBundleContext(BundleContext b)
+  {
+    _bundleContext = b;
+  }
+  
+  
+  /**
+   * Create an AriesApplication from a .eba file: a zip file with a '.eba' extension
+   */
+  public AriesApplication createApplication(IDirectory ebaFile) throws ManagementException {
+    ApplicationMetadata applicationMetadata = null;
+    DeploymentMetadata deploymentMetadata = null;
+    Map<String, BundleConversion> modifiedBundles = new HashMap<String, BundleConversion>();
+    AriesApplicationImpl application = null;
+    String appPath = ebaFile.toString();
+    try {   
+      // try to read the app name out of the application.mf
+      Manifest applicationManifest = parseApplicationManifest (ebaFile);
+      String appName = applicationManifest.getMainAttributes().getValue(AppConstants.APPLICATION_NAME);
+
+      //If the application name is null, we will try to get the file name.
+      if (appName == null || appName.isEmpty()) {
+          String fullPath = appPath;
+          if (fullPath.endsWith("/")) {
+            fullPath = fullPath.substring(0, fullPath.length() -1);  
+          }
+              
+          int last_slash = fullPath.lastIndexOf("/");
+          appName = fullPath.substring(last_slash + 1, fullPath.length()); 
+      }
+                  
+      IFile deploymentManifest = ebaFile.getFile(AppConstants.DEPLOYMENT_MF);
+      /* We require that all other .jar and .war files included by-value be valid bundles
+       * because a DEPLOYMENT.MF has been provided. If no DEPLOYMENT.MF, migrate 
+       * wars to wabs, plain jars to bundles
+       */
+      Set<BundleInfo> extraBundlesInfo = new HashSet<BundleInfo>();
+      for (IFile f : ebaFile) { 
+        if (f.isDirectory()) { 
+          continue;
+        }
+        BundleManifest bm = getBundleManifest (f);
+        if (bm != null) {
+          if (bm.isValid()) {
+            extraBundlesInfo.add(new SimpleBundleInfo(bm, f.toURL().toExternalForm()));
+          } else if (deploymentManifest == null) { 
+            // We have a jar that needs converting to a bundle, or a war to migrate to a WAB 
+            // We only do this if a DEPLOYMENT.MF does not exist.
+            BundleConversion convertedBinary = null;
+            Iterator<BundleConverter> converters = _bundleConverters.iterator();
+            List<ConversionException> conversionExceptions = Collections.emptyList();
+            while (converters.hasNext() && convertedBinary == null) { 
+              try {
+                convertedBinary = converters.next().convert(ebaFile, f);
+              } catch (ServiceException sx) {
+                // We'll get this if our optional BundleConverter has not been injected. 
+              } catch (ConversionException cx) { 
+                conversionExceptions.add(cx);
+              }
+            }
+            if (conversionExceptions.size() > 0) {
+              for (ConversionException cx : conversionExceptions) { 
+                _logger.error("APPMANAGEMENT0004E", new Object[]{f.getName(), appName, cx});
+              }
+              throw new ManagementException (MessageUtil.getMessage("APPMANAGEMENT0005E", appName));
+            }
+            if (convertedBinary != null) { 
+              modifiedBundles.put (f.getName(), convertedBinary);             
+              extraBundlesInfo.add(convertedBinary.getBundleInfo());
+            } 
+          }
+        } 
+      }
+ 
+      // if Application-Content header was not specified build it based on the bundles included by value
+      if (applicationManifest.getMainAttributes().getValue(AppConstants.APPLICATION_CONTENT) == null) {
+          String appContent = buildAppContent(extraBundlesInfo);
+          applicationManifest.getMainAttributes().putValue(AppConstants.APPLICATION_CONTENT, appContent);
+      }
+      
+      ManifestDefaultsInjector.updateManifest(applicationManifest, appName, ebaFile); 
+      applicationMetadata = _applicationMetadataFactory.createApplicationMetadata(applicationManifest);
+      
+      if (deploymentManifest != null) { 
+        deploymentMetadata = _deploymentMetadataFactory.parseDeploymentMetadata(deploymentManifest);
+        
+        // Validate: symbolic names must match
+        String appSymbolicName = applicationMetadata.getApplicationSymbolicName();
+        String depSymbolicName = deploymentMetadata.getApplicationSymbolicName();
+        if (!appSymbolicName.equals(depSymbolicName)) {
+          throw new ManagementException (MessageUtil.getMessage("APPMANAGEMENT0002E", appName, appSymbolicName, depSymbolicName));
+        }
+      }
+
+      application = new AriesApplicationImpl (applicationMetadata, extraBundlesInfo, _localPlatform);
+      application.setDeploymentMetadata(deploymentMetadata);
+      // Store a reference to any modified bundles
+      application.setModifiedBundles (modifiedBundles);
+    } catch (IOException iox) {
+      _logger.error ("APPMANAGEMENT0006E", new Object []{appPath, iox});
+      throw new ManagementException(iox);
+    }
+    return application;
+  }
+
+  private String buildAppContent(Set<BundleInfo> bundleInfos) {
+      StringBuilder builder = new StringBuilder();
+      Iterator<BundleInfo> iterator = bundleInfos.iterator();
+      while (iterator.hasNext()) {
+          BundleInfo info = iterator.next();
+          builder.append(info.getSymbolicName());
+
+          // bundle version is not a required manifest header
+          if (info.getVersion() != null) {
+              String version = info.getVersion().toString();
+              builder.append(";version=\"[");
+              builder.append(version);
+              builder.append(',');
+              builder.append(version);
+              builder.append("]\"");
+          }
+
+          if (iterator.hasNext()) {
+              builder.append(",");
+          }
+      }
+      return builder.toString();
+  }
+  
+  /**
+   * Create an application from a URL. 
+   * The first version of this method isn't smart enough to check whether
+   * the input URL is file://
+   */
+  public AriesApplication createApplication(URL url) throws ManagementException {
+    OutputStream os = null;
+    AriesApplication app = null;
+    try { 
+      File tempFile = _localPlatform.getTemporaryFile();
+      InputStream is = url.openStream();
+      os = new FileOutputStream (tempFile);
+      IOUtils.copy(is, os);
+      IDirectory downloadedSource = FileSystem.getFSRoot(tempFile);
+      app = createApplication (downloadedSource);
+    } catch (IOException iox) {
+      throw new ManagementException (iox);
+    }
+      finally { 
+      IOUtils.close(os);
+    }
+    return app;
+  }
+
+  public AriesApplication resolve(AriesApplication originalApp, ResolveConstraint... constraints) throws ResolverException {
+    AriesApplicationImpl application = new AriesApplicationImpl(originalApp.getApplicationMetadata(), originalApp.getBundleInfo(), _localPlatform);
+    Manifest deploymentManifest = deploymentManifestManager.generateDeploymentManifest(originalApp, constraints);
+    try {
+      application.setDeploymentMetadata(_deploymentMetadataFactory.createDeploymentMetadata(deploymentManifest));
+    } catch (IOException ioe) {
+      throw new ResolverException(ioe);
+    }
+    // Store a reference to any modified bundles
+    if (originalApp instanceof AriesApplicationImpl) {
+      // TODO: are we really passing streams around ?
+      application.setModifiedBundles(((AriesApplicationImpl) originalApp).getModifiedBundles());
+    }
+    return application;
+  } 
+
+  public AriesApplicationContext install(AriesApplication app) throws BundleException, ManagementException, ResolverException {
+    
+    if (!app.isResolved()) {
+      app = resolve(app);
+    }
+  
+    // Register an Application Repository for this application if none exists
+    String appScope = app.getApplicationMetadata().getApplicationScope();    
+    ServiceReference[] ref = null;
+    try {
+        String filter = "(" + BundleRepository.REPOSITORY_SCOPE + "=" + appScope + ")";
+        ref = _bundleContext.getServiceReferences(BundleRepository.class.getName(),filter);
+    } 
+    catch (InvalidSyntaxException e) {
+        // Something went wrong attempting to find a service so we will act as if 
+        // there is no existing service.
+    }
+    
+    if (ref == null || ref.length == 0) {
+        Dictionary dict = new Hashtable();
+        dict.put(BundleRepository.REPOSITORY_SCOPE, appScope);
+        _bundleContext.registerService(BundleRepository.class.getName(), 
+            new ApplicationRepository(app), 
+            dict);
+    }
+  
+    AriesApplicationContext result = _applicationContextManager.getApplicationContext(app);
+    return result;
+  }
+  
+  public void uninstall(AriesApplicationContext app) throws BundleException 
+  {
+    _applicationContextManager.remove(app);
+  }
+
+  public void addApplicationListener(AriesApplicationListener l) {
+    // Need application listener lifecycle support
+  }
+
+  public void removeApplicationListener(AriesApplicationListener l) {
+    // TODO Auto-generated method stub
+
+  }
+
+
+
+  /**
+   * Locate and parse an application.mf in an eba
+   * @param source An aries application file
+   * @return parsed manifest, or an empty Manifest
+   * @throws IOException
+   */
+  private Manifest parseApplicationManifest (IDirectory source) throws IOException {
+    Manifest result = new Manifest();
+    IFile f = source.getFile(AppConstants.APPLICATION_MF);
+    if (f != null) { 
+      InputStream is = null;
+      try { 
+        is = f.open();
+        result = ManifestProcessor.parseManifest(is);
+      } catch (IOException iox) { 
+        _logger.error ("APPMANAGEMENT0007E", new Object[]{source.getName(), iox});
+        throw iox;
+      } finally { 
+        IOUtils.close(is);
+      }
+    }
+    return result;
+  }
+  
+  /**
+   * Extract a bundle manifest from an IFile representing a bundle
+   * @param file The bundle to extract the manifest from
+   * @return bundle manifest
+   */
+  private BundleManifest getBundleManifest(IFile file) throws IOException {
+    BundleManifest mf = null;
+    InputStream in = null;
+    try { 
+      in = file.open();
+      mf = BundleManifest.fromBundle(in);
+    } finally { 
+      IOUtils.close(in);
+    }    
+    return mf;
+  }
+
+  public AriesApplicationContext update(AriesApplication app, DeploymentMetadata depMf) throws UpdateException {
+    if (!(app instanceof AriesApplicationImpl)) throw new IllegalArgumentException("Argument is not AriesApplication created by this manager");
+    
+    if (!!!app.getApplicationMetadata().getApplicationSymbolicName().equals(depMf.getApplicationSymbolicName())
+        || !!!app.getApplicationMetadata().getApplicationVersion().equals(depMf.getApplicationVersion())) {
+      throw new IllegalArgumentException("The deployment metadata does not match the application.");
+    }
+    
+    DeploymentMetadata oldMetadata = app.getDeploymentMetadata();
+    
+    AriesApplicationContext foundCtx = null;
+    for (AriesApplicationContext ctx : _applicationContextManager.getApplicationContexts()) {
+      if (ctx.getApplication().equals(app)) {
+        foundCtx = ctx;
+        break;
+      }
+    }
+    
+    ((AriesApplicationImpl) app).setDeploymentMetadata(depMf);
+    
+    if (foundCtx != null) {
+      try {
+        return _applicationContextManager.update(app, oldMetadata);
+      } catch (UpdateException ue) {
+        if (ue.hasRolledBack()) {
+          ((AriesApplicationImpl) app).setDeploymentMetadata(oldMetadata);
+        }
+        
+        throw ue;
+      }
+    } else {
+      return null;
+    }
+  }
+}

Added: aries/tags/application-0.3/application-management/src/main/java/org/apache/aries/application/management/internal/MessageUtil.java
URL: http://svn.apache.org/viewvc/aries/tags/application-0.3/application-management/src/main/java/org/apache/aries/application/management/internal/MessageUtil.java?rev=1075132&view=auto
==============================================================================
--- aries/tags/application-0.3/application-management/src/main/java/org/apache/aries/application/management/internal/MessageUtil.java (added)
+++ aries/tags/application-0.3/application-management/src/main/java/org/apache/aries/application/management/internal/MessageUtil.java Sun Feb 27 20:20:13 2011
@@ -0,0 +1,46 @@
+/*
+ * 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 WARRANTIESOR 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.aries.application.management.internal;
+
+import java.text.MessageFormat;
+import java.util.ResourceBundle;
+
+public class MessageUtil
+{
+  /** The resource bundle for blueprint messages */
+  private final static ResourceBundle messages = ResourceBundle.getBundle("org.apache.aries.application.management.messages.AppManagementMessages");
+  
+  /**
+   * Resolve a message from the bundle, including any necessary formatting.
+   * 
+   * @param key     the message key.
+   * @param inserts any required message inserts.
+   * @return        the message translated into the server local.
+   */
+  public static final String getMessage(String key, Object ... inserts)
+  {
+    String msg = messages.getString(key);
+    
+    if (inserts.length > 0)
+      msg = MessageFormat.format(msg, inserts);
+    
+    return msg;
+  }
+}

Added: aries/tags/application-0.3/application-management/src/main/java/org/apache/aries/application/management/repository/ApplicationRepository.java
URL: http://svn.apache.org/viewvc/aries/tags/application-0.3/application-management/src/main/java/org/apache/aries/application/management/repository/ApplicationRepository.java?rev=1075132&view=auto
==============================================================================
--- aries/tags/application-0.3/application-management/src/main/java/org/apache/aries/application/management/repository/ApplicationRepository.java (added)
+++ aries/tags/application-0.3/application-management/src/main/java/org/apache/aries/application/management/repository/ApplicationRepository.java Sun Feb 27 20:20:13 2011
@@ -0,0 +1,124 @@
+/*
+ * 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 WARRANTIESOR 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.aries.application.management.repository;
+
+import java.util.Set;
+
+import org.apache.aries.application.Content;
+import org.apache.aries.application.DeploymentContent;
+import org.apache.aries.application.management.AriesApplication;
+import org.apache.aries.application.management.BundleInfo;
+import org.apache.aries.application.management.spi.framework.BundleFramework;
+import org.apache.aries.application.management.spi.repository.BundleRepository;
+import org.apache.aries.application.management.spi.resolve.AriesApplicationResolver;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.Version;
+
+public class ApplicationRepository implements BundleRepository
+{
+  private static final int REPOSITORY_COST = 0;
+
+  private AriesApplication app;
+  AriesApplicationResolver resolver;
+
+  public ApplicationRepository(AriesApplication app)
+  {
+    this.app = app;
+  }
+  
+  public int getCost()
+  {
+    return REPOSITORY_COST;
+  }
+
+  public BundleSuggestion suggestBundleToUse(DeploymentContent content)
+  {
+    BundleInfo bundleInfo = null;
+    if ((app.getBundleInfo() != null) && (!app.getBundleInfo().isEmpty())) {
+      for (BundleInfo bi : app.getBundleInfo()) {
+        if (bi.getSymbolicName().equals(content.getContentName()) && (bi.getVersion().equals(content.getVersion().getExactVersion()))) {
+          bundleInfo = bi;
+          break;
+        }
+      }
+    }
+    
+    if (bundleInfo != null) {
+      return new BundleSuggestionImpl(bundleInfo);
+    } else {
+      return null;
+    }
+  }
+
+  private class BundleSuggestionImpl implements BundleSuggestion
+  {
+    private final BundleInfo bundleInfo;
+    
+    BundleSuggestionImpl(BundleInfo bundleInfo)
+    {
+      this.bundleInfo = bundleInfo;
+    }
+
+    public int getCost()
+    {
+      return REPOSITORY_COST;
+    }
+
+    public Set<Content> getExportPackage()
+    {
+      if (bundleInfo != null) {
+      return bundleInfo.getExportPackage();
+      } else {
+        return null;
+      }
+    }
+
+    public Set<Content> getImportPackage()
+    {
+      if (bundleInfo != null) {
+        return bundleInfo.getImportPackage();
+        } else {
+          return null;
+        }
+      
+    }
+
+    public Version getVersion() 
+    {
+      if (bundleInfo != null) {
+        return bundleInfo.getVersion();
+        } else {        	
+          return null;
+        }
+      
+    }
+
+    public Bundle install(BundleFramework framework, AriesApplication app) throws BundleException
+    {
+      if (bundleInfo != null ) {
+        return framework.getIsolatedBundleContext().installBundle(bundleInfo.getLocation());
+      } else {
+        throw new BundleException("Unable to install the bundle, as the BundleInfo is null.");
+      }
+    }
+    
+  }
+  
+}

Added: aries/tags/application-0.3/application-management/src/main/resources/OSGI-INF/blueprint/app-management.xml
URL: http://svn.apache.org/viewvc/aries/tags/application-0.3/application-management/src/main/resources/OSGI-INF/blueprint/app-management.xml?rev=1075132&view=auto
==============================================================================
--- aries/tags/application-0.3/application-management/src/main/resources/OSGI-INF/blueprint/app-management.xml (added)
+++ aries/tags/application-0.3/application-management/src/main/resources/OSGI-INF/blueprint/app-management.xml Sun Feb 27 20:20:13 2011
@@ -0,0 +1,43 @@
+<?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.
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+  
+  <bean id="app-manager" class="org.apache.aries.application.management.impl.AriesApplicationManagerImpl" scope="singleton" activation="lazy">
+    <property name="applicationMetadataFactory" ref="app-metadata-factory"/>
+    <property name="deploymentMetadataFactory" ref="deployment-metadata-factory"/>
+    <property name="bundleConverters" ref="bundle-converters"/>
+    <property name="deploymentManifestManager" ref="deploymentManifestManager"/>
+    <property name="localPlatform" ref="localPlatform"/>
+    <property name="applicationContextManager" ref="application-context-manager"/>
+    <property name="bundleContext" ref="blueprintBundleContext"/>
+  </bean>
+  
+  <reference id="app-metadata-factory" interface="org.apache.aries.application.ApplicationMetadataFactory"/>
+  <reference id="deployment-metadata-factory" interface="org.apache.aries.application.DeploymentMetadataFactory"/>
+  <reference-list id="bundle-converters" 
+                  interface="org.apache.aries.application.management.spi.convert.BundleConverter"
+                  availability="optional"/>
+  <reference id="deploymentManifestManager" interface="org.apache.aries.application.management.spi.resolve.DeploymentManifestManager"/>
+  <reference id="localPlatform" interface="org.apache.aries.application.management.spi.runtime.LocalPlatform"/>
+  <reference id="application-context-manager" interface="org.apache.aries.application.management.spi.runtime.AriesApplicationContextManager"/>
+    
+  <service interface="org.apache.aries.application.management.AriesApplicationManager" ref="app-manager" />
+  
+</blueprint>

Added: aries/tags/application-0.3/application-management/src/main/resources/org/apache/aries/application/messages/AppManagementMessages.properties
URL: http://svn.apache.org/viewvc/aries/tags/application-0.3/application-management/src/main/resources/org/apache/aries/application/messages/AppManagementMessages.properties?rev=1075132&view=auto
==============================================================================
--- aries/tags/application-0.3/application-management/src/main/resources/org/apache/aries/application/messages/AppManagementMessages.properties (added)
+++ aries/tags/application-0.3/application-management/src/main/resources/org/apache/aries/application/messages/AppManagementMessages.properties Sun Feb 27 20:20:13 2011
@@ -0,0 +1,25 @@
+#
+# 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.
+#
+APPMANAGEMENT0001E=APPMANAGEMENT0001E: Unable to fully delete directory {0}. 
+APPMANAGEMENT0002E=APPMANAGEMENT0002E: Unable to create Aries application from {0} since APPLICATION.MF symbolic name {1} does not equals DEPLOYMENT.MF symbolic name {2}.
+APPMANAGEMENT0004E=APPMANAGEMENT0004E: Exception caught when converting artifact {0} in {1}: {2}.
+APPMANAGEMENT0005E=APPMANAGEMENT0005E: Failed to create application from {0} due to conversion errors: see log for details.
+APPMANAGEMENT0006E=APPMANAGEMENT0006E: IOException encountered while constructing Aries application from {0}: {1}.
+APPMANAGEMENT0007E=APPMANAGEMENT0007E: IOException encountered while parsing APPICATION.MF in {0}: {1}. 
+APPMANAGEMENT0008E=APPMANAGEMENT0008E: ResolverException encountered while constructing Aries application from {0}: {1}.

Added: aries/tags/application-0.3/application-management/src/test/java/org/apache/aries/application/management/impl/AriesApplicationManagerImplTest.java
URL: http://svn.apache.org/viewvc/aries/tags/application-0.3/application-management/src/test/java/org/apache/aries/application/management/impl/AriesApplicationManagerImplTest.java?rev=1075132&view=auto
==============================================================================
--- aries/tags/application-0.3/application-management/src/test/java/org/apache/aries/application/management/impl/AriesApplicationManagerImplTest.java (added)
+++ aries/tags/application-0.3/application-management/src/test/java/org/apache/aries/application/management/impl/AriesApplicationManagerImplTest.java Sun Feb 27 20:20:13 2011
@@ -0,0 +1,523 @@
+/*
+ * 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 WARRANTIESOR 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.aries.application.management.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
+
+import org.apache.aries.application.ApplicationMetadata;
+import org.apache.aries.application.ApplicationMetadataFactory;
+import org.apache.aries.application.Content;
+import org.apache.aries.application.DeploymentContent;
+import org.apache.aries.application.DeploymentMetadata;
+import org.apache.aries.application.DeploymentMetadataFactory;
+import org.apache.aries.application.ServiceDeclaration;
+import org.apache.aries.application.filesystem.IDirectory;
+import org.apache.aries.application.filesystem.IFile;
+import org.apache.aries.application.impl.ApplicationMetadataFactoryImpl;
+import org.apache.aries.application.impl.ContentImpl;
+import org.apache.aries.application.impl.DeploymentContentImpl;
+import org.apache.aries.application.impl.DeploymentMetadataFactoryImpl;
+import org.apache.aries.application.management.AriesApplication;
+import org.apache.aries.application.management.AriesApplicationContext;
+import org.apache.aries.application.management.BundleInfo;
+import org.apache.aries.application.management.ManagementException;
+import org.apache.aries.application.management.ResolveConstraint;
+import org.apache.aries.application.management.ResolverException;
+import org.apache.aries.application.management.UpdateException;
+import org.apache.aries.application.management.spi.convert.BundleConversion;
+import org.apache.aries.application.management.spi.convert.BundleConverter;
+import org.apache.aries.application.management.spi.convert.ConversionException;
+import org.apache.aries.application.management.spi.repository.PlatformRepository;
+import org.apache.aries.application.management.spi.resolve.AriesApplicationResolver;
+import org.apache.aries.application.management.spi.resolve.DeploymentManifestManager;
+import org.apache.aries.application.management.spi.runtime.AriesApplicationContextManager;
+import org.apache.aries.application.management.spi.runtime.LocalPlatform;
+import org.apache.aries.application.modelling.DeployedBundles;
+import org.apache.aries.application.modelling.ModelledResource;
+import org.apache.aries.application.utils.AppConstants;
+import org.apache.aries.application.utils.filesystem.FileSystem;
+import org.apache.aries.application.utils.filesystem.IOUtils;
+import org.apache.aries.application.utils.management.SimpleBundleInfo;
+import org.apache.aries.application.utils.manifest.BundleManifest;
+import org.apache.aries.unittest.mocks.MethodCall;
+import org.apache.aries.unittest.mocks.Skeleton;
+import org.apache.aries.unittest.utils.EbaUnitTestUtils;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Version;
+
+/**
+ * Initial, simple test that creates and stores an AriesApplication. No
+ * BundleConverters are used in this test. 
+ */
+public class AriesApplicationManagerImplTest {
+  
+  static class DummyDMManager implements DeploymentManifestManager {
+
+    private AriesApplicationResolver resolver;
+    public Manifest generateDeploymentManifest(AriesApplication app,
+        ResolveConstraint... constraints) throws ResolverException
+    {
+      
+      Map<String, String> deploymentMap = new HashMap<String, String>();
+      Set<BundleInfo> byValueBundles = app.getBundleInfo();
+      StringBuilder deployedContents = new StringBuilder();
+      boolean beginning= true;
+      for (BundleInfo bundle: byValueBundles) {
+        if (!!!beginning) {
+          deployedContents.append(",");
+        }
+        deployedContents.append(bundle.getSymbolicName()+";" + AppConstants.DEPLOYMENT_BUNDLE_VERSION + "=" +  bundle.getVersion());
+        beginning = false;
+      }
+      deploymentMap.put(AppConstants.DEPLOYMENT_CONTENT, deployedContents.toString());
+      // fake the provision bundle now.
+      String persistenceLibraryLocation = "../src/test/resources/bundles/repository/a.handy.persistence.library.jar";
+      File persistenceLibrary = new File (persistenceLibraryLocation);
+      BundleManifest mf = BundleManifest.fromBundle(persistenceLibrary);
+      
+      deploymentMap.put(AppConstants.DEPLOYMENT_PROVISION_BUNDLE, mf.getSymbolicName()+";" + AppConstants.DEPLOYMENT_BUNDLE_VERSION + "=" + mf.getVersion());
+      deploymentMap.put(AppConstants.APPLICATION_SYMBOLIC_NAME, app.getApplicationMetadata().getApplicationSymbolicName());
+     
+      deploymentMap.put(AppConstants.APPLICATION_VERSION, app.getApplicationMetadata().getApplicationVersion().toString());
+      
+      
+      Manifest man = new Manifest();
+      Attributes att = man.getMainAttributes();
+      att.putValue(Attributes.Name.MANIFEST_VERSION.toString(), AppConstants.MANIFEST_VERSION);
+      for (Map.Entry<String, String> entry : deploymentMap.entrySet()) {
+        att.putValue(entry.getKey(),  entry.getValue());
+      }
+      return man;
+    }
+
+    public void setResolver(AriesApplicationResolver resolver) {
+      this.resolver = resolver;
+    }
+
+    public AriesApplicationResolver getResolver()
+    {
+      
+      return resolver;
+    }
+
+    public Manifest generateDeploymentManifest(String appName,
+        String appVersion, Collection<Content> appContent,
+        Collection<ModelledResource> byValueBundles,
+        Collection<Content> useBundleSet, Collection<Content> otherBundles,
+        Collection<ServiceDeclaration> appImportServices)
+        throws ResolverException {
+      return null;
+    }
+
+    public DeployedBundles generateDeployedBundles(ApplicationMetadata appMetadata,
+        Collection<ModelledResource> byValueBundles, Collection<Content> otherBundles)
+        throws ResolverException {
+      // Not required or used in this test
+      return null;
+    }
+
+    public Manifest generateDeploymentManifest(String appSymbolicName,
+        String appVersion, DeployedBundles deployedBundles)
+        throws ResolverException {
+      // Not required or used in this test
+      return null;
+    }
+  }
+
+  static class DummyResolver implements AriesApplicationResolver {
+    Set<BundleInfo> nextResult;
+    public Set<BundleInfo> resolve(AriesApplication app, ResolveConstraint... constraints) {
+      Set<BundleInfo> info = new HashSet<BundleInfo>(nextResult);
+      
+      info.addAll(app.getBundleInfo());
+      
+      return info;
+    } 
+    void setNextResult (Set<BundleInfo> r) { 
+      nextResult = r;
+    }
+    public BundleInfo getBundleInfo(String bundleSymbolicName, Version bundleVersion)
+    {
+      return null;
+    }
+    public Collection<ModelledResource> resolve(String appName, String appVersion,
+        Collection<ModelledResource> byValueBundles, Collection<Content> inputs)
+        throws ResolverException
+    {
+      
+      return byValueBundles;
+    }
+    
+	   public Collection<ModelledResource> resolve(String appName, String appVersion,
+		       Collection<ModelledResource> byValueBundles, Collection<Content> inputs, PlatformRepository platformRepository)
+		       throws ResolverException
+		   {
+		     
+		     return byValueBundles;
+		   }
+
+  }
+  
+  static class DummyLocalPlatform implements LocalPlatform {
+    public File getTemporaryDirectory() throws IOException {
+      File f = File.createTempFile("ebaTmp", null);
+      f.delete();
+      f.mkdir();
+      return f;
+    } 
+    public File getTemporaryFile () throws IOException { 
+      // Not used
+      return File.createTempFile("ebaTmp", null);
+    }
+  }
+  
+  static class DummyConverter implements BundleConverter {
+
+	public BundleConversion convert(IDirectory parentEba, IFile toBeConverted)
+			throws ConversionException {
+		if (toBeConverted.getName().equals("helloWorld.war")) {
+			InputStream is = null;
+            try {
+            	is = new FileInputStream(new File("../src/test/resources/conversion/MANIFEST.MF"));
+            	Manifest warManifest = new Manifest(is);           
+            	final File convertedFile = new File("./ariesApplicationManagerImplTest/conversion/helloWorld.war");
+            	IOUtils.jarUp(new File("../src/test/resources/conversion/conversion.eba/helloWorld.war"), convertedFile, warManifest);            
+                final String location = toBeConverted.toString();                
+            	return new BundleConversion() {
+
+					public BundleInfo getBundleInfo() throws IOException {
+						return new SimpleBundleInfo(BundleManifest.fromBundle(convertedFile), location);
+					}
+
+					public InputStream getInputStream() throws IOException {
+						return new FileInputStream(convertedFile);
+					}
+                	
+                };
+            } catch (IOException e) {
+            	e.printStackTrace();                
+            } finally {
+            	try {
+            	if (is != null)
+            		is.close();
+            	} catch (Exception e) {
+            		e.printStackTrace();
+            	}
+            }
+        }
+
+        return null;
+    }
+	
+	  
+  }
+  
+
+
+  static final String TEST_EBA = "./ariesApplicationManagerImplTest/test.eba";
+  static final String CONVERSION_EBA = "./ariesApplicationManagerImplTest/conversion.eba";
+  @BeforeClass 
+  public static void preTest() throws Exception { 
+    new File("ariesApplicationManagerImplTest/conversion").mkdirs();
+    EbaUnitTestUtils.createEba("../src/test/resources/bundles/test.eba", TEST_EBA);
+    File src = new File ("../src/test/resources/bundles/repository/a.handy.persistence.library.jar");
+    File dest = new File ("ariesApplicationManagerImplTest/a.handy.persistence.library.jar");
+    IOUtils.zipUp(src, dest);
+    EbaUnitTestUtils.createEba("../src/test/resources/conversion/conversion.eba", CONVERSION_EBA);
+  }
+  
+  AriesApplicationManagerImpl _appMgr;
+  ApplicationMetadataFactory _appMetaFactory;
+  DummyResolver _resolver;
+  DummyConverter _converter;
+  DummyDMManager _dmMgr;
+  @Before
+  public void setup() { 
+    _appMgr = new AriesApplicationManagerImpl ();
+    _appMetaFactory = new ApplicationMetadataFactoryImpl ();
+
+    DeploymentMetadataFactory dmf = new DeploymentMetadataFactoryImpl();
+    _converter = new DummyConverter();
+    List<BundleConverter> bundleConverters = new ArrayList<BundleConverter>();
+    bundleConverters.add(_converter);
+    _resolver = new DummyResolver(); 
+    _dmMgr = new DummyDMManager();
+    _dmMgr.setResolver(_resolver);
+    _appMgr.setApplicationMetadataFactory(_appMetaFactory);
+    _appMgr.setDeploymentMetadataFactory(dmf);
+    _appMgr.setBundleConverters(bundleConverters);
+    _appMgr.setDeploymentManifestManager(_dmMgr);
+    _appMgr.setLocalPlatform(new DummyLocalPlatform());
+  }
+  
+  @Test
+  public void testCreate() throws Exception { 
+    AriesApplication app = createApplication (TEST_EBA);
+    
+    ApplicationMetadata appMeta = app.getApplicationMetadata();
+    assertEquals (appMeta.getApplicationName(), "Test application");
+    assertEquals (appMeta.getApplicationSymbolicName(), "org.apache.aries.application.management.test");
+    assertEquals (appMeta.getApplicationVersion(), new Version("1.0"));
+    List<Content> appContent = appMeta.getApplicationContents();
+    assertEquals (appContent.size(), 2);
+    Content fbw = new ContentImpl("foo.bar.widgets;version=1.0.0");
+    Content mbl = new ContentImpl("my.business.logic;version=1.0.0");
+    assertTrue (appContent.contains(fbw));
+    assertTrue (appContent.contains(mbl));
+    
+    DeploymentMetadata dm = app.getDeploymentMetadata();
+    List<DeploymentContent> dcList = dm.getApplicationDeploymentContents();
+
+    assertEquals (2, dcList.size());
+    DeploymentContent dc1 = new DeploymentContentImpl ("foo.bar.widgets;deployed-version=1.1.0");
+    DeploymentContent dc2 = new DeploymentContentImpl ("my.business.logic;deployed-version=1.1.0");
+    DeploymentContent dc3 = new DeploymentContentImpl ("a.handy.persistence.library;deployed-version=1.1.0");
+    assertTrue (dcList.contains(dc1));
+    assertTrue (dcList.contains(dc2));
+    
+    dcList = dm.getApplicationProvisionBundles();
+    
+    assertEquals(1, dcList.size());
+    assertTrue (dcList.contains(dc3));
+
+  }
+  
+  @Test
+  public void testCreateAndConversion() throws Exception {
+	  	AriesApplication app = createApplication (CONVERSION_EBA);	    
+	    ApplicationMetadata appMeta = app.getApplicationMetadata();	    
+	    assertEquals (appMeta.getApplicationName(), "conversion.eba");	   
+	    assertEquals (appMeta.getApplicationSymbolicName(), "conversion.eba");	    
+	    assertEquals (appMeta.getApplicationVersion(), new Version("0.0"));	    
+	    List<Content> appContent = appMeta.getApplicationContents();
+	    assertEquals (2, appContent.size());
+	    Content fbw = new ContentImpl("hello.world.jar;version=\"[1.1.0, 1.1.0]\"");
+	    Content mbl = new ContentImpl("helloWorld.war;version=\"[0.0.0, 0.0.0]\"");
+	    assertTrue (appContent.contains(fbw));
+	    assertTrue (appContent.contains(mbl));
+	    
+	    DeploymentMetadata dm = app.getDeploymentMetadata();
+	    List<DeploymentContent> dcList = dm.getApplicationDeploymentContents();
+
+	    assertEquals (2, dcList.size());
+	    DeploymentContent dc1 = new DeploymentContentImpl ("hello.world.jar;deployed-version=1.1.0");
+	    DeploymentContent dc2 = new DeploymentContentImpl ("helloWorld.war;deployed-version=0.0.0");
+	    DeploymentContent dc3 = new DeploymentContentImpl ("a.handy.persistence.library;deployed-version=1.1.0");
+	    assertTrue (dcList.contains(dc1));
+	    assertTrue (dcList.contains(dc2));
+	    
+	    dcList = dm.getApplicationProvisionBundles();
+	    
+	    assertEquals(1, dcList.size());
+	    assertTrue (dcList.contains(dc3));
+	    
+	    assertEquals(2, app.getBundleInfo().size());
+	    BundleInfo info;
+	    info = findBundleInfo(app.getBundleInfo(), "hello.world.jar");
+	    assertNotNull(info);
+	    assertEquals("HelloWorldJar", info.getHeaders().get(Constants.BUNDLE_NAME));
+	    
+	    info = findBundleInfo(app.getBundleInfo(), "helloWorld.war");
+        assertNotNull(info);
+        assertEquals("helloWorld.war", info.getHeaders().get(Constants.BUNDLE_NAME));
+        assertEquals("/test", info.getHeaders().get("Bundle-ContextPath"));
+  }
+  
+  private BundleInfo findBundleInfo(Set<BundleInfo> infos, String symbolicName) {
+      for (BundleInfo info : infos) {
+          if (symbolicName.equals(info.getSymbolicName())) {
+              return info;
+          }
+      }
+      return null;
+  }
+  
+  @Test
+  public void testStoreAndReload() throws Exception { 
+    AriesApplication app = createApplication (TEST_EBA);
+    File dest = new File ("ariesApplicationManagerImplTest/stored.eba");
+    app.store(dest);
+    
+    /* Dest should be a zip file with four entries:
+     *  /foo.bar.widgets.jar
+     *  /my.business.logic.jar
+     *  /META-INF/APPLICATION.MF
+     *  /META-INF/DEPLOYMENT.MF
+     */
+    
+    IDirectory storedEba = FileSystem.getFSRoot(dest);
+    assertNotNull (storedEba);
+    assertEquals (storedEba.listFiles().size(), 3);
+    IFile ifile = storedEba.getFile("META-INF/APPLICATION.MF");
+    assertNotNull (ifile);
+    ifile = storedEba.getFile ("META-INF/DEPLOYMENT.MF");
+    assertNotNull (ifile);
+    ifile = storedEba.getFile ("foo.bar.widgets.jar");
+    assertNotNull (ifile);
+    ifile = storedEba.getFile ("my.business.logic.jar");
+    assertNotNull (ifile);
+    
+    AriesApplication newApp = _appMgr.createApplication(storedEba);
+    DeploymentMetadata dm = newApp.getDeploymentMetadata();
+    assertEquals (2, dm.getApplicationDeploymentContents().size());
+    assertEquals(1, dm.getApplicationProvisionBundles().size());
+    assertEquals (dm.getApplicationSymbolicName(), app.getApplicationMetadata().getApplicationSymbolicName());
+    assertEquals (dm.getApplicationVersion(), app.getApplicationMetadata().getApplicationVersion());
+  }
+  
+  @Test
+  public void testUpdate() throws Exception {
+    AriesApplication app = createApplication(TEST_EBA);
+
+    DeploymentMetadata depMf = createUpdateDepMf();
+    
+    AriesApplicationContextManager ctxMgr = Skeleton.newMock(AriesApplicationContextManager.class);
+    _appMgr.setApplicationContextManager(ctxMgr);
+
+    _appMgr.update(app, depMf);
+    
+    assertTrue("Deployment.mf should have been updated", app.getDeploymentMetadata() == depMf);
+  }
+  
+  @Test(expected=IllegalArgumentException.class)
+  public void testUpdateWithIncorrectDepMf() throws Exception
+  {
+    AriesApplication app = createApplication(TEST_EBA);
+
+    DeploymentMetadata depMf = Skeleton.newMock(DeploymentMetadata.class);
+    Skeleton.getSkeleton(depMf).setReturnValue(new MethodCall(DeploymentMetadata.class, "getApplicationSymbolicName"), "random.app");
+    Skeleton.getSkeleton(depMf).setReturnValue(new MethodCall(DeploymentMetadata.class, "getApplicationVersion"), new Version("1.0.0"));
+    
+    AriesApplicationContextManager ctxMgr = Skeleton.newMock(AriesApplicationContextManager.class);
+    _appMgr.setApplicationContextManager(ctxMgr);
+
+    _appMgr.update(app, depMf);    
+  }
+  
+  @Test
+  public void testFailedUpdate() throws Exception {
+    AriesApplication app = createApplication(TEST_EBA);
+
+    DeploymentMetadata depMf = createUpdateDepMf();
+    
+    AriesApplicationContext ctx = Skeleton.newMock(AriesApplicationContext.class);
+    Skeleton.getSkeleton(ctx).setReturnValue(new MethodCall(AriesApplicationContext.class, "getApplication"), app);
+    
+    AriesApplicationContextManager ctxMgr = Skeleton.newMock(AriesApplicationContextManager.class);
+    Skeleton.getSkeleton(ctxMgr).setReturnValue(
+        new MethodCall(AriesApplicationContextManager.class, "getApplicationContexts"), 
+        Collections.singleton(ctx));    
+    
+    Skeleton.getSkeleton(ctxMgr).setThrows(
+        new MethodCall(AriesApplicationContextManager.class, "update", AriesApplication.class, DeploymentMetadata.class), 
+        new UpdateException("", null, false, null));
+    
+    _appMgr.setApplicationContextManager(ctxMgr);
+
+    try {
+      _appMgr.update(app, depMf);
+      fail("Update should have failed.");
+    } catch (UpdateException e) {
+      assertTrue("Deployment.mf should have been updated", app.getDeploymentMetadata() == depMf);
+    }
+  }
+  
+  @Test
+  public void testRolledbackUpdate() throws Exception {
+    AriesApplication app = createApplication(TEST_EBA);
+
+    DeploymentMetadata depMf = createUpdateDepMf();
+    DeploymentMetadata oldMf = app.getDeploymentMetadata();
+    
+    AriesApplicationContext ctx = Skeleton.newMock(AriesApplicationContext.class);
+    Skeleton.getSkeleton(ctx).setReturnValue(new MethodCall(AriesApplicationContext.class, "getApplication"), app);
+    
+    AriesApplicationContextManager ctxMgr = Skeleton.newMock(AriesApplicationContextManager.class);
+    Skeleton.getSkeleton(ctxMgr).setReturnValue(
+        new MethodCall(AriesApplicationContextManager.class, "getApplicationContexts"), 
+        Collections.singleton(ctx));    
+    
+    Skeleton.getSkeleton(ctxMgr).setThrows(
+        new MethodCall(AriesApplicationContextManager.class, "update", AriesApplication.class, DeploymentMetadata.class), 
+        new UpdateException("", null, true, null));
+    
+    _appMgr.setApplicationContextManager(ctxMgr);
+
+    try {
+      _appMgr.update(app, depMf);
+      fail("Update should have failed.");
+    } catch (UpdateException e) {
+      assertTrue("Deployment.mf should have been rolled back to the old", app.getDeploymentMetadata() == oldMf);
+    }
+  }
+  
+  private DeploymentMetadata createUpdateDepMf()
+  {
+    DeploymentMetadata depMf = Skeleton.newMock(DeploymentMetadata.class);
+    Skeleton.getSkeleton(depMf).setReturnValue(new MethodCall(DeploymentMetadata.class, "getApplicationSymbolicName"), "org.apache.aries.application.management.test");
+    Skeleton.getSkeleton(depMf).setReturnValue(new MethodCall(DeploymentMetadata.class, "getApplicationVersion"), new Version("1.0.0"));
+
+    return depMf;
+  }
+  
+  private AriesApplication createApplication (String fileName) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException, ManagementException, ResolverException {
+    // This next block is a very long winded way of constructing a BundleInfoImpl
+    // against the existing (BundleManifest bm, String location) constructor. If we 
+    // find we need a String-based BundleInfoImpl constructor for other reasons, 
+    // we could change to using it here. 
+    Set<BundleInfo> nextResolverResult = new HashSet<BundleInfo>();
+    String persistenceLibraryLocation = "../src/test/resources/bundles/repository/a.handy.persistence.library.jar";
+    File persistenceLibrary = new File (persistenceLibraryLocation);
+    BundleManifest mf = BundleManifest.fromBundle(persistenceLibrary);
+    BundleInfo resolvedPersistenceLibrary = new SimpleBundleInfo(mf, persistenceLibraryLocation); 
+    Field v = SimpleBundleInfo.class.getDeclaredField("_version");
+    v.setAccessible(true);
+    v.set(resolvedPersistenceLibrary, new Version("1.1.0"));
+    nextResolverResult.add(resolvedPersistenceLibrary);
+    _resolver.setNextResult(nextResolverResult);
+    
+    IDirectory testEba = FileSystem.getFSRoot(new File(fileName));    
+    AriesApplication app = _appMgr.createApplication(testEba);
+    app = _appMgr.resolve(app);
+    return app;
+  }
+}

Added: aries/tags/application-0.3/application-management/src/test/java/org/apache/aries/application/management/repository/ApplicationRepositoryTest.java
URL: http://svn.apache.org/viewvc/aries/tags/application-0.3/application-management/src/test/java/org/apache/aries/application/management/repository/ApplicationRepositoryTest.java?rev=1075132&view=auto
==============================================================================
--- aries/tags/application-0.3/application-management/src/test/java/org/apache/aries/application/management/repository/ApplicationRepositoryTest.java (added)
+++ aries/tags/application-0.3/application-management/src/test/java/org/apache/aries/application/management/repository/ApplicationRepositoryTest.java Sun Feb 27 20:20:13 2011
@@ -0,0 +1,55 @@
+/*
+ * 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.aries.application.management.repository;
+
+import java.util.HashSet;
+import java.util.Map;
+
+import org.apache.aries.application.DeploymentContent;
+import org.apache.aries.application.VersionRange;
+import org.apache.aries.application.impl.DeploymentContentImpl;
+import org.apache.aries.application.management.AriesApplication;
+import org.apache.aries.application.management.BundleInfo;
+import org.apache.aries.application.management.spi.repository.BundleRepository.BundleSuggestion;
+import org.apache.aries.unittest.mocks.MethodCall;
+import org.apache.aries.unittest.mocks.Skeleton;
+import org.junit.Test;
+import org.osgi.framework.Version;
+
+import static org.junit.Assert.*;
+
+public class ApplicationRepositoryTest {
+  @Test
+  public void testBundleNotInApp() {
+    AriesApplication app = Skeleton.newMock(AriesApplication.class);
+    
+    BundleInfo bi = Skeleton.newMock(BundleInfo.class);
+    Skeleton.getSkeleton(bi).setReturnValue(new MethodCall(BundleInfo.class, "getSymbolicName"), "test.bundle");
+    Skeleton.getSkeleton(bi).setReturnValue(new MethodCall(BundleInfo.class, "getVersion"), new Version("1.0.0"));
+    
+    Skeleton.getSkeleton(app).setReturnValue(
+        new MethodCall(AriesApplication.class, "getBundleInfo"), 
+        new HashSet<BundleInfo>());
+    
+    ApplicationRepository rep = new ApplicationRepository(app);
+    BundleSuggestion sug = rep.suggestBundleToUse(new DeploymentContentImpl("test.bundle", new Version("2.0.0")));
+    
+    assertNull("We have apparently found a bundle that is not in the application in the ApplicationRepository", sug);
+  }
+}

Added: aries/tags/application-0.3/application-management/src/test/java/org/apache/aries/unittest/utils/EbaUnitTestUtils.java
URL: http://svn.apache.org/viewvc/aries/tags/application-0.3/application-management/src/test/java/org/apache/aries/unittest/utils/EbaUnitTestUtils.java?rev=1075132&view=auto
==============================================================================
--- aries/tags/application-0.3/application-management/src/test/java/org/apache/aries/unittest/utils/EbaUnitTestUtils.java (added)
+++ aries/tags/application-0.3/application-management/src/test/java/org/apache/aries/unittest/utils/EbaUnitTestUtils.java Sun Feb 27 20:20:13 2011
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIESOR 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.aries.unittest.utils;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
+
+import org.apache.aries.application.utils.filesystem.IOUtils;
+
+public class EbaUnitTestUtils {
+
+private static final String TEMP_DIR = "unittest/tmpEbaContent";
+  
+  public static void createEba(String rootFolder, String outputFile) throws IOException
+  {
+    File tempDir = new File(TEMP_DIR);
+    tempDir.mkdirs();
+    
+    createEbaRecursive(new File(rootFolder), tempDir, "");
+    IOUtils.zipUp(tempDir, new File(outputFile));
+    IOUtils.deleteRecursive(tempDir);
+  }
+  
+  private static void createEbaRecursive(File folder, File tempDir, String prefix) throws IOException
+  {
+    File[] files = folder.listFiles();
+    
+    if (files != null) {
+      for (File f : files)
+      {
+        if ((f.getName().endsWith(".jar") || f.getName().endsWith(".war")) && f.isDirectory())
+        {
+          File manifestFile = new File(f, "META-INF/MANIFEST.MF");
+          Manifest m;
+          
+          if (manifestFile.isFile())
+            m = new Manifest(new FileInputStream(manifestFile));
+          else
+          {
+            m = new Manifest();
+            m.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
+          }
+            
+          File jarFile = new File(tempDir, prefix + f.getName());
+          jarFile.getParentFile().mkdirs();
+          
+          IOUtils.jarUp(f, jarFile, m); 
+        }
+        else if (f.isFile())
+        {
+          IOUtils.writeOut(tempDir, prefix + f.getName(), new FileInputStream(f));
+        }
+        else if (f.isDirectory())
+        {
+          createEbaRecursive(f, tempDir, prefix + f.getName() + File.separator);
+        }
+      }
+    }
+  }
+  
+  public static void cleanupEba(String outputFile)
+  {
+    new File(outputFile).delete();
+  }
+}

Added: aries/tags/application-0.3/application-management/src/test/resources/bundles/repository/a.handy.persistence.library.jar/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/aries/tags/application-0.3/application-management/src/test/resources/bundles/repository/a.handy.persistence.library.jar/META-INF/MANIFEST.MF?rev=1075132&view=auto
==============================================================================
--- aries/tags/application-0.3/application-management/src/test/resources/bundles/repository/a.handy.persistence.library.jar/META-INF/MANIFEST.MF (added)
+++ aries/tags/application-0.3/application-management/src/test/resources/bundles/repository/a.handy.persistence.library.jar/META-INF/MANIFEST.MF Sun Feb 27 20:20:13 2011
@@ -0,0 +1,8 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: HandyPersistenceLibrary
+Bundle-SymbolicName: a.handy.persistence.library
+Bundle-Version: 1.1
+Bundle-Vendor: Apache.org
+Export-Package: org.apache.handy.persistence
+

Added: aries/tags/application-0.3/application-management/src/test/resources/bundles/test.eba/META-INF/APPLICATION.MF
URL: http://svn.apache.org/viewvc/aries/tags/application-0.3/application-management/src/test/resources/bundles/test.eba/META-INF/APPLICATION.MF?rev=1075132&view=auto
==============================================================================
--- aries/tags/application-0.3/application-management/src/test/resources/bundles/test.eba/META-INF/APPLICATION.MF (added)
+++ aries/tags/application-0.3/application-management/src/test/resources/bundles/test.eba/META-INF/APPLICATION.MF Sun Feb 27 20:20:13 2011
@@ -0,0 +1,8 @@
+Manifest-Version: 1.0
+Application-ManifestVersion: 1.0
+Application-Name: Test application
+Application-SymbolicName: org.apache.aries.application.management.test
+Application-Version: 1.0
+Application-Content: foo.bar.widgets;version=1.0.0,
+ my.business.logic;version=1.0.0
+

Added: aries/tags/application-0.3/application-management/src/test/resources/bundles/test.eba/foo.bar.widgets.jar/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/aries/tags/application-0.3/application-management/src/test/resources/bundles/test.eba/foo.bar.widgets.jar/META-INF/MANIFEST.MF?rev=1075132&view=auto
==============================================================================
--- aries/tags/application-0.3/application-management/src/test/resources/bundles/test.eba/foo.bar.widgets.jar/META-INF/MANIFEST.MF (added)
+++ aries/tags/application-0.3/application-management/src/test/resources/bundles/test.eba/foo.bar.widgets.jar/META-INF/MANIFEST.MF Sun Feb 27 20:20:13 2011
@@ -0,0 +1,9 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: FooBarWidgets
+Bundle-SymbolicName: foo.bar.widgets
+Bundle-Version: 1.1
+Bundle-Vendor: Apache.org
+Export-Package: foo.bar.widgets
+
+

Added: aries/tags/application-0.3/application-management/src/test/resources/bundles/test.eba/my.business.logic.jar/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/aries/tags/application-0.3/application-management/src/test/resources/bundles/test.eba/my.business.logic.jar/META-INF/MANIFEST.MF?rev=1075132&view=auto
==============================================================================
--- aries/tags/application-0.3/application-management/src/test/resources/bundles/test.eba/my.business.logic.jar/META-INF/MANIFEST.MF (added)
+++ aries/tags/application-0.3/application-management/src/test/resources/bundles/test.eba/my.business.logic.jar/META-INF/MANIFEST.MF Sun Feb 27 20:20:13 2011
@@ -0,0 +1,7 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: MyBusinessLogic
+Bundle-SymbolicName: my.business.logic
+Bundle-Version: 1.1
+Bundle-Vendor: Apache.org
+Export-Package: my.business.logic

Added: aries/tags/application-0.3/application-management/src/test/resources/conversion/MANIFEST.MF
URL: http://svn.apache.org/viewvc/aries/tags/application-0.3/application-management/src/test/resources/conversion/MANIFEST.MF?rev=1075132&view=auto
==============================================================================
--- aries/tags/application-0.3/application-management/src/test/resources/conversion/MANIFEST.MF (added)
+++ aries/tags/application-0.3/application-management/src/test/resources/conversion/MANIFEST.MF Sun Feb 27 20:20:13 2011
@@ -0,0 +1,11 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: helloWorld.war
+Bundle-SymbolicName: helloWorld.war
+Bundle-Version: 0.0.0
+Bundle-Vendor: Apache.org
+Bundle-ContextPath: /test
+Export-Package: apache.org.helloWorldWar
+
+
+

Added: aries/tags/application-0.3/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/aries/tags/application-0.3/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF?rev=1075132&view=auto
==============================================================================
--- aries/tags/application-0.3/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF (added)
+++ aries/tags/application-0.3/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF Sun Feb 27 20:20:13 2011
@@ -0,0 +1,9 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: HelloWorldJar
+Bundle-SymbolicName: hello.world.jar
+Bundle-Version: 1.1.0
+Bundle-Vendor: Apache.org
+Export-Package: apache.org.helloWorldJar
+
+

Added: aries/tags/application-0.3/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/aries/tags/application-0.3/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml?rev=1075132&view=auto
==============================================================================
--- aries/tags/application-0.3/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml (added)
+++ aries/tags/application-0.3/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml Sun Feb 27 20:20:13 2011
@@ -0,0 +1,19 @@
+<!--
+    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.
+-->
+<web-app>
+<display-name>Hello World</display-name>
+</web-app> 

Added: aries/tags/application-0.3/application-modeller/pom.xml
URL: http://svn.apache.org/viewvc/aries/tags/application-0.3/application-modeller/pom.xml?rev=1075132&view=auto
==============================================================================
--- aries/tags/application-0.3/application-modeller/pom.xml (added)
+++ aries/tags/application-0.3/application-modeller/pom.xml Sun Feb 27 20:20:13 2011
@@ -0,0 +1,102 @@
+<!--
+ 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 xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.aries.application</groupId>
+        <artifactId>application</artifactId>
+        <version>0.3</version>
+    </parent>
+
+    <artifactId>org.apache.aries.application.modeller</artifactId>
+    <packaging>bundle</packaging>
+    <name>Apache Aries Application Modelling</name>
+    <description>
+      Modelling utilities for working with Aries Applications.
+    </description>
+
+    <properties>
+    	<aries.osgi.private.pkg>
+            org.apache.aries.application.modelling.impl;
+            org.apache.aries.application.modelling.internal;
+            org.apache.aries.application.modelling.utils.impl
+        </aries.osgi.private.pkg>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.aries.application</groupId>
+            <artifactId>org.apache.aries.application.api</artifactId>
+        </dependency>
+        <dependency>
+             <groupId>org.apache.aries</groupId>
+             <artifactId>org.apache.aries.util</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.aries.testsupport</groupId>
+            <artifactId>org.apache.aries.testsupport.unit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.aries.jndi</groupId>
+            <artifactId>org.apache.aries.jndi.api</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+            <version>4.2.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+          <groupId>org.osgi</groupId>
+          <artifactId>org.osgi.compendium</artifactId>
+          <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-simple</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+        	<groupId>org.apache.aries.application</groupId>
+        	<artifactId>org.apache.aries.application.utils</artifactId>
+        	<scope>provided</scope>
+        </dependency>
+        <dependency>
+        	<groupId>org.apache.aries.blueprint</groupId>
+        	<artifactId>org.apache.aries.blueprint.api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.aries.blueprint</groupId>
+            <artifactId>org.apache.aries.blueprint.core</artifactId>
+        </dependency>
+    </dependencies>
+
+</project>

Added: aries/tags/application-0.3/application-modeller/src/main/java/org/apache/aries/application/modelling/impl/AbstractExportedBundle.java
URL: http://svn.apache.org/viewvc/aries/tags/application-0.3/application-modeller/src/main/java/org/apache/aries/application/modelling/impl/AbstractExportedBundle.java?rev=1075132&view=auto
==============================================================================
--- aries/tags/application-0.3/application-modeller/src/main/java/org/apache/aries/application/modelling/impl/AbstractExportedBundle.java (added)
+++ aries/tags/application-0.3/application-modeller/src/main/java/org/apache/aries/application/modelling/impl/AbstractExportedBundle.java Sun Feb 27 20:20:13 2011
@@ -0,0 +1,93 @@
+/*
+ * 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 WARRANTIESOR 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.aries.application.modelling.impl;
+
+import java.util.Map;
+
+import org.apache.aries.application.modelling.ExportedBundle;
+import org.apache.aries.application.modelling.ImportedBundle;
+import org.apache.aries.application.modelling.ModellingConstants;
+import org.apache.aries.application.modelling.ResourceType;
+import org.apache.aries.application.utils.AppConstants;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Version;
+
+ abstract class AbstractExportedBundle implements ExportedBundle
+{
+
+
+  /**
+   * Get the exported bundle or composite's manifest attributes
+   * @return attributes extracted from the object's manifest 
+   */
+  public abstract Map<String, Object> getAttributes(); 
+
+  /**
+   * This is always BUNDLE, even for composites. Their compositey-ness is detected
+   * from ModelledResource.getType()
+   */
+
+  public final ResourceType getType() { 
+    
+    return ResourceType.BUNDLE;
+  }
+  
+  /**
+   * Get the bundle's symbolic name
+   * @return symbolic name
+   */
+  public String getSymbolicName() {
+    
+    String result = String.valueOf(getAttributes().get(ModellingConstants.OBR_SYMBOLIC_NAME));
+    
+    return result;
+  }
+
+  /**
+   * Get the bundle or composite's version
+   * @return version
+   */
+  public String getVersion () { 
+    
+    String result = String.valueOf(getAttributes().get(Constants.VERSION_ATTRIBUTE));
+    
+    return Version.parseVersion(result).toString();
+  }
+
+
+  
+  public String toDeploymentString() {
+    
+    String result = getSymbolicName() + ";" + AppConstants.DEPLOYMENT_BUNDLE_VERSION + "=" + getVersion();
+    return result;
+  }
+  
+  /**
+   * Return true if this is a fragment
+   * @return true if this is a fragment
+   */
+  public abstract boolean isFragment();
+  
+  /**
+   * If this bundle is a fragment, this method will return the bundle to which it attaches 
+   * @return fragment host
+   */
+  public abstract ImportedBundle getFragmentHost();
+
+}



Mime
View raw message