/*******************************************************************************
 * Copyright (c) 2010, 2011 Actuate Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *  Actuate Corporation  - initial API and implementation
 *******************************************************************************/

package org.eclipse.birt.core.framework.jar;

import java.io.IOException;
import java.net.URL;
import java.util.Enumeration;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.eclipse.birt.core.framework.FrameworkException;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.core.framework.PlatformConfig;
import org.eclipse.birt.core.framework.PlatformLauncher;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.RegistryFactory;
import org.eclipse.core.runtime.spi.IRegistryProvider;

public class ServiceLauncher extends PlatformLauncher
{

	static final String MANIFEST_ENTRY = "META-INF/MANIFEST.MF";

	static Logger logger = Logger.getLogger( Platform.class.getName( ) );

	private ServicePlatform platform;

	public ServiceLauncher( )
	{
	}

	public void startup( final PlatformConfig config )
			throws FrameworkException
	{
		platform = new ServicePlatform( config );

		try
		{
			Enumeration<URL> plugins = ServiceLauncher.class.getClassLoader( )
					.getResources( MANIFEST_ENTRY );

			while ( plugins.hasMoreElements( ) )
			{
				URL root = new URL( plugins.nextElement( ), ".." );
				try
				{
					platform.installBundle( root );
				}
				catch ( Exception ex )
				{
					logger.log( Level.WARNING, "Failed to install plugin from "
							+ root, ex );
				}
			}
			platform.startup( );

			Platform.setPlatform( platform );

			RegistryFactory
					.setDefaultRegistryProvider( new IRegistryProvider( ) {

						public IExtensionRegistry getRegistry( )
						{
							return platform.extensionRegistry;
						}
					} );
		}
		catch ( IOException ex )
		{
			throw new FrameworkException(
					"Can't find any bundle from the classpath", ex );
		}
		catch ( CoreException ex )
		{
			throw new FrameworkException(
					"Can't register the ExtensionRegistry classpath", ex );
		}

	}

	public void shutdown( )
	{
		Platform.setPlatform( null );
		if ( platform != null )
		{
			platform.shutdown( );
			platform = null;
		}
	}
}

@@ -1708,50 +1708,463 @@
 %09%09%09%09
-URL root = new URL( plugins.nextElement( )
+// the wsjar:// URL in websphere doesn't support .. to get the%0A%09%09%09%09// parent folder, so we construct the root from the file path%0A%09%09%09%09URL root = null;%0A%09%09%09%09URL url = plugins.nextElement( );%0A%09%09%09%09String path = url.toExternalForm( );%0A%09%09%09%09if ( path.endsWith( MANIFEST_ENTRY ) )%0A%09%09%09%09%7B%0A%09%09%09%09%09String rootPath = path.substring( 0, path.length( )%0A%09%09%09%09%09%09%09- MANIFEST_ENTRY.length( ) );%0A%09%09%09%09%09root = new URL( url, rootPath );%0A%09%09%09%09%7D%0A%09%09%09%09else%0A%09%09%09%09%7B%0A%09%09%09%09%09root = new URL( url
 , %22.
@@ -2165,24 +2165,30 @@
 rl, %22..%22 );%0A
+%09%09%09%09%7D%0A
 %09%09%09%09try%0A%09%09%09%09

support new runtime in websphere 6.1