001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018: package org.apache.ivy.plugins.repository.ssh;
019:
020: import java.io.IOException;
021: import java.io.InputStream;
022:
023: import org.apache.ivy.plugins.repository.Resource;
024: import org.apache.ivy.util.Message;
025:
026: /**
027: * Resource for SSH Ivy Repository
028: */
029: public class SshResource implements Resource {
030:
031: private boolean resolved = false;
032:
033: private String uri = null;
034:
035: private boolean bExists = false;
036:
037: private long len = 0;
038:
039: private long lastModified = 0;
040:
041: private SshRepository repository = null;
042:
043: public SshResource() {
044: resolved = true;
045: }
046:
047: public SshResource(SshRepository repository, String uri) {
048: this .uri = uri;
049: this .repository = repository;
050: resolved = false;
051: }
052:
053: public SshResource(SshRepository repository, String uri,
054: boolean bExists, long len, long lastModified) {
055: this .uri = uri;
056: this .bExists = bExists;
057: this .len = len;
058: this .lastModified = lastModified;
059: this .repository = repository;
060: resolved = true;
061: }
062:
063: /*
064: * (non-Javadoc)
065: *
066: * @see org.apache.ivy.repository.Resource#exists()
067: */
068: public boolean exists() {
069: if (!resolved) {
070: resolve();
071: }
072: return bExists;
073: }
074:
075: /*
076: * (non-Javadoc)
077: *
078: * @see org.apache.ivy.repository.Resource#getContentLength()
079: */
080: public long getContentLength() {
081: if (!resolved) {
082: resolve();
083: }
084: return len;
085: }
086:
087: /*
088: * (non-Javadoc)
089: *
090: * @see org.apache.ivy.repository.Resource#getLastModified()
091: */
092: public long getLastModified() {
093: if (!resolved) {
094: resolve();
095: }
096: return lastModified;
097: }
098:
099: private void resolve() {
100: Message.debug("SShResource: resolving " + uri);
101: SshResource res = repository.resolveResource(uri);
102: len = res.getContentLength();
103: lastModified = res.getLastModified();
104: bExists = res.exists();
105: resolved = true;
106: Message.debug("SShResource: resolved " + this );
107: }
108:
109: /*
110: * (non-Javadoc)
111: *
112: * @see org.apache.ivy.repository.Resource#getName()
113: */
114: public String getName() {
115: return uri;
116: }
117:
118: public String toString() {
119: StringBuffer buffer = new StringBuffer();
120: buffer.append("SshResource:");
121: buffer.append(uri);
122: buffer.append(" (");
123: buffer.append(len);
124: buffer.append(")]");
125: return buffer.toString();
126: }
127:
128: public boolean isLocal() {
129: return false;
130: }
131:
132: public Resource clone(String cloneName) {
133: return new SshResource(repository, cloneName);
134: }
135:
136: public InputStream openStream() throws IOException {
137: return repository.openStream(this);
138: }
139: }
|