1    /*
2     * Copyright 2008 :torweg free software group
3     * 
4     * This program is free software: you can redistribute it and/or modify
5     * it under the terms of the GNU General Public License as published by
6     * the Free Software Foundation, either version 3 of the License, or
7     * (at your option) any later version.
8     * 
9     * This program is distributed in the hope that it will be useful,
10    * but WITHOUT ANY WARRANTY; without even the implied warranty of
11    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    * GNU General Public License for more details.
13    * 
14    * You should have received a copy of the GNU General Public License
15    * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16    *
17    */
18   package org.torweg.pulse.accesscontrol.attributes;
19   
20   import java.io.Serializable;
21   
22   import javax.persistence.Column;
23   import javax.persistence.Entity;
24   import javax.persistence.GeneratedValue;
25   import javax.persistence.Id;
26   import javax.xml.bind.annotation.XmlAccessOrder;
27   import javax.xml.bind.annotation.XmlAccessType;
28   import javax.xml.bind.annotation.XmlAccessorOrder;
29   import javax.xml.bind.annotation.XmlAccessorType;
30   import javax.xml.bind.annotation.XmlAttribute;
31   import javax.xml.bind.annotation.XmlRootElement;
32   
33   import org.torweg.pulse.bundle.JDOMable;
34   import org.torweg.pulse.service.request.Command;
35   
36   /**
37    * is an entity representing a check against a given type.
38    * 
39    * @author Thomas Weber, Daniel Dietz
40    * @param <T>
41    *            the type the check is for
42    * @version $Revision: 1378 $
43    */
44   @Entity
45   @XmlRootElement(name = "abstract-typed-check")
46   @XmlAccessorOrder(XmlAccessOrder.UNDEFINED)
47   @XmlAccessorType(XmlAccessType.FIELD)
48   public abstract class AbstractTypedCheck<T> implements JDOMable, Serializable {
49   
50       /**
51        * serialVersionUID.
52        */
53       private static final long serialVersionUID = 4317625797418319493L;
54       /**
55        * primary key.
56        */
57       @Id
58       @GeneratedValue
59       @Column(unique = true, nullable = false, updatable = false)
60       @XmlAttribute(name = "id")
61       private Long id;
62   
63       /**
64        * returns the primary key.
65        * 
66        * @return the primary key
67        */
68       public final Long getId() {
69           return this.id;
70       }
71   
72       /**
73        * checks whether the given value is valid for the check.
74        * 
75        * @param value
76        *            the value to check
77        * @return {@code true}, if and only if the value passed the check.
78        *         Otherwise {@code false}.
79        */
80       public abstract boolean isValid(final AbstractValue<?> value);
81   
82       /**
83        * builds a new instance from the given {@code Command}.
84        * 
85        * @param c
86        *            the command
87        * @return a new instance
88        */
89       public abstract AbstractTypedCheck<T> checkFromCommand(final Command c);
90   
91       /**
92        * sets the values for the check from a given {@code Command} and
93        * returns the check with the newly set check.
94        * 
95        * @param c
96        *            the command
97        * @return the initialised check with the newly set check
98        * @see org.torweg.pulse.accesscontrol.attributes.AbstractTypedCheck#setCheckFromCommand(org.torweg.pulse.service.request.Command)
99        */
100      public abstract AbstractTypedCheck<T> setCheckFromCommand(final Command c);
101  
102  }
103