Package org.jboss.hal.meta
Class AddressTemplate
- java.lang.Object
-
- org.jboss.hal.meta.AddressTemplate
-
public final class AddressTemplate extends Object implements Iterable<String>
Template for a DMR address which might contain multiple variable parts.An address template can be defined using the following BNF:
<address template> ::= "/" | <segment> <segment> ::= <tuple> | <segment>"/"<tuple> <tuple> ::= <variable> | <key>"="<value> <variable> ::= "{"<alpha>"}" <key> ::= <alpha> <value> ::= <variable> | <alpha> | "*" <alpha> ::= <upper> | <lower> <upper> ::= "A" | "B" | … | "Z" <lower> ::= "a" | "b" | … | "z"Following variables are supported: -
{domain.controller}-{selected.profile}-{selected.group}-{selected.server-config}-{selected.server}To get a fully qualified address from an address template use the method
resolve(). For standalone mode the variables will resolve to an empty string. The values of the variables are managed by theStatementContext.AddressTemplate a2 = AddressTemplate.of("{selected.profile}"); AddressTemplate a3 = AddressTemplate.of("{selected.profile}/subsystem=mail"); AddressTemplate a4 = AddressTemplate.of("{selected.profile}/subsystem=mail/mail-session=*");
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceAddressTemplate.Unresolver
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description AddressTemplateappend(String template)Appends the specified encoded template to this template and returns a new template.AddressTemplateappend(AddressTemplate template)booleanequals(Object o)StringfirstName()StringfirstValue()AddressTemplategetParent()inthashCode()booleanisEmpty()booleanisOptional()Iterator<String>iterator()AddressTemplatejsAppend(Object address)Append an address to this addrress template and return a new one.StringlastName()StringlastValue()static AddressTemplateof(String template)Creates a new address template from an encoded string template.static AddressTemplateof(ResourceAddress address)Turns a resource address into an address template which is the opposite ofresolve(StatementContext, String...).static AddressTemplateof(ResourceAddress address, AddressTemplate.Unresolver unresolver)Turns a resource address into an address template which is the opposite ofresolve(StatementContext, String...).static AddressTemplateof(StatementContext.Expression placeholder)Creates a new address template from a well known placeholder.static AddressTemplateof(StatementContext.Expression placeholder, String template)Creates a new address template from a placeholder and an encoded string template. '/' characters inside values must have been encoded usingModelNodeHelper.encodeValue(String).static AddressTemplateof(StatementContext.Expression placeholder1, StatementContext.Expression placeholder2)Creates a new address template from two placeholders.static AddressTemplateof(StatementContext.Expression placeholder1, StatementContext.Expression placeholder2, String template)Creates a new address template from two placeholders and an encoded string template. '/' characters inside values must have been encoded usingModelNodeHelper.encodeValue(String).AddressTemplatereplaceWildcards(String wildcard, String... wildcards)Replaces one or more wildcards with the specified values starting from left to right and returns a new address template.ResourceAddressresolve(StatementContext context, String... wildcards)Resolve this address template against the specified statement context.intsize()AddressTemplatesubTemplate(int fromIndex, int toIndex)Works likeList.subList(int, int)over the tokens of this template and throws the same exceptions.StringtoString()-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Field Detail
-
ROOT
public static final AddressTemplate ROOT
The root template
-
EQUALS
public static final String EQUALS
- See Also:
- Constant Field Values
-
OPTIONAL
public static final String OPTIONAL
- See Also:
- Constant Field Values
-
-
Method Detail
-
of
public static AddressTemplate of(StatementContext.Expression placeholder)
Creates a new address template from a well known placeholder.
-
of
public static AddressTemplate of(StatementContext.Expression placeholder, String template)
Creates a new address template from a placeholder and an encoded string template. '/' characters inside values must have been encoded usingModelNodeHelper.encodeValue(String).
-
of
public static AddressTemplate of(StatementContext.Expression placeholder1, StatementContext.Expression placeholder2)
Creates a new address template from two placeholders.
-
of
public static AddressTemplate of(StatementContext.Expression placeholder1, StatementContext.Expression placeholder2, String template)
Creates a new address template from two placeholders and an encoded string template. '/' characters inside values must have been encoded usingModelNodeHelper.encodeValue(String).
-
of
public static AddressTemplate of(String template)
Creates a new address template from an encoded string template.
-
of
public static AddressTemplate of(ResourceAddress address)
Turns a resource address into an address template which is the opposite ofresolve(StatementContext, String...).
-
of
public static AddressTemplate of(ResourceAddress address, AddressTemplate.Unresolver unresolver)
Turns a resource address into an address template which is the opposite ofresolve(StatementContext, String...). Use theAddressTemplate.Unresolverfunction to specify how the segments of the resource address are "unresolved". It is called for each segment of the specified resource address.
-
toString
public String toString()
-
isEmpty
public boolean isEmpty()
- Returns:
- true if this template contains no tokens, false otherwise
-
size
public int size()
- Returns:
- the number of tokens
-
append
public AddressTemplate append(String template)
Appends the specified encoded template to this template and returns a new template. If the specified template does not start with a slash, '/' is automatically appended. '/' characters inside values must have been encoded usingModelNodeHelper.encodeValue(String).- Parameters:
template- the encoded template to append (makes no difference whether it starts with '/' or not)- Returns:
- a new template
-
append
public AddressTemplate append(AddressTemplate template)
-
subTemplate
public AddressTemplate subTemplate(int fromIndex, int toIndex)
Works likeList.subList(int, int)over the tokens of this template and throws the same exceptions.- Parameters:
fromIndex- low endpoint (inclusive) of the sub templatetoIndex- high endpoint (exclusive) of the sub template- Returns:
- a new address template containing the specified tokens.
- Throws:
IndexOutOfBoundsException- for an illegal endpoint index value (fromIndex < 0 || toIndex > size || fromIndex > toIndex)
-
getParent
public AddressTemplate getParent()
- Returns:
- the parent address template or the root template
-
replaceWildcards
public AddressTemplate replaceWildcards(String wildcard, String... wildcards)
Replaces one or more wildcards with the specified values starting from left to right and returns a new address template.This method does not resolve the address template. The returned template is still unresolved.
- Parameters:
wildcard- the first wildcard (mandatory)wildcards- more wildcards (optional)- Returns:
- a new (still unresolved) address template with the wildcards replaced by the specified values.
-
firstName
public String firstName()
- Returns:
- the name of the first segment or null if this address template is empty.
-
firstValue
public String firstValue()
- Returns:
- the value of the first segment or null if this address template is empty.
-
lastName
public String lastName()
- Returns:
- the name of the last segment or null if this address template is empty.
-
lastValue
public String lastValue()
- Returns:
- the value of the last segment or null if this address template is empty.
-
isOptional
public boolean isOptional()
-
resolve
public ResourceAddress resolve(StatementContext context, String... wildcards)
Resolve this address template against the specified statement context.- Parameters:
context- the statement contextwildcards- An optional list of values which are used to resolve any wildcards in this address template from left to right- Returns:
- a fully qualified resource address which might be empty, but which does not contain any tokens
-
jsAppend
public AddressTemplate jsAppend(Object address)
Append an address to this addrress template and return a new one.- Parameters:
address- The address to append.- Returns:
- a new address template with the specified address added at the end.
-
-