From: <ja...@us...> - 2006-10-09 14:34:09
|
Revision: 84 http://svn.sourceforge.net/surveyforge/?rev=84&view=rev Author: javism Date: 2006-10-09 07:33:53 -0700 (Mon, 09 Oct 2006) Log Message: ----------- Support for InternationalizedString Issue: 1548431 Modified Paths: -------------- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/GlobalVariable.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ObjectVariable.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/StatisticalObjectType.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/VariableFamily.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Question.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Questionnaire.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Study.java Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/GlobalVariable.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/GlobalVariable.java 2006-10-09 14:30:12 UTC (rev 83) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/GlobalVariable.java 2006-10-09 14:33:53 UTC (rev 84) @@ -22,7 +22,9 @@ package org.surveyforge.core.metadata; import java.io.Serializable; +import java.util.Locale; +import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -31,6 +33,7 @@ import javax.persistence.ManyToOne; import org.hibernate.annotations.GenericGenerator; +import org.surveyforge.util.InternationalizedString; /** @@ -43,35 +46,35 @@ @Entity public class GlobalVariable implements Serializable { - private static final long serialVersionUID = 1661678204467740737L; + private static final long serialVersionUID = 1661678204467740737L; @SuppressWarnings("unused") @Id @Column(length = 50) @GeneratedValue(generator = "system-uuid") @GenericGenerator(name = "system-uuid", strategy = "uuid") - private String id; + private String id; /** Version for optimistic locking. */ @SuppressWarnings("unused") @javax.persistence.Version - private int lockingVersion; + private int lockingVersion; /** A global variable is identified by a unique language independent identifier, which may typically be an abbreviation of its name. */ @Column(unique = true, length = 50) - private String identifier; + private String identifier; /** The official name of the global variable is provided by the owner of the variable. */ - @Column(length = 250) - private String name = ""; + @ManyToOne(cascade = {CascadeType.ALL}) + private InternationalizedString name = new InternationalizedString( ); /** * Short general multilingual description of the global variable, including its purpose, its main subject areas etc. */ - @Column(length = 500) - private String description = ""; + @ManyToOne(cascade = {CascadeType.ALL}) + private InternationalizedString description = new InternationalizedString( ); /** Family to which the global variable belongs. */ @ManyToOne @JoinColumn(name = "variableFamily_id", insertable = false, updatable = false) - private VariableFamily variableFamily; + private VariableFamily variableFamily; protected GlobalVariable( ) @@ -126,55 +129,127 @@ throw new NullPointerException( ); } + + public InternationalizedString getInternationalizedName( ) + { + return this.name; + } + /** - * Returns the name of the GlobalVariable. + * Returns the name of this Global Variable. * - * @return Returns the name. + * @return the name of this Global Variable for the default language. + * @see InternationalizedString#getString() */ public String getName( ) { - return this.name; + return this.name.getString( ); } /** - * Sets a new name to the GlobalVariable. + * Returns the name of this Global Variable for the given language. * - * @param name The name to set. - * @throws NullPointerException If the name is <code>null</code>. + * @param locale the language of the Global Variable to be returned. + * @return the name of this Global Variable for the given language. + * @see InternationalizedString#getString(Locale) */ + public String getName( Locale locale ) + { + return this.name.getString( locale ); + } + + /** + * Sets the name of this Global Variable. The name must be non <code>null</code>, otherwise a {@link NullPointerException} is + * thrown. + * + * @param name the name of this Global Variable. + * @throws NullPointerException if the name is <code>null</code>. + */ public void setName( String name ) { if( name != null ) - this.name = name; + this.name.setString( name ); else throw new NullPointerException( ); } /** - * Returns the description of the GlobalVariable. + * Sets the name of this Global Variable for the given language. The language and name must be non <code>null</code>, otherwise a + * {@link NullPointerException} is thrown. * - * @return Returns the description. + * @param locale the language of the name to be set. + * @param name the name of this Global Variable. + * @throws NullPointerException if the language or name are <code>null</code>. */ - public String getDescription( ) + public void setName( Locale locale, String name ) { + if( name != null ) + this.name.setString( locale, name ); + else + throw new NullPointerException( ); + } + + + public InternationalizedString getInternationalizedDescription( ) + { return this.description; } /** - * Sets a new description of the GlobalVariable. + * Returns the description of this Global Variable. * - * @param description The description to set. - * @throws NullPointerException If the description is <code>null</code>. + * @return the description of this Global Variable for the default language. + * @see InternationalizedString#getString() */ + public String getDescription( ) + { + return this.description.getString( ); + } + + /** + * Returns the description of this Global Variable for the given language. + * + * @param locale the language of the Global Variable to be returned. + * @return the description of this Global Variable for the given language. + * @see InternationalizedString#getString(Locale) + */ + public String getDescription( Locale locale ) + { + return this.description.getString( locale ); + } + + /** + * Sets the description of this Global Variable. The description must be non <code>null</code>, otherwise a + * {@link NullPointerException} is thrown. + * + * @param description the description of this Global Variable. + * @throws NullPointerException if the description is <code>null</code>. + */ public void setDescription( String description ) { if( description != null ) - this.description = description; + this.description.setString( description ); else throw new NullPointerException( ); } /** + * Sets the description of this Global Variable for the given language. The language and description must be non <code>null</code>, + * otherwise a {@link NullPointerException} is thrown. + * + * @param locale the language of the description to be set. + * @param description the description of this Global Variable. + * @throws NullPointerException if the language or description are <code>null</code>. + */ + public void setDescription( Locale locale, String description ) + { + if( description != null ) + this.description.setString( locale, description ); + else + throw new NullPointerException( ); + } + + /** * Returns the {@link VariableFamily} of the GlobalVariable. * * @return Returns the variableFamily. Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ObjectVariable.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ObjectVariable.java 2006-10-09 14:30:12 UTC (rev 83) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ObjectVariable.java 2006-10-09 14:33:53 UTC (rev 84) @@ -22,7 +22,9 @@ package org.surveyforge.core.metadata; import java.io.Serializable; +import java.util.Locale; +import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -31,6 +33,7 @@ import javax.persistence.ManyToOne; import org.hibernate.annotations.GenericGenerator; +import org.surveyforge.util.InternationalizedString; /** * An object variable defines the concept of a variable in connection with a defined statistical object (e.g. the income of a person). @@ -62,11 +65,11 @@ @Column(unique = true, length = 50) private String identifier; /** The name is the official, language dependent name of the global variable, provided by the owner of the variable. */ - @Column(length = 250) - private String name = ""; + @ManyToOne(cascade = {CascadeType.ALL}) + private InternationalizedString name = new InternationalizedString(); /** Short general multilingual description of the object variable, including its purpose, its main subject areas etc. */ - @Column(length = 500) - private String description = ""; + @ManyToOne(cascade = {CascadeType.ALL}) + private InternationalizedString description = new InternationalizedString(); /** * Each object variable belongs to a statistical object or unit. The object variable exists only in the context of the object * variable. @@ -121,55 +124,126 @@ throw new NullPointerException( ); } + public InternationalizedString getInternationalizedName( ) + { + return this.name; + } + /** - * Returns the name of the ObjectVariable. + * Returns the name of this Object Variable. * - * @return Returns the name. + * @return the name of this Object Variable for the default language. + * @see InternationalizedString#getString() */ public String getName( ) { - return this.name; + return this.name.getString( ); } /** - * Sets the name of the ObjectVariable. + * Returns the name of this Object Variable for the given language. * - * @param name The name to set. - * @throws NullPointerException If the name is <code>null</code>. + * @param locale the language of the Object Variable to be returned. + * @return the name of this Object Variable for the given language. + * @see InternationalizedString#getString(Locale) */ + public String getName( Locale locale ) + { + return this.name.getString( locale ); + } + + /** + * Sets the name of this Object Variable. The name must be non <code>null</code>, otherwise a {@link NullPointerException} is + * thrown. + * + * @param name the name of this Object Variable. + * @throws NullPointerException if the name is <code>null</code>. + */ public void setName( String name ) { if( name != null ) - this.name = name; + this.name.setString( name ); else throw new NullPointerException( ); } /** - * Returns the description of the ObjectVariable. + * Sets the name of this Object Variable for the given language. The language and name must be non <code>null</code>, otherwise a + * {@link NullPointerException} is thrown. * - * @return Returns the description. + * @param locale the language of the name to be set. + * @param name the name of this Object Variable. + * @throws NullPointerException if the language or name are <code>null</code>. */ - public String getDescription( ) + public void setName( Locale locale, String name ) { + if( name != null ) + this.name.setString( locale, name ); + else + throw new NullPointerException( ); + } + + + public InternationalizedString getInternationalizedDescription( ) + { return this.description; } /** - * Sets a new description to the ObjectVariable. + * Returns the description of this Object Variable. * - * @param description The description to set. - * @throws NullPointerException If the description is <code>null</code>. + * @return the description of this Object Variable for the default language. + * @see InternationalizedString#getString() */ + public String getDescription( ) + { + return this.description.getString( ); + } + + /** + * Returns the description of this Object Variable for the given language. + * + * @param locale the language of the Object Variable to be returned. + * @return the description of this Object Variable for the given language. + * @see InternationalizedString#getString(Locale) + */ + public String getDescription( Locale locale ) + { + return this.description.getString( locale ); + } + + /** + * Sets the description of this Object Variable. The description must be non <code>null</code>, otherwise a + * {@link NullPointerException} is thrown. + * + * @param description the description of this Object Variable. + * @throws NullPointerException if the description is <code>null</code>. + */ public void setDescription( String description ) { if( description != null ) - this.description = description; + this.description.setString( description ); else throw new NullPointerException( ); } /** + * Sets the description of this Object Variable for the given language. The language and description must be non <code>null</code>, + * otherwise a {@link NullPointerException} is thrown. + * + * @param locale the language of the description to be set. + * @param description the description of this Object Variable. + * @throws NullPointerException if the language or description are <code>null</code>. + */ + public void setDescription( Locale locale, String description ) + { + if( description != null ) + this.description.setString( locale, description ); + else + throw new NullPointerException( ); + } + + /** * Returns the {@link StatisticalObjectType} this ObjectVariable belongs to. * * @return Returns the StatisticalObjectType. Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/StatisticalObjectType.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/StatisticalObjectType.java 2006-10-09 14:30:12 UTC (rev 83) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/StatisticalObjectType.java 2006-10-09 14:33:53 UTC (rev 84) @@ -25,6 +25,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Locale; import javax.persistence.CascadeType; import javax.persistence.Column; @@ -38,6 +39,7 @@ import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.IndexColumn; +import org.surveyforge.util.InternationalizedString; /** * Statistical objects or units may be real world objects (e.g. person, enterprise) or abstract objects like events or states (e.g. @@ -69,11 +71,11 @@ @Column(unique = true, length = 50) private String identifier; /** Unique name statistical unit. */ - @Column(length = 250) - private String name = ""; + @ManyToOne(cascade = {CascadeType.ALL}) + private InternationalizedString name = new InternationalizedString( ); /** Short general multilingual description of the statistical object/unit, including its purpose, its main subject areas etc. */ - @Column(length = 500) - private String description = ""; + @ManyToOne(cascade = {CascadeType.ALL}) + private InternationalizedString description = new InternationalizedString( ); /** A super-type is a generalisation of an object type. */ @ManyToOne @JoinColumn(name = "superType_id", insertable = false, updatable = false) @@ -127,55 +129,126 @@ throw new NullPointerException( ); } + public InternationalizedString getInternationalizedName( ) + { + return this.name; + } + /** - * Returns the name of the StatisticalObjectType. + * Returns the name of this Statistical Object Type. * - * @return Returns the name. + * @return the name of this Statistical Object Type for the default language. + * @see InternationalizedString#getString() */ public String getName( ) { - return this.name; + return this.name.getString( ); } /** - * Sets a new name to the StatisticalObjectType. + * Returns the name of this Statistical Object Type for the given language. * - * @param name The name to set. - * @throws NullPointerException If the name is <code>null</code>. + * @param locale the language of the Statistical Object Type to be returned. + * @return the name of this Statistical Object Type for the given language. + * @see InternationalizedString#getString(Locale) */ + public String getName( Locale locale ) + { + return this.name.getString( locale ); + } + + /** + * Sets the name of this Statistical Object Type. The name must be non <code>null</code>, otherwise a {@link NullPointerException} is + * thrown. + * + * @param name the name of this Statistical Object Type. + * @throws NullPointerException if the name is <code>null</code>. + */ public void setName( String name ) { if( name != null ) - this.name = name; + this.name.setString( name ); else throw new NullPointerException( ); } /** - * Returns the description of the StatisticalObjectType. + * Sets the name of this Statistical Object Type for the given language. The language and name must be non <code>null</code>, otherwise a + * {@link NullPointerException} is thrown. * - * @return Returns the description. + * @param locale the language of the name to be set. + * @param name the name of this Statistical Object Type. + * @throws NullPointerException if the language or name are <code>null</code>. */ - public String getDescription( ) + public void setName( Locale locale, String name ) { + if( name != null ) + this.name.setString( locale, name ); + else + throw new NullPointerException( ); + } + + + public InternationalizedString getInternationalizedDescription( ) + { return this.description; } /** - * Sets a new description for the StatisticalObjectType. + * Returns the description of this Statistical Object Type. * - * @param description The description to set. - * @throws NullPointerException If the name is <code>null</code>. + * @return the description of this Statistical Object Type for the default language. + * @see InternationalizedString#getString() */ + public String getDescription( ) + { + return this.description.getString( ); + } + + /** + * Returns the description of this Statistical Object Type for the given language. + * + * @param locale the language of the Statistical Object Type to be returned. + * @return the description of this Statistical Object Type for the given language. + * @see InternationalizedString#getString(Locale) + */ + public String getDescription( Locale locale ) + { + return this.description.getString( locale ); + } + + /** + * Sets the description of this Statistical Object Type. The description must be non <code>null</code>, otherwise a + * {@link NullPointerException} is thrown. + * + * @param description the description of this Statistical Object Type. + * @throws NullPointerException if the description is <code>null</code>. + */ public void setDescription( String description ) { if( description != null ) - this.description = description; + this.description.setString( description ); else throw new NullPointerException( ); } /** + * Sets the description of this Statistical Object Type for the given language. The language and description must be non <code>null</code>, + * otherwise a {@link NullPointerException} is thrown. + * + * @param locale the language of the description to be set. + * @param description the description of this Statistical Object Type. + * @throws NullPointerException if the language or description are <code>null</code>. + */ + public void setDescription( Locale locale, String description ) + { + if( description != null ) + this.description.setString( locale, description ); + else + throw new NullPointerException( ); + } + + /** * Return the super type of the StatisticalObjectType. * * @return Returns the superType. Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/VariableFamily.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/VariableFamily.java 2006-10-09 14:30:12 UTC (rev 83) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/VariableFamily.java 2006-10-09 14:33:53 UTC (rev 84) @@ -25,6 +25,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Locale; import javax.persistence.CascadeType; import javax.persistence.Column; @@ -33,10 +34,12 @@ import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.IndexColumn; +import org.surveyforge.util.InternationalizedString; /** * A variable family groups a number of global variables that refer to a certain theme. @@ -46,34 +49,34 @@ @Entity public class VariableFamily implements Serializable { - private static final long serialVersionUID = 7344092827765295413L; + private static final long serialVersionUID = 7344092827765295413L; @SuppressWarnings("unused") @Id @Column(length = 50) @GeneratedValue(generator = "system-uuid") @GenericGenerator(name = "system-uuid", strategy = "uuid") - private String id; + private String id; /** Version for optimistic locking. */ @SuppressWarnings("unused") @javax.persistence.Version - private int lockingVersion; + private int lockingVersion; /** A VariableFamily is identified by a unique identifier. */ @Column(unique = true, length = 50) - private String identifier; + private String identifier; /** * Detailed description of the VariableFamily. The description describes the theme of the {@link GlobalVariable}s included in the * family. */ - @Column(length = 500) - private String description = ""; + @ManyToOne(cascade = {CascadeType.ALL}) + private InternationalizedString description = new InternationalizedString( ); /** The family have the list of all {@link GlobalVariable}s included in the theme. */ @OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) @IndexColumn(name = "globalVariablesIndex") @JoinColumn(name = "variableFamily_id", nullable = false) - private List<GlobalVariable> globalVariables = new ArrayList<GlobalVariable>( ); + private List<GlobalVariable> globalVariables = new ArrayList<GlobalVariable>( ); protected VariableFamily( ) {} @@ -113,31 +116,66 @@ throw new NullPointerException( ); } + public InternationalizedString getInternationalizedDescription( ) + { + return this.description; + } + /** - * Returns the description of the family. + * Returns the description of this Variable Family. * - * @return Returns the description. + * @return the description of this Variable Family for the default language. + * @see InternationalizedString#getString() */ public String getDescription( ) { - return this.description; + return this.description.getString( ); } /** - * Sets a new description to the family. + * Returns the description of this Variable Family for the given language. * - * @param description The description to set. - * @throws NullPointerException If the description is <code>null</code>. + * @param locale the language of the Variable Family to be returned. + * @return the description of this Variable Family for the given language. + * @see InternationalizedString#getString(Locale) */ + public String getDescription( Locale locale ) + { + return this.description.getString( locale ); + } + + /** + * Sets the description of this Variable Family. The description must be non <code>null</code>, otherwise a {@link NullPointerException} is + * thrown. + * + * @param description the description of this Variable Family. + * @throws NullPointerException if the description is <code>null</code>. + */ public void setDescription( String description ) { if( description != null ) - this.description = description; + this.description.setString( description ); else throw new NullPointerException( ); } /** + * Sets the description of this Variable Family for the given language. The language and description must be non <code>null</code>, + * otherwise a {@link NullPointerException} is thrown. + * + * @param locale the language of the description to be set. + * @param description the description of this Variable Family. + * @throws NullPointerException if the language or description are <code>null</code>. + */ + public void setDescription( Locale locale, String description ) + { + if( description != null ) + this.description.setString( locale, description ); + else + throw new NullPointerException( ); + } + + /** * Returns the list of {@link GlobalVariable}s of the family. * * @return Returns the list of {@link GlobalVariable}s. Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Question.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Question.java 2006-10-09 14:30:12 UTC (rev 83) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Question.java 2006-10-09 14:33:53 UTC (rev 84) @@ -22,13 +22,17 @@ package org.surveyforge.core.survey; import java.io.Serializable; +import java.util.Locale; +import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; +import javax.persistence.ManyToOne; import org.hibernate.annotations.GenericGenerator; +import org.surveyforge.util.InternationalizedString; /** * The question contain the text for the question, with the sub questions being used to provide further information about the question. @@ -39,34 +43,33 @@ @Entity public class Question implements Serializable { - private static final long serialVersionUID = 0L; + private static final long serialVersionUID = 0L; @SuppressWarnings("unused") @Id @Column(length = 50) @GeneratedValue(generator = "system-uuid") @GenericGenerator(name = "system-uuid", strategy = "uuid") - private String id; + private String id; /** Version for optimistic locking. */ @SuppressWarnings("unused") @javax.persistence.Version - private int lockingVersion; + private int lockingVersion; /** A question has a language independent identifier that identifies the question among all other globally defined questions. */ @Column(unique = true, length = 50) - private String identifier; + private String identifier; /** * The question contains the exact text of the question that has been asked to collect the data. The question text is language * dependent. */ - @Column(length = 250) - private String text = ""; + @ManyToOne(cascade = {CascadeType.ALL}) + private InternationalizedString text = new InternationalizedString( ); /** The description contains explanatory notes to the question and/or an extended definition of the question's meaning. */ - @Column(length = 500) - private String description = ""; + @ManyToOne(cascade = {CascadeType.ALL}) + private InternationalizedString description = new InternationalizedString( ); - protected Question( ) {} @@ -119,55 +122,125 @@ throw new NullPointerException( ); } + public InternationalizedString getInternationalizedText( ) + { + return this.text; + } + /** - * Returns the text of the question. + * Returns the text of this Question. * - * @return Returns the question. + * @return the text of this Question for the default language. + * @see InternationalizedString#getString() */ public String getText( ) { - return this.text; + return this.text.getString( ); } /** - * Sets the text of the Question. + * Returns the text of this Question for the given language. * - * @param text The text to set. - * @throws NullPointerException if the text is <code>null</code> or is empty. + * @param locale the language of the Question to be returned. + * @return the text of this Question for the given language. + * @see InternationalizedString#getString(Locale) */ + public String getText( Locale locale ) + { + return this.text.getString( locale ); + } + + /** + * Sets the text of this Question. The text must be non <code>null</code>, otherwise a {@link NullPointerException} is thrown. + * + * @param text the text of this Question. + * @throws NullPointerException if the text is <code>null</code>. + */ public void setText( String text ) { if( text != null ) - this.text = text; + this.text.setString( text ); else throw new NullPointerException( ); } /** - * Returns the description of the Question. + * Sets the text of this Question for the given language. The language and text must be non <code>null</code>, otherwise a + * {@link NullPointerException} is thrown. * - * @return Returns the description. + * @param locale the language of the text to be set. + * @param text the text of this Question. + * @throws NullPointerException if the language or text are <code>null</code>. */ - public String getDescription( ) + public void setText( Locale locale, String text ) { + if( text != null ) + this.text.setString( locale, text ); + else + throw new NullPointerException( ); + } + + + public InternationalizedString getInternationalizedDescription( ) + { return this.description; } /** - * Sets the description text of the Question. + * Returns the description of this Question. * - * @param description The description to set. - * @throws NullPointerException if the description text is <code>null</code>. + * @return the description of this Question for the default language. + * @see InternationalizedString#getString() */ + public String getDescription( ) + { + return this.description.getString( ); + } + + /** + * Returns the description of this Question for the given language. + * + * @param locale the language of the Question to be returned. + * @return the description of this Question for the given language. + * @see InternationalizedString#getString(Locale) + */ + public String getDescription( Locale locale ) + { + return this.description.getString( locale ); + } + + /** + * Sets the description of this Question. The description must be non <code>null</code>, otherwise a {@link NullPointerException} + * is thrown. + * + * @param description the description of this Question. + * @throws NullPointerException if the description is <code>null</code>. + */ public void setDescription( String description ) { if( description != null ) - this.description = description; + this.description.setString( description ); else throw new NullPointerException( ); } + /** + * Sets the description of this Question for the given language. The language and description must be non <code>null</code>, + * otherwise a {@link NullPointerException} is thrown. + * + * @param locale the language of the description to be set. + * @param description the description of this Question. + * @throws NullPointerException if the language or description are <code>null</code>. + */ + public void setDescription( Locale locale, String description ) + { + if( description != null ) + this.description.setString( locale, description ); + else + throw new NullPointerException( ); + } + @Override public boolean equals( Object object ) { Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Questionnaire.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Questionnaire.java 2006-10-09 14:30:12 UTC (rev 83) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Questionnaire.java 2006-10-09 14:33:53 UTC (rev 84) @@ -27,9 +27,9 @@ import java.util.Collections; import java.util.Comparator; import java.util.List; +import java.util.Locale; import javax.persistence.CascadeType; -import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.JoinColumn; @@ -56,33 +56,33 @@ /** * */ - private static final long serialVersionUID = -357629851050021121L; + private static final long serialVersionUID = -357629851050021121L; /** A questionnaire has a title as provided by the owner or maintenance unit. */ - @Column(length = 250) - private String title = ""; + @ManyToOne(cascade = {CascadeType.ALL}) + private InternationalizedString title = new InternationalizedString( ); /** * Detailed description of the questionnaire. The questionnaire description typically describes the underlying concept of the * questionnaire and basic principles. */ - @Column(length = 500) - private String description = ""; + @ManyToOne(cascade = {CascadeType.ALL}) + private InternationalizedString description = new InternationalizedString( ); /** A questionnaire may have its content organized in pages. */ @OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) @IndexColumn(name = "pageIndex") // @JoinColumn(name = "questionnaire_page_id") @JoinColumn(name = "questionnaire_page_id") - private List<Feed> pageFeeds = new ArrayList<Feed>( ); + private List<Feed> pageFeeds = new ArrayList<Feed>( ); /** A questionnaire may have its content organized in sections. */ @OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) @IndexColumn(name = "sectionIndex") @JoinColumn(name = "questionnaire_section_id") - private List<SectionFeed> sectionFeeds = new ArrayList<SectionFeed>( ); + private List<SectionFeed> sectionFeeds = new ArrayList<SectionFeed>( ); /** A questionnaire is included in a Study. */ @ManyToOne @JoinColumn(name = "study_id", insertable = false, updatable = false) - private Study study; + private Study study; protected Questionnaire( ) @@ -106,56 +106,124 @@ } - // } + public InternationalizedString getInternationalizedTitle( ) + { + return this.title; + } + /** - * Returns the title of the questionnaire. + * Returns the title of this Questionnaire. * - * @return Returns the title. + * @return the title of this Questionnaire for the default language. + * @see InternationalizedString#getString() */ public String getTitle( ) { - return this.title; + return this.title.getString( ); } /** - * Sets the title of the Questionnaire. + * Returns the title of this Questionnaire for the given language. * - * @param title The title to set. - * @throws NullPointerException If the title is <code>null</code>. + * @param locale the language of the Questionnaire to be returned. + * @return the title of this Questionnaire for the given language. + * @see InternationalizedString#getString(Locale) */ + public String getTitle( Locale locale ) + { + return this.title.getString( locale ); + } + + /** + * Sets the title of this Questionnaire. The title must be non <code>null</code>, otherwise a {@link NullPointerException} is thrown. + * + * @param title the title of this Questionnaire. + * @throws NullPointerException if the title is <code>null</code>. + */ public void setTitle( String title ) { if( title != null ) - this.title = title; + this.title.setString( title ); else throw new NullPointerException( ); } /** - * Returns the description of the questionnaire. + * Sets the title of this Questionnaire for the given language. The language and title must be non <code>null</code>, otherwise a + * {@link NullPointerException} is thrown. * - * @return Returns the description. + * @param locale the language of the title to be set. + * @param title the title of this Questionnaire. + * @throws NullPointerException if the language or title are <code>null</code>. */ - public String getDescription( ) + public void setTitle( Locale locale, String title ) { + if( title != null ) + this.title.setString( locale, title ); + else + throw new NullPointerException( ); + } + + + public InternationalizedString getInternationalizedDescription( ) + { return this.description; } /** - * Sets the description of the Questionnaire. + * Returns the description of this Questionnaire. * - * @param description The description to set. - * @throws NullPointerException If the description is <code>null</code> + * @return the description of this Questionnaire for the default language. + * @see InternationalizedString#getString() */ + public String getDescription( ) + { + return this.description.getString( ); + } + + /** + * Returns the description of this Questionnaire for the given language. + * + * @param locale the language of the Questionnaire to be returned. + * @return the description of this Questionnaire for the given language. + * @see InternationalizedString#getString(Locale) + */ + public String getDescription( Locale locale ) + { + return this.description.getString( locale ); + } + + /** + * Sets the description of this Questionnaire. The description must be non <code>null</code>, otherwise a {@link NullPointerException} is + * thrown. + * + * @param description the description of this Questionnaire. + * @throws NullPointerException if the description is <code>null</code>. + */ public void setDescription( String description ) { if( description != null ) - this.description = description; + this.description.setString( description ); else throw new NullPointerException( ); } /** + * Sets the description of this Questionnaire for the given language. The language and description must be non <code>null</code>, + * otherwise a {@link NullPointerException} is thrown. + * + * @param locale the language of the description to be set. + * @param description the description of this Questionnaire. + * @throws NullPointerException if the language or description are <code>null</code>. + */ + public void setDescription( Locale locale, String description ) + { + if( description != null ) + this.description.setString( locale, description ); + else + throw new NullPointerException( ); + } + /** * Adds a new {@link Element} to he Questionnaire. * * @param element The element to add. Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Study.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Study.java 2006-10-09 14:30:12 UTC (rev 83) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Study.java 2006-10-09 14:33:53 UTC (rev 84) @@ -25,6 +25,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Locale; import javax.persistence.CascadeType; import javax.persistence.Column; @@ -33,10 +34,12 @@ import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.IndexColumn; +import org.surveyforge.util.InternationalizedString; /** * Studies are used to document the concepts and production rules for statistical data. A statistical activity might describe @@ -48,40 +51,40 @@ @Entity public class Study implements Serializable { - private static final long serialVersionUID = -4089931270976596457L; + private static final long serialVersionUID = -4089931270976596457L; @SuppressWarnings("unused") @Id @Column(length = 50) @GeneratedValue(generator = "system-uuid") @GenericGenerator(name = "system-uuid", strategy = "uuid") - private String id; + private String id; /** Version for optimistic locking. */ @SuppressWarnings("unused") @javax.persistence.Version - private int lockingVersion; + private int lockingVersion; /** * A statistical activity is identified by a unique identifier, which may typically be an abbreviation of its title or a systematic * number. */ @Column(unique = true, nullable = false, length = 50) - private String identifier; + private String identifier; /** A statistical activity has a title as provided by the owner or maintenance unit. */ - @Column(length = 250) - private String title = ""; + @ManyToOne(cascade = {CascadeType.ALL}) + private InternationalizedString title = new InternationalizedString( ); /** * Detailed description of the statistical activity. The activity description describes the actions performed in the frame of the * activity. */ - @Column(length = 500) - private String description = ""; + @ManyToOne(cascade = {CascadeType.ALL}) + private InternationalizedString description = new InternationalizedString( ); /** When the statistical activity includes a survey one or more questionnaires can be defined in the context of the activity. */ @OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) @IndexColumn(name = "questionnairesIndex") @JoinColumn(name = "study_id", nullable = false) - private List<Questionnaire> questionnaires = new ArrayList<Questionnaire>( ); + private List<Questionnaire> questionnaires = new ArrayList<Questionnaire>( ); protected Study( ) {} @@ -121,55 +124,126 @@ throw new NullPointerException( ); } + + public InternationalizedString getInternationalizedTitle( ) + { + return this.title; + } + /** - * Returns the title of the Study. + * Returns the title of this Study. * - * @return Returns the title. + * @return the title of this Study for the default language. + * @see InternationalizedString#getString() */ public String getTitle( ) { - return this.title; + return this.title.getString( ); } /** - * Sets a new title to the Study. + * Returns the title of this Study for the given language. * - * @param title The title to set. - * @throws NullPointerException If the title is <code>null</code>. + * @param locale the language of the Study to be returned. + * @return the title of this Study for the given language. + * @see InternationalizedString#getString(Locale) */ + public String getTitle( Locale locale ) + { + return this.title.getString( locale ); + } + + /** + * Sets the title of this Study. The title must be non <code>null</code>, otherwise a {@link NullPointerException} is thrown. + * + * @param title the title of this Study. + * @throws NullPointerException if the title is <code>null</code>. + */ public void setTitle( String title ) { if( title != null ) - this.title = title; + this.title.setString( title ); else throw new NullPointerException( ); } /** - * Returns the description of the Study. + * Sets the title of this Study for the given language. The language and title must be non <code>null</code>, otherwise a + * {@link NullPointerException} is thrown. * - * @return Returns the description. + * @param locale the language of the title to be set. + * @param title the title of this Study. + * @throws NullPointerException if the language or title are <code>null</code>. */ - public String getDescription( ) + public void setTitle( Locale locale, String title ) { + if( title != null ) + this.title.setString( locale, title ); + else + throw new NullPointerException( ); + } + + + public InternationalizedString getInternationalizedDescription( ) + { return this.description; } /** - * Sets a new description to the Study. + * Returns the description of this Study. * - * @param description The description to set. - * @throws NullPointerException If the description is <code>null</code>. + * @return the description of this Study for the default language. + * @see InternationalizedString#getString() */ + public String getDescription( ) + { + return this.description.getString( ); + } + + /** + * Returns the description of this Study for the given language. + * + * @param locale the language of the Study to be returned. + * @return the description of this Study for the given language. + * @see InternationalizedString#getString(Locale) + */ + public String getDescription( Locale locale ) + { + return this.description.getString( locale ); + } + + /** + * Sets the description of this Study. The description must be non <code>null</code>, otherwise a {@link NullPointerException} is + * thrown. + * + * @param description the description of this Study. + * @throws NullPointerException if the description is <code>null</code>. + */ public void setDescription( String description ) { if( description != null ) - this.description = description; + this.description.setString( description ); else throw new NullPointerException( ); } /** + * Sets the description of this Study for the given language. The language and description must be non <code>null</code>, + * otherwise a {@link NullPointerException} is thrown. + * + * @param locale the language of the description to be set. + * @param description the description of this Study. + * @throws NullPointerException if the language or description are <code>null</code>. + */ + public void setDescription( Locale locale, String description ) + { + if( description != null ) + this.description.setString( locale, description ); + else + throw new NullPointerException( ); + } + + /** * Return the list of {@link Questionnaire}s included in the Study. * * @return Returns the questionnaires. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |