Package java.beans

Examples of java.beans.XMLEncoder$Record


    /**
     * The test checks that java.lang.String exemplar store is correct
     */
    public void testEncodeString() {
        XMLEncoder e = new XMLEncoder(System.out);
        e.setExceptionListener(new ExceptionListener() {
            public void exceptionThrown(Exception e) {
                fail("Exception " + e.getClass() + " is thrown: "
                        + e.getMessage());
            }
        });

        try {
            e.writeObject(new String("hello"));
        } finally {
            e.close();
        }
    }
View Full Code Here


    /**
     * The test checks that array exemplar store is correct
     */
    public void testEncodeArray() {
        XMLEncoder e = new XMLEncoder(System.out);
        e.setExceptionListener(new ExceptionListener() {
            public void exceptionThrown(Exception e) {
                fail("Exception " + e.getClass() + " is thrown: "
                        + e.getMessage());
            }
        });

        try {
            e.writeObject(new int[] { 1, 2, 3 });
        } finally {
            e.close();
        }
    }
View Full Code Here

    /**
     * The test checks that null exemplar store is correct
     */
    public void testEncodeNull() {
        XMLEncoder e = new XMLEncoder(System.out);
        e.setExceptionListener(new ExceptionListener() {
            public void exceptionThrown(Exception e) {
                fail("Exception " + e.getClass() + " is thrown: "
                        + e.getMessage());
            }
        });

        try {
            e.writeObject(null);
        } finally {
            e.close();
        }
    }
View Full Code Here

    /**
     * The test checks that complex scenario store is correct
     */
    public void testEncodingScenario() {
        XMLEncoder e = new XMLEncoder(System.out);
        e.setExceptionListener(new ExceptionListener() {
            public void exceptionThrown(Exception e) {
                fail("Exception " + e.getClass() + " is thrown: "
                        + e.getMessage());
            }
        });

        StandardBean bean1 = new StandardBean("bean1");

        StandardBean bean2 = new StandardBean();
        bean2.setText(null);

        bean1.setPeer(bean2);
        bean2.setPeer(bean1);

        try {
            e.writeObject(bean1);
            e.writeObject(bean2);
        } finally {
            e.close();
        }
    }
View Full Code Here

    /**
     * This is a regression test for HARMONY-5707.
     */
    public void test5707() {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        XMLEncoder encoder = new XMLEncoder(baos);
        TstBean5707 bean1 = new TstBean5707();

        encoder.writeObject(bean1);
        encoder.close();       
    }
View Full Code Here

        str += "=" + string((Statement) exp);
        return str;
    }

    public void testWriteExpression_Scenario1() {
        XMLEncoder xmlEncoder = new XMLEncoder((OutputStream) null);
        try {
            xmlEncoder.writeExpression((Expression) null);
            fail("should throw NullPointerException");
        } catch (NullPointerException e) {
            // Expected
        }
    }
View Full Code Here

    return null;
  }

  public static String serializeExpression(ExprNodeDesc expr) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    XMLEncoder encoder = new XMLEncoder(baos);
    encoder.setPersistenceDelegate(java.sql.Date.class, new DatePersistenceDelegate());
    encoder.setPersistenceDelegate(Timestamp.class, new TimestampPersistenceDelegate());
    try {
      encoder.writeObject(expr);
    } finally {
      encoder.close();
    }
    try {
      return baos.toString("UTF-8");
    } catch (UnsupportedEncodingException ex) {
      throw new RuntimeException("UTF-8 support required", ex);
View Full Code Here

  /**
   * Serialize the object. This helper function mainly makes sure that enums,
   * counters, etc are handled properly.
   */
  public static void serializeObject(Object plan, OutputStream out) {
    XMLEncoder e = new XMLEncoder(out);
    e.setExceptionListener(new ExceptionListener() {
      public void exceptionThrown(Exception e) {
        LOG.warn(org.apache.hadoop.util.StringUtils.stringifyException(e));
        throw new RuntimeException("Cannot serialize object", e);
      }
    });
    // workaround for java 1.5
    e.setPersistenceDelegate(ExpressionTypes.class, new EnumDelegate());
    e.setPersistenceDelegate(GroupByDesc.Mode.class, new EnumDelegate());
    e.setPersistenceDelegate(Operator.ProgressCounter.class, new EnumDelegate());
    e.setPersistenceDelegate(java.sql.Date.class, new DatePersistenceDelegate());
    e.setPersistenceDelegate(Timestamp.class, new TimestampPersistenceDelegate());

    e.setPersistenceDelegate(org.datanucleus.store.types.backed.Map.class, new MapDelegate());
    e.setPersistenceDelegate(org.datanucleus.store.types.backed.List.class, new ListDelegate());
    e.setPersistenceDelegate(org.antlr.runtime.CommonToken.class, new CommonTokenDelegate());

    e.writeObject(plan);
    e.close();
  }
View Full Code Here

                }
                closeCalled = true;
                super.close();
            }
        };
        XMLEncoder enc = new XMLEncoder(out);
        enc.writeObject(new Integer(3));
        assertEquals(0, out.size());

        enc.close();

        assertTrue(out.size() > 0);
        try {
            out.close();
            fail();
View Full Code Here

        }
    }

    public void testFlush() {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        XMLEncoder enc = new XMLEncoder(out);
        Integer i = new Integer(3);
        enc.writeObject(i);
        assertEquals(0, out.size());
        assertNotNull(enc.get(i));

        enc.flush();

        assertTrue(out.size() > 0);
        assertNull(enc.get(i));
    }
View Full Code Here

TOP

Related Classes of java.beans.XMLEncoder$Record

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.