Package javax.xml.bind

Examples of javax.xml.bind.JAXBContext


         // I'm testing unknown content-length here
         GetMethod method = new GetMethod("http://localhost:8080/basic-integration-test/xml");
         int status = client.executeMethod(method);
         Assert.assertEquals(HttpResponseCodes.SC_OK, status);
         String result = method.getResponseBodyAsString();
         JAXBContext ctx = JAXBContext.newInstance(Customer.class);
         Customer cust = (Customer)ctx.createUnmarshaller().unmarshal(new StringReader(result));
         Assert.assertEquals("Bill Burke", cust.getName());
         method.releaseConnection();
      }
   }
View Full Code Here


         throw new JAXBUnmarshalException("Unable to find JAXBContext for media type: " + mediaType);
      }

      try
      {
         JAXBContext ctx = finder.findCachedContext(Entry.class, mediaType, annotations);
         Entry entry = (Entry) ctx.createUnmarshaller().unmarshal(entityStream);
         if (entry.getContent() != null) entry.getContent().setFinder(finder);
         return entry;
      }
      catch (JAXBException e)
      {
View Full Code Here

      {
         set.add(entry.getContent().getJAXBObject().getClass());
      }
      try
      {
         JAXBContext ctx = finder.findCacheContext(mediaType, annotations, set.toArray(new Class[set.size()]));
         Marshaller marshaller = ctx.createMarshaller();
         NamespacePrefixMapper mapper = new NamespacePrefixMapper()
         {
            public String getPreferredPrefix(String namespace, String s1, boolean b)
            {
               if (namespace.equals("http://www.w3.org/2005/Atom")) return "atom";
View Full Code Here

         throw new JAXBUnmarshalException("Unable to find JAXBContext for media type: " + mediaType);
      }

      try
      {
         JAXBContext ctx = finder.findCachedContext(Feed.class, mediaType, annotations);
         Feed feed = (Feed) ctx.createUnmarshaller().unmarshal(entityStream);
         for (Entry entry : feed.getEntries())
         {
            if (entry.getContent() != null) entry.getContent().setFinder(finder);
         }
         return feed;
View Full Code Here

            set.add(entry.getContent().getJAXBObject().getClass());
         }
      }
      try
      {
         JAXBContext ctx = finder.findCacheContext(mediaType, annotations, set.toArray(new Class[set.size()]));
         Marshaller marshaller = ctx.createMarshaller();
         NamespacePrefixMapper mapper = new NamespacePrefixMapper()
         {
            public String getPreferredPrefix(String namespace, String s1, boolean b)
            {
               if (namespace.equals("http://www.w3.org/2005/Atom")) return "atom";
View Full Code Here

   public void testCache() throws Exception
   {
      {
         ContextResolver<JAXBContextFinder> resolver = getProviderFactory().getContextResolver(JAXBContextFinder.class, MediaType.APPLICATION_XML_TYPE);
         JAXBContextFinder finder = resolver.getContext(Child.class);
         JAXBContext ctx = finder.findCachedContext(Child.class, MediaType.APPLICATION_XML_TYPE, null);


         JAXBContext ctx2 = finder.findCachedContext(Child.class, MediaType.APPLICATION_XML_TYPE, null);

         Assert.assertTrue(ctx == ctx2);
      }

      {
         ContextResolver<JAXBContextFinder> resolver = getProviderFactory().getContextResolver(JAXBContextFinder.class, MediaType.APPLICATION_JSON_TYPE);
         JAXBContextFinder finder = resolver.getContext(Child.class);
         JAXBContext ctx = finder.findCachedContext(Child.class, MediaType.APPLICATION_JSON_TYPE, null);


         JAXBContext ctx2 = finder.findCachedContext(Child.class, MediaType.APPLICATION_JSON_TYPE, null);

         Assert.assertTrue(ctx == ctx2);
      }
      {
         MediaType mediaType = new MediaType("application", "fastinfoset");
         ContextResolver<JAXBContextFinder> resolver = getProviderFactory().getContextResolver(JAXBContextFinder.class, mediaType);
         JAXBContextFinder finder = resolver.getContext(Child.class);
         JAXBContext ctx = finder.findCachedContext(Child.class, mediaType, null);


         JAXBContext ctx2 = finder.findCachedContext(Child.class, mediaType, null);

         Assert.assertTrue(ctx == ctx2);
      }
   }
View Full Code Here

   public void testCache2() throws Exception
   {
      {
         ContextResolver<JAXBContextFinder> resolver = getProviderFactory().getContextResolver(JAXBContextFinder.class, MediaType.APPLICATION_XML_TYPE);
         JAXBContextFinder finder = resolver.getContext(Child.class);
         JAXBContext ctx = finder.findCacheContext(MediaType.APPLICATION_XML_TYPE, null, Child.class, Parent.class);


         JAXBContext ctx2 = finder.findCacheContext(MediaType.APPLICATION_XML_TYPE, null, Child.class, Parent.class);

         Assert.assertTrue(ctx == ctx2);
      }

      {
         ContextResolver<JAXBContextFinder> resolver = getProviderFactory().getContextResolver(JAXBContextFinder.class, MediaType.APPLICATION_JSON_TYPE);
         JAXBContextFinder finder = resolver.getContext(Child.class);
         JAXBContext ctx = finder.findCacheContext(MediaType.APPLICATION_JSON_TYPE, null, Child.class, Parent.class);


         JAXBContext ctx2 = finder.findCacheContext(MediaType.APPLICATION_JSON_TYPE, null, Child.class, Parent.class);

         Assert.assertTrue(ctx == ctx2);
      }
      {
         MediaType mediaType = new MediaType("application", "fastinfoset");
         ContextResolver<JAXBContextFinder> resolver = getProviderFactory().getContextResolver(JAXBContextFinder.class, mediaType);
         JAXBContextFinder finder = resolver.getContext(Child.class);
         JAXBContext ctx = finder.findCacheContext(mediaType, null, Child.class, Parent.class);


         JAXBContext ctx2 = finder.findCacheContext(mediaType, null, Child.class, Parent.class);

         Assert.assertTrue(ctx == ctx2);
      }
   }
View Full Code Here

      MultivaluedMap<String, String> httpHeaders,
      InputStream entityStream, final MultipartRelatedInput xopPackage)
      throws IOException {
    try {
      InputPart rootPart = xopPackage.getRootPart();
      JAXBContext jaxb = findJAXBContext(type, annotations, rootPart
          .getMediaType(), true);
      Unmarshaller unmarshaller = jaxb.createUnmarshaller();
      unmarshaller
          .setAttachmentUnmarshaller(new XopAttachmentUnmarshaller(
              xopPackage));
      return unmarshaller.unmarshal(new StreamSource(rootPart.getBody(
          InputStream.class, null)));
View Full Code Here

   private static final Logger logger = Logger.getLogger(TestJAXBNamespacePrefix.class);

   @Test
   public void testNamespacePrefix() throws Exception
   {
      JAXBContext ctx = JAXBContext.newInstance(PurchaseOrderType.class);
      PurchaseOrderType po = new PurchaseOrderType();
      Items items = new Items();
      Item item = new Item();
      item.setComment("Tetsing");
      item.setPartNum("242-GZ");
      item.setProductName("My Thing");
      item.setQuantity(6);
      item.setUSPrice(new BigDecimal(13.99));
      items.getItem().add(item);
      po.setItems(items);
      Marshaller marshaller = ctx.createMarshaller();
      XmlSchema xmlSchema = PurchaseOrderType.class.getPackage().getAnnotation(XmlSchema.class);
      XmlNamespacePrefixMapper mapper = new XmlNamespacePrefixMapper(xmlSchema.xmlns());
      try
      {
         marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", mapper);
View Full Code Here

            }
            catch (NumberFormatException ignored)
            {
            }
         }
         JAXBContext jaxb = findJAXBContext(type, annotations, mediaType, true);
         Unmarshaller unmarshaller = jaxb.createUnmarshaller();
         unmarshaller = decorateUnmarshaller(type, annotations, mediaType, unmarshaller);
         return (T) unmarshaller.unmarshal(new StreamSource(entityStream));
      }
      catch (JAXBException e)
      {
View Full Code Here

TOP

Related Classes of javax.xml.bind.JAXBContext

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.