org.springframework.oxm.Marshaller.supports()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(10.3k)|赞(0)|评价(0)|浏览(145)

本文整理了Java中org.springframework.oxm.Marshaller.supports()方法的一些代码示例,展示了Marshaller.supports()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Marshaller.supports()方法的具体详情如下:
包路径:org.springframework.oxm.Marshaller
类名称:Marshaller
方法名:supports

Marshaller.supports介绍

[英]Indicate whether this marshaller can marshal instances of the supplied type.
[中]指示此封送拆收器是否可以封送所提供类型的实例。

代码示例

代码示例来源:origin: spring-projects/spring-framework

  1. @Override
  2. protected boolean canConvertTo(Object payload, @Nullable MessageHeaders headers) {
  3. return (supportsMimeType(headers) && this.marshaller != null &&
  4. this.marshaller.supports(payload.getClass()));
  5. }

代码示例来源:origin: spring-projects/spring-framework

  1. @Override
  2. public boolean canWrite(Class<?> clazz, @Nullable MediaType mediaType) {
  3. return (canWrite(mediaType) && this.marshaller != null && this.marshaller.supports(clazz));
  4. }

代码示例来源:origin: spring-projects/spring-framework

  1. /**
  2. * Check whether the given value from the current view's model is eligible
  3. * for marshalling through the configured {@link Marshaller}.
  4. * <p>The default implementation calls {@link Marshaller#supports(Class)},
  5. * unwrapping a given {@link JAXBElement} first if applicable.
  6. * @param modelKey the value's key in the model (never {@code null})
  7. * @param value the value to check (never {@code null})
  8. * @return whether the given value is to be considered as eligible
  9. * @see Marshaller#supports(Class)
  10. */
  11. protected boolean isEligibleForMarshalling(String modelKey, Object value) {
  12. Assert.state(this.marshaller != null, "No Marshaller set");
  13. Class<?> classToCheck = value.getClass();
  14. if (value instanceof JAXBElement) {
  15. classToCheck = ((JAXBElement<?>) value).getDeclaredType();
  16. }
  17. return this.marshaller.supports(classToCheck);
  18. }

代码示例来源:origin: org.springframework/spring-web

  1. @Override
  2. public boolean canWrite(Class<?> clazz, @Nullable MediaType mediaType) {
  3. return (canWrite(mediaType) && this.marshaller != null && this.marshaller.supports(clazz));
  4. }

代码示例来源:origin: org.springframework/spring-webmvc

  1. /**
  2. * Check whether the given value from the current view's model is eligible
  3. * for marshalling through the configured {@link Marshaller}.
  4. * <p>The default implementation calls {@link Marshaller#supports(Class)},
  5. * unwrapping a given {@link JAXBElement} first if applicable.
  6. * @param modelKey the value's key in the model (never {@code null})
  7. * @param value the value to check (never {@code null})
  8. * @return whether the given value is to be considered as eligible
  9. * @see Marshaller#supports(Class)
  10. */
  11. protected boolean isEligibleForMarshalling(String modelKey, Object value) {
  12. Assert.state(this.marshaller != null, "No Marshaller set");
  13. Class<?> classToCheck = value.getClass();
  14. if (value instanceof JAXBElement) {
  15. classToCheck = ((JAXBElement<?>) value).getDeclaredType();
  16. }
  17. return this.marshaller.supports(classToCheck);
  18. }

代码示例来源:origin: spring-projects/spring-batch

  1. /**
  2. * Write the value objects and flush them to the file.
  3. *
  4. * @param items the value object
  5. *
  6. * @throws IOException thrown if general error occurs.
  7. * @throws XmlMappingException thrown if error occurs during XML Mapping.
  8. */
  9. @Override
  10. public void write(List<? extends T> items) throws XmlMappingException, IOException {
  11. if(!this.initialized) {
  12. throw new WriterNotOpenException("Writer must be open before it can be written to");
  13. }
  14. currentRecordCount += items.size();
  15. for (Object object : items) {
  16. Assert.state(marshaller.supports(object.getClass()),
  17. "Marshaller must support the class of the marshalled object");
  18. Result result = createStaxResult();
  19. marshaller.marshal(object, result);
  20. }
  21. try {
  22. eventWriter.flush();
  23. if (forceSync) {
  24. channel.force(false);
  25. }
  26. }
  27. catch (XMLStreamException | IOException e) {
  28. throw new WriteFailedException("Failed to flush the events", e);
  29. }
  30. }

代码示例来源:origin: spring-projects/spring-framework

  1. @Test
  2. public void testRenderUnsupportedModel() throws Exception {
  3. Object toBeMarshalled = new Object();
  4. String modelKey = "key";
  5. Map<String, Object> model = new HashMap<>();
  6. model.put(modelKey, toBeMarshalled);
  7. MockHttpServletRequest request = new MockHttpServletRequest();
  8. MockHttpServletResponse response = new MockHttpServletResponse();
  9. given(marshallerMock.supports(Object.class)).willReturn(false);
  10. try {
  11. view.render(model, request, response);
  12. fail("IllegalStateException expected");
  13. }
  14. catch (IllegalStateException ex) {
  15. // expected
  16. }
  17. }

代码示例来源:origin: spring-projects/spring-framework

  1. @Test
  2. public void renderModelKeyUnsupported() throws Exception {
  3. Object toBeMarshalled = new Object();
  4. String modelKey = "key";
  5. view.setModelKey(modelKey);
  6. Map<String, Object> model = new HashMap<>();
  7. model.put(modelKey, toBeMarshalled);
  8. MockHttpServletRequest request = new MockHttpServletRequest();
  9. MockHttpServletResponse response = new MockHttpServletResponse();
  10. given(marshallerMock.supports(Object.class)).willReturn(false);
  11. try {
  12. view.render(model, request, response);
  13. fail("IllegalStateException expected");
  14. }
  15. catch (IllegalStateException ex) {
  16. // expected
  17. }
  18. }

代码示例来源:origin: spring-projects/spring-framework

  1. @Test
  2. public void renderModelKeyWithJaxbElement() throws Exception {
  3. String toBeMarshalled = "value";
  4. String modelKey = "key";
  5. view.setModelKey(modelKey);
  6. Map<String, Object> model = new HashMap<>();
  7. model.put(modelKey, new JAXBElement<>(new QName("model"), String.class, toBeMarshalled));
  8. MockHttpServletRequest request = new MockHttpServletRequest();
  9. MockHttpServletResponse response = new MockHttpServletResponse();
  10. given(marshallerMock.supports(String.class)).willReturn(true);
  11. marshallerMock.marshal(eq(toBeMarshalled), isA(StreamResult.class));
  12. view.render(model, request, response);
  13. assertEquals("Invalid content type", "application/xml", response.getContentType());
  14. assertEquals("Invalid content length", 0, response.getContentLength());
  15. }

代码示例来源:origin: spring-projects/spring-framework

  1. @Test
  2. public void renderNoModelKeyAndBindingResultFirst() throws Exception {
  3. Object toBeMarshalled = new Object();
  4. String modelKey = "key";
  5. Map<String, Object> model = new LinkedHashMap<>();
  6. model.put(BindingResult.MODEL_KEY_PREFIX + modelKey, new BeanPropertyBindingResult(toBeMarshalled, modelKey));
  7. model.put(modelKey, toBeMarshalled);
  8. MockHttpServletRequest request = new MockHttpServletRequest();
  9. MockHttpServletResponse response = new MockHttpServletResponse();
  10. given(marshallerMock.supports(BeanPropertyBindingResult.class)).willReturn(true);
  11. given(marshallerMock.supports(Object.class)).willReturn(true);
  12. view.render(model, request, response);
  13. assertEquals("Invalid content type", "application/xml", response.getContentType());
  14. assertEquals("Invalid content length", 0, response.getContentLength());
  15. verify(marshallerMock).marshal(eq(toBeMarshalled), isA(StreamResult.class));
  16. }

代码示例来源:origin: spring-projects/spring-framework

  1. @Test
  2. public void renderNoModelKey() throws Exception {
  3. Object toBeMarshalled = new Object();
  4. String modelKey = "key";
  5. Map<String, Object> model = new HashMap<>();
  6. model.put(modelKey, toBeMarshalled);
  7. MockHttpServletRequest request = new MockHttpServletRequest();
  8. MockHttpServletResponse response = new MockHttpServletResponse();
  9. given(marshallerMock.supports(Object.class)).willReturn(true);
  10. view.render(model, request, response);
  11. assertEquals("Invalid content type", "application/xml", response.getContentType());
  12. assertEquals("Invalid content length", 0, response.getContentLength());
  13. verify(marshallerMock).marshal(eq(toBeMarshalled), isA(StreamResult.class));
  14. }

代码示例来源:origin: spring-projects/spring-framework

  1. @Test
  2. public void canWrite() {
  3. Marshaller marshaller = mock(Marshaller.class);
  4. given(marshaller.supports(Integer.class)).willReturn(false);
  5. given(marshaller.supports(String.class)).willReturn(true);
  6. MarshallingHttpMessageConverter converter = new MarshallingHttpMessageConverter();
  7. converter.setMarshaller(marshaller);
  8. assertFalse(converter.canWrite(Boolean.class, MediaType.TEXT_PLAIN));
  9. assertFalse(converter.canWrite(Integer.class, MediaType.TEXT_XML));
  10. assertTrue(converter.canWrite(String.class, MediaType.TEXT_XML));
  11. }

代码示例来源:origin: spring-projects/spring-framework

  1. @Test
  2. public void renderModelKey() throws Exception {
  3. Object toBeMarshalled = new Object();
  4. String modelKey = "key";
  5. view.setModelKey(modelKey);
  6. Map<String, Object> model = new HashMap<>();
  7. model.put(modelKey, toBeMarshalled);
  8. MockHttpServletRequest request = new MockHttpServletRequest();
  9. MockHttpServletResponse response = new MockHttpServletResponse();
  10. given(marshallerMock.supports(Object.class)).willReturn(true);
  11. marshallerMock.marshal(eq(toBeMarshalled), isA(StreamResult.class));
  12. view.render(model, request, response);
  13. assertEquals("Invalid content type", "application/xml", response.getContentType());
  14. assertEquals("Invalid content length", 0, response.getContentLength());
  15. }

代码示例来源:origin: org.springframework/spring-messaging

  1. @Override
  2. protected boolean canConvertTo(Object payload, @Nullable MessageHeaders headers) {
  3. return (supportsMimeType(headers) && this.marshaller != null &&
  4. this.marshaller.supports(payload.getClass()));
  5. }

代码示例来源:origin: apache/servicemix-bundles

  1. @Override
  2. protected boolean canConvertTo(Object payload, @Nullable MessageHeaders headers) {
  3. return (supportsMimeType(headers) && this.marshaller != null &&
  4. this.marshaller.supports(payload.getClass()));
  5. }

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-messaging

  1. @Override
  2. protected boolean canConvertTo(Object payload, @Nullable MessageHeaders headers) {
  3. return (supportsMimeType(headers) && this.marshaller != null &&
  4. this.marshaller.supports(payload.getClass()));
  5. }

代码示例来源:origin: apache/servicemix-bundles

  1. @Override
  2. public boolean canRead(Class<?> clazz, @Nullable MediaType mediaType) {
  3. return (canRead(mediaType) && this.unmarshaller != null && this.unmarshaller.supports(clazz));
  4. }

代码示例来源:origin: apache/servicemix-bundles

  1. @Override
  2. public boolean canWrite(Class<?> clazz, @Nullable MediaType mediaType) {
  3. return (canWrite(mediaType) && this.marshaller != null && this.marshaller.supports(clazz));
  4. }

代码示例来源:origin: org.springframework.ws/spring-ws-core

  1. private boolean supportsReturnType(Method method) {
  2. if (Void.TYPE.equals(method.getReturnType())) {
  3. return true;
  4. }
  5. else {
  6. if (getMarshaller() instanceof GenericMarshaller) {
  7. return ((GenericMarshaller) getMarshaller()).supports(method.getGenericReturnType());
  8. }
  9. else {
  10. return getMarshaller().supports(method.getReturnType());
  11. }
  12. }
  13. }

代码示例来源:origin: apache/servicemix-bundles

  1. private boolean supportsReturnType(Method method) {
  2. if (Void.TYPE.equals(method.getReturnType())) {
  3. return true;
  4. }
  5. else {
  6. if (getMarshaller() instanceof GenericMarshaller) {
  7. return ((GenericMarshaller) getMarshaller()).supports(method.getGenericReturnType());
  8. }
  9. else {
  10. return getMarshaller().supports(method.getReturnType());
  11. }
  12. }
  13. }

相关文章