throws InvalidFrameException, InvalidDataTypeException {
//Use reflection to map id to frame body, which makes things much easier
//to keep things up to date,although slight performance hit.
//logger.finest("Creating framebody:start");
AbstractID3v2FrameBody frameBody;
try {
Class<AbstractID3v2FrameBody> c = (Class<AbstractID3v2FrameBody>) Class.forName("org.jaudiotagger.tag.id3.framebody.FrameBody" + identifier);
Class<?>[] constructorParameterTypes = {Class.forName("java.nio.ByteBuffer"), Integer.TYPE};
Object[] constructorParameterValues = {byteBuffer, frameSize};
Constructor<AbstractID3v2FrameBody> construct = c.getConstructor(constructorParameterTypes);
frameBody = (construct.newInstance(constructorParameterValues));
}
//No class defined for this frame type,use FrameUnsupported
catch (ClassNotFoundException cex) {
//logger.info(getLoggingFilename() + ":" + "Identifier not recognised:" + identifier + " using FrameBodyUnsupported");
try {
frameBody = new FrameBodyUnsupported(byteBuffer, frameSize);
}
//Should only throw InvalidFrameException but unfortunately legacy hierachy forces
//read method to declare it can throw InvalidtagException
catch (InvalidFrameException ife) {
throw ife;
} catch (InvalidTagException te) {
throw new InvalidFrameException(te.getMessage());
}
}
//An error has occurred during frame instantiation, if underlying cause is an unchecked exception or error
//propagate it up otherwise mark this frame as invalid
catch (InvocationTargetException ite) {
logger.severe(getLoggingFilename() + ":" + "An error occurred within abstractID3v2FrameBody for identifier:" + identifier + ":" + ite.getCause().getMessage());
if (ite.getCause() instanceof Error) {
throw (Error) ite.getCause();
} else if (ite.getCause() instanceof RuntimeException) {
throw (RuntimeException) ite.getCause();
} else if (ite.getCause() instanceof InvalidFrameException) {
throw (InvalidFrameException) ite.getCause();
} else if (ite.getCause() instanceof InvalidDataTypeException) {
throw (InvalidDataTypeException) ite.getCause();
} else {
throw new InvalidFrameException(ite.getCause().getMessage());
}
}
//No Such Method should not happen
catch (NoSuchMethodException sme) {
logger.log(Level.SEVERE, getLoggingFilename() + ":" + "No such method:" + sme.getMessage(), sme);
throw new RuntimeException(sme.getMessage());
}
//Instantiate Interface/Abstract should not happen
catch (InstantiationException ie) {
logger.log(Level.SEVERE, getLoggingFilename() + ":" + "Instantiation exception:" + ie.getMessage(), ie);
throw new RuntimeException(ie.getMessage());
}
//Private Constructor shouild not happen
catch (IllegalAccessException iae) {
logger.log(Level.SEVERE, getLoggingFilename() + ":" + "Illegal access exception :" + iae.getMessage(), iae);
throw new RuntimeException(iae.getMessage());
}
//logger.finest(getLoggingFilename() + ":" + "Created framebody:end" + frameBody.getIdentifier());
frameBody.setHeader(this);
return frameBody;
}