001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.xml.axi.datatype;
043:
044: import java.util.ArrayList;
045: import java.util.List;
046: import junit.framework.*;
047: import org.netbeans.modules.xml.axi.*;
048: import org.netbeans.modules.xml.axi.visitor.DefaultVisitor;
049:
050: /**
051: *
052: * @author Ayub Khan
053: */
054: public class DatatypePerfTest extends AbstractTestCase {
055:
056: public static final String TEST_XSD = "resources/OTA_TravelItinerary.xsd";
057: public static final String GLOBAL_ELEMENT = "OTA_TravelItineraryRS";
058:
059: private List<AbstractAttribute> attList;
060:
061: public DatatypePerfTest(String testName) {
062: super (testName, TEST_XSD, GLOBAL_ELEMENT);
063: }
064:
065: protected void setUp() throws Exception {
066: super .setUp();
067: attList = new ArrayList<AbstractAttribute>();
068: }
069:
070: public static Test suite() {
071: TestSuite suite = new TestSuite(DatatypePerfTest.class);
072:
073: return suite;
074: }
075:
076: /**
077: * Test of createElement method, of class org.netbeans.modules.xml.axi.XAMFactory.
078: */
079: public void testCreateDatatype() {
080: validateSchema(axiModel.getSchemaModel());
081: Element element = globalElement;
082: assertNotNull(element);
083:
084: attList.clear();
085: TestVisitor visitor = new TestVisitor();
086: visitor.visit(element);
087:
088: String contentType = "";
089: if (element.getType() instanceof Datatype)
090: contentType = element.getType().getName();
091: print("\n\n=================\nGE: " + element.getName() + "["
092: + contentType + "]");
093: }
094:
095: private void printAttributes(List<Attribute> attList) {
096: for (Attribute attr : attList) {
097: String attName = "";
098: if (attr.getName() != null)
099: attName = attr.getName();
100: Datatype type = (Datatype) attr.getType();
101: if (type != null) {
102: print("\n=================\n" + attName + "["
103: + type.getName() + "]");
104: printFacets(type);
105: }
106: }
107: }
108:
109: private void printFacets(final Datatype type) {
110: print("\nlength: " + type.getLengths());
111: print("\nminLength: " + type.getMinLengths());
112: print("\nmaxLength: " + type.getMaxLengths());
113: print("\npattern: " + type.getPatterns());
114: print("\nenum: " + type.getEnumerations());
115: print("\nwhitespace: " + type.getWhiteSpaces());
116: }
117:
118: private class TestVisitor extends DefaultVisitor {
119:
120: private int depth = 0;
121:
122: /**
123: * Creates a new instance of TestVisitor
124: */
125: public TestVisitor() {
126: try {
127: } catch (Exception ex) {
128: //ex.printStackTrace();
129: assertTrue("Should not be here", false);
130: }
131: }
132:
133: public void visit(Element element) {
134: for (AbstractAttribute attr : element.getAttributes()) {
135: visit(attr);
136: }
137: visitChildren(element);
138: }
139:
140: public void visit(AbstractAttribute attribute) {
141: attList.add(attribute);
142: }
143:
144: protected void visitChildren(AXIComponent component) {
145: for (AXIComponent child : component.getChildren()) {
146: child.accept(this);
147: }
148: }
149: }
150:
151: }
|