cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mpfingsth...@apache.org
Subject svn commit: r267351 - in /cocoon/gsoc/mpfingsthorn/forms: java/org/apache/cocoon/forms/binding/ java/org/apache/cocoon/forms/binding/library/ java/org/apache/cocoon/forms/formmodel/ java/org/apache/cocoon/forms/formmodel/library/ samples/library/forms/...
Date Sat, 03 Sep 2005 00:25:50 GMT
Author: mpfingsthorn
Date: Fri Sep  2 17:25:02 2005
New Revision: 267351

URL: http://svn.apache.org/viewcvs?rev=267351&view=rev
Log:
Libraries now include relative to themselves. Fixed some inheritance issue for top-level widgets
and bindings. They ignored the extends attribute, not anymore though. Added some more library
depth to the sample to test it.

Added:
    cocoon/gsoc/mpfingsthorn/forms/samples/library/libraries/library_form1-second.xml   (with
props)
    cocoon/gsoc/mpfingsthorn/forms/samples/library/libraries/library_form1-second_binding.xml
  (with props)
Modified:
    cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/binding/ComposedJXPathBindingBase.java
    cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/binding/JXPathBindingManager.java
    cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/binding/library/Library.java
    cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/binding/library/LibraryManager.java
    cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/binding/library/LibraryManagerImpl.java
    cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/formmodel/AbstractContainerDefinition.java
    cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/formmodel/AbstractContainerDefinitionBuilder.java
    cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinitionBuilder.java
    cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/formmodel/FormDefinitionBuilder.java
    cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/formmodel/library/Library.java
    cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/formmodel/library/LibraryManager.java
    cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/formmodel/library/LibraryManagerImpl.java
    cocoon/gsoc/mpfingsthorn/forms/samples/library/forms/form1_binding.xml
    cocoon/gsoc/mpfingsthorn/forms/samples/library/forms/form1_model.xml
    cocoon/gsoc/mpfingsthorn/forms/samples/library/forms/form1_template.xml

Modified: cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/binding/ComposedJXPathBindingBase.java
URL: http://svn.apache.org/viewcvs/cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/binding/ComposedJXPathBindingBase.java?rev=267351&r1=267350&r2=267351&view=diff
==============================================================================
--- cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/binding/ComposedJXPathBindingBase.java
(original)
+++ cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/binding/ComposedJXPathBindingBase.java
Fri Sep  2 17:25:02 2005
@@ -33,41 +33,6 @@
 public class ComposedJXPathBindingBase extends JXPathBindingBase {
     private final JXPathBindingBase[] subBindings;
     
-    
-    public static JXPathBindingBase[] mergeBindings(JXPathBindingBase[] existing, JXPathBindingBase[]
extra) throws Exception {
-    	
-    	if(existing == null || existing.length == 0)
-    		return extra;
-    	
-    	if(extra == null || extra.length == 0)
-    		return existing;
-    	
-    	// have to do it the stupid painter way..
-    	ArrayList list = new ArrayList(existing.length);
-    	for(int i=0; i<existing.length; i++)
-    		list.add(existing[i]);
-    	
-    	for(int i=0; i<extra.length; i++) {
-    		if(extra[i].getId()==null)
-    			list.add(extra[i]);
-    		else {
-    			// try to replace existing one
-    			boolean match = false;
-    			for(int j=0; j<list.size(); j++) {
-    				if(extra[i].getId().equals(((JXPathBindingBase)list.get(j)).getId())) {
-    					list.set(j,extra[i]);
-    					match = true;
-    					break; // stop searching
-    				}
-    			}
-    			// if no match, just add
-    			if(!match)
-    				list.add(extra[i]);
-    		}
-    	}	
-    	
-    	return (JXPathBindingBase[])list.toArray(new JXPathBindingBase[0]);
-    }
 
     /**
      * need accessors!

Modified: cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/binding/JXPathBindingManager.java
URL: http://svn.apache.org/viewcvs/cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/binding/JXPathBindingManager.java?rev=267351&r1=267350&r2=267351&view=diff
==============================================================================
--- cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/binding/JXPathBindingManager.java
(original)
+++ cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/binding/JXPathBindingManager.java
Fri Sep  2 17:25:02 2005
@@ -15,6 +15,7 @@
  */
 package org.apache.cocoon.forms.binding;
 
+import java.util.ArrayList;
 import java.util.Stack;
 
 import org.apache.avalon.framework.activity.Disposable;
@@ -39,6 +40,7 @@
 import org.apache.cocoon.forms.datatype.DatatypeManager;
 import org.apache.cocoon.forms.util.DomHelper;
 import org.apache.cocoon.forms.util.SimpleServiceSelector;
+import org.apache.cocoon.util.location.LocationAttributes;
 import org.apache.excalibur.source.Source;
 import org.apache.excalibur.source.SourceResolver;
 import org.w3c.dom.Document;
@@ -97,7 +99,7 @@
                                        configuration.getChild("bindings"));
         
         libraryManager = new LibraryManagerImpl();
-        libraryManager.setAssistant(getBuilderAssistant());
+        libraryManager.setBindingManager(this);
         LifecycleHelper.setupComponent(libraryManager,
         								getLogger(),
         								this.avalonContext,
@@ -166,7 +168,7 @@
         }
     }
 
-    private Assistant getBuilderAssistant() {
+    public Assistant getBuilderAssistant() {
         return new Assistant();
     }
 
@@ -225,10 +227,22 @@
             if(context.getLocalLibrary() == null) {
             	Library lib = new Library(libraryManager);
             	context.setLocalLibrary(lib);
+            	lib.setAssistant(getBuilderAssistant());
+            	lib.setSourceURI(LocationAttributes.getURI(configElm));
             	flag = true;
-            	System.out.println("Set local library on "+context+" to "+lib);
             }
             
+            if(context.getLocalLibrary()!=null && configElm.getAttribute("extends")!=null)
{
+        		try {
+        			context.setSuperBinding(context.getLocalLibrary().getBinding(configElm.getAttribute("extends")));
+        			
+        		} catch(LibraryException e) {
+        			throw new RuntimeException("Error extending binding! (at "+DomHelper.getLocation(configElm)+")",e);
+        		}
+        	} else {
+        		context.setSuperBinding(null);
+        	}
+            
             JXPathBindingBase childBinding = bindingBuilder.buildBinding(configElm, this);
             
             if(flag && childBinding != null) {
@@ -238,13 +252,46 @@
             // this might get called unnecessarily, but solves issues with the libraries
             if(childBinding != null)
             	childBinding.enableLogging(getLogger());
-            	
-            System.out.println("made new binding! "+configElm.getLocalName());
             
             
             return childBinding;
         }
 
+        private JXPathBindingBase[] mergeBindings(JXPathBindingBase[] existing, JXPathBindingBase[]
extra) {
+        	
+        	if(existing == null || existing.length == 0)
+        		return extra;
+        	
+        	if(extra == null || extra.length == 0)
+        		return existing;
+        	
+        	// have to do it the stupid painter way..
+        	ArrayList list = new ArrayList(existing.length);
+        	for(int i=0; i<existing.length; i++)
+        		list.add(existing[i]);
+        	
+        	for(int i=0; i<extra.length; i++) {
+        		if(extra[i].getId()==null)
+        			list.add(extra[i]);
+        		else {
+        			// try to replace existing one
+        			boolean match = false;
+        			for(int j=0; j<list.size(); j++) {
+        				if(extra[i].getId().equals(((JXPathBindingBase)list.get(j)).getId())) {
+        					list.set(j,extra[i]);
+        					match = true;
+        					break; // stop searching
+        				}
+        			}
+        			// if no match, just add
+        			if(!match)
+        				list.add(extra[i]);
+        		}
+        	}	
+        	
+        	return (JXPathBindingBase[])list.toArray(new JXPathBindingBase[0]);
+        }
+        
         /**
          * proxy for compatibility
          * 
@@ -291,7 +338,7 @@
                         
                         popContext();
                     }
-                    return childBindings;
+                    return mergeBindings(existingBindings,childBindings);
                 }
             }
             return null;

Modified: cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/binding/library/Library.java
URL: http://svn.apache.org/viewcvs/cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/binding/library/Library.java?rev=267351&r1=267350&r2=267351&view=diff
==============================================================================
--- cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/binding/library/Library.java
(original)
+++ cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/binding/library/Library.java
Fri Sep  2 17:25:02 2005
@@ -26,6 +26,7 @@
 import org.apache.cocoon.forms.binding.BindingManager;
 import org.apache.cocoon.forms.binding.JXPathBindingManager;
 import org.apache.cocoon.forms.util.DomHelper;
+import org.apache.cocoon.util.location.LocationAttributes;
 
 import org.w3c.dom.Element;
 
@@ -47,6 +48,7 @@
 	// shared object with dependencies
 	protected Object shared = new Object();
 	
+	protected String sourceURI = null;
 	protected JXPathBindingManager.Assistant assistant = null;
 	
 	public Library(ServiceManager sm) {
@@ -65,6 +67,13 @@
 		this.assistant = assistant;
 	}
 	
+	public void setSourceURI(String uri) {
+		sourceURI = uri;
+	}
+	public String getSourceURI() {
+		return sourceURI;
+	}
+	
 	public boolean dependenciesHaveChanged() throws Exception {
 		
 		Iterator it = this.inclusions.values().iterator();
@@ -91,7 +100,7 @@
 		try {
 			// library keys may not contain ":"!
 			if( (!inclusions.containsKey(key) || key.indexOf(SEPARATOR)>-1) 
-					&& manager.getLibrary(librarysource)!=null) {
+					&& manager.getLibrary(librarysource, sourceURI)!=null) {
 				inclusions.put(key,new Dependency(librarysource));
 				return true;
 			}
@@ -119,7 +128,7 @@
 		if(librarykey!=null) {
 			if(inclusions.containsKey(librarykey)) {
 				try {
-					return manager.getLibrary(((Dependency)inclusions.get(librarykey)).sourceURI).getBinding(definitionkey);
+					return manager.getLibrary(((Dependency)inclusions.get(librarykey)).dependencySourceURI,
sourceURI).getBinding(definitionkey);
 				} catch(Exception e) {
 					throw new LibraryException("Couldn't get Library key='"+librarykey+"' source='"+inclusions.get(librarykey)+"",e);
 				}
@@ -132,6 +141,7 @@
 	}
 	
 	public void buildLibrary(Element libraryElement) throws Exception {
+		sourceURI = LocationAttributes.getURI(libraryElement);
 		this.assistant.getContext().setLocalLibrary(this);
         Element[] bindingElements = DomHelper.getChildElements(libraryElement, BindingManager.NAMESPACE);
         for (int i = 0; i < bindingElements.length; i++) {
@@ -158,21 +168,21 @@
 	 */
 	public class Dependency {
 		
-		private String sourceURI;
+		private String dependencySourceURI;
 		private Object shared;
 		
-		public Dependency(String sourceURI) throws Exception {
-			this.sourceURI = sourceURI;
+		public Dependency(String dependencySourceURI) throws Exception {
+			this.dependencySourceURI = dependencySourceURI;
 			
-			Library lib = manager.getLibrary(sourceURI);
+			Library lib = manager.getLibrary(this.dependencySourceURI,sourceURI);
 			this.shared = lib.shared;
 		}
 		
 		public boolean isValid() throws LibraryException {
 			try {
 				
-				if(manager.libraryInCache(sourceURI)) {
-					Library lib = manager.getLibrary(sourceURI);
+				if(manager.libraryInCache(dependencySourceURI,sourceURI)) {
+					Library lib = manager.getLibrary(dependencySourceURI,sourceURI);
 					
 					if(this.shared == lib.shared)
 						return true;

Modified: cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/binding/library/LibraryManager.java
URL: http://svn.apache.org/viewcvs/cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/binding/library/LibraryManager.java?rev=267351&r1=267350&r2=267351&view=diff
==============================================================================
--- cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/binding/library/LibraryManager.java
(original)
+++ cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/binding/library/LibraryManager.java
Fri Sep  2 17:25:02 2005
@@ -30,9 +30,11 @@
 	String ROLE = LibraryManager.class.getName();
 	
 	Library getLibrary(String librarysource) throws Exception;
+	Library getLibrary(String librarysource, String relative) throws Exception;
 	Library getNewLibrary();
 	
 	boolean libraryInCache(String librarysource) throws Exception;
+	boolean libraryInCache(String librarysource, String relative) throws Exception;
 	
 	void debug(String msg);
 }

Modified: cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/binding/library/LibraryManagerImpl.java
URL: http://svn.apache.org/viewcvs/cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/binding/library/LibraryManagerImpl.java?rev=267351&r1=267350&r2=267351&view=diff
==============================================================================
--- cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/binding/library/LibraryManagerImpl.java
(original)
+++ cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/binding/library/LibraryManagerImpl.java
Fri Sep  2 17:25:02 2005
@@ -49,7 +49,7 @@
     private Configuration configuration;
     private CacheManager cacheManager;
     
-    private JXPathBindingManager.Assistant assistant;
+    private JXPathBindingManager bindingManager;
 
     public void configure(Configuration configuration) throws ConfigurationException {
         this.configuration = configuration;
@@ -61,8 +61,8 @@
         this.cacheManager = (CacheManager)serviceManager.lookup(CacheManager.ROLE);
     }
     
-    public void setAssistant(JXPathBindingManager.Assistant assistant) {
-    	this.assistant = assistant;
+    public void setBindingManager(JXPathBindingManager bindingManager) {
+    	this.bindingManager = bindingManager;
     }
     
     public void initialize() throws Exception {
@@ -71,18 +71,22 @@
     }
     
     public boolean libraryInCache(String librarysource) throws Exception {
+    	return libraryInCache(librarysource,null);
+    }
+    
+    public boolean libraryInCache(String librarysource, String relative) throws Exception
{
     	SourceResolver sourceResolver = null;
         Source source = null;
         
         if(getLogger().isDebugEnabled())
-        	getLogger().debug("Checking if library is in cache: '"+librarysource+"'");
+        	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);
+            source = sourceResolver.resolveURI(librarysource, relative, null);
             
             lib = (Library)this.cacheManager.get(source, PREFIX);
             
@@ -96,7 +100,7 @@
             	result = true;
         } catch(Exception e) {
         	if(getLogger().isErrorEnabled())
-            	getLogger().error("Problem getting library '"+librarysource+"'!",e);
+            	getLogger().error("Problem getting library '"+librarysource+"' relative to '"+relative+"'!",e);
         	throw e;
         } finally {
             if (source != null)
@@ -107,15 +111,19 @@
 
         if(getLogger().isDebugEnabled()) {
         	if(result)
-        		getLogger().debug("Library IS in cache : '"+librarysource+"'");
+        		getLogger().debug("Library IS in cache : '"+librarysource+"' relative to '"+relative+"'");
         	else
-        		getLogger().debug("Library IS NOT in cache : '"+librarysource+"'");
+        		getLogger().debug("Library IS NOT in cache : '"+librarysource+"' relative to '"+relative+"'");
         }
         
         return result;
     }
     
-	public Library getLibrary(String librarysource) throws Exception {
+    public Library getLibrary(String librarysource) throws Exception {
+    	return getLibrary(librarysource,null);
+    }
+    
+	public Library getLibrary(String librarysource, String relative) throws Exception {
 		SourceResolver sourceResolver = null;
         Source source = null;
         Document libraryDocument = null;
@@ -123,11 +131,11 @@
         Library lib = null;
         
         if(getLogger().isDebugEnabled())
-        	getLogger().debug("Getting library instance: '"+librarysource+"'");
+        	getLogger().debug("Getting library instance: '"+librarysource+"' relative to '"+relative+"'");
         
         try {
             sourceResolver = (SourceResolver)serviceManager.lookup(SourceResolver.ROLE);
-            source = sourceResolver.resolveURI(librarysource);
+            source = sourceResolver.resolveURI(librarysource, relative, null);
             
             lib = (Library)this.cacheManager.get(source, PREFIX);
             
@@ -169,7 +177,7 @@
 	
 	public Library getNewLibrary() {
 		Library lib = new Library(this);
-		lib.setAssistant(this.assistant);
+		lib.setAssistant(this.bindingManager.getBuilderAssistant());
         
         if(getLogger().isDebugEnabled())
         	getLogger().debug("Created new library! "+lib);

Modified: cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/formmodel/AbstractContainerDefinition.java
URL: http://svn.apache.org/viewcvs/cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/formmodel/AbstractContainerDefinition.java?rev=267351&r1=267350&r2=267351&view=diff
==============================================================================
--- cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/formmodel/AbstractContainerDefinition.java
(original)
+++ cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/formmodel/AbstractContainerDefinition.java
Fri Sep  2 17:25:02 2005
@@ -49,10 +49,13 @@
     	if(definition instanceof AbstractContainerDefinition) {
     		AbstractContainerDefinition other = (AbstractContainerDefinition)definition;
     		
+    		System.err.println("Nr of inherited defs: "+other.definitions.getWidgetDefinitions().size());
     		Iterator otherwidgets = other.definitions.getWidgetDefinitions().iterator();
     		while(otherwidgets.hasNext()) {
     			try {
-    				this.definitions.addWidgetDefinition((WidgetDefinition)otherwidgets.next());
+    				WidgetDefinition def = (WidgetDefinition)otherwidgets.next();
+    				this.definitions.addWidgetDefinition(def);
+    				System.err.println("Container: added "+def.getId());
     			} catch(DuplicateIdException ignore) {}
     		}
     	} else {

Modified: cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/formmodel/AbstractContainerDefinitionBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/formmodel/AbstractContainerDefinitionBuilder.java?rev=267351&r1=267350&r2=267351&view=diff
==============================================================================
--- cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/formmodel/AbstractContainerDefinitionBuilder.java
(original)
+++ cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/formmodel/AbstractContainerDefinitionBuilder.java
Fri Sep  2 17:25:02 2005
@@ -14,6 +14,10 @@
 		Element widgetsElement = DomHelper.getChildElement(element, Constants.DEFINITION_NS, widgetsElementName,
true);
         // All child elements of the widgets element are widgets
         Element[] widgetElements = DomHelper.getChildElements(widgetsElement, Constants.DEFINITION_NS);
+        WidgetDefinitionBuilderContext oldContext = this.context;
+        this.context = new WidgetDefinitionBuilderContext(this.context);
+        this.context.setSuperDefinition(null);
+        
         if(widgetElements!=null)
         for (int i = 0; i < widgetElements.length; i++) {
             Element widgetElement = widgetElements[i];
@@ -21,13 +25,13 @@
             String newId = null;
             WidgetDefinition def = null;
             if(this.context !=null)
-	            if((newId = (String)widgetElement.getAttribute("extends")) != null) {
+	            if((newId = widgetElement.getAttribute("extends")) != null) {
 	            	if((def = this.context.getLocalLibrary().getDefinition(newId))!=null)
 	            		this.context.setSuperDefinition(def);
 	            	else if((def = definition.getWidgetDefinition(newId))!=null)
 	            		this.context.setSuperDefinition(def);
 	            }
-	            else
+	            else 
 	            	this.context.setSuperDefinition(null);
                 
             WidgetDefinition widgetDefinition = buildAnotherWidgetDefinition(widgetElement);
@@ -36,6 +40,7 @@
             	definition.addWidgetDefinition(widgetDefinition);
         }
         
+        this.context = oldContext;
     }
 
 }

Modified: cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinitionBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinitionBuilder.java?rev=267351&r1=267350&r2=267351&view=diff
==============================================================================
--- cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinitionBuilder.java
(original)
+++ cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinitionBuilder.java
Fri Sep  2 17:25:02 2005
@@ -85,6 +85,8 @@
     	// location
     	definition.setLocation(DomHelper.getLocation(widgetElement));
     	
+    	System.err.println(widgetElement.getAttribute("id")+" ("+widgetElement.getAttribute("extends")+"):
"+this.context.getSuperDefinition());
+    	
     	if(this.context.getSuperDefinition()!=null)
     		definition.initializeFrom(this.context.getSuperDefinition());
     	

Modified: cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/formmodel/FormDefinitionBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/formmodel/FormDefinitionBuilder.java?rev=267351&r1=267350&r2=267351&view=diff
==============================================================================
--- cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/formmodel/FormDefinitionBuilder.java
(original)
+++ cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/formmodel/FormDefinitionBuilder.java
Fri Sep  2 17:25:02 2005
@@ -18,6 +18,7 @@
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.cocoon.forms.formmodel.library.LibraryManager;
+import org.apache.cocoon.util.location.LocationAttributes;
 import org.w3c.dom.Element;
 
 /**
@@ -43,6 +44,9 @@
         FormDefinition formDefinition = new FormDefinition(libraryManager);
         this.context = new WidgetDefinitionBuilderContext();
         this.context.setLocalLibrary(formDefinition.getLocalLibrary());
+        
+        // set local URI
+        formDefinition.getLocalLibrary().setSourceURI(LocationAttributes.getURI(formElement));
         
         super.setupDefinition(formElement, formDefinition);
         setDisplayData(formElement, formDefinition);

Modified: cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/formmodel/library/Library.java
URL: http://svn.apache.org/viewcvs/cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/formmodel/library/Library.java?rev=267351&r1=267350&r2=267351&view=diff
==============================================================================
--- cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/formmodel/library/Library.java
(original)
+++ cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/formmodel/library/Library.java
Fri Sep  2 17:25:02 2005
@@ -27,6 +27,7 @@
 import org.apache.cocoon.forms.formmodel.WidgetDefinitionBuilder;
 import org.apache.cocoon.forms.formmodel.WidgetDefinitionBuilderContext;
 import org.apache.cocoon.forms.util.DomHelper;
+import org.apache.cocoon.util.location.LocationAttributes;
 
 import org.w3c.dom.Element;
 
@@ -52,6 +53,7 @@
 	// shared object with dependencies
 	protected Object shared = new Object();
 	
+	protected String sourceURI = null;
 	protected WidgetDefinitionBuilderContext context;
 	
 	public Library(LibraryManager lm) {
@@ -60,6 +62,13 @@
 		context.setLocalLibrary(this);
 	}
 	
+	public void setSourceURI(String uri) {
+		sourceURI = uri;
+	}
+	public String getSourceURI() {
+		return sourceURI;
+	}
+	
 	public void setWidgetDefinitionBuilderSelector(ServiceSelector selector) {
 		this.widgetDefinitionBuilderSelector = selector;
 	}
@@ -90,7 +99,7 @@
 		try {
 			// library keys may not contain ":"!
 			if( (!inclusions.containsKey(key) || key.indexOf(SEPARATOR)>-1) 
-					&& manager.getLibrary(librarysource)!=null) {
+					&& manager.getLibrary(librarysource, sourceURI)!=null) {
 				inclusions.put(key,new Dependency(librarysource));
 				return true;
 			}
@@ -118,7 +127,7 @@
 		if(librarykey!=null) {
 			if(inclusions.containsKey(librarykey)) {
 				try {
-					return manager.getLibrary(((Dependency)inclusions.get(librarykey)).sourceURI).getDefinition(definitionkey);
+					return manager.getLibrary(((Dependency)inclusions.get(librarykey)).dependencySourceURI,
sourceURI).getDefinition(definitionkey);
 				} catch(Exception e) {
 					throw new LibraryException("Couldn't get Library key='"+librarykey+"' source='"+inclusions.get(librarykey)+"",e);
 				}
@@ -131,6 +140,7 @@
 	}
 	
 	public void buildLibrary(Element libraryElement) throws Exception {
+		sourceURI = LocationAttributes.getURI(libraryElement);
 		Element widgetsElement = DomHelper.getChildElement(libraryElement, Constants.DEFINITION_NS,
"widgets", true);
         // All child elements of the widgets element are widgets
         Element[] widgetElements = DomHelper.getChildElements(widgetsElement, Constants.DEFINITION_NS);
@@ -142,6 +152,9 @@
 	}
 	
 	public void addDefinition(WidgetDefinition definition) throws LibraryException {
+		if(definition == null)
+			return;
+		
 		if(definitions.containsKey(definition.getId()))
 			throw new LibraryException("Library already contains a widget with this ID!");
 		
@@ -158,6 +171,13 @@
             throw new CascadingException("Unknown kind of widget '" + widgetName + "' at
" +
                                          DomHelper.getLocation(widgetDefinition), e);
         }
+        
+        String extend = widgetDefinition.getAttribute("extends");  
+        if(extend!=null && !"".equals(extend))
+        	context.setSuperDefinition(getDefinition(extend));
+        else
+        	context.setSuperDefinition(null);
+        
         return builder.buildWidgetDefinition(widgetDefinition,context);
     }
 	
@@ -170,21 +190,21 @@
 	 */
 	public class Dependency {
 		
-		private String sourceURI;
+		private String dependencySourceURI;
 		private Object shared;
 		
-		public Dependency(String sourceURI) throws Exception {
-			this.sourceURI = sourceURI;
+		public Dependency(String dependencySourceURI) throws Exception {
+			this.dependencySourceURI = dependencySourceURI;
 			
-			Library lib = manager.getLibrary(sourceURI);
+			Library lib = manager.getLibrary(this.dependencySourceURI,sourceURI);
 			this.shared = lib.shared;
 		}
 		
 		public boolean isValid() throws LibraryException {
 			try {
 				
-				if(manager.libraryInCache(sourceURI)) {
-					Library lib = manager.getLibrary(sourceURI);
+				if(manager.libraryInCache(dependencySourceURI,sourceURI)) {
+					Library lib = manager.getLibrary(dependencySourceURI,sourceURI);
 					
 					if(this.shared == lib.shared)
 						return true;

Modified: cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/formmodel/library/LibraryManager.java
URL: http://svn.apache.org/viewcvs/cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/formmodel/library/LibraryManager.java?rev=267351&r1=267350&r2=267351&view=diff
==============================================================================
--- cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/formmodel/library/LibraryManager.java
(original)
+++ cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/formmodel/library/LibraryManager.java
Fri Sep  2 17:25:02 2005
@@ -30,9 +30,11 @@
 	String ROLE = LibraryManager.class.getName();
 	
 	Library getLibrary(String librarysource) throws Exception;
+	Library getLibrary(String librarysource, String relative) throws Exception;
 	Library getNewLibrary();
 	
 	boolean libraryInCache(String librarysource) throws Exception;
+	boolean libraryInCache(String librarysource, String relative) throws Exception;
 	
 	void debug(String msg);
 }

Modified: cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/formmodel/library/LibraryManagerImpl.java
URL: http://svn.apache.org/viewcvs/cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/formmodel/library/LibraryManagerImpl.java?rev=267351&r1=267350&r2=267351&view=diff
==============================================================================
--- cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/formmodel/library/LibraryManagerImpl.java
(original)
+++ cocoon/gsoc/mpfingsthorn/forms/java/org/apache/cocoon/forms/formmodel/library/LibraryManagerImpl.java
Fri Sep  2 17:25:02 2005
@@ -67,18 +67,22 @@
     }
     
     public boolean libraryInCache(String librarysource) throws Exception {
+    	return libraryInCache(librarysource,null);
+    }
+    
+    public boolean libraryInCache(String librarysource, String relative) throws Exception
{
     	SourceResolver sourceResolver = null;
         Source source = null;
         
         if(getLogger().isDebugEnabled())
-        	getLogger().debug("Checking if library is in cache: '"+librarysource+"'");
+        	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);
+            source = sourceResolver.resolveURI(librarysource, relative, null);
             
             lib = (Library)this.cacheManager.get(source, PREFIX);
             
@@ -92,7 +96,7 @@
             	result = true;
         } catch(Exception e) {
         	if(getLogger().isErrorEnabled())
-            	getLogger().error("Problem getting library '"+librarysource+"'!",e);
+            	getLogger().error("Problem getting library '"+librarysource+"' relative to '"+relative+"'!",e);
         	throw e;
         } finally {
             if (source != null)
@@ -103,15 +107,19 @@
 
         if(getLogger().isDebugEnabled()) {
         	if(result)
-        		getLogger().debug("Library IS in cache : '"+librarysource+"'");
+        		getLogger().debug("Library IS in cache : '"+librarysource+"' relative to '"+relative+"'");
         	else
-        		getLogger().debug("Library IS NOT in cache : '"+librarysource+"'");
+        		getLogger().debug("Library IS NOT in cache : '"+librarysource+"' relative to '"+relative+"'");
         }
         
         return result;
     }
     
-	public Library getLibrary(String librarysource) throws Exception {
+    public Library getLibrary(String librarysource) throws Exception {
+    	return getLibrary(librarysource,null);
+    }
+    
+	public Library getLibrary(String librarysource, String relative) throws Exception {
 		SourceResolver sourceResolver = null;
         Source source = null;
         Document libraryDocument = null;
@@ -119,11 +127,11 @@
         Library lib = null;
         
         if(getLogger().isDebugEnabled())
-        	getLogger().debug("Getting library instance: '"+librarysource+"'");
+        	getLogger().debug("Getting library instance: '"+librarysource+"' relative to '"+relative+"'");
         
         try {
             sourceResolver = (SourceResolver)serviceManager.lookup(SourceResolver.ROLE);
-            source = sourceResolver.resolveURI(librarysource);
+            source = sourceResolver.resolveURI(librarysource, relative, null);
             
             lib = (Library)this.cacheManager.get(source, PREFIX);
             

Modified: cocoon/gsoc/mpfingsthorn/forms/samples/library/forms/form1_binding.xml
URL: http://svn.apache.org/viewcvs/cocoon/gsoc/mpfingsthorn/forms/samples/library/forms/form1_binding.xml?rev=267351&r1=267350&r2=267351&view=diff
==============================================================================
--- cocoon/gsoc/mpfingsthorn/forms/samples/library/forms/form1_binding.xml (original)
+++ cocoon/gsoc/mpfingsthorn/forms/samples/library/forms/form1_binding.xml Fri Sep  2 17:25:02
2005
@@ -19,11 +19,11 @@
   xmlns:fd="http://apache.org/cocoon/forms/1.0#definition" 
   path="/data" >
   
-  <fb:import prefix="lib" uri="libraries/library_form1_binding.xml"/>
+  <fb:import prefix="lib" uri="../libraries/library_form1-second_binding.xml"/>
   
   <fb:new id="lib:class1"/>
   
-  <fb:expand id="lib:field2"/>
-  <fb:value id="field3" path="field3" extends="lib:field2"/>
+  <fb:expand id="lib:ext:field2"/>
+  <fb:value id="field3" path="field3" extends="lib:ext:field2"/>
   
 </fb:context>

Modified: cocoon/gsoc/mpfingsthorn/forms/samples/library/forms/form1_model.xml
URL: http://svn.apache.org/viewcvs/cocoon/gsoc/mpfingsthorn/forms/samples/library/forms/form1_model.xml?rev=267351&r1=267350&r2=267351&view=diff
==============================================================================
--- cocoon/gsoc/mpfingsthorn/forms/samples/library/forms/form1_model.xml (original)
+++ cocoon/gsoc/mpfingsthorn/forms/samples/library/forms/form1_model.xml Fri Sep  2 17:25:02
2005
@@ -19,12 +19,12 @@
   xmlns:i18n="http://apache.org/cocoon/i18n/2.1">
   
   <fd:widgets>
-    <fd:import prefix="lib" uri="libraries/library_form1.xml"/>
+    <fd:import prefix="lib" uri="../libraries/library_form1-second.xml"/>
     
     <fd:new id="lib:class1"/>
-    <fd:expand id="lib:field2"/>
+    <fd:expand id="lib:ext:field2"/>
     
-    <fd:field id="field3" extends="lib:field2">
+    <fd:field id="field3" extends="lib:ext:field2">
       <fd:datatype base="integer"/>
     </fd:field>
     

Modified: cocoon/gsoc/mpfingsthorn/forms/samples/library/forms/form1_template.xml
URL: http://svn.apache.org/viewcvs/cocoon/gsoc/mpfingsthorn/forms/samples/library/forms/form1_template.xml?rev=267351&r1=267350&r2=267351&view=diff
==============================================================================
--- cocoon/gsoc/mpfingsthorn/forms/samples/library/forms/form1_template.xml (original)
+++ cocoon/gsoc/mpfingsthorn/forms/samples/library/forms/form1_template.xml Fri Sep  2 17:25:02
2005
@@ -23,6 +23,7 @@
         <fi:styling layout="columns"/>
         <fi:items>
           <ft:widget id="field1"/>
+          <ft:widget id="field1-2"/>
           <ft:widget id="field2"/>
           <ft:widget id="field3"/>
         </fi:items>

Added: cocoon/gsoc/mpfingsthorn/forms/samples/library/libraries/library_form1-second.xml
URL: http://svn.apache.org/viewcvs/cocoon/gsoc/mpfingsthorn/forms/samples/library/libraries/library_form1-second.xml?rev=267351&view=auto
==============================================================================
--- cocoon/gsoc/mpfingsthorn/forms/samples/library/libraries/library_form1-second.xml (added)
+++ cocoon/gsoc/mpfingsthorn/forms/samples/library/libraries/library_form1-second.xml Fri
Sep  2 17:25:02 2005
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<fd:library
+  xmlns:fd="http://apache.org/cocoon/forms/1.0#definition"
+  xmlns:i18n="http://apache.org/cocoon/i18n/2.1">
+  <fd:widgets>
+    
+    <fd:import prefix="ext" uri="library_form1.xml"/>
+    
+    <fd:class id="class1" extends="ext:class1">
+      <fd:widgets>
+        <fd:field id="field1-2">
+          <fd:label>Field1-2:</fd:label>
+          <fd:datatype base="string"/>
+        </fd:field>
+      </fd:widgets>
+    </fd:class>
+    
+    <fd:expand id="ext:field2"/>
+    
+  </fd:widgets>
+</fd:library>
\ No newline at end of file

Propchange: cocoon/gsoc/mpfingsthorn/forms/samples/library/libraries/library_form1-second.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/gsoc/mpfingsthorn/forms/samples/library/libraries/library_form1-second_binding.xml
URL: http://svn.apache.org/viewcvs/cocoon/gsoc/mpfingsthorn/forms/samples/library/libraries/library_form1-second_binding.xml?rev=267351&view=auto
==============================================================================
--- cocoon/gsoc/mpfingsthorn/forms/samples/library/libraries/library_form1-second_binding.xml
(added)
+++ cocoon/gsoc/mpfingsthorn/forms/samples/library/libraries/library_form1-second_binding.xml
Fri Sep  2 17:25:02 2005
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<fb:library
+  xmlns:fb="http://apache.org/cocoon/forms/1.0#binding" 
+  xmlns:fd="http://apache.org/cocoon/forms/1.0#definition" 
+  >
+  
+  <fb:import prefix="ext" uri="library_form1_binding.xml"/>
+  
+  <fb:class id="class1" extends="ext:class1">
+    <fb:value id="field1-2" path="field12"/>
+  </fb:class>
+  
+  <fb:expand id="ext:field2"/>
+  
+</fb:library>
\ No newline at end of file

Propchange: cocoon/gsoc/mpfingsthorn/forms/samples/library/libraries/library_form1-second_binding.xml
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message