From 56c2add9e5cff32435d113ac856a852677a4a901 Mon Sep 17 00:00:00 2001 From: Javier Montalvo Orus Date: Thu, 10 May 2007 10:40:43 +0000 Subject: [PATCH] [176216] parsers dynamically loaded when needed --- .../ftp/parser/FTPClientConfigFactory.java | 125 ++++++++++++------ 1 file changed, 86 insertions(+), 39 deletions(-) diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.ftp/src/org/eclipse/rse/internal/subsystems/files/ftp/parser/FTPClientConfigFactory.java b/rse/plugins/org.eclipse.rse.subsystems.files.ftp/src/org/eclipse/rse/internal/subsystems/files/ftp/parser/FTPClientConfigFactory.java index 1b21a225e16..32bf4473fdd 100644 --- a/rse/plugins/org.eclipse.rse.subsystems.files.ftp/src/org/eclipse/rse/internal/subsystems/files/ftp/parser/FTPClientConfigFactory.java +++ b/rse/plugins/org.eclipse.rse.subsystems.files.ftp/src/org/eclipse/rse/internal/subsystems/files/ftp/parser/FTPClientConfigFactory.java @@ -12,6 +12,7 @@ package org.eclipse.rse.internal.subsystems.files.ftp.parser; import java.util.Hashtable; import java.util.Set; +import java.util.TreeSet; import org.apache.commons.net.ftp.FTPClientConfig; 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 { -private static FTPClientConfigFactory factory = null; + private static FTPClientConfigFactory factory = null; + private Set keySet = new TreeSet(); private Hashtable ftpConfig = 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 @@ -45,44 +48,11 @@ private static FTPClientConfigFactory factory = null; 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(); for (int i = 0; i < ce.length; i++) { - config = null; - - String name = ce[i].getAttribute("name"); //$NON-NLS-1$ - 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) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - ftpFileEntryParser.put(clas, entryParser); - - String defaultDateFormatStr = ce[i].getAttribute("defaultDateFormatStr"); //$NON-NLS-1$ - String recentDateFormatStr = ce[i].getAttribute("recentDateFormatStr"); //$NON-NLS-1$ - String serverLanguageCode = ce[i].getAttribute("serverLanguageCode"); //$NON-NLS-1$ - String shortMonthNames = ce[i].getAttribute("shortMonthNames"); //$NON-NLS-1$ - String serverTimeZoneId = ce[i].getAttribute("serverTimeZoneId"); //$NON-NLS-1$ - - config = new FTPClientConfig(clas); - - //not necessary checking for null, as null is valid input - config.setDefaultDateFormatStr(defaultDateFormatStr); - config.setRecentDateFormatStr(recentDateFormatStr); - config.setServerLanguageCode(serverLanguageCode); - config.setShortMonthNames(shortMonthNames); - config.setServerTimeZoneId(serverTimeZoneId); - - ftpConfig.put(name, config); - + String label = ce[i].getAttribute("name"); //$NON-NLS-1$ + keySet.add(label); } } @@ -92,6 +62,53 @@ private static FTPClientConfigFactory factory = null; */ 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$ + + 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); + + String defaultDateFormatStr = ce[i].getAttribute("defaultDateFormatStr"); //$NON-NLS-1$ + String recentDateFormatStr = ce[i].getAttribute("recentDateFormatStr"); //$NON-NLS-1$ + String serverLanguageCode = ce[i].getAttribute("serverLanguageCode"); //$NON-NLS-1$ + String shortMonthNames = ce[i].getAttribute("shortMonthNames"); //$NON-NLS-1$ + String serverTimeZoneId = ce[i].getAttribute("serverTimeZoneId"); //$NON-NLS-1$ + + config = new FTPClientConfig(clas); + + //not necessary checking for null, as null is valid input + config.setDefaultDateFormatStr(defaultDateFormatStr); + config.setRecentDateFormatStr(recentDateFormatStr); + config.setServerLanguageCode(serverLanguageCode); + config.setShortMonthNames(shortMonthNames); + config.setServerTimeZoneId(serverTimeZoneId); + + ftpConfig.put(label, config); + + } + } + } + + return (FTPClientConfig)ftpConfig.get(key); } @@ -101,7 +118,7 @@ private static FTPClientConfigFactory factory = null; */ 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) */ 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); } @@ -116,8 +164,7 @@ private static FTPClientConfigFactory factory = null; * (non-Javadoc) * @see org.apache.commons.net.ftp.parser.FTPFileEntryParserFactory#createFileEntryParser(org.apache.commons.net.ftp.FTPClientConfig) */ - public FTPFileEntryParser createFileEntryParser(FTPClientConfig config) - throws ParserInitializationException { + public FTPFileEntryParser createFileEntryParser(FTPClientConfig config) throws ParserInitializationException { String key = config.getServerSystemKey(); return createFileEntryParser(key);