Verwendung von Out-Parametern
Im unten stehenden Code wird durch offene Dokumente iteriert, wobei jedes davon validiert wird. Für jede Validierung wird mit Hilfe der Ausgabeparameter der Methode "Validation" eine Meldung generiert.
01 // Iterate through all open documents and set the View mode to 'Text'.
02 for (Document doc:authenticDesktop.getDocuments())
03 if ( doc.getCurrentViewMode() != SPYViewModes.spyViewText)
04 doc.switchViewMode(SPYViewModes.spyViewText);
05
06 // An alternative iteration mode is index-based. COM indices are typically zero-based.
07 Documents documents = authenticDesktop.getDocuments();
08 for (int i = 1; i <= documents.getCount(); i++)
09 {
10 Document doc = documents.getItem(i);
11
12 // Validation is one of the few methods that have output parameters.
13 // The class JVariant is the correct type for parameters in these cases.
14 // To get values back, mark them with the by-reference flag.
15 JVariant validationErrorText = new JVariant.JStringVariant(""); validationErrorText.setByRefFlag();
16 JVariant validationErrorCount = new JVariant.JIntVariant(0); validationErrorCount.setByRefFlag();
17 JVariant validationErrorXMLData = new JVariant.JIDispatchVariant(0); validationErrorXMLData.setByRefFlag();
18 if (!doc.isValid(validationErrorText, validationErrorCount, validationErrorXMLData))
19 System.out.println("Document " + doc.getName() + " is not wellformed - " + validationErrorText.getStringValue());
20 else
21 System.out.println("Document " + doc.getName() + " is wellformed.");
22 }