edu.wisc.ssec.mcidasv.servermanager
Class EntryTransforms

java.lang.Object
  extended by edu.wisc.ssec.mcidasv.servermanager.EntryTransforms

public class EntryTransforms
extends Object

Useful methods for doing things like converting a AddeServer to a RemoteAddeEntry.


Field Summary
static Function<AddeServer,RemoteAddeEntry> convertIdvServer
          Function that transforms an AddeServer into a RemoteAddeEntry.
private static String cygwinPrefix
           
private static int cygwinPrefixLength
           
private static Matcher hostMatcher
          No sense in rebuilding things that don't need to be rebuilt.
private static Pattern hostPattern
          Matches "host" declarations in a MCTABLE file.
private static org.slf4j.Logger logger
          Logger object.
private static Matcher routeMatcher
          No sense in rebuilding things that don't need to be rebuilt.
private static Pattern routePattern
          Matches dataset routing information in a MCTABLE file.
 
Constructor Summary
private EntryTransforms()
          This is a utility class.
 
Method Summary
static String addeFormatToStr(LocalAddeEntry.AddeFormat format)
           
static void appendResolvFile(String filename, Collection<LocalAddeEntry> entries)
          Writes a Collection of LocalAddeEntrys to a "RESOLV.SRV" file.
static List<String> asResolvEntries(Collection<LocalAddeEntry> entries)
          Converts a Collection of LocalAddeEntrys into a List of Strings.
static String asResolvEntry(LocalAddeEntry entry)
          Converts a given LocalAddeEntry into a String that is suitable for including in a "RESOLV.SRV" file.
protected static Set<AddeEntry> convertAddeServerXml(Element root, AddeEntry.EntrySource source)
          Converts the XML contents of IdvResourceManager.RSC_ADDESERVER to a Set of RemoteAddeEntrys.
static Set<RemoteAddeEntry> convertIdvServers(List<AddeServer> idvServers)
           
static Set<AddeServer> convertMcvServers(Collection<AddeEntry> entries)
           
protected static Set<RemoteAddeEntry> convertUserXml(Element root)
          Converts the XML contents of ResourceManager.RSC_NEW_USERSERVERS to a Set of RemoteAddeEntrys.
static Set<RemoteAddeEntry> createEntriesFrom(RemoteAddeEntry entry)
           
static String demungeFileMask(String path)
          De-munges file mask strings.
static String entryTypeToStr(AddeEntry.EntryType type)
          Converts a given AddeEntry.EntryType to its String representation.
protected static Set<RemoteAddeEntry> extractMctableEntries(String path, String username, String project)
           
static Set<AddeEntry.EntryType> findEntryTypes(Collection<? extends AddeEntry> entries)
           
private static Map<String,String> mapDatasetsToIp(Map<String,String> datasets, Map<String,String> hostMap)
           
private static List<RemoteAddeEntry> mapDatasetsToName(Map<String,String> datasetToHost, Map<String,String> hostToIp, String username, String project)
          This method is slightly confusing, sorry!
private static Map<String,String> mapIpToName(Map<String,Set<String>> map)
           
static String mungeFileMask(String mask)
          Munges a file mask String into something "RESOLV.SRV" expects.
static Set<LocalAddeEntry> readResolvFile(String filename)
          Reads a "RESOLV.SRV" file and converts the contents into a Set of LocalAddeEntrys.
static LocalAddeEntry readResolvLine(String line)
          Converts a String containing a "RESOLV.SRV" entry into a LocalAddeEntry.
static Set<LocalAddeEntry> removeTemporaryEntriesFromResolvFile(String filename, Collection<LocalAddeEntry> entries)
           
static String serverNameToStr(LocalAddeEntry.ServerName serverName)
          Converts a given LocalAddeEntry.ServerName to its String representation.
static LocalAddeEntry.AddeFormat strToAddeFormat(String s)
          Attempts to convert a String into a member of LocalAddeEntry.AddeFormat.
static AddeEntry.EntrySource strToEntrySource(String s)
          Attempts to convert a String to an AddeEntry.EntrySource.
static AddeEntry.EntryStatus strToEntryStatus(String s)
          Attempts to convert a String into an AddeEntry.EntryStatus.
static AddeEntry.EntryType strToEntryType(String s)
          Attempts to convert a String to a AddeEntry.EntryType.
static AddeEntry.EntryValidity strToEntryValidity(String s)
          Attempts to convert a String to an AddeEntry.EntryValidity.
static LocalAddeEntry.ServerName strToServerName(String s)
          Attempts to convert a String to a LocalAddeEntry.ServerName.
private static void writeResolvFile(String filename, boolean append, Collection<LocalAddeEntry> entries)
          Writes a Collection of LocalAddeEntrys to a "RESOLV.SRV" file.
static void writeResolvFile(String filename, Collection<LocalAddeEntry> entries)
          Writes a Collection of LocalAddeEntrys to a "RESOLV.SRV" file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private static final org.slf4j.Logger logger
Logger object.


routePattern

private static final Pattern routePattern
Matches dataset routing information in a MCTABLE file.


hostPattern

private static final Pattern hostPattern
Matches "host" declarations in a MCTABLE file.


routeMatcher

private static final Matcher routeMatcher
No sense in rebuilding things that don't need to be rebuilt.


hostMatcher

private static final Matcher hostMatcher
No sense in rebuilding things that don't need to be rebuilt.


cygwinPrefix

private static final String cygwinPrefix
See Also:
Constant Field Values

cygwinPrefixLength

private static final int cygwinPrefixLength

convertIdvServer

public static final Function<AddeServer,RemoteAddeEntry> convertIdvServer
Function that transforms an AddeServer into a RemoteAddeEntry.

Constructor Detail

EntryTransforms

private EntryTransforms()
This is a utility class. Don't create it!

Method Detail

findEntryTypes

public static Set<AddeEntry.EntryType> findEntryTypes(Collection<? extends AddeEntry> entries)

convertIdvServers

public static Set<RemoteAddeEntry> convertIdvServers(List<AddeServer> idvServers)

convertMcvServers

public static Set<AddeServer> convertMcvServers(Collection<AddeEntry> entries)

convertUserXml

protected static Set<RemoteAddeEntry> convertUserXml(Element root)
Converts the XML contents of ResourceManager.RSC_NEW_USERSERVERS to a Set of RemoteAddeEntrys.

Parameters:
root - "Root" of the XML to convert.
Returns:
Set of RemoteAddeEntrys described by root.

createEntriesFrom

public static Set<RemoteAddeEntry> createEntriesFrom(RemoteAddeEntry entry)

convertAddeServerXml

protected static Set<AddeEntry> convertAddeServerXml(Element root,
                                                     AddeEntry.EntrySource source)
Converts the XML contents of IdvResourceManager.RSC_ADDESERVER to a Set of RemoteAddeEntrys.

Parameters:
root - XML to convert.
source - Used to "bulk set" the origin of whatever RemoteAddeEntrys get created.
Returns:
Set of RemoteAddeEntrys contained within root.

serverNameToStr

public static String serverNameToStr(LocalAddeEntry.ServerName serverName)
Converts a given LocalAddeEntry.ServerName to its String representation. Note that the resulting String is lowercase.

Parameters:
serverName - The server name to convert. Cannot be null.
Returns:
serverName converted to a lowercase String representation.
Throws:
NullPointerException - if serverName is null.

strToServerName

public static LocalAddeEntry.ServerName strToServerName(String s)
Attempts to convert a String to a LocalAddeEntry.ServerName.

Parameters:
s - Value whose ServerName is wanted. Cannot be null.
Returns:
One of ServerName. If there was no "sensible" conversion, the method returns LocalAddeEntry.ServerName.INVALID.
Throws:
NullPointerException - if s is null.

entryTypeToStr

public static String entryTypeToStr(AddeEntry.EntryType type)
Converts a given AddeEntry.EntryType to its String representation. Note that the resulting String is lowercase.

Parameters:
type - The type to convert. Cannot be null.
Returns:
type converted to a lowercase String representation.
Throws:
NullPointerException - if type is null.

strToEntryType

public static AddeEntry.EntryType strToEntryType(String s)
Attempts to convert a String to a AddeEntry.EntryType.

Parameters:
s - Value whose EntryType is wanted. Cannot be null.
Returns:
One of EntryType. If there was no "sensible" conversion, the method returns AddeEntry.EntryType.UNKNOWN.
Throws:
NullPointerException - if s is null.

strToEntrySource

public static AddeEntry.EntrySource strToEntrySource(String s)
Attempts to convert a String to an AddeEntry.EntrySource.

Parameters:
s - String representation of an EntrySource. Cannot be null.
Returns:
Uses AddeEntry.EntrySource.valueOf(String) to convert s to an EntrySource and returns. If no conversion was possible, returns AddeEntry.EntrySource.USER.
Throws:
NullPointerException - if s is null.

strToEntryValidity

public static AddeEntry.EntryValidity strToEntryValidity(String s)
Attempts to convert a String to an AddeEntry.EntryValidity.

Parameters:
s - String representation of an EntryValidity. Cannot be null.
Returns:
Uses AddeEntry.EntryValidity.valueOf(String) to convert s to an EntryValidity and returns. If no conversion was possible, returns AddeEntry.EntryValidity.UNVERIFIED.
Throws:
NullPointerException - if s is null.

strToEntryStatus

public static AddeEntry.EntryStatus strToEntryStatus(String s)
Attempts to convert a String into an AddeEntry.EntryStatus.

Parameters:
s - String representation of an EntryStatus. Cannot be null.
Returns:
Uses AddeEntry.EntryStatus.valueOf(String) to convert s into an EntryStatus and returns. If no conversion was possible, returns AddeEntry.EntryStatus.DISABLED.
Throws:
NullPointerException - if s is null.

strToAddeFormat

public static LocalAddeEntry.AddeFormat strToAddeFormat(String s)
Attempts to convert a String into a member of LocalAddeEntry.AddeFormat. This method does a little bit of magic with the incoming String:
  1. spaces are replaced with underscores
  2. dashes ("-") are removed
This was done because older "RESOLV.SRV" files permitted the "MCV" key to contain spaces or dashes, and that doesn't play so well with Java's enums.

Parameters:
s - String representation of an AddeFormat. Cannot be null.
Returns:
Uses LocalAddeEntry.AddeFormat.valueOf(String) to convert the modified String into an AddeFormat and returns. If no conversion was possible, returns LocalAddeEntry.AddeFormat.INVALID.
Throws:
NullPointerException - if s is null.

addeFormatToStr

public static String addeFormatToStr(LocalAddeEntry.AddeFormat format)

extractMctableEntries

protected static Set<RemoteAddeEntry> extractMctableEntries(String path,
                                                            String username,
                                                            String project)

mapDatasetsToName

private static List<RemoteAddeEntry> mapDatasetsToName(Map<String,String> datasetToHost,
                                                       Map<String,String> hostToIp,
                                                       String username,
                                                       String project)
This method is slightly confusing, sorry! Think of it kind of like a "SQL JOIN"...

Basically create RemoteAddeEntrys by using a hostname to determine which dataset belongs to which IP.

Parameters:
datasetToHost - Map of ADDE groups to host names.
hostToIp - Map of host names to IP addresses.
username - ADDE username.
project - ADDE project number (as a String).
Returns:
List of RemoteAddeEntry instances. Each hostname will have a value from datasetToHost and the accounting information is formed from username and project.

mapIpToName

private static Map<String,String> mapIpToName(Map<String,Set<String>> map)

mapDatasetsToIp

private static Map<String,String> mapDatasetsToIp(Map<String,String> datasets,
                                                  Map<String,String> hostMap)

readResolvFile

public static Set<LocalAddeEntry> readResolvFile(String filename)
                                          throws IOException
Reads a "RESOLV.SRV" file and converts the contents into a Set of LocalAddeEntrys.

Parameters:
filename - Filename containing desired LocalAddeEntrys. Cannot be null.
Returns:
Set of LocalAddeEntrys contained within filename.
Throws:
IOException - if there was a problem reading from filename.
See Also:
readResolvLine(String)

readResolvLine

public static LocalAddeEntry readResolvLine(String line)
Converts a String containing a "RESOLV.SRV" entry into a LocalAddeEntry.


writeResolvFile

public static void writeResolvFile(String filename,
                                   Collection<LocalAddeEntry> entries)
                            throws IOException
Writes a Collection of LocalAddeEntrys to a "RESOLV.SRV" file. This method discards the current contents of filename!

Parameters:
filename - Filename that will contain the LocalAddeEntrys within entries. Cannot be null.
entries - Set of entries to be written to filename. Cannot be null.
Throws:
IOException - if there was a problem writing to filename.
See Also:
appendResolvFile(String, Collection)

appendResolvFile

public static void appendResolvFile(String filename,
                                    Collection<LocalAddeEntry> entries)
                             throws IOException
Writes a Collection of LocalAddeEntrys to a "RESOLV.SRV" file. This method will append the contents of entries to filename.

Parameters:
filename - Filename that will contain the LocalAddeEntrys within entries. Cannot be null.
entries - Collection of entries to be written to filename. Cannot be null.
Throws:
IOException - if there was a problem writing to filename.
See Also:
writeResolvFile(String, Collection)

writeResolvFile

private static void writeResolvFile(String filename,
                                    boolean append,
                                    Collection<LocalAddeEntry> entries)
                             throws IOException
Writes a Collection of LocalAddeEntrys to a "RESOLV.SRV" file.

Parameters:
filename - Filename that will contain the LocalAddeEntrys within entries. Cannot be null.
append - If true, append entries to filename. Otherwise discards contents of filename.
entries - Collection of entries to be written to filename. Cannot be null.
Throws:
IOException - if there was a problem writing to filename.
See Also:
appendResolvFile(String, Collection), asResolvEntry(LocalAddeEntry)

removeTemporaryEntriesFromResolvFile

public static Set<LocalAddeEntry> removeTemporaryEntriesFromResolvFile(String filename,
                                                                       Collection<LocalAddeEntry> entries)
                                                                throws IOException
Throws:
IOException

demungeFileMask

public static String demungeFileMask(String path)
De-munges file mask strings.

Throws:
NullPointerException - if path is null.

mungeFileMask

public static String mungeFileMask(String mask)
Munges a file mask String into something "RESOLV.SRV" expects.

Munging is only needed for Windows users--the process converts back slashes into forward slashes and prefixes with "/cygdrive/".

Throws:
NullPointerException - if mask is null.

asResolvEntries

public static List<String> asResolvEntries(Collection<LocalAddeEntry> entries)
Converts a Collection of LocalAddeEntrys into a List of Strings.

Parameters:
entries - Collection of entries to convert. Should not be null.
Returns:
entries represented as Strings.
See Also:
asResolvEntry(LocalAddeEntry)

asResolvEntry

public static String asResolvEntry(LocalAddeEntry entry)
Converts a given LocalAddeEntry into a String that is suitable for including in a "RESOLV.SRV" file. This method does not append a newline to the end of the String.

Parameters:
entry - The LocalAddeEntry to convert. Should not be null.
Returns:
entry as a "RESOLV.SRV" entry.