| /* |
| * 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.felix.webconsole.internal.core; |
| |
| |
| import java.io.File; |
| import java.io.InputStream; |
| |
| import org.osgi.framework.Bundle; |
| import org.osgi.framework.BundleContext; |
| import org.osgi.framework.BundleException; |
| import org.osgi.service.startlevel.StartLevel; |
| |
| |
| abstract class InstallHelper extends BaseUpdateInstallHelper |
| { |
| private final BundleContext bundleContext; |
| private final String location; |
| private final int startlevel; |
| private final boolean doStart; |
| |
| InstallHelper( final BundleContext bundleContext, final File bundleFile, final String location, final int startlevel, |
| final boolean doStart, final boolean refreshPackages ) |
| { |
| super( "Background Install " + bundleFile, bundleFile, refreshPackages ); |
| |
| this.bundleContext = bundleContext; |
| this.location = location; |
| this.startlevel = startlevel; |
| this.doStart = doStart; |
| } |
| |
| |
| protected Bundle doRun( InputStream bundleStream ) throws BundleException |
| { |
| Bundle bundle = bundleContext.installBundle( location, bundleStream ); |
| |
| if ( startlevel > 0 ) |
| { |
| StartLevel sl = ( StartLevel ) getService( StartLevel.class.getName() ); |
| if ( sl != null ) |
| { |
| sl.setBundleStartLevel( bundle, startlevel ); |
| } |
| } |
| |
| if ( doStart ) |
| { |
| bundle.start(); |
| } |
| |
| return bundle; |
| } |
| } |