2 * Copyright (C) 2007-2012 Argeo GmbH
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.jcr
;
18 import javax
.jcr
.RepositoryException
;
19 import javax
.jcr
.Session
;
20 import javax
.jcr
.observation
.Event
;
21 import javax
.jcr
.observation
.EventIterator
;
22 import javax
.jcr
.observation
.EventListener
;
23 import javax
.jcr
.observation
.ObservationManager
;
25 import org
.apache
.commons
.logging
.Log
;
26 import org
.apache
.commons
.logging
.LogFactory
;
27 import org
.argeo
.ArgeoException
;
29 /** To be overridden */
30 public class DefaultJcrListener
implements EventListener
{
31 private final static Log log
= LogFactory
.getLog(DefaultJcrListener
.class);
32 private Session session
;
33 private String path
= "/";
34 private Boolean deep
= true;
38 addEventListener(session().getWorkspace().getObservationManager());
39 if (log
.isDebugEnabled())
40 log
.debug("Registered JCR event listener on " + path
);
41 } catch (Exception e
) {
42 throw new ArgeoException("Cannot register event listener", e
);
48 session().getWorkspace().getObservationManager()
49 .removeEventListener(this);
50 if (log
.isDebugEnabled())
51 log
.debug("Unregistered JCR event listener on " + path
);
52 } catch (Exception e
) {
53 throw new ArgeoException("Cannot unregister event listener", e
);
57 /** Default is listen to all events */
58 protected Integer
getEvents() {
59 return Event
.NODE_ADDED
| Event
.NODE_REMOVED
| Event
.PROPERTY_ADDED
60 | Event
.PROPERTY_CHANGED
| Event
.PROPERTY_REMOVED
;
63 /** To be overidden */
64 public void onEvent(EventIterator events
) {
65 while (events
.hasNext()) {
66 Event event
= events
.nextEvent();
71 /** To be overidden */
72 protected void addEventListener(ObservationManager observationManager
)
73 throws RepositoryException
{
74 observationManager
.addEventListener(this, getEvents(), path
, deep
,
78 private Session
session() {
82 public void setPath(String path
) {
86 public void setDeep(Boolean deep
) {
90 public void setSession(Session session
) {
91 this.session
= session
;