当前位置: 首页>>代码示例>>Java>>正文


Java Resource类代码示例

本文整理汇总了Java中org.restlet.resource.Resource的典型用法代码示例。如果您正苦于以下问题:Java Resource类的具体用法?Java Resource怎么用?Java Resource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Resource类属于org.restlet.resource包,在下文中一共展示了Resource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: score

import org.restlet.resource.Resource; //导入依赖的package包/类
@Override
public float score(Object source, Variant target, Resource resource) {
    float result = -1.0F;

    if (source instanceof Document) {
        if (target == null) {
            result = 0.5F;
        } else if (MediaType.APPLICATION_ALL_XML.isCompatible(target
                .getMediaType())) {
            result = 0.8F;
        } else if (MediaType.APPLICATION_XML.isCompatible(target
                .getMediaType())) {
            result = 0.9F;
        } else if (MediaType.TEXT_XML.isCompatible(target.getMediaType())) {
            result = 0.9F;
        } else {
            result = 0.5F;
        }
    }

    return result;
}
 
开发者ID:restlet,项目名称:restlet-framework,代码行数:23,代码来源:XmlConverter.java

示例2: score

import org.restlet.resource.Resource; //导入依赖的package包/类
@Override
public float score(Object source, Variant target, Resource resource) {
    float result = -1.0F;

    if (source != null
            && (source instanceof JaxbRepresentation<?> || isJaxbRootElementClass(source
                    .getClass()))) {
        if (target == null) {
            result = 0.8F;
        } else if (isCompatible(target.getMediaType())) {
            result = 1.0F;
        } else {
            // Allow for JAXB object to be used for JSON and other
            // representations
            result = 0.7F;
        }
    }

    return result;
}
 
开发者ID:restlet,项目名称:restlet-framework,代码行数:21,代码来源:JaxbConverter.java

示例3: toObject

import org.restlet.resource.Resource; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <T> T toObject(Representation source, Class<T> target,
        Resource resource) throws IOException {
    JaxbRepresentation<?> jaxbSource = null;
    if (source instanceof JaxbRepresentation) {
        jaxbSource = (JaxbRepresentation<?>) source;
    } else {
        jaxbSource = new JaxbRepresentation<T>(source, target);
    }

    T result = null;
    if (target == null) {
        result = (T) jaxbSource.getObject();
    } else if (JaxbRepresentation.class.isAssignableFrom(target)) {
        result = target.cast(jaxbSource);
    } else if (isJaxbRootElementClass(target)) {
        result = target.cast(jaxbSource.getObject());
    }

    return result;
}
 
开发者ID:restlet,项目名称:restlet-framework,代码行数:23,代码来源:JaxbConverter.java

示例4: toRepresentation

import org.restlet.resource.Resource; //导入依赖的package包/类
@Override
public Representation toRepresentation(Object source, Variant target,
        Resource resource) throws IOException {

    if (source instanceof TemplateResolution) {
        Locale locale = getLocale(resource);

        TemplateRepresentation tr = new TemplateRepresentation(
                ((TemplateResolution) source).getTemplateResource().getBaseName(), locale,
                target.getMediaType());
        tr.setDataModel(resource.getRequest(), resource.getResponse());
        return tr;
    }

    return null;
}
 
开发者ID:restlet,项目名称:restlet-framework,代码行数:17,代码来源:ThymeleafConverter.java

示例5: score

import org.restlet.resource.Resource; //导入依赖的package包/类
@Override
public float score(Object source, Variant target, Resource resource) {
    float result = -1.0F;

    if (source instanceof GsonRepresentation<?>) {
        result = 1.0F;
    } else {
        if (target == null) {
            result = 0.5F;
        } else if (VARIANT_JSON.isCompatible(target)) {
            result = 0.8F;
        } else {
            result = 0.5F;
        }
    }

    return result;
}
 
开发者ID:restlet,项目名称:restlet-framework,代码行数:19,代码来源:GsonConverter.java

示例6: toRepresentation

import org.restlet.resource.Resource; //导入依赖的package包/类
@Override
public Representation toRepresentation(Object source, Variant target,
        Resource resource) throws IOException {
    Representation result = null;

    if (source instanceof GsonRepresentation) {
        result = (GsonRepresentation<?>) source;
    } else {
        if (target.getMediaType() == null) {
            target.setMediaType(MediaType.APPLICATION_JSON);
        }

        if (VARIANT_JSON.isCompatible(target)) {
            GsonRepresentation<Object> gsonRepresentation = create(source);
            result = gsonRepresentation;
        }
    }

    return result;
}
 
开发者ID:restlet,项目名称:restlet-framework,代码行数:21,代码来源:GsonConverter.java

示例7: score

import org.restlet.resource.Resource; //导入依赖的package包/类
@Override
public float score(Object source, Variant target, Resource resource) {
    float result = -1.0F;

    if (source instanceof JacksonRepresentation<?>) {
        result = 1.0F;
    } else {
        if (target == null) {
            result = 0.5F;
        } else if (isCompatible(target)) {
            result = 0.8F;
        } else {
            result = 0.5F;
        }
    }

    return result;
}
 
开发者ID:restlet,项目名称:restlet-framework,代码行数:19,代码来源:JacksonConverter.java

示例8: toObject

import org.restlet.resource.Resource; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <T> T toObject(Representation source, Class<T> target,
        Resource resource) throws IOException {
    Object result = null;

    // The source for the Jackson conversion
    JacksonRepresentation<?> jacksonSource = null;
    if (source instanceof JacksonRepresentation) {
        jacksonSource = (JacksonRepresentation<?>) source;
    } else if (isCompatible(source)) {
        jacksonSource = create(source, target);
    }

    if (jacksonSource != null) {
        // Handle the conversion
        if ((target != null)
                && JacksonRepresentation.class.isAssignableFrom(target)) {
            result = jacksonSource;
        } else {
            result = jacksonSource.getObject();
        }
    }

    return (T) result;
}
 
开发者ID:restlet,项目名称:restlet-framework,代码行数:27,代码来源:JacksonConverter.java

示例9: toRepresentation

import org.restlet.resource.Resource; //导入依赖的package包/类
@Override
public Representation toRepresentation(Object source, Variant target,
        Resource resource) {
    Representation result = null;

    if (source instanceof JacksonRepresentation) {
        result = (JacksonRepresentation<?>) source;
    } else {
        if (target.getMediaType() == null) {
            target.setMediaType(MediaType.APPLICATION_JSON);
        }
        if (isCompatible(target)) {
            result = create(target.getMediaType(), source);
        }
    }

    return result;
}
 
开发者ID:restlet,项目名称:restlet-framework,代码行数:19,代码来源:JacksonConverter.java

示例10: score

import org.restlet.resource.Resource; //导入依赖的package包/类
@Override
public float score(Object source, Variant target, Resource resource) {
    float result = -1.0F;

    if (source instanceof FormDataSet) {
        if (target == null) {
            result = 0.5F;
        } else if (MediaType.APPLICATION_WWW_FORM.isCompatible(target
                .getMediaType())
                || MediaType.MULTIPART_FORM_DATA.isCompatible(target
                        .getMediaType())) {
            result = 1.0F;
        } else {
            result = 0.5F;
        }
    }

    return result;
}
 
开发者ID:restlet,项目名称:restlet-framework,代码行数:20,代码来源:HtmlConverter.java

示例11: getBestHelper

import org.restlet.resource.Resource; //导入依赖的package包/类
/**
 * Returns the best converter helper matching the given parameters.
 * 
 * @param source
 *            The object to convert to a representation.
 * @param target
 *            The target representation variant.
 * @param resource
 *            The optional parent resource.
 * @return The matched converter helper or null.
 */
public static ConverterHelper getBestHelper(Object source, Variant target,
        Resource resource) {
    ConverterHelper result = null;
    float bestScore = -1.0F;
    float currentScore;

    for (ConverterHelper ch : Engine.getInstance()
            .getRegisteredConverters()) {
        if (ch != null) {
            try {
                currentScore = ch.score(source, target, resource);

                if (currentScore > bestScore) {
                    bestScore = currentScore;
                    result = ch;
                }
            } catch (Exception e) {
                Context.getCurrentLogger().error("Unable get the score of the " + ch
                                + " converter helper.", e);
            }
        }
    }

    return result;
}
 
开发者ID:restlet,项目名称:restlet-framework,代码行数:37,代码来源:ConverterUtils.java

示例12: score

import org.restlet.resource.Resource; //导入依赖的package包/类
@Override
public <T> float score( Representation source, Class<T> target,
                        Resource resource
)
{
    float result = -1.0F;

    if( source instanceof JsonRepresentation<?> )
    {
        result = 1.0F;
    }
    else if( ( target != null )
             && JsonRepresentation.class.isAssignableFrom( target ) )
    {
        result = 1.0F;
    }
    else if( isCompatible( source ) )
    {
        result = 0.8F;
    }

    return result;
}
 
开发者ID:apache,项目名称:polygene-java,代码行数:24,代码来源:PolygeneConverter.java

示例13: toRepresentation

import org.restlet.resource.Resource; //导入依赖的package包/类
@Override
public Representation toRepresentation( Object source, Variant target, Resource resource )
{
    Representation result = null;

    if( source instanceof JsonRepresentation )
    {
        result = (JsonRepresentation<?>) source;
    }
    else
    {
        if( target.getMediaType() == null )
        {
            target.setMediaType( MediaType.APPLICATION_JSON );
        }
        if( isCompatible( target ) )
        {
            result = create( target.getMediaType(), source );
        }
    }

    return result;
}
 
开发者ID:apache,项目名称:polygene-java,代码行数:24,代码来源:PolygeneConverter.java

示例14: score

import org.restlet.resource.Resource; //导入依赖的package包/类
@Override
public float score(Object source, Variant target, Resource resource) {
	 float result = -1.0F;

        if (source instanceof XMLRepresentation<?>) {
            result = 1.0F;
        } else {
            if (target == null) {
                result = 0.5F;
            } else if (VARIANT_APPLICATION_ALL_XML.isCompatible(target)
                    || VARIANT_APPLICATION_XML.isCompatible(target)
                    || VARIANT_TEXT_XML.isCompatible(target)) {
                result = 1.0F;
            } else {
                result = 0.5F;
            }
        }

        return result;
}
 
开发者ID:lathil,项目名称:Ptoceti,代码行数:21,代码来源:XMLConverter.java

示例15: toObject

import org.restlet.resource.Resource; //导入依赖的package包/类
@Override
public <T> T toObject(Representation source, Class<T> target,
		Resource resource) throws IOException {
	 Object result = null;

        // The source for the Jackson conversion
        XMLRepresentation<?> obixSource = null;

        if (source instanceof XMLRepresentation) {
        	obixSource = (XMLRepresentation<?>) source;
        } else if (VARIANT_APPLICATION_ALL_XML.isCompatible(source) || VARIANT_APPLICATION_XML.isCompatible(source) || VARIANT_TEXT_XML.isCompatible(source)) {
        	obixSource = create(source, target, resource);
        }

        if (obixSource != null) {
            // Handle the conversion
            if ((target != null)
                    && XMLRepresentation.class.isAssignableFrom(target)) {
                result = obixSource;
            } else {
                result = obixSource.getObject();
            }
        }

        return (T) result;
}
 
开发者ID:lathil,项目名称:Ptoceti,代码行数:27,代码来源:XMLConverter.java


注:本文中的org.restlet.resource.Resource类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。