Source Code Cross Referenced for MBeanServerRepositoryController.java in  » JMX » jfoxmx » org » huihoo » jfox » jmx » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » JMX » jfoxmx » org.huihoo.jfox.jmx 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* JFox, the OpenSource J2EE Application Server
002:         *
003:         * Copyright (C) 2002 huihoo.com
004:         * Distributable under GNU LGPL license
005:         * See the GNU Lesser General Public License for more details.
006:         */
007:
008:        package org.huihoo.jfox.jmx;
009:
010:        import java.util.Iterator;
011:        import java.util.Set;
012:        import java.util.HashSet; //import java.util.Hashtable;
013:        //import java.util.Map;
014:        //import java.util.List;
015:        //import java.util.ArrayList;
016:
017:        import javax.management.ObjectName;
018:        import javax.management.InstanceNotFoundException;
019:        import javax.management.InstanceAlreadyExistsException;
020:        import javax.management.RuntimeOperationsException;
021:        import javax.management.MalformedObjectNameException;
022:        import javax.management.QueryExp;
023:        import javax.management.ObjectInstance;
024:        import javax.management.MBeanServer;
025:
026:        /**
027:         *
028:         * @author <a href="mailto:young_yy@hotmail.com">Young Yang</a>
029:         */
030:
031:        public class MBeanServerRepositoryController {
032:
033:            //  private List domains = new ArrayList();
034:            private MBeanServerRepository repo = new MBeanServerRepositorySupport();
035:
036:            //  private String domain;
037:
038:            private MBeanServer server = null;
039:
040:            public MBeanServerRepositoryController(MBeanServer server) {
041:                this .server = server;
042:            }
043:
044:            public String getDomain() {
045:                return server.getDefaultDomain();
046:            }
047:
048:            //  public void setDomain(String domain) {
049:            //    this.domain = domain;
050:            //    domains.add(domain);
051:            //  }
052:
053:            public MBeanMetaData retrieve(ObjectName name)
054:                    throws InstanceNotFoundException {
055:                if (name.isPattern())
056:                    throw new RuntimeOperationsException(
057:                            new IllegalArgumentException("ObjectName "
058:                                    + name.toString()
059:                                    + " is a pattern object name"));
060:                name = this .getCompleteObjectName(name);
061:                if (!contains(name))
062:                    throw new InstanceNotFoundException(name.toString());
063:                return repo.get(name);
064:            }
065:
066:            public void store(ObjectName name, MBeanMetaData metadata)
067:                    throws InstanceAlreadyExistsException {
068:                if (name.isPattern())
069:                    throw new RuntimeOperationsException(
070:                            new IllegalArgumentException("ObjectName "
071:                                    + name.toString()
072:                                    + " is a pattern object name"));
073:                name = this .getCompleteObjectName(name);
074:                if (contains(name))
075:                    throw new InstanceAlreadyExistsException(name.toString());
076:                repo.put(name, metadata);
077:            }
078:
079:            public void remove(ObjectName name)
080:                    throws InstanceNotFoundException {
081:                if (name.isPattern())
082:                    throw new RuntimeOperationsException(
083:                            new IllegalArgumentException("ObjectName "
084:                                    + name.toString()
085:                                    + " is a pattern object name"));
086:                name = this .getCompleteObjectName(name);
087:                if (!contains(name))
088:                    throw new InstanceNotFoundException(name.toString());
089:                repo.remove(name);
090:            }
091:
092:            public int getRepoSize() {
093:                return repo.size();
094:            }
095:
096:            public boolean contains(ObjectName name) {
097:                if (name.isPattern())
098:                    throw new RuntimeOperationsException(
099:                            new IllegalArgumentException("ObjectName "
100:                                    + name.toString()
101:                                    + " is a pattern object name"));
102:                name = this .getCompleteObjectName(name);
103:                return repo.contains(name);
104:            }
105:
106:            public Iterator iterator() {
107:                return repo.iterator();
108:            }
109:
110:            public Set queryMBeans(ObjectName pattern, QueryExp query) {
111:                HashSet set = new HashSet();
112:                if (pattern == null) {
113:                    try {
114:                        pattern = new ObjectName("*:*");
115:                    } catch (MalformedObjectNameException malformedobjectnameexception) {
116:                    }
117:                }
118:                pattern = getCompleteObjectName(pattern);
119:
120:                // not pattern ,single mbean
121:                if (!pattern.isPattern()) {
122:                    try {
123:                        MBeanMetaData meta = retrieve(pattern);
124:                        if (meta != null)
125:                            set.add(meta.getObjectInstance());
126:                    } catch (InstanceNotFoundException ignore) {
127:                    } catch (RuntimeOperationsException e) {
128:                        e.printStackTrace();
129:                    }
130:                } else {
131:                    //      String p_domain = pattern.getDomain();
132:                    Iterator it = this .iterator();
133:                    while (it.hasNext()) {
134:                        MBeanMetaData meta = (MBeanMetaData) it.next();
135:                        ObjectInstance instance = meta.getObjectInstance();
136:                        ObjectName objectName = instance.getObjectName();
137:                        //          String domain = objectName.getDomain();
138:                        //        if(matchDomain(domain,p_domain) && matchKeys(objectName,pattern)){ // domain & keys all matched
139:                        //          set.add(instance);
140:                        //        }
141:                        // changed from jmx1.2
142:                        try {
143:                            if (pattern.apply(objectName)) {
144:                                set.add(instance);
145:                            }
146:                        } catch (Exception e) {
147:                            e.printStackTrace();
148:                        }
149:                    }
150:                }
151:                return set;
152:
153:            }
154:
155:            /*
156:            // domain match
157:            private boolean matchDomain(String domain, String pattern) {
158:              int s_index = 0; // string index
159:              int s_length = domain.length(); // string length
160:              int p_length = pattern.length();
161:              for (int p_index = 0; p_index < p_length; ++p_index) {
162:                char c = pattern.charAt(p_index);
163:                if (c == '*') {
164:                  while (s_index < s_length) {
165:                    if (matchDomain(domain.substring(s_index),pattern.substring(p_index + 1))) return true;
166:                    s_index++;
167:                  }
168:                }
169:                else if (c == '?') {
170:                  s_index++;
171:                  if (s_index > s_length) return false;
172:                }
173:                else {
174:                  if (s_index >= s_length || c != domain.charAt(s_index)) return false;
175:                  s_index++;
176:                }
177:              }
178:              return s_index == s_length;
179:            }
180:
181:            // keys match
182:            private boolean matchKeys(ObjectName objectName, ObjectName pattern){
183:              Hashtable nameTable = objectName.getKeyPropertyList();
184:              Hashtable patternTable = pattern.getKeyPropertyList();
185:              boolean matches = true;
186:              if(!pattern.isPropertyPattern()){ // not pattern,must be equal
187:                matches = nameTable.equals(patternTable);
188:              }
189:              else{ // is pattern, so nameTable must containsAll patterTable
190:                Iterator it = patternTable.entrySet().iterator();
191:                while(it.hasNext()){
192:                  Map.Entry entry = (Map.Entry)it.next();
193:                  String key = (String)entry.getKey();
194:                  String value = (String)entry.getValue();
195:                  if(!nameTable.containsKey(key) || !nameTable.get(key).equals(value)){
196:                    matches = false;
197:                    break;
198:                  }
199:                }
200:              }
201:
202:              return matches;
203:            }
204:             */
205:
206:            ObjectName getCompleteObjectName(ObjectName objectName) {
207:                if (objectName.getDomain().trim().length() == 0) {// use defaultdomain
208:                    try {
209:                        objectName = new ObjectName(getDomain(), objectName
210:                                .getKeyPropertyList());
211:                    } catch (MalformedObjectNameException e) {
212:                        e.printStackTrace();
213:                    }
214:                }
215:                return objectName;
216:            }
217:
218:            String[] getDomains() {
219:                Set domains = new HashSet();
220:                for (Iterator iter = repo.keys().iterator(); iter.hasNext();) {
221:                    ObjectName objName = (ObjectName) iter.next();
222:                    domains.add(objName.getDomain());
223:                }
224:                return (String[]) domains.toArray(new String[0]);
225:            }
226:
227:            /*
228:                public String[] getDomains()  {
229:            /* Permission check
230:            SecurityManager sm = System.getSecurityManager();
231:            if (sm != null) {
232:                // Check if the caller has the right to invoke 'getDomains'
233:                //
234:                checkMBeanPermission(null, null, null, "getDomains");
235:
236:                // Return domains
237:                //
238:                String[] domains = repository.getDomains();
239:
240:                // Check if the caller has the right to invoke 'getDomains'
241:                // on each specific domain in the list.
242:                //
243:                ArrayList result = new ArrayList(domains.length);
244:                for (int i = 0; i < domains.length; i++) {
245:            	try {
246:            	    ObjectName domain = new ObjectName(domains[i] + ":x=x");
247:            	    checkMBeanPermission(null, null, domain, "getDomains");
248:            	    result.add(domains[i]);
249:            	} catch (MalformedObjectNameException e) {
250:            	    // Should never occur...
251:            	} catch (SecurityException e) {
252:            	    // Do not add this domain to the list
253:            	}
254:                }
255:
256:                // Make an array from result.
257:                //
258:                return (String[]) result.toArray(new String[result.size()]);
259:            } else {
260:                return repository.getDomains();
261:            }
262:              }
263:             */
264:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.