org.beigesoft.replicator.service.SrvFieldHasIdWriterXml Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of beige-replicator Show documentation
Show all versions of beige-replicator Show documentation
It replicate/persist any entity according XML settings and user's requirements with a file or network (HTTP).
Right now it has implemented XML format of stored/transferred data.
The newest version!
package org.beigesoft.replicator.service;
/*
* Beigesoft ™
*
* Licensed under the Apache License, Version 2.0
*
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*/
import java.util.Map;
import java.io.Writer;
import org.beigesoft.model.IHasId;
import org.beigesoft.exception.ExceptionWithCode;
import org.beigesoft.service.IUtilXml;
/**
* Service to write owned entity as ID.
* According Beige Replicator specification #1.
*
* @author Yury Demidenko
*/
public class SrvFieldHasIdWriterXml implements ISrvFieldWriter {
/**
* XML service.
**/
private IUtilXml utilXml;
/**
*
* Write standard field of entity into a stream
* (writer - file or pass it through network).
*
* @param pField value
* @param pFieldName Field Name
* @param pWriter writer
* @param pAddParam additional params (e.g. exclude fields set)
* @throws Exception - an exception
**/
@Override
public final void write(final Object pField, final String pFieldName,
final Writer pWriter,
final Map pAddParam) throws Exception {
String fieldValue;
if (pField == null) {
fieldValue = "NULL";
} else {
if (!IHasId.class.isAssignableFrom(pField.getClass())) {
throw new ExceptionWithCode(ExceptionWithCode
.CONFIGURATION_MISTAKE, "It's wrong service to write that field: "
+ pField + "/" + pFieldName);
}
fieldValue = ((IHasId) pField).getItsId().toString();
}
pWriter.write(" " + pFieldName + "=\"" + fieldValue
+ "\"\n");
}
//Simple getters and setters:
/**
* Getter for utilXml.
* @return IUtilXml
**/
public final IUtilXml getUtilXml() {
return this.utilXml;
}
/**
* Setter for utilXml.
* @param pUtilXml reference
**/
public final void setUtilXml(final IUtilXml pUtilXml) {
this.utilXml = pUtilXml;
}
}