2009/04/15 - Apache HiveMind has been retired.

For more information, please explore the Attic.

Clover coverage report - Code Coverage for hivemind-jmx release 1.2.1
Coverage timestamp: Fri Feb 10 2006 16:34:17 PST
file stats: LOC: 149   Methods: 8
NCLOC: 77   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ObjectNameBuilderImpl.java 75% 85.2% 87.5% 83.7%
coverage coverage
 1    // Copyright 2005 The Apache Software Foundation
 2    //
 3    // Licensed under the Apache License, Version 2.0 (the "License");
 4    // you may not use this file except in compliance with the License.
 5    // You may obtain a copy of the License at
 6    //
 7    // http://www.apache.org/licenses/LICENSE-2.0
 8    //
 9    // Unless required by applicable law or agreed to in writing, software
 10    // distributed under the License is distributed on an "AS IS" BASIS,
 11    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12    // See the License for the specific language governing permissions and
 13    // limitations under the License.
 14   
 15    package org.apache.hivemind.management.impl;
 16   
 17    import java.beans.PropertyEditorManager;
 18   
 19    import javax.management.MalformedObjectNameException;
 20    import javax.management.ObjectName;
 21   
 22    import org.apache.hivemind.ApplicationRuntimeException;
 23    import org.apache.hivemind.internal.ServicePoint;
 24    import org.apache.hivemind.management.ObjectNameBuilder;
 25    import org.apache.hivemind.util.IdUtils;
 26   
 27    /**
 28    * Implementation of {@link org.apache.hivemind.management.ObjectNameBuilder}. A configurable domain
 29    * is prepended to the ObjectNames. The ObjectNames include the module, extensionId and a type as
 30    * key properties. Example for a service:
 31    * HiveMind:module=hivemind,type=servicePoint,id=hivemind.Startup When using this naming Jconsole
 32    * interprets the module key as package name and id as a class name.
 33    *
 34    * @author Achim Huegen
 35    * @since 1.1
 36    */
 37    public class ObjectNameBuilderImpl implements ObjectNameBuilder
 38    {
 39    private String _domain = "hivemind";
 40   
 41    static
 42    {
 43    // Register PropertyEditor for ObjectNames. This is needed
 44    // in MBeans contributions. Since ObjectNameBuilder is injected in
 45    // MBeanRegistry, this is done just in time here
 46    // Registration should be done in a more general way,
 47    // but the concept discussed here:
 48    // http://wiki.apache.org/jakarta-hivemind/ExtendingSmartTranslator
 49    // doesn't work because MBeanRegistry is eagerly loaded.
 50  1 PropertyEditorManager.registerEditor(ObjectName.class, ObjectNameEditor.class);
 51    }
 52   
 53    /**
 54    * Creates an ObjectName from a String
 55    */
 56  22 protected ObjectName createObjectNameInstance(String name)
 57    {
 58  22 ObjectName objectName;
 59  22 try
 60    {
 61  22 objectName = new ObjectName(name);
 62    }
 63    catch (MalformedObjectNameException e)
 64    {
 65    // Should never occur
 66  0 throw new ApplicationRuntimeException(e);
 67    }
 68  22 return objectName;
 69   
 70    }
 71   
 72    /**
 73    * Creates an ObjectName from list of keys and values and prepends the domain. Maintains the
 74    * order of the keys and this distinguishes the method from the ObjectName constructor that
 75    * accepts an hashtable of keys and values. The order influences the visualization in JConsole.
 76    * Example: Hivemind:key1=value1,key2=value2
 77    */
 78  22 public ObjectName createObjectName(String[] keys, String[] values)
 79    {
 80  22 if (keys.length != values.length)
 81  0 throw new IllegalArgumentException("Arrays keys and values must have same length");
 82  22 StringBuffer sb = new StringBuffer();
 83  22 sb.append(_domain + ':');
 84  22 for (int i = 0; i < values.length; i++)
 85    {
 86  67 if (i > 0)
 87  45 sb.append(",");
 88  67 sb.append(keys[i]);
 89  67 sb.append("=");
 90  67 sb.append(values[i]);
 91    }
 92  22 return createObjectNameInstance(sb.toString());
 93    }
 94   
 95    /**
 96    * @see org.apache.hivemind.management.ObjectNameBuilder#createObjectName(java.lang.String,
 97    * java.lang.String)
 98    */
 99  21 public ObjectName createObjectName(String qualifiedId, String type)
 100    {
 101  21 String moduleId = IdUtils.extractModule(qualifiedId);
 102  21 if (moduleId == null)
 103  0 moduleId = "(default package)";
 104  21 String id = IdUtils.stripModule(qualifiedId);
 105  21 return createObjectName(moduleId, id, type);
 106    }
 107   
 108    /**
 109    * @see org.apache.hivemind.management.ObjectNameBuilder#createObjectName(java.lang.String,
 110    * java.lang.String, java.lang.String)
 111    */
 112  21 public ObjectName createObjectName(String moduleId, String id, String type)
 113    {
 114  21 return createObjectName(new String[]
 115    { "module", "type", "id" }, new String[]
 116    { moduleId, type, id });
 117    }
 118   
 119    /**
 120    * @see org.apache.hivemind.management.ObjectNameBuilder#createServiceObjectName(org.apache.hivemind.internal.ServicePoint)
 121    */
 122  11 public ObjectName createServiceObjectName(ServicePoint servicePoint)
 123    {
 124  11 return createObjectName(servicePoint.getExtensionPointId(), "service");
 125    }
 126   
 127    /**
 128    * @see org.apache.hivemind.management.ObjectNameBuilder#createServiceDecoratorName(org.apache.hivemind.internal.ServicePoint,
 129    * java.lang.String)
 130    */
 131  1 public ObjectName createServiceDecoratorName(ServicePoint servicePoint, String decoratorType)
 132    {
 133  1 return createObjectName(new String[]
 134    { "module", "type", "id", "decorator" }, new String[]
 135    { servicePoint.getModule().getModuleId(), "service",
 136    IdUtils.stripModule(servicePoint.getExtensionPointId()), decoratorType });
 137    }
 138   
 139  0 public String getDomain()
 140    {
 141  0 return _domain;
 142    }
 143   
 144  4 public void setDomain(String domain)
 145    {
 146  4 _domain = domain;
 147    }
 148   
 149    }