Search in sources :

Example 1 with MBeanParameterInfo

use of javax.management.MBeanParameterInfo in project tdi-studio-se by Talend.

the class InvokeDialog method validate.

/**
     * Validates the specified text.
     */
void validate() {
    boolean enableButton = true;
    for (Entry<MBeanParameterInfo, Control> entry : controls.entrySet()) {
        Control control = entry.getValue();
        if (!(control instanceof Text)) {
            continue;
        }
        String type = entry.getKey().getType();
        String text = ((Text) control).getText();
        if (!validateNumber(type, text)) {
            enableButton = false;
            break;
        }
    }
    Button invokeButton = getButton(IDialogConstants.CLIENT_ID);
    if (invokeButton != null) {
        invokeButton.setEnabled(enableButton);
    }
}
Also used : Control(org.eclipse.swt.widgets.Control) Button(org.eclipse.swt.widgets.Button) Text(org.eclipse.swt.widgets.Text) MBeanParameterInfo(javax.management.MBeanParameterInfo)

Example 2 with MBeanParameterInfo

use of javax.management.MBeanParameterInfo in project tdi-studio-se by Talend.

the class InvokeDialog method getParams.

/**
     * Gets the parameters.
     * 
     * @return The parameters
     */
private Object[] getParams() {
    List<Object> params = new ArrayList<Object>();
    for (final MBeanParameterInfo signature : info.getSignature()) {
        String text = getText(signature);
        Object object;
        String type = signature.getType();
        if ("int".equals(type)) {
            //$NON-NLS-1$
            object = Integer.valueOf(text);
        } else if ("long".equals(type)) {
            //$NON-NLS-1$
            object = Long.valueOf(text);
        } else if ("boolean".equals(type)) {
            //$NON-NLS-1$
            object = Boolean.valueOf(text);
        } else if ("java.lang.String".equals(type)) {
            //$NON-NLS-1$
            object = String.valueOf(text);
        } else if ("[J".equals(type)) {
            //$NON-NLS-1$
            //$NON-NLS-1$
            String[] elements = text.split(",");
            long[] objects = new long[elements.length];
            for (int i = 0; i < elements.length; i++) {
                objects[i] = Long.parseLong(elements[i]);
            }
            object = objects;
        } else {
            //$NON-NLS-1$
            throw new IllegalStateException("unknown parameter type");
        }
        params.add(object);
    }
    return params.toArray(new Object[0]);
}
Also used : ArrayList(java.util.ArrayList) MBeanParameterInfo(javax.management.MBeanParameterInfo)

Example 3 with MBeanParameterInfo

use of javax.management.MBeanParameterInfo in project tdi-studio-se by Talend.

the class InvokeDialog method getMethodSignature.

/**
     * Gets the method signature.
     * 
     * @return The method signature
     */
private String getMethodSignature() {
    StringBuffer buffer = new StringBuffer();
    buffer.append(info.getName());
    //$NON-NLS-1$
    buffer.append("(");
    StringBuffer paramBuffer = new StringBuffer();
    for (MBeanParameterInfo parameterInfo : info.getSignature()) {
        if (paramBuffer.length() != 0) {
            //$NON-NLS-1$
            paramBuffer.append(", ");
        }
        String param = parameterInfo.getType();
        if (param.startsWith("[")) {
            //$NON-NLS-1$
            param = Signature.toString(param);
        }
        int index = param.lastIndexOf('.');
        if (index > 0) {
            param = param.substring(index + 1);
        }
        paramBuffer.append(param);
    }
    buffer.append(paramBuffer);
    //$NON-NLS-1$
    buffer.append(")");
    return buffer.toString();
}
Also used : MBeanParameterInfo(javax.management.MBeanParameterInfo)

Example 4 with MBeanParameterInfo

use of javax.management.MBeanParameterInfo in project tdi-studio-se by Talend.

the class InvokeDialog method createParameterGroup.

/**
     * Creates the parameter group.
     * 
     * @param parent The parent composite
     */
private void createParameterGroup(Composite parent) {
    if (info.getSignature().length == 0) {
        return;
    }
    Group group = new Group(parent, SWT.NONE);
    group.setText(Messages.parametersGroupLabel);
    GridLayout layout = new GridLayout(2, false);
    group.setLayout(layout);
    group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    for (MBeanParameterInfo signature : info.getSignature()) {
        Label label = new Label(group, SWT.NONE);
        String type = signature.getType();
        if (type.startsWith("[")) {
            //$NON-NLS-1$
            type = Signature.toString(type);
            label.setToolTipText(Messages.enterCommaSeparatedValuesToolTip);
        }
        int index = type.lastIndexOf('.');
        if (index > 0) {
            type = type.substring(index + 1);
        }
        //$NON-NLS-1$
        label.setText(type + ":");
        if (Boolean.class.getSimpleName().equalsIgnoreCase(type)) {
            Combo combo = new Combo(group, SWT.READ_ONLY);
            combo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
            combo.add(Boolean.TRUE.toString());
            combo.add(Boolean.FALSE.toString());
            combo.select(0);
            controls.put(signature, combo);
        } else {
            Text text = new Text(group, SWT.BORDER);
            text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
            text.addModifyListener(new ModifyListener() {

                @Override
                public void modifyText(ModifyEvent e) {
                    validate();
                }
            });
            controls.put(signature, text);
        }
    }
}
Also used : Group(org.eclipse.swt.widgets.Group) ModifyListener(org.eclipse.swt.events.ModifyListener) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) Text(org.eclipse.swt.widgets.Text) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) GridData(org.eclipse.swt.layout.GridData) MBeanParameterInfo(javax.management.MBeanParameterInfo)

Example 5 with MBeanParameterInfo

use of javax.management.MBeanParameterInfo in project tdi-studio-se by Talend.

the class OperationsTab method getValidOperations.

/**
     * Gets the valid MBean operations.
     * 
     * @param operations
     * @return The valid MBean operations
     */
static MBeanOperationInfo[] getValidOperations(MBeanOperationInfo[] operations) {
    List<MBeanOperationInfo> validOperations = new ArrayList<MBeanOperationInfo>();
    for (MBeanOperationInfo operation : operations) {
        boolean invalid = false;
        MBeanParameterInfo[] signature = operation.getSignature();
        for (int i = 0; i < signature.length; i++) {
            String name = signature[i].getName();
            String type = signature[i].getType();
            String description = signature[i].getDescription();
            if (name == null || type == null || description == null) {
                invalid = true;
                signature[i] = new MBeanParameterInfo(getNonNull(name), getNonNull(type), getNonNull(description), signature[i].getDescriptor());
            }
        }
        if (invalid) {
            operation = new MBeanOperationInfo(operation.getName(), operation.getDescription(), signature, operation.getReturnType(), operation.getImpact(), operation.getDescriptor());
        }
        validOperations.add(operation);
    }
    return validOperations.toArray(new MBeanOperationInfo[validOperations.size()]);
}
Also used : MBeanOperationInfo(javax.management.MBeanOperationInfo) ArrayList(java.util.ArrayList) MBeanParameterInfo(javax.management.MBeanParameterInfo)

Aggregations

MBeanParameterInfo (javax.management.MBeanParameterInfo)59 MBeanOperationInfo (javax.management.MBeanOperationInfo)36 MBeanInfo (javax.management.MBeanInfo)19 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)15 ObjectName (javax.management.ObjectName)10 ArrayList (java.util.ArrayList)9 Descriptor (javax.management.Descriptor)8 Method (java.lang.reflect.Method)5 MBeanConstructorInfo (javax.management.MBeanConstructorInfo)5 Annotation (java.lang.annotation.Annotation)4 ModelMBeanOperationInfo (javax.management.modelmbean.ModelMBeanOperationInfo)4 Test (org.junit.Test)4 IOException (java.io.IOException)3 TreeMap (java.util.TreeMap)3 Attribute (javax.management.Attribute)3 ImmutableDescriptor (javax.management.ImmutableDescriptor)3 MBeanNotificationInfo (javax.management.MBeanNotificationInfo)3 ReflectionException (javax.management.ReflectionException)3 DescriptorSupport (javax.management.modelmbean.DescriptorSupport)3 Constructor (java.lang.reflect.Constructor)2