Package org.jibx.runtime

Examples of org.jibx.runtime.IUnmarshallingContext


     * @throws UnavailableException if any error occurs that stops the mapper from being created
     */
    private Map createServiceDefinitions(HttpServlet servlet) throws UnavailableException {

        // set up JiBX unmarshalling for service configuration files
        IUnmarshallingContext ctx = null;
        try {
            IBindingFactory factory = BindingDirectory.getFactory(ServiceDefinition.class);
            ctx = factory.createUnmarshallingContext();
        } catch (JiBXException e) {
            logger.error("Unable to initialize unmarshalling", e);
            throw new UnavailableException("Unable to initialize unmarshalling. \n" + getErrorDetails(e));
        }

        // read and validate service definitions
        String path = null;
        String file = null;
        try {

            // loop through all initialization parameter pairs
            HashMap map = new HashMap();
            Enumeration pnum = servlet.getInitParameterNames();
            ServletContext serv = servlet.getServletContext();
            while (pnum.hasMoreElements()) {

                // parameter name is path and value is service definition file
                path = (String) pnum.nextElement();
                file = "/WEB-INF/" + servlet.getInitParameter(path);
                InputStream is = null;
                try {
                    is = serv.getResourceAsStream(file);
                    if (is == null) {
                        logger.error("Service definition not found for service " + path + " at " + file);
                        throw new UnavailableException("Service definition not found for service " + path + " at "
                            + file + ". Check configuration of servlet " + servlet.getServletName()
                            + " in WEB-INF/web.xml.");
                    }
                    ServiceDefinition sdef = (ServiceDefinition) ctx.unmarshalDocument(is, null);
                    if (!path.startsWith("/")) {
                        path = "/" + path;
                    }
                    map.put(path, sdef);

View Full Code Here


            System.err.println("Need at least one service definition and port number parameter");
            System.exit(1);
        }

        // set up JiBX unmarshalling for service configuration files
        IUnmarshallingContext ctx = null;
        try {
            ctx = BindingDirectory.getFactory(ServiceDefinition.class).createUnmarshallingContext();
        } catch (JiBXException e) {
            System.err.println("Unable to initialize unmarshalling: " + e.getMessage());
        }

        // parse all command line arguments and unmarshal the service definitions
        ServiceDefinition[] sdefs = new ServiceDefinition[args.length];
        int[] ports = new int[args.length];
        boolean valid = true;
        for (int i = 0; i < args.length; i++) {
            String arg = args[i];
            int split = arg.indexOf('=');
            String path = arg.substring(0, split);
            if (split > 0) {
                InputStream is = null;
                try {
                    ports[i] = Integer.parseInt(arg.substring(split + 1));
                    is = new FileInputStream(path);
                    sdefs[i] = (ServiceDefinition)ctx.unmarshalDocument(is, null);
                } catch (NumberFormatException e) {
                    System.err.println("Error parsing port number in argument " + i + ": " + arg);
                    valid = false;
                } catch (FileNotFoundException e) {
                    System.err.println("Service definition file not found for argument " + i + ": " + path);
View Full Code Here

   }

   public void testPageSetMapping() throws Exception
   {
      IBindingFactory bfact = BindingDirectory.getFactory(PageSet.class);
      IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
      Object obj =
         uctx.unmarshalDocument(new FileInputStream("src/test/resources/portal/portal/classic/pages.xml"), null);
      assertEquals(Page.PageSet.class, obj.getClass());
   }
View Full Code Here

   }

   public void testPortalConfigMapping() throws Exception
   {
      IBindingFactory bfact = BindingDirectory.getFactory(PortalConfig.class);
      IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
      Object obj =
         uctx.unmarshalDocument(new FileInputStream("src/test/resources/portal/portal/classic/portal.xml"), null);
      assertEquals(PortalConfig.class, obj.getClass());
   }
View Full Code Here

   }

   public void testNavigationMapping() throws Exception
   {
      IBindingFactory bfact = BindingDirectory.getFactory(PageNavigation.class);
      IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
      Object obj =
         uctx.unmarshalDocument(new FileInputStream("src/test/resources/portal/portal/classic/navigation.xml"), null);
      assertEquals(PageNavigation.class, obj.getClass());

      IMarshallingContext mctx = bfact.createMarshallingContext();
      mctx.setIndent(2);
      mctx.marshalDocument(obj, "UTF-8", null, new FileOutputStream("target/navigation.xml"));

      obj = uctx.unmarshalDocument(new FileInputStream("target/navigation.xml"), null);
      assertEquals(PageNavigation.class, obj.getClass());
   }
View Full Code Here

   }

   public void testPortletPreferencesMapping() throws Exception
   {
      IBindingFactory bfact = BindingDirectory.getFactory(PortalConfig.class);
      IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
      Object obj =
         uctx.unmarshalDocument(
            new FileInputStream("src/test/resources/portal/portal/classic/portlet-preferences.xml"), null);
      assertEquals(PortletPreferencesSet.class, obj.getClass());

      IMarshallingContext mctx = bfact.createMarshallingContext();
      mctx.setIndent(2);
View Full Code Here

   }

   public void testPortletApplicationMapping() throws Exception
   {
      IBindingFactory bfact = BindingDirectory.getFactory(PortalConfig.class);
      IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
      Application<Portlet> app =
         (Application<Portlet>)uctx.unmarshalDocument(new FileInputStream(
            "src/test/resources/jibx/portlet-application.xml"), null);
      TransientApplicationState portletState = (TransientApplicationState)app.getState();
      assertNotNull(portletState);
      assertEquals("web/BannerPortlet", portletState.getContentId());
      Portlet preferences = (Portlet)portletState.getContentState();
View Full Code Here

   private Container toContainer(String xml) throws Exception
   {
      ByteArrayInputStream is = new ByteArrayInputStream(xml.getBytes());
      IBindingFactory bfact = BindingDirectory.getFactory(Container.class);
      IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
      return (Container)uctx.unmarshalDocument(is, null);
   }
View Full Code Here

     * @param is input stream
     * @return root element
     * @throws Exception
     */
    protected GlobalCustom readCustom(InputStream is) throws Exception {
        IUnmarshallingContext ictx = m_bindingFactory.createUnmarshallingContext();
        ValidationContext vctx = new ValidationContext();
        ictx.setDocument(is, null);
        ictx.setUserContext(vctx);
        GlobalCustom custom = new GlobalCustom();
        ((IUnmarshallable)custom).unmarshal(ictx);
        List problems = vctx.getProblems();
        if (problems.size() > 0) {
            StringBuffer buff = new StringBuffer();
View Full Code Here

        String bindname = precomp ? "precomp" : "normal";
        IBindingFactory bfact =
            BindingDirectory.getFactory(bindname, "org.jibx.binding.model");
       
        // unmarshal document to construct objects
        IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
        uctx.setDocument(is, fname, null);
        uctx.pushObject(new UnmarshalWrapper(vctx, contain));
        BindingElement binding = new BindingElement();
        binding.setPrecompiled(precomp);
        ((IUnmarshallable)binding).unmarshal(uctx);
        uctx.popObject();
        return binding;
    }
View Full Code Here

TOP

Related Classes of org.jibx.runtime.IUnmarshallingContext

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.