org.apache.jackrabbit.api.observation.JackrabbitEventFilter Maven / Gradle / Ivy
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.jackrabbit.api.observation;
import static java.util.Arrays.copyOf;
/**
* A storage object for event filter configuration.
*
* The parameters of the filter can then be set by chaining the set methods,
* since each method returns the same EventFilter
with the indicated parameter set.
*
* Once the filter is configured, it and an {@link javax.jcr.observation.EventListener} object are
* passed to
* {@link org.apache.jackrabbit.api.observation.JackrabbitObservationManager#addEventListener(javax.jcr.observation.EventListener, JackrabbitEventFilter)}.
*
* The filter restricts which events are sent to the EventListener
according to the
* following parameters. Note that the term associated parent node of an event means the
* parent node of the item at (or formerly at) the path returned by
* {@link javax.jcr.observation.Event#getPath}.
*
* -
*
eventTypes
:
* A bitwise OR
of the event types to be listened to. See
* {@link javax.jcr.observation.Event} for details.
*
* -
*
absPath
, absPaths
, excludedPaths
,
* isDeep
: Only events whose associated parent node is at one
* of the paths in absPath
or absPaths
(or within
* its subgraph, if isDeep
is true
) will be received
* except if the associated parent node is at one of the paths in
* excludedPaths
or its subgraph.
* It is permissible to register a listener for a path where no node currently
* exists.
*
* -
*
uuid
:
* Only events whose associated parent node has one of
* the identifiers in this list will be received. If his parameter is
* null
then no identifier-related restriction is placed on
* events received. Note that specifying an empty array instead of
* null
would result in no nodes being listened to. The term
* "UUID" is used for compatibility with JCR 1.0.
*
* -
*
nodeTypeName
:
* Only events whose associated parent node has
* one of the node types (or a subtype of one of the node types) in this
* list will be received. If his parameter is null
then no node
* type-related restriction is placed on events received. Note that
* specifying an empty array instead of null
would result in no
* nodes types being listened to.
*
* -
*
noLocal
: if true
, then events
* generated by the session through which the listener was registered are
* ignored. Otherwise, they are not ignored.
*
* -
*
noExternal
: if true
, then events
* from external cluster nodes are ignored. Otherwise, they are not ignored.
*
* -
*
noInternal
: if true
, then events
* from this cluster node are ignored. Otherwise, they are not ignored.
*
*
* The restrictions are "ANDed" together. In other words, for a particular node to be "listened to" it
* must meet all the restrictions.
*
*/
public class JackrabbitEventFilter { // TODO extends EventFilter once JCR 2.1 is out
private int eventTypes;
private String absPath;
private boolean isDeep;
private String[] identifiers;
private String[] nodeTypeNames;
private boolean noLocal;
private String[] absPaths = new String[]{};
private String[] excludedPaths = new String[]{};
private boolean noExternal;
private boolean noInternal;
/**
* Sets the eventTypes
parameter of the filter.
* If left unset, this parameter defaults to 0
.
*
* @param eventTypes an int
.
* @return This EventFilter object with the eventTypes
parameter set.
*/
public JackrabbitEventFilter setEventTypes(int eventTypes) {
this.eventTypes = eventTypes;
return this;
}
/**
* Returns the eventTypes
parameter of the filter.
*
* @return an int
.
*/
public int getEventTypes() {
return eventTypes;
}
/**
* Sets the absPath
parameter of the filter.
* If left unset, this parameter defaults to null
.
*
* @param absPath an absolute path String
.
* @return This EventFilter object with the absPath
parameter set.
*/
public JackrabbitEventFilter setAbsPath(String absPath) {
this.absPath = absPath;
return this;
}
/**
* Returns the absPath
parameter of the filter.
*
* @return a String
.
*/
public String getAbsPath() {
return absPath;
}
/**
* Sets the isDeep
parameter of the filter.
* If left unset, this parameter defaults to false
.
*
* @param isDeep a boolean
.
* @return This EventFilter object with the isDeep
parameter set.
*/
public JackrabbitEventFilter setIsDeep(boolean isDeep) {
this.isDeep = isDeep;
return this;
}
/**
* Returns the isDeep
parameter of the filter.
*
* @return a boolean
.
*/
public boolean getIsDeep() {
return isDeep;
}
/**
* Sets the identifiers
parameter of the filter.
* If left unset, this parameter defaults to null
.
*
* @param identifiers a String
array.
* @return This EventFilter object with the identifiers
parameter set.
*/
public JackrabbitEventFilter setIdentifiers(String[] identifiers) {
this.identifiers = copyOf(identifiers, identifiers.length);
return null;
}
/**
* Returns the uuids
parameter of the filter.
*
* @return a String
array.
*/
public String[] getIdentifiers() {
return identifiers == null ? null : copyOf(identifiers, identifiers.length);
}
/**
* Sets the nodeTypeNames
parameter of the filter.
* If left unset, this parameter defaults to null
.
*
* @param nodeTypeNames a String
array.
* @return This EventFilter object with the nodeTypes
parameter set.
*/
public JackrabbitEventFilter setNodeTypes(String[] nodeTypeNames) {
this.nodeTypeNames = copyOf(nodeTypeNames, nodeTypeNames.length);
return this;
}
/**
* Returns the nodeTypeName
parameter of the filter.
*
* @return a String
array.
*/
public String[] getNodeTypes() {
return nodeTypeNames == null ? null : copyOf(nodeTypeNames, nodeTypeNames.length);
}
/**
* Sets the noLocal
parameter of the filter.
* If left unset, this parameter defaults to false
.
*
* @param noLocal a boolean
.
* @return This EventFilter object with the noLocal
parameter set.
*/
public JackrabbitEventFilter setNoLocal(boolean noLocal) {
this.noLocal = noLocal;
return this;
}
/**
* Returns the noLocal
parameter of the filter.
*
* @return a boolean
.
*/
public boolean getNoLocal() {
return noLocal;
}
/**
* Sets the absPaths
parameter of the filter.
* If left unset, this parameter defaults to an empty array.
*
* @param absPaths an absolute path String
array.
* @return This EventFilter object with the absPaths
parameter set.
*/
public JackrabbitEventFilter setAdditionalPaths(String... absPaths) {
this.absPaths = copyOf(absPaths, absPaths.length);
return this;
}
/**
* Returns the absPaths
parameter of the filter.
*
* @return a String
array.
*/
public String[] getAdditionalPaths() {
return copyOf(absPaths, absPaths.length);
}
/**
* Sets the excludedPaths
parameter of the filter.
* If left unset, this parameter defaults to an empty array.
*
* @param excludedPaths an absolute path String
array.
* @return This EventFilter object with the excludedPaths
parameter set.
*/
public JackrabbitEventFilter setExcludedPaths(String... excludedPaths) {
this.excludedPaths = copyOf(excludedPaths, excludedPaths.length);
return this;
}
/**
* Returns the excludedPaths
parameter of the filter.
*
* @return a String
array.
*/
public String[] getExcludedPaths() {
return copyOf(excludedPaths, excludedPaths.length);
}
/**
* Sets the noExternal
parameter of the filter.
* If left unset, this parameter defaults to false
.
*
* @param noExternal a boolean
.
* @return This EventFilter object with the noExternal
parameter set.
*/
public JackrabbitEventFilter setNoExternal(boolean noExternal) {
this.noExternal = noExternal;
return this;
}
/**
* Returns the noExternal
parameter of the filter.
*
* @return a boolean
.
*/
public boolean getNoExternal() {
return noExternal;
}
/**
* Sets the noInternal
parameter of the filter.
* If left unset, this parameter defaults to false
.
*
* @param noInternal a boolean
.
* @return This EventFilter object with the noExternal
parameter set.
*/
public JackrabbitEventFilter setNoInternal(boolean noInternal) {
this.noInternal = noInternal;
return this;
}
/**
* Returns the noInternal
parameter of the filter.
*
* @return a boolean
.
*/
public boolean getNoInternal() {
return noInternal;
}
}