3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.cdm
.model
.common
;
12 import java
.io
.Serializable
;
14 import javax
.persistence
.Embeddable
;
15 import javax
.persistence
.EmbeddedId
;
16 import javax
.persistence
.Entity
;
18 import org
.hibernate
.validator
.constraints
.Length
;
21 * This class may hold all prefrences data for a CDM database.
22 * E.g. one may store what the default nomenclatural code is,
23 * or which default formatter (cache strategy) to use for a
25 * The structure represents a triple where the first item
26 * (subject) defines for which object the given information is valid.
27 * The second item (predicate) describes the type of information
28 * and the third item (value) represents the actual value.
30 * E.g. for defining a database wide default nomenclatural code
31 * you may define a triple ("database", "eu.etaxonomy.cdm.model.name.NomenclaturalCode", "ICZN").
32 * The set of allowed values and semantics for each combination
33 * is up to implementing classes.
34 * The only restrictions we have is the length of the fields and
35 * the fact that the first two items (subject, predicate) do
36 * create a unique key.
38 * Size of single fields may be enlarged in future versions. "Value" may
45 public class CdmPreferences
implements Serializable
{
46 private static final long serialVersionUID
= 4307599154287181582L;
50 public static class PrefKey
implements Serializable
{
51 private static final long serialVersionUID
= 9019957853773606194L;
54 private String subject
;
57 private String predicate
;
61 public PrefKey(String subject
, String predicate
){
62 if (subject
== null) throw new IllegalArgumentException("Subject must not be null for preference");
63 if (predicate
== null) throw new IllegalArgumentException("Predicate must not be null for preference");
64 if (subject
.length() > 255) throw new IllegalArgumentException("Subject must not be longer then 255 for preference");
65 if (predicate
.length() > 255) throw new IllegalArgumentException("Predicate must not be longer then 255 for preference");
67 this.subject
= subject
;
68 this.predicate
= predicate
;
72 public int hashCode() {
75 result
= prime
* result
+ ((predicate
== null) ?
0 : predicate
.hashCode());
76 result
= prime
* result
+ ((subject
== null) ?
0 : subject
.hashCode());
81 public boolean equals(Object obj
) {
84 } else if (obj
== null){
86 }else if (getClass() != obj
.getClass()){
89 PrefKey other
= (PrefKey
) obj
;
90 return ( predicate
.equals(other
.predicate
) && subject
.equals(other
.subject
));
100 private String value
;
104 * @param subject must not be null and must not be longer then 255 characters.
105 * @param predicate must not be null and must not be longer then 255 characters.
106 * @param value must not be longer then 1023 characters.
108 public CdmPreferences(String subject
, String predicate
, String value
){
109 this.key
= new PrefKey(subject
, predicate
);
110 //TODO are null values allowed? assert predicate != null : "value must not be null for preference";
111 if (value
!= null && value
.length() > 1023) {throw new IllegalArgumentException(
112 String
.format("value must not be longer then 1023 characters for preference. Value = %s", value
));
118 public String
getSubject() {
122 public String
getPredicate() {
123 return key
.predicate
;
126 public String
getValue() {
130 //TODO do we need a setter?