1 19 package org.netbeans.modules.xslt.model.impl; 20 21 import java.util.Collection ; 22 import java.util.LinkedHashSet ; 23 import java.util.LinkedList ; 24 import java.util.List ; 25 import java.util.StringTokenizer ; 26 27 import javax.xml.namespace.QName ; 28 29 import org.netbeans.modules.xml.xam.Model; 30 import org.netbeans.modules.xml.xam.Reference; 31 import org.netbeans.modules.xslt.model.AttributeSet; 32 import org.netbeans.modules.xslt.model.ReferenceableXslComponent; 33 import org.netbeans.modules.xslt.model.Stylesheet; 34 import org.netbeans.modules.xslt.model.XslModel; 35 import org.netbeans.modules.xslt.model.XslReference; 36 37 38 44 class AttributeSetReferenceListResolver implements 45 ReferenceListResolveFactory 46 { 47 48 51 public boolean isApplicable( Class referenceType ) { 52 return AttributeSet.class.isAssignableFrom( referenceType ); 53 } 54 55 58 public <T extends ReferenceableXslComponent> List <XslReference<T>> resolve( 59 AttributeAccess access, Class <T> clazz, String value ) 60 { 61 StringTokenizer tokenizer = new StringTokenizer (value, " "); 62 List <Reference<T>> references = new LinkedList <Reference<T>>(); 63 while (tokenizer.hasMoreTokens()) { 64 String next = tokenizer.nextToken(); 65 Collection <Reference<T>> collection = find( clazz , next , access ); 66 references.addAll( collection ); 67 } 68 return null; 69 } 70 71 @SuppressWarnings ("unchecked") 72 private <T extends ReferenceableXslComponent> Collection <Reference<T>> 73 find( Class <T> clazz, String next , AttributeAccess access) 74 { 75 assert AttributeSet.class.isAssignableFrom( clazz ); 76 LinkedHashSet <XslModel> list = Utilities.getAvailibleModels( 77 access.getComponent().getModel()); 78 Collection <Reference<T>> collection = new LinkedList <Reference<T>>(); 79 QName qName = getQName( next , access ); 80 for (XslModel model : list) { 81 if ( Model.State.VALID.equals( model.getState() )) { 82 Stylesheet stylesheet = model.getStylesheet(); 83 if ( stylesheet == null ) { 84 continue; 85 } 86 List <AttributeSet> children = 87 stylesheet.getChildren( AttributeSet.class ); 88 Collection <AttributeSet> result = find( children , qName ); 89 for (AttributeSet set : result) { 90 XslReference<AttributeSet> ref = 91 new GlobalReferenceImpl<AttributeSet>( set , 92 AttributeSet.class , access.getComponent() ); 93 if ( result != null ) { 94 collection.add( (Reference<T>) ref ); 95 } 96 } 97 } 98 } 99 return null; 100 } 101 102 private QName getQName( String value, AttributeAccess access ) { 103 assert value!=null; 104 String [] parts = value.split(":"); String prefix = null; 106 String localPart; 107 if (parts.length == 2) { 108 prefix = parts[0]; 109 localPart = parts[1]; 110 } else { 111 localPart = parts[0]; 112 } 113 String ns = access.getComponent().lookupNamespaceURI(prefix); 114 return new QName ( ns , localPart , prefix ); 115 } 116 117 private Collection <AttributeSet> find( 118 List <AttributeSet> children , QName qName) 119 { 120 Collection <AttributeSet> collection = new LinkedList <AttributeSet>(); 121 assert qName != null; 122 for (AttributeSet set : children) { 123 QName name = set.getName(); 124 if ( name == null ) { 125 continue; 126 } 127 String localPart = name.getLocalPart(); 128 String ns = name.getNamespaceURI(); 129 if ( qName.getLocalPart().equals( localPart) 130 && Utilities.equals( qName.getNamespaceURI() , ns ) ) 131 { 132 collection.add( set ); 133 } 134 } 135 return collection; 136 } 137 138 } 139 | Popular Tags |