1 20 package org.objectweb.jorm.facility.naming.longid; 21 22 import org.objectweb.jorm.api.PException; 23 import org.objectweb.jorm.naming.api.PExceptionNaming; 24 import org.objectweb.jorm.naming.api.PNameGetter; 25 import org.objectweb.jorm.naming.lib.AbstractInheritKeyFilteredPNamingContext; 26 import org.objectweb.jorm.type.api.PType; 27 import org.objectweb.jorm.type.api.PTypeSpace; 28 29 40 public class LongIdPNC extends AbstractInheritKeyFilteredPNamingContext { 41 42 long lid; 43 44 48 private int cidSize; 49 50 55 public LongIdPNC(int cidsize) throws PException { 56 super(PTypeSpace.LONG, CTLONG); 57 setNullPName(new LongIdPName(-1, new LongIdBinder())); 58 ((LongIdBinder) getNull().getPNameManager()).setNullPName(getNull()); 59 setCidSize(cidsize); 60 init(); 61 } 62 63 66 public int getCidSize() { 67 return cidSize; 68 } 69 70 73 public void setCidSize(int cidSize) { 74 this.cidSize = cidSize; 75 } 76 77 85 public Object evaluate(Object png, Object ctx) throws PException { 86 if (png instanceof LongIdPNG) { 87 long id = ((LongIdPNG) png).pnGetLid(ctx); 88 id = id >> (LongIdManager.LONG_SIZE - cidSize); 89 return new Long (id); 90 } else if (png instanceof PNameGetter) { 91 long id = ((PNameGetter) png).pngetLongField("lid", ctx); 92 id = id >> (LongIdManager.LONG_SIZE - cidSize); 93 return new Long (id); 94 } else if (png instanceof Long ) { 95 long id = ((Long ) png).longValue(); 96 id = id >> (LongIdManager.LONG_SIZE - cidSize); 97 return new Long (id); 98 } 99 throw new PExceptionNaming( 100 "Impossible to evaluate without a PNameGetter: " + png); 101 } 102 103 public void setNullPName(Object o) throws PException { 104 super.setNullPName(o); 105 PNameGetter png = (PNameGetter) nullPName.encodeAbstract(); 107 lid = png.pngetLongField("lid", null); 108 } 109 110 public boolean isNull(Object _png, Object ctx) throws PException { 111 if (_png instanceof org.objectweb.jorm.facility.naming.longid.LongIdPNG) { 112 org.objectweb.jorm.facility.naming.longid.LongIdPNG png = (org.objectweb.jorm.facility.naming.longid.LongIdPNG) _png; 113 if (this.lid != png.pnGetLid(ctx)) { 114 return false; 115 } 116 } else if (_png instanceof PNameGetter) { 117 PNameGetter png = (PNameGetter) _png; 118 if (this.lid != png.pngetLongField("lid", ctx)) { 119 return false; 120 } 121 } else { 122 throw new PException("The specified pname getter is not supported: " + _png); 123 } 124 return true; 125 } 126 127 public void setPType(PType pt) { 128 super.setPType(pt); 129 nullPName.getPNameManager().setPType(pt); 130 } 131 132 } 133 | Popular Tags |