|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
com.ibm.wbi.Meg
A Meg is a self-contained content tailoring entity. It receives a call
to handleRequest()
to tailor a particular type of
"Request" specified by the provided RequestEvent
.
The meg must be thread safe since multiple threads (for different requests)
may be calling the handleRequest()
method.
Field Summary | |
static java.lang.String |
COPYRIGHT
IBM copyright information. |
static int |
EDITOR
An Editor meg. |
static int |
GENERATOR
A Generator meg. |
static int |
MONITOR
A Monitor meg. |
static int |
REQUEST_EDITOR
A Request Editor meg. |
static int |
UNDEFINED
An undefined meg type. |
Method Summary | |
void |
forwardRequest(Meg meg,
RequestEvent event)
Forward this request directly to another Meg for
handling. |
java.lang.String |
getCondition()
Get the condition of the Meg . |
boolean |
getEnabled()
Get the enabled state of the Meg . |
java.lang.String |
getMegProperty(java.lang.String key)
Returns the property which is mapped to the given key name. |
java.lang.String |
getMegProperty(java.lang.String key,
java.lang.String defaultValue)
Returns the property which is mapped to the given key name or a default value if no value was found in the database. |
java.util.Enumeration |
getMegPropertyKeys()
Returns an enumeration of all the Meg property keys
set by this Meg . |
java.lang.String |
getName()
Get the name of the Meg . |
Plugin |
getPlugin()
Get the Plugin of the Meg . |
int |
getPriority()
Get the priority of the Meg in the range of 100 to 1. |
SystemContext |
getSystemContext()
Get the SystemContext object passed in with the
initialize method. |
abstract int |
getType()
Get the Meg type. |
abstract void |
handleRequest(RequestEvent event)
The method called to handle a request that satisfies the Meg 's condition. |
void |
initialize()
Called when the Meg is initialized. |
void |
initialize(SystemContext systemContext)
Deprecated. Override initialize() instead and use
getSystemContext() |
boolean |
isEnabled()
Determine if this Meg is enabled. |
boolean |
isMegApplicable(RequestInfo ri)
Determines if this meg satisfies a request by its RequestInfo
object using the built condition tree (does not consider if
it is enabled or not). |
protected void |
loadMegResources(Section section)
Retains a reference to the database section for this Meg 's properties which is used for
getMegResource and setMegResource
methods. |
protected void |
run(java.lang.Object argument)
|
void |
setCondition(java.lang.String condition)
Set the condition of the Meg . |
void |
setEnabled(boolean enabled)
Set the enabled state of the Meg . |
void |
setMegProperty(java.lang.String key,
java.lang.String value)
Sets the property which is mapped to the given Meg
property key name. |
void |
setName(java.lang.String name)
Set the name of the Meg used to provide a description. |
void |
setPriority(int priority)
Set the priority of the Meg . |
void |
setSystemContext(SystemContext systemContext)
Set the SystemContext object for this Meg. |
void |
setup(java.lang.String propertyName)
Load the attributes for the Meg from a property file. |
void |
setup(java.lang.String name,
java.lang.String condition)
Setup the Meg with the given attributes. |
void |
setup(java.lang.String name,
java.lang.String condition,
int priority)
Setup the Meg with the given attributes and is enabled. |
void |
setup(java.lang.String name,
java.lang.String condition,
int priority,
boolean enabled)
Setup the Meg with the given attributes. |
Field Detail |
public static final java.lang.String COPYRIGHT
public static final int UNDEFINED
public static final int REQUEST_EDITOR
public static final int GENERATOR
public static final int EDITOR
public static final int MONITOR
Method Detail |
public void setup(java.lang.String propertyName)
Meg
from a property file. Any
or all of the following attributes can be set:
propertyName
- The property file to load the meg attributes
from.public void setup(java.lang.String name, java.lang.String condition)
Meg
with the given attributes. The
priority defaults to 1 and the Meg
is enabled.name
- The name of the meg.condition
- The condition under which this meg should be
invoked.public void setup(java.lang.String name, java.lang.String condition, int priority)
Meg
with the given attributes and is enabled.name
- The name of the meg.condition
- The condition under which this meg should be
invoked.priority
- The priority of the meg incase of a condition tie.public void setup(java.lang.String name, java.lang.String condition, int priority, boolean enabled)
Meg
with the given attributes.name
- The name of the meg.condition
- The condition under which this meg should be
invoked.priority
- The priority of the meg incase of a condition tie.enabled
- true
if enabled.setCondition(java.lang.String)
public void initialize() throws MegException
Called when the Meg
is initialized. Meg
subclasses should override this method and do any Meg
-
specific initialization that needs to be done. The SystemContext
variable is available through getSystemContext()
.
getSystemContext()
public void initialize(SystemContext systemContext)
initialize()
instead and use
getSystemContext()
initialize()
,
getSystemContext()
public void setSystemContext(SystemContext systemContext)
SystemContext
object for this Meg. This method
should only be called by the object administrating the plugins.systemContext
- Holds "static" information that pertains to
the engine that the Meg is running under.
Implementations are encouraged to not store
this object put instead obtain it from the
getSystemContext()
method.public SystemContext getSystemContext()
SystemContext
object passed in with the
initialize
method.public abstract void handleRequest(RequestEvent event) throws RequestRejectedException, java.io.IOException
Meg
's condition.event
- The request event used to modify the request/response.RequestRejectedException
- Thrown if the request is
rejected. This must be thrown before anything is written
to the event
's output stream otherwise the
meg forfeits it's opportunity.java.io.IOException
- Can be thrown if an exception was
generated by the meg while processing the
MegInput/OutputStreamspublic void forwardRequest(Meg meg, RequestEvent event) throws RequestRejectedException, java.io.IOException
Meg
for
handling. The other Meg
must be of the
same type as the caller, otherwise the results are undefined
(e.g., a RequestEditor
can only forward a request
to another RequestEditor
).meg
- The Meg
to handle the request.event
- The RequestEvent
being forwarded.RequestRejectedException
- Thrown if meg
rejects the request.java.io.IOException
- Thrown if an exception was generated
while meg
was processing the
MegInput/OutputStreamspublic void setName(java.lang.String name)
Meg
used to provide a description.name
- The name of the Meg
.public java.lang.String getName()
Meg
.Meg
.public void setCondition(java.lang.String condition)
Meg
. The condition property is
used to determine whether the meg should be invoked for a transaction.
The condition property is specified according to a grammar for
Monitors, Editors, RequestEditors and Generators
. The basic concept of the meg condition grammar is the use of one
or more key-value pairs. A key-value pair consists of a keyword
(predefined or application-specific) and an argument.
The basic expressions for evaluating an attribute-value pair are: AttributeName = Value and AttributeName ~ Value. The '~' operator is a case-insensitive comparison. The Value can be the special value '%null%' which means that the given AttributeName should not be defined.
The following rules apply for specifying conditions:
Note: The following condition information is specific to the HTTP/1.0 protocol
WBI offers two different kinds of keywords: predefined and application-specific.
content-type
method
protocol
server
host
path
url
port
query
responseCode
user-agent
For example, if you wanted to register a response editor that was triggered when a response was issued from hosts that ended with the letters 'ibm.com' and were of type HTML, the following syntax would be used:
myMeg.setCondition("host~*ibm.com & content-type~*htm*");If you wished to register a generator that fired when the following request was issued:
http://_myPlugin/generator/OneYou would use the following when registering your generator:
myMeg.setCondition("protocol=http & host~_myPlugin & path=/generator/One");
AppKeyword := '$'( [a-zA-Z0-9] | '-' | '_' )*The constraints on arguments to application-specific keywords are the same as for the predefined keywords.
Examples:
A simple application-specific keyword would be:
myMeg.setCondition("$myApp=invokeMyMeg");Application-specific keywords can be combined with any predefined keyword, such as:
myMeg.setCondition("$myApp=invokeMyMeg & host~www.yahoo.com");Note:The rules for combining application-specific keywords with any other keyword (application-specific or predefined) are the same as for combinations of predefined keywords only.
A meg that was setup with application-specific keyword(s) will only be invoked during a transaction if another meg sets these keywords correctly. Application-specific keywords are referred to as extra rule keys within WBI. These extra rule keys can be set during a transaction by any meg that is invoked during the transaction. Extra rule keys are set by calling the
setExtraRuleKey( String key, String value )method of class RequestInfo.
condition
- A string holding the condition under which this meg gets invoked.RequestInfo
,
DocumentInfo
public java.lang.String getCondition()
Meg
.Meg.setCondition(...)
public void setEnabled(boolean enabled)
Meg
.enabled
- true
if enabled.public boolean getEnabled()
Meg
.true
if enabled.public boolean isEnabled()
Meg
is enabled.true
if enabled.public void setPriority(int priority)
Meg
. The allowable range for
a Meg
priority is between 100 and 1 with 100 being the
highest priority and 1 being the lowest. The priority is only
used in dispatching a Meg
if multiple Meg
s
have conditions that match the request. The conflict is resolved by
which Meg
has the highest priority.priority
- The priority of the Meg
(100 to 1).public int getPriority()
Meg
in the range of 100 to 1.Meg
(100 to 1).public final Plugin getPlugin()
Plugin
of the Meg
.null
if none; else the Plugin
.public java.util.Enumeration getMegPropertyKeys()
Meg
property keys
set by this Meg
.public void setMegProperty(java.lang.String key, java.lang.String value)
Meg
property key name.key
- The key name used to reference the object.value
- The property.public java.lang.String getMegProperty(java.lang.String key)
key
- The key name used to reference the object.public java.lang.String getMegProperty(java.lang.String key, java.lang.String defaultValue)
key
- The key name used to reference the object.defaultValue
- The default value for the resource.public abstract int getType()
Meg.UNDEFINED
Meg.REQUEST_EDITOR
Meg.GENERATOR
Meg.MONITOR
public final boolean isMegApplicable(RequestInfo ri)
RequestInfo
object using the built condition tree (does not consider if
it is enabled or not).ri
- The RequestInfo
object.true
if meg satisfies the condition; else
false
.protected void loadMegResources(Section section)
Meg
's properties which is used for
getMegResource
and setMegResource
methods.section
- The DatabaseSection representing the properties
for the meg.protected final void run(java.lang.Object argument) throws java.lang.Exception
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |