1 package org.sapia.soto.aop; 2 3 import org.sapia.soto.ConfigurationException; 4 5 import org.sapia.util.xml.confix.ObjectHandlerIF; 6 7 8 18 public class AdviceDef implements ObjectHandlerIF { 19 private String _clazz; 20 private String _id; 21 private Advice _instance; 22 23 26 public AdviceDef() { 27 super(); 28 } 29 30 35 public void setClass(String clazz) { 36 _clazz = clazz; 37 } 38 39 44 public void setId(String id) { 45 _id = id; 46 } 47 48 53 public String getId() { 54 return _id; 55 } 56 57 62 public Advice getInstance() throws ConfigurationException { 63 if (_instance != null) { 64 return _instance; 65 } 66 67 if (_clazz == null) { 68 if (_id != null) { 69 throw new ConfigurationException( 70 "'class' attribute not specified on advice definition"); 71 } else { 72 throw new ConfigurationException( 73 "'class' attribute not specified on advice definition: " + _id); 74 } 75 } 76 77 try { 78 return _instance = (Advice) Class.forName(_clazz).newInstance(); 79 } catch (ClassNotFoundException e) { 80 throw new ConfigurationException("Could not find advice class", e); 81 } catch (IllegalAccessException e) { 82 throw new ConfigurationException( 83 "Could not access constructor for security reasons; does the advice class " + 84 _clazz + " has a public constructor?", e); 85 } catch (InstantiationException e) { 86 throw new ConfigurationException("Could not instantiate advice class", e); 87 } 88 } 89 90 public void setAdvice(Advice advice) 91 throws org.sapia.util.xml.confix.ConfigurationException { 92 if (_instance == null) { 93 _instance = (Advice) advice; 94 } else { 95 throw new org.sapia.util.xml.confix.ConfigurationException( 96 "Advice instance already specified"); 97 } 98 99 _instance = advice; 100 } 101 102 105 public void handleObject(String name, Object obj) 106 throws org.sapia.util.xml.confix.ConfigurationException { 107 if (obj instanceof Advice) { 108 setAdvice((Advice) obj); 109 } else { 110 throw new org.sapia.util.xml.confix.ConfigurationException( 111 "element 'name' does not correspond to and Advice instance"); 112 } 113 } 114 } 115 | Popular Tags |