2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
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.
17 package org
.argeo
.jcr
;
19 import javax
.jcr
.RepositoryException
;
20 import javax
.jcr
.Session
;
21 import javax
.jcr
.observation
.Event
;
22 import javax
.jcr
.observation
.EventIterator
;
23 import javax
.jcr
.observation
.EventListener
;
24 import javax
.jcr
.observation
.ObservationManager
;
26 import org
.apache
.commons
.logging
.Log
;
27 import org
.apache
.commons
.logging
.LogFactory
;
28 import org
.argeo
.ArgeoException
;
30 /** To be overridden */
31 public class DefaultJcrListener
implements EventListener
{
32 private final static Log log
= LogFactory
.getLog(DefaultJcrListener
.class);
33 private Session session
;
34 private String path
= "/";
35 private Boolean deep
= true;
39 addEventListener(session().getWorkspace().getObservationManager());
40 if (log
.isDebugEnabled())
41 log
.debug("Registered JCR event listener on " + path
);
42 } catch (Exception e
) {
43 throw new ArgeoException("Cannot register event listener", e
);
49 session().getWorkspace().getObservationManager()
50 .removeEventListener(this);
51 if (log
.isDebugEnabled())
52 log
.debug("Unregistered JCR event listener on " + path
);
53 } catch (Exception e
) {
54 throw new ArgeoException("Cannot unregister event listener", e
);
58 /** Default is listen to all events */
59 protected Integer
getEvents() {
60 return Event
.NODE_ADDED
| Event
.NODE_REMOVED
| Event
.PROPERTY_ADDED
61 | Event
.PROPERTY_CHANGED
| Event
.PROPERTY_REMOVED
;
64 /** To be overidden */
65 public void onEvent(EventIterator events
) {
66 while (events
.hasNext()) {
67 Event event
= events
.nextEvent();
72 /** To be overidden */
73 protected void addEventListener(ObservationManager observationManager
)
74 throws RepositoryException
{
75 observationManager
.addEventListener(this, getEvents(), path
, deep
,
79 private Session
session() {
83 public void setPath(String path
) {
87 public void setDeep(Boolean deep
) {
91 public void setSession(Session session
) {
92 this.session
= session
;