import org.w3c.dom.TypeInfo; //导入方法依赖的package包/类
/**
* Determine which Release
could be used to represent the indicated
* Document
at a specific target version. If the target version has
* multiple views then the message type is used to make the selection.
*
* @param documentThe source document being converted.
* @paramsourceThe Release
object for the source document.
* @param targetVersionNumberThe target version number.
* @returnThe Release
instance for the target schema.
* @sinceTFP 1.7
*/
public static Release compatibleRelease (Document document, Release source, String targetVersionNumber)
{
VersionsourceVersion = Version.parse (source.getVersion ());
VersiontargetVersion = Version.parse (targetVersionNumber);
String view = null;
Stringtype= null;
// If the target this not 5.0 or later its a direct conversion
if (targetVersion.getMajor () <= 4)
return (Releases.FPML.getReleaseForVersion (targetVersionNumber));
// Otherwise determine the target view based on version and message type
if (sourceVersion.getMajor () <= 3)
view = "confirmation";
else if (sourceVersion.getMajor () == 4) {
Element root = document.getDocumentElement ();
TypeInfo info = root.getSchemaTypeInfo ();
if ((info == null) || (info.getTypeName () == null)) {
NamedNodeMap list = root.getAttributes ();
for (int index = 0; index < list.getLength (); ++index) {
Attr attr = (Attr) list.item (index);
if ((attr.getNamespaceURI () != null)
&& attr.getNamespaceURI ().equals (Schema.INSTANCE_URL)
&& attr.getLocalName ().equals ("type")) {
type = attr.getValue ();
break;
}
}
}
else
type = info.getTypeName ();
// Look for messages that are in the reporting view
if (type.equals ("CancelTradeCashflows")
|| type.equals ("CreditEventNotification")
|| type.equals ("PositionAcknowledged")
|| type.equals ("PositionAsserted")
|| type.equals ("PositionMatchResults")
|| type.equals ("PositionReport")
|| type.equals ("RequestPortfolio")
|| type.equals ("RequestPositionReport")
|| type.equals ("RequestValuationReport")
|| type.equals ("TradeCashflowsAsserted")
|| type.equals ("TradeCashflowsMatchResult")
|| type.equals ("ValuationReport"))
view = "reporting";
else
view = "confirmation";
}
else
view = extractView (((SchemaRelease) source).getNamespaceUri ());
// Find a release that matches the target version and view
Enumeration cursor = Releases.FPML.releases ();
while (cursor.hasMoreElements ()) {
Release target = cursor.nextElement ();
if (target.getVersion ().equals (targetVersionNumber)) {
if (view.equals (extractView (((SchemaRelease) target).getNamespaceUri ())))
return (target);
}
}
// Otherwise no possible release
return (null);
}