org.symbian.tools.mtw.core/src/org/symbian/tools/mtw/core/internal/runtimes/LazyPackager.java
changeset 461 7a8f9fa8d278
parent 460 c0bff5ed874c
child 462 cdc4995b1677
equal deleted inserted replaced
460:c0bff5ed874c 461:7a8f9fa8d278
     1 /**
       
     2  * Copyright (c) 2010 Symbian Foundation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of the License "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Symbian Foundation - initial contribution.
       
    11  * Contributors:
       
    12  * Description:
       
    13  * Overview:
       
    14  * Details:
       
    15  * Platforms/Drives/Compatibility:
       
    16  * Assumptions/Requirement/Pre-requisites:
       
    17  * Failures and causes:
       
    18  */
       
    19 package org.symbian.tools.mtw.core.internal.runtimes;
       
    20 
       
    21 import java.io.File;
       
    22 
       
    23 import org.eclipse.core.resources.IResource;
       
    24 import org.eclipse.core.runtime.CoreException;
       
    25 import org.eclipse.core.runtime.IConfigurationElement;
       
    26 import org.eclipse.core.runtime.IPath;
       
    27 import org.eclipse.core.runtime.IProgressMonitor;
       
    28 import org.symbian.tools.mtw.core.MTWCore;
       
    29 import org.symbian.tools.mtw.core.projects.IMTWProject;
       
    30 import org.symbian.tools.mtw.core.runtimes.IMobileWebRuntime;
       
    31 import org.symbian.tools.mtw.core.runtimes.IPackager;
       
    32 import org.symbian.tools.mtw.core.runtimes.IPackagerDelegate;
       
    33 
       
    34 public class LazyPackager implements IPackager {
       
    35     private final IConfigurationElement element;
       
    36     private IPackagerDelegate packager;
       
    37 
       
    38     public LazyPackager(IConfigurationElement element) {
       
    39         this.element = element;
       
    40     }
       
    41 
       
    42     public File packageApplication(IMTWProject project, IProgressMonitor monitor)
       
    43             throws CoreException {
       
    44         return getPackager().packageApplication(project, monitor);
       
    45     }
       
    46 
       
    47     private IPackagerDelegate getPackager() {
       
    48         if (packager == null) {
       
    49             try {
       
    50                 packager = (IPackagerDelegate) element.createExecutableExtension("delegate");
       
    51             } catch (CoreException e) {
       
    52                 MTWCore.log(String.format("Cannot instantiate %s from plugin %s", element.getAttribute("delegate"),
       
    53                         element.getDeclaringExtension().getNamespaceIdentifier()), e);
       
    54                 throw new RuntimeException(e);
       
    55             }
       
    56         }
       
    57         return packager;
       
    58     }
       
    59 
       
    60     public IPath getPathInPackage(IResource resource) {
       
    61         return getPackager().getPathInPackage(resource);
       
    62     }
       
    63 
       
    64     public String getFileType(IMTWProject project) {
       
    65         return getPackager().getFileType(project);
       
    66     }
       
    67 
       
    68     public IMobileWebRuntime getTargetRuntime() {
       
    69         String id = element.getAttribute("targetRuntime");
       
    70         if (id != null) {
       
    71             return MTWCore.getDefault().getRuntimesManager().getRuntime(id);
       
    72         } else {
       
    73             return getSourceRuntime();
       
    74         }
       
    75     }
       
    76 
       
    77     public IMobileWebRuntime getSourceRuntime() {
       
    78         IMobileWebRuntime runtime = MTWCore.getDefault().getRuntimesManager()
       
    79                 .getRuntime(element.getAttribute("sourceRuntime"));
       
    80         return runtime;
       
    81     }
       
    82 
       
    83 }