View Javadoc
1 /* 2 * Created on 2004.09.23. 3 * 4 * In p2p project 5 */ 6 7 8 package net.sf.bigyo.container.config; 9 10 import net.sf.bigyo.api.GeneratedConfig; 11 import net.sf.bigyo.api.Reconfigurable; 12 import net.sf.bigyo.container.ReconfigurationFailedException; 13 import net.sf.bigyo.container.api.Constants; 14 import net.sf.bigyo.model.ComponentConfig; 15 16 import org.apache.log4j.LogManager; 17 import org.apache.log4j.Logger; 18 19 /*** 20 * @author zsombor 21 * 22 * Created at 1:56:01 net.sf.bigyo.container.config.PreGeneratedWrapperStrategy 23 * 24 */ 25 public class PreGeneratedWrapperStrategy extends SimpleConfigurationStrategy implements ConfigurationStrategy { 26 27 final static Logger LOG = LogManager.getLogger(PreGeneratedWrapperStrategy.class); 28 29 /*** 30 * 31 */ 32 public PreGeneratedWrapperStrategy() { 33 super(); 34 // Auto-generated constructor stub 35 } 36 37 /* 38 * (non-Javadoc) 39 * 40 * @see net.sf.bigyo.container.config.ConfigurationStrategy#initConfigurationBean(java.lang.Object) 41 */ 42 public Object initConfigurationBean(Object bean) { 43 if (bean == null) { 44 LOG.info("no config bean passed."); 45 return null; 46 } 47 String className = bean.getClass().getName(); 48 try { 49 Class cls = Class.forName(Constants.getWrapperName(className)); 50 Object wrapper = cls.newInstance(); 51 if (wrapper instanceof GeneratedConfig) { 52 GeneratedConfig gc = (GeneratedConfig) wrapper; 53 gc.setWrappedObject(bean); 54 return gc; 55 } 56 57 } catch (ClassNotFoundException e) { 58 LOG.warn("not found pre-generated config wrapper for " + className, e); 59 } catch (InstantiationException e) { 60 LOG.warn("not found pre-generated config wrapper for " + className, e); 61 } catch (IllegalAccessException e) { 62 LOG.warn("not found pre-generated config wrapper for " + className, e); 63 } 64 65 return bean; 66 } 67 68 /* 69 * (non-Javadoc) 70 * 71 * @see net.sf.bigyo.container.config.ConfigurationStrategy#reconfigureService(java.lang.Object, 72 * net.sf.bigyo.container.ComponentConfig, 73 * net.sf.bigyo.container.ComponentConfig) 74 */ 75 public void reconfigureService(Object service, ComponentConfig oldConfigBean, ComponentConfig newConfigBean) 76 throws ReconfigurationFailedException, ReconfigurationNotSupportedException { 77 78 Object oldConfig = oldConfigBean.getConfigBean(); 79 if (oldConfig instanceof GeneratedConfig) { 80 GeneratedConfig oldGcConfig = (GeneratedConfig) oldConfig; 81 Object newConfig = newConfigBean.getConfigBean(); 82 if (service instanceof Reconfigurable) { 83 ((Reconfigurable) service).reconfigure(newConfig, null); 84 } else { 85 // switch the wrapped object, no notification is delivered 86 oldGcConfig.setWrappedObject(getSerializableConfigurationBean(newConfig)); 87 } 88 89 return; 90 } else { 91 // fallback to default strategy 92 super.reconfigureService(service, oldConfigBean, newConfigBean); 93 } 94 95 } 96 97 /* 98 * (non-Javadoc) 99 * 100 * @see net.sf.bigyo.container.config.ConfigurationStrategy#getSerializableConfigurationBean(java.lang.Object) 101 */ 102 public Object getSerializableConfigurationBean(Object bean) { 103 if (bean instanceof GeneratedConfig) { 104 return ((GeneratedConfig) bean).getWrappedObject(); 105 } 106 return bean; 107 } 108 109 /* 110 * (non-Javadoc) 111 * 112 * @see net.sf.bigyo.container.config.ConfigurationStrategy#isModifiedSince(net.sf.bigyo.container.ComponentConfig) 113 */ 114 public boolean isModifiedSince(ComponentConfig oldConfigBean) { 115 Object oldConfig = oldConfigBean.getConfigBean(); 116 if (oldConfig instanceof GeneratedConfig) { 117 GeneratedConfig oldGcConfig = (GeneratedConfig) oldConfig; 118 return oldGcConfig.clearModified(); 119 // modified since the last check... we should ignore the 120 // modification 121 } 122 return false; 123 } 124 }

This page was automatically generated by Maven