Source Code Cross Referenced for JSR77ManagementIdentifier.java in  » J2EE » ow2-easybeans » org » ow2 » easybeans » jsr77 » 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 » J2EE » ow2 easybeans » org.ow2.easybeans.jsr77 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * EasyBeans
003:         * Copyright (C) 2006 Bull S.A.S.
004:         * Contact: easybeans@ow2.org
005:         *
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2.1 of the License, or any later version.
010:         *
011:         * This library is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
019:         * USA
020:         *
021:         * --------------------------------------------------------------------------
022:         * $Id: JSR77ManagementIdentifier.java 1970 2007-10-16 11:49:25Z benoitf $
023:         * --------------------------------------------------------------------------
024:         */package org.ow2.easybeans.jsr77;
025:
026:        import java.net.URL;
027:        import java.util.Hashtable;
028:        import java.util.Iterator;
029:
030:        import javax.management.MalformedObjectNameException;
031:        import javax.management.ObjectName;
032:
033:        import org.ow2.easybeans.api.jmx.EZBManagementIdentifier;
034:        import org.ow2.util.log.Log;
035:        import org.ow2.util.log.LogFactory;
036:
037:        /**
038:         * Specialized {@link EZBManagementIdentifier} for JSR77 MBeans.
039:         * @author Guillaume Sauthier
040:         * @author Florent BENOIT
041:         * @param <T> Managed Type
042:         */
043:        public abstract class JSR77ManagementIdentifier<T> implements 
044:                EZBManagementIdentifier<T> {
045:
046:            /**
047:             * Default domain name.
048:             */
049:            private static final String DEFAULT_DOMAIN_NAME = "";
050:
051:            /**
052:             * Logger.
053:             */
054:            private static Log logger = LogFactory
055:                    .getLog(JSR77ManagementIdentifier.class);
056:
057:            /**
058:             * Domain name.
059:             */
060:            private String domainName = null;
061:
062:            /**
063:             * Server name.
064:             */
065:            private String serverName = null;
066:
067:            /**
068:             * Empty default constructor.
069:             */
070:            protected JSR77ManagementIdentifier() {
071:            }
072:
073:            /**
074:             * @param name base ObjectName
075:             * @return Returns a String that contains "inherited" properties from
076:             *         parent's ObjectName
077:             */
078:            @SuppressWarnings("unchecked")
079:            protected static String getInheritedPropertiesAsString(
080:                    final ObjectName name) {
081:                Hashtable<String, ?> table = (Hashtable<String, ?>) name
082:                        .getKeyPropertyList().clone();
083:                // we remove some attributes from the ObjectName
084:                table.remove("j2eeType");
085:                table.remove("type");
086:                table.remove("subtype");
087:                table.remove("name");
088:                StringBuffer sb = new StringBuffer();
089:                Iterator<String> it = table.keySet().iterator();
090:                while (it.hasNext()) {
091:                    String key = it.next();
092:                    sb.append(key + "=" + table.get(key) + ",");
093:                }
094:                if (sb.length() > 1) {
095:                    // remove the trailing comma
096:                    sb.setLength(sb.length() - 1);
097:                }
098:                return sb.toString();
099:            }
100:
101:            /**
102:             * @param parentObjectName Parent ObjectName.
103:             * @return Returns the couple j2eetype=name of the parent ObjectName.
104:             */
105:            protected static String getParentNameProperty(
106:                    final String parentObjectName) {
107:                ObjectName on = null;
108:                try {
109:                    on = ObjectName.getInstance(parentObjectName);
110:                } catch (MalformedObjectNameException e) {
111:                    logger.error("Cannot get objectname on {0}",
112:                            parentObjectName, e);
113:                    return "";
114:                } catch (NullPointerException e) {
115:                    logger.error("Cannot get objectname on {0}",
116:                            parentObjectName, e);
117:                    return "";
118:                }
119:
120:                String type = on.getKeyProperty("j2eeType");
121:                String name = on.getKeyProperty("name");
122:
123:                return type + "=" + name;
124:            }
125:
126:            /**
127:             * @param objectName given ObjectName.
128:             * @return the coupe property=value with value which is the value stored in the objectName
129:             */
130:            protected static String getPropertyNameValue(
131:                    final String objectName, final String property) {
132:                ObjectName on = null;
133:                try {
134:                    on = ObjectName.getInstance(objectName);
135:                } catch (MalformedObjectNameException e) {
136:                    logger.error("Cannot get objectname on {0}", objectName, e);
137:                    return "";
138:                } catch (NullPointerException e) {
139:                    logger.error("Cannot get objectname on {0}", objectName, e);
140:                    return "";
141:                }
142:
143:                String value = on.getKeyProperty(property);
144:                return property + "=" + value;
145:            }
146:
147:            /**
148:             * @return Returns the JMX Domain name of the MBean.
149:             */
150:            public String getDomain() {
151:                if (domainName == null) {
152:                    return DEFAULT_DOMAIN_NAME;
153:                }
154:                return domainName;
155:            }
156:
157:            /**
158:             * Sets the domain for this identifier.
159:             * @param domainName the JMX Domain name of the MBean.
160:             */
161:            public void setDomain(final String domainName) {
162:                this .domainName = domainName;
163:            }
164:
165:            /**
166:             * @return the JMX Server name of the MBean.
167:             */
168:            public String getServerName() {
169:                return serverName;
170:            }
171:
172:            /**
173:             * Sets the Server name for this identifier.
174:             * @param serverName the JMX Server name of this MBean.
175:             */
176:            public void setServerName(final String serverName) {
177:                this .serverName = serverName;
178:            }
179:
180:            /**
181:             * {@inheritDoc}
182:             */
183:            public String getTypeName() {
184:                return "j2eeType";
185:            }
186:
187:            /**
188:             * {@inheritDoc}
189:             */
190:            public String getTypeProperty() {
191:                return getTypeName() + "=" + getTypeValue();
192:            }
193:
194:            /**
195:             * @return the logger
196:             */
197:            public static final Log getLogger() {
198:                return logger;
199:            }
200:
201:            /**
202:             * @return the String for J2EEServer.
203:             */
204:            protected String getJ2EEServerString() {
205:                return "J2EEServer=" + serverName;
206:            }
207:
208:            /**
209:             * For a given URL, make a shorter name.
210:             * @param url the given URL
211:             * @return a short name for the given URL
212:             */
213:            public String shorterName(final URL url) {
214:
215:                String urlExternalForm = url.toExternalForm();
216:
217:                // if it ends by a /, remove this last one
218:                if (urlExternalForm.charAt(urlExternalForm.length() - 1) == '/') {
219:                    urlExternalForm = urlExternalForm.substring(0,
220:                            urlExternalForm.length() - 1);
221:                }
222:
223:                // get string after the last / (all URL have this, no need to test if
224:                // there is a / character)
225:                int slashPos = urlExternalForm.lastIndexOf('/');
226:                String shortName = urlExternalForm.substring(slashPos + 1,
227:                        urlExternalForm.length());
228:                int dotPos = shortName.lastIndexOf('.');
229:                if (dotPos != -1) {
230:                    shortName = shortName.substring(0, dotPos);
231:                }
232:                return shortName;
233:            }
234:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.