View Javadoc

1   /*
2    * Copyright (C) 2007 ETH Zurich
3    *
4    * This file is part of Fosstrak (www.fosstrak.org).
5    *
6    * Fosstrak is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Lesser General Public
8    * License version 2.1, as published by the Free Software Foundation.
9    *
10   * Fosstrak is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13   * Lesser General Public License for more details.
14   *
15   * You should have received a copy of the GNU Lesser General Public
16   * License along with Fosstrak; if not, write to the Free
17   * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18   * Boston, MA  02110-1301  USA
19   */
20  
21  package org.fosstrak.epcis.repository.model;
22  
23  import java.sql.Timestamp;
24  
25  import org.fosstrak.epcis.utils.TimeParser;
26  import org.apache.commons.logging.Log;
27  import org.apache.commons.logging.LogFactory;
28  
29  /**
30   * A simple representation for an event field extension.
31   * 
32   * @author Marco Steybe
33   */
34  public class EventFieldExtension {
35  
36      private static final Log LOG = LogFactory.getLog(EventFieldExtension.class);
37  
38      private Long id;
39      private String prefix = null;
40      private String namespace = null;
41      private String localname = null;
42      private String fieldname = null;
43      private String valueColumnName = null;
44      private Integer intValue = null;
45      private Float floatValue = null;
46      private Timestamp dateValue = null;
47      private String strValue = null;
48  
49      /**
50       * Constructs a new EventFieldExtension from the parameters. The value will
51       * be parsed to see if it represents an integer, a float, a date, or a
52       * string.
53       * 
54       * @param prefix
55       *            The prefix of the event field.
56       * @param namespace
57       *            The namespace for the prefix.
58       * @param localname
59       *            The localname (tag name) of the event field.
60       * @param value
61       *            The value of the event field.
62       */
63      public EventFieldExtension(final String prefix, final String namespace, final String localname, final String value) {
64          this.localname = localname;
65          this.prefix = prefix;
66          this.namespace = namespace;
67          this.fieldname = namespace + "#" + localname;
68          LOG.debug("    resolved fieldname of extension to '" + fieldname + "'");
69          this.strValue = value;
70          // try parsing the value
71          try {
72              this.intValue = new Integer(strValue);
73              this.valueColumnName = "intValue";
74              LOG.debug("    value of extension is of type Integer.");
75          } catch (NumberFormatException e1) {
76              try {
77                  this.floatValue = new Float(strValue);
78                  this.valueColumnName = "floatValue";
79                  LOG.info("    value of extension is of type Float.");
80              } catch (NumberFormatException e2) {
81                  try {
82                      this.dateValue = TimeParser.parseAsTimestamp(strValue);
83                      this.valueColumnName = "dateValue";
84                      LOG.info("    value of extension is of type Date.");
85                  } catch (Exception e3) {
86                      // treat value as String
87                      LOG.info("    value of extension is of type String.");
88                      this.valueColumnName = "strValue";
89                  }
90              }
91          }
92      }
93  
94      public EventFieldExtension() {
95          super();
96      }
97  
98      public Long getId() {
99          return id;
100     }
101 
102     public void setId(Long id) {
103         this.id = id;
104     }
105 
106     /**
107      * @return The date value of the event field extension.
108      */
109     public Timestamp getDateValue() {
110         return dateValue;
111     }
112 
113     /**
114      * @return The name of the event field extension.
115      */
116     public String getFieldname() {
117         return fieldname;
118     }
119 
120     /**
121      * @return The float value of the event field extension.
122      */
123     public Float getFloatValue() {
124         return floatValue;
125     }
126 
127     /**
128      * @return The int value of the event field extension.
129      */
130     public Integer getIntValue() {
131         return intValue;
132     }
133 
134     /**
135      * @return The localname of the event field extension.
136      */
137     public String getLocalname() {
138         return localname;
139     }
140 
141     /**
142      * @return The namespace of the event field extension.
143      */
144     public String getNamespace() {
145         return namespace;
146     }
147 
148     /**
149      * @return The prefix of the event field extension.
150      */
151     public String getPrefix() {
152         return prefix;
153     }
154 
155     /**
156      * @return The string value of the event field extension.
157      */
158     public String getStrValue() {
159         return strValue;
160     }
161 
162     /**
163      * @return The value column name of the event field extension.
164      */
165     public String getValueColumnName() {
166         return valueColumnName;
167     }
168 
169     public void setDateValue(Timestamp dateValue) {
170         this.dateValue = dateValue;
171     }
172 
173     public void setFieldname(String fieldname) {
174         this.fieldname = fieldname;
175     }
176 
177     public void setFloatValue(Float floatValue) {
178         this.floatValue = floatValue;
179     }
180 
181     public void setIntValue(Integer intValue) {
182         this.intValue = intValue;
183     }
184 
185     public void setLocalname(String localname) {
186         this.localname = localname;
187     }
188 
189     public void setNamespace(String namespace) {
190         this.namespace = namespace;
191     }
192 
193     public void setPrefix(String prefix) {
194         this.prefix = prefix;
195     }
196 
197     public void setStrValue(String strValue) {
198         this.strValue = strValue;
199     }
200 
201     public void setValueColumnName(String valueColumnName) {
202         this.valueColumnName = valueColumnName;
203     }
204 
205 }