1 10 11 package org.mule.providers.gs.filters; 12 13 import java.lang.reflect.InvocationTargetException ; 14 import java.util.HashMap ; 15 import java.util.Iterator ; 16 import java.util.Map ; 17 18 import net.jini.core.entry.Entry; 19 20 import org.apache.commons.beanutils.BeanUtils; 21 import org.apache.commons.lang.StringUtils; 22 import org.mule.providers.gs.JiniMessage; 23 import org.mule.umo.UMOMessage; 24 import org.mule.util.ClassUtils; 25 26 29 public class JavaSpaceTemplateFilter implements JavaSpaceFilter 30 { 31 public static final String NULL_VALUE = "null"; 32 33 protected String expectedType = null; 34 protected Map fields = new HashMap (); 35 protected Entry entry = null; 36 37 public JavaSpaceTemplateFilter() 38 { 39 super(); 40 } 41 42 public JavaSpaceTemplateFilter(String expectedType) 43 { 44 setExpectedType(expectedType); 45 } 46 47 53 public boolean accept(UMOMessage message) 54 { 55 return true; 57 } 58 59 public String getExpectedType() 60 { 61 return expectedType; 62 } 63 64 public void setExpectedType(String expectedType) 65 { 66 if (NULL_VALUE.equalsIgnoreCase(expectedType) || StringUtils.isEmpty(expectedType)) 67 { 68 expectedType = null; 69 } 70 else 71 { 72 this.expectedType = expectedType; 73 } 74 } 75 76 public Map getFields() 77 { 78 return fields; 79 } 80 81 public void setFields(Map fields) 82 { 83 for (Iterator iterator = fields.entrySet().iterator(); iterator.hasNext();) 84 { 85 Map.Entry entry = (Map.Entry )iterator.next(); 86 setProperty(entry.getKey(), entry.getValue()); 87 } 88 } 89 90 public Entry getEntry() 91 throws IllegalAccessException , NoSuchMethodException , InvocationTargetException , 92 InstantiationException , ClassNotFoundException 93 { 94 95 if (entry == null) 96 { 97 if (expectedType == null) 98 { 99 return null; } 101 Object entryType = ClassUtils.instanciateClass(expectedType, ClassUtils.NO_ARGS); 102 if (!(entryType instanceof Entry)) 103 { 104 entry = new JiniMessage(null, entryType); 105 if (fields.size() > 0) 106 { 107 BeanUtils.populate(entry, fields); 109 BeanUtils.populate(((JiniMessage)entry).getPayload(), fields); 111 } 112 } 113 else 114 { 115 entry = (Entry)entryType; 116 if (fields.size() > 0) 117 { 118 BeanUtils.populate(entry, fields); 119 } 120 } 121 122 } 123 return entry; 124 } 125 126 public void setEntry(Entry entry) 127 { 128 this.entry = entry; 129 } 130 131 public Object getProperty(Object key) 133 { 134 return fields.get(key); 135 } 136 137 public void setProperty(Object key, Object value) 139 { 140 if (NULL_VALUE.equalsIgnoreCase(value.toString())) 141 { 142 fields.put(key, null); 143 } 144 else 145 { 146 fields.put(key, value); 147 } 148 } 149 150 public String toString() 151 { 152 return "Filter{" + "expectedType=" + expectedType + ", fields=" + fields + "}"; 153 } 154 } 155 | Popular Tags |