Package org.eigenbase.resgen

# Class ResourceDefinition

java.lang.Object
org.eigenbase.resgen.ResourceDefinition

public class ResourceDefinition extends Object
Definition of a resource such as a parameterized message or exception.

A resource is identified within a `ResourceBundle` by a text key, and has a message in its base locale (which is usually US-English (en_US)). It may also have a set of properties, which are represented as name-value pairs.

A resource definition is immutable.

Since:
  19 September, 2005
Version:
  $Id: //open/util/resgen/src/org/eigenbase/resgen/ResourceDefinition.java#4 $
Author:
  jhyde

## Field Summary

Fields
Modifier and Type
Field
Description
`final String`
`baseMessage`
`final String`
`key`
`static final int`
`TYPE_DATE`
`static final int`
`TYPE_NUMBER`
`static final int`
`TYPE_STRING`
`static final int`
`TYPE_TIME`
`static final int`
`TYPE_UNKNOWN`

## Constructor Summary

Constructors
Constructor
Description
`ResourceDefinition(String key, String baseMessage)`
Creates a resource definition with no properties.
`ResourceDefinition(String key, String baseMessage, String[] props)`
Creates a resource definition.

## Method Summary

Modifier and Type
Method
Description
`protected static int`
`getArgType(int i, String message)`
Returns the type of the `i`th argument inside a message, or `TYPE_UNKNOWN` if not found.
`String[]`
`getArgTypes()`
Returns the types of arguments.
`protected static String[]`
`getArgTypes(String message, String[] typeNames)`
Parses a message for the arguments inside it, and returns an array with the types of those arguments.
`protected static String[]`
`getArgTypesByHand(String message, String[] typeNames)`
`String`
`getBaseMessage()`
Returns this resource definition's message in the base locale.
`String`
`getKey()`
Returns this resource definition's key.
`Properties`
`getProperties()`
Returns the properties of this resource definition.
`ResourceInstance`
`instantiate(ResourceBundle bundle, Object[] args)`
Creates an instance of this definition with a set of parameters.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### key

public final String key

### baseMessage

public final String baseMessage

### TYPE_UNKNOWN

public static final int TYPE_UNKNOWN

See Also:
  - Constant Field Values

### TYPE_STRING

public static final int TYPE_STRING

See Also:
  - Constant Field Values

### TYPE_NUMBER

public static final int TYPE_NUMBER

See Also:
  - Constant Field Values

### TYPE_DATE

public static final int TYPE_DATE

See Also:
  - Constant Field Values

### TYPE_TIME

public static final int TYPE_TIME

See Also:
  - Constant Field Values

## Constructor Details

### ResourceDefinition

public ResourceDefinition(String key, String baseMessage)
Creates a resource definition with no properties.

Parameters:
  `key` - Unique name for this resource definition.
  `baseMessage` - Message for this resource definition in the base locale.

### ResourceDefinition

public ResourceDefinition(String key, String baseMessage, String[] props)
Creates a resource definition.

Parameters:
  `key` - Unique name for this resource definition.
  `baseMessage` - Message for this resource definition in the base locale.
  `props` - Array of property name/value pairs. `null` means the same as an empty array.

## Method Details

### getKey

public String getKey()
Returns this resource definition's key.

### getBaseMessage

public String getBaseMessage()
Returns this resource definition's message in the base locale. (To find the message in another locale, you will need to load a resource bundle for that locale.)

### getProperties

public Properties getProperties()
Returns the properties of this resource definition.

### getArgTypes

public String[] getArgTypes()
Returns the types of arguments.

### instantiate

public ResourceInstance instantiate(ResourceBundle bundle, Object[] args)
Creates an instance of this definition with a set of parameters. This is a factory method, which may be overridden by a derived class.

Parameters:
  `bundle` - Resource bundle the resource instance will belong to (This contains the locale, among other things.)
  `args` - Arguments to populate the message's parameters. The arguments must be consistent in number and type with the results of `getArgTypes()`.

### getArgTypes

protected static String[] getArgTypes(String message, String[] typeNames)
Parses a message for the arguments inside it, and returns an array with the types of those arguments.

For example, `getArgTypes("I bought {0,number} {2}s", new String[] {"string", "number", "date", "time"})` yields {"number", null, "string"}. Note the null corresponding to missing message #1.

Parameters:
  `message` - Message to be parsed.
  `typeNames` - Strings to return for types.
Returns:
  Array of type names

### getArgTypesByHand

protected static String[] getArgTypesByHand(String message, String[] typeNames)

### getArgType

protected static int getArgType(int i, String message)
Returns the type of the `i`th argument inside a message, or `TYPE_UNKNOWN` if not found.

Parameters:
  `i` - Ordinal of argument
  `message` - Message to parse
Returns:
  Type code (`TYPE_STRING` etc.)