Extract read and write part values to an object for SCALAR, SPECTRUM and IMAGE

@param da
@return array of primitives for SCALAR, array of primitives for SPECTRUM, array of primitives array of primitives
for IMAGE
@throws DevFailed
65
public static Object extract(final DeviceAttribute da) throws DevFailed {
	if (da == null) {
		throw DevFailedUtils.newDevFailed(ERROR_MSG_DA);
	}
	return InsertExtractFactory.getAttributeExtractor(da.getType()).extract(da);
    }
768646
public int[] extractUShortArray() throws DevFailed {
		manageExceptions("extractUShortArray");
		if (use_union) {
	    	final short[] argOut = attributeValue_5.value.ushort_att_value();
	    	final int[] val = new int[argOut.length];
	    	for (int i = 0; i < argOut.length; i++) {
			val[i] = 0xFFFF & argOut[i];
	    	}
	    	return val;
		} else {
	    	return deviceAttribute_3.extractUShortArray();
		}
    }
130068
public DbDatum[] get_property(final DeviceProxy deviceProxy,
                                  final String[] propertyNames) throws DevFailed {
		if (deviceProxy.url.protocol == TANGO) {
	    	checkIfUseDb(deviceProxy, "get_property()");

	    	if (deviceProxy.getDb_dev() == null) {
			deviceProxy.setDb_dev(new DbDevice(deviceProxy.devname, deviceProxy.url.host,
				deviceProxy.url.strPort));
	    	}
	    	return deviceProxy.getDb_dev().get_property(propertyNames);
		} else {
			if (deviceProxy.taco_device == null && deviceProxy.devname != null) {
	    		build_connection(deviceProxy);
			}
	    	return deviceProxy.taco_device.get_property(propertyNames);
		}
    }
1227771
@Override
    public String[] getDeviceList(final String serverName, final String className) throws DevFailed {
        return cache.getDeviceList(serverName, className);
    }
202161
public List<String> getDevicePipeList(String deviceName, String wildcard) throws DevFailed {
        return databaseDAO.getDevicePipeList(this, deviceName, wildcard);
    }
39854
public static Object extract(final DeviceData deviceDataArgout) throws DevFailed {
	Object argout = null;
	switch (deviceDataArgout.getType()) {
	case TangoConst.Tango_DEV_SHORT:
	    argout = Short.valueOf(deviceDataArgout.extractShort());
	    break;
	case TangoConst.Tango_DEV_USHORT:
	    argout = Integer.valueOf(deviceDataArgout.extractUShort()).shortValue();
	    break;
	case TangoConst.Tango_DEV_CHAR:
	    Except.throw_exception("TANGO_WRONG_DATA_ERROR",
		    "out type Tango_DEV_CHAR not supported",
		    "CommandHelper.extract(deviceDataArgout)");
	    break;
	case TangoConst.Tango_DEV_UCHAR:
	    Except.throw_exception("TANGO_WRONG_DATA_ERROR",
		    "out type Tango_DEV_UCHAR not supported",
		    "CommandHelper.extract(deviceDataArgout)");
	    break;
	case TangoConst.Tango_DEV_LONG:
	    argout = Integer.valueOf(deviceDataArgout.extractLong());
	    break;
	case TangoConst.Tango_DEV_ULONG:
	    argout = Long.valueOf(deviceDataArgout.extractULong());
	    break;
	case TangoConst.Tango_DEV_LONG64:
	    argout = Long.valueOf(deviceDataArgout.extractLong64());
	    break;
	case TangoConst.Tango_DEV_ULONG64:
	    argout = Long.valueOf(deviceDataArgout.extractULong64());
	    break;
	case TangoConst.Tango_DEV_INT:
	    argout = Integer.valueOf(deviceDataArgout.extractLong());
	    break;
	case TangoConst.Tango_DEV_FLOAT:
	    argout = Float.valueOf(deviceDataArgout.extractFloat());
	    break;
	case TangoConst.Tango_DEV_DOUBLE:
	    argout = Double.valueOf(deviceDataArgout.extractDouble());
	    break;
	case TangoConst.Tango_DEV_STRING:
	    argout = deviceDataArgout.extractString();
	    break;
	case TangoConst.Tango_DEV_BOOLEAN:
	    argout = Boolean.valueOf(deviceDataArgout.extractBoolean());
	    break;
	case TangoConst.Tango_DEV_STATE:
	    argout = deviceDataArgout.extractDevState();
	    break;
	case TangoConst.Tango_DEVVAR_DOUBLESTRINGARRAY:
	    argout = deviceDataArgout.extractDoubleStringArray();
	    break;
	case TangoConst.Tango_DEVVAR_LONGSTRINGARRAY:
	    argout = deviceDataArgout.extractLongStringArray();
	    break;
	default:
	    Except.throw_exception("TANGO_WRONG_DATA_ERROR", "output type "
		    + deviceDataArgout.getType() + " not supported",
		    "CommandHelper.extract(Short value,deviceDataArgout)");
	    break;
	}

	return argout;
    }
889963
public DevState[] extractDevStateArray() throws DevFailed {
	manageExceptions("extractDevStateArray()");
	try {
	    if (isArray()) {
		return DevVarStateArrayHelper.extract(attrval.value);
	    } else {
		// It is used for state attribute
		return new DevState[] { DevStateHelper.extract(attrval.value) };
	    }
	} catch (final org.omg.CORBA.BAD_PARAM e) {
	    Except
		    .throw_wrong_data_exception(
			    e.toString(),
			    "Exception catched : "
				    + e.toString()
				    + "\n"
				    + "Maybe the attribute value has not been initialized",
			    "DeviceAttribute.extractDevStateArray()");
	}
	return new DevState[0];// never used
    }
905804
public static <T> Object castToArray(final Class<T> type, final Object val) throws DevFailed {
	Object result = null;
	final Object array1D = val;
	if (val == null || type.isAssignableFrom(val.getClass())) {
	    result = val;
	} else {
	    LOGGER.debug("converting {} to {}", val.getClass().getCanonicalName(), type.getCanonicalName());
	    final Class<?> typeConv = Array.newInstance(type, 0).getClass();
	    final Transmorph transmorph = new Transmorph(creatConv());
	    try {
		result = transmorph.convert(array1D, typeConv);
	    } catch (final ConverterException e) {
		LOGGER.error("convertion error", e);
		throw DevFailedUtils.newDevFailed(e);
	    }
	}
	return result;
    }
499776
public static Float extractToFloat(final DeviceData deviceDataArgout) throws DevFailed {
	final Object value = CommandHelper.extract(deviceDataArgout);
	Float argout = null;
	if (value instanceof Short) {
	    argout = Float.valueOf(((Short) value).floatValue());
	} else if (value instanceof String) {
	    try {
		argout = Float.valueOf((String) value);
	    } catch (final Exception e) {
		Except.throw_exception("TANGO_WRONG_DATA_ERROR", "output type " + value
			+ " is not a numerical", "CommandHelper.extractToFloat(deviceDataArgin)");
	    }
	} else if (value instanceof Integer) {
	    argout = Float.valueOf(((Integer) value).floatValue());
	} else if (value instanceof Long) {
	    argout = Float.valueOf(((Long) value).floatValue());
	} else if (value instanceof Float) {
	    argout = Float.valueOf(((Float) value).floatValue());
	} else if (value instanceof Boolean) {
	    if (((Boolean) value).booleanValue()) {
		argout = Float.valueOf(1);
	    } else {
		argout = Float.valueOf(0);
	    }
	} else if (value instanceof Double) {
	    argout = Float.valueOf(((Double) value).floatValue());
	} else if (value instanceof DevState) {
	    argout = Float.valueOf(Integer.valueOf(((DevState) value).value()).floatValue());
	} else {
	    Except.throw_exception("TANGO_WRONG_DATA_ERROR", "output type " + value.getClass()
		    + " not supported",
		    "CommandHelper.extractToFloat(Object value,deviceDataArgin)");
	}

	return argout;
    }
369842
public <T> T read(final Class<T> type) throws DevFailed {
        update();
        return extract(type);
    }
720129
public DbDatum[] get_device_property(String name, String[] propnames) throws DevFailed {
		return databaseDAO.get_device_property(this, name, propnames);
	}
930687
public static Integer extractToInteger(final DeviceData deviceDataArgout) throws DevFailed {
	final Object value = CommandHelper.extract(deviceDataArgout);
	Integer argout = null;
	if (value instanceof Short) {
	    argout = Integer.valueOf(((Short) value).intValue());
	} else if (value instanceof String) {
	    try {
		argout = Integer.valueOf((String) value);
	    } catch (final Exception e) {
		Except.throw_exception("TANGO_WRONG_DATA_ERROR", "output type " + value
			+ " is not a numerical", "CommandHelper.extractToInteger(deviceDataArgin)");
	    }
	} else if (value instanceof Integer) {
	    argout = (Integer) value;
	} else if (value instanceof Long) {
	    argout = Integer.valueOf(((Long) value).intValue());
	} else if (value instanceof Float) {
	    argout = Integer.valueOf(((Float) value).intValue());
	} else if (value instanceof Boolean) {
	    if (((Boolean) value).booleanValue()) {
		argout = Integer.valueOf(1);
	    } else {
		argout = Integer.valueOf(0);
	    }
	} else if (value instanceof Double) {
	    argout = Integer.valueOf(((Double) value).intValue());
	} else if (value instanceof DevState) {
	    argout = Integer.valueOf(((DevState) value).value());
	} else {
	    Except.throw_exception("TANGO_WRONG_DATA_ERROR", "output type " + value.getClass()
		    + " not supported",
		    "CommandHelper.extractToInteger(Object value,deviceDataArgin)");
	}

	return argout;
    }
61908
public static Object fromArrayTo2DArray(final Object array, final int dimX, final int dimY) throws DevFailed {
        Object array2D = null;
        // final Profiler profilerPeriod = new Profiler("fromArrayTo2DArray");
        // profilerPeriod.start("fromArrayTo2DArray");
        if (array.getClass().isArray()) {
            if (dimY > 0) {// to a 2D Array
                array2D = Array.newInstance(array.getClass().getComponentType(), dimY, dimX);
                for (int y = 0; y < dimY; y++) {
                    final Object line = Array.get(array2D, y);
                    System.arraycopy(array, y * dimX, line, 0, Array.getLength(line));
                }

            } else {
                array2D = Array.newInstance(array.getClass().getComponentType(), Array.getLength(array));
                System.arraycopy(array, 0, array2D, 0, Array.getLength(array));
            }
        } else {
            array2D = array;
        }
        // profilerPeriod.stop().print();
        return array2D;
    }
572855
public static String[] extractToStringArray(final DeviceData deviceDataArgout) throws DevFailed {
	final Object[] values = CommandHelper.extractArray(deviceDataArgout);
	if (values == null) {
	    Except.throw_exception("TANGO_WRONG_DATA_ERROR", "output is empty ",
		    "CommandHelper.extractToStringArray(deviceDataArgin)");
	}
	final String[] argout = new String[values.length];

	if (values.length > 0) {
	    if (values[0] instanceof Short) {
		for (int i = 0; i < values.length; i++) {
		    argout[i] = ((Short) values[i]).toString();
		}
	    } else if (values[0] instanceof String) {
		for (int i = 0; i < values.length; i++) {
		    argout[i] = (String) values[i];
		}

	    } else if (values[0] instanceof Integer) {
		for (int i = 0; i < values.length; i++) {
		    argout[i] = ((Integer) values[i]).toString();
		}
	    } else if (values[0] instanceof Long) {
		for (int i = 0; i < values.length; i++) {
		    argout[i] = ((Long) values[i]).toString();
		}
	    } else if (values[0] instanceof Float) {
		for (int i = 0; i < values.length; i++) {
		    argout[i] = ((Float) values[i]).toString();
		}
	    } else if (values[0] instanceof Boolean) {
		for (int i = 0; i < values.length; i++) {
		    argout[i] = ((Boolean) values[i]).toString();
		}
	    } else if (values[0] instanceof Double) {
		for (int i = 0; i < values.length; i++) {
		    argout[i] = ((Double) values[i]).toString();
		}
	    } else if (values[0] instanceof Byte) {
		for (int i = 0; i < values.length; i++) {
		    argout[i] = ((Byte) values[i]).toString();
		}
	    } else if (values[0] instanceof DevState) {
		for (int i = 0; i < values.length; i++) {
		    argout[i] = StateUtilities.getNameForState((DevState) values[0]);
		}
	    } else {
		Except.throw_exception("TANGO_WRONG_DATA_ERROR", "output type "
			+ values[0].getClass() + " not supported",
			"CommandHelper.extractToStringArray(Object value,deviceDataArgin)");
	    }
	}
	return argout;
    }
294179
public static short[] extractToShortArray(final DeviceData deviceDataArgout) throws DevFailed {
	final Object[] values = CommandHelper.extractArray(deviceDataArgout);
	if (values == null) {
	    Except.throw_exception("TANGO_WRONG_DATA_ERROR", "output is empty ",
		    "CommandHelper.extractToShortArray(deviceDataArgin)");
	}
	final short[] argout = new short[values.length];

	if (values.length > 0) {
	    if (values[0] instanceof Short) {
		for (int i = 0; i < values.length; i++) {
		    argout[i] = ((Short) values[i]).shortValue();
		}
	    } else if (values[0] instanceof String) {
		try {
		    for (int i = 0; i < values.length; i++) {
			argout[i] = Double.valueOf((String) values[i]).shortValue();
		    }
		} catch (final Exception e) {
		    Except.throw_exception("TANGO_WRONG_DATA_ERROR", "output type not numerical",
			    "CommandHelper.extractToShortArray(deviceDataArgin)");
		}
	    } else if (values[0] instanceof Integer) {
		for (int i = 0; i < values.length; i++) {
		    argout[i] = ((Integer) values[i]).shortValue();
		}
	    } else if (values[0] instanceof Long) {
		for (int i = 0; i < values.length; i++) {
		    argout[i] = ((Long) values[i]).shortValue();
		}
	    } else if (values[0] instanceof Float) {
		for (int i = 0; i < values.length; i++) {
		    argout[i] = ((Float) values[i]).shortValue();
		}
	    } else if (values[0] instanceof Boolean) {
		for (int i = 0; i < values.length; i++) {
		    if (((Boolean) values[i]).booleanValue()) {
			argout[i] = (short) 1;
		    } else {
			argout[i] = (short) 0;
		    }
		}
	    } else if (values[0] instanceof Double) {
		for (int i = 0; i < values.length; i++) {
		    argout[i] = ((Double) values[i]).shortValue();
		}
	    } else if (values[0] instanceof Byte) {
		for (int i = 0; i < values.length; i++) {
		    argout[i] = ((Byte) values[i]).shortValue();
		}
	    } else if (values[0] instanceof DevState) {
		for (int i = 0; i < values.length; i++) {
		    argout[i] = Integer.valueOf(((DevState) values[i]).value()).shortValue();
		}
	    } else {
		Except.throw_exception("TANGO_WRONG_DATA_ERROR", "output type "
			+ values[0].getClass() + " not supported",
			"CommandHelper.extractToShortArray(Object value,deviceDataArgin)");
	    }
	}
	return argout;
    }
890281
public List<DbHistory> getClassPipePropertyHistory(String className,String pipeName,
                                                             String propertyName) throws DevFailed {
        return databaseDAO.getClassPipePropertyHistory(this, className, pipeName, propertyName);
    }
655785
public static String extractToString(final DeviceAttribute deviceAttributeRead)
	    throws DevFailed {
	final Object value = AttributeHelper.extract(deviceAttributeRead);
	String argout = null;
	if (value instanceof Short) {
	    argout = ((Short) value).toString();
	} else if (value instanceof String) {
	    argout = (String) value;
	} else if (value instanceof Integer) {
	    argout = ((Integer) value).toString();
	} else if (value instanceof Long) {
	    argout = ((Long) value).toString();
	} else if (value instanceof Float) {
	    argout = ((Float) value).toString();
	} else if (value instanceof Boolean) {
	    argout = ((Boolean) value).toString();
	} else if (value instanceof Double) {
	    argout = ((Double) value).toString();
	} else if (value instanceof DevState) {
	    argout = StateUtilities.getNameForState((DevState) value);
	} else {
	    Except.throw_exception("TANGO_WRONG_DATA_ERROR", "output type " + value.getClass()
		    + " not supported",
		    "AttributeHelper.extractToString(Object value,deviceAttributeWritten)");
	}

	return argout;
    }