1 22 package org.jboss.ejb.plugins.cmp.jdbc.metadata; 23 24 import java.util.Iterator ; 25 import java.util.HashMap ; 26 import org.jboss.deployment.DeploymentException; 27 import org.jboss.metadata.MetaData; 28 import org.w3c.dom.Element ; 29 30 36 public final class JDBCEntityCommandMetaData 37 { 38 39 41 42 private final String commandName; 43 44 45 private final Class commandClass; 46 47 48 private final HashMap attributes = new HashMap (); 49 50 51 53 57 public JDBCEntityCommandMetaData( Element element ) 58 throws DeploymentException 59 { 60 commandName = element.getAttribute( "name" ); 62 if( commandName.trim().length() < 1 ) 63 { 64 throw new DeploymentException( "entity-command element must have " 65 + " not empty name attribute" ); 66 } 67 68 String commandClassStr = element.getAttribute( "class" ); 69 if(commandClassStr != null) 70 { 71 try 72 { 73 commandClass = GetTCLAction. 74 getContextClassLoader().loadClass( commandClassStr ); 75 } catch (ClassNotFoundException e) { 76 throw new DeploymentException( "Could not load class: " 77 + commandClassStr); 78 } 79 } 80 else 81 { 82 commandClass = null; 83 } 84 85 for( Iterator iter = MetaData.getChildrenByTagName( element, "attribute" ); 87 iter.hasNext(); ) 88 { 89 Element attrEl = (Element ) iter.next(); 90 91 String attrName = attrEl.getAttribute( "name" ); 93 if( attrName == null ) 94 { 95 throw new DeploymentException( "entity-command " + commandName 96 + " has an attribute with no name" ); 97 } 98 99 String attrValue = MetaData.getElementContent( attrEl ); 101 102 attributes.put( attrName, attrValue ); 103 } 104 } 105 106 111 public JDBCEntityCommandMetaData( Element element, 112 JDBCEntityCommandMetaData defaultValues ) 113 throws DeploymentException 114 { 115 commandName = defaultValues.getCommandName(); 117 118 String commandClassStr = element.getAttribute( "class" ); 119 if( (commandClassStr != null) 120 && (commandClassStr.trim().length() > 0) ) 121 { 122 try 123 { 124 commandClass = GetTCLAction. 125 getContextClassLoader().loadClass( commandClassStr ); 126 } catch (ClassNotFoundException e) { 127 throw new DeploymentException( "Could not load class: " 128 + commandClassStr); 129 } 130 } 131 else 132 { 133 commandClass = defaultValues.getCommandClass(); 134 } 135 136 attributes.putAll( defaultValues.attributes ); 138 for( Iterator iter = MetaData.getChildrenByTagName( element, "attribute" ); 139 iter.hasNext(); ) 140 { 141 Element attrEl = (Element ) iter.next(); 142 143 String attrName = attrEl.getAttribute( "name" ); 145 if( attrName == null ) 146 { 147 throw new DeploymentException( "entity-command " + commandName 148 + " has an attribute with no name" ); 149 } 150 151 String attrValue = MetaData.getElementContent( attrEl ); 153 154 attributes.put( attrName, attrValue ); 155 } 156 } 157 158 160 163 public String getCommandName() { 164 return commandName; 165 } 166 167 170 public Class getCommandClass() { 171 return commandClass; 172 } 173 174 177 public String getAttribute( String name ) 178 { 179 return (String ) attributes.get( name ); 180 } 181 182 184 public String toString() 185 { 186 return new StringBuffer ( "[commandName=" ).append( commandName ). 187 append( ",commandClass=" ).append( commandClass ). 188 append( ",attributes=" ).append( attributes.toString() ). 189 append( "]" ).toString(); 190 } 191 } 192 | Popular Tags |