1 19 20 package org.netbeans.modules.xml.axi.impl; 21 22 import java.io.IOException ; 23 import java.util.ArrayList ; 24 import java.util.HashMap ; 25 import java.util.Iterator ; 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 40 public class GardenOfEden extends DefaultSchemaGenerator { 41 42 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 gct = SchemaGeneratorUtil.findTypeFromOtherModel(e, element, sm); 73 if(gct == null) { 74 String typeName = null; 75 if(element.getType() instanceof ContentModel) { 76 typeName = ((ContentModel)element.getType()).getName(); 77 HashMap <String , 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 { 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 |