io.legaldocml.akn.element.Block Maven / Gradle / Ivy
The newest version!
package io.legaldocml.akn.element;
import com.google.common.collect.ImmutableMap;
import io.legaldocml.akn.AknAttributes;
import io.legaldocml.akn.AknObject;
import io.legaldocml.akn.attribute.Name;
import io.legaldocml.akn.group.BlockElements;
import io.legaldocml.io.AttributeGetterSetter;
import io.legaldocml.io.XmlWriter;
import io.legaldocml.io.impl.Buffers;
import java.io.IOException;
import static io.legaldocml.akn.AknElements.BLOCK;
import static io.legaldocml.akn.element.Attributes.attributeGetterSetter4String;
import static io.legaldocml.akn.util.XmlWriterHelper.writeName;
import static io.legaldocml.unsafe.UnsafeHelper.getFieldOffset;
/**
* The element block is a generic element for a block. It can be placed in a container instead of any of the other
* blocks. The attribute name is required and gives a name to the element.
*
*
*
*
*
*
*
*
*
*
*
*
*
* @author Jacques Militello
*/
public final class Block extends InlineType implements Name, BlockElements {
/**
* Memory address.
*/
private static final long ADDRESS_BLOCK = Buffers.address(BLOCK);
private static final ImmutableMap> ATTRIBUTES;
static {
ATTRIBUTES = ImmutableMap.>builder()
.putAll(InlineType.ATTRIBUTES)
.put(AknAttributes.NAME, attributeGetterSetter4String(AknAttributes.NAME, getFieldOffset(Block.class, "name")))
.build();
}
/**
* Name of this block.
*/
private String name;
/**
* {@inheritDoc}
*/
public String getName() {
return this.name;
}
/**
* {@inheritDoc}
*/
public void setName(String name) {
this.name = name;
}
/**
* {@inheritDoc}
*/
@Override
public void write(XmlWriter writer) throws IOException {
writer.writeStart(ADDRESS_BLOCK, 5);
writeName(writer, this);
super.write(writer);
writer.writeEnd(ADDRESS_BLOCK, 5);
}
/**
* {@inheritDoc}
*/
@Override
public String name() {
return BLOCK;
}
/**
* {@inheritDoc}
*/
@Override
public ImmutableMap> attributes() {
return ATTRIBUTES;
}
}