1 19 20 package org.netbeans.modules.xml.xsd; 21 22 import java.util.*; 23 24 import org.netbeans.modules.xml.api.model.GrammarQuery; 25 import org.netbeans.modules.xml.api.model.GrammarResult; 26 import org.netbeans.modules.xml.api.model.HintContext; 27 28 29 30 37 class XSDGrammar implements GrammarQuery { 38 39 40 private Map elements; 41 42 private Map types; 43 44 private Namespace namespace; 45 46 private Namespace schemaNamespace; 47 private Namespace targetNamespace; 48 49 50 XSDGrammar(Map elements, Map types, Namespace targetNamespace, Namespace schemaNamespace) { 51 this.elements = elements; 52 this.types = types; 53 this.namespace = null; 54 this.schemaNamespace = schemaNamespace; 55 this.targetNamespace = targetNamespace; 56 } 57 58 59 public java.awt.Component getCustomizer(HintContext nodeCtx) { 60 return null; 61 } 62 63 64 public org.openide.nodes.Node.Property[] getProperties(HintContext nodeCtx) { 65 return null; 66 } 67 68 69 public boolean hasCustomizer(HintContext nodeCtx) { 70 return false; 71 } 72 73 76 public boolean isAllowed(Enumeration en) { 77 return true; 78 } 79 80 public Enumeration queryAttributes(HintContext ownerElementCtx) { 81 Thread.dumpStack(); 82 return Collections.enumeration(new ArrayList()); 83 } 84 85 public GrammarResult queryDefault(HintContext parentNodeCtx) { 86 Thread.dumpStack(); 87 return null; 88 } 89 90 public Enumeration queryElements(HintContext virtualElementCtx) { 91 String parentName = computeUnprefixedName(virtualElementCtx.getParentNode().getNodeName()); 92 SchemaElement parent = (SchemaElement) elements.get(parentName); 93 94 if (parent == null) { 95 return Collections.enumeration(new ArrayList()); 96 } 97 98 ArrayList list = new ArrayList(50); 99 String previous = (virtualElementCtx.getPreviousSibling() == null ? null : computeUnprefixedName(virtualElementCtx.getPreviousSibling().getNodeName())); 100 System.err.println("PREVIOUS: " + previous); 101 103 resolveChildren(parent, list, getNamespace()); 104 if (previous != null) { 105 System.err.println("list size: " + list.size()); 106 while (list.size() > 0) { 107 SchemaElement e = (SchemaElement) list.get(0); 108 String ename = e.getSAXAttributes().getValue("name"); 109 System.err.println("ENAME: " + ename); 110 111 if (ename == null || (! ename.equalsIgnoreCase(previous))) { 112 list.remove(0); 113 System.err.println("REMOVED ENAME"); 114 } else { 115 list.remove(0); 116 System.err.println("BUILD DONE"); 117 break; 118 } 119 } 120 } 121 122 return Collections.enumeration(list); 123 } 124 125 126 private String computeUnprefixedName(String s) { 127 assert namespace != null; 128 assert s != null; 129 130 int i = s.indexOf(':'); 131 if (i >= 0) { 132 String ret = s.substring(i + 1); 133 System.err.println("computeUN nsPref: " + namespace.getPrefix() + " name: " + s + " ret: " + ret); 134 assert namespace.getPrefix().equals(s.substring(0, i)); 135 return ret; 136 } 137 return s; 138 } 139 140 private static void resolveChildren(SchemaElement parent, List list, Namespace ns) { 141 Iterator it = parent.getSubelements(); 142 while (it.hasNext()) { 143 SchemaElement e = (SchemaElement) it.next(); 144 if (e.isComposite()) { 145 System.err.println("RESOLVE COMPOSITE: " + e.getQname()); 146 resolveChildren(e, list, ns); 147 } else { 148 System.err.println("ADDING NON COMPOSITE: " + e.getQname()); 149 e.setPrefix(ns.getPrefix()); 150 list.add(e); 151 } 152 } 153 } 154 155 public Enumeration queryEntities(String prefix) { 156 Thread.dumpStack(); 157 return Collections.enumeration(new ArrayList()); 158 } 159 160 public Enumeration queryNotations(String prefix) { 161 Thread.dumpStack(); 162 return Collections.enumeration(new ArrayList()); 163 } 164 165 public Enumeration queryValues(HintContext virtualTextCtx) { 166 Thread.dumpStack(); 167 return Collections.enumeration(new ArrayList()); 168 } 169 170 174 public org.netbeans.modules.xml.xsd.Namespace getNamespace() { 175 return namespace; 176 } 177 178 182 public void setNamespace(org.netbeans.modules.xml.xsd.Namespace namespace) { 183 this.namespace = namespace; 184 } 185 186 } | Popular Tags |