com.sun.jini.loader.pref.internal
Class PreferredResources

java.lang.Object
  extended by com.sun.jini.loader.pref.internal.PreferredResources

public final class PreferredResources
extends Object

Internal data structure which holds preference information for a preferred class loader. This utility is used only by the preferred class loader provider and is not intended to be a public API. A preferred resources object is created from an input stream which is formatted according to the Preferred List Syntax which is defined in the specification for net.jini.loader.pref.PreferredClassProvider Preferred resources instances hold preferred list expression data and the preferred state for the resources contained in a given preferred class loader.

Since:
2.0
Author:
Sun Microsystems, Inc.

Field Summary
private  Map completeNamePrefs
           
private  Boolean defaultPreference
          default preference setting
private static String HEADER_MAJOR_VERSION
           
private static String HEADER_MINOR_VERSION
           
private static String HEADER_TITLE
          string that starts preference specification headers
private  boolean isEmpty
          flag to signal if this preference object is empty
static int NAME_NO_PREFERENCE
          Constant value that indicates that there is no preference value for a given name.
static int NAME_NOT_PREFERRED
          Constant value that indicates that the resource for a given name is known to be not preferred.
static int NAME_PREFERRED
          Constant value that indicates that a given name is preferred.
static int NAME_PREFERRED_RESOURCE_EXISTS
          Constant value that indicates that a given resource is preferred.
private static String NAME_PREFIX
           
private  Map namespacePrefs
           
private  Map packagePrefs
           
private static String PREF_PREFIX
          preference syntax keywords
 
Constructor Summary
PreferredResources(InputStream in)
          Create a preference object from a stream of formatted preference syntax.
 
Method Summary
private  Integer getClassNameState(String name)
          Returns the preference state for a given name (as is done in getNonclassNameState) but also interprets the notation for inner classes as a wild card so that the preference value for a container class propagates to the classes it contains.
 Boolean getDefaultPreference()
          Returns the preference setting that will be applied to names which have no explicit preference setting in contained preference settings.
private  Boolean getNamespacePreference(String namespace)
          Return a Boolean for the most specific namespace expression which matches name. null if the name does not match a namespace preference expression.
 int getNameState(String name, boolean isClass)
          Searches the preference maps to determine the preference state of the named resource.
 Boolean getWildcardPreference(String name)
          Return the boolean value of the most specific wild card (package and namespace) expression which matches name.
private  void mapPut(Map map, String name, Object preference)
          Insert a preference expression and value into a given map.
private  void read(InputStream in)
          Read and parse preference information from the parameter input stream in.
private  String readLineTrimComments(BufferedReader br)
          Reads the next line from the specified BufferedReader, removing leading and trailing whitespace and comments.
 void setNameState(String name, int prefState)
          Enable MarshalInputStream to optimize preference information: permits complete name expressions to be added for names that only match wild-card expressions.
 void write(OutputStream out)
          Write the preferences to the specified OutputStream using the preference list syntax.
private  void writeMap(Map prefs, Writer out, String suffix)
          Write the contents of the map into out using the preference syntax.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NAME_NO_PREFERENCE

public static final int NAME_NO_PREFERENCE
Constant value that indicates that there is no preference value for a given name.

See Also:
Constant Field Values

NAME_NOT_PREFERRED

public static final int NAME_NOT_PREFERRED
Constant value that indicates that the resource for a given name is known to be not preferred. This state is applicable when a preference expression declared that the name is not preferred or when the resource for the name (preferred or not) is known to not exist.

See Also:
Constant Field Values

NAME_PREFERRED

public static final int NAME_PREFERRED
Constant value that indicates that a given name is preferred. This state is applicable when a preference expression declares the name to be preferred but it is uncertain whether the resource for the name the exists.

See Also:
Constant Field Values

NAME_PREFERRED_RESOURCE_EXISTS

public static final int NAME_PREFERRED_RESOURCE_EXISTS
Constant value that indicates that a given resource is preferred. This state is applicable when a preference expression declares the name to be preferred and the resource for the name is known to exist.

See Also:
Constant Field Values

HEADER_TITLE

private static final String HEADER_TITLE
string that starts preference specification headers

See Also:
Constant Field Values

HEADER_MAJOR_VERSION

private static final String HEADER_MAJOR_VERSION
See Also:
Constant Field Values

HEADER_MINOR_VERSION

private static final String HEADER_MINOR_VERSION
See Also:
Constant Field Values

PREF_PREFIX

private static final String PREF_PREFIX
preference syntax keywords

See Also:
Constant Field Values

NAME_PREFIX

private static final String NAME_PREFIX
See Also:
Constant Field Values

namespacePrefs

private Map namespacePrefs

packagePrefs

private Map packagePrefs

completeNamePrefs

private Map completeNamePrefs

isEmpty

private boolean isEmpty
flag to signal if this preference object is empty


defaultPreference

private Boolean defaultPreference
default preference setting

Constructor Detail

PreferredResources

public PreferredResources(InputStream in)
                   throws IOException
Create a preference object from a stream of formatted preference syntax.

Throws:
IOException
See Also:
PreferredResources
Method Detail

read

private void read(InputStream in)
           throws IOException
Read and parse preference information from the parameter input stream in. When the method completes, the preference expression maps contain preference settings for preference names contained in the input stream.

Throws:
IOException

readLineTrimComments

private String readLineTrimComments(BufferedReader br)
                             throws IOException
Reads the next line from the specified BufferedReader, removing leading and trailing whitespace and comments. Null is returned on EOF.

Throws:
IOException

mapPut

private void mapPut(Map map,
                    String name,
                    Object preference)
             throws IOException
Insert a preference expression and value into a given map.

Throws:
IOException

write

public void write(OutputStream out)
           throws IOException
Write the preferences to the specified OutputStream using the preference list syntax. Preference expressions are written in the following order: Complete name expressions Package expressions Namespace expressions

Parameters:
out - the stream to which formatted preference information will be written
Throws:
IOException - if an error occurs while writing to the stream

writeMap

private void writeMap(Map prefs,
                      Writer out,
                      String suffix)
               throws IOException
Write the contents of the map into out using the preference syntax.

Throws:
IOException

getDefaultPreference

public Boolean getDefaultPreference()
Returns the preference setting that will be applied to names which have no explicit preference setting in contained preference settings. The default preference is set by the first preference setting with no associated name in a preferences list file.

Returns:
default boolean preference value for these preferences

setNameState

public void setNameState(String name,
                         int prefState)
                  throws IOException
Enable MarshalInputStream to optimize preference information: permits complete name expressions to be added for names that only match wild-card expressions. These added expressions hold data that tells if a resource has been loaded. This method makes this object mutable. Synchronization must be used to ensure consistent preference state when this method is called.

Parameters:
name - the name for which preferred state will be set
prefState - the preferred state for the given name
Throws:
IOException - if the name length is zero length

getNameState

public int getNameState(String name,
                        boolean isClass)
                 throws IOException
Searches the preference maps to determine the preference state of the named resource. The preference state for the given resource name is returned. The preference state is an integer that is equal to one of the preference state values defined above. This state integer tells the preference value of name and whether its resource is known to exist.

Parameters:
name -
isClass - whether the given name refers to a class resource
Returns:
the state for the given name which will be set to one of the following values: NAME_NO_PREFERENCE, NAME_NOT_PREFERRED, NAME_PREFERRED, NAME_PREFERRED_RESOURCE_EXISTS
Throws:
IOException - if an error occurs getting the state for the supplied name

getClassNameState

private Integer getClassNameState(String name)
                           throws IOException
Returns the preference state for a given name (as is done in getNonclassNameState) but also interprets the notation for inner classes as a wild card so that the preference value for a container class propagates to the classes it contains. More specific inner classes names override more general container preference.

Throws:
IOException

getWildcardPreference

public Boolean getWildcardPreference(String name)
Return the boolean value of the most specific wild card (package and namespace) expression which matches name. Package preferences are always more specific than namespace preferences.

Parameters:
name - the resource name to which the returned boolean value will apply
Returns:
Boolean.TRUE/code> if name is preferred. Boolean.FALSE is it is not. null if there is no wildcard preference for the name.

getNamespacePreference

private Boolean getNamespacePreference(String namespace)
Return a Boolean for the most specific namespace expression which matches name. null if the name does not match a namespace preference expression.



Copyright 2007-2010, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.