1 package org.sapia.validator.config; 2 3 import org.sapia.util.xml.confix.CreationStatus; 4 import org.sapia.util.xml.confix.ObjectCreationException; 5 import org.sapia.util.xml.confix.ObjectFactoryIF; 6 import org.sapia.validator.Rule; 7 import org.sapia.validator.Vlad; 8 9 import java.util.*; 10 11 22 public class XmlObjectFactory implements ObjectFactoryIF { 23 private Map _defs = new HashMap(); 24 private Vlad _vlad; 25 26 29 public XmlObjectFactory(Vlad vlad) { 30 _vlad = vlad; 31 } 32 33 36 public CreationStatus newObjectFor(String prefix, String uri, 37 String localName, Object parent) 38 throws ObjectCreationException { 39 Def def = (Def) _defs.get(localName); 40 41 if (def == null) { 42 throw new ObjectCreationException("No definition for: " + prefix + ":" 43 + localName); 44 } 45 46 try { 47 Object toReturn = def.toInstance(); 48 if(toReturn instanceof Rule){ 49 ((Rule)toReturn).initName(prefix, localName); 50 } 51 return CreationStatus.create(toReturn); 52 53 } catch (ConfigException e) { 58 throw new ObjectCreationException( 59 "Could not create object from definition for: " + prefix + ":" 60 + localName, e); 61 } 62 } 63 64 67 public void registerDef(String localName, Def def) 68 throws IllegalArgumentException { 69 if (_defs.get(localName) != null) { 70 throw new IllegalArgumentException ( 71 "A definition already exists for the given name: " + localName); 72 } 73 74 _defs.put(localName, def); 75 } 76 } 77 | Popular Tags |