/*
* Copyright (c) 2004-2011 Marco Maccaferri and others.
* 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:
* Marco Maccaferri - initial API and implementation
*/
package org.eclipsetrader.yahoo.internal.news;
import javax.xml.bind.JAXBException;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExecutableExtension;
import org.eclipse.core.runtime.IExecutableExtensionFactory;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipsetrader.yahoo.internal.YahooActivator;
public class NewsProviderFactory implements IExecutableExtensionFactory, IExecutableExtension {
private static NewsProvider provider;
private String id;
private String name;
public NewsProviderFactory() {
}
/* (non-Javadoc)
* @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement, java.lang.String, java.lang.Object)
*/
@Override
public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException {
id = config.getAttribute("id");
name = config.getAttribute("name");
}
/* (non-Javadoc)
* @see org.eclipse.core.runtime.IExecutableExtensionFactory#create()
*/
@Override
public Object create() throws CoreException {
if (provider == null) {
provider = new NewsProvider(id, name);
try {
provider.startUp();
} catch (JAXBException e) {
Status status = new Status(IStatus.WARNING, YahooActivator.PLUGIN_ID, 0, "Error initializing news provider", e);
throw new CoreException(status);
}
}
return provider;
}
}