private boolean calculateWithValidValues() { Iterator it = metaProperties.iterator(); while (it.hasNext()) { MetaProperty m = (MetaProperty) it.next(); if (m.hasValidValues()) return true; } return false; }
public Collection getMetaPropertiesArguments() throws XavaException { StringTokenizer st = new StringTokenizer(getArguments(), ","); Collection result = new ArrayList(); while (st.hasMoreTokens()) { String argument = st.nextToken(); StringTokenizer argumentSt = new StringTokenizer(argument); String type = argumentSt.nextToken().trim(); String name = argumentSt.nextToken().trim(); MetaProperty p = new MetaProperty(); p.setName(name); p.setTypeName(type); result.add(p); } return result; }
private Object getValueWithoutWebEditorsFormat(int row, int column) { Object r = original.getValueAt(row, column); if (r instanceof Boolean) { if (((Boolean) r).booleanValue()) return XavaResources.getString(locale, "yes"); return XavaResources.getString(locale, "no"); } if (withValidValues) { MetaProperty p = getMetaProperty(column); if (p.hasValidValues()) { return p.getValidValueLabel(locale, original.getValueAt(row, column)); } } if (r instanceof java.util.Date) { MetaProperty p = getMetaProperty(column); // In order to use the type declared by the developer // and not the one returned by JDBC or the JPA engine if (java.sql.Time.class.isAssignableFrom(p.getType())) { return DateFormat.getTimeInstance(DateFormat.SHORT, locale).format(r); } if (java.sql.Timestamp.class.isAssignableFrom(p.getType())) { DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); return dateFormat.format(r); } return DateFormat.getDateInstance(DateFormat.SHORT, locale).format(r); } if (r instanceof BigDecimal) { return formatBigDecimal(r, locale); } return r; }
/** This method generates the output given a context and output stream */ public boolean generate(XPathContext context, ProgramWriter out) { try { String collectionName = Strings.firstUpper(collection.getName()); if (ejb) { out.print(" \n\t/**\n\t * @ejb:interface-method\n\t */"); } out.print(" \n\tpublic java.util.Collection get"); out.print(collectionName); out.print("() {"); if (ejb) { out.print( " \n\t\tboolean cmtActivated = false;\n\t\tif (!org.openxava.hibernate.XHibernate.isCmt()) {\n\t\t\torg.openxava.hibernate.XHibernate.setCmt(true);\n\t\t\tcmtActivated = true;\n\t\t}"); } out.print(" \n\t\ttry {"); MetaCalculator calculator = collection.getMetaCalculator(); String calculatorClass = calculator.getClassName(); out.print(" \t\t\n\t\t\t"); out.print(calculatorClass); out.print(" "); out.print(collection.getName()); out.print("Calculator= ("); out.print(calculatorClass); out.print(")\n\t\t\t\tgetMetaModel().getMetaCollection(\""); out.print(collection.getName()); out.print("\").getMetaCalculator().createCalculator();"); Iterator itSets = calculator.getMetaSetsWithoutValue().iterator(); while (itSets.hasNext()) { MetaSet set = (MetaSet) itSets.next(); String propertyNameInCalculator = Strings.firstUpper(set.getPropertyName()); String propertyNameFrom = set.getPropertyNameFrom(); MetaProperty p = metaModel.getMetaProperty(propertyNameFrom); if (propertyNameFrom.indexOf('.') >= 0) { if (p.isKey() || p.getMetaModel() instanceof MetaAggregate) { propertyNameFrom = Strings.firstUpper(Strings.change(propertyNameFrom, ".", "_")); } else { StringTokenizer st = new StringTokenizer(propertyNameFrom, "."); String ref = st.nextToken(); String pro = st.nextToken(); propertyNameFrom = Strings.firstUpper(ref) + "().get" + Strings.firstUpper(pro); } } else { propertyNameFrom = Strings.firstUpper(propertyNameFrom); } String getPropertyFrom = "boolean".equals(p.getTypeName()) ? "is" : "get"; String value = set.getValue(); if (set.hasValue()) { out.print(" \n\t\t\t"); out.print(collection.getName()); out.print("Calculator.set"); out.print(propertyNameInCalculator); out.print("(\""); out.print(value); out.print("\");"); } else { out.print(" \t\n\t\t\t"); out.print(collection.getName()); out.print("Calculator.set"); out.print(propertyNameInCalculator); out.print("("); out.print(getPropertyFrom); out.print(propertyNameFrom); out.print("());"); } } // else/sets if (IModelCalculator.class.isAssignableFrom(Class.forName(calculatorClass))) { out.print(" \n\t\t\t\t"); out.print(collection.getName()); out.print("Calculator.setModel(this);"); } if (IEntityCalculator.class.isAssignableFrom(Class.forName(calculatorClass))) { out.print(" \n\t\t\t\t"); out.print(collection.getName()); out.print("Calculator.setEntity(this);"); } if (IJDBCCalculator.class.isAssignableFrom(Class.forName(calculatorClass))) { out.print(" \n\t\t\t\t"); out.print(collection.getName()); out.print("Calculator.setConnectionProvider(getPortableContext());"); } String calculateValueSentence = collection.getName() + "Calculator.calculate()"; out.print(" \n\t\t\treturn "); out.print(Generators.generateCast("java.util.Collection", calculateValueSentence)); out.print( ";\n\t\t}\n\t\tcatch (Exception ex) {\n\t\t\tex.printStackTrace();\n\t\t\tthrow new "); out.print(getException()); out.print("(XavaResources.getString(\"generator.calculate_value_error\", \""); out.print(collection.getName()); out.print("\", \""); out.print(metaModel.getName()); out.print("\", ex.getLocalizedMessage()));\n\t\t}"); if (ejb) { out.print( " \n\t\tfinally {\n\t\t\tif (cmtActivated) {\n\t\t\t\torg.openxava.hibernate.XHibernate.setCmt(false);\n\t\t\t}\n\t\t}"); } out.print(" \t\t\t\t\n\t}"); } catch (Exception e) { System.out.println("Exception: " + e.getMessage()); e.printStackTrace(); return false; } return true; }