本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}