1 23 24 package examples.invoice.persistclass; 25 26 import org.objectweb.jorm.api.PAccessor; 27 import org.objectweb.jorm.api.PBinding; 28 import org.objectweb.jorm.api.PException; 29 import org.objectweb.jorm.naming.api.PName; 30 import org.objectweb.jorm.naming.api.PNamingContext; 31 32 35 public class ProdUnits implements PAccessor, ProdUnitsAccessor { 36 private PName productPn; 37 private Product product; 38 private int quantity; 39 private PBinding pBinding; 40 private ProdUnitsHelper prodUnitsHelper; 41 private PNamingContext productNC; 42 43 public PBinding getPBinding() { 44 return pBinding; 45 } 46 47 50 private Product getProduct() throws PException { 51 try { 52 if (product == null) 53 product = prodUnitsHelper.getProductHelper().getProduct( 54 pBinding.getPClassMapping().getPMapper(), productPn); 55 } catch (Exception e) { 56 e.printStackTrace(); 57 throw new PException(e, "Cannot getProduct within ProdUnits!"); 58 } 59 return product; 60 } 61 62 65 public ProdUnits(ProdUnitsHelper puh, Object conn, PBinding pb, PName pn, int quant) throws PException { 66 prodUnitsHelper = puh; 67 pBinding = pb; 68 productNC = (PNamingContext) pBinding.getPClassMapping().getPNameCoder("product"); 69 productPn = pn; 70 quantity = quant; 71 pBinding.export(conn); 72 pBinding.write(conn, this); 73 } 74 75 78 public ProdUnits(ProdUnitsHelper puh, Object conn, PBinding pb) throws PException { 79 prodUnitsHelper = puh; 80 pBinding = pb; 81 productNC = (PNamingContext) pBinding.getPClassMapping().getPNameCoder("product"); 82 pb.read(conn, this); 83 } 84 85 88 public void delete(Object conn) throws PException { 89 pBinding.unexport(conn); 90 pBinding.write(conn, this); 91 pBinding = null; 92 } 93 94 97 public String toPrintable() throws PException { 98 return "ID: [" + pBinding.getPName().encodeString() + "] - VALUE: [product: [" + getProduct().toPrintable() + "], quantity: " + quantity + "]"; 99 } 100 101 103 public Object getMemoryInstance() { 104 return this; 105 } 106 107 109 public void paSetProduct(PName val, Object conn) throws PException { 111 productPn = productNC.resolve(conn, val); 112 } 113 114 public PName paGetProduct(Object conn) throws PException { 115 return productNC.export(conn, productPn); 116 } 117 118 public void paSetQuantity(int val) throws PException { 120 quantity = val; 121 } 122 123 public int paGetQuantity() throws PException { 124 return quantity; 125 } 126 } 127 | Popular Tags |