You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2006/07/27 00:42:37 UTC
svn commit: r425889 - in /lenya/trunk/src:
impl/java/org/apache/lenya/cms/observation/
impl/java/org/apache/lenya/cms/publication/
java/org/apache/lenya/cms/observation/ java/org/apache/lenya/cms/publication/
java/org/apache/lenya/cms/repository/ modul...
Author: andreas
Date: Wed Jul 26 15:42:35 2006
New Revision: 425889
URL: http://svn.apache.org/viewvc?rev=425889&view=rev
Log:
Added initial version of observation implementation
Added:
lenya/trunk/src/impl/java/org/apache/lenya/cms/observation/
lenya/trunk/src/impl/java/org/apache/lenya/cms/observation/ObservationManager.java
lenya/trunk/src/java/org/apache/lenya/cms/observation/
lenya/trunk/src/java/org/apache/lenya/cms/observation/ObservationException.java
lenya/trunk/src/java/org/apache/lenya/cms/observation/ObservationRegistry.java
lenya/trunk/src/java/org/apache/lenya/cms/observation/RepositoryEvent.java
lenya/trunk/src/java/org/apache/lenya/cms/observation/RepositoryListener.java
lenya/trunk/src/java/org/apache/lenya/cms/repository/NodeListener.java
lenya/trunk/src/modules-core/observation-impl/
lenya/trunk/src/modules-core/observation-impl/config/
lenya/trunk/src/modules-core/observation-impl/config/cocoon-xconf/
lenya/trunk/src/modules-core/observation-impl/config/cocoon-xconf/observation-registry.xconf
lenya/trunk/src/modules-core/observation-impl/java/
lenya/trunk/src/modules-core/observation-impl/java/src/
lenya/trunk/src/modules-core/observation-impl/java/test/
lenya/trunk/src/modules-core/observation-impl/java/test/org/
lenya/trunk/src/modules-core/observation-impl/java/test/org/apache/
lenya/trunk/src/modules-core/observation-impl/java/test/org/apache/lenya/
lenya/trunk/src/modules-core/observation-impl/java/test/org/apache/lenya/cms/
lenya/trunk/src/modules-core/observation-impl/java/test/org/apache/lenya/cms/observation/
lenya/trunk/src/modules-core/observation-impl/java/test/org/apache/lenya/cms/observation/ObservationTest.java
lenya/trunk/src/modules-core/observation-impl/java/test/org/apache/lenya/cms/observation/TestListener.java
lenya/trunk/src/modules-core/observation-impl/module.xml
Modified:
lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/DocumentImpl.java
lenya/trunk/src/java/org/apache/lenya/cms/publication/Document.java
lenya/trunk/src/java/org/apache/lenya/cms/repository/Node.java
lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/RepoNode.java
lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNode.java
lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeFactory.java
Added: lenya/trunk/src/impl/java/org/apache/lenya/cms/observation/ObservationManager.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/impl/java/org/apache/lenya/cms/observation/ObservationManager.java?rev=425889&view=auto
==============================================================================
--- lenya/trunk/src/impl/java/org/apache/lenya/cms/observation/ObservationManager.java (added)
+++ lenya/trunk/src/impl/java/org/apache/lenya/cms/observation/ObservationManager.java Wed Jul 26 15:42:35 2006
@@ -0,0 +1,109 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation
+ *
+ * Licensed 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.lenya.cms.observation;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.lenya.cms.publication.Document;
+import org.apache.lenya.cms.repository.Node;
+import org.apache.lenya.cms.repository.NodeListener;
+
+/**
+ * Observation manager. Works as an observation registry and sends the notifications.
+ */
+public class ObservationManager extends AbstractLogEnabled implements ObservationRegistry,
+ ThreadSafe {
+
+ private Map identifier2listeners = new HashMap();
+ private Map identifier2doc = new HashMap();
+ private Set listeners = new HashSet();
+
+ public synchronized void registerListener(RepositoryListener listener, Document doc)
+ throws ObservationException {
+ Set listeners = getListeners(doc);
+ if (listeners.contains(listener)) {
+ throw new ObservationException("The listener [" + listener
+ + "] is already registered for the document [" + doc + "].");
+ }
+ listeners.add(listener);
+ }
+
+ protected Set getListeners(Document doc) {
+ Set listeners = (Set) this.identifier2listeners.get(doc.getIdentifier());
+ if (listeners == null) {
+ listeners = new HashSet();
+ this.identifier2listeners.put(doc.getIdentifier(), listeners);
+ this.identifier2doc.put(doc.getIdentifier(), doc);
+ }
+ return listeners;
+ }
+
+ public synchronized void registerListener(RepositoryListener listener)
+ throws ObservationException {
+ if (this.listeners.contains(listener)) {
+ throw new ObservationException("The listener [" + listener + "] is already registered.");
+ }
+ this.listeners.add(listener);
+ }
+
+ public void documentChanged(Document doc) {
+ RepositoryEvent event = new RepositoryEvent(doc);
+ Set allListeners = new HashSet();
+ synchronized (this) {
+ allListeners.addAll(this.listeners);
+ allListeners.addAll(getListeners(doc));
+ }
+ Notifier notifier = new Notifier(allListeners, event);
+ new Thread(notifier).run();
+ }
+
+ public class Notifier implements Runnable {
+
+ private Set listeners;
+ private RepositoryEvent event;
+
+ public Notifier(Set listeners, RepositoryEvent event) {
+ this.listeners = listeners;
+ this.event = event;
+ }
+
+ public void run() {
+ for (Iterator i = listeners.iterator(); i.hasNext();) {
+ RepositoryListener listener = (RepositoryListener) i.next();
+ listener.documentChanged(event);
+ }
+ }
+ }
+
+ public void nodeChanged(Node node) {
+ for (Iterator i = this.identifier2doc.values().iterator(); i.hasNext();) {
+ Document doc = (Document) i.next();
+ String docUri = doc.getRepositoryNode().getSourceURI();
+ if (docUri.equals(node.getSourceURI())) {
+ documentChanged(doc);
+ }
+ }
+
+ }
+
+}
Modified: lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/DocumentImpl.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/DocumentImpl.java?rev=425889&r1=425888&r2=425889&view=diff
==============================================================================
--- lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/DocumentImpl.java (original)
+++ lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/DocumentImpl.java Wed Jul 26 15:42:35 2006
@@ -409,7 +409,7 @@
}
- protected DocumentIdentifier getIdentifier() {
+ public DocumentIdentifier getIdentifier() {
return this.identifier;
}
@@ -597,4 +597,5 @@
throw new DocumentException(e);
}
}
-}
+
+}
\ No newline at end of file
Added: lenya/trunk/src/java/org/apache/lenya/cms/observation/ObservationException.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/observation/ObservationException.java?rev=425889&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/observation/ObservationException.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/observation/ObservationException.java Wed Jul 26 15:42:35 2006
@@ -0,0 +1,50 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation
+ *
+ * Licensed 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.lenya.cms.observation;
+
+public class ObservationException extends Exception {
+
+ /**
+ *
+ */
+ public ObservationException() {
+ super();
+ }
+
+ /**
+ * @param arg0
+ * @param arg1
+ */
+ public ObservationException(String arg0, Throwable arg1) {
+ super(arg0, arg1);
+ }
+
+ /**
+ * @param arg0
+ */
+ public ObservationException(String arg0) {
+ super(arg0);
+ }
+
+ /**
+ * @param arg0
+ */
+ public ObservationException(Throwable arg0) {
+ super(arg0);
+ }
+
+}
Added: lenya/trunk/src/java/org/apache/lenya/cms/observation/ObservationRegistry.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/observation/ObservationRegistry.java?rev=425889&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/observation/ObservationRegistry.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/observation/ObservationRegistry.java Wed Jul 26 15:42:35 2006
@@ -0,0 +1,40 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation
+ *
+ * Licensed 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.lenya.cms.observation;
+
+import org.apache.lenya.cms.publication.Document;
+import org.apache.lenya.cms.repository.NodeListener;
+
+public interface ObservationRegistry extends NodeListener {
+
+ String ROLE = ObservationRegistry.class.getName();
+
+ /**
+ * @param listener The listener.
+ * @param document The document to listen to.
+ * @throws ObservationException if the listener is already registered for this document.
+ */
+ void registerListener(RepositoryListener listener, Document document) throws ObservationException;
+
+ /**
+ * Registers a listener which is notified for all events.
+ * @param listener The listener.
+ * @throws ObservationException if the listener is already registered.
+ */
+ void registerListener(RepositoryListener listener) throws ObservationException;
+
+}
Added: lenya/trunk/src/java/org/apache/lenya/cms/observation/RepositoryEvent.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/observation/RepositoryEvent.java?rev=425889&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/observation/RepositoryEvent.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/observation/RepositoryEvent.java Wed Jul 26 15:42:35 2006
@@ -0,0 +1,36 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation
+ *
+ * Licensed 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.lenya.cms.observation;
+
+import org.apache.lenya.cms.publication.Document;
+
+/**
+ * Repository event.
+ */
+public class RepositoryEvent {
+
+ private Document document;
+
+ public RepositoryEvent(Document document) {
+ this.document = document;
+ }
+
+ public Document getDocument() {
+ return this.document;
+ }
+
+}
Added: lenya/trunk/src/java/org/apache/lenya/cms/observation/RepositoryListener.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/observation/RepositoryListener.java?rev=425889&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/observation/RepositoryListener.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/observation/RepositoryListener.java Wed Jul 26 15:42:35 2006
@@ -0,0 +1,30 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation
+ *
+ * Licensed 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.lenya.cms.observation;
+
+/**
+ * Listener to repository events.
+ */
+public interface RepositoryListener {
+
+ /**
+ * Called when a node was changed.
+ * @param event The event.
+ */
+ void documentChanged(RepositoryEvent event);
+
+}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/Document.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/publication/Document.java?rev=425889&r1=425888&r2=425889&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/Document.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/Document.java Wed Jul 26 15:42:35 2006
@@ -238,4 +238,9 @@
* @throws DocumentException if an error occurs.
*/
long getContentLength() throws DocumentException;
+
+ /**
+ * @return The document identifier for this document.
+ */
+ DocumentIdentifier getIdentifier();
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/repository/Node.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/repository/Node.java?rev=425889&r1=425888&r2=425889&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/repository/Node.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/repository/Node.java Wed Jul 26 15:42:35 2006
@@ -20,7 +20,6 @@
import java.io.OutputStream;
import java.util.Collection;
-import org.apache.lenya.cms.metadata.MetaData;
import org.apache.lenya.cms.metadata.MetaDataOwner;
/**
@@ -153,4 +152,16 @@
*/
void registerRemoved() throws RepositoryException;
+ /**
+ * @param listener The listener to add.
+ * @throws RepositoryException if the listener is already registered.
+ */
+ void addListener(NodeListener listener) throws RepositoryException;
+
+ /**
+ * Checks if a listener is registered.
+ * @param listener The listener.
+ * @return A boolean value.
+ */
+ boolean isListenerRegistered(NodeListener listener);
}
Added: lenya/trunk/src/java/org/apache/lenya/cms/repository/NodeListener.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/repository/NodeListener.java?rev=425889&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/repository/NodeListener.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/repository/NodeListener.java Wed Jul 26 15:42:35 2006
@@ -0,0 +1,30 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation
+ *
+ * Licensed 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.lenya.cms.repository;
+
+
+/**
+ * Listener for nodes.
+ */
+public interface NodeListener {
+
+ /**
+ * @param node The node which has changed.
+ */
+ void nodeChanged(Node node);
+
+}
Added: lenya/trunk/src/modules-core/observation-impl/config/cocoon-xconf/observation-registry.xconf
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/observation-impl/config/cocoon-xconf/observation-registry.xconf?rev=425889&view=auto
==============================================================================
--- lenya/trunk/src/modules-core/observation-impl/config/cocoon-xconf/observation-registry.xconf (added)
+++ lenya/trunk/src/modules-core/observation-impl/config/cocoon-xconf/observation-registry.xconf Wed Jul 26 15:42:35 2006
@@ -0,0 +1,24 @@
+<?xml version="1.0"?>
+<!--
+ Copyright 1999-2005 The Apache Software Foundation
+
+ Licensed 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.
+-->
+
+<!-- $Id: usecases-workflow-deactivate.xconf 348547 2005-11-23 20:13:01Z chestnut $ -->
+
+ <xconf xpath="/cocoon" unless="/cocoon/component[@role = 'org.apache.lenya.cms.observation.ObservationRegistry']">
+ <component logger="lenya.observation.registry"
+ class="org.apache.lenya.cms.observation.ObservationManager"
+ role="org.apache.lenya.cms.observation.ObservationRegistry"/>
+ </xconf>
Added: lenya/trunk/src/modules-core/observation-impl/java/test/org/apache/lenya/cms/observation/ObservationTest.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/observation-impl/java/test/org/apache/lenya/cms/observation/ObservationTest.java?rev=425889&view=auto
==============================================================================
--- lenya/trunk/src/modules-core/observation-impl/java/test/org/apache/lenya/cms/observation/ObservationTest.java (added)
+++ lenya/trunk/src/modules-core/observation-impl/java/test/org/apache/lenya/cms/observation/ObservationTest.java Wed Jul 26 15:42:35 2006
@@ -0,0 +1,81 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation
+ *
+ * Licensed 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.lenya.cms.observation;
+
+import org.apache.lenya.ac.impl.AbstractAccessControlTest;
+import org.apache.lenya.cms.cocoon.source.SourceUtil;
+import org.apache.lenya.cms.publication.Document;
+import org.apache.lenya.cms.publication.DocumentFactory;
+import org.apache.lenya.cms.publication.DocumentUtil;
+import org.apache.lenya.cms.publication.Publication;
+import org.apache.lenya.cms.publication.PublicationUtil;
+import org.apache.lenya.cms.repository.RepositoryUtil;
+import org.apache.lenya.cms.repository.Session;
+import org.apache.lenya.xml.NamespaceHelper;
+
+public class ObservationTest extends AbstractAccessControlTest {
+
+ public void testObservation() throws Exception {
+ login("lenya");
+ Session session = RepositoryUtil.getSession(getManager(), getRequest());
+ DocumentFactory factory = DocumentUtil.createDocumentIdentityMap(getManager(), session);
+
+ Publication publication = PublicationUtil.getPublication(getManager(), "test");
+ Document doc = factory.get(publication, Publication.AUTHORING_AREA, "/index", "en");
+
+ TestListener docListener = new TestListener();
+ TestListener allListener = new TestListener();
+
+ ObservationRegistry registry = null;
+ try {
+ registry = (ObservationRegistry) getManager().lookup(ObservationRegistry.ROLE);
+ registry.registerListener(docListener, doc);
+
+ Exception e = null;
+ try {
+ registry.registerListener(docListener, doc);
+ }
+ catch (ObservationException e1) {
+ e = e1;
+ }
+ assertNotNull(e);
+
+ registry.registerListener(allListener);
+ }
+ finally {
+ if (registry != null) {
+ getManager().release(registry);
+ }
+ }
+
+ NamespaceHelper xml = new NamespaceHelper("http://apache.org/lenya/test", "", "test");
+ doc.getRepositoryNode().lock();
+ SourceUtil.writeDOM(xml.getDocument(), doc.getSourceURI(), getManager());
+
+ assertFalse(docListener.wasNotified());
+ assertFalse(allListener.wasNotified());
+
+ doc.getRepositoryNode().getSession().commit();
+
+ Thread.currentThread().sleep(100);
+
+ assertTrue(docListener.wasNotified());
+ assertTrue(allListener.wasNotified());
+
+ }
+
+}
Added: lenya/trunk/src/modules-core/observation-impl/java/test/org/apache/lenya/cms/observation/TestListener.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/observation-impl/java/test/org/apache/lenya/cms/observation/TestListener.java?rev=425889&view=auto
==============================================================================
--- lenya/trunk/src/modules-core/observation-impl/java/test/org/apache/lenya/cms/observation/TestListener.java (added)
+++ lenya/trunk/src/modules-core/observation-impl/java/test/org/apache/lenya/cms/observation/TestListener.java Wed Jul 26 15:42:35 2006
@@ -0,0 +1,18 @@
+/**
+ *
+ */
+package org.apache.lenya.cms.observation;
+
+public class TestListener implements RepositoryListener {
+
+ private boolean notified = false;
+
+ public void documentChanged(RepositoryEvent event) {
+ this.notified = true;
+ }
+
+ public boolean wasNotified() {
+ return this.notified;
+ }
+
+}
\ No newline at end of file
Added: lenya/trunk/src/modules-core/observation-impl/module.xml
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/observation-impl/module.xml?rev=425889&view=auto
==============================================================================
--- lenya/trunk/src/modules-core/observation-impl/module.xml (added)
+++ lenya/trunk/src/modules-core/observation-impl/module.xml Wed Jul 26 15:42:35 2006
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 1999-2005 The Apache Software Foundation
+
+ Licensed 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.
+-->
+
+<!-- $Id: publication.xml 374687 2006-02-03 15:24:55Z michi $ -->
+
+<module xmlns="http://apache.org/lenya/module/1.0">
+ <id>org.apache.lenya.modules.observation-impl</id>
+ <published>false</published>
+ <package>org.apache.lenya.modules</package>
+ <version>0.1-dev</version>
+ <name>Observation implementation</name>
+ <lenya-version>@lenya.version@</lenya-version>
+ <description>Observation implementation</description>
+</module>
Modified: lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/RepoNode.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/RepoNode.java?rev=425889&r1=425888&r2=425889&view=diff
==============================================================================
--- lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/RepoNode.java (original)
+++ lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/RepoNode.java Wed Jul 26 15:42:35 2006
@@ -19,6 +19,8 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
import org.apache.avalon.framework.container.ContainerUtil;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
@@ -27,6 +29,7 @@
import org.apache.lenya.cms.metadata.MetaDataException;
import org.apache.lenya.cms.repo.Translation;
import org.apache.lenya.cms.repository.Node;
+import org.apache.lenya.cms.repository.NodeListener;
import org.apache.lenya.cms.repository.RepositoryException;
import org.apache.lenya.cms.repository.Session;
@@ -181,6 +184,20 @@
public String[] getMetaDataNamespaceUris() throws MetaDataException {
// TODO Auto-generated method stub
return null;
+ }
+
+ private Set listeners = new HashSet();
+
+ public void addListener(NodeListener listener) throws RepositoryException {
+ if (this.listeners.contains(listener)) {
+ throw new RepositoryException("The listener [" + listener
+ + "] is already registered for node [" + this + "]!");
+ }
+ this.listeners.add(listener);
+ }
+
+ public boolean isListenerRegistered(NodeListener listener) {
+ return this.listeners.contains(listener);
}
}
Modified: lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNode.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNode.java?rev=425889&r1=425888&r2=425889&view=diff
==============================================================================
--- lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNode.java (original)
+++ lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNode.java Wed Jul 26 15:42:35 2006
@@ -26,6 +26,7 @@
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -311,6 +312,11 @@
out.write(buf, 0, read);
read = in.read(buf);
}
+
+ for (Iterator i = this.listeners.iterator(); i.hasNext(); ) {
+ NodeListener listener = (NodeListener) i.next();
+ listener.nodeChanged(this);
+ }
} catch (Exception e) {
throw new RepositoryException(e);
@@ -875,6 +881,20 @@
}
Set uris = this.namespace2metamap.keySet();
return (String[]) uris.toArray(new String[uris.size()]);
+ }
+
+ private Set listeners = new HashSet();
+
+ public void addListener(NodeListener listener) throws RepositoryException {
+ if (this.listeners.contains(listener)) {
+ throw new RepositoryException("The listener [" + listener
+ + "] is already registered for node [" + this + "]!");
+ }
+ this.listeners.add(listener);
+ }
+
+ public boolean isListenerRegistered(NodeListener listener) {
+ return this.listeners.contains(listener);
}
}
Modified: lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeFactory.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeFactory.java?rev=425889&r1=425888&r2=425889&view=diff
==============================================================================
--- lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeFactory.java (original)
+++ lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeFactory.java Wed Jul 26 15:42:35 2006
@@ -21,6 +21,7 @@
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.lenya.cms.observation.ObservationRegistry;
/**
* Factory to create source nodes.
@@ -50,7 +51,20 @@
if (this.session == null) {
throw new RepositoryException("The session has not been set!");
}
- return new SourceNode(this.session, key, this.manager, getLogger());
+ Node node = new SourceNode(this.session, key, this.manager, getLogger());
+ ObservationRegistry registry = null;
+ try {
+ registry = (ObservationRegistry) this.manager.lookup(ObservationRegistry.ROLE);
+ node.addListener(registry);
+ } catch (ServiceException e) {
+ throw new RepositoryException(e);
+ }
+ finally {
+ if (registry != null) {
+ this.manager.release(registry);
+ }
+ }
+ return node;
}
public String getItemType() {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org