1 16 package org.apache.cocoon.forms.formmodel; 17 18 import java.util.Iterator ; 19 import java.util.List ; 20 import java.util.ListIterator ; 21 22 30 public class NewDefinition extends AbstractWidgetDefinition { 31 private boolean resolving; 32 private ClassDefinition classDefinition; 33 34 public NewDefinition() { 35 super(); 36 resolving = false; 37 classDefinition = null; 38 } 39 40 private ClassDefinition getClassDefinition() throws Exception { 41 FormDefinition formDefinition = getFormDefinition(); 42 WidgetDefinition classDefinition = formDefinition.getWidgetDefinition(getId()); 43 44 if (classDefinition == null) classDefinition = formDefinition.getLocalLibrary().getDefinition(getId()); 46 47 if (classDefinition == null) 48 throw new Exception ("NewDefinition: Class with id \"" + getId() + "\" does not exist (" + getLocation() + ")"); 49 if (!(classDefinition instanceof ClassDefinition)) 50 throw new Exception ("NewDefinition: Id \"" + getId() + "\" is not a class (" + getLocation() + ")"); 51 return (ClassDefinition)classDefinition; 52 } 53 54 public void resolve(List parents, WidgetDefinition parent) throws Exception { 56 if (resolving) { 58 ListIterator parentsIt = parents.listIterator(parents.size()); 60 while(parentsIt.hasPrevious()) { 61 WidgetDefinition definition = (WidgetDefinition)parentsIt.previous(); 62 if (definition instanceof UnionDefinition) break; 63 if (definition == this) 64 throw new Exception ("NewDefinition: Non-terminating recursion detected in widget definition : " 65 + parent.getId() + " (" + getLocation() + ")"); 66 } 67 } 68 resolving = true; 70 parents.add(this); 71 classDefinition = getClassDefinition(); 72 Iterator definitionsIt = classDefinition.getWidgetDefinitions().iterator(); 73 parents.add(this); 74 while (definitionsIt.hasNext()) { 75 WidgetDefinition definition = (WidgetDefinition)definitionsIt.next(); 76 if (definition instanceof ContainerDefinition) { 78 ((ContainerDefinition)definition).resolve(parents, parent); 79 } 80 81 if (definition instanceof NewDefinition) { 83 ((NewDefinition)definition).resolve(parents, parent); 84 } else { 85 ((ContainerDefinition)parent).addWidgetDefinition(definition); 86 } 87 } 88 parents.remove(parents.size()-1); 89 resolving = false; 90 } 91 92 public Widget createInstance() { 93 return null; 94 } 95 } 96 | Popular Tags |