Example usage for com.badlogic.gdx.beans IndexedPropertyDescriptor getWriteMethod

List of usage examples for com.badlogic.gdx.beans IndexedPropertyDescriptor getWriteMethod

Introduction

In this page you can find the example usage for com.badlogic.gdx.beans IndexedPropertyDescriptor getWriteMethod.

Prototype

public Method getWriteMethod() 

Source Link

Usage

From source file:org.apache.harmony.beans.Command.java

License:Apache License

private String getMethodName(Map<String, Command> references)
        throws NoSuchMethodException, IntrospectionException, Exception {
    if (methodName == null) {
        String methodValue = null;
        if (isTag("class")) { //$NON-NLS-1$
            addArgument(new Argument(String.class, data), 0);
            methodValue = "forName"; //$NON-NLS-1$
        } else if (isPrimitive()) {
            if (isTag("char")) { //$NON-NLS-1$
                if (data.length() != 1) {
                    throw new IntrospectionException(Messages.getString("beans.43", //$NON-NLS-1$
                            data));/*from   www  .  j  av a2 s  .co  m*/
                }
                addArgument(new Argument(char.class, Character.valueOf(data.charAt(0))), 0);
            } else {
                addArgument(new Argument(String.class, data), 0);
            }
            methodValue = "new"; //$NON-NLS-1$
        } else if (isConstructor() || hasAttr("method", "new")) { //$NON-NLS-1$ //$NON-NLS-2$
            methodValue = "new"; //$NON-NLS-1$
        } else if (isArray()) {
            methodValue = "new"; //$NON-NLS-1$
            int length = hasAttr("length") ? Integer //$NON-NLS-1$
                    .parseInt(getAttr("length")) : getArgumentsNumber(); //$NON-NLS-1$
            copyArgumentsToCommands();
            addArgument(new Argument(int.class, Integer.valueOf(length)), 0);
        } else if (hasAttr("property")) { //$NON-NLS-1$
            String propertyValue = getAttr("property"); //$NON-NLS-1$
            if (hasAttr("index")) { //$NON-NLS-1$
                addArgument(new Argument(int.class, new Integer(getAttr("index"))), 0); //$NON-NLS-1$
            }

            BeanInfo beanInfo = Introspector.getBeanInfo(getTarget(references).getClass());
            PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors();

            boolean methodFound = false;
            Method method = null;
            for (PropertyDescriptor pd : pds) {
                if (propertyValue.equals(pd.getName())) {
                    int argsNum = getArgumentsNumber();
                    if (hasAttr("index")) { //$NON-NLS-1$
                        IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
                        if (argsNum == 1) {
                            method = ipd.getIndexedReadMethod();
                        } else if (argsNum == 0) {
                            method = ipd.getReadMethod();
                        }
                    } else {
                        method = pd.getReadMethod();
                    }

                    if (method != null) {
                        methodFound = matchMethodParams(method, references);
                    }

                    if (methodFound == false) {
                        if (hasAttr("index")) { //$NON-NLS-1$
                            IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
                            if (argsNum == 2) {
                                method = ipd.getIndexedWriteMethod();
                            } else if (argsNum == 1) {
                                method = ipd.getWriteMethod();
                            }
                        } else {
                            method = pd.getWriteMethod();
                        }
                    }

                    if (method != null) {
                        methodFound = matchMethodParams(method, references);
                    }
                }
            }

            if (method == null) {
                throw new NoSuchMethodException(Messages.getString("beans.44", //$NON-NLS-1$
                        propertyValue));
            }
            methodValue = method.getName();
        } else if (hasAttr("method")) { //$NON-NLS-1$
            if (hasAttr("index")) { //$NON-NLS-1$
                addArgument(new Argument(int.class, Integer.valueOf(getAttr("index"))), 0); //$NON-NLS-1$
            }
            methodValue = getAttr("method"); //$NON-NLS-1$
        } else if (hasAttr("index")) { //$NON-NLS-1$
            addArgument(new Argument(int.class, Integer.valueOf(getAttr("index"))), 0); //$NON-NLS-1$
            methodValue = getArgumentsNumber() > 1 ? "set" : "get"; //$NON-NLS-1$ //$NON-NLS-2$
            if (ctx.isArray()) {
                addArgument(ctx.getResult(), 0);
            }
        } else if (hasAttr("field")) { //$NON-NLS-1$
            addArgument(new Argument(Class.forName(getAttr("class"), true, //$NON-NLS-1$
                    Thread.currentThread().getContextClassLoader())), 0);

            methodValue = "get"; //$NON-NLS-1$
        } else {
            throw new Exception(Messages.getString("beans.45")); //$NON-NLS-1$
        }
        methodName = methodValue;
    }
    return methodName;
}