pulse - the web application framework Get pulse at SourceForge.net. Fast, secure and Free Open Source software downloads Ohloh project report for pulse-java

org.torweg.pulse.accesscontrol
Class CommandMatcher

java.lang.Object
  extended by org.torweg.pulse.util.entity.AbstractBasicEntity
      extended by org.torweg.pulse.accesscontrol.CommandMatcher
All Implemented Interfaces:
java.io.Serializable

@Entity
public class CommandMatcher
extends AbstractBasicEntity

A CommandMatcher is an entity used to restrict the execution of Commands.

It has an Attribute permission, being the necessary Permission to execute Commands matched by this CommandMatcher. It also has the Attributes locale, bundle, action, sitemapNodeId and parameters, that are used to check if a CommandMatcher matches a Command. Since a Command also has the last five Attributes, it is matched by a CommandMatcher, if each Attribute of the CommandMatcher is either null or equal to its correspondent of the Command. As to the Parameters, a subset is sufficent, too.

Version:
$Revision: 1479 $
Author:
Christian Schatt, Daniel Dietz
See Also:
Serialized Form

Constructor Summary
protected CommandMatcher()
          Deprecated. 
  CommandMatcher(Permission newPermission)
          The Constructor that sets the Permission needed to execute a matching Command.
 
Method Summary
 void addParameter(Parameter param)
          Adds a Parameter to the <CommandMatcher's Parameters.
static CommandMatcher buildMatcher(org.jdom.Element command)
          Builds the CommandMatcher defined in the mapping XML.
 org.jdom.Element deserializeToJDOM()
          Serializes the state of the CommandMatcher as a JDOM Element.
 java.lang.String getAction()
          Returns the action of the CommandMatcher.
 Bundle getBundle()
          Returns the Bundle of the CommandMatcher.
 java.util.Locale getLocale()
          Returns the Locale of the CommandMatcher.
 Parameter getParameter(java.lang.String paramName)
          Returns the Parameter named paramName, if it is associated with the CommandMatcher.
 java.util.List<Parameter> getParameters()
          Returns a shallow copy of the CommandMatcher's Collection of Parameters.
 Permission getPermission()
          Returns the Permission of the CommandMatcher.
 java.lang.Long getSitemapNodeId()
          Returns the CommandMatcher's SitemapNode id.
 boolean matchesCommand(Command command)
          Checks if the Command is matched by the CommandMatcher.
 boolean removeParameter(java.lang.String paramName)
          Removes the Parameter named paramName from the CommandMatcher's Collection of Parameters, if it is part of it.
 void setAction(java.lang.String newAction)
          Sets the action of the CommandMatcher.
 void setBundle(Bundle newBundle)
          Sets the Bundle of the CommandMatcher.
 void setLocale(java.util.Locale newLocale)
          Sets the Locale of the CommandMatcher.
 void setPermission(Permission newPermission)
          Sets the Permission of the CommandMatcher.
 void setSitemapNodeId(java.lang.Long newSitemapNodeId)
          Sets the SitemapNode id of the CommandMatcher.
 net.sf.json.JSONObject toJSON()
          Serializes the state of the CommandMatcher as a JSONObject.
 java.lang.String toString()
          Returns a String representation of the CommandMatcher.
 
Methods inherited from class org.torweg.pulse.util.entity.AbstractBasicEntity
compareTo, equals, getFullQualifiedClassNameJAXB, getId, hashCode
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CommandMatcher

@Deprecated
protected CommandMatcher()
Deprecated. 

used for HibernateTM.


CommandMatcher

public CommandMatcher(Permission newPermission)
The Constructor that sets the Permission needed to execute a matching Command.

Parameters:
newPermission - the Permission needed to execute a matching Command
Method Detail

getLocale

public final java.util.Locale getLocale()
Returns the Locale of the CommandMatcher.

Returns:
the Locale of the CommandMatcher or null

setLocale

public final void setLocale(java.util.Locale newLocale)
Sets the Locale of the CommandMatcher.

Parameters:
newLocale - the new Locale of the CommandMatcher

getBundle

public final Bundle getBundle()
Returns the Bundle of the CommandMatcher.

Returns:
the Bundle of the CommandMatcher or null

setBundle

public final void setBundle(Bundle newBundle)
Sets the Bundle of the CommandMatcher.

Parameters:
newBundle - the new Bundle of the CommandMatcher

getAction

public final java.lang.String getAction()
Returns the action of the CommandMatcher.

Returns:
the action of the CommandMatcher or null

setAction

public final void setAction(java.lang.String newAction)
Sets the action of the CommandMatcher.

Parameters:
newAction - the new action of the CommandMatcher

getSitemapNodeId

public final java.lang.Long getSitemapNodeId()
Returns the CommandMatcher's SitemapNode id.

Returns:
the CommandMatcher's SitemapNode id or null

setSitemapNodeId

public final void setSitemapNodeId(java.lang.Long newSitemapNodeId)
Sets the SitemapNode id of the CommandMatcher.

Parameters:
newSitemapNodeId - the new SitemapNode id of the CommandMatcher

getParameters

public final java.util.List<Parameter> getParameters()
Returns a shallow copy of the CommandMatcher's Collection of Parameters.

Attention: Since the returned List is not a reference to the CommandMatcher's internal Collection, any modifications to its state will get lost. However, modifications to the state of the List's elements will be consistent.

For example: Adding/Deleting a Parameter to/from the List will not have any effect, when the CommandMatcher is saved. On the other hand, modifications to a Parameter in the List will be made persistent, when the Parameter is saved.

Returns:
the Parameters associated with the CommandMatcher

getParameter

public final Parameter getParameter(java.lang.String paramName)
Returns the Parameter named paramName, if it is associated with the CommandMatcher.

Parameters:
paramName - the name of the Parameter to be sought-after
Returns:
the Parameter named paramName or null

addParameter

public final void addParameter(Parameter param)
Adds a Parameter to the <CommandMatcher's Parameters. The Parameter will not be added, if the CommandMatcher already contains a Parameter of the same name. In this case, its values will be added to the existing Parameter.

Parameters:
param - the Parameter to be added

removeParameter

public final boolean removeParameter(java.lang.String paramName)
Removes the Parameter named paramName from the CommandMatcher's Collection of Parameters, if it is part of it.

Parameters:
paramName - the name of the Parameter to be removed
Returns:
true if the CommandMatcher's Collection changed as a result of the call

getPermission

public final Permission getPermission()
Returns the Permission of the CommandMatcher.

Returns:
the Permission of the CommandMatcher

setPermission

public final void setPermission(Permission newPermission)
Sets the Permission of the CommandMatcher.

Parameters:
newPermission - the new Permission of the CommandMatcher

matchesCommand

public final boolean matchesCommand(Command command)
Checks if the Command is matched by the CommandMatcher. If the Attributes bundle, action, locale and sitemapNodeId of the CommandMatcher are either null or equal to their correspondent of the Command, and the Parameters attached to the CommandMatcher are a subset of those attached to the Command, it's a match.

Parameters:
command - the Command to be checked for a match with the CommandMatcher
Returns:
true if the CommandMatcher matches the Command

toString

public final java.lang.String toString()
Returns a String representation of the CommandMatcher.

Overrides:
toString in class java.lang.Object
Returns:
a String representation of the CommandMatcher

deserializeToJDOM

public final org.jdom.Element deserializeToJDOM()
Serializes the state of the CommandMatcher as a JDOM Element.

Returns:
the state of the CommandMatcherher} as a JDOM Element

buildMatcher

public static CommandMatcher buildMatcher(org.jdom.Element command)
Builds the CommandMatcher defined in the mapping XML.

Sample mapping XML snippet:

   <command action="actionname" locale="de_DE">
     <parameter name="param1">
       <value>value1.1</value>
       <value>value1.2</value>
     </parameter>
     <parameter name="param2"/>
     <parameter name="param3">
       <value>value3</value>
     </parameter>
   </command>
 
The above sample is full blown. The following example shows the minimal mapping:
   <command action="actionname"/>
 

Parameters:
command - the command XML
Returns:
the CommandMatcher defined in the mapping XML

toJSON

public final net.sf.json.JSONObject toJSON()
Serializes the state of the CommandMatcher as a JSONObject.

Returns:
the state of the CommandMatcher as a JSONObject