
com.mindoo.domino.jna.internal.LMBCSStringList Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of domino-jna Show documentation
Show all versions of domino-jna Show documentation
Java project to access the HCL Domino C API using Java Native Access (JNA)
package com.mindoo.domino.jna.internal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import com.mindoo.domino.jna.errors.NotesError;
import com.mindoo.domino.jna.errors.NotesErrorUtils;
import com.mindoo.domino.jna.gc.IAllocatedMemory;
import com.mindoo.domino.jna.gc.NotesGC;
import com.mindoo.domino.jna.utils.NotesStringUtils;
import com.mindoo.domino.jna.utils.PlatformUtils;
import com.sun.jna.Memory;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.LongByReference;
import com.sun.jna.ptr.ShortByReference;
/**
* A textlist implementation that stores the values as LMBCS encoded strings
*
* @author Karsten Lehmann
*/
public class LMBCSStringList implements IAllocatedMemory, Iterable {
private List m_values;
private boolean m_prefixDataType;
private int m_handle32;
private long m_handle64;
private int m_listSizeBytes;
private boolean m_noFree;
@SuppressWarnings("unchecked")
public LMBCSStringList(boolean prefixDataType) {
this(Collections.EMPTY_LIST, prefixDataType);
}
public LMBCSStringList(List values, boolean prefixDataType) {
if (values==null) {
values = Collections.emptyList();
}
m_values = new ArrayList();
m_prefixDataType = prefixDataType;
allocate();
NotesGC.__memoryAllocated(this);
addAll(values);
}
public boolean isPrefixDataType() {
return m_prefixDataType;
}
public int getListSizeInBytes() {
return m_listSizeBytes;
}
private void allocate() {
short result;
if (PlatformUtils.is64Bit()) {
LongByReference rethList = new LongByReference();
ShortByReference retListSize = new ShortByReference();
result = NotesNativeAPI64.get().ListAllocate((short) 0,
(short) 0,
m_prefixDataType ? 1 : 0, rethList, null, retListSize);
NotesErrorUtils.checkResult(result);
m_handle64 = rethList.getValue();
Mem64.OSUnlockObject(m_handle64);
m_listSizeBytes = retListSize.getValue() & 0xffff;
}
else {
IntByReference rethList = new IntByReference();
ShortByReference retListSize = new ShortByReference();
result = NotesNativeAPI32.get().ListAllocate((short) 0,
(short) 0,
m_prefixDataType ? 1 : 0, rethList, null, retListSize);
NotesErrorUtils.checkResult(result);
m_handle32 = rethList.getValue();
Mem32.OSUnlockObject(m_handle32);
m_listSizeBytes = retListSize.getValue() & 0xffff;
}
}
/**
* Removes all entries from the list
*/
public void clear() {
if (m_values.isEmpty()) {
return;
}
checkHandle();
ShortByReference retListSize = new ShortByReference();
short result;
if (PlatformUtils.is64Bit()) {
result = NotesNativeAPI64.get().ListRemoveAllEntries(m_handle64, m_prefixDataType ? 1 : 0, retListSize);
}
else {
result = NotesNativeAPI32.get().ListRemoveAllEntries(m_handle32, m_prefixDataType ? 1 : 0, retListSize);
}
NotesErrorUtils.checkResult(result);
m_listSizeBytes = (int) (retListSize.getValue() & 0xffff);
m_values.clear();
}
/**
* Adds a value to the list
*
* @param value value to add
*/
public void add(String value) {
addAll(Arrays.asList(value));
}
/**
* Adds values to the list
*
* @param newValues values to add
*/
public void addAll(List newValues) {
if (newValues.isEmpty()) {
return;
}
checkHandle();
if ((m_values.size() + newValues.size())> 65535) {
throw new IllegalArgumentException("String list size must fit in a WORD ("+m_values.size()+">65535)");
}
short result;
if (PlatformUtils.is64Bit()) {
ShortByReference retListSize = new ShortByReference();
retListSize.setValue((short) (m_listSizeBytes & 0xffff));
for (int i=0; i iterator() {
return m_values.iterator();
}
public int getSize() {
return m_values.size();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy