mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-07 16:26:11 +02:00
[176216] parsers dynamically loaded when needed
This commit is contained in:
parent
23d19b52fe
commit
56c2add9e5
1 changed files with 86 additions and 39 deletions
|
@ -12,6 +12,7 @@ package org.eclipse.rse.internal.subsystems.files.ftp.parser;
|
||||||
|
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.TreeSet;
|
||||||
|
|
||||||
import org.apache.commons.net.ftp.FTPClientConfig;
|
import org.apache.commons.net.ftp.FTPClientConfig;
|
||||||
import org.apache.commons.net.ftp.FTPFileEntryParser;
|
import org.apache.commons.net.ftp.FTPFileEntryParser;
|
||||||
|
@ -24,10 +25,12 @@ import org.eclipse.rse.internal.services.files.ftp.parser.IFTPClientConfigFactor
|
||||||
|
|
||||||
public class FTPClientConfigFactory implements IFTPClientConfigFactory {
|
public class FTPClientConfigFactory implements IFTPClientConfigFactory {
|
||||||
|
|
||||||
private static FTPClientConfigFactory factory = null;
|
private static FTPClientConfigFactory factory = null;
|
||||||
|
|
||||||
|
private Set keySet = new TreeSet();
|
||||||
private Hashtable ftpConfig = new Hashtable();
|
private Hashtable ftpConfig = new Hashtable();
|
||||||
private Hashtable ftpFileEntryParser = new Hashtable();
|
private Hashtable ftpFileEntryParser = new Hashtable();
|
||||||
|
private IExtensionPoint ep = Platform.getExtensionRegistry().getExtensionPoint("org.eclipse.rse.subsystems.files.ftp","ftpFileEntryParser"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor of the parser factory
|
* Constructor of the parser factory
|
||||||
|
@ -45,23 +48,41 @@ private static FTPClientConfigFactory factory = null;
|
||||||
|
|
||||||
private FTPClientConfigFactory() {
|
private FTPClientConfigFactory() {
|
||||||
|
|
||||||
FTPClientConfig config = null;
|
|
||||||
|
|
||||||
IExtensionPoint ep = Platform.getExtensionRegistry().getExtensionPoint("org.eclipse.rse.subsystems.files.ftp","ftpFileEntryParser"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
IConfigurationElement[] ce = ep.getConfigurationElements();
|
IConfigurationElement[] ce = ep.getConfigurationElements();
|
||||||
for (int i = 0; i < ce.length; i++) {
|
for (int i = 0; i < ce.length; i++) {
|
||||||
|
|
||||||
config = null;
|
String label = ce[i].getAttribute("name"); //$NON-NLS-1$
|
||||||
|
keySet.add(label);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
String name = ce[i].getAttribute("name"); //$NON-NLS-1$
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.eclipse.rse.internal.services.files.ftp.parser.IFTPClientConfigFactory#getFTPClientConfig(java.lang.String)
|
||||||
|
*/
|
||||||
|
public FTPClientConfig getFTPClientConfig(String key)
|
||||||
|
{
|
||||||
|
if(!ftpConfig.containsKey(key))
|
||||||
|
{
|
||||||
|
IConfigurationElement[] ce = ep.getConfigurationElements();
|
||||||
|
for (int i = 0; i < ce.length; i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
String label = ce[i].getAttribute("name"); //$NON-NLS-1$
|
||||||
|
|
||||||
|
if(label.equals(key))
|
||||||
|
{
|
||||||
|
|
||||||
|
FTPClientConfig config = null;
|
||||||
|
|
||||||
|
//populate tables
|
||||||
String clas = ce[i].getAttribute("class"); //$NON-NLS-1$
|
String clas = ce[i].getAttribute("class"); //$NON-NLS-1$
|
||||||
|
|
||||||
FTPFileEntryParser entryParser=null;
|
FTPFileEntryParser entryParser=null;
|
||||||
try {
|
try {
|
||||||
entryParser = (FTPFileEntryParser)ce[i].createExecutableExtension("class"); //$NON-NLS-1$
|
entryParser = (FTPFileEntryParser)ce[i].createExecutableExtension("class"); //$NON-NLS-1$
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
// TODO Auto-generated catch block
|
throw new ParserInitializationException(e.getMessage());
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ftpFileEntryParser.put(clas, entryParser);
|
ftpFileEntryParser.put(clas, entryParser);
|
||||||
|
@ -81,17 +102,13 @@ private static FTPClientConfigFactory factory = null;
|
||||||
config.setShortMonthNames(shortMonthNames);
|
config.setShortMonthNames(shortMonthNames);
|
||||||
config.setServerTimeZoneId(serverTimeZoneId);
|
config.setServerTimeZoneId(serverTimeZoneId);
|
||||||
|
|
||||||
ftpConfig.put(name, config);
|
ftpConfig.put(label, config);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
* @see org.eclipse.rse.internal.services.files.ftp.parser.IFTPClientConfigFactory#getFTPClientConfig(java.lang.String)
|
|
||||||
*/
|
|
||||||
public FTPClientConfig getFTPClientConfig(String key)
|
|
||||||
{
|
|
||||||
return (FTPClientConfig)ftpConfig.get(key);
|
return (FTPClientConfig)ftpConfig.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,7 +118,7 @@ private static FTPClientConfigFactory factory = null;
|
||||||
*/
|
*/
|
||||||
public Set getKeySet()
|
public Set getKeySet()
|
||||||
{
|
{
|
||||||
return ftpConfig.keySet();
|
return keySet;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -109,6 +126,37 @@ private static FTPClientConfigFactory factory = null;
|
||||||
* @see org.apache.commons.net.ftp.parser.FTPFileEntryParserFactory#createFileEntryParser(java.lang.String)
|
* @see org.apache.commons.net.ftp.parser.FTPFileEntryParserFactory#createFileEntryParser(java.lang.String)
|
||||||
*/
|
*/
|
||||||
public FTPFileEntryParser createFileEntryParser(String key) throws ParserInitializationException {
|
public FTPFileEntryParser createFileEntryParser(String key) throws ParserInitializationException {
|
||||||
|
|
||||||
|
//
|
||||||
|
// the hashtable "ftpFileEntryParser" will be populated previously by getFTPClientConfig()
|
||||||
|
// but in case the execution flow gets modified it's worth checking and populating it if required
|
||||||
|
//
|
||||||
|
if(!ftpFileEntryParser.containsKey(key))
|
||||||
|
{
|
||||||
|
IConfigurationElement[] ce = ep.getConfigurationElements();
|
||||||
|
for (int i = 0; i < ce.length; i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
String label = ce[i].getAttribute("name"); //$NON-NLS-1$
|
||||||
|
|
||||||
|
if(label.equals(key))
|
||||||
|
{
|
||||||
|
//populate tables
|
||||||
|
String clas = ce[i].getAttribute("class"); //$NON-NLS-1$
|
||||||
|
|
||||||
|
FTPFileEntryParser entryParser=null;
|
||||||
|
try {
|
||||||
|
entryParser = (FTPFileEntryParser)ce[i].createExecutableExtension("class"); //$NON-NLS-1$
|
||||||
|
} catch (CoreException e) {
|
||||||
|
throw new ParserInitializationException(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
ftpFileEntryParser.put(clas, entryParser);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return (FTPFileEntryParser)ftpFileEntryParser.get(key);
|
return (FTPFileEntryParser)ftpFileEntryParser.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,8 +164,7 @@ private static FTPClientConfigFactory factory = null;
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
* @see org.apache.commons.net.ftp.parser.FTPFileEntryParserFactory#createFileEntryParser(org.apache.commons.net.ftp.FTPClientConfig)
|
* @see org.apache.commons.net.ftp.parser.FTPFileEntryParserFactory#createFileEntryParser(org.apache.commons.net.ftp.FTPClientConfig)
|
||||||
*/
|
*/
|
||||||
public FTPFileEntryParser createFileEntryParser(FTPClientConfig config)
|
public FTPFileEntryParser createFileEntryParser(FTPClientConfig config) throws ParserInitializationException {
|
||||||
throws ParserInitializationException {
|
|
||||||
|
|
||||||
String key = config.getServerSystemKey();
|
String key = config.getServerSystemKey();
|
||||||
return createFileEntryParser(key);
|
return createFileEntryParser(key);
|
||||||
|
|
Loading…
Add table
Reference in a new issue