0N/A/*
2362N/A * Copyright (c) 2005, 2006, 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/Aimport java.util.Arrays;
0N/Aimport javax.management.openmbean.ArrayType;
0N/Aimport javax.management.openmbean.CompositeData;
0N/Aimport javax.management.openmbean.CompositeDataSupport;
0N/Aimport javax.management.openmbean.CompositeDataView;
0N/Aimport javax.management.openmbean.CompositeType;
0N/Aimport javax.management.openmbean.OpenDataException;
0N/Aimport javax.management.openmbean.OpenType;
0N/Aimport javax.management.openmbean.SimpleType;
0N/A
0N/Apublic interface MerlinMXBean {
0N/A
0N/A int PInt = 59;
0N/A SimpleType PIntType = SimpleType.INTEGER;
0N/A int getPInt();
0N/A void setPInt(int x);
0N/A int opPInt(int x, int y);
0N/A
0N/A long PLong = Long.MAX_VALUE;
0N/A SimpleType PLongType = SimpleType.LONG;
0N/A long getPLong();
0N/A void setPLong(long x);
0N/A long opPLong(long x, long y);
0N/A
0N/A short PShort = 55;
0N/A SimpleType PShortType = SimpleType.SHORT;
0N/A short getPShort();
0N/A void setPShort(short x);
0N/A short opPShort(short x, short y);
0N/A
0N/A byte PByte = 13;
0N/A SimpleType PByteType = SimpleType.BYTE;
0N/A byte getPByte();
0N/A void setPByte(byte x);
0N/A byte opPByte(byte x, byte y);
0N/A
0N/A char PChar = 'x';
0N/A SimpleType PCharType = SimpleType.CHARACTER;
0N/A char getPChar();
0N/A void setPChar(char x);
0N/A char opPChar(char x, char y);
0N/A
0N/A float PFloat = 1.3f;
0N/A SimpleType PFloatType = SimpleType.FLOAT;
0N/A float getPFloat();
0N/A void setPFloat(float x);
0N/A float opPFloat(float x, float y);
0N/A
0N/A double PDouble = Double.MAX_VALUE;
0N/A SimpleType PDoubleType = SimpleType.DOUBLE;
0N/A double getPDouble();
0N/A void setPDouble(double x);
0N/A double opPDouble(double x, double y);
0N/A
0N/A boolean PBoolean = true;
0N/A SimpleType PBooleanType = SimpleType.BOOLEAN;
0N/A boolean getPBoolean();
0N/A void setPBoolean(boolean x);
0N/A boolean opPBoolean(boolean x, boolean y);
0N/A
0N/A Integer WInteger = new Integer(59);
0N/A SimpleType WIntegerType = SimpleType.INTEGER;
0N/A Integer getWInteger();
0N/A void setWInteger(Integer x);
0N/A Integer opWInteger(Integer x, Integer y);
0N/A
0N/A Long WLong = new Long(Long.MAX_VALUE);
0N/A SimpleType WLongType = SimpleType.LONG;
0N/A Long getWLong();
0N/A void setWLong(Long x);
0N/A Long opWLong(Long x, Long y);
0N/A
0N/A Short WShort = new Short(Short.MAX_VALUE);
0N/A SimpleType WShortType = SimpleType.SHORT;
0N/A Short getWShort();
0N/A void setWShort(Short x);
0N/A Short opWShort(Short x, Short y);
0N/A
0N/A Byte WByte = new Byte(Byte.MAX_VALUE);
0N/A SimpleType WByteType = SimpleType.BYTE;
0N/A Byte getWByte();
0N/A void setWByte(Byte x);
0N/A Byte opWByte(Byte x, Byte y);
0N/A
0N/A Character WCharacter = new Character('x');
0N/A SimpleType WCharacterType = SimpleType.CHARACTER;
0N/A Character getWCharacter();
0N/A void setWCharacter(Character x);
0N/A Character opWCharacter(Character x, Character y);
0N/A
0N/A Float WFloat = new Float(1.3f);
0N/A SimpleType WFloatType = SimpleType.FLOAT;
0N/A Float getWFloat();
0N/A void setWFloat(Float x);
0N/A Float opWFloat(Float x, Float y);
0N/A
0N/A Double WDouble = new Double(Double.MAX_VALUE);
0N/A SimpleType WDoubleType = SimpleType.DOUBLE;
0N/A Double getWDouble();
0N/A void setWDouble(Double x);
0N/A Double opWDouble(Double x, Double y);
0N/A
0N/A Boolean WBoolean = Boolean.TRUE;
0N/A SimpleType WBooleanType = SimpleType.BOOLEAN;
0N/A Boolean getWBoolean();
0N/A void setWBoolean(Boolean x);
0N/A Boolean opWBoolean(Boolean x, Boolean y);
0N/A
0N/A int[] PIntA = {2, 3, 5, 7, 11, 13};
0N/A ArrayType PIntAType = ArrayTypeMaker.make(SimpleType.INTEGER, true);
0N/A int[] getPIntA();
0N/A void setPIntA(int[] x);
0N/A int[] opPIntA(int[] x, int[] y);
0N/A
0N/A int[][] PInt2D = {{1, 2}, {3, 4}};
0N/A ArrayType PInt2DType = ArrayTypeMaker.make(1, PIntAType);
0N/A int[][] getPInt2D();
0N/A void setPInt2D(int[][] x);
0N/A int[][] opPInt2D(int[][] x, int[][] y);
0N/A
0N/A Integer[] WIntA = {new Integer(3), new Integer(5)};
0N/A ArrayType WIntAType = ArrayTypeMaker.make(1, SimpleType.INTEGER);
0N/A Integer[] getWIntA();
0N/A void setWIntA(Integer[] x);
0N/A Integer[] opWIntA(Integer[] x, Integer[] y);
0N/A
0N/A Integer[][] WInt2D = {{new Integer(3)}, {new Integer(5)}};
0N/A ArrayType WInt2DType = ArrayTypeMaker.make(2, SimpleType.INTEGER);
0N/A Integer[][] getWInt2D();
0N/A void setWInt2D(Integer[][] x);
0N/A Integer[][] opWInt2D(Integer[][] x, Integer[][] y);
0N/A
0N/A String XString = "yo!";
0N/A SimpleType XStringType = SimpleType.STRING;
0N/A String getXString();
0N/A void setXString(String x);
0N/A String opXString(String x, String y);
0N/A
0N/A String[] XStringA = {"hello", "world"};
0N/A ArrayType XStringAType = ArrayTypeMaker.make(1, SimpleType.STRING);
0N/A String[] getXStringA();
0N/A void setXStringA(String[] x);
0N/A String[] opXStringA(String[] x, String[] y);
0N/A
0N/A int[] NoInts = {};
0N/A ArrayType NoIntsType = ArrayTypeMaker.make(SimpleType.INTEGER, true);
0N/A int[] getNoInts();
0N/A void setNoInts(int[] x);
0N/A int[] opNoInts(int[] x, int[] y);
0N/A
0N/A GetSetBean GetSet = GetSetBean.make(5, "x", new String[] {"a", "b"});
0N/A CompositeType GetSetType =
0N/A CompositeTypeMaker.make(GetSetBean.class.getName(),
0N/A GetSetBean.class.getName(),
0N/A new String[] {"int", "string", "stringArray"},
0N/A new String[] {"int", "string", "stringArray"},
0N/A new OpenType[] {
0N/A SimpleType.INTEGER,
0N/A SimpleType.STRING,
0N/A ArrayTypeMaker.make(1, SimpleType.STRING),
0N/A });
0N/A GetSetBean getGetSet();
0N/A void setGetSet(GetSetBean bean);
0N/A GetSetBean opGetSet(GetSetBean x, GetSetBean y);
0N/A
0N/A GetterInterface Interface = new GetterInterface() {
0N/A public boolean isWhatsit() {
0N/A return true;
0N/A }
0N/A
0N/A public int[] getInts() {
0N/A return new int[] {1};
0N/A }
0N/A
0N/A public String[] getStrings() {
0N/A return new String[] {"x"};
0N/A }
0N/A
0N/A public GetSetBean getGetSet() {
0N/A return GetSetBean.make(3, "a", new String[] {"b"});
0N/A }
0N/A
0N/A public boolean equals(Object o) {
0N/A if (!(o instanceof GetterInterface))
0N/A return false;
0N/A GetterInterface i = (GetterInterface) o;
0N/A return isWhatsit() == i.isWhatsit() &&
0N/A Arrays.equals(getInts(), i.getInts()) &&
0N/A Arrays.equals(getStrings(), i.getStrings()) &&
0N/A getGetSet().equals(i.getGetSet());
0N/A }
0N/A };
0N/A CompositeType InterfaceType =
0N/A CompositeTypeMaker.make(GetterInterface.class.getName(),
0N/A GetterInterface.class.getName(),
0N/A new String[] {
0N/A "ints", "getSet", "strings", "whatsit",
0N/A },
0N/A new String[] {
0N/A "ints", "getSet", "strings", "whatsit",
0N/A },
0N/A new OpenType[] {
0N/A ArrayTypeMaker.make(SimpleType.INTEGER, true),
0N/A GetSetType,
0N/A ArrayTypeMaker.make(1, SimpleType.STRING),
0N/A SimpleType.BOOLEAN,
0N/A });
0N/A GetterInterface getInterface();
0N/A void setInterface(GetterInterface i);
0N/A GetterInterface opInterface(GetterInterface x, GetterInterface y);
0N/A
0N/A /* Testing that we can use a public no-arg constructor plus a setter
0N/A * for every getter to reconstruct this object. Note that the
0N/A * constructor-guessing logic is no longer valid for this class,
0N/A * so if we can reconstruct it it must be because of the setters.
0N/A */
0N/A public static class GetSetBean {
0N/A public GetSetBean() {
0N/A this(0, null, null);
0N/A }
0N/A
0N/A private GetSetBean(int Int, String string, String[] stringArray) {
0N/A this.Int = Int;
0N/A this.string = string;
0N/A this.stringArray = stringArray;
0N/A }
0N/A
0N/A public static GetSetBean
0N/A make(int Int, String string, String[] stringArray) {
0N/A GetSetBean b = new GetSetBean(Int, string, stringArray);
0N/A return b;
0N/A }
0N/A
0N/A public int getInt() {
0N/A return Int;
0N/A }
0N/A
0N/A public String getString() {
0N/A return this.string;
0N/A }
0N/A
0N/A public String[] getStringArray() {
0N/A return this.stringArray;
0N/A }
0N/A
0N/A public void setInt(int x) {
0N/A this.Int = x;
0N/A }
0N/A
0N/A public void setString(String string) {
0N/A this.string = string;
0N/A }
0N/A
0N/A public void setStringArray(String[] stringArray) {
0N/A this.stringArray = stringArray;
0N/A }
0N/A
0N/A public boolean equals(Object o) {
0N/A if (!(o instanceof GetSetBean))
0N/A return false;
0N/A GetSetBean b = (GetSetBean) o;
0N/A return (b.Int == Int &&
0N/A b.string.equals(string) &&
0N/A Arrays.equals(b.stringArray, stringArray));
0N/A }
0N/A
0N/A String string;
0N/A String[] stringArray;
0N/A int Int;
0N/A }
0N/A
0N/A public static interface GetterInterface {
0N/A public String[] getStrings();
0N/A public int[] getInts();
0N/A public boolean isWhatsit();
0N/A public GetSetBean getGetSet();
0N/A
0N/A // We uselessly mention the public methods inherited from Object because
0N/A // they should not prevent the interface from being translatable.
0N/A // We could consider encoding the result of hashCode() and toString()
0N/A // on the original object that implements this interface into the
0N/A // generated CompositeData and referencing that in the proxy, but
0N/A // that seems ambitious for now. Doing it only if hashCode() and/or
0N/A // toString() are mentioned in the interface is a possibility but
0N/A // a rather abstruse one.
0N/A public boolean equals(Object o);
0N/A public int hashCode();
0N/A public String toString();
0N/A }
0N/A
0N/A public static class ArrayTypeMaker {
0N/A static ArrayType make(int dims, OpenType baseType) {
0N/A try {
0N/A return new ArrayType(dims, baseType);
0N/A } catch (OpenDataException e) {
0N/A throw new Error(e);
0N/A }
0N/A }
0N/A
0N/A static ArrayType make(SimpleType baseType, boolean primitiveArray) {
0N/A try {
0N/A return new ArrayType(baseType, primitiveArray);
0N/A } catch (OpenDataException e) {
0N/A throw new Error(e);
0N/A }
0N/A }
0N/A }
0N/A
0N/A public static class CompositeTypeMaker {
0N/A static CompositeType make(String className,
0N/A String description,
0N/A String[] itemNames,
0N/A String[] itemDescriptions,
0N/A OpenType[] itemTypes) {
0N/A try {
0N/A return new CompositeType(className,
0N/A description,
0N/A itemNames,
0N/A itemDescriptions,
0N/A itemTypes);
0N/A } catch (OpenDataException e) {
0N/A throw new Error(e);
0N/A }
0N/A }
0N/A }
0N/A
0N/A public static interface GraphMXBean {
0N/A public NodeMXBean[] getNodes();
0N/A }
0N/A
0N/A public static class Graph implements GraphMXBean {
0N/A public Graph(Node... nodes) {
0N/A for (Node node : nodes)
0N/A node.setGraph(this);
0N/A this.nodes = nodes;
0N/A }
0N/A
0N/A public NodeMXBean[] getNodes() {
0N/A return nodes;
0N/A }
0N/A
0N/A private final Node[] nodes;
0N/A }
0N/A
0N/A public static interface NodeMXBean {
0N/A public String getName();
0N/A public GraphMXBean getGraph();
0N/A }
0N/A
0N/A public static class Node implements NodeMXBean {
0N/A public Node(String name) {
0N/A this.name = name;
0N/A }
0N/A
0N/A public String getName() {
0N/A return name;
0N/A }
0N/A
0N/A public GraphMXBean getGraph() {
0N/A return graph;
0N/A }
0N/A
0N/A public void setGraph(Graph graph) {
0N/A this.graph = graph;
0N/A }
0N/A
0N/A private final String name;
0N/A private Graph graph;
0N/A }
0N/A
0N/A SimpleType GraphType = SimpleType.OBJECTNAME;
0N/A GraphMXBean getGraph();
0N/A void setGraph(GraphMXBean g);
0N/A GraphMXBean opGraph(GraphMXBean x, GraphMXBean y);
0N/A String GraphObjectName = "test:type=GraphMXBean";
0N/A String NodeAObjectName = "test:type=NodeMXBean,name=a";
0N/A String NodeBObjectName = "test:type=NodeMXBean,name=b";
0N/A Node NodeA = new Node("a");
0N/A Node NodeB = new Node("b");
0N/A GraphMXBean Graph = new Graph(NodeA, NodeB);
0N/A
0N/A public static class ExoticCompositeData implements CompositeDataView {
0N/A private ExoticCompositeData(String whatsit) {
0N/A this.whatsit = whatsit;
0N/A }
0N/A
0N/A public static ExoticCompositeData from(CompositeData cd) {
0N/A String whatsit = (String) cd.get("whatsit");
0N/A if (!whatsit.startsWith("!"))
0N/A throw new IllegalArgumentException(whatsit);
0N/A return new ExoticCompositeData(whatsit.substring(1));
0N/A }
0N/A
0N/A public CompositeData toCompositeData(CompositeType ct) {
0N/A try {
0N/A return new CompositeDataSupport(ct, new String[] {"whatsit"},
0N/A new String[] {"!" + whatsit});
0N/A } catch (Exception e) {
0N/A throw new RuntimeException(e);
0N/A }
0N/A }
0N/A
0N/A public String getWhatsit() {
0N/A return whatsit;
0N/A }
0N/A
0N/A public boolean equals(Object o) {
0N/A return ((o instanceof ExoticCompositeData) &&
0N/A ((ExoticCompositeData) o).whatsit.equals(whatsit));
0N/A }
0N/A
0N/A private final String whatsit;
0N/A
0N/A public static final CompositeType type;
0N/A static {
0N/A try {
0N/A type =
0N/A new CompositeType(ExoticCompositeData.class.getName(),
0N/A ExoticCompositeData.class.getName(),
0N/A new String[] {"whatsit"},
0N/A new String[] {"whatsit"},
0N/A new OpenType[] {SimpleType.STRING});
0N/A } catch (Exception e) {
0N/A throw new RuntimeException(e);
0N/A }
0N/A }
0N/A }
0N/A CompositeType ExoticType = ExoticCompositeData.type;
0N/A ExoticCompositeData getExotic();
0N/A void setExotic(ExoticCompositeData ecd);
0N/A ExoticCompositeData opExotic(ExoticCompositeData ecd1,
0N/A ExoticCompositeData ecd2);
0N/A ExoticCompositeData Exotic = new ExoticCompositeData("foo");
0N/A}