1 18 19 20 package org.apache.struts.tiles.xmlDefinition; 21 22 import java.util.Iterator ; 23 24 import org.apache.commons.logging.Log; 25 import org.apache.commons.logging.LogFactory; 26 import org.apache.struts.tiles.ComponentDefinition; 27 import org.apache.struts.tiles.NoSuchDefinitionException; 28 29 32 public class XmlDefinition extends ComponentDefinition 33 { 34 37 private String inherit; 38 39 40 protected static Log log = LogFactory.getLog(XmlDefinition.class); 41 42 45 private boolean isVisited=false; 46 47 48 51 public XmlDefinition() 52 { 53 super(); 54 } 57 58 63 public void addAttribute( XmlAttribute attribute) 64 { 65 putAttribute( attribute.getName(), attribute.getValue() ); 66 } 67 68 73 public void setExtends(String name) 74 { 75 inherit = name; 76 } 77 78 83 public String getExtends() 84 { 85 return inherit; 86 } 87 88 92 public boolean isExtending( ) 93 { 94 return inherit!=null; 95 } 96 97 101 public void setIsVisited( boolean isVisited ) 102 { 103 this.isVisited = isVisited; 104 } 105 106 113 public void resolveInheritance( XmlDefinitionsSet definitionsSet ) 114 throws NoSuchDefinitionException 115 { 116 if( isVisited || !isExtending() ) 118 return; 119 120 if(log.isDebugEnabled()) 121 log.debug( "Resolve definition for child name='" + getName() 122 + "' extends='" + getExtends() + "'."); 123 124 setIsVisited( true ); 126 127 XmlDefinition parent = definitionsSet.getDefinition( getExtends() ); 129 if( parent == null ) 130 { String msg = "Error while resolving definition inheritance: child '" 132 + getName() + "' can't find its ancestor '" 133 + getExtends() + "'. Please check your description file."; 134 log.error( msg ); 135 throw new NoSuchDefinitionException( msg ); 137 } 138 139 parent.resolveInheritance( definitionsSet ); 140 141 Iterator parentAttributes = parent.getAttributes().keySet().iterator(); 143 while( parentAttributes.hasNext() ) 144 { 145 String name = (String )parentAttributes.next(); 146 if( !getAttributes().containsKey(name) ) 147 putAttribute( name, parent.getAttribute(name) ); 148 } 149 if( path == null ) 151 setPath( parent.getPath() ); 152 if( role == null ) 153 setRole( parent.getRole() ); 154 if( controller==null ) 155 { 156 setController( parent.getController()); 157 setControllerType( parent.getControllerType()); 158 } 159 } 160 161 168 public void overload( XmlDefinition child ) 169 { 170 if( child.getPath() != null ) 171 { 172 path = child.getPath(); 173 } 174 if( child.getExtends() != null ) 175 { 176 inherit = child.getExtends(); 177 } 178 if( child.getRole() != null ) 179 { 180 role = child.getRole(); 181 } 182 if( child.getController()!=null ) 183 { 184 controller = child.getController(); 185 controllerType = child.getControllerType(); 186 } 187 attributes.putAll( child.getAttributes()); 189 } 190 } 191 | Popular Tags |