1 /* 2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. 3 */ 4 /* 5 * Licensed to the Apache Software Foundation (ASF) under one or more 6 * contributor license agreements. See the NOTICE file distributed with 7 * this work for additional information regarding copyright ownership. 8 * The ASF licenses this file to You under the Apache License, Version 2.0 9 * (the "License"); you may not use this file except in compliance with 10 * the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, software 15 * distributed under the License is distributed on an "AS IS" BASIS, 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 * See the License for the specific language governing permissions and 18 * limitations under the License. 19 */ 20 21 package com.sun.org.apache.xerces.internal.jaxp.validation; 22 23 import java.lang.ref.WeakReference; 24 25 import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool; 26 27 /** 28 * <p>An implementation of Schema for W3C XML Schemas 29 * that keeps a weak reference to its grammar pool. If 30 * no validators currently have a reference to the 31 * grammar pool, the garbage collector is free to reclaim 32 * its memory.</p> 33 * 34 * @author Michael Glavassevich, IBM 35 * @LastModified: Oct 2017 36 */ 37 final class WeakReferenceXMLSchema extends AbstractXMLSchema { 38 39 /** Weak reference to grammar pool. */ 40 private WeakReference<XMLGrammarPool> fGrammarPool = new WeakReference<>(null); 41 42 public WeakReferenceXMLSchema() {} 43 44 /* 45 * XSGrammarPoolContainer methods 46 */ 47 48 public synchronized XMLGrammarPool getGrammarPool() { 49 XMLGrammarPool grammarPool = fGrammarPool.get(); 50 // If there's no grammar pool then either we haven't created one 51 // yet or the garbage collector has already cleaned out the previous one. 52 if (grammarPool == null) { 53 grammarPool = new SoftReferenceGrammarPool(); 54 fGrammarPool = new WeakReference<>(grammarPool); 55 } 56 return grammarPool; 57 } 58 59 public boolean isFullyComposed() { 60 return false; 61 } 62 63 } // WeakReferenceXMLSchema