/* * JBoss, Home of Professional Open Source. * * See the LEGAL.txt file distributed with this work for information regarding copyright ownership and licensing. * * See the AUTHORS.txt file distributed with this work for a full listing of individual contributors. */ package org.teiid.designer.metamodels.wsdl; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import java.util.MissingResourceException; import java.util.ResourceBundle; import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.Plugin; import org.eclipse.emf.common.CommonPlugin; import org.eclipse.emf.common.util.ResourceLocator; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.common.util.WrappedException; import org.osgi.framework.BundleContext; import org.teiid.core.designer.PluginUtil; import org.teiid.core.designer.util.PluginUtilImpl; /** * The main plugin class to be used in the desktop. * * @since 8.0 */ public class WsdlMetamodelPlugin extends Plugin { public static final String PLUGIN_ID = "org.teiid.designer.metamodels.wsdl"; //$NON-NLS-1$ public static final String PACKAGE_ID = WsdlMetamodelPlugin.class.getPackage().getName(); /** * Provides access to the plugin's log and to it's resources. */ private static final String I18N_NAME = PACKAGE_ID + ".i18n"; //$NON-NLS-1$ public static final PluginUtil Util = new PluginUtilImpl(PLUGIN_ID, I18N_NAME, ResourceBundle.getBundle(I18N_NAME)); private static final ResourceLocator RESOURCE_LOCATOR = new ResourceLocator() { @Override public URL getBaseURL() { if (INSTANCE != null) { URL baseUrl; try { baseUrl = FileLocator.resolve(INSTANCE.getBundle().getEntry("/")); //$NON-NLS-1$ } catch (final IOException err) { baseUrl = null; } return baseUrl; } try { final URI uri = URI.createURI(getClass().getResource("plugin.properties").toString()); //$NON-NLS-1$ final URL baseUrl = new URL(uri.trimSegments(1).toString() + "/"); //$NON-NLS-1$ return baseUrl; } catch (IOException exception) { throw new WrappedException(exception); } } @Override public Object getImage( String key ) { try { final URL baseUrl = getBaseURL(); final URL url = new URL(baseUrl + "icons/" + key + ".gif"); //$NON-NLS-1$//$NON-NLS-2$ InputStream inputStream = url.openStream(); inputStream.close(); return url; } catch (MalformedURLException exception) { throw new WrappedException(exception); } catch (IOException exception) { throw new MissingResourceException( CommonPlugin.INSTANCE.getString("_UI_StringResourceNotFound_exception", new Object[] {key}), //$NON-NLS-1$ getClass().getName(), key); } } @Override public String getString( String key ) { return Util.getString(key); } @Override public String getString( String key, Object[] substitutions ) { return Util.getString(key, substitutions); } @Override public String getString( final String key, final boolean translate ) { return getString(key); } @Override public String getString( final String key, final Object[] substitutions, final boolean translate ) { return getString(key, substitutions); } }; /** * * @return the EMF ResourceLocator used when run as a plugin */ public static ResourceLocator getPluginResourceLocator() { // NO_UCD return RESOURCE_LOCATOR; } static WsdlMetamodelPlugin INSTANCE = null; /** * Construct an instance of MetaMatrixPlugin. */ public WsdlMetamodelPlugin() { } /** * @see org.eclipse.core.runtime.Plugin#start(org.osgi.framework.BundleContext) * @since 4.3.2 */ @Override public void start( BundleContext context ) throws Exception { super.start(context); WsdlMetamodelPlugin.INSTANCE = this; ((PluginUtilImpl)Util).initializePlatformLogger(this); // This must be called to initialize the platform logger! } }