aboutsummaryrefslogtreecommitdiff
path: root/src/com/sun/org/apache/xalan/internal/xsltc/trax/TemplatesImpl.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/sun/org/apache/xalan/internal/xsltc/trax/TemplatesImpl.java')
-rw-r--r--src/com/sun/org/apache/xalan/internal/xsltc/trax/TemplatesImpl.java120
1 files changed, 94 insertions, 26 deletions
diff --git a/src/com/sun/org/apache/xalan/internal/xsltc/trax/TemplatesImpl.java b/src/com/sun/org/apache/xalan/internal/xsltc/trax/TemplatesImpl.java
index e6d9cc3..e0ee6fb 100644
--- a/src/com/sun/org/apache/xalan/internal/xsltc/trax/TemplatesImpl.java
+++ b/src/com/sun/org/apache/xalan/internal/xsltc/trax/TemplatesImpl.java
@@ -1,15 +1,15 @@
/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
*/
/*
- * Copyright 2001-2004 The Apache Software Foundation.
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -24,28 +24,29 @@
package com.sun.org.apache.xalan.internal.xsltc.trax;
import com.sun.org.apache.xalan.internal.XalanConstants;
+import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
+import com.sun.org.apache.xalan.internal.utils.SecuritySupport;
+import com.sun.org.apache.xalan.internal.xsltc.DOM;
+import com.sun.org.apache.xalan.internal.xsltc.Translet;
+import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
+import com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet;
import java.io.IOException;
+import java.io.NotSerializableException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
+import java.io.ObjectStreamField;
import java.io.Serializable;
-import java.util.Properties;
import java.security.AccessController;
import java.security.PrivilegedAction;
-
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
import javax.xml.XMLConstants;
import javax.xml.transform.Templates;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.URIResolver;
-import com.sun.org.apache.xalan.internal.xsltc.DOM;
-import com.sun.org.apache.xalan.internal.xsltc.Translet;
-import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
-import com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet;
-import com.sun.org.apache.xalan.internal.xsltc.runtime.Hashtable;
-import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
-import com.sun.org.apache.xalan.internal.utils.SecuritySupport;
-
/**
* @author Morten Jorgensen
* @author G. Todd Millerj
@@ -90,7 +91,7 @@ public final class TemplatesImpl implements Templates, Serializable {
/**
* Contains the list of auxiliary class definitions.
*/
- private Hashtable _auxClasses = null;
+ private transient Map<String, Class<?>> _auxClasses = null;
/**
* Output properties of this translet.
@@ -123,18 +124,60 @@ public final class TemplatesImpl implements Templates, Serializable {
*/
private transient TransformerFactoryImpl _tfactory = null;
- private boolean _useServicesMechanism;
+ /**
+ * A flag to determine whether the Service Mechanism is used
+ */
+ private transient boolean _useServicesMechanism;
/**
* protocols allowed for external references set by the stylesheet processing instruction, Import and Include element.
*/
- private String _accessExternalStylesheet = XalanConstants.EXTERNAL_ACCESS_DEFAULT;
+ private transient String _accessExternalStylesheet = XalanConstants.EXTERNAL_ACCESS_DEFAULT;
+
+ /**
+ * @serialField _name String The Name of the main class
+ * @serialField _bytecodes byte[][] Class definition
+ * @serialField _class Class[] The translet class definition(s).
+ * @serialField _transletIndex int The index of the main translet class
+ * @serialField _outputProperties Properties Output properties of this translet.
+ * @serialField _indentNumber int Number of spaces to add for output indentation.
+ */
+ private static final ObjectStreamField[] serialPersistentFields =
+ new ObjectStreamField[] {
+ new ObjectStreamField("_name", String.class),
+ new ObjectStreamField("_bytecodes", byte[][].class),
+ new ObjectStreamField("_class", Class[].class),
+ new ObjectStreamField("_transletIndex", int.class),
+ new ObjectStreamField("_outputProperties", Properties.class),
+ new ObjectStreamField("_indentNumber", int.class),
+ };
static final class TransletClassLoader extends ClassLoader {
- TransletClassLoader(ClassLoader parent) {
+ private final Map<String,Class> _loadedExternalExtensionFunctions;
+
+ TransletClassLoader(ClassLoader parent) {
+ super(parent);
+ _loadedExternalExtensionFunctions = null;
+ }
+
+ TransletClassLoader(ClassLoader parent,Map<String, Class> mapEF) {
super(parent);
+ _loadedExternalExtensionFunctions = mapEF;
}
+ public Class<?> loadClass(String name) throws ClassNotFoundException {
+ Class<?> ret = null;
+ // The _loadedExternalExtensionFunctions will be empty when the
+ // SecurityManager is not set and the FSP is turned off
+ if (_loadedExternalExtensionFunctions != null) {
+ ret = _loadedExternalExtensionFunctions.get(name);
+ }
+ if (ret == null) {
+ ret = super.loadClass(name);
+ }
+ return ret;
+ }
+
/**
* Access to final protected superclass member from outer class.
*/
@@ -193,6 +236,7 @@ public final class TemplatesImpl implements Templates, Serializable {
* if yes then we need to deserialize the URIResolver
* Fix for bugzilla bug 22438
*/
+ @SuppressWarnings("unchecked")
private void readObject(ObjectInputStream is)
throws IOException, ClassNotFoundException
{
@@ -205,7 +249,16 @@ public final class TemplatesImpl implements Templates, Serializable {
}
}
- is.defaultReadObject();
+ // We have to read serialized fields first.
+ ObjectInputStream.GetField gf = is.readFields();
+ _name = (String)gf.get("_name", null);
+ _bytecodes = (byte[][])gf.get("_bytecodes", null);
+ _class = (Class[])gf.get("_class", null);
+ _transletIndex = gf.get("_transletIndex", -1);
+
+ _outputProperties = (Properties)gf.get("_outputProperties", null);
+ _indentNumber = gf.get("_indentNumber", 0);
+
if (is.readBoolean()) {
_uriResolver = (URIResolver) is.readObject();
}
@@ -221,7 +274,22 @@ public final class TemplatesImpl implements Templates, Serializable {
*/
private void writeObject(ObjectOutputStream os)
throws IOException, ClassNotFoundException {
- os.defaultWriteObject();
+ if (_auxClasses != null) {
+ //throw with the same message as when Hashtable was used for compatibility.
+ throw new NotSerializableException(
+ "com.sun.org.apache.xalan.internal.xsltc.runtime.Hashtable");
+ }
+
+ // Write serialized fields
+ ObjectOutputStream.PutField pf = os.putFields();
+ pf.put("_name", _name);
+ pf.put("_bytecodes", _bytecodes);
+ pf.put("_class", _class);
+ pf.put("_transletIndex", _transletIndex);
+ pf.put("_outputProperties", _outputProperties);
+ pf.put("_indentNumber", _indentNumber);
+ os.writeFields();
+
if (_uriResolver instanceof Serializable) {
os.writeBoolean(true);
os.writeObject((Serializable) _uriResolver);
@@ -330,7 +398,7 @@ public final class TemplatesImpl implements Templates, Serializable {
TransletClassLoader loader = (TransletClassLoader)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
- return new TransletClassLoader(ObjectFactory.findClassLoader());
+ return new TransletClassLoader(ObjectFactory.findClassLoader(),_tfactory.getExternalExtensionsMap());
}
});
@@ -339,7 +407,7 @@ public final class TemplatesImpl implements Templates, Serializable {
_class = new Class[classCount];
if (classCount > 1) {
- _auxClasses = new Hashtable();
+ _auxClasses = new HashMap<>();
}
for (int i = 0; i < classCount; i++) {