src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TemplatesImpl.java
equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved. |
3 * @LastModified: Sep 2017 |
3 * @LastModified: Oct 2017 |
4 */ |
4 */ |
5 /* |
5 /* |
6 * Licensed to the Apache Software Foundation (ASF) under one or more |
6 * Licensed to the Apache Software Foundation (ASF) under one or more |
7 * contributor license agreements. See the NOTICE file distributed with |
7 * contributor license agreements. See the NOTICE file distributed with |
8 * this work for additional information regarding copyright ownership. |
8 * this work for additional information regarding copyright ownership. |
95 |
95 |
96 /** |
96 /** |
97 * Contains the translet class definition(s). These are created when |
97 * Contains the translet class definition(s). These are created when |
98 * this Templates is created or when it is read back from disk. |
98 * this Templates is created or when it is read back from disk. |
99 */ |
99 */ |
100 private Class[] _class = null; |
100 private Class<?>[] _class = null; |
101 |
101 |
102 /** |
102 /** |
103 * The index of the main translet class in the arrays _class[] and |
103 * The index of the main translet class in the arrays _class[] and |
104 * _bytecodes. |
104 * _bytecodes. |
105 */ |
105 */ |
131 * which is used by the document('') function. |
131 * which is used by the document('') function. |
132 * Use ThreadLocal because a DTM cannot be shared between |
132 * Use ThreadLocal because a DTM cannot be shared between |
133 * multiple threads. |
133 * multiple threads. |
134 * Declaring it transient to fix bug 22438 |
134 * Declaring it transient to fix bug 22438 |
135 */ |
135 */ |
136 private transient ThreadLocal _sdom = new ThreadLocal(); |
136 private transient ThreadLocal<DOM> _sdom = new ThreadLocal<>(); |
137 |
137 |
138 /** |
138 /** |
139 * A reference to the transformer factory that this templates |
139 * A reference to the transformer factory that this templates |
140 * object belongs to. |
140 * object belongs to. |
141 */ |
141 */ |
197 } |
197 } |
198 |
198 |
199 /** |
199 /** |
200 * Access to final protected superclass member from outer class. |
200 * Access to final protected superclass member from outer class. |
201 */ |
201 */ |
202 Class defineClass(final byte[] b) { |
202 Class<?> defineClass(final byte[] b) { |
203 return defineClass(null, b, 0, b.length); |
203 return defineClass(null, b, 0, b.length); |
204 } |
204 } |
205 |
205 |
206 Class defineClass(final byte[] b, ProtectionDomain pd) { |
206 Class<?> defineClass(final byte[] b, ProtectionDomain pd) { |
207 return defineClass(null, b, 0, b.length, pd); |
207 return defineClass(null, b, 0, b.length, pd); |
208 } |
208 } |
209 } |
209 } |
210 |
210 |
211 |
211 |
273 |
273 |
274 // We have to read serialized fields first. |
274 // We have to read serialized fields first. |
275 ObjectInputStream.GetField gf = is.readFields(); |
275 ObjectInputStream.GetField gf = is.readFields(); |
276 _name = (String)gf.get("_name", null); |
276 _name = (String)gf.get("_name", null); |
277 _bytecodes = (byte[][])gf.get("_bytecodes", null); |
277 _bytecodes = (byte[][])gf.get("_bytecodes", null); |
278 _class = (Class[])gf.get("_class", null); |
278 _class = (Class<?>[])gf.get("_class", null); |
279 _transletIndex = gf.get("_transletIndex", -1); |
279 _transletIndex = gf.get("_transletIndex", -1); |
280 |
280 |
281 _outputProperties = (Properties)gf.get("_outputProperties", null); |
281 _outputProperties = (Properties)gf.get("_outputProperties", null); |
282 _indentNumber = gf.get("_indentNumber", 0); |
282 _indentNumber = gf.get("_indentNumber", 0); |
283 |
283 |
366 * Note: This method is private for security reasons. See |
366 * Note: This method is private for security reasons. See |
367 * CR 6537898. When merging with Apache, we must ensure |
367 * CR 6537898. When merging with Apache, we must ensure |
368 * that the privateness of this method is maintained (that |
368 * that the privateness of this method is maintained (that |
369 * is why it wasn't removed). |
369 * is why it wasn't removed). |
370 */ |
370 */ |
371 private synchronized Class[] getTransletClasses() { |
371 private synchronized Class<?>[] getTransletClasses() { |
372 try { |
372 try { |
373 if (_class == null) defineTransletClasses(); |
373 if (_class == null) defineTransletClasses(); |
374 } |
374 } |
375 catch (TransformerConfigurationException e) { |
375 catch (TransformerConfigurationException e) { |
376 // Falls through |
376 // Falls through |
459 if (_bytecodes == null) { |
459 if (_bytecodes == null) { |
460 ErrorMsg err = new ErrorMsg(ErrorMsg.NO_TRANSLET_CLASS_ERR); |
460 ErrorMsg err = new ErrorMsg(ErrorMsg.NO_TRANSLET_CLASS_ERR); |
461 throw new TransformerConfigurationException(err.toString()); |
461 throw new TransformerConfigurationException(err.toString()); |
462 } |
462 } |
463 |
463 |
464 TransletClassLoader loader = (TransletClassLoader) |
464 TransletClassLoader loader = |
465 AccessController.doPrivileged(new PrivilegedAction() { |
465 AccessController.doPrivileged(new PrivilegedAction<TransletClassLoader>() { |
466 public Object run() { |
466 public TransletClassLoader run() { |
467 return new TransletClassLoader(ObjectFactory.findClassLoader(),_tfactory.getExternalExtensionsMap()); |
467 return new TransletClassLoader(ObjectFactory.findClassLoader(), |
|
468 _tfactory.getExternalExtensionsMap()); |
468 } |
469 } |
469 }); |
470 }); |
470 |
471 |
471 try { |
472 try { |
472 final int classCount = _bytecodes.length; |
473 final int classCount = _bytecodes.length; |
473 _class = new Class[classCount]; |
474 _class = new Class<?>[classCount]; |
474 |
475 |
475 if (classCount > 1) { |
476 if (classCount > 1) { |
476 _auxClasses = new HashMap<>(); |
477 _auxClasses = new HashMap<>(); |
477 } |
478 } |
478 |
479 |
509 // java.xml needs to instantiate the translet class |
510 // java.xml needs to instantiate the translet class |
510 thisModule.addReads(m); |
511 thisModule.addReads(m); |
511 |
512 |
512 for (int i = 0; i < classCount; i++) { |
513 for (int i = 0; i < classCount; i++) { |
513 _class[i] = loader.defineClass(_bytecodes[i], pd); |
514 _class[i] = loader.defineClass(_bytecodes[i], pd); |
514 final Class superClass = _class[i].getSuperclass(); |
515 final Class<?> superClass = _class[i].getSuperclass(); |
515 |
516 |
516 // Check if this is the main class |
517 // Check if this is the main class |
517 if (superClass.getName().equals(ABSTRACT_TRANSLET)) { |
518 if (superClass.getName().equals(ABSTRACT_TRANSLET)) { |
518 _transletIndex = i; |
519 _transletIndex = i; |
519 } |
520 } |