KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > axi > impl > GardenOfEden


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.axi.impl;
21
22 import java.io.IOException JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.HashMap JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import org.netbeans.modules.xml.axi.AXIComponent;
27 import org.netbeans.modules.xml.axi.Attribute;
28 import org.netbeans.modules.xml.axi.Compositor;
29 import org.netbeans.modules.xml.axi.ContentModel;
30 import org.netbeans.modules.xml.axi.Element;
31 import org.netbeans.modules.xml.axi.SchemaGenerator;
32 import org.netbeans.modules.xml.axi.datatype.Datatype;
33 import org.netbeans.modules.xml.schema.model.*;
34 import org.netbeans.modules.xml.xam.dom.NamedComponentReference;
35
36 /**
37  *
38  * @author Ayub Khan
39  */

40 public class GardenOfEden extends DefaultSchemaGenerator {
41     
42     /**
43      * Creates a new instance of GardenOfEden
44      */

45     public GardenOfEden(SchemaGenerator.Mode mode) {
46         super(mode);
47     }
48     
49     protected SchemaGenerator.Pattern getSchemaDesignPattern() {
50         return SchemaGenerator.Pattern.GARDEN_OF_EDEN;
51     }
52     
53     public void visit(Element element) {
54         prepareGlobalElement(element);
55     }
56     
57     public void visit(Datatype d) {
58         createGlobalSimpleType(d, sm, datatypeParent, id, pc);
59     }
60     
61     protected void setPeer(final Element element,
62             final org.netbeans.modules.xml.schema.model.Element e,
63             final ElementReference eref) {
64         if(getMode() != SchemaGenerator.Mode.TRANSFORM)
65             super.setPeer(element, e, eref);
66         else {
67             if(element.getChildren().size() > 0) {
68                 GlobalComplexType gct = (GlobalComplexType) getRef(e);
69                 if(gct == null) {
70                     GlobalComplexType foundgct = null;
71                     //check type from another schema model
72
gct = SchemaGeneratorUtil.findTypeFromOtherModel(e, element, sm);
73                     if(gct == null) {
74                         String JavaDoc typeName = null;
75                         if(element.getType() instanceof ContentModel) {
76                             typeName = ((ContentModel)element.getType()).getName();
77                             HashMap JavaDoc<String JavaDoc, SchemaComponent> map =
78                                     namesMap.get(GlobalComplexType.class);
79                             if(map != null && map.get(typeName) != null) {
80                                 foundgct = (GlobalComplexType) map.get(typeName);
81                                 addRef(e, foundgct);
82                             }
83                         }
84                         if(typeName == null)
85                             typeName = element.getName()+"Type";
86                         gct = createGlobalComplexType(typeName);
87                         if(foundgct != null)
88                             SchemaGeneratorUtil.setType(e, foundgct);
89                         else {
90                             sgh.addComplexType(gct, -1);
91                             SchemaGeneratorUtil.setType(e, gct);
92                             addRef(e, gct);
93                         }
94                     }
95                 }
96                 assert gct != null;
97                 scParent = gct;
98             } else
99                 scParent = e;
100         }
101     }
102     
103     protected SchemaComponent getParent(final AXIComponent axiparent)
104     throws IllegalArgumentException JavaDoc {
105         SchemaComponent scParent = null;
106         if(axiparent instanceof Element){
107             SchemaComponent e = axiparent.getPeer();
108             if(e instanceof ElementReference) {
109                 e = getRef(e);
110                 assert e != null;
111             }
112             scParent = getRef(e);
113             if(scParent == null) {
114                 scParent = SchemaGeneratorUtil.getLocalComplexType(e);
115                 if(scParent == null)
116                     scParent = createPeerGlobalComplexType((Element)axiparent);
117                 addRef(e, (GlobalType) scParent);
118             }
119         } else
120             scParent = super.getParent(axiparent);
121         return scParent;
122     }
123 }
124
Popular Tags