You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by je...@apache.org on 2008/03/05 15:27:09 UTC

svn commit: r633857 - in /xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop: apps/ events/ fo/

Author: jeremias
Date: Wed Mar  5 06:27:08 2008
New Revision: 633857

URL: http://svn.apache.org/viewvc?rev=633857&view=rev
Log:
Javadocs.
Moved out event listener registration into a CompositeEventListener.
Event broadcaster uses the events effective severity, not the initial value (for the case where listeners override the initial value).
Set up a special EventBroadCaster in the FOUserAgent that filters events through a class (FOValidationEventListenerProxy) that adjusts the event severity for relaxed validation.

Added:
    xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/CompositeEventListener.java   (with props)
    xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/FOValidationEventListenerProxy.java   (with props)
Modified:
    xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/apps/FOUserAgent.java
    xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/DefaultEventBroadcaster.java
    xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/EventBroadcaster.java

Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/apps/FOUserAgent.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/apps/FOUserAgent.java?rev=633857&r1=633856&r2=633857&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/apps/FOUserAgent.java (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/apps/FOUserAgent.java Wed Mar  5 06:27:08 2008
@@ -37,8 +37,11 @@
 
 import org.apache.fop.Version;
 import org.apache.fop.events.DefaultEventBroadcaster;
+import org.apache.fop.events.Event;
 import org.apache.fop.events.EventBroadcaster;
+import org.apache.fop.events.EventListener;
 import org.apache.fop.fo.FOEventHandler;
+import org.apache.fop.fo.FOValidationEventListenerProxy;
 import org.apache.fop.pdf.PDFEncryptionParams;
 import org.apache.fop.render.Renderer;
 import org.apache.fop.render.RendererFactory;
@@ -68,7 +71,8 @@
 public class FOUserAgent {
 
     /** Defines the default target resolution (72dpi) for FOP */
-    public static final float DEFAULT_TARGET_RESOLUTION = FopFactoryConfigurator.DEFAULT_TARGET_RESOLUTION;
+    public static final float DEFAULT_TARGET_RESOLUTION
+                = FopFactoryConfigurator.DEFAULT_TARGET_RESOLUTION;
 
     private static Log log = LogFactory.getLog("FOP");
 
@@ -92,7 +96,7 @@
     private Renderer rendererOverride = null;
     private FOEventHandler foEventHandlerOverride = null;
     private boolean locatorEnabled = true; // true by default (for error messages).
-    private EventBroadcaster eventBroadcaster = new DefaultEventBroadcaster();
+    private EventBroadcaster eventBroadcaster = new FOPEventBroadcaster();
     
     /** Producer:  Metadata element for the system/software that produces
      * the document. (Some renderers can store this in the document.)
@@ -577,5 +581,21 @@
         return this.eventBroadcaster;
     }
 
+    private class FOPEventBroadcaster extends DefaultEventBroadcaster {
+
+        private EventListener rootListener;
+        
+        public FOPEventBroadcaster() {
+            this.rootListener = new FOValidationEventListenerProxy(
+                    this.listeners, FOUserAgent.this);
+        }
+        
+        /** {@inheritDoc} */
+        public void broadcastEvent(Event event) {
+            rootListener.processEvent(event);
+        }
+        
+    }
+    
 }
 

Added: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/CompositeEventListener.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/CompositeEventListener.java?rev=633857&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/CompositeEventListener.java (added)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/CompositeEventListener.java Wed Mar  5 06:27:08 2008
@@ -0,0 +1,69 @@
+/*
+ * 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.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.events;
+
+import java.util.List;
+
+/**
+ * EventListener implementation forwards events to possibly multiple other EventListeners.
+ */
+public class CompositeEventListener implements EventListener {
+
+    private List listeners = new java.util.ArrayList();
+    
+    /**
+     * Adds an event listener to the broadcaster. It is appended to the list of previously
+     * registered listeners (the order of registration defines the calling order).
+     * @param listener the listener to be added
+     */
+    public synchronized void addEventListener(EventListener listener) {
+        this.listeners.add(listener);
+    }
+
+    /**
+     * Removes an event listener from the broadcaster. If the event listener is not registered,
+     * nothing happens.
+     * @param listener the listener to be removed
+     */
+    public synchronized void removeEventListener(EventListener listener) {
+        this.listeners.remove(listener);
+    }
+
+    private synchronized int getListenerCount() {
+        return this.listeners.size();
+    }
+    
+    /**
+     * Indicates whether any listeners have been registered with the broadcaster.
+     * @return true if listeners are present, false otherwise
+     */
+    public boolean hasEventListeners() {
+        return (getListenerCount() > 0);
+    }
+    
+    /** {@inheritDoc} */
+    public synchronized void processEvent(Event event) {
+        for (int i = 0, c = getListenerCount(); i < c; i++) {
+            EventListener listener = (EventListener)this.listeners.get(i);
+            listener.processEvent(event);
+        }
+    }
+
+}

Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/CompositeEventListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/CompositeEventListener.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/DefaultEventBroadcaster.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/DefaultEventBroadcaster.java?rev=633857&r1=633856&r2=633857&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/DefaultEventBroadcaster.java (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/DefaultEventBroadcaster.java Wed Mar  5 06:27:08 2008
@@ -24,7 +24,6 @@
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
 import java.util.Iterator;
-import java.util.List;
 import java.util.Map;
 import java.util.MissingResourceException;
 
@@ -39,31 +38,33 @@
 import org.apache.fop.events.model.EventProducerModel;
 import org.apache.fop.events.model.EventSeverity;
 
+/**
+ * Default implementation of the EventBroadcaster interface. It holds a list of event listeners
+ * and can provide {@link EventProducer} instances for type-safe event production.
+ */
 public class DefaultEventBroadcaster implements EventBroadcaster {
 
-    private List listeners = new java.util.ArrayList();
+    /** Holds all registered event listeners */
+    protected CompositeEventListener listeners = new CompositeEventListener();
     
     /** {@inheritDoc} */
     public void addEventListener(EventListener listener) {
-        this.listeners.add(listener);
+        this.listeners.addEventListener(listener);
     }
 
     /** {@inheritDoc} */
     public void removeEventListener(EventListener listener) {
-        this.listeners.remove(listener);
+        this.listeners.removeEventListener(listener);
     }
 
     /** {@inheritDoc} */
-    public int getListenerCount() {
-        return this.listeners.size();
+    public boolean hasEventListeners() {
+        return this.listeners.hasEventListeners();
     }
     
     /** {@inheritDoc} */
     public void broadcastEvent(Event event) {
-        for (int i = 0, c = getListenerCount(); i < c; i++) {
-            EventListener listener = (EventListener)this.listeners.get(i);
-            listener.processEvent(event);
-        }
+        this.listeners.processEvent(event);
     }
 
     private static final String EVENT_MODEL_FILENAME = "event-model.xml";
@@ -74,6 +75,11 @@
         loadModel(DefaultEventBroadcaster.class, EVENT_MODEL_FILENAME);
     }
 
+    /**
+     * Loads an event model overriding any previously loaded event model.
+     * @param resourceBaseClass base class to use for loading resources
+     * @param resourceName the resource name pointing to the event model to be loaded
+     */
     public static void loadModel(Class resourceBaseClass, String resourceName) {
         InputStream in = resourceBaseClass.getResourceAsStream(resourceName);
         if (in == null) {
@@ -92,6 +98,7 @@
         }
     }
 
+    /** {@inheritDoc} */
     public EventProducer getEventProducerFor(Class clazz) {
         if (!EventProducer.class.isAssignableFrom(clazz)) {
             throw new IllegalArgumentException(
@@ -139,7 +146,8 @@
                         }
                         Event ev = new Event(args[0], eventID, methodModel.getSeverity(), params);
                         broadcastEvent(ev);
-                        if (methodModel.getSeverity() == EventSeverity.FATAL) {
+                        
+                        if (ev.getSeverity() == EventSeverity.FATAL) {
                             EventExceptionManager.throwException(ev,
                                     methodModel.getExceptionClass());
                         }

Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/EventBroadcaster.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/EventBroadcaster.java?rev=633857&r1=633856&r2=633857&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/EventBroadcaster.java (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/EventBroadcaster.java Wed Mar  5 06:27:08 2008
@@ -19,17 +19,43 @@
 
 package org.apache.fop.events;
 
-
+/**
+ * The EventBroadcaster is the central relay point for events. It receives events from various
+ * parts of the application and forwards them to any registered EventListener.
+ */
 public interface EventBroadcaster {
 
+    /**
+     * Adds an event listener to the broadcaster. It is appended to the list of previously
+     * registered listeners (the order of registration defines the calling order).
+     * @param listener the listener to be added
+     */
     void addEventListener(EventListener listener);
     
+    /**
+     * Removes an event listener from the broadcaster. If the event listener is not registered,
+     * nothing happens.
+     * @param listener the listener to be removed
+     */
     void removeEventListener(EventListener listener);
  
-    int getListenerCount();
+    /**
+     * Indicates whether any listeners have been registered with the broadcaster.
+     * @return true if listeners are present, false otherwise
+     */
+    boolean hasEventListeners();
     
+    /**
+     * Broadcasts an event. This method is usually called from within the observed component.
+     * @param event the event to be broadcast
+     */
     void broadcastEvent(Event event);
     
+    /**
+     * Returns an event producer instance for the given interface class.
+     * @param clazz the Class object identifying an {@link EventProducer} interface
+     * @return the event producer instance
+     */
     EventProducer getEventProducerFor(Class clazz);
     
 }

Added: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/FOValidationEventListenerProxy.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/FOValidationEventListenerProxy.java?rev=633857&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/FOValidationEventListenerProxy.java (added)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/FOValidationEventListenerProxy.java Wed Mar  5 06:27:08 2008
@@ -0,0 +1,56 @@
+/*
+ * 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.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.fo;
+
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.events.Event;
+import org.apache.fop.events.EventListener;
+import org.apache.fop.events.model.EventSeverity;
+
+/**
+ * EventListener proxy that inspects all validation events. It reacts on each event based on
+ * the strict validation setting in the user agent. 
+ */
+public class FOValidationEventListenerProxy implements EventListener {
+
+    private static final String FOVALIDATION_EVENT_ID_PREFIX
+                = FOValidationEventProducer.class.getName();
+    
+    private EventListener delegate;
+    private FOUserAgent userAgent;
+    
+    public FOValidationEventListenerProxy(EventListener delegate, FOUserAgent userAgent) {
+        this.delegate = delegate;
+        this.userAgent = userAgent;
+    }
+    
+    /** {@inheritDoc} */
+    public synchronized void processEvent(Event event) {
+        if (event.getEventID().startsWith(FOVALIDATION_EVENT_ID_PREFIX)) {
+            Boolean canRecover = (Boolean)event.getParam("canRecover");
+            if (Boolean.TRUE.equals(canRecover) && !userAgent.validateStrictly()) {
+                //Reduce severity if FOP can recover
+                event.setSeverity(EventSeverity.WARN);
+            }
+        }
+        this.delegate.processEvent(event);
+    }
+
+}

Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/FOValidationEventListenerProxy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/FOValidationEventListenerProxy.java
------------------------------------------------------------------------------
    svn:keywords = Id



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org