Package java.beans

Examples of java.beans.XMLEncoder


    /**
     * The test checks that java.lang.Integer exemplar store is correct
     */
    public void testEncodeInteger() {
        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 Integer(1));
        } finally {
            e.close();
        }
    }
View Full Code Here


    /**
     * The test checks that java.lang.Long exemplar store is correct
     */
    public void testEncodeLong() {
        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 Long(1));
        } finally {
            e.close();
        }
    }
View Full Code Here

    /**
     * The test checks that java.lang.Short exemplar store is correct
     */
    public void testEncodeShort() {
        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 Short((short) 1));
        } finally {
            e.close();
        }
    }
View Full Code Here

    /**
     * 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

    /**
     * The test checks that encoder can handle writeExpression in initialize
     */
    public void testEncodeExpressionAsStatement() {
        XMLEncoder e = new XMLEncoder(System.out);
        e.setExceptionListener(new ExceptionListener() {
            public void exceptionThrown(Exception e) {
                fail("Exception " + e.getClass() + " is thrown: "
                        + e.getMessage());
            }
        });

        try {
            final Object object = new Object();
            e.setPersistenceDelegate(AType.class,
                    new DefaultPersistenceDelegate() {
                        @SuppressWarnings("unchecked")
                        @Override
                        protected void initialize(Class type,
                                Object oldInstance, Object newInstance,
                                Encoder out) {
                            out.writeExpression(new Expression(object,
                                    oldInstance, "go", new Object[] {}));
                        }
                    });
            AType a = new AType();

            // e.writeObject(object);
            e.writeObject(a);
            e.writeObject(object);
        } 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

    return null;
  }

  public static String serializeExpression(ExprNodeDesc expr) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    XMLEncoder encoder = new XMLEncoder(baos);
    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

TOP

Related Classes of java.beans.XMLEncoder

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.