use of org.bedework.calfacade.annotations.Dump in project bw-calendar-engine by Bedework.
the class DumpEntity method dump.
/**
* Dump the entire entity into the given file.
*
* @param f - the file
* @throws CalFacadeException
*/
@NoWrap
public void dump(final File f) throws CalFacadeException {
Dump dCl = getClass().getAnnotation(Dump.class);
if (dCl.format() == DumpFormat.xml) {
Writer wtr = null;
try {
XmlEmit xml = new XmlEmit();
wtr = new FileWriter(f);
xml.startEmit(wtr);
dump(xml, DumpType.def, false);
xml.flush();
return;
} catch (CalFacadeException cfe) {
throw cfe;
} catch (Throwable t) {
throw new CalFacadeException(t);
} finally {
if (wtr != null) {
try {
wtr.close();
} catch (Throwable t) {
throw new CalFacadeException(t);
}
}
}
}
if (dCl.format() == DumpFormat.vCard) {
Writer wtr = null;
try {
VCard vc = new VCard();
dump(vc, DumpType.def);
String vcStr = vc.toString();
wtr = new FileWriter(f);
wtr.append(vcStr);
return;
} catch (CalFacadeException cfe) {
throw cfe;
} catch (Throwable t) {
throw new CalFacadeException(t);
} finally {
if (wtr != null) {
try {
wtr.close();
} catch (Throwable t) {
throw new CalFacadeException(t);
}
}
}
}
throw new CalFacadeException("Unsupported dump format " + dCl.format());
}
use of org.bedework.calfacade.annotations.Dump in project bw-calendar-engine by Bedework.
the class DumpEntity method dump.
/* ====================================================================
* Private Vcard methods
* ==================================================================== */
/**
* Dump this entity as a vcard.
*
* @param vc
* @param dtype
* @throws CalFacadeException
*/
@NoWrap
private void dump(final VCard vc, final DumpType dtype) throws CalFacadeException {
if (!hasDumpValue()) {
return;
}
NoDump ndCl = getClass().getAnnotation(NoDump.class);
Dump dCl = getClass().getAnnotation(Dump.class);
/* If dumpKeyFields is true we are dumping a field which is referred to by
* a key field - for example, a principal is addressed by the principal
* href.
*/
boolean dumpKeyFields = dtype == DumpType.reference;
ArrayList<String> noDumpMethods = null;
ArrayList<String> firstMethods = null;
try {
if (ndCl != null) {
if (ndCl.value().length == 0) {
return;
}
noDumpMethods = new ArrayList<String>();
for (String m : ndCl.value()) {
noDumpMethods.add(m);
}
}
if (!dumpKeyFields && (dCl != null) && (dCl.firstFields().length != 0)) {
firstMethods = new ArrayList<String>();
for (String f : dCl.firstFields()) {
firstMethods.add(methodName(f));
}
}
QName qn = null;
/*
if (dtype != DumpType.compound) {
qn = startElement(xml, getClass(), dCl);
}
Collection<ComparableMethod> ms = findGetters(dCl, dtype);
if (firstMethods != null) {
doFirstMethods:
for (String methodName: firstMethods) {
for (ComparableMethod cm: ms) {
Method m = cm.m;
if (methodName.equals(m.getName())) {
Dump d = m.getAnnotation(Dump.class);
dumpValue(xml, m, d, m.invoke(this, (Object[])null), fromCollection);
continue doFirstMethods;
}
}
error("Listed first field has no corresponding getter: " + methodName);
}
}
for (ComparableMethod cm: ms) {
Method m = cm.m;
if ((noDumpMethods != null) &&
noDumpMethods.contains(fieldName(m.getName()))) {
continue;
}
if ((firstMethods != null) &&
firstMethods.contains(m.getName())) {
continue;
}
Dump d = m.getAnnotation(Dump.class);
dumpValue(xml, m, d, m.invoke(this, (Object[])null), fromCollection);
}
if (qn != null) {
closeElement(xml, qn);
}
*/
// } catch (CalFacadeException cfe) {
// throw cfe;
} catch (Throwable t) {
throw new CalFacadeException(t);
}
}
use of org.bedework.calfacade.annotations.Dump in project bw-calendar-engine by Bedework.
the class DumpEntity method dump.
/* ====================================================================
* Private XML methods
* ==================================================================== */
/**
* Dump this entity as xml.
*
* @param xml
* @param dtype
* @param fromCollection true if the value is a member of a collection
* @throws CalFacadeException
*/
@NoWrap
private void dump(final XmlEmit xml, final DumpType dtype, final boolean fromCollection) throws CalFacadeException {
if (!hasDumpValue()) {
return;
}
NoDump ndCl = getClass().getAnnotation(NoDump.class);
Dump dCl = getClass().getAnnotation(Dump.class);
boolean dumpKeyFields = dtype == DumpType.reference;
ArrayList<String> noDumpMethods = null;
ArrayList<String> firstMethods = null;
try {
if (ndCl != null) {
if (ndCl.value().length == 0) {
return;
}
noDumpMethods = new ArrayList<String>();
for (String m : ndCl.value()) {
noDumpMethods.add(m);
}
}
if (!dumpKeyFields && (dCl != null) && (dCl.firstFields().length != 0)) {
firstMethods = new ArrayList<String>();
for (String f : dCl.firstFields()) {
firstMethods.add(methodName(f));
}
}
QName qn = null;
if (fromCollection || (dtype != DumpType.compound)) {
qn = startElement(xml, getClass(), dCl);
}
Collection<ComparableMethod> ms = findGetters(dCl, dtype);
if (firstMethods != null) {
doFirstMethods: for (String methodName : firstMethods) {
for (ComparableMethod cm : ms) {
Method m = cm.m;
if (methodName.equals(m.getName())) {
Dump d = m.getAnnotation(Dump.class);
dumpValue(xml, m, d, m.invoke(this, (Object[]) null), fromCollection);
continue doFirstMethods;
}
}
error("Listed first field has no corresponding getter: " + methodName);
}
}
for (ComparableMethod cm : ms) {
Method m = cm.m;
if ((noDumpMethods != null) && noDumpMethods.contains(fieldName(m.getName()))) {
continue;
}
if ((firstMethods != null) && firstMethods.contains(m.getName())) {
continue;
}
Dump d = m.getAnnotation(Dump.class);
dumpValue(xml, m, d, m.invoke(this, (Object[]) null), fromCollection);
}
if (qn != null) {
closeElement(xml, qn);
}
} catch (CalFacadeException cfe) {
throw cfe;
} catch (Throwable t) {
throw new CalFacadeException(t);
}
}
Aggregations