001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package com.tc.object.config;
005:
006: import java.util.ArrayList;
007: import java.util.HashMap;
008: import java.util.HashSet;
009: import java.util.Iterator;
010: import java.util.List;
011: import java.util.Map;
012: import java.util.Set;
013:
014: public class StandardDSOSpringConfigHelper implements
015: DSOSpringConfigHelper {
016: private String rootName;
017: private boolean locationInfoEnabled = false;
018: private boolean fastProxyEnabled = false;
019:
020: private final List applicationNamePatterns = new ArrayList();
021: private final List configPatterns = new ArrayList();
022: private final List distributedEvents = new ArrayList();
023:
024: public boolean isLocationInfoEnabled() {
025: return locationInfoEnabled;
026: }
027:
028: public String getRootName() {
029: return rootName;
030: }
031:
032: public void setRootName(String rootName) {
033: this .rootName = rootName;
034: }
035:
036: public void setLocationInfoEnabled(boolean locationInfoEnabled) {
037: this .locationInfoEnabled = locationInfoEnabled;
038: }
039:
040: /**
041: * Map of <code>String</code> bean name to <code>Set</code> of the excluded fields.
042: */
043: private final Map beans = new HashMap();
044:
045: public boolean isMatchingApplication(String applicationName) {
046: for (Iterator it = applicationNamePatterns.iterator(); it
047: .hasNext();) {
048: if (isMatching((String) it.next(), applicationName)) {
049: return true;
050: }
051: }
052: return false;
053: }
054:
055: public boolean isMatchingConfig(String configPath) {
056: for (Iterator it = configPatterns.iterator(); it.hasNext();) {
057: if (isMatching((String) it.next(), configPath)) {
058: return true;
059: }
060: }
061: return false;
062: }
063:
064: protected boolean isMatching(String pattern, String s) {
065: if ("*".equals(pattern)) {
066: return true;
067: } else if (s == null) {
068: return false;
069: } else if (pattern.startsWith("*")) {
070: if (pattern.endsWith("*")) {
071: return s.indexOf(pattern.substring(1,
072: pattern.length() - 1)) > -1;
073: } else {
074: return s.endsWith(pattern.substring(1));
075: }
076: } else if (pattern.endsWith("*")) {
077: return s.startsWith(pattern.substring(0,
078: pattern.length() - 1));
079: }
080: return pattern.equals(s);
081: }
082:
083: public boolean isDistributedEvent(String className) {
084: for (Iterator it = distributedEvents.iterator(); it.hasNext();) {
085: String expression = (String) it.next();
086: if (isMatching(expression, className)) {
087: return true;
088: }
089: }
090: return false;
091: }
092:
093: public boolean isDistributedBean(String beanName) {
094: return this .beans.containsKey(beanName);
095: }
096:
097: public boolean isDistributedField(String beanName, String fieldName) {
098: Set excludedFields = (Set) this .beans.get(beanName);
099: return excludedFields == null
100: || !excludedFields.contains(fieldName);
101: }
102:
103: public List getDistributedEvents() {
104: return distributedEvents;
105: }
106:
107: public Map getDistributedBeans() {
108: return this .beans;
109: }
110:
111: public void addApplicationNamePattern(String pattern) {
112: this .applicationNamePatterns.add(pattern);
113: }
114:
115: public void addConfigPattern(String pattern) {
116: this .configPatterns.add(pattern);
117: }
118:
119: public void addDistributedEvent(String expression) {
120: distributedEvents.add(expression);
121: }
122:
123: public void addBean(String beanName) {
124: this .beans.put(beanName, new HashSet());
125: }
126:
127: public void excludeField(String beanName, String fieldName) {
128: Set excludedFields = (Set) this .beans.get(beanName);
129: if (excludedFields == null) {
130: excludedFields = new HashSet();
131: this .beans.put(beanName, excludedFields);
132: }
133: excludedFields.add(fieldName);
134: }
135:
136: public boolean isFastProxyEnabled() {
137: return fastProxyEnabled;
138: }
139:
140: public void setFastProxyEnabled(boolean fastProxyEnabled) {
141: this.fastProxyEnabled = fastProxyEnabled;
142: }
143:
144: }
|