1 4 package com.tc.object.config; 5 6 import java.util.ArrayList ; 7 import java.util.HashMap ; 8 import java.util.HashSet ; 9 import java.util.Iterator ; 10 import java.util.List ; 11 import java.util.Map ; 12 import java.util.Set ; 13 14 public class StandardDSOSpringConfigHelper implements DSOSpringConfigHelper { 15 private String rootName; 16 private boolean locationInfoEnabled = false; 17 private boolean fastProxyEnabled = false; 18 19 private final List applicationNamePatterns = new ArrayList (); 20 private final List configPatterns = new ArrayList (); 21 private final List distributedEvents = new ArrayList (); 22 23 public boolean isLocationInfoEnabled() { 24 return locationInfoEnabled; 25 } 26 27 public String getRootName() { 28 return rootName; 29 } 30 31 public void setRootName(String rootName) { 32 this.rootName = rootName; 33 } 34 35 public void setLocationInfoEnabled(boolean locationInfoEnabled) { 36 this.locationInfoEnabled = locationInfoEnabled; 37 } 38 39 42 private final Map beans = new HashMap (); 43 44 public boolean isMatchingApplication(String applicationName) { 45 for (Iterator it = applicationNamePatterns.iterator(); it.hasNext();) { 46 if (isMatching((String ) it.next(), applicationName)) { return true; } 47 } 48 return false; 49 } 50 51 public boolean isMatchingConfig(String configPath) { 52 for (Iterator it = configPatterns.iterator(); it.hasNext();) { 53 if (isMatching((String ) it.next(), configPath)) { return true; } 54 } 55 return false; 56 } 57 58 protected boolean isMatching(String pattern, String s) { 59 if ("*".equals(pattern)) { 60 return true; 61 } else if (s == null) { 62 return false; 63 } else if (pattern.startsWith("*")) { 64 if (pattern.endsWith("*")) { 65 return s.indexOf(pattern.substring(1, pattern.length() - 1)) > -1; 66 } else { 67 return s.endsWith(pattern.substring(1)); 68 } 69 } else if (pattern.endsWith("*")) { return s.startsWith(pattern.substring(0, pattern.length() - 1)); } 70 return pattern.equals(s); 71 } 72 73 public boolean isDistributedEvent(String className) { 74 for (Iterator it = distributedEvents.iterator(); it.hasNext();) { 75 String expression = (String ) it.next(); 76 if (isMatching(expression, className)) { return true; } 77 } 78 return false; 79 } 80 81 public boolean isDistributedBean(String beanName) { 82 return this.beans.containsKey(beanName); 83 } 84 85 public boolean isDistributedField(String beanName, String fieldName) { 86 Set excludedFields = (Set ) this.beans.get(beanName); 87 return excludedFields == null || !excludedFields.contains(fieldName); 88 } 89 90 public List getDistributedEvents() { 91 return distributedEvents; 92 } 93 94 public Map getDistributedBeans() { 95 return this.beans; 96 } 97 98 public void addApplicationNamePattern(String pattern) { 99 this.applicationNamePatterns.add(pattern); 100 } 101 102 public void addConfigPattern(String pattern) { 103 this.configPatterns.add(pattern); 104 } 105 106 public void addDistributedEvent(String expression) { 107 distributedEvents.add(expression); 108 } 109 110 public void addBean(String beanName) { 111 this.beans.put(beanName, new HashSet ()); 112 } 113 114 public void excludeField(String beanName, String fieldName) { 115 Set excludedFields = (Set ) this.beans.get(beanName); 116 if (excludedFields == null) { 117 excludedFields = new HashSet (); 118 this.beans.put(beanName, excludedFields); 119 } 120 excludedFields.add(fieldName); 121 } 122 123 public boolean isFastProxyEnabled() { 124 return fastProxyEnabled; 125 } 126 127 public void setFastProxyEnabled(boolean fastProxyEnabled) { 128 this.fastProxyEnabled = fastProxyEnabled; 129 } 130 131 } 132 | Popular Tags |