org.rhq.plugins.jmx
Class ObjectNameQueryUtility

java.lang.Object
  extended by org.rhq.plugins.jmx.ObjectNameQueryUtility

public class ObjectNameQueryUtility
extends Object

A utility class to help in querying object names and utilizing parts of the object name for setting configuration values and changing string messages. A template that you'd build this utility with could look like "foo:name=%myName%,type=myType". This will be "translated" into a valid JMX objectName Query of the form "foo:type=myType,*". It will also detect that we've got a variable defined as "myName" that we'd like to later match to.

We can then find beans with the query and apply their objectName properties to the object and use those found values to rewrite strings or setup configuration properities. For example, we've got a detected object name for the above template "foo:name=bar,type=myType". We set its detected keys against this utility and we now have a variable defined as the key "myName" and the value of "bar". Then I can call formatMessage with "A foo called {myName}" which will be translated into "A foo called bar". This can be useful for naming resources and descriptions using parts of a mapped ObjectName.

Author:
Greg Hinkle

Constructor Summary
ObjectNameQueryUtility(String objectNameQueryTemplate)
          Builds a mapped query utility object and finds the variables in the supplied object name query template.
ObjectNameQueryUtility(String objectNameQueryTemplate, Configuration parentConfiguration)
          Builds a mapped query utility object and finds the variables in the supplied object name query template.
 
Method Summary
 String formatMessage(String message)
          Format a message with {} formatted replacement keys.
 String getQueryTemplate()
           
 String getTranslatedQuery()
           
 Map<String,String> getVariableProperties()
           
 Map<String,String> getVariableValues()
           
 boolean isContainsExtraKeyProperties(Set<String> strings)
           
 void resetVariables()
          Clears out variables so that a new found bean can be used against the same utility object again.
 boolean setMatchedKeyValues(Map<String,String> keyProperties)
          Set values for properties from an objectName.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectNameQueryUtility

public ObjectNameQueryUtility(String objectNameQueryTemplate)
Builds a mapped query utility object and finds the variables in the supplied object name query template.

Parameters:
objectNameQueryTemplate - string of form "a:b=%c%,d=e,f=%g%"

ObjectNameQueryUtility

public ObjectNameQueryUtility(String objectNameQueryTemplate,
                              Configuration parentConfiguration)
Builds a mapped query utility object and finds the variables in the supplied object name query template. This version first translates the objectName template for defined values in provided configuration. This is explicitly built for hierarchical objectName models to find the children of parents.

Parameters:
objectNameQueryTemplate - string of form "a:b=%c%,d=e,f=%g%,h={myParentsH}"
parentConfiguration - the config holding the matched values for the object name key property variables
Method Detail

setMatchedKeyValues

public boolean setMatchedKeyValues(Map<String,String> keyProperties)
Set values for properties from an objectName. These are first translated into the "real" keys. e.g. foo:bar=%baz% In this case, the property of the bar objectName property will be set into the properties keyed against "baz" which is the real key.

Parameters:
keyProperties - properties from the found objectName to apply
Returns:
true if the objectName properties contained all variable properties or false if some where missing (e.g. foo:A=%a%,B=%b% is the queryTemplate but objectName found is foo:A=alpha)

formatMessage

public String formatMessage(String message)
Format a message with {} formatted replacement keys.

Parameters:
message - the message to format
Returns:
the formatted text with variables replaced

resetVariables

public void resetVariables()
Clears out variables so that a new found bean can be used against the same utility object again.


getQueryTemplate

public String getQueryTemplate()

getVariableProperties

public Map<String,String> getVariableProperties()

getVariableValues

public Map<String,String> getVariableValues()

getTranslatedQuery

public String getTranslatedQuery()

isContainsExtraKeyProperties

public boolean isContainsExtraKeyProperties(Set<String> strings)


Copyright © 2008-2011 Red Hat, Inc.. All Rights Reserved.