Search in sources :

Example 1 with GwtConfigParameterType

use of org.eclipse.kura.web.shared.model.GwtConfigParameter.GwtConfigParameterType in project kura by eclipse.

the class GwtComponentServiceImpl method getObjectValue.

private Object getObjectValue(GwtConfigParameter gwtConfigParam, String strValue) {
    Object objValue = null;
    GwtConfigParameterType gwtType = gwtConfigParam.getType();
    if (gwtType == GwtConfigParameterType.STRING) {
        objValue = strValue;
    } else if (strValue != null && !strValue.trim().isEmpty()) {
        switch(gwtType) {
            case LONG:
                objValue = Long.parseLong(strValue);
                break;
            case DOUBLE:
                objValue = Double.parseDouble(strValue);
                break;
            case FLOAT:
                objValue = Float.parseFloat(strValue);
                break;
            case INTEGER:
                objValue = Integer.parseInt(strValue);
                break;
            case SHORT:
                objValue = Short.parseShort(strValue);
                break;
            case BYTE:
                objValue = Byte.parseByte(strValue);
                break;
            case BOOLEAN:
                objValue = Boolean.parseBoolean(strValue);
                break;
            case PASSWORD:
                objValue = new Password(strValue);
                break;
            case CHAR:
                objValue = Character.valueOf(strValue.charAt(0));
                break;
            default:
                break;
        }
    }
    return objValue;
}
Also used : GwtConfigParameterType(org.eclipse.kura.web.shared.model.GwtConfigParameter.GwtConfigParameterType) Password(org.eclipse.kura.configuration.Password)

Example 2 with GwtConfigParameterType

use of org.eclipse.kura.web.shared.model.GwtConfigParameter.GwtConfigParameterType in project kura by eclipse.

the class GwtComponentServiceImpl method getObjectValue.

private Object[] getObjectValue(GwtConfigParameter gwtConfigParam, String[] defaultValues) {
    List<Object> values = new ArrayList<Object>();
    GwtConfigParameterType type = gwtConfigParam.getType();
    switch(type) {
        case BOOLEAN:
            for (String value : defaultValues) {
                if (!value.trim().isEmpty()) {
                    values.add(Boolean.valueOf(value));
                }
            }
            return values.toArray(new Boolean[] {});
        case BYTE:
            for (String value : defaultValues) {
                if (!value.trim().isEmpty()) {
                    values.add(Byte.valueOf(value));
                }
            }
            return values.toArray(new Byte[] {});
        case CHAR:
            for (String value : defaultValues) {
                if (!value.trim().isEmpty()) {
                    values.add(new Character(value.charAt(0)));
                }
            }
            return values.toArray(new Character[] {});
        case DOUBLE:
            for (String value : defaultValues) {
                if (!value.trim().isEmpty()) {
                    values.add(Double.valueOf(value));
                }
            }
            return values.toArray(new Double[] {});
        case FLOAT:
            for (String value : defaultValues) {
                if (!value.trim().isEmpty()) {
                    values.add(Float.valueOf(value));
                }
            }
            return values.toArray(new Float[] {});
        case INTEGER:
            for (String value : defaultValues) {
                if (!value.trim().isEmpty()) {
                    values.add(Integer.valueOf(value));
                }
            }
            return values.toArray(new Integer[] {});
        case LONG:
            for (String value : defaultValues) {
                if (!value.trim().isEmpty()) {
                    values.add(Long.valueOf(value));
                }
            }
            return values.toArray(new Long[] {});
        case SHORT:
            for (String value : defaultValues) {
                if (!value.trim().isEmpty()) {
                    values.add(Short.valueOf(value));
                }
            }
            return values.toArray(new Short[] {});
        case PASSWORD:
            for (String value : defaultValues) {
                if (!value.trim().isEmpty()) {
                    values.add(new Password(value));
                }
            }
            return values.toArray(new Password[] {});
        case STRING:
            for (String value : defaultValues) {
                if (!value.trim().isEmpty()) {
                    values.add(value);
                }
            }
            return values.toArray(new String[] {});
        default:
            return null;
    }
}
Also used : ArrayList(java.util.ArrayList) GwtConfigParameterType(org.eclipse.kura.web.shared.model.GwtConfigParameter.GwtConfigParameterType) Password(org.eclipse.kura.configuration.Password)

Aggregations

Password (org.eclipse.kura.configuration.Password)2 GwtConfigParameterType (org.eclipse.kura.web.shared.model.GwtConfigParameter.GwtConfigParameterType)2 ArrayList (java.util.ArrayList)1