1 6 7 package com.hp.hpl.jena.enhanced; 8 9 import com.hp.hpl.jena.graph.*; 10 import com.hp.hpl.jena.util.cache.*; 11 12 26 27 public class EnhGraph 28 extends Polymorphic 29 { 30 32 protected Graph graph; 33 34 35 static private int cnt = 0; 36 37 38 protected Cache enhNodes = CacheManager.createCache( CacheManager.ENHNODECACHE, "EnhGraph-" + cnt++, 1000 ); 39 40 41 private Personality personality; 42 43 public boolean isValid() 44 { return true; } 45 46 55 public EnhGraph( Graph g, Personality p ) { 56 super(); 57 graph = g; 58 personality = p; 59 } 60 61 63 67 public Graph asGraph() { 68 return graph; 69 } 70 71 75 final public int hashCode() { 76 return graph.hashCode(); 77 } 78 79 80 93 final public boolean equals(Object o) { 94 return 95 this == o 96 || o instanceof EnhGraph && graph.equals(((EnhGraph) o).asGraph()); 97 } 98 99 100 108 final public boolean isIsomorphicWith(EnhGraph eg){ 109 return graph.isIsomorphicWith(eg.graph); 110 } 111 112 120 public EnhNode getNodeAs(Node n,Class interf) { 121 EnhNode eh = (EnhNode)enhNodes.get(n); 123 if ( eh != null ) 124 return eh.viewAs(interf); 125 126 eh = (EnhNode) ((GraphPersonality) personality).nodePersonality() 128 .newInstance( interf, n, this ); 129 enhNodes.put( n, eh ); 130 return eh; 131 } 132 133 134 138 public CacheControl getNodeCacheControl() { 139 return enhNodes; 140 } 141 142 146 public void setNodeCache(Cache cc) { 147 enhNodes = cc; 148 } 149 150 151 158 protected Polymorphic convertTo(Class t) { 159 throw new PersonalityConfigException 160 ( "Alternative perspectives on graphs has not been implemented yet" ); 161 } 162 163 167 protected boolean canSupport( Class t ) 168 { return false; } 169 170 175 protected Personality getPersonality() { 176 return personality; 177 } 178 179 180 } 181 182 211 | Popular Tags |