1 6 7 package com.hp.hpl.jena.graph.compose; 8 9 import java.util.*; 10 11 import com.hp.hpl.jena.graph.Graph; 12 import com.hp.hpl.jena.shared.PrefixMapping; 13 import com.hp.hpl.jena.shared.impl.PrefixMappingImpl; 14 import com.hp.hpl.jena.util.CollectionFactory; 15 16 17 public class PolyadicPrefixMappingImpl extends PrefixMappingImpl implements PrefixMapping 18 { 19 private Polyadic poly; 20 private PrefixMapping pending = new PrefixMappingImpl(); 21 22 public PolyadicPrefixMappingImpl( Polyadic p ) 23 { poly = p; 24 } 25 26 private PrefixMapping getBaseMapping() 27 { 28 Graph base = poly.getBaseGraph(); 29 return base == null ? pending : base.getPrefixMapping(); 30 } 31 32 public PrefixMapping setNsPrefix( String prefix, String uri ) 33 { 34 checkUnlocked(); 35 getBaseMapping().setNsPrefix( prefix, uri ); 36 return this; 37 } 38 39 public PrefixMapping removeNsPrefix( String prefix ) 40 { 41 checkUnlocked(); 42 getBaseMapping().removeNsPrefix( prefix ); 43 return this; 44 } 45 46 52 public PrefixMapping setNsPrefixes( PrefixMapping other ) 53 { return setNsPrefixes( other.getNsPrefixMap() ); } 54 55 63 public PrefixMapping setNsPrefixes( Map other ) 64 { 65 checkUnlocked(); 66 getBaseMapping().setNsPrefixes( other ); 67 return this; 68 } 69 70 public String getNsPrefixURI( String prefix ) 71 { 72 PrefixMapping bm = getBaseMapping(); 73 String s = bm.getNsPrefixURI( prefix ); 74 if (s == null) 75 { 76 List graphs = poly.getSubGraphs(); 77 for (int i = 0; i < graphs.size(); i += 1) 78 { 79 String ss = ((Graph) graphs.get(i)).getPrefixMapping().getNsPrefixURI( prefix ); 80 if (ss != null) return ss; 81 } 82 } 83 return s; 84 } 85 86 public Map getNsPrefixMap() 87 { 88 Map result = CollectionFactory.createHashedMap(); 89 List graphs = poly.getSubGraphs(); 90 for (int i = 0; i < graphs.size(); i += 1) 91 result.putAll( ((Graph) graphs.get(i)).getPrefixMapping().getNsPrefixMap() ); 92 result.putAll( getBaseMapping().getNsPrefixMap() ); 93 return result; 94 } 95 96 public String getNsURIPrefix( String uri ) 97 { 98 String s = getBaseMapping().getNsURIPrefix( uri ); 99 if (s == null) 100 { 101 List graphs = poly.getSubGraphs(); 102 for (int i = 0; i < graphs.size(); i += 1) 103 { 104 String ss = ((Graph) graphs.get(i)).getPrefixMapping().getNsURIPrefix( uri ); 105 if (ss != null) return ss; 106 } 107 } 108 return s; 109 } 110 111 116 public String expandPrefix( String prefixed ) 117 { 118 String s = getBaseMapping().expandPrefix( prefixed ); 119 if (s.equals( prefixed )) 120 { 121 List graphs = poly.getSubGraphs(); 122 for (int i = 0; i < graphs.size(); i += 1) 123 { 124 String ss = ((Graph) graphs.get(i)).getPrefixMapping().expandPrefix( prefixed ); 125 if (!ss.equals( prefixed )) return ss; 126 } 127 } 128 return s; 129 } 130 131 134 public String toString() 135 { return "<polyadic prefix map>"; } 136 137 144 public String shortForm( String uri ) 145 { 146 String s = getBaseMapping().shortForm( uri ); 147 if (s.equals( uri )) 148 { 149 List graphs = poly.getSubGraphs(); 150 for (int i = 0; i < graphs.size(); i += 1) 151 { 152 String ss = ((Graph) graphs.get(i)).getPrefixMapping().shortForm( uri ); 153 if (!ss.equals( uri )) return ss; 154 } 155 } 156 return s; 157 } 158 159 public String qnameFor( String uri ) 160 { 161 String result = getBaseMapping().qnameFor( uri ); 162 if (result == null) 163 { 164 List graphs = poly.getSubGraphs(); 165 for (int i = 0; i < graphs.size(); i += 1) 166 { 167 String ss = ((Graph) graphs.get(i)).getPrefixMapping().qnameFor( uri ); 168 if (ss != null) return ss; 169 } 170 } 171 return result; 172 } 173 } 174 175 | Popular Tags |