import com.novell.service.file.nw.NetwareVolume;
import com.novell.service.file.nw.NetwareDirectory;
import com.novell.service.file.nw.NetwareFile;
import com.novell.service.file.nw.NetwareVolume;
import com.novell.service.file.nw.NetwareDirectory;
import com.novell.service.file.nw.NetwareFile;
import com.novell.service.file.nw.DirectoryEntryInformation;
import com.novell.service.file.nw.Trustee;
import com.novell.service.file.nw.TrusteeEnumerator;
import com.novell.service.file.nw.EAEnumerator;
import com.novell.service.file.nw.ExtendedAttribute;
import com.novell.service.file.nw.DirectorySpaceInformation;
import com.novell.service.file.nw.VolumeInformation;
import com.novell.service.file.nw.VolumeRestrictionEnumerator;
import com.novell.service.file.nw.VolumeRestriction;
import com.novell.service.file.nw.VolumeUtilization;
import com.novell.java.io.NFile;
import com.novell.java.io.RandomAccess;
import com.novell.service.jncp.NSIException;
import java.io.OutputStream;
import java.io.InputStream;
import java.io.IOException;
public class TextualStatic implements StaticAttributeValueInterface
{
private boolean verbose;
private Textual text;
private static String[] contents =
{
"line one (offset 0)\r\n",
"line two (offset 21)\r\n",
"line three (offset 43)\r\n",
"line four (offset 67)\r\n",
"line five (offset 90)\r\n",
"line six (offset 113)\r\n",
"line seven (offset 136)\r\n",
"line eight (offset 161)\r\n",
"line nine (offset 186)\r\n",
"line ten (offset 210)\r\n",
"345678901234567890123456",
"1234567890123456789012345678901234567890123456789012345678901234",
"1234567890123456789012345678901234567890123456789012345678901234",
"1234567890123456789012345678901234567890123456789012345678901234",
"1234567890123456789012345678901234567890123456789012345678901234",
"1234567890123456789012345678901234567890123456789012345678901234",
"1234567890123456789012345678901234567890123456789012345678901234",
"1234567890123456789012345678901234567890123456789012345678901234",
"1234567890123456789012345678901234567890123456789012345678901234",
"1234567890123456789012345678901234567890123456789012345678901234",
"1234567890123456789012345678901234567890123456789012345678901234",
"1234567890123456789012345678901234567890123456789012345678901234",
"1234567890123456789012345678901234567890123456789012345678901234",
"1234567890123456789012345678901234567890123456789012345678901234",
"1234567890123456789012345678901234567890123456789012345678901234",
"1234567890123456789012345678901234567890123456789012345678901234",
"1234567890123456789012345678901234567890123456789012345678901234",
"1234567890123456789012345678901234567890123456789012345678901234",
"1234567890123456789012345678901234567890123456789012345678901234",
"1234567890123456789012345678901234567890123456789012345678901234",
"1234567890123456789012345678901234567890123456789012345678901234",
"1234567890123456789012345678901234567890123456789012345678901234",
"1234567890123456789012345678901234567890123456789012345678901234",
"1234567890123456789012345678901234567890123456789012345678901234",
"1234567890123456789012345678901234567890123456789012345678901234",
"1234567890123456789012345678901234567890123456789012345678901234",
"1234567890123456789012345678901234567890123456789012345678901234",
"1234567890123456789012345678901234567890123456789012345678901234",
"1234567890123456789012345678901234567890123456789012345678901234",
"1234567890123456789012345678901234567890123456789012345678901234",
"1234567890123456789012345678901234567890123456789012345678901234",
"1234567890123456789012345678901234567890123456789012345678901234",
"1234567890123456789012345678901234567890123456789012345678901234"
};
private static int[] offsets = {0, 21, 43, 67, 90, 113, 136, 161, 186, 210};
public TextualStatic(boolean verbose)
{
this.verbose = verbose;
text = new Textual(verbose);
}
public void handleNFile(NFile file)
{
message("lastModified: " + file.lastModified() + "\n");
message("length: " + file.length() + "\n");
}
public void handleNetwareFile(NetwareFile file)
{
try
{
DirectoryEntryInformation dei =
file.getDirectoryEntryInformation();
text.displayDirectoryEntryInformation(dei);
handleEAEnumerator(file);
handleTrusteeEnumerator(file);
}
catch (NSIException nsi)
{
System.out.println("handler failed: " + nsi);
nsi.printStackTrace();
System.exit(-1);
}
}
public void handleNetwareDirectory(NetwareDirectory directory)
{
handleNetwareFile((NetwareFile) directory);
try
{
DirectorySpaceInformation dsi =
directory.getDirectorySpaceInformation();
text.displayDirectorySpaceInformation(dsi);
} catch (NSIException nsi)
{
System.out.println("handler failed: " + nsi);
nsi.printStackTrace();
System.exit(-1);
}
}
public void handleNetwareVolume(
NetwareVolume volume,
String objectName)
{
handleNetwareDirectory((NetwareDirectory) volume);
try
{
handleVolumeInformation(volume);
handleVolumeRestrictionEnumerator(volume);
handleVolumeUtilization(volume, objectName);
}
catch (NSIException nsi)
{
System.out.println("handler failed: " + nsi);
nsi.printStackTrace();
System.exit(-1);
}
}
public void handleDirectoryEntryInformation(NetwareFile file)
{
try
{
DirectoryEntryInformation value =
file.getDirectoryEntryInformation();
text.displayDirectoryEntryInformation(value);
}
catch (NSIException nsi)
{
System.out.println("handler failed: " + nsi);
nsi.printStackTrace();
System.exit(-1);
}
}
public void handleTrusteeEnumerator(NetwareFile file)
{
try
{
TrusteeEnumerator value = file.getTrusteeEnumerator();
int count = 0;
while (value.hasMore())
{
text.displayTrustee(value.next());
++count;
}
message(
"\t\t" + count + " " + value.ATTRIBUTE_ID + "'s present\n");
}
catch (NSIException nsi)
{
System.out.println("handler failed: " + nsi);
nsi.printStackTrace();
System.exit(-1);
}
}
public void handleEAEnumerator(NetwareFile file)
{
try
{
EAEnumerator value = file.getEAEnumerator();
int count = 0;
while (value.hasMore())
{
text.displayExtendedAttribute(value.next());
++count;
}
message(
"\t\t" + count + " " + value.ATTRIBUTE_ID + "'s present\n");
}
catch (NSIException nsi)
{
System.out.println("handler failed: " + nsi);
nsi.printStackTrace();
System.exit(-1);
}
}
public void handleDirectorySpaceInformation(
NetwareDirectory directory)
{
try
{
DirectorySpaceInformation value =
directory.getDirectorySpaceInformation();
text.displayDirectorySpaceInformation(value);
}
catch (NSIException nsi)
{
System.out.println("handler failed: " + nsi);
nsi.printStackTrace();
System.exit(-1);
}
}
public void handleVolumeInformation(NetwareVolume volume)
{
try
{
VolumeInformation value = volume.getVolumeInformation();
text.displayVolumeInformation(value);
}
catch (NSIException nsi)
{
System.out.println("handler failed: " + nsi);
nsi.printStackTrace();
System.exit(-1);
}
}
public void handleVolumeRestrictionEnumerator(NetwareVolume volume)
{
try
{
VolumeRestrictionEnumerator value =
volume.getVolumeRestrictionEnumerator();
int count = 0;
while (value.hasMore())
{
text.displayVolumeRestriction(value.next());
++count;
}
message(
"\t\t" + count + " " + value.ATTRIBUTE_ID + "'s present\n");
}
catch (NSIException nsi)
{
System.out.println("handler failed: " + nsi);
nsi.printStackTrace();
System.exit(-1);
}
}
public void handleVolumeUtilization(
NetwareVolume volume,
String objectName)
{
try
{
VolumeUtilization value = volume.getVolumeUtilization();
value.setName(objectName);
text.displayVolumeUtilization(value);
}
catch (NSIException nsi)
{
System.out.println("handler failed: " + nsi);
nsi.printStackTrace();
System.exit(-1);
}
}
public void message(String value)
{
if (verbose)
{
System.out.print(value);
}
}
public void writeStream(OutputStream os)
throws IOException
{
for (int i=0; i < contents.length; i++)
{
byte[] data = contents[i].getBytes();
os.write(data);
}
}
public void readStream(InputStream is)
throws IOException, RuntimeException
{
for (int i=0; i < contents.length; i++)
{
byte[] expected = contents[i].getBytes();
byte[] received = new byte[expected.length];
int count = is.read(received);
if (count != received.length)
{
throw new RuntimeException(
"readStream, read wrong number of characters: exp:" +
expected.length + " rec: " + count + " value: " +
new String(received));
}
for (int j=0; j < expected.length; j++)
{
if (received[j] != expected[j])
{
throw new RuntimeException(
"readStream, unexpected character read - exp: " +
expected[j] + " rec: " + received[j] + " at: " + j);
}
}
}
byte[] received = new byte[80];
int count = is.read(received);
if (count != -1)
{
throw new RuntimeException(
"readStream, stream had data beyond pattern: " +
new String(received));
}
}
public void readRandom(RandomAccess ra)
throws IOException, RuntimeException
{
for (int i=9; i >= 0; i--)
{
byte[] expected = contents[i].getBytes();
byte[] received = new byte[expected.length];
ra.setPosition(offsets[i]);
int count = ra.read(received);
if (count != received.length)
{
throw new RuntimeException(
"readRandom, read wrong number of characters: exp:" +
expected.length + " rec: " + count + " value: " +
new String(received));
}
for (int j=0; j < expected.length; j++)
{
if (received[j] != expected[j]){
throw new RuntimeException(
"readRandom, unexpected character read - exp: " +
expected[j] + " rec: " + received[j] + " at: " + j);
}
}
}
}
}