⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 valuehelper.java

📁 jsr170接口的java实现。是个apache的开源项目。
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        Value val;        int srcType = srcValue.getType();        if (srcType == targetType) {            // no conversion needed, return original value            return srcValue;        }        switch (targetType) {            case PropertyType.STRING:                // convert to STRING                try {                    val = factory.createValue(srcValue.getString());                } catch (RepositoryException re) {                    throw new ValueFormatException("conversion failed: "                            + PropertyType.nameFromValue(srcType) + " to "                            + PropertyType.nameFromValue(targetType), re);                }                break;            case PropertyType.BINARY:                // convert to BINARY                try {                    val = factory.createValue(srcValue.getStream());                } catch (RepositoryException re) {                    throw new ValueFormatException("conversion failed: "                            + PropertyType.nameFromValue(srcType) + " to "                            + PropertyType.nameFromValue(targetType), re);                }                break;            case PropertyType.BOOLEAN:                // convert to BOOLEAN                try {                    val = factory.createValue(srcValue.getBoolean());                } catch (RepositoryException re) {                    throw new ValueFormatException("conversion failed: "                            + PropertyType.nameFromValue(srcType) + " to "                            + PropertyType.nameFromValue(targetType), re);                }                break;            case PropertyType.DATE:                // convert to DATE                try {                    val = factory.createValue(srcValue.getDate());                } catch (RepositoryException re) {                    throw new ValueFormatException("conversion failed: "                            + PropertyType.nameFromValue(srcType) + " to "                            + PropertyType.nameFromValue(targetType), re);                }                break;            case PropertyType.DOUBLE:                // convert to DOUBLE                try {                    val = factory.createValue(srcValue.getDouble());                } catch (RepositoryException re) {                    throw new ValueFormatException("conversion failed: "                            + PropertyType.nameFromValue(srcType) + " to "                            + PropertyType.nameFromValue(targetType), re);                }                break;            case PropertyType.LONG:                // convert to LONG                try {                    val = factory.createValue(srcValue.getLong());                } catch (RepositoryException re) {                    throw new ValueFormatException("conversion failed: "                            + PropertyType.nameFromValue(srcType) + " to "                            + PropertyType.nameFromValue(targetType), re);                }                break;            case PropertyType.PATH:                // convert to PATH                switch (srcType) {                    case PropertyType.PATH:                        // no conversion needed, return original value                        // (redundant code, just here for the sake of clarity)                        return srcValue;                    case PropertyType.BINARY:                    case PropertyType.STRING:                    case PropertyType.NAME: // a name is always also a relative path                        // try conversion via string                        String path;                        try {                            // get string value                            path = srcValue.getString();                        } catch (RepositoryException re) {                            // should never happen                            throw new ValueFormatException("failed to convert source value to PATH value",                                    re);                        }                        val = factory.createValue(path, targetType);                        break;                    case PropertyType.BOOLEAN:                    case PropertyType.DATE:                    case PropertyType.DOUBLE:                    case PropertyType.LONG:                    case PropertyType.REFERENCE:                        throw new ValueFormatException("conversion failed: "                                + PropertyType.nameFromValue(srcType) + " to "                                + PropertyType.nameFromValue(targetType));                    default:                        throw new IllegalArgumentException("not a valid type constant: " + srcType);                }                break;            case PropertyType.NAME:                // convert to NAME                switch (srcType) {                    case PropertyType.NAME:                        // no conversion needed, return original value                        // (redundant code, just here for the sake of clarity)                        return srcValue;                    case PropertyType.BINARY:                    case PropertyType.STRING:                    case PropertyType.PATH: // path might be a name (relative path of length 1)                        // try conversion via string                        String name;                        try {                            // get string value                            name = srcValue.getString();                        } catch (RepositoryException re) {                            // should never happen                            throw new ValueFormatException("failed to convert source value to NAME value",                                    re);                        }                        val = factory.createValue(name, targetType);                        break;                    case PropertyType.BOOLEAN:                    case PropertyType.DATE:                    case PropertyType.DOUBLE:                    case PropertyType.LONG:                    case PropertyType.REFERENCE:                        throw new ValueFormatException("conversion failed: "                                + PropertyType.nameFromValue(srcType) + " to "                                + PropertyType.nameFromValue(targetType));                    default:                        throw new IllegalArgumentException("not a valid type constant: " + srcType);                }                break;            case PropertyType.REFERENCE:                // convert to REFERENCE                switch (srcType) {                    case PropertyType.REFERENCE:                        // no conversion needed, return original value                        // (redundant code, just here for the sake of clarity)                        return srcValue;                    case PropertyType.BINARY:                    case PropertyType.STRING:                        // try conversion via string                        String uuid;                        try {                            // get string value                            uuid = srcValue.getString();                        } catch (RepositoryException re) {                            // should never happen                            throw new ValueFormatException("failed to convert source value to REFERENCE value", re);                        }                        val = factory.createValue(uuid, targetType);                        break;                    case PropertyType.BOOLEAN:                    case PropertyType.DATE:                    case PropertyType.DOUBLE:                    case PropertyType.LONG:                    case PropertyType.PATH:                    case PropertyType.NAME:                        throw new ValueFormatException("conversion failed: "                                + PropertyType.nameFromValue(srcType) + " to "                                + PropertyType.nameFromValue(targetType));                    default:                        throw new IllegalArgumentException("not a valid type constant: " + srcType);                }                break;            default:                throw new IllegalArgumentException("not a valid type constant: " + targetType);        }        return val;    }    /**     * Same as {@link #copy(Value, ValueFactory)} using <code>ValueFactoryImpl</code>.     *     * @param srcValue     * @throws IllegalStateException     * @deprecated Use {@link #copy(Value, ValueFactory)} instead.     */    public static Value copy(Value srcValue) throws IllegalStateException {        return copy(srcValue, ValueFactoryImpl.getInstance());    }    /**     *     * @param srcValue     * @param factory     * @throws IllegalStateException     */    public static Value copy(Value srcValue, ValueFactory factory)        throws IllegalStateException {        if (srcValue == null) {            return null;        }        Value newVal = null;        try {            switch (srcValue.getType()) {                case PropertyType.BINARY:                    newVal = factory.createValue(srcValue.getStream());                    break;                case PropertyType.BOOLEAN:                    newVal = factory.createValue(srcValue.getBoolean());                    break;                case PropertyType.DATE:                    newVal = factory.createValue(srcValue.getDate());                    break;                case PropertyType.DOUBLE:                    newVal = factory.createValue(srcValue.getDouble());                    break;                case PropertyType.LONG:                    newVal = factory.createValue(srcValue.getLong());                    break;                case PropertyType.PATH:                case PropertyType.NAME:                case PropertyType.REFERENCE:                    newVal = factory.createValue(srcValue.getString(), srcValue.getType());                    break;                case PropertyType.STRING:                    newVal = factory.createValue(srcValue.getString());                    break;            }        } catch (RepositoryException re) {            // should never get here        }        return newVal;    }    /**     * Same as {@link #copy(Value[], ValueFactory)} using <code>ValueFactoryImpl</code>.     *     * @param srcValues

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -