diff options
Diffstat (limited to 'src/java/org/apache/fop/pdf/PDFReference.java')
-rw-r--r-- | src/java/org/apache/fop/pdf/PDFReference.java | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/src/java/org/apache/fop/pdf/PDFReference.java b/src/java/org/apache/fop/pdf/PDFReference.java new file mode 100644 index 000000000..4ca50a79f --- /dev/null +++ b/src/java/org/apache/fop/pdf/PDFReference.java @@ -0,0 +1,67 @@ +/* + * 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 + * + * 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, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ + +package org.apache.fop.pdf; + +import java.lang.ref.Reference; +import java.lang.ref.SoftReference; + +/** + * Class representing a PDF object reference. The object holds a soft reference to the actual + * PDF object so the garbage collector can free the object if it's not referenced elsewhere. The + * important thing about the class is the reference information to the actual PDF object in the + * PDF file. + */ +public class PDFReference implements PDFWritable { + + private String indirectReference; + + private Reference objReference; + + /** + * Creates a new PDF reference. + * @param obj the object to be referenced + */ + public PDFReference(PDFObject obj) { + this.indirectReference = obj.referencePDF(); + this.objReference = new SoftReference(obj); + } + + /** + * Returns the PDF object + * @return the PDF object, or null if it has been released + */ + public PDFObject getObject() { + if (this.objReference != null) { + PDFObject obj = (PDFObject)this.objReference.get(); + if (obj == null) { + this.objReference = null; + } + return obj; + } else { + return null; + } + } + + /** @see org.apache.fop.pdf.PDFWritable#toInlinePDFString() */ + public String toInlinePDFString() { + return this.indirectReference; + } + +} |