FileDocCategorySizeDatePackage
EventImpl.javaAPI DocphoneME MR2 API (J2ME)8892Wed May 02 18:00:28 BST 2007com.sun.kvem.midp.pim

EventImpl

public class EventImpl extends AbstractPIMItem implements javax.microedition.pim.Event
Implementation of a PIM Event.

Fields Summary
private javax.microedition.pim.RepeatRule
repeatRule
Rule for repeating events.
Constructors Summary
public EventImpl(AbstractPIMList list)
Constructs an event implementation handler.

param
list handler for event list


                    
       
        super(list, PIM.EVENT_LIST);
        if (list != null && !(list instanceof EventListImpl)) {
            throw new RuntimeException("Wrong list passed");
        }
    
EventImpl(AbstractPIMList list, javax.microedition.pim.Event base)
Constructs an event list from a base entry.

param
list event list handler
param
base event template

        super(list, base);
        if (!(list instanceof EventListImpl)) {
            throw new RuntimeException("Wrong list passed");
        }
        this.repeatRule = base.getRepeat();
    
Methods Summary
PIMFormatgetEncodingFormat()
Gets the encoding format handler.

return
the PIM format handler

        return new VCalendar10Format();
    
public javax.microedition.pim.RepeatRulegetRepeat()
Gets the repeat rule, if any.

return
repeat rule, which could be null
see
#setRepeat

        if (repeatRule == null) {
            return null;
        }
        // clone the repeat rule
        int[] fields = repeatRule.getFields();
        RepeatRule newRule = new RepeatRule();
        for (int i = 0; i < fields.length; i++) {
            int field = fields[i];
            switch (field) {
                case RepeatRule.COUNT:
                case RepeatRule.DAY_IN_MONTH:
                case RepeatRule.DAY_IN_WEEK:
                case RepeatRule.DAY_IN_YEAR:
                case RepeatRule.FREQUENCY:
                case RepeatRule.INTERVAL:
                case RepeatRule.MONTH_IN_YEAR:
                case RepeatRule.WEEK_IN_MONTH:
                    newRule.setInt(field, repeatRule.getInt(field));
                    break;
                case RepeatRule.END:
                    newRule.setDate(field, repeatRule.getDate(field));
                    break;
            }
        }
        Enumeration dates = repeatRule.getExceptDates();
        while (dates.hasMoreElements()) {
            Date date = (Date) dates.nextElement();
            newRule.addExceptDate(date.getTime());
        }
        return newRule;
    
protected intgetRevisionField()
Gets the revision field identifier.

return
revision field identifier

        return REVISION;
    
protected intgetUIDField()
Gets the UID field identifier.

return
UID field identifier

        return UID;
    
static booleanisValidPIMField(int field)
Ensures the PIM field identifier is supported.

param
field the property identifier
return
true if the field is supported

        switch (field) {
            case Event.ALARM:
            case Event.CLASS:
            case Event.END:
            case Event.LOCATION:
            case Event.NOTE:
            case Event.REVISION:
            case Event.START:
            case Event.SUMMARY:
            case Event.UID:
                return true;
            default:
                return false;
        }
    
protected voidsetDefaultValues()
Sets default values for this item.

        super.setDefaultValues();
        if (repeatRule != null) {
            try {
                repeatRule.getInt(RepeatRule.FREQUENCY);
            } catch (FieldEmptyException e) {
                repeatRule.setInt(RepeatRule.FREQUENCY, RepeatRule.DAILY);
            }
            try {
                repeatRule.getInt(RepeatRule.INTERVAL);
            } catch (FieldEmptyException e) {
                repeatRule.setInt(RepeatRule.INTERVAL, 1);
            }
        }
    
public voidsetRepeat(javax.microedition.pim.RepeatRule value)
Updates the repeat rule.

param
value the new repeat rule
see
#getRepeat

        this.repeatRule = value;
        setModified(true);
    
protected java.lang.StringtoDisplayableString()
Converts the Event record to a printable format.

return
formatted Event record

        StringBuffer sb = new StringBuffer("Event[");
        String data = formatData();
        sb.append(data);
        RepeatRule rule = getRepeat();
        if (rule != null) {
            if (data.length() > 0) {
                sb.append(", ");
            }
            sb.append("Rule=[");
            int[] fields = rule.getFields();
            for (int i = 0; i < fields.length; i++) {
                if (i != 0) {
                    sb.append(",");
                }
                int field = fields[i];
                switch (field) {
                    case RepeatRule.FREQUENCY:
                        sb.append("Frequency=");
                        switch (rule.getInt(field)) {
                            case RepeatRule.DAILY:
                                sb.append("Daily");
                                break;
                            case RepeatRule.WEEKLY:
                                sb.append("Weekly");
                                break;
                            case RepeatRule.MONTHLY:
                                sb.append("Monthly");
                                break;
                            case RepeatRule.YEARLY:
                                sb.append("Yearly");
                                break;
                            default:
                                sb.append("<Unknown: " +
                                    rule.getInt(field) + ">");
                        }
                        break;
                    case RepeatRule.END:
                        sb.append("End=" +
                            PIMHandler.getInstance()
                                .composeDateTime(rule.getDate(field)));
                        break;
                    case RepeatRule.COUNT:
                        sb.append("Count=" + rule.getInt(field));
                        break;
                    case RepeatRule.INTERVAL:
                        sb.append("Interval=" + rule.getInt(field));
                        break;
                    case RepeatRule.DAY_IN_WEEK:
                        sb.append("DayInWeek=0x" + Integer
                            .toHexString(rule.getInt(field)));
                        break;
                    case RepeatRule.DAY_IN_MONTH:
                        sb.append("DayInMonth=" + rule.getInt(field));
                        break;
                    case RepeatRule.DAY_IN_YEAR:
                        sb.append("DayInYear=" + rule.getInt(field));
                        break;
                    case RepeatRule.WEEK_IN_MONTH:
                        sb.append("WeekInMonth=0x" + Integer
                            .toHexString(rule.getInt(field)));
                        break;
                    case RepeatRule.MONTH_IN_YEAR:
                        sb.append("MonthInYear=0x" + Integer
                            .toHexString(rule.getInt(field)));
                        break;
                    default:
                        sb.append("<Unknown: " + field + "="
                            + rule.getInt(field));

                }
            }
            sb.append("]");
        }
        sb.append("]");
        return sb.toString();