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: package org.apache.ivy.plugins.repository;
19:
20: public abstract class LazyResource implements Resource {
21: private boolean _init = false;
22:
23: private boolean _local;
24:
25: private String _name;
26:
27: private long _lastModified;
28:
29: private long _contentLength;
30:
31: private boolean _exists;
32:
33: public LazyResource(String name) {
34: _name = name;
35: }
36:
37: protected abstract void init();
38:
39: private void checkInit() {
40: if (!_init) {
41: init();
42: _init = true;
43: }
44: }
45:
46: public boolean exists() {
47: checkInit();
48: return _exists;
49: }
50:
51: public long getContentLength() {
52: checkInit();
53: return _contentLength;
54: }
55:
56: public long getLastModified() {
57: checkInit();
58: return _lastModified;
59: }
60:
61: public String getName() {
62: return _name;
63: }
64:
65: public boolean isLocal() {
66: checkInit();
67: return _local;
68: }
69:
70: public String toString() {
71: return getName();
72: }
73:
74: protected void setContentLength(long contentLength) {
75: _contentLength = contentLength;
76: }
77:
78: protected void setExists(boolean exists) {
79: _exists = exists;
80: }
81:
82: protected void setLastModified(long lastModified) {
83: _lastModified = lastModified;
84: }
85:
86: protected void setLocal(boolean local) {
87: _local = local;
88: }
89:
90: protected void init(Resource r) {
91: setContentLength(r.getContentLength());
92: setLocal(r.isLocal());
93: setLastModified(r.getLastModified());
94: setExists(r.exists());
95: }
96:
97: }
|