UC Berkeley Group for User Interface Research
Updated November 17, 2000

edu.berkeley.guir.lib.schema
Class Schema

java.lang.Object
  |
  +--edu.berkeley.guir.lib.schema.Schema
All Implemented Interfaces:
Serializable

public class Schema
extends Object
implements Serializable

Represents a valid Schema (fieldnames plus value types) and valid properties in that Schema. Essentially, this allows us to have an extensible hashtable that has some basic form of type-checking.

An example Schema file follows:

 
 
 #
 # This file describes what OSKI's vCalendar schema looks like.
 # That is, it defines what are valid fields, and what are valid values
 # for those fields.
 #
 # Lists values / properties that are valid within a schema.
 #
 # In order, the needed sections are:
 # [NAME]
 # [PROPERTIES]
 # [FIELDS]
 #
 # "X-"    means allow anything starting with "X-"
 # "*"     means allow anything
 # "#"     means allow digits
 # "$DATE" means allow dates
 #
 # :*
 # :* ; * ; [LIST | SINGLETON]
 #
 [NAME]
 OskiEvent Schema;1.0
 
 [PROPERTIES]
 VALUE:INLINE, URL, CONTENT-ID, CID, X-, 
 TYPE:WAVE, PCM, VCARD, X-, 
 RSVP:YES, NO, 
 EXPECT:FYI, REQUIRE, REQUEST, IMMEDIATE, 
 CHARSET:*, 
 PCM:*, 
 DELEGATED:X-, 
 X-:*, 
 ROLE:ATTENDEE, ORGANIZER, OWNER, DELEGATE, X-, 
 LANGUAGE:*, 
 STATUS:ACCEPTED, NEEDS ACTION, SENT, TENTATIVE, CONFIRMED, DECLINED, COMPLETED, 
 WAVE:*, 
 ENCODING:7BIT, 8BIT, QUOTED-PRINTABLE, BASE64, X-, 
 VCARD:*, 
 
 [FIELDS]
 X-        :*,        ;ROLE                       ;SINGLETON
 DCREATED  :*,        ;                           ;SINGLETON
 TRANSP    :#,        ;                           ;SINGLETON
 RRULE     :*,        ;                           ;SINGLETON
 UID       :*,        ;                           ;SINGLETON
 DUE       :*,        ;                           ;SINGLETON
 RNUM      :#,        ;                           ;SINGLETON
 AALARM    :*,        ;TYPE, VALUE,               ;SINGLETON
 URL       :*,        ;                           ;SINGLETON
 MALARM    :*,        ;TYPE, VALUE,               ;SINGLETON
 RELATED-TO:*,        ;                           ;SINGLETON
 RDATE     :$DATE,    ;                           ;UNILIST
 DALARM    :*,        ;TYPE, VALUE,               ;SINGLETON
 PALARM    :*,        ;TYPE, VALUE,               ;SINGLETON
 SEQUENCE  :#,        ;                           ;SINGLETON
 ATTENDEE  :*,        ;ROLE, STATUS, VALUE, TYPE, ;MULTILIST
 EXRULE    :*,        ;                           ;SINGLETON
 DTEND     :$DATE,    ;                           ;SINGLETON
 DTSTART   :$DATE,    ;                           ;SINGLETON
 SUMMARY   :*,        ;                           ;SINGLETON
 LOCATION  :*,        ;VALUE, TYPE,               ;SINGLETON
 ATTACH    :*,        ;VALUE,                     ;MULTILIST
 COMPLETED :*,        ;                           ;SINGLETON
 EXDATE    :$DATE,    ;                           ;UNILIST
 DESCRIPTION:*,       ;ENCODING,                  ;SINGLETON
 PRIORITY  :#,        ;                           ;SINGLETON
 LAST-MODIFIED:$DATE, ;                           ;SINGLETON
 CLASS     :PUBLIC, PRIVATE, CONFIDENTIAL, X-, ;  ;SINGLETON
 STATUS:ACCEPTED, NEEDS ACTION, SENT, TENTATIVE, CONFIRMED, DECLINED, COMPLETED, DELEGATED, X-, ; ;SINGLETON
 RESOURCES:CATERING, CHAIRS, EASEL, PROJECTOR, VCR, VEHICLE, X-, ; ;UNILIST
 CATEGORIES:APPOINTMENT, BUSINESS, EDUCATION, HOLIDAY, MEETING, MISCELLANEOUS, PERSONAL, PHONE CALL, SICK DAY, SPECIAL OCCASION, TRAVEL, VACATION, X-, ; ;UNILIST
 

This software is distributed under the Berkeley Software License.

 Revisions:  - GUIRLib-v1.0-1.0.0, Nov 27 1998, JH
               Created class
             - GUIRLib-v1.2-1.0.0, Jun 22 2000, JH
               Touched for GUIRLib release
             - GUIRLib-v1.3-1.0.0, Aug 11 2000, JH
               Touched for GUIRLib release
             - GUIRLib-v1.4-1.0.0, Aug 31 2000, JH
               Touched for GUIRLib release
 

Since:
JDK 1.2
Version:
GUIRLib-v1.4-1.0.0, Aug 31 2000
Author:
Jason Hong ( jasonh@cs.berkeley.edu )
See Also:
Serialized Form

Field Summary
static String D_ALL
          Accept any String.
static String D_DATE
          Accept any valid ISO8601 date.
static String D_DIGIT
          Accept any String of digits.
static String D_EXTENSION
          Accept any String starting with "X-".
static String[] DIRECTIVES_FIELDS
          This lists the valid directives that field values can have.
static String[] DIRECTIVES_PROPERTIES
          This lists the valid directives that property values can have.
static int FLAG_MULTILIST
           
static int FLAG_SINGLETON
           
static int FLAG_UNILIST
           
static String MULTILIST
           
static String SINGLETON
           
static String UNILIST
           
 
Constructor Summary
Schema(InputStream istream)
          Create a Schema using parameters from the given filename.
Schema(String newSchemaName, String newVersion)
          Create a new Schema object with the specified name and version.
 
Method Summary
 void addField(String strFieldName)
          Add a field to be considered valid in this Schema.
 void addFieldProperty(String strFieldName, String strPropertyName)
          Add a property to a field.
 void addFieldValue(String strFieldName, String strValue)
          Add a value to a field.
 void addProperty(String strPropertyName)
          Add a property that is considered valid.
 void addPropertyValue(String strPropertyName, String strValue)
          Add a value to a property that is considered valid.
 String getSchemaName()
          Get the name for this Schema.
 String getSchemaVersion()
          Get the version value for this Schema.
 Enumeration getValidFieldProperties(String strFieldName)
          Get the properties valid for a field.
 Enumeration getValidFields()
          Get the fields valid in this schema.
 Enumeration getValidFieldValues(String strFieldName)
           
 Enumeration getValidProperties()
          Get the properties valid for a field.
 Enumeration getValidPropertyValues(String strProperty)
           
 void importSchema(InputStream istream)
          Import a schema from an inputstream.
 boolean isList(String strFieldName)
          See if the specified field name is a list or not.
 boolean isMultiList(String strFieldName)
          See if the specified field name is a multi list or not.
 boolean isSingleton(String strFieldName)
          See if the specified field name is a singleton or not.
 boolean isUniList(String strFieldName)
          See if the specified field name is a uni list or not.
 boolean isValidField(String strFieldName)
          See if the specified field name is a valid one.
 boolean isValidFieldProperty(String strFieldName, String strPropertyName)
          See if the specified property is valid for the specified field.
 boolean isValidFieldValue(String strFieldName, String strValue)
          See if the specified value is valid for the specified field.
 boolean isValidProperty(String strPropertyName)
          See if the specified property is valid in general.
 boolean isValidPropertyValue(String strPropertyName, String strValue)
          See if the specified property is valid for the specified field.
static void main(String[] argv)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SINGLETON

public static final String SINGLETON

UNILIST

public static final String UNILIST

MULTILIST

public static final String MULTILIST

FLAG_SINGLETON

public static final int FLAG_SINGLETON

FLAG_UNILIST

public static final int FLAG_UNILIST

FLAG_MULTILIST

public static final int FLAG_MULTILIST

D_EXTENSION

public static final String D_EXTENSION
Accept any String starting with "X-".

D_ALL

public static final String D_ALL
Accept any String.

D_DIGIT

public static final String D_DIGIT
Accept any String of digits.

D_DATE

public static final String D_DATE
Accept any valid ISO8601 date. For example, "19960329T083000Z" and "19960401T235959".

DIRECTIVES_FIELDS

public static final String[] DIRECTIVES_FIELDS
This lists the valid directives that field values can have.

DIRECTIVES_PROPERTIES

public static final String[] DIRECTIVES_PROPERTIES
This lists the valid directives that property values can have.
Constructor Detail

Schema

public Schema(String newSchemaName,
              String newVersion)
Create a new Schema object with the specified name and version.
Parameters:
newSchemaName - is the name to set the schema.
newVersion - is the version to set to.

Schema

public Schema(InputStream istream)
       throws IOException
Create a Schema using parameters from the given filename.
Parameters:
strFileName - is the filename to open.
Method Detail

getSchemaName

public String getSchemaName()
Get the name for this Schema.
Returns:
a String containing the name.

getSchemaVersion

public String getSchemaVersion()
Get the version value for this Schema.
Returns:
a String containing the version.

isSingleton

public boolean isSingleton(String strFieldName)
See if the specified field name is a singleton or not.
Returns:
true if the specified field name is a singleton, false otherwise.
Throws:
NoSuchElementException - if the field name does not exist.

isUniList

public boolean isUniList(String strFieldName)
See if the specified field name is a uni list or not.
Returns:
true if the field is a uni list, false otherwise.

isMultiList

public boolean isMultiList(String strFieldName)
See if the specified field name is a multi list or not.
Returns:
true if the field is a multi list, false otherwise.

isList

public boolean isList(String strFieldName)
See if the specified field name is a list or not.
Returns:
true if the specified field name is a list, false otherwise.
Throws:
NoSuchElementException - if the field name does not exist.

isValidField

public boolean isValidField(String strFieldName)
See if the specified field name is a valid one.

isValidFieldValue

public boolean isValidFieldValue(String strFieldName,
                                 String strValue)
See if the specified value is valid for the specified field.

isValidFieldProperty

public boolean isValidFieldProperty(String strFieldName,
                                    String strPropertyName)
See if the specified property is valid for the specified field.

isValidProperty

public boolean isValidProperty(String strPropertyName)
See if the specified property is valid in general.

isValidPropertyValue

public boolean isValidPropertyValue(String strPropertyName,
                                    String strValue)
See if the specified property is valid for the specified field.

getValidFields

public Enumeration getValidFields()
Get the fields valid in this schema.

getValidFieldValues

public Enumeration getValidFieldValues(String strFieldName)

getValidProperties

public Enumeration getValidProperties()
Get the properties valid for a field.

getValidPropertyValues

public Enumeration getValidPropertyValues(String strProperty)

getValidFieldProperties

public Enumeration getValidFieldProperties(String strFieldName)
Get the properties valid for a field.

importSchema

public void importSchema(InputStream istream)
                  throws IOException
Import a schema from an inputstream.

addProperty

public void addProperty(String strPropertyName)
Add a property that is considered valid. Does nothing if the property already exists.
Parameters:
strPropertyName - is the name of the property.

addPropertyValue

public void addPropertyValue(String strPropertyName,
                             String strValue)
Add a value to a property that is considered valid.
Parameters:
strPropertyName - is the name of the property. This is created if it does not already exist.
strValue - is the name of the value that will be considered valid.

addField

public void addField(String strFieldName)
Add a field to be considered valid in this Schema.
Parameters:
strFieldName - is the name of the field.

addFieldProperty

public void addFieldProperty(String strFieldName,
                             String strPropertyName)
Add a property to a field.
Parameters:
strFieldName - is the name of the field.
strPropertyName - is the name of the property to add.

addFieldValue

public void addFieldValue(String strFieldName,
                          String strValue)
Add a value to a field.
Parameters:
strFieldName - is the name of the field.
strValue - is the name of the value to add.

toString

public String toString()
Overrides:
toString in class Object

main

public static void main(String[] argv)
                 throws Exception

Copyright Information