1 package org.paneris.jammyjoes.model;
2
3 import java.util.Enumeration;
4
5 import org.melati.poem.Database;
6 import org.melati.poem.DefinitionSource;
7 import org.melati.poem.PoemException;
8 import org.paneris.jammyjoes.controller.ParameterProvider;
9 import org.paneris.jammyjoes.controller.SearchType;
10 import org.paneris.jammyjoes.model.generated.TypeTableBase;
11
12 public class TypeTable extends TypeTableBase {
13
14 public TypeTable(Database database, String name, DefinitionSource definitionSource)
15 throws PoemException {
16 super(database, name, definitionSource);
17 }
18
19 public SearchType fromParameter(ParameterProvider provider) {
20 String typeString = provider.getParam("field_type", 1);
21 if (typeString != null) {
22 try {
23 return new SearchType((Type)getObject(asInt(typeString)));
24 } catch (NumberFormatException e) {
25 Enumeration en = getTypeColumn().selectionWhereEq(typeString);
26 if (en.hasMoreElements()) {
27 return new SearchType((Type)en.nextElement());
28 }
29 }
30 }
31 return new SearchType();
32 }
33
34
35 public Integer asInt(String in) {
36 return in == null ? null : new Integer(in);
37 }
38
39 }