1 18 19 package org.objectweb.jac.aspects.gui.reports; 20 21 import dori.jasper.engine.JRDataSource; 22 import dori.jasper.engine.JRException; 23 import dori.jasper.engine.JRField; 24 import java.util.Collection ; 25 import java.util.Iterator ; 26 import org.objectweb.jac.aspects.gui.GuiAC; 27 import org.objectweb.jac.core.ObjectRepository; 28 import org.objectweb.jac.core.rtti.ClassItem; 29 import org.objectweb.jac.core.rtti.ClassRepository; 30 import org.objectweb.jac.core.rtti.CollectionItem; 31 32 35 public class JacDataSource implements JRDataSource { 36 ClassItem componentType; 37 Collection collection; 38 39 Iterator it; 40 Object current; 41 42 45 public JacDataSource(ClassItem cl) { 46 this.componentType = cl; 47 this.collection = ObjectRepository.getObjects(cl); 48 } 49 50 56 public JacDataSource(Collection collection, ClassItem componentType) { 57 this.collection = collection; 58 this.componentType = componentType; 59 } 60 61 67 public JacDataSource(Object substance, CollectionItem collection) { 68 this.collection = collection.getActualCollectionThroughAccessor(substance); 69 this.componentType = collection.getComponentType(); 70 } 71 72 73 79 public JacDataSource(Object substance, String collectionName) { 80 this(substance,ClassRepository.get().getClass(substance).getCollection(collectionName)); 81 } 82 84 public boolean next() throws JRException 85 { 86 if (it==null) { 87 it = collection.iterator(); 88 } 89 boolean result = it.hasNext(); 90 if (result) 91 current = it.next(); 92 return result; 93 } 94 95 99 public Object getFieldValue(JRField field) throws JRException 100 { 101 if (current==null) { 102 throw new JRException( 103 "JacDataSource: No current object to get field "+ 104 field.getName()); 105 } 106 String name = field.getDescription(); 107 Object value = null; 108 if (componentType!=null) { 109 value = componentType.getField(name).getThroughAccessor(current); 110 } else { 111 ClassItem cl = ClassRepository.get().getClass(current); 112 value = cl.getField(name).getThroughAccessor(current); 113 } 114 115 if (field.getValueClass()==String .class && 116 value!=null && 117 value.getClass()!=String .class) { 118 value = GuiAC.toString(value); 119 } 120 return value; 121 } 122 123 } 124 | Popular Tags |