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