01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18:
19: package org.apache.tools.ant.util;
20:
21: import java.lang.ref.WeakReference;
22:
23: /**
24: * These classes are part of some code to reduce memory leaks by only
25: * retaining weak references to things
26: * on Java1.2+, and yet still work (with leaky hard references) on Java1.1.
27: * Now that Ant is 1.2+ only,
28: * life is simpler and none of the classes are needed any more.
29: *
30: * They are only retained in case a third-party task uses them
31: * @since ant1.6
32: * @see org.apache.tools.ant.util.optional.WeakishReference12
33: * @deprecated deprecated 1.7; will be removed in Ant1.8
34: * Just use {@link java.lang.ref.WeakReference} directly.
35: */
36: public class WeakishReference {
37:
38: private WeakReference weakref;
39:
40: /**
41: * create a new soft reference, which is bound to a
42: * Weak reference inside
43: *
44: * @param reference
45: * @see java.lang.ref.WeakReference
46: */
47: WeakishReference(Object reference) {
48: this .weakref = new WeakReference(reference);
49: }
50:
51: /**
52: * Returns this reference object's referent. If this reference object has
53: * been cleared, then this method returns <code>null</code>.
54: *
55: * @return The object to which this reference refers, or
56: * <code>null</code> if this reference object has been cleared.
57: */
58: public Object get() {
59: return weakref.get();
60: }
61:
62: /**
63: * create the appropriate type of reference for the java version
64: * @param object the object that the reference will refer to.
65: * @return reference to the Object.
66: */
67: public static WeakishReference createReference(Object object) {
68: return new WeakishReference(object);
69: }
70:
71: /**
72: * This was a hard reference for Java 1.1. Since Ant1.7,
73: * @deprecated since 1.7.
74: * Hopefully nobody is using this.
75: */
76: public static class HardReference extends WeakishReference {
77:
78: /**
79: * constructor.
80: * @param object the object that the reference will refer to.
81: */
82: public HardReference(Object object) {
83: super(object);
84: }
85:
86: }
87:
88: }
|