components/visual-panels/core/src/java/vpanels/panel/com/oracle/solaris/vp/panel/common/api/file/RemoteFile.java
branchs11-update
changeset 2805 4888f6212f94
parent 827 0944d8c0158b
child 1700 d04a7bb15a5b
equal deleted inserted replaced
2804:7546c836fd87 2805:4888f6212f94
    18  *
    18  *
    19  * CDDL HEADER END
    19  * CDDL HEADER END
    20  */
    20  */
    21 
    21 
    22 /*
    22 /*
    23  * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
    23  * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
    24  */
    24  */
    25 
    25 
    26 package com.oracle.solaris.vp.panel.common.api.file;
    26 package com.oracle.solaris.vp.panel.common.api.file;
    27 
    27 
    28 import java.io.*;
    28 import java.io.*;
    29 import java.util.List;
    29 import java.util.List;
    30 import com.oracle.solaris.rad.ObjectException;
    30 import com.oracle.solaris.rad.client.RadObjectException;
    31 
    31 
    32 @SuppressWarnings({"serial"})
    32 @SuppressWarnings({"serial"})
    33 public class RemoteFile extends File {
    33 public class RemoteFile extends File {
    34     //
    34     //
    35     // Instance data
    35     // Instance data
    36     //
    36     //
    37 
    37 
    38     private FileBrowserMXBean browser;
    38     private FileBrowser browser;
    39     private FileSnapshot snapshot;
    39     private FileSnapshot snapshot;
    40 
    40 
    41     //
    41     //
    42     // Constructors
    42     // Constructors
    43     //
    43     //
    44 
    44 
    45     public RemoteFile(FileBrowserMXBean browser, FileSnapshot snapshot) {
    45     public RemoteFile(FileBrowser browser, FileSnapshot snapshot) {
    46 	super(snapshot.getPath());
    46 	super(snapshot.getPath());
    47 	this.browser = browser;
    47 	this.browser = browser;
    48 	this.snapshot = snapshot;
    48 	this.snapshot = snapshot;
    49     }
    49     }
    50 
    50 
   106 	    return this;
   106 	    return this;
   107 	}
   107 	}
   108 	String path = snapshot.getCanonicalPath();
   108 	String path = snapshot.getCanonicalPath();
   109 	try {
   109 	try {
   110 	    return new RemoteFile(browser, browser.getFile(path));
   110 	    return new RemoteFile(browser, browser.getFile(path));
   111 	} catch (ObjectException e) {
   111 	} catch (RadObjectException e) {
   112 	    throw new IOException(e);
   112 	    throw new IOException(e);
   113 	}
   113 	}
   114     }
   114     }
   115 
   115 
   116     @Override
   116     @Override
   134     public RemoteFile getParentFile() {
   134     public RemoteFile getParentFile() {
   135 	String parent = getParent();
   135 	String parent = getParent();
   136 	try {
   136 	try {
   137 	    return parent == null ? null :
   137 	    return parent == null ? null :
   138 		new RemoteFile(browser, browser.getFile(parent));
   138 		new RemoteFile(browser, browser.getFile(parent));
   139 	} catch (ObjectException e) {
   139 	} catch (RadObjectException e) {
   140 	    /* Not correct, but our choices are limited */
   140 	    /* Not correct, but our choices are limited */
   141 	    return null;
   141 	    return null;
   142 	}
   142 	}
   143     }
   143     }
   144 
   144 
   191 	    int i = 0;
   191 	    int i = 0;
   192 	    for (FileSnapshot ss : snapshots)
   192 	    for (FileSnapshot ss : snapshots)
   193 		names[i++] = ss.getBaseName();
   193 		names[i++] = ss.getBaseName();
   194 
   194 
   195 	    return names;
   195 	    return names;
   196 	} catch (ObjectException e) {
   196 	} catch (RadObjectException e) {
   197 	    return null;
   197 	    return null;
   198 	}
   198 	}
   199     }
   199     }
   200 
   200 
   201     @Override
   201     @Override
   202     public RemoteFile[] listFiles() {
   202     public RemoteFile[] listFiles() {
   203 	try {
   203 	try {
   204 	    List<FileSnapshot> snapshots = browser.getFiles(getAbsolutePath());
   204 	    List<FileSnapshot> snapshots = browser.getFiles(getAbsolutePath());
   205 	    return toFiles(snapshots);
   205 	    return toFiles(snapshots);
   206 	} catch (ObjectException e) {
   206 	} catch (RadObjectException e) {
   207 	    return null;
   207 	    return null;
   208 	}
   208 	}
   209     }
   209     }
   210 
   210 
   211     @Override
   211     @Override
   276 
   276 
   277     //
   277     //
   278     // RemoteFile methods
   278     // RemoteFile methods
   279     //
   279     //
   280 
   280 
   281     public FileBrowserMXBean getBrowser() {
   281     public FileBrowser getBrowser() {
   282 	return browser;
   282 	return browser;
   283     }
   283     }
   284 
   284 
   285     public FileSnapshot getSnapshot() {
   285     public FileSnapshot getSnapshot() {
   286 	return snapshot;
   286 	return snapshot;
   293     //
   293     //
   294     // Static methods
   294     // Static methods
   295     //
   295     //
   296 
   296 
   297     public static RemoteFile[] toFiles(
   297     public static RemoteFile[] toFiles(
   298 	FileBrowserMXBean browser, List<FileSnapshot> snapshots) {
   298 	FileBrowser browser, List<FileSnapshot> snapshots) {
   299 
   299 
   300 	RemoteFile[] files = new RemoteFile[snapshots.size()];
   300 	RemoteFile[] files = new RemoteFile[snapshots.size()];
   301 
   301 
   302 	int i = 0;
   302 	int i = 0;
   303 	for (FileSnapshot ss : snapshots)
   303 	for (FileSnapshot ss : snapshots)