本文整理汇总了Java中org.restlet.representation.Variant类的典型用法代码示例。如果您正苦于以下问题:Java Variant类的具体用法?Java Variant怎么用?Java Variant使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Variant类属于org.restlet.representation包,在下文中一共展示了Variant类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: TopicManagementRestletResource
import org.restlet.representation.Variant; //导入依赖的package包/类
public TopicManagementRestletResource() {
getVariants().add(new Variant(MediaType.TEXT_PLAIN));
getVariants().add(new Variant(MediaType.APPLICATION_JSON));
setNegotiated(false);
_helixMirrorMakerManager = (HelixMirrorMakerManager) getApplication().getContext()
.getAttributes().get(HelixMirrorMakerManager.class.toString());
_autoTopicWhitelistingManager = (AutoTopicWhitelistingManager) getApplication().getContext()
.getAttributes().get(AutoTopicWhitelistingManager.class.toString());
if (getApplication().getContext().getAttributes()
.containsKey(KafkaBrokerTopicObserver.class.toString())) {
_srcKafkaBrokerTopicObserver = (KafkaBrokerTopicObserver) getApplication().getContext()
.getAttributes().get(KafkaBrokerTopicObserver.class.toString());
} else {
_srcKafkaBrokerTopicObserver = null;
}
}
示例2: ValidationRestletResource
import org.restlet.representation.Variant; //导入依赖的package包/类
public ValidationRestletResource() {
getVariants().add(new Variant(MediaType.TEXT_PLAIN));
getVariants().add(new Variant(MediaType.APPLICATION_JSON));
setNegotiated(false);
_validationManager = (ValidationManager) getApplication().getContext()
.getAttributes().get(ValidationManager.class.toString());
if (getApplication().getContext().getAttributes()
.containsKey(SourceKafkaClusterValidationManager.class.toString())) {
_srcKafkaValidationManager =
(SourceKafkaClusterValidationManager) getApplication().getContext()
.getAttributes().get(SourceKafkaClusterValidationManager.class.toString());
} else {
_srcKafkaValidationManager = null;
}
}
示例3: score
import org.restlet.representation.Variant; //导入依赖的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;
}
示例4: score
import org.restlet.representation.Variant; //导入依赖的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;
}
示例5: toRepresentation
import org.restlet.representation.Variant; //导入依赖的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;
}
示例6: score
import org.restlet.representation.Variant; //导入依赖的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;
}
示例7: toRepresentation
import org.restlet.representation.Variant; //导入依赖的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;
}
示例8: score
import org.restlet.representation.Variant; //导入依赖的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;
}
示例9: toRepresentation
import org.restlet.representation.Variant; //导入依赖的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.representation.Variant; //导入依赖的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: doNegotiatedHandle
import org.restlet.representation.Variant; //导入依赖的package包/类
/**
* Effectively handles a call with content negotiation of the response
* entity. The default behavior is to dispatch the call to call a matching
* annotated method or one of the {@link #get(Variant)},
* {@link #post(Representation,Variant)},
* {@link #put(Representation,Variant)}, {@link #delete(Variant)},
* {@link #head(Variant)} or {@link #options(Variant)} methods.<br>
* <br>
* If no acceptable variant is found, the
* {@link Status#CLIENT_ERROR_NOT_ACCEPTABLE} status is set.
*
* @return The response entity.
* @throws ResourceException
*/
protected Representation doNegotiatedHandle() throws ResourceException {
Representation result = null;
if ((getVariants() != null) && (!getVariants().isEmpty())) {
Variant preferredVariant = getPreferredVariant(getVariants());
if (preferredVariant == null) {
// No variant was found matching the client preferences
doError(Status.CLIENT_ERROR_NOT_ACCEPTABLE);
result = describeVariants();
} else {
// Update the variant dimensions used for content
// negotiation
updateDimensions();
result = doHandle(preferredVariant);
}
} else {
// No variant declared for this method.
result = doHandle();
}
return result;
}
示例12: patch
import org.restlet.representation.Variant; //导入依赖的package包/类
/**
* Apply a patch entity to the current representation of the resource
* retrieved by calling {@link #get()}. By default, the
* {@link ConverterService#applyPatch(Representation, Representation)}
* method is used and then the {@link #put(Representation, Variant)} method
* called.
*
* @param entity
* The patch entity to apply.
* @param variant
* The variant of the response entity.
* @return The optional result entity.
* @throws ResourceException
* @see <a href="https://tools.ietf.org/html/rfc5789">HTTP PATCH method</a>
*/
protected Representation patch(Representation entity, Variant variant)
throws ResourceException {
Representation result = null;
try {
if (variant instanceof VariantInfo) {
result = doHandle(((VariantInfo) variant).getAnnotationInfo(),
variant);
} else {
// Default implementation
result = put(getConverterService().applyPatch(get(), entity),
variant);
// doError(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED);
}
} catch (IOException e) {
throw new ResourceException(e);
}
return result;
}
示例13: getObjectClasses
import org.restlet.representation.Variant; //导入依赖的package包/类
@Override
public List<Class<?>> getObjectClasses(Variant source) {
List<Class<?>> result = null;
result = addObjectClass(result, String.class);
result = addObjectClass(result, InputStream.class);
result = addObjectClass(result, Reader.class);
if (source.getMediaType() != null) {
MediaType mediaType = source.getMediaType();
if ((ObjectRepresentation.VARIANT_OBJECT_BINARY_SUPPORTED && MediaType.APPLICATION_JAVA_OBJECT
.equals(mediaType))
|| (ObjectRepresentation.VARIANT_OBJECT_XML_SUPPORTED && MediaType.APPLICATION_JAVA_OBJECT_XML
.equals(mediaType))) {
result = addObjectClass(result, Object.class);
} else if (MediaType.APPLICATION_WWW_FORM.equals(mediaType)) {
result = addObjectClass(result, Form.class);
}
}
return result;
}
示例14: getBestHelper
import org.restlet.representation.Variant; //导入依赖的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;
}
示例15: getVariants
import org.restlet.representation.Variant; //导入依赖的package包/类
/**
* Returns the list of variants that can be converted from a given object
* class.
*
* @param sourceClass
* The source class.
* @param targetVariant
* The expected representation metadata.
* @return The list of variants that can be converted.
*/
public static List<VariantInfo> getVariants(Class<?> sourceClass,
Variant targetVariant) {
List<VariantInfo> result = null;
for (ConverterHelper ch : Engine.getInstance()
.getRegisteredConverters()) {
if (ch != null) {
try {
result = ch.addVariants(sourceClass, targetVariant, result);
} catch (IOException e) {
Context.getCurrentLogger().debug(
"Unable get the variants of the " + ch + " converter helper.", e);
}
}
}
return result;
}