1 29 30 package com.caucho.config; 31 32 35 public abstract class BuilderProgram { 36 private NodeBuilder _nodeBuilder; 38 private ClassLoader _loader; 39 40 protected BuilderProgram() 41 { 42 this(NodeBuilder.getCurrentBuilder()); 43 } 44 45 protected BuilderProgram(NodeBuilder builder) 46 { 47 54 55 _loader = Thread.currentThread().getContextClassLoader(); 56 } 57 58 61 public void configure(Object bean) 62 throws ConfigException 63 { 64 if (NodeBuilder.getCurrentBuilder() != null) 66 configureImpl(NodeBuilder.getCurrentBuilder(), bean); 67 else 68 configureImpl(NodeBuilder.createForProgram(), bean); 69 } 70 71 public Object configure(Class type) 72 throws ConfigException 73 { 74 if (NodeBuilder.getCurrentBuilder() != null) 75 return configureImpl(NodeBuilder.getCurrentBuilder(), type); 76 else 77 return configureImpl(NodeBuilder.createForProgram(), type); 78 } 79 80 83 public void configureImpl(NodeBuilder builder, Object bean) 84 throws ConfigException 85 { 86 throw new UnsupportedOperationException (getClass().getName()); 87 } 88 89 92 protected Object configureImpl(NodeBuilder builder, Class type) 93 throws ConfigException 94 { 95 try { 96 Object bean = type.newInstance(); 97 98 configureImpl(builder, bean); 99 100 return bean; 101 } catch (RuntimeException e) { 102 throw e; 103 } catch (Exception e) { 104 throw new ConfigException(e); 105 } 106 } 107 108 public void init(Object bean) 109 throws ConfigException 110 { 111 Config.init(bean); 112 } 113 } 114 | Popular Tags |