com.endeca.portal.data.functions
Class QueryFunction

java.lang.Object
  extended by com.endeca.portal.data.functions.QueryFunction
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
QueryConfig, QueryFilter

public abstract class QueryFunction
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable

The base class of all QueryFunctions. Wraps functionality for serializing and deserializing, cloning, and comparing. Refer to subclasses for specific types of functions.

Subclassing

For Semantic reasons, you should usually consider subclassing either QueryFilter or QueryConfig, not this class directly. Other than that, simply pay attention to the abstract methods in this class and your toString() implementation.

See Also:
QueryFilter, QueryConfig, Serialized Form

Field Summary
static java.lang.String CLASS_PROPERTY
           
 
Constructor Summary
protected QueryFunction()
           
 
Method Summary
abstract  void applyToDiscoveryServiceQuery(com.endeca.mdex.conversation.Request query)
          Apply this function to a Request.
 QueryFunction clone()
           
 boolean equals(java.lang.Object other)
           
 boolean equals(QueryFunction other)
          Compares two QueryFunction instances by checking class types and using the object's toString() method
abstract  java.util.List<java.lang.reflect.Method> getGetters()
          Return the list of property getters on this function.
static
<T extends QueryFunction>
T
getInstance(java.lang.Class<T> klass, org.json.JSONObject init)
          convenience function to instantiate a new function from a JSON configuration.
static
<T extends QueryFunction>
T
getInstance(org.json.JSONObject init)
           
 java.lang.String getName()
          Retrieve the name.
abstract  java.util.List<java.lang.reflect.Method> getSetters()
          Return the list of property setters on this function.
 int hashCode()
           
 void init(org.json.JSONObject json)
          Initialize this instance from a JSON configuration.
 void setName(java.lang.String name)
          Set the name.
 org.json.JSONObject toJSON()
          Construct a JSON representation of this function.
abstract  java.lang.String toString()
          This class' toString is abstract: all concrete subclasses are expected to provide an implementation. toString is used in comparing QueryFunction instances for equality, so if you implement a QueryFunction subclass it is important that your toString implementation be consistent and deterministic.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

CLASS_PROPERTY

public static java.lang.String CLASS_PROPERTY
Constructor Detail

QueryFunction

protected QueryFunction()
Method Detail

getName

public java.lang.String getName()
Retrieve the name.

Returns:
the name

setName

public void setName(java.lang.String name)
Set the name.

Parameters:
name - the name to set

getInstance

public static <T extends QueryFunction> T getInstance(java.lang.Class<T> klass,
                                                      org.json.JSONObject init)
                                           throws java.lang.ClassNotFoundException,
                                                  java.lang.IllegalAccessException,
                                                  java.lang.InstantiationException,
                                                  org.json.JSONException,
                                                  java.lang.IllegalArgumentException,
                                                  java.lang.reflect.InvocationTargetException
convenience function to instantiate a new function from a JSON configuration.

Type Parameters:
T -
Parameters:
klass - the class of the function to initialize
init - the JSON representation of the function to initialize
Returns:
The new instance
Throws:
java.lang.ClassNotFoundException
java.lang.IllegalAccessException
java.lang.InstantiationException
org.json.JSONException
java.lang.IllegalArgumentException
java.lang.reflect.InvocationTargetException

getInstance

public static <T extends QueryFunction> T getInstance(org.json.JSONObject init)
                                           throws org.json.JSONException,
                                                  java.lang.ClassNotFoundException,
                                                  java.lang.IllegalArgumentException,
                                                  java.lang.IllegalAccessException,
                                                  java.lang.InstantiationException,
                                                  java.lang.reflect.InvocationTargetException
Throws:
org.json.JSONException
java.lang.ClassNotFoundException
java.lang.IllegalArgumentException
java.lang.IllegalAccessException
java.lang.InstantiationException
java.lang.reflect.InvocationTargetException

init

public void init(org.json.JSONObject json)
          throws org.json.JSONException
Initialize this instance from a JSON configuration. This method calls the String setters for each attribute defined in the JSON configuration. If there is no String setter, the attribute is skipped.

Parameters:
json - the JSON configuration
Throws:
java.lang.IllegalArgumentException
java.lang.IllegalAccessException
org.json.JSONException
See Also:
toJSON()

applyToDiscoveryServiceQuery

public abstract void applyToDiscoveryServiceQuery(com.endeca.mdex.conversation.Request query)
                                           throws QueryFunctionUnsupportedException
Apply this function to a Request. Must be implemented by subclass.

Parameters:
query -
Throws:
QueryFunctionUnsupportedException

getGetters

public abstract java.util.List<java.lang.reflect.Method> getGetters()
Return the list of property getters on this function. Must be implemented by subclass. Required for correct JSON serialization/deserialization support. For most subclasses, implementing this method should be simple, as long as your getter methods follow standard Java naming conventions (e.g. "getPropertyName()"). All you should need to write is:
 private static List getters = Reflection.getGetters(MyFunctionClass.class);
 \@Override
 public List getGetters() {
        return getters;
 }
 

Returns:
the list of getters

getSetters

public abstract java.util.List<java.lang.reflect.Method> getSetters()
Return the list of property setters on this function. Must be implemented by subclass. Required for correct JSON serialization/deserialization support. For most subclasses, implementing this method should be simple, as long as your setter methods follow standard Java naming conventions (e.g. "setPropertyName(PropertyType)"). All you should need to write is:
 private static List setters = Reflection.getSetters(MyFunctionClass.class);
 \@Override
 public List getSetters() {
        return setters;
 }
 

Returns:
the list of setters

toJSON

public org.json.JSONObject toJSON()
Construct a JSON representation of this function.

Returns:
The JSON represenation
See Also:
init(JSONObject)

toString

public abstract java.lang.String toString()
This class' toString is abstract: all concrete subclasses are expected to provide an implementation. toString is used in comparing QueryFunction instances for equality, so if you implement a QueryFunction subclass it is important that your toString implementation be consistent and deterministic.

Overrides:
toString in class java.lang.Object

clone

public QueryFunction clone()
Overrides:
clone in class java.lang.Object

equals

public boolean equals(java.lang.Object other)
Overrides:
equals in class java.lang.Object

equals

public boolean equals(QueryFunction other)
Compares two QueryFunction instances by checking class types and using the object's toString() method

Parameters:
other -
Returns:

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object