KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > object > config > StandardDSOSpringConfigHelper


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.object.config;
5
6 import java.util.ArrayList JavaDoc;
7 import java.util.HashMap JavaDoc;
8 import java.util.HashSet JavaDoc;
9 import java.util.Iterator JavaDoc;
10 import java.util.List JavaDoc;
11 import java.util.Map JavaDoc;
12 import java.util.Set JavaDoc;
13
14 public class StandardDSOSpringConfigHelper implements DSOSpringConfigHelper {
15   private String JavaDoc rootName;
16   private boolean locationInfoEnabled = false;
17   private boolean fastProxyEnabled = false;
18   
19   private final List JavaDoc applicationNamePatterns = new ArrayList JavaDoc();
20   private final List JavaDoc configPatterns = new ArrayList JavaDoc();
21   private final List JavaDoc distributedEvents = new ArrayList JavaDoc();
22
23   public boolean isLocationInfoEnabled() {
24     return locationInfoEnabled;
25   }
26
27   public String JavaDoc getRootName() {
28     return rootName;
29   }
30
31   public void setRootName(String JavaDoc rootName) {
32     this.rootName = rootName;
33   }
34
35   public void setLocationInfoEnabled(boolean locationInfoEnabled) {
36     this.locationInfoEnabled = locationInfoEnabled;
37   }
38   
39   /**
40    * Map of <code>String</code> bean name to <code>Set</code> of the excluded fields.
41    */

42   private final Map JavaDoc beans = new HashMap JavaDoc();
43
44   public boolean isMatchingApplication(String JavaDoc applicationName) {
45     for (Iterator JavaDoc it = applicationNamePatterns.iterator(); it.hasNext();) {
46       if (isMatching((String JavaDoc) it.next(), applicationName)) { return true; }
47     }
48     return false;
49   }
50
51   public boolean isMatchingConfig(String JavaDoc configPath) {
52     for (Iterator JavaDoc it = configPatterns.iterator(); it.hasNext();) {
53       if (isMatching((String JavaDoc) it.next(), configPath)) { return true; }
54     }
55     return false;
56   }
57
58   protected boolean isMatching(String JavaDoc pattern, String JavaDoc 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 JavaDoc className) {
74     for (Iterator JavaDoc it = distributedEvents.iterator(); it.hasNext();) {
75       String JavaDoc expression = (String JavaDoc) it.next();
76       if (isMatching(expression, className)) { return true; }
77     }
78     return false;
79   }
80
81   public boolean isDistributedBean(String JavaDoc beanName) {
82     return this.beans.containsKey(beanName);
83   }
84
85   public boolean isDistributedField(String JavaDoc beanName, String JavaDoc fieldName) {
86     Set JavaDoc excludedFields = (Set JavaDoc) this.beans.get(beanName);
87     return excludedFields == null || !excludedFields.contains(fieldName);
88   }
89
90   public List JavaDoc getDistributedEvents() {
91     return distributedEvents;
92   }
93
94   public Map JavaDoc getDistributedBeans() {
95     return this.beans;
96   }
97
98   public void addApplicationNamePattern(String JavaDoc pattern) {
99     this.applicationNamePatterns.add(pattern);
100   }
101
102   public void addConfigPattern(String JavaDoc pattern) {
103     this.configPatterns.add(pattern);
104   }
105
106   public void addDistributedEvent(String JavaDoc expression) {
107     distributedEvents.add(expression);
108   }
109
110   public void addBean(String JavaDoc beanName) {
111     this.beans.put(beanName, new HashSet JavaDoc());
112   }
113
114   public void excludeField(String JavaDoc beanName, String JavaDoc fieldName) {
115     Set JavaDoc excludedFields = (Set JavaDoc) this.beans.get(beanName);
116     if (excludedFields == null) {
117       excludedFields = new HashSet JavaDoc();
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