KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > TestPrototype


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  */

19
20 import java.io.File JavaDoc;
21 import java.io.FileInputStream JavaDoc;
22 import java.io.FileOutputStream JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.List JavaDoc;
25
26 // Generated classes
27
import samples.doml.*;
28 import samples.doml.Package;
29
30 /**
31  * Created on Aug 15, 2002
32  * Test use of prototype with generated classes inheritence
33  * @author Christophe Ney - cney@batisseurs.com
34  */

35 public class TestPrototype {
36
37     static class ClassImplPrototype extends ClassImpl {
38         private static int i = 0;
39         // clone and automatically set the class name
40
protected Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
41             ClassImpl ret = (ClassImpl)super.clone();
42             ret.setName("Class_"+(i++));
43             return ret;
44         }
45     }
46
47     public static void main(String JavaDoc[] args) {
48         try {
49             // set prototype for ClassImpl
50
ClassImpl.setPrototype(new ClassImplPrototype());
51
52             Doml root = DomlImpl.newInstance();
53             Vendor v = VendorImpl.newInstance();
54             Package JavaDoc pkg = PackageImpl.newInstance();
55
56             root.setVendor(v);
57             v.setXmlpackage(pkg);
58             // add classes with automatically generated names
59
pkg.addXmlclass(ClassImpl.newInstance());
60             pkg.addXmlclass(ClassImpl.newInstance());
61             pkg.addXmlclass(ClassImpl.newInstance());
62
63             root.marshal(System.out);
64
65         } catch (Exception JavaDoc e) {
66             e.printStackTrace();
67         }
68     }
69 }
70
Popular Tags