All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.glassfish.admin.runtime.jsr77.WebModuleMB Maven / Gradle / Ivy

There is a newer version: 4.1.2.181
Show newest version
/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright (c) 2008-2010 Oracle and/or its affiliates. All rights reserved.
 *
 * The contents of this file are subject to the terms of either the GNU
 * General Public License Version 2 only ("GPL") or the Common Development
 * and Distribution License("CDDL") (collectively, the "License").  You
 * may not use this file except in compliance with the License.  You can
 * obtain a copy of the License at
 * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
 * or packager/legal/LICENSE.txt.  See the License for the specific
 * language governing permissions and limitations under the License.
 *
 * When distributing the software, include this License Header Notice in each
 * file and include the License file at packager/legal/LICENSE.txt.
 *
 * GPL Classpath Exception:
 * Oracle designates this particular file as subject to the "Classpath"
 * exception as provided by Oracle in the GPL Version 2 section of the License
 * file that accompanied this code.
 *
 * Modifications:
 * If applicable, add the following below the License Header, with the fields
 * enclosed by brackets [] replaced by your own identifying information:
 * "Portions Copyright [year] [name of copyright owner]"
 *
 * Contributor(s):
 * If you wish your version of this file to be governed by only the CDDL or
 * only the GPL Version 2, indicate your decision by adding "[Contributor]
 * elects to include this software in this distribution under the [CDDL or GPL
 * Version 2] license."  If you don't indicate a single choice of license, a
 * recipient has the option to distribute your version of this file under
 * either the CDDL, the GPL Version 2 or to extend the choice of license to
 * its licensees as provided above.  However, if you add GPL Version 2 code
 * and therefore, elected the GPL Version 2 license, then the option applies
 * only if the new code is made subject to such option by the copyright
 * holder.
 */

package org.glassfish.admin.runtime.jsr77;

import java.lang.reflect.Constructor;
import java.util.Iterator;
import javax.management.*;

/**
 * Dynamic MBean for managing web module
 */

public class WebModuleMB extends WebModuleMdl implements DynamicMBean {

    private String className = this.getClass().getName();
    private String description = "Web Module MBean";

    private MBeanAttributeInfo[] mbAttrInfoArr = new MBeanAttributeInfo[16];
    private MBeanConstructorInfo[] mbConstrInfoArr = new MBeanConstructorInfo[1];
    private MBeanOperationInfo[] mbOpInfoArr = new MBeanOperationInfo[3];
    private MBeanInfo mbInfo = null;

    public WebModuleMB(String name,boolean state, boolean statistics) {
        // FIXME
        super(name,state,statistics);
	buildMBeanInfo();
    }

    public Object getAttribute(String attribute_name) 
	throws AttributeNotFoundException,
	       MBeanException,
	       ReflectionException {

	// Check attribute_name is not null to avoid NullPointerException later on
	if (attribute_name == null) {
	    throw new RuntimeOperationsException(
                new IllegalArgumentException("Attribute name cannot be null"), 
		"Cannot invoke a getter of " + className + " with null attribute name");
	}

	// Check for a recognized attribute_name and call the corresponding getter
	if (attribute_name.equals("J2EEApplication")) {
	    return getJ2EEApplication();
	} 
	if (attribute_name.equals("J2EEServer")) {
	    return getJ2EEServer();
	} 
	if (attribute_name.equals("ModuleName")) {
	    return getModuleName();
	} 
	if (attribute_name.equals("deploymentDescriptor")) {
	    return getdeploymentDescriptor();
	} 
	if (attribute_name.equals("servlets")) {
	    return getservlets();
	} 
	if (attribute_name.equals("eventProvider")) {
	    return iseventProvider();
	} 
	if (attribute_name.equals("eventTypes")) {
	    return geteventTypes();
	} 
	if (attribute_name.equals("j2eeType")) {
	    return getj2eeType();
	} 
	if (attribute_name.equals("javaVMs")) {
	    return getjavaVMs();
	} 
	if (attribute_name.equals("name")) {
	    return getname();
	} 
	if (attribute_name.equals("objectName")) {
	    return getobjectName();
	} 
	if (attribute_name.equals("server")) {
	    return getserver();
	} 
	if (attribute_name.equals("startTime")) {
	    return getstartTime();
	} 
	if (attribute_name.equals("state")) {
	    return getstate();
	}
	if (attribute_name.equals("stateManageable")) {
	    return isstateManageable();
	}
	if (attribute_name.equals("statisticsProvider")) {
	    return isstatisticsProvider();
	}

	// If attribute_name has not been recognized throw an AttributeNotFoundException
	throw(new AttributeNotFoundException(
            "Cannot find " + attribute_name + " attribute in " + className));
    }

    /**
     * Sets the value of the specified attribute of the Dynamic MBean.
     */
    public void setAttribute(Attribute attribute) 
	throws AttributeNotFoundException,
	       InvalidAttributeValueException,
	       MBeanException, 
	       ReflectionException {

	// Check attribute is not null to avoid NullPointerException later on
	if (attribute == null) {
	    throw new RuntimeOperationsException(
            new IllegalArgumentException("Attribute cannot be null"), 
	    "Cannot invoke a setter of " + className + " with null attribute");
	}
	String name = attribute.getName();
	Object value = attribute.getValue();

	if (name == null) {
	    throw new RuntimeOperationsException(
                new IllegalArgumentException("Attribute name cannot be null"), 
		"Cannot invoke the setter of " + className + " with null attribute name");
	}

	// Check for a recognized attribute_name and call the corresponding getter
	if (name.equals("state")) {
	    setstate((java.lang.Integer)value);
	} else {
	    throw(new AttributeNotFoundException("Attribute " + name +
	        " not found in " + this.getClass().getName()));
	}
    }

    public AttributeList getAttributes(String[] attributeNames) {

	// Check attributeNames is not null to avoid NullPointerException later on
	if (attributeNames == null) {
	    throw new RuntimeOperationsException(
                new IllegalArgumentException("attributeNames[] cannot be null"),
	        "Cannot invoke a getter of " + className);
	}
	AttributeList resultList = new AttributeList();

	// if attributeNames is empty, return an empty result list
	if (attributeNames.length == 0)
	    return resultList;
        
	// build the result attribute list
	for (int i=0 ; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy