public class MacroProcessor
extends java.lang.Object
Title: Framework Support Library
Description: Simple macro processor which resolves macro definitions embedded into some string to actual values which these definitions represent.
Example: The following string with macro definitions:
Current date and time is $datetime:(yyyyMMdd-hh:mm:ss).
After processing is resolved to another string:
Current date and time is 20111109-05:20:01.
The syntax for macro definition is the following:
$<functionName>:(<functionArgument>)
Where: <functionArgument>
is optional and for some macro functions can be omitted.
The following functions for macro definitions are supported:
datetime
- current date and/or time.
Function argument is pattern for result date/time representation. Standard Java format is used.
See SimpleDateFormat
for details.
system
- value of system property.
Function argument is name of system property.
rand
- randomly generated integer.
Does not take an argument.
guid
- generated unique identified.
Does not take an argument.
gvar
- value of runtime global variable.
Function argument is a fully qualified name of the global variable in the following form:
<PoolName>.<VariableName>
hash
- hash out of provided argument.
Function argument is the value which is supposed to be hashed.
hostname
- value of system property 'hostname' or interface with specified index.
If function has argument then it determines interface index, otherwise it determines the name of the localhost.
event
- special function which is used for event properties retrieval.
NOTE: method setEvent(com.streamscape.sdo.ImmutableEventDatagram)
should be called to set event before resolving of such macro definitions.
Function argument is the name of an event property which is supposed to be resolved.
Depending on the set thru setEvent(com.streamscape.sdo.ImmutableEventDatagram)
event model, the following properties can be specified as an argument
for macro definition:
EventDatagram
Any user defined or one of the following system properties:
EventSource
EventId
EventKey
EventGroupId
CorrelationId
EventReplyTo
EventForwardTo
Timestamp
EventExpiration
ExceptionEventDatagram
One of the following system properties:
EventSource
EventId
EventKey
EventGroupId
CorrelationId
EventReplyTo
Timestamp
ErrorCode
ErrorMessage
Severity
AdvisoryEventDatagram
One of the following system properties:
EventSource
EventId
EventKey
EventGroupId
CorrelationId
Timestamp
StateAdvisory
Any user defined or one of the following system properties:
EventSource
EventId
EventKey
EventGroupId
CorrelationId
Timestamp
StateAdvisoryName
StateAdvisoryMessage
StateAdvisoryType
MetricAdvisory
One of the following system properties:
EventSource
EventId
EventKey
EventGroupId
CorrelationId
Timestamp
MetricAdvisoryMessage
MetricMaxTreshold
MetricMinTreshold
MetricValue
MetricUnits
Example: The following code snippet shows the basics of work with the 'event' macro definition:
DataEvent event = (DataEvent)EventDatagramFactory.getInstance().createEvent(EVENT_ID);
event.setEventStringProperty("TestStringProperty", "TestStringPropertyValue");
MacroProcessor macroProcessor = new MacroProcessor();
macroProcessor.setEvent(event);
System.out.println(macroProcessor.process("Value of test string property is '$event:(TestStringProperty)'"));
Value of test string property is 'TestStringPropertyValue'
static
- special function which is used for processStaticMacro(String)
method.
Function argument is another macro definition(s) which is supposed to be processed during processStaticMacro(String)
method invocation.
Example: The following string with macro definitions:
Current date and time is $static:($datetime:(yyyyMMdd-hh:mm:ss)) and corresponding macro looks like $datetime:(yyyyMMdd-hh:mm:ss).
After processing with processStaticMacro(String)
method is resolved to string:
Current date and time is 20111109-05:20:01 and corresponding macro looks like $datetime:(yyyyMMdd-hh:mm:ss).
And after processing with process(String)
method is resolved to another string:
Current date and time is 20111109-05:20:01 and corresponding macro looks like 20111109-05:20:01.
NOTE: Nested macro definitions are allowed.
Example: The following string with nested macro definitions:
Hash out of the current date is $hash:($datetime:(yyyyMMdd)).
After processing is resolved to another string:
Hash out of the current date is 0a8edd6456e99df353e79601137a58fc.
Copyright: Copyright (c) 2010
Company: StreamScape Technologies
Modifier and Type | Class and Description |
---|---|
static class |
MacroProcessor.EventMacroSystemParams |
Constructor and Description |
---|
MacroProcessor()
Creates a new instance of macro processor.
|
MacroProcessor(Moderator moderator) |
Modifier and Type | Method and Description |
---|---|
static boolean |
isGlobalVariable(java.lang.String value) |
static boolean |
isMacro(java.lang.String source) |
java.lang.String |
process(java.lang.String source)
Performs processing of the provided string.
|
java.lang.String |
processStaticMacro(java.lang.String source)
Performs macro substitutions of all macro definitions enclosed into 'static' function.
|
void |
setEvent(ImmutableEventDatagram event) |
public MacroProcessor()
public MacroProcessor(Moderator moderator)
public java.lang.String process(java.lang.String source)
source
- Source string for processing.public void setEvent(ImmutableEventDatagram event)
public java.lang.String processStaticMacro(java.lang.String source)
source
- Source string for processing.public static boolean isMacro(java.lang.String source)
public static boolean isGlobalVariable(java.lang.String value)
Copyright © 2015-2024 StreamScape Technologies. All rights reserved.