1 18 19 package sync4j.server.engine.dm; 20 21 import java.util.logging.Logger ; 22 import java.util.logging.Level ; 23 24 import org.apache.commons.lang.StringUtils; 25 26 import sync4j.framework.tools.beans.*; 27 28 import sync4j.framework.logging.Sync4jLogger; 29 import sync4j.framework.logging.Sync4jLoggerName; 30 import sync4j.framework.config.Configuration; 31 import sync4j.framework.config.ConfigurationConstants; 32 import sync4j.framework.server.dm.ProcessorSelector; 33 import sync4j.framework.engine.dm.ManagementProcessor; 34 import sync4j.framework.engine.dm.DeviceDMState; 35 import sync4j.framework.core.dm.ddf.DevInfo; 36 37 55 public class OperationProcessorSelector 56 implements ProcessorSelector, LazyInitBean, ConfigurationConstants { 57 58 60 private transient Logger log; 61 62 64 67 private String defaultProcessor; 68 69 74 public void setDefaultProcessor(String defaultProcessor) { 75 this.defaultProcessor = defaultProcessor; 76 } 77 78 83 public String getDefaultProcessor() { 84 return this.defaultProcessor; 85 } 86 87 90 private String errorProcessor; 91 92 97 public void setErrorProcessor(String errorProcessor) { 98 this.errorProcessor = errorProcessor; 99 } 100 101 106 public String getErrorProcessor() { 107 return this.errorProcessor; 108 } 109 110 113 private String namePrefix; 114 115 120 public void setNamePrefix(String namePrefix) { 121 this.namePrefix = namePrefix; 122 } 123 124 129 public String getNamePrefix() { 130 return namePrefix; 131 } 132 133 136 private String namePostfix; 137 138 143 public void setNamePostfix(String namePostfix) { 144 this.namePostfix = namePostfix; 145 } 146 147 152 public String getNamePostfix() { 153 return namePostfix; 154 } 155 156 157 159 162 public OperationProcessorSelector() { 163 log = Sync4jLogger.getLogger(Sync4jLoggerName.ENGINE); 164 } 165 166 170 public ManagementProcessor getProcessor(DeviceDMState dms, DevInfo devInfo) { 171 String processorName = null; 172 173 if (log.isLoggable(Level.FINE)) { 174 log.fine("dms: " + dms); 175 } 176 177 if (dms.state == DeviceDMState.STATE_ERROR) { 178 processorName = errorProcessor; 179 } else { 180 if (StringUtils.isEmpty(dms.operation)) { 181 processorName = defaultProcessor; 182 } else { 183 processorName = namePrefix + dms.operation + namePostfix; 184 } 185 } 186 187 if (log.isLoggable(Level.FINE)) { 188 log.fine("Selected processor: " + processorName); 189 } 190 191 try { 192 return (ManagementProcessor) 193 Configuration.getConfiguration().getBeanInstanceByName(processorName); 194 } catch (Exception e){ 195 if (log.isLoggable(Level.SEVERE)) { 196 log.severe("Error creating the management processor: " + e.getMessage()); 197 log.throwing(getClass().getName(), "getProcessor", e); 198 } 199 } 200 201 return null; 202 } 203 204 211 public void init() throws BeanInitializationException { 212 if (StringUtils.isEmpty(defaultProcessor)) { 213 throw new BeanInitializationException("Missing mandatory parameter defaultProcessor"); 214 } 215 216 if (StringUtils.isEmpty(namePrefix)) { 217 namePrefix = ""; 218 } 219 220 if (StringUtils.isEmpty(namePostfix)) { 221 namePostfix = ""; 222 } 223 } 224 225 227 } | Popular Tags |