// Since "tileCodec" is the only category that we care about or honor
// currently in the remote communication.
NegotiableCapability codecCap = getNegotiatedValue("tileCodec");
TileDecoderFactory tdf = null;
TileCodecParameterList tcpl = null;
if (codecCap != null) {
String category = codecCap.getCategory();
String capabilityName = codecCap.getCapabilityName();
List generators = codecCap.getGenerators();
Class factory;
for (Iterator i=generators.iterator(); i.hasNext(); ) {
factory = (Class)i.next();
if (tdf == null &&
TileDecoderFactory.class.isAssignableFrom(factory)) {
try {
tdf = (TileDecoderFactory)factory.newInstance();
} catch (InstantiationException ie) {
throw new RemoteImagingException(ImageUtil.getStackTraceString(ie));
} catch (IllegalAccessException iae) {
throw new RemoteImagingException(ImageUtil.getStackTraceString(iae));
}
}
}
if (tdf == null) {
throw new RemoteImagingException(
JaiI18N.getString("RMIServerProxy0"));
}
TileCodecDescriptor tcd =
(TileCodecDescriptor)registry.getDescriptor("tileDecoder",
capabilityName);
if (tcd.includesSampleModelInfo() == false ||
tcd.includesLocationInfo() == false) {
throw new RemoteImagingException(
JaiI18N.getString("RMIServerProxy1"));
}
ParameterListDescriptor pld =
tcd.getParameterListDescriptor("tileDecoder");
tcpl = new TileCodecParameterList(capabilityName,
new String[] {"tileDecoder"},
pld);
// Set parameters on TileCodecParameterList only if there are any
// parameters defined.
if (pld != null) {
String paramNames[] = pld.getParamNames();
String currParam;
Object currValue;
if (paramNames != null) {
for (int i=0; i<paramNames.length; i++) {
currParam = paramNames[i];
try {
currValue = codecCap.getNegotiatedValue(currParam);
} catch (IllegalArgumentException iae) {
// If this parameter is not defined on the
// NegotiableCapability, then move onto the next
continue;
}
tcpl.setParameter(currParam, currValue);
}
}
}
}
try {
// If a compression hint was set, use it
if (codecCap != null) {
byte ctile[] = remoteImage.getCompressedTile(id,
tileX,
tileY);
ByteArrayInputStream stream = new ByteArrayInputStream(ctile);
TileDecoder decoder = tdf.createDecoder(stream, tcpl);
try {
return decoder.decode();
} catch (java.io.IOException ioe) {
throw new RemoteImagingException(ImageUtil.getStackTraceString(ioe));
}