| 1 34 35 36 package com.micronova.util.codec; 37 38 import java.util.*; 39 import java.util.regex.*; 40 41 import com.micronova.util.*; 42 43 public class CodecBean extends Codec 44 { 45 46 47 private static Pattern pattern; 48 49 static 50 { 51 pattern = Pattern.compile("<[?][xX][mM][lL][^?]*[?]>"); 52 } 53 54 55 56 public static Object encode(Object object) throws Exception  57 { 58 if (object != null) 59 { 60 String encoded = BeanUtil.encode(object); 61 62 object = pattern.matcher(encoded).replaceFirst(""); 63 } 64 65 return object; 66 } 67 68 69 70 public static Object decode(Object object) throws Exception  71 { 72 if (object != null) 73 { 74 String s = pattern.matcher(object.toString()).replaceFirst(""); 75 76 object = BeanUtil.decode(s); 77 } 78 79 return object; 80 } 81 82 83 84 public static Object fill(Object object, Object propertyMap) throws Exception  85 { 86 if (object != null) 87 { 88 Map map = null; 89 90 if (propertyMap instanceof Map) 91 { 92 map = (Map)propertyMap; 93 } 94 else 95 { 96 map = new NestedMap(propertyMap); 97 } 98 99 object = BeanUtil.fill(object, map); 100 } 101 102 return object; 103 } 104 105 106 107 public static Object get(Object object, Object property) throws Exception  108 { 109 if (object != null) 110 { 111 object = BeanUtil.getProperty(object, property.toString()); 112 } 113 114 return object; 115 } 116 117 118 119 public static Object getProperty(Object object, Object property) throws Exception  120 { 121 if (object != null) 122 { 123 object = BeanUtil.getBeanProperty(object, property.toString()); 124 } 125 126 return object; 127 } 128 129 130 131 public static Object set(Object object, Object property, Object value) throws Exception  132 { 133 if (object != null) 134 { 135 BeanUtil.setProperty(object, property.toString(), value); 136 } 137 138 return object; 139 } 140 141 142 143 public static Object setProperty(Object object, Object property, Object value) throws Exception  144 { 145 if (object != null) 146 { 147 BeanUtil.setBeanProperty(object, property.toString(), value); 148 } 149 150 return object; 151 } 152 153 154 155 public static Object getMap(Object object) throws Exception  156 { 157 if (object != null) 158 { 159 object = BeanUtil.getMap(object); 160 } 161 162 return object; 163 } 164 } 165 | Popular Tags |