KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > services > impl > DeferredObjectImpl


1 // Copyright 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.tapestry.services.impl;
16
17 import org.apache.hivemind.Location;
18 import org.apache.hivemind.internal.Module;
19 import org.apache.hivemind.schema.Translator;
20
21 /**
22  * An encapsulation of an invocation of
23  * {@link org.apache.hivemind.schema.Translator#translate(org.apache.hivemind.internal.Module, java.lang.Class, java.lang.String, org.apache.hivemind.Location)},
24  * allowing the actual invocation (and all the object creation, etc., that entails) to be deferred,
25  * or even avoided all together.
26  *
27  * @author Howard M. Lewis Ship
28  * @since 4.0
29  */

30 public class DeferredObjectImpl implements DeferredObject
31 {
32     private final Module _module;
33
34     private final Translator _objectTranslator;
35
36     private final String JavaDoc _objectReference;
37
38     private final Location _location;
39
40     private Object JavaDoc _object;
41
42     public DeferredObjectImpl(final Translator objectTranslator, final Module module,
43             final String JavaDoc objectReference, final Location location)
44     {
45         _objectTranslator = objectTranslator;
46         _module = module;
47         _objectReference = objectReference;
48         _location = location;
49     }
50
51     public synchronized Object JavaDoc getObject()
52     {
53         if (_object == null)
54             _object = _objectTranslator.translate(
55                     _module,
56                     Object JavaDoc.class,
57                     _objectReference,
58                     _location);
59
60         return _object;
61     }
62
63     public Location getLocation()
64     {
65         return _location;
66     }
67 }
Popular Tags