KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > cowsultants > itracker > ejb > beans > entity > CustomFieldBean


1 /*
2  * This software was designed and created by Jason Carroll.
3  * Copyright (c) 2002, 2003, 2004 Jason Carroll.
4  * The author can be reached at jcarroll@cowsultants.com
5  * ITracker website: http://www.cowsultants.com
6  * ITracker forums: http://www.cowsultants.com/phpBB/index.php
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it only under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  */

18
19 package cowsultants.itracker.ejb.beans.entity;
20
21 import java.util.*;
22 import java.sql.Timestamp JavaDoc;
23
24 import cowsultants.itracker.ejb.client.models.CustomFieldModel;
25 import cowsultants.itracker.ejb.client.models.CustomFieldValueModel;
26
27 public abstract class CustomFieldBean extends GenericBean {
28
29     public abstract int getFieldType();
30     public abstract void setFieldType(int value);
31
32     public abstract String JavaDoc getDateFormat();
33     public abstract void setDateFormat(String JavaDoc value);
34
35     public abstract int getRequired();
36     public abstract void setRequired(int value);
37
38     public abstract int getSortOptionsByName();
39     public abstract void setSortOptionsByName(int value);
40
41     public abstract Collection getValues();
42     public abstract void setValues(Collection values);
43
44     public abstract Collection getProjects();
45     public abstract void setProjects(Collection projects);
46
47     public abstract Collection getFields();
48     public abstract void setFields(Collection values);
49
50     public CustomFieldModel getModel() {
51         CustomFieldModel model = new CustomFieldModel();
52         model.setId(this.getId());
53         model.setFieldType(this.getFieldType());
54         model.setDateFormat(this.getDateFormat());
55         model.setRequired((this.getRequired() == 1 ? true : false));
56         model.setSortOptionsByName((this.getSortOptionsByName() == 1 ? true : false));
57         model.setLastModifiedDate(this.getLastModifiedDate());
58         model.setCreateDate(this.getCreateDate());
59
60         int i = 0;
61         Collection values = this.getValues();
62         CustomFieldValueModel[] options = new CustomFieldValueModel[values.size()];
63         for(Iterator iterator = values.iterator(); iterator.hasNext(); i++) {
64             options[i] = ((CustomFieldValueLocal) iterator.next()).getModel();
65         }
66         Arrays.sort(options, new CustomFieldValueModel().new CompareBySortOrder());
67         model.setOptions(options);
68
69         return model;
70     }
71
72     public void setModel(CustomFieldModel model) {
73         this.setFieldType(model.getFieldType());
74         this.setDateFormat(model.getDateFormat());
75         this.setRequired((model.isRequired() ? 1 : 0));
76         this.setSortOptionsByName((model.getSortOptionsByName() ? 1 : 0));
77         this.setLastModifiedDate(new Timestamp JavaDoc(new Date().getTime()));
78     }
79
80 }
81
Popular Tags