KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > axi > datatype > DatatypePerfTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.axi.datatype;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.List JavaDoc;
24 import junit.framework.*;
25 import org.netbeans.modules.xml.axi.*;
26 import org.netbeans.modules.xml.axi.visitor.DefaultVisitor;
27
28
29 /**
30  *
31  * @author Ayub Khan
32  */

33 public class DatatypePerfTest extends AbstractTestCase {
34     
35     public static final String JavaDoc TEST_XSD = "resources/OTA_TravelItinerary.xsd";
36     public static final String JavaDoc GLOBAL_ELEMENT = "OTA_TravelItineraryRS";
37     
38     private List JavaDoc<AbstractAttribute> attList;
39     
40     public DatatypePerfTest(String JavaDoc testName) {
41         super(testName, TEST_XSD, GLOBAL_ELEMENT);
42     }
43     
44     protected void setUp() throws Exception JavaDoc {
45         super.setUp();
46         attList = new ArrayList JavaDoc<AbstractAttribute>();
47     }
48     
49     public static Test suite() {
50         TestSuite suite = new TestSuite(DatatypePerfTest.class);
51         
52         return suite;
53     }
54     
55     /**
56      * Test of createElement method, of class org.netbeans.modules.xml.axi.XAMFactory.
57      */

58     public void testCreateDatatype() {
59         validateSchema(axiModel.getSchemaModel());
60         Element element = globalElement;
61         assertNotNull(element);
62         
63         attList.clear();
64         TestVisitor visitor = new TestVisitor();
65         visitor.visit(element);
66         
67         String JavaDoc contentType = "";
68         if(element.getType() instanceof Datatype)
69             contentType = element.getType().getName();
70         print("\n\n=================\nGE: "+element.getName()+"["+contentType+"]");
71     }
72     
73     private void printAttributes(List JavaDoc<Attribute> attList) {
74         for(Attribute attr:attList) {
75             String JavaDoc attName = "";
76             if(attr.getName() != null)
77                 attName = attr.getName();
78             Datatype type = (Datatype) attr.getType();
79             if(type != null) {
80                 print("\n=================\n"+attName+"["+type.getName()+"]");
81                 printFacets(type);
82             }
83         }
84     }
85     
86     private void printFacets(final Datatype type) {
87         print("\nlength: "+type.getLengths());
88         print("\nminLength: "+type.getMinLengths());
89         print("\nmaxLength: "+type.getMaxLengths());
90         print("\npattern: "+type.getPatterns());
91         print("\nenum: "+type.getEnumerations());
92         print("\nwhitespace: "+type.getWhiteSpaces());
93     }
94     
95     private class TestVisitor extends DefaultVisitor {
96         
97         private int depth = 0;
98         
99         /**
100          * Creates a new instance of TestVisitor
101          */

102         public TestVisitor() {
103             try {
104             } catch(Exception JavaDoc ex) {
105                 //ex.printStackTrace();
106
assertTrue("Should not be here", false);
107             }
108         }
109         
110         public void visit(Element element) {
111             for(AbstractAttribute attr : element.getAttributes()) {
112                 visit(attr);
113             }
114             visitChildren(element);
115         }
116         
117         public void visit(AbstractAttribute attribute) {
118             attList.add(attribute);
119         }
120         
121         protected void visitChildren(AXIComponent component) {
122             for(AXIComponent child: component.getChildren()) {
123                 child.accept(this);
124             }
125         }
126     }
127     
128 }
129
Popular Tags