
bw-calendar-facade.4.1.4.source-code.BwEventProxy.rsrc Maven / Gradle / Ivy
Show all versions of bw-calendar-facade Show documentation
/* **********************************************************************
Licensed to Jasig under one or more contributor license
agreements. See the NOTICE file distributed with this work
for additional information regarding copyright ownership.
Jasig licenses this file to you under the Apache License,
Version 2.0 (the "License"); you may not use this file
except in compliance with the License. You may obtain a
copy of the License at:
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
package org.bedework.calfacade;
import org.bedework.calfacade.base.ChangeFlag;
import org.bedework.calfacade.base.OverrideList;
import org.bedework.calfacade.base.OverrideSet;
import org.bedework.calfacade.util.CalFacadeUtil;
//import org.bedework.util.misc.Util;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
/** DO NOT EDIT THE GENERATED JAVA.
*
*
The proxy java source is generated based on annotations in the event file.
* To change the proxy, either make changes to the annotations processing or
* change the annotations in the event class.
*
*
An event proxy in Bedework.If an event is an alias or reference to another
* event, this class holds links to both. The referring event will hold user
* changes, which override the values in the target.
*
*
For any collection we need to copy the entire collection into the
* referring event if a change is made. We need a flag to indicate such changes.
*
*
We cannot just look at the values in the two objects becuase we have to
* call the getXXX method to allow the persistance engine to retrieve the
* collection.
*
*
We could also remove the current mode, that of creating an empty collection
* in the get methods when none exists.
*
*
XXX Incomplete. Some fields we can handle easily (String mostly).
* Problems still arise with fields like locations and recurrence stuff.
*
* @author Mike Douglass
* @version 1.0
*/
public class BwEventProxy extends BwEvent implements ChangeFlag {
/** The referring event
*/
private BwEventAnnotation ref;
private boolean changeFlag;
/** Constructor
*
* @param ref
*/
public BwEventProxy(BwEventAnnotation ref) {
this.ref = ref;
}
/* ====================================================================
* Bean methods
* ==================================================================== */
/** Get referenced event
*
* @return BwEventAnnotation
*/
public BwEventAnnotation getRef() {
return ref;
}
/** Set the event change flag.
*
* @param val boolean true if event changed.
*/
public void setChangeFlag(boolean val) {
changeFlag = val;
}
/** See if the event has changed.
*
* @return boolean true if event changed.
*/
public boolean getChangeFlag() {
if (changeFlag) {
return true;
}
if (!CalFacadeUtil.eqObjval(ref.getDtstart(), getTarget().getDtstart())) {
changeFlag = true;
return true;
}
if (!CalFacadeUtil.eqObjval(ref.getDtend(), getTarget().getDtend())) {
changeFlag = true;
return true;
}
return false;
}
/** Get the target from the ref
*
* @return BwEvent target of reference
*/
public BwEvent getTarget() {
return ref.getTarget();
}
/* ====================================================================
* BwDbentity methods
* ==================================================================== */
/* (non-Javadoc)
* @see org.bedework.calfacade.BwEvent#setId(int)
*/
public void setId(int val) {
throw new RuntimeException("Immutable");
}
/* (non-Javadoc)
* @see org.bedework.calfacade.BwEvent#getId()
*/
public int getId() {
return ref.getId();
}
/* (non-Javadoc)
* @see org.bedework.calfacade.BwEvent#setSeq(int)
*/
public void setSeq(int val) {
throw new RuntimeException("Immutable");
}
/* (non-Javadoc)
* @see org.bedework.calfacade.BwEvent#getSeq()
*/
public int getSeq() {
return ref.getSeq();
}
/* ====================================================================
* BwOwnedDbentity methods
* ==================================================================== */
/* (non-Javadoc)
* @see org.bedework.calfacade.base.BwOwnedDbentity#setOwnerHref(java.lang.String)
*/
public void setOwnerHref(String val) {
if (!CalFacadeUtil.eqObjval(getTarget().getOwnerHref(), val)) {
ref.setOwnerHref(val);
setChangeFlag(true);
}
}
/* (non-Javadoc)
* @see org.bedework.calfacade.base.BwOwnedDbentity#getOwnerHref()
*/
public String getOwnerHref() {
return ref.getOwnerHref();
}
/* (non-Javadoc)
* @see org.bedework.calfacade.base.BwOwnedDbentity#setPublick(Boolean)
*/
public void setPublick(Boolean val) {
/*
Boolean old = ref.getPublick();
ref.setPublick(val);
if (Util.cmpObjval(old, val) != 0) {
setChangeFlag(true);
}
*/
ref.setPublick(val);
setChangeFlag(true);
}
/* (non-Javadoc)
* @see org.bedework.calfacade.base.BwOwnedDbentity#getPublick()
*/
public Boolean getPublick() {
Boolean val = ref.getPublick();
if (val != null) {
return val;
}
return getTarget().getPublick();
//return ref.getPublick();
}
/* (non-Javadoc)
* @see org.bedework.calfacade.BwEvent#setCreatorHref(java.lang.String)
*/
public void setCreatorHref(String val) {
if (!CalFacadeUtil.eqObjval(getTarget().getCreatorHref(), val)) {
ref.setCreatorHref(val);
setChangeFlag(true);
}
}
/* (non-Javadoc)
* @see org.bedework.calfacade.BwEvent#getCreatorHref()
*/
public String getCreatorHref() {
return getTarget().getCreatorHref();
}
/** Set the access
*
* @param val String access
*/
public void setAccess(String val) {
if (!CalFacadeUtil.eqObjval(getTarget().getAccess(), val)) {
ref.setAccess(val);
setChangeFlag(true);
}
}
/** Get the access
*
* @return String access
*/
public String getAccess() {
if (!ref.getOverride()) {
// Always comes from the annotation.
return ref.getAccess();
}
String val = ref.getAccess();
if (val != null) {
return val;
}
return getTarget().getAccess();
}
/** Set the object's collection path
*
* @param val String path
*/
public void setColPath(String val) {
ref.setColPath(val);
}
/** Get the object's collection path
*
* @return String path
*/
public String getColPath() {
String val = ref.getColPath();
if (val != null) {
return val;
}
return getTarget().getColPath();
}
/* ====================================================================
* Start, end and duration methods
* Currently these are always set in the annotation
* ==================================================================== */
/* (non-Javadoc)
* @see org.bedework.calfacade.BwEvent#setDtstart(org.bedework.calfacade.BwDateTime)
*/
public void setDtstart(BwDateTime val) {
if (!CalFacadeUtil.eqObjval(getRef().getDtstart(), val)) {
ref.setDtstart(val);
setChangeFlag(true);
}
}
/* (non-Javadoc)
* @see org.bedework.calfacade.BwEvent#setDtend(org.bedework.calfacade.BwDateTime)
*/
public void setDtend(BwDateTime val) {
if (!CalFacadeUtil.eqObjval(getRef().getDtend(), val)) {
ref.setDtend(val);
setChangeFlag(true);
}
}
/* (non-Javadoc)
* @see org.bedework.calfacade.BwEvent#setEndType(char)
*/
public void setEndType(char val) {
ref.setEndType(val);
setChangeFlag(true);
}
/* (non-Javadoc)
* @see org.bedework.calfacade.BwEvent#setDuration(java.lang.String)
*/
public void setDuration(String val) {
if (!CalFacadeUtil.eqObjval(getRef().getDuration(), val)) {
ref.setDuration(val);
setChangeFlag(true);
}
}
/* (non-Javadoc)
* @see org.bedework.calfacade.BwEvent#setNoStart(java.lang.Boolean)
*/
public void setNoStart(Boolean val) {
if (!CalFacadeUtil.eqObjval(getRef().getNoStart(), val)) {
ref.setNoStart(val);
setChangeFlag(true);
}
}
/* ====================================================================
* Temp methods until schema change
* ==================================================================== */
@Override
public void setOrganizerSchedulingObject(final Boolean val) {
final List props =
getXproperties(BwXproperty.bedeworkOrganizerSchedulingObject);
BwXproperty xp = null;
if ((props != null) && (props.size() > 0)) {
xp = props.get(0);
}
if (xp != null) {
if (val == null) {
// Delete property
removeXproperty(xp);
} else {
xp.setValue(String.valueOf(val));
}
} else if (val != null) {
addXproperty(new BwXproperty(BwXproperty.bedeworkOrganizerSchedulingObject,
null,
String.valueOf(val)));
}
}
@Override
public Boolean getOrganizerSchedulingObject() {
String val = ref.getXproperty(BwXproperty.bedeworkOrganizerSchedulingObject);
if (val != null) {
return Boolean.valueOf(val);
}
return getTarget().getOrganizerSchedulingObject();
}
@Override
public void setAttendeeSchedulingObject(final Boolean val) {
final List props =
getXproperties(BwXproperty.bedeworkAttendeeSchedulingObject);
BwXproperty xp = null;
if ((props != null) && (props.size() > 0)) {
xp = props.get(0);
}
if (xp != null) {
if (val == null) {
// Delete property
removeXproperty(xp);
} else {
xp.setValue(String.valueOf(val));
}
} else {
addXproperty(new BwXproperty(BwXproperty.bedeworkAttendeeSchedulingObject,
null,
String.valueOf(val)));
}
}
@Override
public Boolean getAttendeeSchedulingObject() {
String val = ref.getXproperty(BwXproperty.bedeworkAttendeeSchedulingObject);
if (val != null) {
return Boolean.valueOf(val);
}
return getTarget().getAttendeeSchedulingObject();
}
/* ====================================================================
* Bean methods
* ==================================================================== */
++++++++++++++++++++++++++++++++++++++++++++++++++ Code inserted here
/* ====================================================================
* Recurrence Helper methods
* ==================================================================== */
/* (non-Javadoc)
* @see org.bedework.calfacade.BwEvent#hasRrules()
*/
public boolean hasRrules() {
return ref.hasRrules() || getTarget().hasRrules();
}
/* (non-Javadoc)
* @see org.bedework.calfacade.BwEvent#hasExrules()
*/
public boolean hasExrules() {
return ref.hasExrules() || getTarget().hasExrules();
}
/* ====================================================================
* Convenience methods
* ==================================================================== */
/** Set the last mod for this event.
*/
public void updateLastmod() {
ref.updateLastmod();
}
/** Set the dtstamp for this event.
*/
public void updateDtstamp() {
ref.updateDtstamp();
}
/* ====================================================================
* Factory methods
* ==================================================================== */
/** Creates an annotation object for the given event then returns a proxy
* object to handle it.
*
* @param ev BwEvent object to annotate
* @param ownerHref
* @param forInstance true if this is an overrride or a recurrence instance
* @return BwEventProxy object
*/
public static BwEventProxy makeAnnotation(BwEvent ev,
String ownerHref,
boolean forInstance) {
BwEventAnnotation ann = new BwEventAnnotation();
initAnnotation(ann, ev, ownerHref, forInstance);
return new BwEventProxy(ann);
}
/** Initialise an annotation object from the given event.
*
* @param ann The annotation object
* @param ev BwEvent object to annotate
* @param ownerHref if null event owner is used
* @param forInstance true if this is an overrride or a recurrence instance
*/
public static void initAnnotation(BwEventAnnotation ann,
BwEvent ev,
String ownerHref,
boolean forInstance) {
ann.setTarget(ev);
/* XXX This should be a parameter */
ann.setMaster(ev);
BwDateTime start = ev.getDtstart();
BwDateTime end = ev.getDtend();
ann.setDtstart(start);
ann.setDtend(end);
//ann.setDuration(BwDateTime.makeDuration(start, end).toString());
ann.setDuration(ev.getDuration());
ann.setEndType(ev.getEndType());
ann.setCreatorHref(ev.getCreatorHref());
ann.setUid(ev.getUid());
ann.setName(ev.getName());
ann.setOverride(forInstance);
if (forInstance) {
// Same calendar as master
ann.setColPath(ev.getColPath());
}
if (ownerHref != null) {
ann.setOwnerHref(ownerHref);
} else {
ann.setOwnerHref(ev.getOwnerHref());
}
}
/* ====================================================================
* Recurrence update and query methods
* ==================================================================== */
public BwDuration makeDurationBean() {
String duration = ref.getDuration();
if (duration == null) {
duration = getTarget().getDuration();
}
return BwDuration.makeDuration(duration);
}
/* ====================================================================
* Object methods
* ==================================================================== */
public String toString() {
StringBuilder sb = new StringBuilder("BwEventProxy{");
sb.append(ref.toString());
sb.append("}");
return sb.toString();
}
/** When cloning a proxy we generally need to point the cloned annotation at
* a new target and master.
*
* @param master
* @param target
* @return cloned proxy.
*/
public BwEventProxy clone(BwEvent master, BwEvent target) {
BwEventAnnotation ann = (BwEventAnnotation)ref.clone();
ann.setMaster(master);
ann.setTarget(target);
return new BwEventProxy(ann);
}
public Object clone() {
return new BwEventProxy((BwEventAnnotation)ref.clone());
}
/* ====================================================================
* private methods
* ==================================================================== */
private static int setNoChange = 0;
private static int setRefNull = 1; // call ref.setMMM(null)
private static int setRefVal = 2; // call ref.setMMM(val)
private static int setChanged = 3; // All changes done
private int doSet(ProxiedFieldIndex pfi,
boolean immutable,
Object masterVal,
Object refVal,
Object newVal) {
int res = setNoChange;
if (CalFacadeUtil.eqObjval(masterVal, newVal)) {
// ref = target - turn off any override
if (ref.getEmptyFlag(pfi)) {
ref .setEmptyFlag(pfi, false);
res = setChanged;
}
if (refVal != null) {
res = setRefNull;
}
if (res != setNoChange) {
setChangeFlag(true);
}
return res;
}
/* The new value is different from the master value - we are overriding */
if (immutable) {
// We let if get this far as cloning can result in a set call that does
// nothing
throw new RuntimeException("Immutable");
}
if (newVal == null) {
// Setting override to null
if (!ref.getEmptyFlag(pfi)) {
ref .setEmptyFlag(pfi, true);
res = setRefNull;
setChangeFlag(true);
}
return res;
}
// Setting an override value
if (ref.getEmptyFlag(pfi)) {
ref.setEmptyFlag(pfi, false);
setChangeFlag(true);
}
if (CalFacadeUtil.eqObjval(refVal, newVal)) {
return setNoChange; // Nothing further to do
}
setChangeFlag(true);
return setRefVal;
}
}