1 23 24 package com.sun.enterprise.config.serverbeans.validation; 25 26 import java.util.Map ; 27 import java.util.HashMap ; 28 29 import com.sun.enterprise.config.ConfigBean; 30 import com.sun.enterprise.config.serverbeans.ElementProperty; 31 32 36 37 38 39 public abstract class PropertyHelper { 40 41 static final String ELEMENT_PROPERTY = "ElementProperty"; 42 static final String PROP_NAME_ATTRNAME = "name"; 43 static final String PROP_VALUE_ATTRNAME = "value"; 44 45 50 static public Map getPropertiesMap(ConfigBean parent) { 51 HashMap map = new HashMap (); 52 if(parent!=null) 53 { 54 ElementProperty[] props = 55 (ElementProperty[])parent.getValues(ELEMENT_PROPERTY); 56 if(props!=null) 57 { 58 for(int i=0; i<props.length; i++) 59 { 60 map.put(props[i].getName(), props[i].getValue()); 61 } 62 } 63 } 64 return map; 65 } 66 67 72 static public boolean isPropertyChanged(ValidationContext propValCtx, String name) { 73 ElementProperty prop = (ElementProperty)propValCtx.getTargetBean(); 74 if(!prop.getName().equals(name)) 75 { 76 if(!propValCtx.isUPDATE() || 78 !PROP_NAME_ATTRNAME.equals(propValCtx.name) || 79 !name.equals(propValCtx.value)) 80 { 81 return false; 83 } 84 } 85 86 Map map = getPropertiesMap(propValCtx.getParentBean()); 88 String oldValue = (String )map.get(name); 90 addChangesToPropertiesMap(propValCtx, map); 92 String newValue = (String )map.get(name); 94 if((oldValue==null && newValue==null) || 96 (oldValue!=null && oldValue.equals(newValue)) ) 97 { 98 return false; 100 } 101 return true; 102 } 103 104 108 static public Map getFuturePropertiesMap(ValidationContext propValCtx) { 109 Map map = getPropertiesMap(propValCtx.getParentBean()); 110 return addChangesToPropertiesMap(propValCtx, map); 111 } 112 113 115 static private Map addChangesToPropertiesMap(ValidationContext propValCtx, Map map) { 116 if(propValCtx.isADD() || propValCtx.isSET()) 117 { 118 ElementProperty prop = (ElementProperty)propValCtx.getTargetBean(); 119 map.put(prop.getName(), prop.getValue()); 120 } 121 else if(propValCtx.isUPDATE()) 122 { 123 ElementProperty prop = (ElementProperty)propValCtx.getTargetBean(); 124 if(PROP_NAME_ATTRNAME.equals(propValCtx.name)) 125 { 126 map.remove(prop.getName()); 128 map.put(propValCtx.value, prop.getValue()); 129 } 130 else 131 { 132 map.put(prop.getName(), propValCtx.value); 134 } 135 } 136 return map; 137 } 138 139 } 140 | Popular Tags |