1 6 7 package com.hp.hpl.jena.enhanced; 8 9 import java.util.*; 10 import com.hp.hpl.jena.graph.*; 11 import com.hp.hpl.jena.util.CollectionFactory; 12 13 21 public class Personality { 22 23 25 private Map types = CollectionFactory.createHashedMap(); 26 27 29 30 protected Personality() 31 {} 32 33 34 public Personality( Personality other ) 35 { 36 this(); 37 this.add( other ); 38 } 39 40 42 46 public Personality add( Class interf, Implementation impl ) 47 { 48 types.put( interf, impl ); 49 return this; 50 } 51 52 56 public Personality copy() 57 { return new Personality( this ); } 58 59 63 Implementation getImplementation( Class t ) 64 { return (Implementation) types.get( t ); } 65 66 70 Personality add( Personality p ) { 71 types.putAll( p.types ); 72 return this; 73 } 74 75 80 public Polymorphic newInstance(Class interf, Node n, Polymorphic that ) 81 { 82 Implementation impl = (Implementation) types.get( interf ); 83 if (impl == null) throw new PersonalityConfigException( interf + " not in Personality." ); 84 Polymorphic rslt = impl.wrap( n, (EnhGraph) that ); 85 if (!interf.isInstance(rslt)) 86 throw new PersonalityConfigException( interf + " misconfigured." ); 87 88 return rslt; 89 } 90 91 protected Map getMap() {return types;} 92 } 93 94 123 | Popular Tags |