com.thoughtworks.xstream.converters.ConversionException Java Examples

The following examples show how to use com.thoughtworks.xstream.converters.ConversionException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: smarthome   Author: eclipse-archived   File: ChannelXmlResult.java    License: Eclipse Public License 2.0 6 votes vote down vote up
protected ChannelDefinition toChannelDefinition(String bindingId) throws ConversionException {
    String id = getId();
    String typeId = getTypeId();

    String typeUID = getTypeUID(bindingId, typeId);

    // Convert the channel properties into a map
    Map<String, String> propertiesMap = new HashMap<>();
    for (NodeValue property : getProperties()) {
        propertiesMap.put(property.getAttributes().get("name"), (String) property.getValue());
    }

    return new ChannelDefinitionBuilder(id, new ChannelTypeUID(typeUID)).withProperties(propertiesMap)
            .withLabel(getLabel()).withDescription(getDescription()).withAutoUpdatePolicy(getAutoUpdatePolicy())
            .build();
}
 
Example #2
Source Project: lams   Author: lamsfoundation   File: CGLIBEnhancedConverter.java    License: GNU General Public License v2.0 6 votes vote down vote up
private Callback createReverseEngineeredCallbackOfProperType(Callback callback, int index,
    Map callbackIndexMap) {
    Class iface = null;
    Class[] interfaces = callback.getClass().getInterfaces();
    for (int i = 0; i < interfaces.length; i++ ) {
        if (Callback.class.isAssignableFrom(interfaces[i])) {
            iface = interfaces[i];
            if (iface == Callback.class) {
                ConversionException exception = new ConversionException(
                    "Cannot handle CGLIB callback");
                exception.add("CGLIB-callback-type", callback.getClass().getName());
                throw exception;
            }
            interfaces = iface.getInterfaces();
            if (Arrays.asList(interfaces).contains(Callback.class)) {
                break;
            }
            i = -1;
        }
    }
    return (Callback)Proxy.newProxyInstance(
        iface.getClassLoader(), new Class[]{iface},
        new ReverseEngineeringInvocationHandler(index, callbackIndexMap));
}
 
Example #3
Source Project: Chronicle-Map   Author: OpenHFT   File: AbstractChronicleMapConverter.java    License: Apache License 2.0 6 votes vote down vote up
private static Class forName(String clazz) {

        try {
            return Class.forName(clazz);
        } catch (ClassNotFoundException e) {

            boolean isNative = clazz.endsWith($$NATIVE);
            boolean isHeap = clazz.endsWith($$HEAP);

            if (!isNative && !isHeap)
                throw new ConversionException("class=" + clazz, e);

            final String nativeInterface = isNative ?
                    clazz.substring(0, clazz.length() - $$NATIVE.length()) :
                    clazz.substring(0, clazz.length() - $$HEAP.length());
            try {
                Values.newNativeReference(Class.forName(clazz));
                return Class.forName(nativeInterface);
            } catch (Exception e1) {
                throw new ConversionException("class=" + clazz, e1);
            }
        }
    }
 
Example #4
Source Project: smarthome   Author: eclipse-archived   File: NodeIterator.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Returns the next attribute if the specified name of the node fits to the next node
 * and the attribute with the specified name could be found, or {@code null} if the
 * node or attribute does not exist. In the last case the iterator will <i>not</i>
 * increase its iteration counter.
 * <p>
 * The next node must be of the type {@link NodeAttributes}.
 *
 * @param nodeName the name of the node to be read next (must neither be null, nor empty)
 * @param attributeName the name of the attribute of the node to be read next
 *            (must neither be null, nor empty)
 * @param required true if the occurrence of the node's attribute has to be ensured
 * @return the next attribute of the specified name of the node and attribute
 *         (could be null or empty)
 * @throws ConversionException if the specified node's attribute could not be found in the
 *             next node however it was specified as required
 */
public String nextAttribute(String nodeName, String attributeName, boolean required) throws ConversionException {
    if (hasNext()) {
        Object nextNode = next();

        if (nextNode instanceof NodeAttributes) {
            if (nodeName.equals(((NodeName) nextNode).getNodeName())) {
                return ((NodeAttributes) nextNode).getAttribute(attributeName);
            }
        }

        this.index--;
    }

    if (required) {
        throw new ConversionException("The attribute '" + attributeName + "' in the node '" + nodeName
                + "' is missing!");
    }

    return null;
}
 
Example #5
Source Project: smarthome   Author: eclipse-archived   File: ChannelGroupTypeConverter.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected ChannelGroupTypeXmlResult unmarshalType(HierarchicalStreamReader reader, UnmarshallingContext context,
        Map<String, String> attributes, NodeIterator nodeIterator) throws ConversionException {
    ChannelGroupTypeUID channelGroupTypeUID = new ChannelGroupTypeUID(super.getUID(attributes, context));

    boolean advanced = isAdvanced(attributes, false);

    String label = super.readLabel(nodeIterator);
    String description = super.readDescription(nodeIterator);
    String category = readCategory(nodeIterator);
    List<ChannelXmlResult> channelTypeDefinitions = readChannelTypeDefinitions(nodeIterator);

    ChannelGroupTypeXmlResult groupChannelType = new ChannelGroupTypeXmlResult(channelGroupTypeUID, advanced, label,
            description, category, channelTypeDefinitions);

    return groupChannelType;
}
 
Example #6
Source Project: lams   Author: lamsfoundation   File: JavaFieldConverter.java    License: GNU General Public License v2.0 6 votes vote down vote up
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    String methodName = null;
    String declaringClassName = null;
    
    while((methodName == null || declaringClassName == null) && reader.hasMoreChildren()) {
        reader.moveDown();
        
        if (reader.getNodeName().equals("name")) {
            methodName = reader.getValue();
        } else if (reader.getNodeName().equals("clazz")) {
            declaringClassName = reader.getValue();
        }
        reader.moveUp();
    }
    
    Class declaringClass = (Class)javaClassConverter.fromString(declaringClassName);
    try {
        return declaringClass.getDeclaredField(mapper.realMember(declaringClass, methodName));
    } catch (NoSuchFieldException e) {
        throw new ConversionException(e);
    }
}
 
Example #7
Source Project: lams   Author: lamsfoundation   File: StackTraceElementConverter.java    License: GNU General Public License v2.0 6 votes vote down vote up
public Object fromString(String str) {
    Matcher matcher = PATTERN.matcher(str);
    if (matcher.matches()) {
        String declaringClass = matcher.group(1);
        String methodName = matcher.group(2);
        String fileName = matcher.group(3);
        if (fileName.equals("Unknown Source")) {
            return FACTORY.unknownSourceElement(declaringClass, methodName);
        } else if (fileName.equals("Native Method")) {
            return FACTORY.nativeMethodElement(declaringClass, methodName);
        } else {
            if (matcher.group(4) != null) {
                int lineNumber = Integer.parseInt(matcher.group(5));
                return FACTORY.element(declaringClass, methodName, fileName, lineNumber);
            } else {
                return FACTORY.element(declaringClass, methodName, fileName);
            }
        }
    } else {
        throw new ConversionException("Could not parse StackTraceElement : " + str);
    }
}
 
Example #8
Source Project: lams   Author: lamsfoundation   File: XStream.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Deserialize an object from a hierarchical data structure (such as XML).
 * 
 * @param root If present, the passed in object will have its fields populated, as opposed
 *            to XStream creating a new instance. Note, that this is a special use case!
 *            With the ReflectionConverter XStream will write directly into the raw memory
 *            area of the existing object. Use with care!
 * @param dataHolder Extra data you can use to pass to your converters. Use this as you
 *            want. If not present, XStream shall create one lazily as needed.
 * @throws XStreamException if the object cannot be deserialized
 */
public Object unmarshal(HierarchicalStreamReader reader, Object root, DataHolder dataHolder) {
    try {
        if (!securityInitialized && !securityWarningGiven) {
            securityWarningGiven = true;
            System.err.println("Security framework of XStream not initialized, XStream is probably vulnerable.");
        }
        return marshallingStrategy.unmarshal(
            root, reader, dataHolder, converterLookup, mapper);

    } catch (ConversionException e) {
        Package pkg = getClass().getPackage();
        String version = pkg != null ? pkg.getImplementationVersion() : null;
        e.add("version", version != null ? version : "not available");
        throw e;
    }
}
 
Example #9
Source Project: lams   Author: lamsfoundation   File: ThreadSafePropertyEditor.java    License: GNU General Public License v2.0 6 votes vote down vote up
public ThreadSafePropertyEditor(Class type, int initialPoolSize, int maxPoolSize) {
    if (!PropertyEditor.class.isAssignableFrom(type)) {
        throw new IllegalArgumentException(type.getName()
            + " is not a "
            + PropertyEditor.class.getName());
    }
    editorType = type;
    pool = new Pool(initialPoolSize, maxPoolSize, new Pool.Factory() {
        public Object newInstance() {
            ErrorWritingException ex = null;
            try {
                return editorType.newInstance();
            } catch (InstantiationException e) {
                ex = new ConversionException("Faild to call default constructor", e);
            } catch (IllegalAccessException e) {
                ex = new ObjectAccessException("Cannot call default constructor", e);
            }
            ex.add("construction-type", editorType.getName());
            throw ex;
        }

    });
}
 
Example #10
Source Project: smarthome   Author: eclipse-archived   File: ConverterValueMap.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Reads-in {@code N} children in a key-value map and returns it.
 *
 * @param reader the reader to be used to read-in the children (must not be null)
 * @param numberOfValues the number of children to be read in (< 0 = until end of section)
 * @param context
 * @return the key-value map containing the read-in children (not null, could be empty)
 * @throws ConversionException if not all children could be read-in
 */
public static Map<String, Object> readValueMap(HierarchicalStreamReader reader, int numberOfValues,
        UnmarshallingContext context) throws ConversionException {
    Map<String, Object> valueMap = new HashMap<>((numberOfValues >= 0) ? numberOfValues : 10);
    int counter = 0;

    while (reader.hasMoreChildren() && ((counter < numberOfValues) || (numberOfValues == -1))) {
        reader.moveDown();
        if (reader.hasMoreChildren()) {
            List<?> list = (List<?>) context.convertAnother(context, List.class);
            valueMap.put(reader.getNodeName(), list);
        } else {
            valueMap.put(reader.getNodeName(), reader.getValue());
        }
        reader.moveUp();
        counter++;
    }

    if ((counter < numberOfValues) && (numberOfValues > 0)) {
        throw new ConversionException("Not all children could be read-in!");
    }

    return valueMap;
}
 
Example #11
Source Project: smarthome   Author: eclipse-archived   File: EventDescriptionConverter.java    License: Eclipse Public License 2.0 6 votes vote down vote up
private EventOption toEventOption(NodeValue nodeValue) throws ConversionException {
    if ("option".equals(nodeValue.getNodeName())) {
        String value;
        String label;

        Map<String, String> attributes = nodeValue.getAttributes();
        if ((attributes != null) && (attributes.containsKey("value"))) {
            value = attributes.get("value");
        } else {
            throw new ConversionException("The node 'option' requires the attribute 'value'!");
        }

        label = (String) nodeValue.getValue();

        return new EventOption(value, label);
    }

    throw new ConversionException("Unknown type in the list of 'options'!");
}
 
Example #12
Source Project: openhab-core   Author: openhab   File: ChannelTypeConverter.java    License: Eclipse Public License 2.0 6 votes vote down vote up
private Set<String> readTags(NodeIterator nodeIterator) throws ConversionException {
    Set<String> tags = null;

    List<?> tagsNode = nodeIterator.nextList("tags", false);

    if (tagsNode != null) {
        tags = new HashSet<>(tagsNode.size());

        for (Object tagNodeObject : tagsNode) {
            NodeValue tagNode = (NodeValue) tagNodeObject;

            if ("tag".equals(tagNode.getNodeName())) {
                String tag = (String) tagNode.getValue();

                if (tag != null) {
                    tags.add(tag);
                }
            } else {
                throw new ConversionException("The 'tags' node must only contain 'tag' nodes!");
            }
        }
    }

    return tags;
}
 
Example #13
Source Project: openhab-core   Author: openhab   File: ChannelXmlResult.java    License: Eclipse Public License 2.0 6 votes vote down vote up
protected ChannelDefinition toChannelDefinition(String bindingId) throws ConversionException {
    String id = getId();
    String typeId = getTypeId();

    String typeUID = getTypeUID(bindingId, typeId);

    // Convert the channel properties into a map
    Map<String, String> propertiesMap = new HashMap<>();
    for (NodeValue property : getProperties()) {
        propertiesMap.put(property.getAttributes().get("name"), (String) property.getValue());
    }

    return new ChannelDefinitionBuilder(id, new ChannelTypeUID(typeUID)).withProperties(propertiesMap)
            .withLabel(getLabel()).withDescription(getDescription()).withAutoUpdatePolicy(getAutoUpdatePolicy())
            .build();
}
 
Example #14
Source Project: smarthome   Author: eclipse-archived   File: ChannelTypeConverter.java    License: Eclipse Public License 2.0 6 votes vote down vote up
private Set<String> readTags(NodeIterator nodeIterator) throws ConversionException {
    Set<String> tags = null;

    List<?> tagsNode = nodeIterator.nextList("tags", false);

    if (tagsNode != null) {
        tags = new HashSet<>(tagsNode.size());

        for (Object tagNodeObject : tagsNode) {
            NodeValue tagNode = (NodeValue) tagNodeObject;

            if ("tag".equals(tagNode.getNodeName())) {
                String tag = (String) tagNode.getValue();

                if (tag != null) {
                    tags.add(tag);
                }
            } else {
                throw new ConversionException("The 'tags' node must only contain 'tag' nodes!");
            }
        }
    }

    return tags;
}
 
Example #15
Source Project: openhab-core   Author: openhab   File: NodeIterator.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Returns the next attribute if the specified name of the node fits to the next node
 * and the attribute with the specified name could be found, or {@code null} if the
 * node or attribute does not exist. In the last case the iterator will <i>not</i>
 * increase its iteration counter.
 * <p>
 * The next node must be of the type {@link NodeAttributes}.
 *
 * @param nodeName the name of the node to be read next (must neither be null, nor empty)
 * @param attributeName the name of the attribute of the node to be read next
 *            (must neither be null, nor empty)
 * @param required true if the occurrence of the node's attribute has to be ensured
 * @return the next attribute of the specified name of the node and attribute
 *         (could be null or empty)
 * @throws ConversionException if the specified node's attribute could not be found in the
 *             next node however it was specified as required
 */
public String nextAttribute(String nodeName, String attributeName, boolean required) throws ConversionException {
    if (hasNext()) {
        Object nextNode = next();

        if (nextNode instanceof NodeAttributes) {
            if (nodeName.equals(((NodeName) nextNode).getNodeName())) {
                return ((NodeAttributes) nextNode).getAttribute(attributeName);
            }
        }

        this.index--;
    }

    if (required) {
        throw new ConversionException(
                "The attribute '" + attributeName + "' in the node '" + nodeName + "' is missing!");
    }

    return null;
}
 
Example #16
Source Project: ET_Redux   Author: CIRDLES   File: SampleMetaData.java    License: Apache License 2.0 5 votes vote down vote up
/**
     * decodes <code>ValueModel</code> from <code>file</code> specified by
     * argument <code>filename</code>
     *
     * @param filename location to read data from
     * @param doValidate the value of doValidate
     * @return <code>Object</code> - the <code>ValueModel</code> created from
     * the specified XML <code>file</code>
     * @throws java.io.FileNotFoundException
     * @throws org.earthtime.XMLExceptions.BadOrMissingXMLSchemaException
     * @pre <code>filename</code> references an XML <code>file</code>
     * @post <code>ValueModel</code> stored in <code>filename</code> is returned
     */
    public Object readXMLObject(String filename, boolean doValidate)
            throws FileNotFoundException, ETException, FileNotFoundException, BadOrMissingXMLSchemaException {
        SampleMetaData mySampleMetaData = null;

        BufferedReader reader = URIHelper.getBufferedReader(filename);

        if (reader != null) {
            boolean validXML = false;
            XStream xstream = getXStreamReader();

            validXML = true;//URIHelper.validateXML(reader, getSampleMetaDataXMLSchemaURL());

            if (validXML) {
                // re-create reader
                reader = URIHelper.getBufferedReader(filename);
                try {
                    mySampleMetaData = (SampleMetaData) xstream.fromXML(reader);
                } catch (ConversionException e) {
                    throw new ETException(null, e.getMessage());
                }

//                System.out.println("\nThis is your SampleMetaData that was just read successfully:\n");
//                String xml2 = getXStreamWriter().toXML(mySampleMetaData);
//
//                System.out.println(xml2);
//                System.out.flush();
            }

        } else {
            throw new FileNotFoundException("Badly formed or missing XML data file.");
        }

        return mySampleMetaData;
    }
 
Example #17
Source Project: ET_Redux   Author: CIRDLES   File: ReportSettingsInterface.java    License: Apache License 2.0 5 votes vote down vote up
/**
 *
 *
 * @param filename
 * @param doValidate the value of doValidate
 * @return
 * @throws FileNotFoundException
 * @throws ETException
 * @throws BadOrMissingXMLSchemaException
 */
@Override
public default Object readXMLObject(String filename, boolean doValidate)
        throws FileNotFoundException, ETException, FileNotFoundException, BadOrMissingXMLSchemaException {
    ReportSettingsInterface myReportSettings = null;

    BufferedReader reader = URIHelper.getBufferedReader(filename);

    if (reader != null) {
        boolean isValidOrAirplaneMode = true;

        XStream xstream = getXStreamReader();

        if (doValidate) {
            isValidOrAirplaneMode = URIHelper.validateXML(reader, filename, getReportSettingsXMLSchemaURL());
        }

        if (isValidOrAirplaneMode) {
            // re-create reader
            reader = URIHelper.getBufferedReader(filename);
            try {
                myReportSettings = (ReportSettingsInterface) xstream.fromXML(reader);
            } catch (ConversionException e) {
                throw new ETException(null, e.getMessage());
            }

        } else {
            throw new ETException(null, "XML data file does not conform to schema.");
        }
    } else {
        throw new FileNotFoundException("Missing XML data file.");
    }

    return myReportSettings;
}
 
Example #18
Source Project: lams   Author: lamsfoundation   File: CGLIBEnhancedConverter.java    License: GNU General Public License v2.0 5 votes vote down vote up
public int accept(Method method) {
    if (!callbackIndexMap.containsKey(method)) {
        ConversionException exception = new ConversionException(
            "CGLIB callback not detected in reverse engineering");
        exception.add("CGLIB-callback", method.toString());
        throw exception;
    }
    return ((Integer)callbackIndexMap.get(method)).intValue();
}
 
Example #19
Source Project: lams   Author: lamsfoundation   File: AbstractReflectionConverter.java    License: GNU General Public License v2.0 5 votes vote down vote up
public boolean add(Object object) {
    if (object == null) {
        boolean containsNull = !map.containsKey(null);
        map.put(null, null);
        return containsNull;
    }
    Class itemType = object.getClass();

    if (keyFieldName != null) {
        Field field = (Field)fieldCache.get(itemType);
        if (field == null) {
            field = reflectionProvider.getField(itemType, keyFieldName);
            fieldCache.put(itemType, field);
        }
        if (field != null) {
            Object key = Fields.read(field, object);
            return map.put(key, object) == null;
        }
    } else if (object instanceof Map.Entry) {
        final Map.Entry entry = (Map.Entry)object;
        return map.put(entry.getKey(), entry.getValue()) == null;
    }

    ConversionException exception =
            new ConversionException("Element  is not defined as entry for implicit map");
    exception.add("map-type", map.getClass().getName());
    exception.add("element-type", object.getClass().getName());
    throw exception;
}
 
Example #20
Source Project: lams   Author: lamsfoundation   File: AbstractAttributedCharacterIteratorAttributeConverter.java    License: GNU General Public License v2.0 5 votes vote down vote up
public Object fromString(final String str) {
    if (attributeMap.containsKey(str)) {
        return attributeMap.get(str);
    }
    ConversionException exception = new ConversionException("Cannot find attribute");
    exception.add("attribute-type", type.getName());
    exception.add("attribute-name", str);
    throw exception;
}
 
Example #21
Source Project: ET_Redux   Author: CIRDLES   File: InitialPbModel.java    License: Apache License 2.0 5 votes vote down vote up
/**
     *
     *
     * @param filename
     * @param doValidate the value of doValidate
     * @return
     * @throws FileNotFoundException
     * @throws ETException
     * @throws BadOrMissingXMLSchemaException
     */
    public Object readXMLObject ( String filename, boolean doValidate )
            throws FileNotFoundException, ETException, FileNotFoundException, BadOrMissingXMLSchemaException {
        InitialPbModel myInitialPbModel = null;

        BufferedReader reader = URIHelper.getBufferedReader( filename );

        if ( reader != null ) {
            boolean temp = false;
            XStream xstream = getXStreamReader();

            temp = URIHelper.validateXML( reader, filename, initialPbModelXMLSchemaURL );

            if ( temp ) {
                // re-create reader
                reader = URIHelper.getBufferedReader( filename );
                try {
                    myInitialPbModel = (InitialPbModel) xstream.fromXML( reader );
                } catch (ConversionException e) {
                    throw new ETException( null, e.getMessage() );
                }

//                System.out.println( "This is your InitialPbModel that was just read successfully:\n" );
//
//                String xml2 = getXStreamWriter().toXML( myInitialPbModel );
//
//                System.out.println( xml2 );
//                System.out.flush();
            }

        } else {
            throw new FileNotFoundException( "Badly formed or missing XML data file." );
        }



        return myInitialPbModel;
    }
 
Example #22
Source Project: lams   Author: lamsfoundation   File: LocalDateTimeConverter.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public Object fromString(final String str) {
    try {
        return LocalDateTime.parse(str);
    } catch (final DateTimeParseException e) {
        final ConversionException exception = new ConversionException("Cannot parse value as local date time", e);
        exception.add("value", str);
        throw exception;
    }
}
 
Example #23
Source Project: sakai   Author: sakaiproject   File: VersionedExternalizable.java    License: Educational Community License v2.0 5 votes vote down vote up
@Override
public Object doUnmarshal(final Object result, final HierarchicalStreamReader reader, final UnmarshallingContext context) {
	final String currentVersion = ((VersionedExternalizable) result).getExternalizableVersion();
	final String oldVersion = reader.getAttribute(VERSION_ATTRIBUTE);
	if ((oldVersion == null) || !currentVersion.equals(oldVersion)) {
		// This is one place we might put a version translation method in the future....
		throw new ConversionException("Cannot convert " + result + " from version " + oldVersion + " to version " + currentVersion);
	}
	return super.doUnmarshal(result, reader, context);
      }
 
Example #24
Source Project: ET_Redux   Author: CIRDLES   File: UPbReduxAliquot.java    License: Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param filename
 * @param doValidate
 * @return
 * @throws FileNotFoundException
 * @throws ETException
 * @throws BadOrMissingXMLSchemaException
 */
@Override
public Object readXMLObject(String filename, boolean doValidate)
        throws FileNotFoundException,
        ETException,
        FileNotFoundException,
        BadOrMissingXMLSchemaException {

    AliquotInterface myAliquot = null;

    BufferedReader reader = URIHelper.getBufferedReader(filename);

    if (reader != null) {
        boolean isValidOrAirplaneMode = true;

        XStream xstream = getXStreamReader();

        if (doValidate) {
            isValidOrAirplaneMode = URIHelper.validateXML(reader, filename, aliquotXMLSchemaURL);
        }

        if (isValidOrAirplaneMode) {
            // re-create reader
            reader = URIHelper.getBufferedReader(filename);
            try {
                myAliquot = (AliquotInterface) xstream.fromXML(reader);
            } catch (ConversionException e) {
                throw new ETException(null, e.getMessage());
            }
        } else {
            throw new ETException(null, "XML data file does not conform to schema.");
        }
    } else {
        throw new FileNotFoundException("Missing XML data file.");
    }

    return myAliquot;
}
 
Example #25
Source Project: lams   Author: lamsfoundation   File: DurationConverter.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public Duration fromString(final String str) {
    try {
        return Duration.parse(str);
    } catch (final DateTimeParseException ex) {
        final ConversionException exception = new ConversionException("Cannot parse value as duration", ex);
        exception.add("value", str);
        throw exception;
    }
}
 
Example #26
Source Project: lams   Author: lamsfoundation   File: OffsetTimeConverter.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public Object fromString(final String str) {
    try {
        return OffsetTime.parse(str);
    } catch (final DateTimeParseException e) {
        final ConversionException exception = new ConversionException("Cannot parse value as offset time", e);
        exception.add("value", str);
        throw exception;
    }
}
 
Example #27
Source Project: lams   Author: lamsfoundation   File: ChronologyConverter.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public Chronology fromString(final String str) {
    if (str == null) {
        return null;
    }
    try {
        return Chronology.of(str);
    } catch (final DateTimeException e) {
        final ConversionException exception = new ConversionException("Cannot parse value as chronology", e);
        exception.add("value", str);
        throw exception;
    }
}
 
Example #28
Source Project: lams   Author: lamsfoundation   File: OffsetDateTimeConverter.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public Object fromString(final String str) {
    try {
        return OffsetDateTime.parse(str);
    } catch (final DateTimeParseException e) {
        final ConversionException exception = new ConversionException("Cannot parse value as offset date time", e);
        exception.add("value", str);
        throw exception;
    }
}
 
Example #29
Source Project: lams   Author: lamsfoundation   File: InstantConverter.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public Instant fromString(final String str) {
    try {
        return Instant.parse(str);
    } catch (final DateTimeParseException ex) {
        final ConversionException exception = new ConversionException("Cannot parse value as instant", ex);
        exception.add("value", str);
        throw exception;
    }
}
 
Example #30
Source Project: lams   Author: lamsfoundation   File: JapaneseEraConverter.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public JapaneseEra fromString(final String str) {
    if (str == null) {
        return null;
    }
    try {
        return JapaneseEra.valueOf(str);
    } catch (final IllegalArgumentException e) {
        final ConversionException exception = new ConversionException("Cannot parse value as Japanese era", e);
        exception.add("value", str);
        throw exception;
    }
}