Package org.restlet.engine.converter

Examples of org.restlet.engine.converter.ConverterHelper


    public <T> T toObject(Representation source, Class<T> target,
            UniformResource resource) throws IOException {
        T result = null;

        if ((source != null) && source.isAvailable() && (source.getSize() != 0)) {
            ConverterHelper ch = ConverterUtils.getBestHelper(source, target,
                    resource);

            if (ch != null) {
                Context.getCurrentLogger().fine(
                        "The following converter was selected for the "
                                + source + " representation: " + ch);

                result = ch.toObject(source, target, resource);

                if (result instanceof Representation) {
                    Representation resultRepresentation = (Representation) result;

                    // Copy the variant metadata
View Full Code Here


     * @return The converted representation.
     */
    public Representation toRepresentation(Object source, Variant target,
            UniformResource resource) {
        Representation result = null;
        ConverterHelper ch = ConverterUtils.getBestHelper(source, target,
                resource);

        if (ch != null) {
            try {
                boolean loggable = (resource == null) ? true : resource
                        .isLoggable();

                if (loggable
                        && Context.getCurrentLogger().isLoggable(Level.FINE)) {
                    Context.getCurrentLogger().fine(
                            "Converter selected for "
                                    + source.getClass().getSimpleName() + ": "
                                    + ch.getClass().getSimpleName());
                }

                if (target == null) {
                    List<VariantInfo> variants = ch.getVariants(source
                            .getClass());

                    if ((variants != null) && !variants.isEmpty()) {
                        if (resource != null) {
                            target = resource.getClientInfo()
                                    .getPreferredVariant(variants,
                                            resource.getMetadataService());
                        } else {
                            target = variants.get(0);
                        }
                    } else {
                        target = new Variant();
                    }
                }

                result = ch.toRepresentation(source, target, resource);

                if (result != null) {
                    // Copy the variant metadata if necessary
                    if (result.getCharacterSet() == null) {
                        result.setCharacterSet(target.getCharacterSet());
View Full Code Here

TOP

Related Classes of org.restlet.engine.converter.ConverterHelper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.