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
;
28 /** To be overridden */
29 public class DefaultJcrListener
implements EventListener
{
30 private final static Log log
= LogFactory
.getLog(DefaultJcrListener
.class);
31 private Session session
;
32 private String path
= "/";
33 private Boolean deep
= true;
37 addEventListener(session().getWorkspace().getObservationManager());
38 if (log
.isDebugEnabled())
39 log
.debug("Registered JCR event listener on " + path
);
40 } catch (Exception e
) {
41 throw new ArgeoJcrException("Cannot register event listener", e
);
47 session().getWorkspace().getObservationManager()
48 .removeEventListener(this);
49 if (log
.isDebugEnabled())
50 log
.debug("Unregistered JCR event listener on " + path
);
51 } catch (Exception e
) {
52 throw new ArgeoJcrException("Cannot unregister event listener", e
);
56 /** Default is listen to all events */
57 protected Integer
getEvents() {
58 return Event
.NODE_ADDED
| Event
.NODE_REMOVED
| Event
.PROPERTY_ADDED
59 | Event
.PROPERTY_CHANGED
| Event
.PROPERTY_REMOVED
;
62 /** To be overidden */
63 public void onEvent(EventIterator events
) {
64 while (events
.hasNext()) {
65 Event event
= events
.nextEvent();
70 /** To be overidden */
71 protected void addEventListener(ObservationManager observationManager
)
72 throws RepositoryException
{
73 observationManager
.addEventListener(this, getEvents(), path
, deep
,
77 private Session
session() {
81 public void setPath(String path
) {
85 public void setDeep(Boolean deep
) {
89 public void setSession(Session session
) {
90 this.session
= session
;