Hi Michael - 

I'm reading into your comments that the extension element class and the customized extension element factory are physically included in the compiled stylesheet - is that correct? It seems a bit odd (to me, anyway) to compile the classes directly into the stylesheet instead of resolving them at runtime... just to aid my understanding, can you explain a bit more about why you decided to take this path?

I modified my compile script to include my ExtensionElementFactory and extension element on the classpath, and now I get a java.io.NotSerializableExtension for net.sf.saxon.style.ExpressionContext.  The stack trace (for whatever it's worth) and output from -debug is included at the bottom of this email.  I went back and made sure that the Java classes I'm using all implement Serializable, but I can't tell for sure if this is something in my code or in Saxon itself.   FWIW, my code uses the ExtensionElement, ExtensionElementFactory, Expression, AttributeCollection, Executable, SimpleExpression, ExpressionElement, XPathContext, Controller, NamePool, and Receiver classes from Saxon, but all of these except for the ones that are used by direct superclasses of SimpleExpression and ExtensionElement are all acquired at runtime from the environment, not serialized as part of the class itself.  I can post the extension element and factory source code off-list if needed.

Thanks for all your help -
Chris


On Mar 26, 2008, at 2:11 AM, Michael Kay wrote:

In the script used to compile the stylesheet and then run the compiled version, your extension element factory isn't on the classpath during the compile phase. This means that the expression element-available('abc:xyz') compiles to "false", and at run-time the code simply takes the "false" path. In fact, no attempt will be made to compile the code corresponding to your extension element. This isn't just an accident of the fact that element-available('abc:xyz') is precomputed; the factory code is actually needed at compile time.
 
Let me try and answer some of your supplementary questions below:

As explained above, the extension element factory (and the classes it instantiates) need to be available at compile time, not just at runtime.
 
The reference here to "serialization" is Java serialization (not XML serialization). The .sxx file generated by Compile is really just a Java serialization of the expression tree produced by the Saxon compiler. For it to work, every object referenced from the expression tree needs to implement the Java pseudo-interface Serializable, and this includes objects used in the compiled code of user-defined extension elements. If there are non-serializable objects on the tree, the failures can be obscure to diagnose.
 


Serializing compiled stylesheet
write byte[]: srnet.sf.saxon.PreparedStylesheet?k?)^?|?ZcompileWithTracingI
errorCountL
executablet"Lnet/sf/saxon/instruct/Executable;LnextStylesheetCachetLjava/util/HashMap;LtargetNamePooltLnet/sf/saxon/om/NamePool;
write byte[]: sr net.sf.saxon.instruct.Executable?
^o?0?I
      hostLanguageIlargestPatternStackFrameZstripsInputTypeAnnotationsZstripsWhitespaceLcharacterMapIndexq~LcollationTablet Lnet/sf/saxon/expr/CollationMap;LcompiledGlobalVariablesq~LdecimalFormatManagert)Lnet/sf/saxon/trans/DecimalFormatManager;LdefaultCollationNametLjava/lang/String;LdefaultOutputPropertiestLjava/util/Properties;LfunctionLibraryt(Lnet/sf/saxon/functions/FunctionLibrary;LglobalVariableMapt#Lnet/sf/saxon/instruct/SlotManager;L
keyManagertLnet/sf/saxon/trans/KeyManager;L
                                           locationMapt#Lnet/sf/saxon/instruct/LocationMap;LnamedTemplateTableq~LoutputDeclarationsq~LqueryLibraryModulesq~LreasonUnableToCompileqLrequiredParamstLjava/util/HashSet;L
stripperRulestLnet/sf/saxon/trans/Mode;               ruleManagert Lnet/sf/saxon/trans/RuleManager;L
write byte[]: psrnet.sf.saxon.expr.CollationMap???$????LconfigtLnet/sf/saxon/Configuration;LdefaultCollationNameqLmapq~
write byte[]: srnet.sf.saxon.Configurationz?
{
 ?q?*ZallNodesUntypedZallowExternalFunctionsZallowMultiThreadingdomLevelZexpandDefaultAttributesI
lineNumberingZpreEvaluateDocFunctionIrecoveryPolicyZretainDTDattributeTypesIschemaValidationModeIstripsWhiteSpaceZtimingZtraceExternalFunctionsZtraceOptimizationsZtracingI     treeModelZuseDisableOutputEscapingZ
xIncludeAwareIidationWarningsZversionWarningZ
xmlVersionLcollationResolvert(Lnet/sf/saxon/sort/CollationURIResolver;LcollectionResolvert$Lnet/sf/saxon/CollectionURIResolver;LdocumentNumberAllocatort)Lnet/sf/saxon/om/DocumentNumberAllocator;LdotNetExtensionBinderq~
LexternalObjectModelstLjava/util/List;LglobalDocumentPooltLnet/sf/saxon/om/DocumentPool;LjavaExtensionBinderq~
LmessageEmitterClassqLmoduleURIResolvert&Lnet/sf/saxon/query/ModuleURIResolver;namePoolq~L      optimizertLnet/sf/saxon/expr/Optimizer;LschemaURIResolvert%Lnet/sf/saxon/typ
write byte[]: e/SchemaURIResolver;LserializerFactoryt&Lnet/sf/saxon/event/SerializerFactory;LsourceParserClassqLstandardModuleURIResolverq~styleParserClassqLsystemURIResolvert"Lnet/sf/saxon/StandardURIResolver;LvendorFunctionLibraryt.Lnet/sf/saxon/functions/VendorFunctionLibrary;
write byte[]: sr.net.sf.saxon.sort.StandardCollationURIResolver
                                                               ?????_?
write byte[]: sr4net.sf.saxon.functions.StandardCollectionURIResolver?;?BiA??
write byte[]: sr'net.sf.saxon.om.DocumentNumberAllocatorC?p??InextDocumentNumber
write byte[]: xsrnet.sf.saxon.om.DocumentPool5nJe7??LdocumentNameMapq~
write byte[]: xsr+net.sf.saxon.functions.JavaExtensionLibrary?J%?Z??Lconfigq~LexplicitMappingsq~
write byte[]: vrnet.sf.saxon.exslt.Math
write byte[]: vrnet.sf.saxon.exslt.Sets
write byte[]: thttp://saxon.sf.net/
write byte[]: vr!net.sf.saxon.functions.Extensions
write byte[]: vrnet.sf.saxon.exslt.Random
write byte[]: vrnet.sf.saxon.exslt.Date
write byte[]: vrnet.sf.saxon.exslt.Common
write byte[]: xt!net.sf.saxon.event.MessageEmitterpsrnet.sf.saxon.om.NamePool
                                                                             Y??wh??S
                                                                                     prefixesUsedurisUsedL
clientDataq~[   hashslotst%[Lnet/sf/saxon/om/NamePool$NameEntry;prefixest[Ljava/lang/String;[prefixesForUrit[[Ljava/lang/String;[urisq~F
write byte[]: pur%[Lnet.sf.saxon.om.NamePool$NameEntry;?X+
                                                          ??
write byte[]: xppppppppppppppppppppppppppppppppppppppppppsr"net.sf.saxon.om.NamePool$NameEntryZ?$-/RSuriCodeL   localNameqL     nextEntryt$Lnet/sf/saxon/om/NamePool$NameEntry;
write byte[]: xpdttxmltxsltsaxontxstxsithtmltdtbooktjavattamcppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppur[[Ljava.lang.String;2M ??2?W
write byte[]: q~?uq~?uq~?uq~?uq~?dq~?t$http://www.w3.org/XML/1998/namespacet$http://www.w3.org/1999/XSL/Transformq~7t http://www.w3.org/2001/XMLSchemat)http://www.w3.org/2001/XMLSchema-instancethttp://www.w3.org/1999/xhtmlt'http://www.daisy.org/z3986/2005/dtbook/thttp://saxon.sf.net/java-typetHjava:/techadapt.accessiblemediacenter.converter.saxon.TAMCElementFactoryppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppsret.sf.saxon.expr.Optimizer????????Lconfigq~
write byte[]: q~!psr$net.sf.saxon.event.SerializerFactoryOy??l?i?
write byte[]: psr,net.sf.saxon.query.StandardModuleURIResolver^2??(??!
write byte[]: psr net.sf.saxon.StandardURIResolver?8~??,?ZrecognizeQueryParametersLconfigq~
write byte[]: q~!sr,net.sf.saxon.functions.VendorFunctionLibrary;<i?y
functionTableq~
write byte[]: sr-net.sf.saxon.functions.StandardFunction$Entry?-?v????  I
                                                                         cardinalityI
                                                                                     maxArgumentsI
net/sf/saxon/value/Value;
write byte[]: ur"[Lnet.sf.saxon.value.SequenceType;gm?????9
write byte[]: xpsrnet.sf.saxon.value.SequenceType??o??K?I
                                                         cardinalityL
                                                                     primaryTypeq~
write byte[]: sr net.sf.saxon.pattern.AnyNodeTest?4??$??
write byte[]: xrnet.sf.saxon.pattern.NodeTest
                                             L?Iz?
write byte[]: srnet.sf.saxon.type.AnyItemTypee?\?YQO?
write byte[]: vr net.sf.saxon.functions.Serialize?????^??LoutputPropertiesq~
write byte[]: xr%net.sf.saxon.functions.SystemFunctions|?q???I  operationLdetailst/Lnet/sf/saxon/functions/StandardFunction$Entry;
write byte[]: xrnet.sf.saxon.expr.FunctionCall5"X??t?argumentt[Lnet/sf/saxon/expr/Expression;Lnamet!Lnet/sf/saxon/om/StructuredQName;
write byte[]: xrnet.sf.saxon.expr.Expression??Oi????I
locationIdIstaticPropertiesL    containertLnet/sf/saxon/expr/Container;[        slotsUsedt[I
write byte[]: xpsr#net.sf.saxon.type.BuiltInAtomicType8<?@zm?{IbaseFingerprintI
                                                                               fingerprintZorderedIprimitiveFingerprint
net.sf.saxon.value.Value;????L?3?
write byte[]: q~*vrnet.sf.saxon.functions.Parsec?Ay??LbaseURIq~
write byte[]: xq~ sr!net.sf.saxon.pattern.NodeKindTest?%Y??<?Ikind
write byte[]: vrnet.sf.saxon.functions.ItemAt0%]0??*?
staticContextt(Lnet/sf/saxon/sxpath/IndependentContext;!H???Ldetailst*Lnet/sf/saxon/instruct/InstructionDetails;L
write byte[]: uq~q~:vr$net.sf.saxon.functions.IsWholeNumberSW???+
write byte[]: srnet.sf.saxon.om.StructuredQName3?[w???IlocalNameStartI
                                                                      prefixStart[contentt[C
write byte[]: sr!net.sf.saxon.instruct.GlobalParam:0?_?^ 
Irite byte[]: xr$net.sf.saxon.instruct.GlobalVariable??m ??
 hostLanguageL
stackFrameMapq~

write byte[]: xr%net.sf.saxon.instruct.GeneralVariable?????G?IevaluationModeB
propertiesIreferenceCountI
slotNumberL
variableQNameq~$redTypet!Lnet/sf/saxon/value/SequenceType;LselecttLnet/sf/saxon/expr/Expression;L
write byte[]: xr!net.sf.saxon.instruct.Instruction?L?/tA
write byte[]: q~sr#net.sf.saxon.instruct.DocumentInstr&???e??textOnlyL
                                                                      constantTextq~
write byte[]: xr+net.sf.saxon.instruct.ParentNodeConstructorGc?<?"|<ZlazyConstructionZnamespaceSensitiveTypeI
validationLbaseURIqLcontentq~iL
schemaTypetLnet/sf/saxon/type/SchemaType;
noNodeIfEmptyIoptions/Users/cvonsee/temp/saxon%20test/ss.xslsrnet.sf.saxon.instruct.ValueOfu?n???ZisNumberingInstructionZ
write byte[]: xr+net.sf.saxon.instruct.SimpleNodeConstructor    w??I???Lselectq~i
write byte[]: srnet.sf.saxon.expr.StringLiteral?b?'\-(
write byte[]: xrnet.sf.saxon.expr.Literal?'h?R?z?LvaluetLnet/sf/saxon/value/Value;
write byte[]: srnet.sf.saxon.value.StringValue>???G??IlengthLvaluetLjava/lang/CharSequence;
write byte[]: xrnet.sf.saxon.value.AtomicValue???F???#L typeLabeltLnet/sf/saxon/type/AtomicType;
write byte[]: xrnet.sf.saxon.value.Value*?????h?
write byte[]: xsr'net.sf.saxon.trans.DecimalFormatManager??D??;?ZusingOriginalDefaultL
defaultDFSt#Lnet/sf/saxon/trans/DecimalSymbols;L
                                                formatTableq~
write byte[]: sr!net.sf.saxon.trans.DecimalSymbols$9???b?
IdecimalSeparatorIdigitIgroupingSeparatorI      minusSignIpatternSeparatorIpercentIpermillI     zeroDigitLNaNqinfinityq~
write byte[]: sr9net.sf.saxon.trans.DecimalFormatManager$DecimalFormatInfo?:??fRI
precedenceLdfsq~?
write byte[]: t({http://saxon.sf.net/}stylesheet-version
write byte[]: psr*net.sf.saxon.functions.FunctionLibraryList?YU)????L
                                                                     libraryListq~
write byte[]: sr,net.sf.saxon.functions.SystemFunctionLibrary???q???I
                                                                     functionSet
write byte[]: sr0net.sf.saxon.functions.ExecutableFunctionLibrary4?
                                                                   ?JG?Lconfigq~L       functionsq~
write byte[]: sr1net.sf.saxon.functions.ConstructorFunctionLibrary%??|JC??Lconfigq~
write byte[]: sr(net.sf.saxon.query.XQueryFunctionLibrary?6B?`??Lconfigq~L      functionsq~
write byte[]: xsr!net.sf.saxon.instruct.SlotManager?s?M?@InumberOfVariablesL
                                                                            variableMaptLjava/util/ArrayList;
write byte[]: xpsr!net.sf.saxon.instruct.LocationMap?!? a`?InumberOfModules[modulesq~F
write byte[]: uq~?
q~qppppppppppppppsrnet.sf.saxon.trans.RuleManager??y-?BK?L
                                                          defaultModeq~Lmodesq~omniModeq~
write byte[]: srnet.sf.saxon.trans.Modef???5??QhasRulesZ        isDefaultZ
isStrippermodeNameq~$LmostRecentRuletLnet/sf/saxon/trans/Rule;ruleDictt[Lnet/sf/saxon/trans/Rule;
write byte[]: uq~c%http://saxon.sf.net/_defaultModesaxonsrnet.sf.saxon.trans.RuleB#????I
precedenceprioritysequenceLactiontLjava/lang/Object;Lnextq~?LpatterntLnet/sf/saxon/pattern/Pattern;
write byte[]: srnet.sf.saxon.instruct.Template?????TZbodyIsTailCallReturnerZhasRequiredParamsIminImportPrecedenceI
precedenceL
           requiredTypeq~hL
                           templateNameq~$
write byte[]: xrnet.sf.saxon.instruct.Procedure????!PI
                                                      hostLanguageI
lineNumberLbodyq~iL
stackFrameMapq~
               systemIdq~
write byte[]: sret.sf.saxon.instruct.Block?E???jchildrenq~#
write byte[]: ur[Lnet.sf.saxon.expr.Expression;?!N?B?
write byte[]: xpsrnet.sf.saxon.instruct.Message
?<???0^Lselectq~iL      terminateq~i
write byte[]: sr.net.sf.saxon.instruct.SimpleContentConstructorI{*????&isAtomicZ
                                                                                isSingletonLselectq~iL  separatorq~i
?BaxisIcomputedCardinalityLcontextItemTypeq~itemTypeq~LtesttLnet/sf/saxon/pattern/NodeTest;
write byte[]: srnet.sf.saxon.pattern.NameTest?hR,[?I
                                                    fingerprintnodeKindL        localNameqnamePoolq~Luriq~
write byte[]: srdtechadapt.accessiblemediacenter.converter.saxon.ImageConstructorHandler$ImageTagConstructorValidatorC?6???WLthis$0tILtechadapt/accessiblemediacenter/converter/saxon/ImageConstructorHandler;
write byte[]: xr"net.sf.saxon.expr.SimpleExpressionx?2?????[    argumentsq~#
constantValueq~wLnet.sf.saxon.expr.VariableReference???b?:filteredZ     flattenedZinLoopLbindingtnet/sf/saxon/expr/Binding;L
staticTypeq~h
write byte[]: srGtechadapt.accessiblemediacenter.converter.saxon.ImageConstructorHandlers???TB  Laltq~iL
                                                                                                        contentPathq~iLheightq~iLidq~iimgClassq~iLmaxImageHeightmaxImageWidthq~iLsrcq~iLwidthq~i
write byte[]: xr'net.sf.saxon.style.ExtensionInstruction??P?oN?o
write byte[]: xrnet.sf.saxon.style.StyleElement??????)
                                                      Z
explainingI
lineNumberIreportingCircumstancesLcontainingStylesheett"Lnet/sf/saxon/style/XSLStylesheet;LdefaultCollationNameqLdefaultXPathNamespaceq[excludedNamespacest[S[extensionNamespacesq~L
staticContextt!Lnet/sf/saxon/expr/StaticContext;LvalidationErrort#Lnet/sf/saxon/trans/XPathException;LversiontLjava/math/BigDecimal;
write byte[]: sr net.sf.saxon.style.XSLStylesheetv?Wg?mbZallowsAllBuiltInTypesIdefaultValidationIinputAnnotationsIlargestPatternStackFrameIminImportPrecedenceZneedsDynamicOutputPropertiesInumberOfAliasesI
precedenceZ
           wasIncluded[
                       aliasNCodesq~'[
javaFunctionsq~                       aliasSCodesq~Lexecq~LfunctionLibraryt,Lnet/sf/saxon/functions/FunctionLibraryList;LglobalVariableIndexq~importerq~
LlocalParameterNumbersq~L
LnamespaceAliasListq~?LqueryFunctionst*Lnet/sf/saxon/query/XQueryFunctionLibrary;L
                                                                                  schemaIndexq~L
templateIndexq~topLevelq~/PreparedStylesheet;L
write byte[]: qt$net.sf.saxon.style.ExpressionContextur[Ljava.lang.StackTraceElement;F*<<?"9
write byte[]: tnet.sf.saxon.Compilet
                                    Compile.javatdoMainsq~

java.io.NotSerializableException: net.sf.saxon.style.ExpressionContext
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1081)
        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1375)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1347)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1290)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1079)
        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1375)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1347)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1290)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1079)
        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1375)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1347)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1290)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1079)
        at java.io.ObjectOutputStream.writeArray(ObjectOutputStream.java:1251)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1075)
        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1375)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1347)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1290)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1079)
        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1375)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1347)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1290)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1079)
        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1375)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1347)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1290)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1079)
        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1375)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1347)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1290)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1079)
        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1375)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1347)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1290)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1079)
        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1375)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1347)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1290)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1079)
        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1375)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1347)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1290)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1079)
        at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:302)
        at net.sf.saxon.Compile.doMain(Compile.java:168)
        at net.sf.saxon.Compile.main(Compile.java:42)
squiddy:~/temp/saxon test cvonsee$