All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.beigesoft.replicator.service.SrvFieldWriterXmlStd Maven / Gradle / Ivy

Go to download

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.Date;
import java.util.Map;
import java.io.Writer;

import org.beigesoft.service.IUtilXml;

/**
 * 

Service to write a standard (toString()) field * of replicable/persistable entity. Only fields of type String * will be XML-escaped (it's for good performance). * According Beige Replicator specification #1.

* * @author Yury Demidenko */ public class SrvFieldWriterXmlStd 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 (Enum.class.isAssignableFrom(pField.getClass())) { fieldValue = String.valueOf(((Enum) pField).ordinal()); } else if (pField.getClass() == Date.class) { fieldValue = String.valueOf(((Date) pField).getTime()); } else { fieldValue = pField.toString(); if (pField instanceof String) { fieldValue = getUtilXml().escapeXml(fieldValue); } } 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; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy