KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > util > WeakishReference


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * 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
22 import java.lang.ref.WeakReference JavaDoc;
23
24 /**
25  * These classes are part of some code to reduce memory leaks by only
26  * retaining weak references to things
27  * on Java1.2+, and yet still work (with leaky hard references) on Java1.1.
28  * Now that Ant is 1.2+ only,
29  * life is simpler and none of the classes are needed any more.
30  *
31  * They are only retained in case a third-party task uses them
32  * @since ant1.6
33  * @see org.apache.tools.ant.util.optional.WeakishReference12
34  * @deprecated deprecated 1.7; will be removed in Ant1.8
35  * Just use {@link java.lang.ref.WeakReference} directly.
36  */

37 public class WeakishReference {
38
39
40     private WeakReference JavaDoc weakref;
41
42     /**
43      * create a new soft reference, which is bound to a
44      * Weak reference inside
45      *
46      * @param reference
47      * @see java.lang.ref.WeakReference
48      */

49     WeakishReference(Object JavaDoc reference) {
50         this.weakref = new WeakReference JavaDoc(reference);
51     }
52
53     /**
54      * Returns this reference object's referent. If this reference object has
55      * been cleared, then this method returns <code>null</code>.
56      *
57      * @return The object to which this reference refers, or
58      * <code>null</code> if this reference object has been cleared.
59      */

60     public Object JavaDoc get() {
61         return weakref.get();
62     }
63
64     /**
65      * create the appropriate type of reference for the java version
66      * @param object the object that the reference will refer to.
67      * @return reference to the Object.
68      */

69     public static WeakishReference createReference(Object JavaDoc object) {
70             return new WeakishReference(object);
71     }
72
73
74     /**
75      * This was a hard reference for Java 1.1. Since Ant1.7,
76      * @deprecated since 1.7.
77      * Hopefully nobody is using this.
78      */

79     public static class HardReference extends WeakishReference {
80
81         /**
82          * constructor.
83          * @param object the object that the reference will refer to.
84          */

85         public HardReference(Object JavaDoc object) {
86             super(object);
87         }
88
89     }
90
91 }
92
Popular Tags