0N/A/*
2362N/A * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A * @test
0N/A * @bug 4874819
0N/A * @summary Test that MBeanInfo classes no longer throw an
0N/A * IllegalArgumentException when attribute names, operation names, and
0N/A * Java type names do not strictly follow the expected Java syntax.
0N/A * @author Daniel Fuchs
0N/A * @run clean MustBeValidCommand
0N/A * @run build MustBeValidCommand
0N/A * @run main MustBeValidCommand
0N/A */
0N/A
0N/Aimport javax.management.MBeanInfo;
0N/Aimport javax.management.MBeanAttributeInfo;
0N/Aimport javax.management.MBeanOperationInfo;
0N/Aimport javax.management.MBeanParameterInfo;
0N/Aimport javax.management.MBeanNotificationInfo;
0N/Aimport javax.management.MBeanConstructorInfo;
0N/A
0N/Apublic class MustBeValidCommand {
0N/A
0N/A private static String[][] attributes = {
0N/A { "Attribute with valid identifiers",
0N/A "validType1","validNameAtt1" },
0N/A { "Attribute with invalid type",
0N/A "invalid-type", "validNameAtt2" },
0N/A { "Attribute with invalid name", "valid.type2",
0N/A "invalid-name-att3" },
0N/A { "Attribute with invalid name and type",
0N/A "invalidtype[]","invalid.name.att4" }
0N/A };
0N/A private static String[][] constructors = {
0N/A { "Constructor with valid name",
0N/A "ValidConstructor1" },
0N/A { "Constructor with invalid name",
0N/A "invalid.Constructor2"},
0N/A { "Constructor with invalid name",
0N/A "invalid-constructor-3" },
0N/A { "Constructor with invalid name",
0N/A "invalid constructor" }
0N/A };
0N/A private static String[][] mbeanclasses = {
0N/A { "MBean with valid class name",
0N/A "ValidMBeanClass1" },
0N/A { "MBean with valid class name",
0N/A "valid.mbean.Class2" },
0N/A { "MBean with invalid class name",
0N/A "invalid.MBeanClass3[]"},
0N/A { "MBean with invalid class name",
0N/A "invalid-mbean-class-4" },
0N/A { "MBean with invalid class name",
0N/A "invalid mbean class 5" }
0N/A };
0N/A private static String[][] notificationclasses = {
0N/A { "Notification with valid class name",
0N/A "ValidNotificationClass1" },
0N/A { "Notification with valid class name",
0N/A "valid.notification.Class2" },
0N/A { "Notification with invalid class name",
0N/A "invalid.NotificationClass3[]"},
0N/A { "Notification with invalid class name",
0N/A "invalid-notification-class-4" },
0N/A { "Notification with invalid class name",
0N/A "invalid notification class 5" }
0N/A };
0N/A private static String[][] operations = {
0N/A { "Operation with valid identifiers",
0N/A "validType1","validNameOp1" },
0N/A { "Operation with invalid type",
0N/A "invalid-type", "validNameOp2" },
0N/A { "Operation with invalid name", "valid.type2",
0N/A "invalid-name-op3" },
0N/A { "Operation with invalid name and type",
0N/A "invalidtype[]","invalid.name.op4" }
0N/A };
0N/A private static String[][] parameters = {
0N/A { "Parameter with valid identifiers",
0N/A "validType1","validNamePar1" },
0N/A { "Parameter with invalid type",
0N/A "invalid-type", "validNamePar2" },
0N/A { "Parameter with invalid name", "valid.type2",
0N/A "invalid-name-par3" },
0N/A { "Parameter with invalid name and type",
0N/A "invalidtype[]","invalid.name.par4" }
0N/A };
0N/A
0N/A static private MBeanAttributeInfo[] makeAttInfos(String[][] spec) {
0N/A final MBeanAttributeInfo[] result =
0N/A new MBeanAttributeInfo[spec.length];
0N/A for (int i=0;i<result.length;i++) {
0N/A System.out.println("\tCreate an MBeanAttributeInfo: " +
0N/A spec[i][0]);
0N/A final MBeanAttributeInfo item =
0N/A new MBeanAttributeInfo(spec[i][2],spec[i][1],spec[i][0],
0N/A true,true,false);
0N/A result[i]=item;
0N/A }
0N/A return result;
0N/A }
0N/A
0N/A static private MBeanParameterInfo[] makeParInfos(String[][] spec) {
0N/A final MBeanParameterInfo[] result =
0N/A new MBeanParameterInfo[spec.length];
0N/A for (int i=0;i<result.length;i++) {
0N/A System.out.println("\tCreate an MBeanParameterInfo: " +
0N/A spec[i][0]);
0N/A final MBeanParameterInfo item =
0N/A new MBeanParameterInfo(spec[i][2],spec[i][1],spec[i][0]);
0N/A result[i]=item;
0N/A }
0N/A return result;
0N/A }
0N/A
0N/A static private MBeanOperationInfo[] makeOpInfos(String[][] spec) {
0N/A final MBeanOperationInfo[] result =
0N/A new MBeanOperationInfo[spec.length];
0N/A final MBeanParameterInfo[] pars = makeParInfos(parameters);
0N/A for (int i=0;i<result.length;i++) {
0N/A System.out.println("\tCreate an MBeanOperationInfo: " +
0N/A spec[i][0]);
0N/A final MBeanOperationInfo item =
0N/A new MBeanOperationInfo(spec[i][2],spec[i][0],pars,spec[i][1],
0N/A MBeanOperationInfo.ACTION_INFO);
0N/A result[i]=item;
0N/A }
0N/A return result;
0N/A }
0N/A
0N/A static private MBeanConstructorInfo[] makeCtorInfos(String[][] spec) {
0N/A final MBeanConstructorInfo[] result =
0N/A new MBeanConstructorInfo[spec.length];
0N/A final MBeanParameterInfo[] pars = makeParInfos(parameters);
0N/A for (int i=0;i<result.length;i++) {
0N/A System.out.println("\tCreate an MBeanConstructorInfo: " +
0N/A spec[i][0]);
0N/A final MBeanConstructorInfo item =
0N/A new MBeanConstructorInfo(spec[i][1],spec[i][0],pars);
0N/A result[i]=item;
0N/A }
0N/A return result;
0N/A }
0N/A
0N/A static private MBeanNotificationInfo[] makeNotifInfos(String[][] spec) {
0N/A final MBeanNotificationInfo[] result =
0N/A new MBeanNotificationInfo[spec.length];
0N/A final String[] types = {"valid.type","invalid-type"};
0N/A for (int i=0;i<result.length;i++) {
0N/A System.out.println("\tCreate an MBeanNotificationInfo: " +
0N/A spec[i][0]);
0N/A final MBeanNotificationInfo item =
0N/A new MBeanNotificationInfo(types,spec[i][1],spec[i][0]);
0N/A result[i]=item;
0N/A }
0N/A return result;
0N/A }
0N/A
0N/A public static void main(String[] args) throws Exception {
0N/A // Instantiate the MBean server
0N/A //
0N/A final MBeanAttributeInfo[] atts = makeAttInfos(attributes);
0N/A final MBeanConstructorInfo[] ctors = makeCtorInfos(constructors);
0N/A final MBeanOperationInfo[] ops = makeOpInfos(operations);
0N/A final MBeanNotificationInfo[] notifs =
0N/A makeNotifInfos(notificationclasses);
0N/A
0N/A for (int i=0; i<mbeanclasses.length;i++) {
0N/A System.out.println("Create an MBeanInfo: " + mbeanclasses[i][0]);
0N/A final MBeanInfo mbi =
0N/A new MBeanInfo(mbeanclasses[i][1],mbeanclasses[i][0],
0N/A atts, ctors, ops, notifs);
0N/A }
0N/A
0N/A // Test OK!
0N/A //
0N/A System.out.println("All MBeanInfo successfuly created!");
0N/A System.out.println("Bye! Bye!");
0N/A }
0N/A}