FileDocCategorySizeDatePackage
ServiceConfigHelper.javaAPI DocGlassfish v2 API7717Fri May 04 22:34:40 BST 2007com.sun.enterprise.diagnostics

ServiceConfigHelper

public class ServiceConfigHelper extends Object
Helper which helps reading diagnostic service config elements from domain.xml either from runtime MBeans or by loading the document in local mode.
author
Manisha Umbarje

Fields Summary
private Element
configElement
private Element
diagnosticElement
private com.sun.enterprise.diagnostics.collect.DomainXMLHelper
xmlHelper
private boolean
local
private String
configName
private String
repositoryDir
private String
instanceName
private static String
envInstanceRootVar
private static Logger
logger
Constructors Summary
public ServiceConfigHelper(String instanceName)


       
        this.instanceName = instanceName;
    
public ServiceConfigHelper(String repositoryDir, String instanceName, boolean local)

	this.repositoryDir = repositoryDir;
        this.instanceName = instanceName;
	this.local = local;
        
    
Methods Summary
private java.lang.StringdetermineLogFile(java.lang.String logFileName)
Computes absolute path to log file from log-service/file attribute.

param
logFileName log-service/file value
return
absolute path of the log file.

        if(logFileName.startsWith(envInstanceRootVar)) {
            int length = envInstanceRootVar.length() ;
            if(length > 0) {
                String logFileSuffix = logFileName.substring(length);
                if(repositoryDir != null)
                    logFileName = repositoryDir + logFileSuffix;
                else
                    logFileName = logFileSuffix;
            }
         } 
         return logFileName;
    
public java.lang.StringgetAttribute(java.lang.String attribute)
Returns value of specified attribute from domain.xml

	if (local){
            if (diagnosticElement == null)
                initializeXMLElements();
	    return getDOMAttribute(attribute);
	}
	return getRuntimeAttribute(attribute);
    
public java.lang.StringgetConfigName()
Gets config name

return
config name

        return configName;
    
private java.lang.StringgetDOMAttribute(java.lang.String attribute)
Retrieves attribute from loaded DOM - domain.xml

return
returns value of a attribute in a local mode


	if(attribute.equals(ServerTags.FILE)) {
	    Element logElement = xmlHelper.getElement(configElement,"log-service");
	    return determineLogFile(logElement.getAttribute(ServerTags.FILE));
	}

	logger.log(Level.FINEST, "diagnostic-service.attribute_name",
                new Object[] {attribute});
	logger.log(Level.FINEST, "diagnostic-service.attribute_value",
                new Object[] {diagnosticElement.getAttribute(attribute)});

        return diagnosticElement.getAttribute(attribute);
    
private java.lang.StringgetRuntimeAttribute(java.lang.String attribute)
Retrieves value from runtime attributes

reutrn
runtime value of a attribute

	try {

            logger.log(Level.FINE, "Instance Name :" + instanceName);

            ConfigContext configContext = 
                    AdminService.getAdminService().getAdminContext().getAdminConfigContext();
            Server server = ServerHelper.getServerByName(configContext, instanceName);
            configName = server.getConfigRef();
            Config config = ConfigAPIHelper.getConfigByName(configContext, 
                    configName);
	    if(attribute.equals(ServerTags.FILE)) {
		LogService logService = config.getLogService();
                return determineLogFile(logService.getFile());
	    }
	    else {
		DiagnosticService diagService = config.getDiagnosticService();
		return diagService.getAttributeValue(attribute);
	    }
	} catch(ConfigException ce) {
	    logger.log(Level.SEVERE,
		    "diagnostic-service.error_retrieving_logFileName",
		    ce.getMessage());
	    throw new DiagnosticException(ce.getMessage());
	}

    
private voidinitializeXMLElements()
Initialize XML elements

        try {
            xmlHelper = new DomainXMLHelper(repositoryDir);
            Element element =  xmlHelper.getElement("server", instanceName);
            configName = xmlHelper.getAttribute(element, "config-ref");
            configElement = xmlHelper.getElement("config", configName);
            diagnosticElement = xmlHelper.getElement(configElement,
                                                    "diagnostic-service");
        }catch(Exception e) {
            e.printStackTrace();
            throw new DiagnosticException(e.getMessage());
        }
    
public java.lang.StringinstanceName()
Retrieves instance name

return
instance name

        return instanceName;