cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vgritse...@apache.org
Subject svn commit: r517733 [2/2] - in /cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms: binding/ binding/library/ formmodel/ formmodel/library/ samples/bindings/
Date Tue, 13 Mar 2007 15:37:24 GMT
Modified: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/binding/library/LibraryManagerImpl.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/binding/library/LibraryManagerImpl.java?view=diff&rev=517733&r1=517732&r2=517733
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/binding/library/LibraryManagerImpl.java
(original)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/binding/library/LibraryManagerImpl.java
Tue Mar 13 08:37:22 2007
@@ -16,9 +16,7 @@
  */
 package org.apache.cocoon.forms.binding.library;
 
-import org.apache.avalon.framework.CascadingException;
 import org.apache.avalon.framework.activity.Disposable;
-import org.apache.avalon.framework.activity.Initializable;
 import org.apache.avalon.framework.component.Component;
 import org.apache.avalon.framework.configuration.Configurable;
 import org.apache.avalon.framework.configuration.Configuration;
@@ -34,6 +32,7 @@
 import org.apache.cocoon.forms.CacheManager;
 import org.apache.cocoon.forms.binding.JXPathBindingManager;
 import org.apache.cocoon.forms.util.DomHelper;
+import org.apache.cocoon.util.location.LocationImpl;
 
 import org.w3c.dom.Document;
 import org.xml.sax.InputSource;
@@ -43,24 +42,22 @@
  */
 public class LibraryManagerImpl extends AbstractLogEnabled
                                 implements LibraryManager, Serviceable, Configurable,
-                                           Initializable, Disposable, ThreadSafe, Component
{
+                                           Disposable, ThreadSafe, Component {
 
 	protected static final String PREFIX = "CocoonFormBindingLibrary:";
 
-	private ServiceManager serviceManager;
-    private Configuration configuration;
+	private ServiceManager manager;
     private CacheManager cacheManager;
 
     private JXPathBindingManager bindingManager;
 
 
     public void configure(Configuration configuration) throws ConfigurationException {
-        this.configuration = configuration;
-        getLogger().debug("Gotten a config: top level element: "+this.configuration);
+        // TODO Read config to "preload" libraries
     }
 
     public void service(ServiceManager serviceManager) throws ServiceException {
-        this.serviceManager = serviceManager;
+        this.manager = serviceManager;
         this.cacheManager = (CacheManager)serviceManager.lookup(CacheManager.ROLE);
     }
 
@@ -68,130 +65,124 @@
     	this.bindingManager = bindingManager;
     }
 
-    public void initialize() throws Exception {
-        // read config to "preload" libraries
+    public Library get(String sourceURI) throws LibraryException {
+        return get(sourceURI, null);
     }
 
-    public boolean get(String librarysource) throws Exception {
-    	return get(librarysource,null);
-    }
-
-    public boolean get(String librarysource, String relative) throws Exception {
+    public Library get(String sourceURI, String baseURI) throws LibraryException {
     	SourceResolver sourceResolver = null;
         Source source = null;
-
-        if (getLogger().isDebugEnabled())
-        	getLogger().debug("Checking if library is in cache: '"+librarysource+"' relative
to '"+relative+"'");
-
-        Library lib = null;
-        boolean result = false;
-
         try {
-            sourceResolver = (SourceResolver)serviceManager.lookup(SourceResolver.ROLE);
-            source = sourceResolver.resolveURI(librarysource, relative, null);
+            try {
+                sourceResolver = (SourceResolver) manager.lookup(SourceResolver.ROLE);
+                source = sourceResolver.resolveURI(sourceURI, baseURI, null);
+            } catch (Exception e) {
+                throw new LibraryException("Unable to resolve library.",
+                                           e, new LocationImpl("[LibraryManager]", sourceURI));
+            }
+
+            Library lib = (Library) this.cacheManager.get(source, PREFIX);
+            if (lib != null && lib.dependenciesHaveChanged()) {
+                if (getLogger().isDebugEnabled()) {
+                    getLogger().debug("Library IS REMOVED from cache: '" + sourceURI + "'
relative to '" + baseURI + "'");
+                }
+                this.cacheManager.remove(source, PREFIX); // evict?
+                return null;
+            }
 
-            lib = (Library)this.cacheManager.get(source, PREFIX);
+            if (getLogger().isDebugEnabled()) {
+                if (lib != null) {
+                    getLogger().debug("Library IS in cache: '" + sourceURI + "' relative
to '" + baseURI + "'");
+                } else {
+                    getLogger().debug("Library IS NOT in cache: '" + sourceURI + "' relative
to '" + baseURI + "'");
+                }
+            }
 
-            if( lib != null && lib.dependenciesHaveChanged() ) {
-            	result = false;
-            	this.cacheManager.set(null,source,PREFIX); //evict?
-            }
-            else if( lib == null )
-            	result = false;
-            else
-            	result = true;
-        } catch(Exception e) {
-        	if(getLogger().isErrorEnabled())
-            	getLogger().error("Problem getting library '"+librarysource+"' relative to '"+relative+"'!",e);
-        	throw e;
+            return lib;
         } finally {
-            if (source != null)
+            if (source != null) {
                 sourceResolver.release(source);
-            if (sourceResolver != null)
-            	serviceManager.release(sourceResolver);
-        }
-
-        if(getLogger().isDebugEnabled()) {
-        	if(result)
-        		getLogger().debug("Library IS in cache : '"+librarysource+"' relative to '"+relative+"'");
-        	else
-        		getLogger().debug("Library IS NOT in cache : '"+librarysource+"' relative to '"+relative+"'");
+            }
+            if (sourceResolver != null) {
+                manager.release(sourceResolver);
+            }
         }
-
-        return result;
     }
 
-    public Library load(String librarysource) throws Exception {
-    	return load(librarysource,null);
+    public Library load(String sourceURI) throws LibraryException {
+        return load(sourceURI, null);
     }
 
-	public Library load(String librarysource, String relative) throws Exception {
+	public Library load(String sourceURI, String baseURI) throws LibraryException {
 		SourceResolver sourceResolver = null;
         Source source = null;
-        Document libraryDocument = null;
 
-        Library lib = null;
-
-        if(getLogger().isDebugEnabled())
-        	getLogger().debug("Getting library instance: '"+librarysource+"' relative to '"+relative+"'");
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug("Loading library: '" + sourceURI + "' relative to '" + baseURI
+ "'");
+        }
 
         try {
-            sourceResolver = (SourceResolver)serviceManager.lookup(SourceResolver.ROLE);
-            source = sourceResolver.resolveURI(librarysource, relative, null);
-
-            lib = (Library)this.cacheManager.get(source, PREFIX);
-
-            if( lib != null && lib.dependenciesHaveChanged() ) {
-            	if(getLogger().isDebugEnabled())
-                	getLogger().debug("Library dependencies changed, invalidating!");
+            try {
+                sourceResolver = (SourceResolver) manager.lookup(SourceResolver.ROLE);
+                source = sourceResolver.resolveURI(sourceURI, baseURI, null);
+            } catch (Exception e) {
+                throw new LibraryException("Unable to resolve library.",
+                                           e, new LocationImpl("[LibraryManager]", sourceURI));
+            }
 
-            	lib = null;
+            Library lib = (Library) this.cacheManager.get(source, PREFIX);
+            if (lib != null && lib.dependenciesHaveChanged()) {
+                if (getLogger().isDebugEnabled()) {
+                    getLogger().debug("Library IS EXPIRED in cache: '" + sourceURI + "' relative
to '" + baseURI + "'");
+                }
+                lib = null;
             }
 
-            if( lib == null ) {
-            	if(getLogger().isDebugEnabled())
-                	getLogger().debug("Library not in cache, creating!");
+            if (lib == null) {
+                if (getLogger().isDebugEnabled()) {
+                    getLogger().debug("Library IS NOT in cache, loading: '" + sourceURI +
"' relative to '" + baseURI + "'");
+                }
 
             	try {
                     InputSource inputSource = new InputSource(source.getInputStream());
                     inputSource.setSystemId(source.getURI());
-                    libraryDocument = DomHelper.parse(inputSource, this.serviceManager);
 
+                    Document doc = DomHelper.parse(inputSource, this.manager);
                     lib = newLibrary();
-                    lib.buildLibrary(libraryDocument.getDocumentElement());
+                    lib.buildLibrary(doc.getDocumentElement());
 
                     this.cacheManager.set(lib,source,PREFIX);
-
                 } catch (Exception e) {
-                    throw new CascadingException("Could not parse form definition from "
+
-                                                 source.getURI(), e);
+                    throw new LibraryException("Unable to load library.",
+                                               e, new LocationImpl("[LibraryManager]", source.getURI()));
                 }
             }
+
+            return lib;
         } finally {
-            if (source != null)
+            if (source != null) {
                 sourceResolver.release(source);
-            if (sourceResolver != null)
-            	serviceManager.release(sourceResolver);
+            }
+            if (sourceResolver != null) {
+                manager.release(sourceResolver);
+            }
         }
-
-        return lib;
 	}
 
 	public Library newLibrary() {
-		Library lib = new Library(this);
+		Library lib = new Library(this, bindingManager.getBuilderAssistant());
         lib.enableLogging(getLogger());
-        lib.setAssistant(this.bindingManager.getBuilderAssistant());
-
-        if(getLogger().isDebugEnabled())
-        	getLogger().debug("Created new library! "+lib);
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug("Created new library! " + lib);
+        }
 
         return lib;
 	}
 
 	public void dispose() {
-		this.serviceManager.release(this.cacheManager);
+		this.manager.release(this.cacheManager);
 	    this.cacheManager = null;
-	    this.serviceManager = null;
+	    this.manager = null;
 	}
 
 	public void debug(String msg) {

Modified: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/RepeaterActionDefinition.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/RepeaterActionDefinition.java?view=diff&rev=517733&r1=517732&r2=517733
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/RepeaterActionDefinition.java
(original)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/RepeaterActionDefinition.java
Tue Mar 13 08:37:22 2007
@@ -120,8 +120,8 @@
             // Call action listeners, if any
             super.fireActionEvent(event);
 
-            Repeater repeater = ((RepeaterAction)event.getSource()).getRepeater();
-            
+            Repeater repeater = ((RepeaterAction) event.getSource()).getRepeater();
+
             // and actually delete the rows
             for (int i = repeater.getSize() - 1; i >= 0; i--) {
                 Repeater.RepeaterRow row = repeater.getRow(i);
@@ -129,15 +129,15 @@
                     repeater.removeRow(i);
                 }
             }
-            
+
             if (repeater instanceof EnhancedRepeater) {
-            	try {
-					((EnhancedRepeater)repeater).refreshPage();
-				} catch (BindingException e) {
-					throw new CascadingRuntimeException("Error refreshing repeater page", e);
-				}
+                try {
+                    ((EnhancedRepeater) repeater).refreshPage();
+                } catch (BindingException e) {
+                    throw new CascadingRuntimeException("Error refreshing repeater page",
e);
+                }
             }
-            
+
         }
     }
 
@@ -153,18 +153,18 @@
             super(repeaterName);
             this.insertRows = insertRows;
 
-            this.addActionListener(new ActionListener() {
+            addActionListener(new ActionListener() {
                 public void actionPerformed(ActionEvent event) {
                     Repeater repeater = ((RepeaterAction)event.getSource()).getRepeater();
                     if (repeater instanceof EnhancedRepeater) {
                     	try {
-							((EnhancedRepeater)repeater).goToPage(((EnhancedRepeater)repeater).getMaxPage());
-						} catch (BindingException e) {
+                            ((EnhancedRepeater) repeater).goToPage(((EnhancedRepeater) repeater).getMaxPage());
+                        } catch (BindingException e) {
 							throw new CascadingRuntimeException("Error switching page", e);
 						}
                     }
-                    for (int i=0; i<AddRowActionDefinition.this.insertRows; i++) {
-                        repeater.addRow(); 
+                    for (int i = 0; i < AddRowActionDefinition.this.insertRows; i++) {
+                        repeater.addRow();
                     }
                 }
             });

Modified: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/RepeaterFilterField.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/RepeaterFilterField.java?view=diff&rev=517733&r1=517732&r2=517733
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/RepeaterFilterField.java
(original)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/RepeaterFilterField.java
Tue Mar 13 08:37:22 2007
@@ -21,6 +21,9 @@
 import org.apache.cocoon.forms.event.ValueChangedEvent;
 import org.apache.cocoon.forms.event.ValueChangedListener;
 
+/**
+ * @version $Id$
+ */
 public class RepeaterFilterField extends Field {
 
 	private EnhancedRepeater repeater;
@@ -31,27 +34,29 @@
 		this.field = fieldDefinition.getField();
 	}
 
-	public void initialize() {
-		super.initialize();
-		String name = ((RepeaterFilterFieldDefinition)getDefinition()).getRepeaterName();
-		Widget w = getParent().lookupWidget(name);
-		if (w == null) throw new IllegalArgumentException("Cannot find repeater named " + name);
-		if (!(w instanceof EnhancedRepeater)) throw new IllegalArgumentException("The repeater
named " + name + " is not an enhanced repeater");
-		this.repeater = (EnhancedRepeater) w;
-		
-		this.addValueChangedListener(new ValueChangedListener() {
-			public void valueChanged(ValueChangedEvent event) {
-				if (repeater.validate()) {
-					try {
-						repeater.setFilter(field, event.getNewValue());
-					} catch (BindingException e) {
-						throw new CascadingRuntimeException("Error setting filter",e);
-					}
-				}
-			}
-		});
-	}
-	
-	
+    public void initialize() {
+        super.initialize();
+        String name = ((RepeaterFilterFieldDefinition) getDefinition()).getRepeaterName();
+        Widget w = getParent().lookupWidget(name);
+        if (w == null) {
+            throw new IllegalArgumentException("Cannot find repeater named " + name);
+        }
+        if (!(w instanceof EnhancedRepeater)) {
+            throw new IllegalArgumentException("The repeater named " + name + " is not an
enhanced repeater");
+        }
+        this.repeater = (EnhancedRepeater) w;
+
+        addValueChangedListener(new ValueChangedListener() {
+            public void valueChanged(ValueChangedEvent event) {
+                if (repeater.validate()) {
+                    try {
+                        repeater.setFilter(field, event.getNewValue());
+                    } catch (BindingException e) {
+                        throw new CascadingRuntimeException("Error setting filter", e);
+                    }
+                }
+            }
+        });
+    }
 
 }

Modified: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/library/Library.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/library/Library.java?view=diff&rev=517733&r1=517732&r2=517733
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/library/Library.java
(original)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/library/Library.java
Tue Mar 13 08:37:22 2007
@@ -94,6 +94,7 @@
      * @param key the key
      * @param sourceURI the source of the library to be know as "key"
      * @return true if there was no such key used before, false otherwise
+     * @throws LibraryException if unable to load included library
      */
     public boolean includeAs(String key, String sourceURI)
     throws LibraryException {
@@ -106,7 +107,6 @@
     }
 
     public WidgetDefinition getDefinition(String key) throws LibraryException {
-
         String librarykey = null;
         String definitionkey = key;
 
@@ -125,7 +125,7 @@
                 try {
                     return manager.load(dependency.dependencyURI, sourceURI).getDefinition(definitionkey);
                 } catch (Exception e) {
-                    throw new LibraryException("Couldn't get Library key='" + librarykey
+ "' source='" + dependency + "", e);
+                    throw new LibraryException("Couldn't get library '" + librarykey + "'
source='" + dependency + "'", e);
                 }
             } else {
                 throw new LibraryException("Library '" + librarykey + "' does not exist!
(lookup: '" + key + "')");

Modified: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/samples/bindings/CustomValueWrapBinding.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/samples/bindings/CustomValueWrapBinding.java?view=diff&rev=517733&r1=517732&r2=517733
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/samples/bindings/CustomValueWrapBinding.java
(original)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/samples/bindings/CustomValueWrapBinding.java
Tue Mar 13 08:37:22 2007
@@ -82,7 +82,7 @@
      * @return the configured binding
      * @throws BindingException when the creation fails
      */
-    public static Binding createBinding(Element config) throws BindingException{
+    public static Binding createBinding(Element config) throws BindingException {
 
         try {
             String pfx = DomHelper.getAttribute(config, "prefixchar", null);
@@ -93,7 +93,8 @@
             
             return new CustomValueWrapBinding(prefixChar, suffixChar);
         } catch (Exception e) {
-            throw new BindingException("Could not create instance of CustomValueWrapBinding."
,e);
+            throw new BindingException("Could not create instance of CustomValueWrapBinding.",
e,
+                                       DomHelper.getLocationObject(config));
         }
     }
 }



Mime
View raw message