/[svn]/jlscp/trunk/src/org/linuxsampler/lscp/Client.java
ViewVC logotype

Diff of /jlscp/trunk/src/org/linuxsampler/lscp/Client.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1139 by iliev, Mon Apr 2 20:43:58 2007 UTC revision 1307 by iliev, Mon Aug 27 13:34:34 2007 UTC
# Line 69  public class Client { Line 69  public class Client {
69          private String address;          private String address;
70          private int port;          private int port;
71          private Socket sock = null;          private Socket sock = null;
72          private int soTimeout = 10000;          private int soTimeout = 20000;
73                    
74          private LscpInputStream in = null;          private LscpInputStream in = null;
75          private LscpOutputStream out = null;          private LscpOutputStream out = null;
# Line 79  public class Client { Line 79  public class Client {
79          private boolean printOnlyMode = false;          private boolean printOnlyMode = false;
80                    
81          class EventThread extends Thread {          class EventThread extends Thread {
82                    private Vector<String> queue = new Vector<String>();
83                  private boolean terminate = false;                  private boolean terminate = false;
84                                    
85                  EventThread() { super("LSCP-Event-Thread"); }                  EventThread() { super("LSCP-Event-Thread"); }
# Line 86  public class Client { Line 87  public class Client {
87                  public void                  public void
88                  run() {                  run() {
89                          while(!mustTerminate()) {                          while(!mustTerminate()) {
90                                  try { processNotifications(); }                                  try {
91                                  catch(Exception x) {                                          processQueue();
92                                            processNotifications();
93                                    } catch(Exception x) {
94                                          getLogger().log(Level.FINE, x.getMessage(), x);                                          getLogger().log(Level.FINE, x.getMessage(), x);
95                                  }                                  }
96                                  try { synchronized(this) { wait(100); } }                                  try { synchronized(this) { wait(100); } }
# Line 105  public class Client { Line 108  public class Client {
108                          terminate = true;                          terminate = true;
109                          this.notifyAll();                          this.notifyAll();
110                  }                  }
111                    
112                    public synchronized void
113                    scheduleNotification(String s) { queue.add(s); }
114                    
115                    private void
116                    processQueue() {
117                            String[] notifications = popAllNotifications();
118                            for(String n : notifications) fireEvent(n);
119                    }
120                    
121                    private synchronized String[]
122                    popAllNotifications() {
123                            String[] notifications = queue.toArray(new String[queue.size()]);
124                            queue.removeAllElements();
125                            return notifications;
126                    }
127          }          }
128                    
129          /**          /**
# Line 329  public class Client { Line 348  public class Client {
348                  if(!llMIMI.isEmpty()) subscribe("MIDI_INSTRUMENT_MAP_INFO");                  if(!llMIMI.isEmpty()) subscribe("MIDI_INSTRUMENT_MAP_INFO");
349                  if(!llMIC.isEmpty()) subscribe("MIDI_INSTRUMENT_COUNT");                  if(!llMIC.isEmpty()) subscribe("MIDI_INSTRUMENT_COUNT");
350                  if(!llMII.isEmpty()) subscribe("MIDI_INSTRUMENT_INFO");                  if(!llMII.isEmpty()) subscribe("MIDI_INSTRUMENT_INFO");
351                    if(!llID.isEmpty()) {
352                            subscribe("DB_INSTRUMENT_DIRECTORY_COUNT");
353                            subscribe("DB_INSTRUMENT_DIRECTORY_INFO");
354                            subscribe("DB_INSTRUMENT_COUNT");
355                            subscribe("DB_INSTRUMENT_INFO");
356                    }
357                  if(!llGI.isEmpty()) subscribe("GLOBAL_INFO");                  if(!llGI.isEmpty()) subscribe("GLOBAL_INFO");
358          }          }
359                    
# Line 376  public class Client { Line 401  public class Client {
401                  String s;                  String s;
402                  for(;;) {                  for(;;) {
403                          s = in.readLine();                          s = in.readLine();
404                          if(s.startsWith("NOTIFY:")) fireEvent(s.substring("NOTIFY:".length()));                          if(s.startsWith("NOTIFY:")) {
405                                    eventThread.scheduleNotification(s.substring("NOTIFY:".length()));
406                            }
407                          else break;                          else break;
408                  }                  }
409                  return s;                  return s;
# Line 469  public class Client { Line 496  public class Client {
496          /** MIDI instrument info listeners */          /** MIDI instrument info listeners */
497          private final Vector<MidiInstrumentInfoListener> llMII =          private final Vector<MidiInstrumentInfoListener> llMII =
498                  new Vector<MidiInstrumentInfoListener>();                  new Vector<MidiInstrumentInfoListener>();
499            private final Vector<InstrumentsDbListener> llID = new Vector<InstrumentsDbListener>();
500          private final Vector<GlobalInfoListener> llGI = new Vector<GlobalInfoListener>();          private final Vector<GlobalInfoListener> llGI = new Vector<GlobalInfoListener>();
501                    
502                    
# Line 498  public class Client { Line 526  public class Client {
526                          !llMIMI.isEmpty() ||                          !llMIMI.isEmpty() ||
527                          !llMIC.isEmpty()  ||                          !llMIC.isEmpty()  ||
528                          !llMII.isEmpty()  ||                          !llMII.isEmpty()  ||
529                            !llID.isEmpty()   ||
530                          !llGI.isEmpty();                          !llGI.isEmpty();
531          }          }
532                    
533          private void          private synchronized void
534          fireEvent(String s) {          fireEvent(String s) {
535                  if(s.startsWith("CHANNEL_COUNT:")) {                   if(s.startsWith("DB_INSTRUMENT_DIRECTORY_COUNT:")) {
536                            s = s.substring("DB_INSTRUMENT_DIRECTORY_COUNT:".length());
537                            InstrumentsDbEvent e = new InstrumentsDbEvent(this, s);
538                            for(InstrumentsDbListener l : llID) l.directoryCountChanged(e);
539                    } else if(s.startsWith("DB_INSTRUMENT_DIRECTORY_INFO:")) {
540                            InstrumentsDbEvent e;
541                            s = s.substring("DB_INSTRUMENT_DIRECTORY_INFO:".length());
542                            if(s.startsWith("NAME ")) {
543                                    String[] list;
544                                    try {
545                                            list = parseStringList(s.substring("NAME ".length()), ' ');
546                                            if(list.length != 2) throw new LscpException();
547                                            e = new InstrumentsDbEvent(this, list[0], list[1]);
548                                            for(InstrumentsDbListener l : llID) {
549                                                    l.directoryNameChanged(e);
550                                            }
551                                    } catch(LscpException x) {
552                                            getLogger().log (
553                                                    Level.WARNING,
554                                                    LscpI18n.getLogMsg("CommandFailed!"),
555                                                    x
556                                            );
557                                    }
558                            } else {
559                                    e = new InstrumentsDbEvent(this, s);
560                                    for(InstrumentsDbListener l : llID) l.directoryInfoChanged(e);
561                            }
562                    } else if(s.startsWith("DB_INSTRUMENT_COUNT:")) {
563                            s = s.substring("DB_INSTRUMENT_COUNT:".length());
564                            InstrumentsDbEvent e = new InstrumentsDbEvent(this, s);
565                            for(InstrumentsDbListener l : llID) l.instrumentCountChanged(e);
566                    } else if(s.startsWith("DB_INSTRUMENT_INFO:")) {
567                            InstrumentsDbEvent e;
568                            s = s.substring("DB_INSTRUMENT_INFO:".length());
569                            if(s.startsWith("NAME ")) {
570                                    String[] list;
571                                    try {
572                                            list = parseStringList(s.substring("NAME ".length()), ' ');
573                                            if(list.length != 2) throw new LscpException();
574                                            e = new InstrumentsDbEvent(this, list[0], list[1]);
575                                            for(InstrumentsDbListener l : llID) {
576                                                    l.instrumentNameChanged(e);
577                                            }
578                                    } catch(LscpException x) {
579                                            getLogger().log (
580                                                    Level.WARNING,
581                                                    LscpI18n.getLogMsg("CommandFailed!"),
582                                                    x
583                                            );
584                                    }
585                            } else {
586                                    e = new InstrumentsDbEvent(this, s);
587                                    for(InstrumentsDbListener l : llID) l.instrumentInfoChanged(e);
588                            }
589                    } else if(s.startsWith("DB_INSTRUMENTS_JOB_INFO:")) {
590                            s = s.substring("DB_INSTRUMENTS_JOB_INFO:".length());
591                            try {
592                                    int i = Integer.parseInt(s);
593                                    InstrumentsDbEvent e = new InstrumentsDbEvent(this, i);
594                                    for(InstrumentsDbListener l : llID) l.jobStatusChanged(e);
595                            } catch(NumberFormatException x) {
596                                    s = "Unknown DB_INSTRUMENTS_JOB_INFO format";
597                                    getLogger().log(Level.WARNING, s, x);
598                            }
599                            
600                    } else if(s.startsWith("CHANNEL_COUNT:")) {
601                          try {                          try {
602                                  int i = Integer.parseInt(s.substring("CHANNEL_COUNT:".length()));                                  int i = Integer.parseInt(s.substring("CHANNEL_COUNT:".length()));
603                                  ChannelCountEvent e = new ChannelCountEvent(this, i);                                  ChannelCountEvent e = new ChannelCountEvent(this, i);
# Line 1145  public class Client { Line 1239  public class Client {
1239          /**          /**
1240           * Registers the specified listener for receiving event messages.           * Registers the specified listener for receiving event messages.
1241           * Listeners can be registered regardless of the connection state.           * Listeners can be registered regardless of the connection state.
1242             * @param l The <code>InstrumentsDbListener</code> to register.
1243             */
1244            public synchronized void
1245            addInstrumentsDbListener(InstrumentsDbListener l) {
1246                    if(llID.isEmpty()) {
1247                            subscribe("DB_INSTRUMENT_DIRECTORY_COUNT");
1248                            subscribe("DB_INSTRUMENT_DIRECTORY_INFO");
1249                            subscribe("DB_INSTRUMENT_COUNT");
1250                            subscribe("DB_INSTRUMENT_INFO");
1251                            subscribe("DB_INSTRUMENTS_JOB_INFO");
1252                    }
1253                    llID.add(l);
1254            }
1255            
1256            /**
1257             * Removes the specified listener.
1258             * Listeners can be removed regardless of the connection state.
1259             * @param l The <code>InstrumentsDbListener</code> to remove.
1260             */
1261            public synchronized void
1262            removeInstrumentsDbListener(InstrumentsDbListener l) {
1263                    boolean b = llID.remove(l);
1264                    if(b && llID.isEmpty()) {
1265                            unsubscribe("DB_INSTRUMENT_DIRECTORY_COUNT");
1266                            unsubscribe("DB_INSTRUMENT_DIRECTORY_INFO");
1267                            unsubscribe("DB_INSTRUMENT_COUNT");
1268                            unsubscribe("DB_INSTRUMENT_INFO");
1269                            unsubscribe("DB_INSTRUMENTS_JOB_INFO");
1270                    }
1271            }
1272            
1273            /**
1274             * Registers the specified listener for receiving event messages.
1275             * Listeners can be registered regardless of the connection state.
1276           * @param l The <code>GlobalInfoListener</code> to register.           * @param l The <code>GlobalInfoListener</code> to register.
1277           */           */
1278          public synchronized void          public synchronized void
# Line 2472  public class Client { Line 2600  public class Client {
2600                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
2601          }          }
2602                    
2603            
2604            
2605          /**          /**
2606           * Creates or replaces a MIDI instrument map entry.           * Creates or replaces a MIDI instrument map entry.
2607           * @param mapId The ID of the map, where this instrument should be mapped.           * @param mapId The ID of the map, where this instrument should be mapped.
# Line 2486  public class Client { Line 2616  public class Client {
2616          public synchronized void          public synchronized void
2617          mapMidiInstrument(int mapId, MidiInstrumentEntry entry, MidiInstrumentInfo info)          mapMidiInstrument(int mapId, MidiInstrumentEntry entry, MidiInstrumentInfo info)
2618                                          throws IOException, LSException, LscpException {                                          throws IOException, LSException, LscpException {
2619                    mapMidiInstrument(mapId, entry, info, false);
2620            }
2621            
2622            /**
2623             * Creates or replaces a MIDI instrument map entry.
2624             * @param mapId The ID of the map, where this instrument should be mapped.
2625             * @param entry Specifies the position of the MIDI instrument in the MIDI instrument map.
2626             * @param info Provides the needed information of the
2627             * MIDI instrument, which will be mapped to the specified MIDI instrument map.
2628             * @param nonModal If <code>true</code> the function returns immediately
2629             * and the mapping is established in the background.
2630             * @throws IOException If some I/O error occurs.
2631             * @throws LSException If the mapping failed.
2632             * @throws LscpException If LSCP protocol corruption occurs.
2633             * @see #unmapMidiInstrument
2634             */
2635            public synchronized void
2636            mapMidiInstrument(int mapId, MidiInstrumentEntry entry, MidiInstrumentInfo info, boolean nonModal)
2637                                            throws IOException, LSException, LscpException {
2638                                    
2639                  verifyConnection();                  verifyConnection();
2640                  StringBuffer cmd = new StringBuffer("MAP MIDI_INSTRUMENT ");                  StringBuffer cmd = new StringBuffer("MAP MIDI_INSTRUMENT ");
2641                    if(nonModal) cmd.append("NON_MODAL ");
2642                  cmd.append(mapId).append(' ');                  cmd.append(mapId).append(' ');
2643                  cmd.append(entry.getMidiBank()).append(' ');                  cmd.append(entry.getMidiBank()).append(' ');
2644                  cmd.append(entry.getMidiProgram()).append(' ');                  cmd.append(entry.getMidiProgram()).append(' ');
2645                  cmd.append(info.getEngine()).append(" '");                  cmd.append(info.getEngine()).append(" '");
2646                  cmd.append(info.getFileName()).append("' ");                  cmd.append(info.getFilePath()).append("' ");
2647                  cmd.append(info.getInstrumentIndex()).append(' ');                  cmd.append(info.getInstrumentIndex()).append(' ');
2648                  cmd.append(info.getVolume());                  cmd.append(info.getVolume());
2649                  if(!info.getLoadMode().name().equals("DEFAULT")) {                  if(!info.getLoadMode().name().equals("DEFAULT")) {
# Line 2695  public class Client { Line 2845  public class Client {
2845          loadInstrument(String filename, int instrIdx, int samplerChn, boolean nonModal)          loadInstrument(String filename, int instrIdx, int samplerChn, boolean nonModal)
2846                                                  throws IOException, LscpException, LSException {                                                  throws IOException, LscpException, LSException {
2847                                    
2848                    filename = getEscapedString(filename);
2849                  String cmd = nonModal ? "LOAD INSTRUMENT NON_MODAL " : "LOAD INSTRUMENT ";                  String cmd = nonModal ? "LOAD INSTRUMENT NON_MODAL " : "LOAD INSTRUMENT ";
2850                  String args = '\'' + filename + "' " + instrIdx + ' ' + samplerChn;                  String args = '\'' + filename + "' " + instrIdx + ' ' + samplerChn;
2851                                    
# Line 3567  public class Client { Line 3718  public class Client {
3718                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
3719          }          }
3720                    
3721            
3722            
3723            /**
3724             * Adds the specified directory to the instruments database.
3725             * @param dir The absolute path name of the directory to add.
3726             * @throws IOException If some I/O error occurs.
3727             * @throws LSException If the creation of the directory failed.
3728             * @throws LscpException If LSCP protocol corruption occurs.
3729             */
3730            public synchronized void
3731            addDbDirectory(String dir) throws IOException, LSException, LscpException {
3732                    verifyConnection();
3733                    out.writeLine("ADD DB_INSTRUMENT_DIRECTORY '" + dir + "'");
3734                    if(getPrintOnlyMode()) return;
3735                    
3736                    ResultSet rs = getEmptyResultSet();
3737            }
3738            
3739            /**
3740             * Removes the specified directory from the instruments database.
3741             * @param dir The absolute path name of the directory to remove.
3742             * @throws IOException If some I/O error occurs.
3743             * @throws LscpException If LSCP protocol corruption occurs.
3744             * @throws LSException If the specified directory is not
3745             * empty or if the removal of the directory failed.
3746             */
3747            public synchronized void
3748            removeDbDirectory(String dir) throws IOException, LscpException, LSException {
3749                    removeDbDirectory(dir, false);
3750            }
3751            
3752            /**
3753             * Removes the specified directory from the instruments database.
3754             * @param dir The absolute path name of the directory to remove.
3755             * @param force If <code>true</code> forces the removal of non-empty
3756             * directory and all its content.
3757             * @throws IOException If some I/O error occurs.
3758             * @throws LscpException If LSCP protocol corruption occurs.
3759             * @throws LSException If the removing of the directory failed.
3760             */
3761            public synchronized void
3762            removeDbDirectory(String dir, boolean force)
3763                                    throws IOException, LscpException, LSException {
3764                    
3765                    verifyConnection();
3766                    String s = "REMOVE DB_INSTRUMENT_DIRECTORY ";
3767                    if(force) s += "FORCE ";
3768                    out.writeLine(s + "'" + dir + "'");
3769                    if(getPrintOnlyMode()) return;
3770                    
3771                    ResultSet rs = getEmptyResultSet();
3772            }
3773            
3774            /**
3775             * Removes the specified directories from the instruments database.
3776             * @param dirs The absolute path names of the directories to remove.
3777             * @param force If <code>true</code> forces the removal of non-empty
3778             * directories.
3779             * @throws IOException If some I/O error occurs.
3780             * @throws LscpException If LSCP protocol corruption occurs.
3781             * @throws LSException If the removing of the directores failed.
3782             */
3783            public synchronized void
3784            removeDbDirectories(String[] dirs, boolean force)
3785                                    throws IOException, LscpException, LSException {
3786                    
3787                    verifyConnection();
3788                    String cmd = "REMOVE DB_INSTRUMENT_DIRECTORY ";
3789                    if(force) cmd += "FORCE ";
3790                    
3791                    for(String s : dirs) out.writeLine(cmd + "'" + s + "'");
3792                    
3793                    if(getPrintOnlyMode()) return;
3794                    
3795                    getEmptyResultSets(dirs.length, "Client.dirDeletionFailed!");
3796            }
3797            
3798            /**
3799             * Gets the number of directories in the specified directory.
3800             * @return The current number of directories in the specified directory.
3801             * @param dir The absolute path name of the directory.
3802             * @throws IOException If some I/O error occurs.
3803             * @throws LscpException If LSCP protocol corruption occurs.
3804             * @throws LSException If some other error occurs.
3805             */
3806            public synchronized int
3807            getDbDirectoryCount(String dir) throws IOException, LscpException, LSException {
3808                    return getDbDirectoryCount(dir, false);
3809            }
3810            
3811            /**
3812             * Gets the number of directories in the specified directory.
3813             * @return The current number of directories in the specified directory.
3814             * @param dir The absolute path name of the directory.
3815             * @param recursive If <code>true</code>, the number of all directories
3816             * in the specified subtree will be returned.
3817             * @throws IOException If some I/O error occurs.
3818             * @throws LscpException If LSCP protocol corruption occurs.
3819             * @throws LSException If some other error occurs.
3820             */
3821            public synchronized int
3822            getDbDirectoryCount(String dir, boolean recursive)
3823                                    throws IOException, LscpException, LSException {
3824                    
3825                    verifyConnection();
3826                    String s;
3827                    if(recursive) s = "GET DB_INSTRUMENT_DIRECTORIES RECURSIVE '";
3828                    else s = "GET DB_INSTRUMENT_DIRECTORIES '";
3829                    out.writeLine(s + dir + "'");
3830                    if(getPrintOnlyMode()) return -1;
3831                    
3832                    s = getSingleLineResultSet().getResult();
3833                    return parseInt(s);
3834            }
3835            
3836            /**
3837             * Gets the list of directories in the specified directory.
3838             * @param dir The absolute path name of the directory.
3839             * @return A <code>String</code> array providing the names of
3840             * all directories in the specified directory.
3841             * @throws IOException If some I/O error occurs.
3842             * @throws LscpException If LSCP protocol corruption occurs.
3843             * @throws LSException If the specified path name is invalid.
3844             */
3845            public synchronized String[]
3846            getDbDirectoryNames(String dir) throws IOException, LscpException, LSException {
3847                    verifyConnection();
3848                    out.writeLine("LIST DB_INSTRUMENT_DIRECTORIES '" + dir + "'");
3849                    if(getPrintOnlyMode()) return null;
3850                    
3851                    return parseStringList(getSingleLineResultSet().getResult());
3852            }
3853            
3854            /**
3855             * Gets information about the specified directory.
3856             * @param dir The absolute path name of the directory.
3857             * @return A <code>DbDirectoryInfo</code> instance providing information
3858             * about the specified directory.
3859             * @throws IOException If some I/O error occurs.
3860             * @throws LscpException If LSCP protocol corruption occurs.
3861             * @throws LSException If the specified directory is not found.
3862             */
3863            public synchronized DbDirectoryInfo
3864            getDbDirectoryInfo(String dir) throws IOException, LscpException, LSException {
3865                    verifyConnection();
3866                    out.writeLine("GET DB_INSTRUMENT_DIRECTORY INFO '" + dir + "'");
3867                    if(getPrintOnlyMode()) return null;
3868                    
3869                    ResultSet rs = getMultiLineResultSet();
3870                    DbDirectoryInfo info = new DbDirectoryInfo(rs.getMultiLineResult());
3871                    if(dir.equals("/")) {
3872                            info.setName("/");
3873                    } else if(dir.length() > 1 && dir.charAt(dir.length() - 1) == '/') {
3874                            dir = dir.substring(0, dir.length() - 1);
3875                    }
3876                    int i = dir.lastIndexOf('/');
3877                    if(i != -1 && i < dir.length() - 1) {
3878                            info.setName(dir.substring(i + 1));
3879                            if(i == 0) info.setParentDirectoryPath("/");
3880                            else info.setParentDirectoryPath(dir.substring(0, i));
3881                    }
3882                    
3883                    return info;
3884            }
3885            
3886            /**
3887             * Gets the list of directories in the specified directory.
3888             * @param dir The absolute path name of the directory.
3889             * @return A <code>DbDirectoryInfo</code> array providing
3890             * information about all directories in the specified directory.
3891             * @throws IOException If some I/O error occurs.
3892             * @throws LscpException If LSCP protocol corruption occurs.
3893             * @throws LSException If the specified path name is invalid.
3894             */
3895            public synchronized DbDirectoryInfo[]
3896            getDbDirectories(String dir) throws IOException, LscpException, LSException {
3897                    String[] dirS = getDbDirectoryNames(dir);
3898                    if(dir.charAt(dir.length() - 1) != '/') dir += "/";
3899                    DbDirectoryInfo[] infoS = new DbDirectoryInfo[dirS.length];
3900                    for(int i = 0; i < dirS.length; i++) infoS[i] = getDbDirectoryInfo(dir + dirS[i]);
3901                    return infoS;
3902            }
3903            
3904            /**
3905             * Gets the list of directories in the specified directory.
3906             * @param dir The absolute path name of the directory.
3907             * @return A <code>DbDirectoryInfo</code> array providing
3908             * information about all directories in the specified directory.
3909             * @throws IOException If some I/O error occurs.
3910             * @throws LscpException If LSCP protocol corruption occurs.
3911             * @throws LSException If the specified path name is invalid.
3912             *
3913            public synchronized DbDirectoryInfo[]
3914            getDbDirectories(String dir) throws IOException, LscpException, LSException {
3915                    String[] dirS = getDbDirectoryNames(dir);
3916                    if(dirS.length == 0) return new DbDirectoryInfo[0];
3917                    
3918                    if(dir.charAt(dir.length() - 1) != '/') dir += "/";
3919                    
3920                    for(int i = 0; i < dirS.length; i++) {
3921                            out.writeLine("GET DB_INSTRUMENT_DIRECTORY INFO '" + dir + dirS[i] + "'");
3922                    }
3923                    
3924                    if(getPrintOnlyMode()) return null;
3925                    
3926                    if(dir.length() > 1) dir = dir.substring(0, dir.length() - 1);
3927                    StringBuffer sb = new StringBuffer();
3928                    DbDirectoryInfo[] infoS = new DbDirectoryInfo[dirS.length];
3929                    for(int i = 0; i < dirS.length; i++) {
3930                            try {
3931                                    ResultSet rs = getMultiLineResultSet();
3932                                    infoS[i] = new DbDirectoryInfo(rs.getMultiLineResult());
3933                                    infoS[i].setName(dirS[i]);
3934                                    infoS[i].setParentDirectoryPath(dir);
3935                            } catch (SocketTimeoutException e) {
3936                                    getLogger().log(Level.FINE, e.getMessage(), e);
3937                                    sb.append(e.getMessage()).append("\n");
3938                                    break;
3939                            } catch (Exception e) {
3940                                    getLogger().log(Level.FINE, e.getMessage(), e);
3941                                    sb.append(e.getMessage()).append("\n");
3942                            }
3943                    }
3944                    
3945                    String details = sb.toString();
3946                    if(details.length() > 0) {
3947                            String err = LscpI18n.getLogMsg("Client.getInstrsInfoFailed!");
3948                            throw new LSException(0, err, details);
3949                    }
3950                    
3951                    return infoS;
3952            }*/
3953            
3954            /**
3955             * Renames the specified directory.
3956             * @param dir The absolute path name of the directory to rename.
3957             * @param name The new name for the directory.
3958             * @throws IOException If some I/O error occurs.
3959             * @throws LSException If the renaming of the directory failed.
3960             * @throws LscpException If LSCP protocol corruption occurs.
3961             */
3962            public synchronized void
3963            renameDbDirectory(String dir, String name) throws IOException, LSException, LscpException {
3964                    verifyConnection();
3965                    out.writeLine("SET DB_INSTRUMENT_DIRECTORY NAME '" + dir + "' '" + name + "'");
3966                    if(getPrintOnlyMode()) return;
3967                    
3968                    ResultSet rs = getEmptyResultSet();
3969            }
3970            
3971            /**
3972             * Moves the specified directory into the specified location.
3973             * @param dir The absolute path name of the directory to move.
3974             * @param dst The location where the directory will be moved to.
3975             * @throws IOException If some I/O error occurs.
3976             * @throws LSException If the operation failed.
3977             * @throws LscpException If LSCP protocol corruption occurs.
3978             */
3979            public synchronized void
3980            moveDbDirectory(String dir, String dst) throws IOException, LSException, LscpException {
3981                    verifyConnection();
3982                    out.writeLine("MOVE DB_INSTRUMENT_DIRECTORY '" + dir + "' '" + dst + "'");
3983                    if(getPrintOnlyMode()) return;
3984                    
3985                    ResultSet rs = getEmptyResultSet();
3986            }
3987            
3988            /**
3989             * Moves the specified directories into the specified location.
3990             * @param dirs The absolute path names of the directories to move.
3991             * @param dst The location where the directories will be moved to.
3992             * @throws IOException If some I/O error occurs.
3993             * @throws LSException If the operation failed.
3994             * @throws LscpException If LSCP protocol corruption occurs.
3995             */
3996            public synchronized void
3997            moveDbDirectories(String dirs[], String dst) throws IOException, LSException, LscpException {
3998                    verifyConnection();
3999                    for(String s : dirs) {
4000                            out.writeLine("MOVE DB_INSTRUMENT_DIRECTORY '" + s + "' '" + dst + "'");
4001                    }
4002                    if(getPrintOnlyMode()) return;
4003                    
4004                    getEmptyResultSets(dirs.length, "Client.dirMovingFailed!");
4005            }
4006            
4007            /**
4008             * Copies the specified directory into the specified location.
4009             * @param dir The absolute path name of the directory to copy.
4010             * @param dst The location where the directory will be copied to.
4011             * @throws IOException If some I/O error occurs.
4012             * @throws LSException If the operation failed.
4013             * @throws LscpException If LSCP protocol corruption occurs.
4014             */
4015            public synchronized void
4016            copyDbDirectory(String dir, String dst) throws IOException, LSException, LscpException {
4017                    verifyConnection();
4018                    out.writeLine("COPY DB_INSTRUMENT_DIRECTORY '" + dir + "' '" + dst + "'");
4019                    if(getPrintOnlyMode()) return;
4020                    
4021                    ResultSet rs = getEmptyResultSet();
4022            }
4023            
4024            /**
4025             * Copies the specified directories into the specified location.
4026             * @param dirs The absolute path names of the directories to copy.
4027             * @param dst The location where the directories will be copied to.
4028             * @throws IOException If some I/O error occurs.
4029             * @throws LSException If the operation failed.
4030             * @throws LscpException If LSCP protocol corruption occurs.
4031             */
4032            public synchronized void
4033            copyDbDirectories(String[] dirs, String dst) throws IOException, LSException, LscpException {
4034                    verifyConnection();
4035                    for(String s : dirs) {
4036                            out.writeLine("COPY DB_INSTRUMENT_DIRECTORY '" + s + "' '" + dst + "'");
4037                    }
4038                    if(getPrintOnlyMode()) return;
4039                    
4040                    getEmptyResultSets(dirs.length, "Client.dirCopyingFailed!");
4041            }
4042            
4043            /**
4044             * Changes the description of the specified directory.
4045             * @param dir The absolute path name of the directory.
4046             * @param desc The new description for the directory.
4047             * @throws IOException If some I/O error occurs.
4048             * @throws LSException If failed to change the description.
4049             * @throws LscpException If LSCP protocol corruption occurs.
4050             */
4051            public synchronized void
4052            setDbDirectoryDescription(String dir, String desc)
4053                                    throws IOException, LSException, LscpException {
4054                    
4055                    verifyConnection();
4056                    String s = "SET DB_INSTRUMENT_DIRECTORY DESCRIPTION '";
4057                    out.writeLine(s + dir + "' '" + desc + "'");
4058                    if(getPrintOnlyMode()) return;
4059                    
4060                    ResultSet rs = getEmptyResultSet();
4061            }
4062            
4063            public static enum ScanMode {
4064                    RECURSIVE, NON_RECURSIVE, FLAT
4065            }
4066            
4067            /**
4068             * Adds the specified instrument to the specified instruments database directory.
4069             * @param dbDir The absolute path name of the database directory in which the
4070             * specified instrument will be added.
4071             * @param filePath The absolute path name of the instrument file.
4072             * @param instrIndex The index of the instrument (in the given instrument file) to add.
4073             * @throws IOException If some I/O error occurs.
4074             * @throws LSException If the operation failed.
4075             * @throws LscpException If LSCP protocol corruption occurs.
4076             */
4077            public synchronized void
4078            addDbInstrument(String dbDir, String filePath, int instrIndex)
4079                                            throws IOException, LSException, LscpException {
4080                    
4081                    addDbInstrument(dbDir, filePath, instrIndex, false);
4082            }
4083            
4084            /**
4085             * Adds the specified instrument to the specified instruments database directory.
4086             * @param dbDir The absolute path name of the database directory in which the
4087             * specified instrument will be added.
4088             * @param filePath The absolute path name of the instrument file.
4089             * @param instrIndex The index of the instrument (in the given instrument file) to add.
4090             * @param background If <code>true</code>, the scan will be done
4091             * in background and this method may return before the job is finished.
4092             * @return If <code>background</code> is <code>true</code>, the ID
4093             * of the scan job.
4094             * @throws IOException If some I/O error occurs.
4095             * @throws LSException If the operation failed.
4096             * @throws LscpException If LSCP protocol corruption occurs.
4097             * @see #addInstrumentsDbListener
4098             */
4099            public synchronized int
4100            addDbInstrument(String dbDir, String filePath, int instrIndex, boolean background)
4101                                            throws IOException, LSException, LscpException {
4102                    
4103                    verifyConnection();
4104                    String s = "ADD DB_INSTRUMENTS";
4105                    if(background) s += " NON_MODAL";
4106                    s += " '" + dbDir + "' '" + filePath + "' ";
4107                    out.writeLine(s + String.valueOf(instrIndex));
4108                    if(getPrintOnlyMode()) return -1;
4109                    
4110                    ResultSet rs = getEmptyResultSet();
4111                    return rs.getIndex();
4112            }
4113            
4114            /**
4115             * Adds the instruments in the specified file to the specified
4116             * instruments database directory.
4117             * @param dbDir The absolute path name of the database directory
4118             * in which the the supported instruments will be added.
4119             * @param filePath The absolute path name of the file to scan for instruments.
4120             * @throws IOException If some I/O error occurs.
4121             * @throws LSException If the operation failed.
4122             * @throws LscpException If LSCP protocol corruption occurs.
4123             */
4124            public synchronized void
4125            addDbInstruments(String dbDir, String filePath)
4126                                            throws IOException, LSException, LscpException {
4127                    
4128                    addDbInstruments(dbDir, filePath, false);
4129            }
4130            
4131            /**
4132             * Adds the instruments in the specified file to the specified
4133             * instruments database directory.
4134             * @param dbDir The absolute path name of the database directory
4135             * in which the the supported instruments will be added.
4136             * @param filePath The absolute path name of the file to scan for instruments.
4137             * @param background If <code>true</code>, the scan will be done
4138             * in background and this method may return before the job is finished.
4139             * @return If <code>background</code> is <code>true</code>, the ID
4140             * of the scan job.
4141             * @throws IOException If some I/O error occurs.
4142             * @throws LSException If the operation failed.
4143             * @throws LscpException If LSCP protocol corruption occurs.
4144             * @see #addInstrumentsDbListener
4145             */
4146            public synchronized int
4147            addDbInstruments(String dbDir, String filePath, boolean background)
4148                                            throws IOException, LSException, LscpException {
4149                    
4150                    verifyConnection();
4151                    String s = "ADD DB_INSTRUMENTS";
4152                    if(background) s += " NON_MODAL";
4153                    out.writeLine(s + " '" + dbDir + "' '" + filePath + "'");
4154                    if(getPrintOnlyMode()) return -1;
4155                    
4156                    ResultSet rs = getEmptyResultSet();
4157                    return rs.getIndex();
4158            }
4159            
4160            /**
4161             * Adds the instruments in the specified file system directory
4162             * to the specified instruments database directory.
4163             * @param mode Determines the scanning mode. If RECURSIVE is
4164             * specified, all supported instruments in the specified file system
4165             * direcotry will be added to the specified instruments database
4166             * directory, including the instruments in subdirectories
4167             * of the supplied directory. If NON_RECURSIVE is specified,
4168             * the instruments in the subdirectories will not be processed.
4169             * If FLAT is specified, all supported instruments in the specified
4170             * file system direcotry will be added, including the instruments in
4171             * subdirectories of the supplied directory, but the respective
4172             * subdirectory structure will not be recreated in the instruments
4173             * database and all instruments will be added directly in the
4174             * specified database directory.
4175             * @param dbDir The absolute path name of the database directory
4176             * in which the supported instruments will be added.
4177             * @param fsDir The absolute path name of the file system directory.
4178             * @throws IOException If some I/O error occurs.
4179             * @throws LSException If the operation failed.
4180             * @throws LscpException If LSCP protocol corruption occurs.
4181             */
4182            public synchronized void
4183            addDbInstruments(ScanMode mode, String dbDir, String fsDir)
4184                                            throws IOException, LSException, LscpException {
4185                    
4186                    addDbInstruments(mode, dbDir, fsDir, false);
4187            }
4188            
4189            /**
4190             * Adds the instruments in the specified file system directory
4191             * to the specified instruments database directory.
4192             * @param mode Determines the scanning mode. If RECURSIVE is
4193             * specified, all supported instruments in the specified file system
4194             * direcotry will be added to the specified instruments database
4195             * directory, including the instruments in subdirectories
4196             * of the supplied directory. If NON_RECURSIVE is specified,
4197             * the instruments in the subdirectories will not be processed.
4198             * If FLAT is specified, all supported instruments in the specified
4199             * file system direcotry will be added, including the instruments in
4200             * subdirectories of the supplied directory, but the respective
4201             * subdirectory structure will not be recreated in the instruments
4202             * database and all instruments will be added directly in the
4203             * specified database directory.
4204             * @param dbDir The absolute path name of the database directory
4205             * in which the supported instruments will be added.
4206             * @param fsDir The absolute path name of the file system directory.
4207             * @param background If <code>true</code>, the scan will be done
4208             * in background and this method may return before the job is finished.
4209             * @return If <code>background</code> is <code>true</code>, the ID
4210             * of the scan job.
4211             * @throws IOException If some I/O error occurs.
4212             * @throws LSException If the operation failed.
4213             * @throws LscpException If LSCP protocol corruption occurs.
4214             * @see #addInstrumentsDbListener
4215             */
4216            public synchronized int
4217            addDbInstruments(ScanMode mode, String dbDir, String fsDir, boolean background)
4218                                            throws IOException, LSException, LscpException {
4219                    
4220                    verifyConnection();
4221                    StringBuffer sb = new StringBuffer("ADD DB_INSTRUMENTS");
4222                    if(background) sb.append(" NON_MODAL");
4223                    
4224                    switch(mode) {
4225                            case RECURSIVE:
4226                                    sb.append(" RECURSIVE");
4227                                    break;
4228                            case NON_RECURSIVE:
4229                                    sb.append(" NON_RECURSIVE");
4230                                    break;
4231                            case FLAT:
4232                                    sb.append(" FLAT");
4233                                    break;
4234                    }
4235                    
4236                    sb.append(" '").append(dbDir).append("' '").append(fsDir).append("'");
4237                    out.writeLine(sb.toString());
4238                    if(getPrintOnlyMode()) return -1;
4239                    
4240                    ResultSet rs = getEmptyResultSet();
4241                    return rs.getIndex();
4242            }
4243            
4244            /**
4245             * Removes the specified instrument from the instruments database.
4246             * @param instr The absolute path name of the instrument to remove.
4247             * @throws IOException If some I/O error occurs.
4248             * @throws LscpException If LSCP protocol corruption occurs.
4249             * @throws LSException If the removing of the instrument failed.
4250             */
4251            public synchronized void
4252            removeDbInstrument(String instr) throws IOException, LscpException, LSException {
4253                    
4254                    verifyConnection();
4255                    out.writeLine("REMOVE DB_INSTRUMENT '" + instr + "'");
4256                    if(getPrintOnlyMode()) return;
4257                    
4258                    ResultSet rs = getEmptyResultSet();
4259            }
4260            
4261            /**
4262             * Removes the specified instruments from the instruments database.
4263             * @param instrs The absolute path names of the instruments to remove.
4264             * @throws IOException If some I/O error occurs.
4265             * @throws LscpException If LSCP protocol corruption occurs.
4266             * @throws LSException If the removing of the instruments failed.
4267             */
4268            public synchronized void
4269            removeDbInstruments(String[] instrs) throws IOException, LscpException, LSException {
4270                    verifyConnection();
4271                    for(String s : instrs) {
4272                            out.writeLine("REMOVE DB_INSTRUMENT '" + s + "'");
4273                    }
4274                    if(getPrintOnlyMode()) return;
4275                    
4276                    getEmptyResultSets(instrs.length, "Client.instrDeletionFailed!");
4277            }
4278            
4279            /**
4280             * Gets the number of instruments in the specified directory.
4281             * @return The current number of instruments in the specified directory.
4282             * @param dir The absolute path name of the directory.
4283             * @throws IOException If some I/O error occurs.
4284             * @throws LscpException If LSCP protocol corruption occurs.
4285             * @throws LSException If some other error occurs.
4286             */
4287            public synchronized int
4288            getDbInstrumentCount(String dir) throws IOException, LscpException, LSException {
4289                    return getDbInstrumentCount(dir, false);
4290            }
4291            
4292            /**
4293             * Gets the number of instruments in the specified directory.
4294             * @return The current number of instruments in the specified directory.
4295             * @param dir The absolute path name of the directory.
4296             * @param recursive If <code>true</code>, the number of all instruments
4297             * in the specified subtree will be returned.
4298             * @throws IOException If some I/O error occurs.
4299             * @throws LscpException If LSCP protocol corruption occurs.
4300             * @throws LSException If some other error occurs.
4301             */
4302            public synchronized int
4303            getDbInstrumentCount(String dir, boolean recursive)
4304                                    throws IOException, LscpException, LSException {
4305                    
4306                    verifyConnection();
4307                    String s;
4308                    if(recursive) s = "GET DB_INSTRUMENTS RECURSIVE '";
4309                    else s = "GET DB_INSTRUMENTS '";
4310                    out.writeLine(s + dir + "'");
4311                    if(getPrintOnlyMode()) return -1;
4312                    
4313                    s = getSingleLineResultSet().getResult();
4314                    return parseInt(s);
4315            }
4316            
4317            /**
4318             * Gets the list of instruments in the specified directory.
4319             * @param dir The absolute path name of the directory.
4320             * @return A <code>String</code> array providing the names of
4321             * all instruments in the specified directory.
4322             * @throws IOException If some I/O error occurs.
4323             * @throws LscpException If LSCP protocol corruption occurs.
4324             * @throws LSException If the specified path name is invalid.
4325             */
4326            public synchronized String[]
4327            getDbInstrumentNames(String dir) throws IOException, LscpException, LSException {
4328                    verifyConnection();
4329                    out.writeLine("LIST DB_INSTRUMENTS '" + dir + "'");
4330                    if(getPrintOnlyMode()) return null;
4331                    
4332                    return parseStringList(getSingleLineResultSet().getResult());
4333            }
4334            
4335            /**
4336             * Gets information about the specified instrument.
4337             * @param instr The absolute path name of the instrument.
4338             * @return A <code>DbInstrumentInfo</code> instance providing information
4339             * about the specified instrument.
4340             * @throws IOException If some I/O error occurs.
4341             * @throws LscpException If LSCP protocol corruption occurs.
4342             * @throws LSException If the specified instrument is not found.
4343             */
4344            public synchronized DbInstrumentInfo
4345            getDbInstrumentInfo(String instr) throws IOException, LscpException, LSException {
4346                    verifyConnection();
4347                    out.writeLine("GET DB_INSTRUMENT INFO '" + instr + "'");
4348                    if(getPrintOnlyMode()) return null;
4349                    
4350                    ResultSet rs = getMultiLineResultSet();
4351                    DbInstrumentInfo info = new DbInstrumentInfo(rs.getMultiLineResult());
4352                    int i = instr.lastIndexOf('/');
4353                    if(i != -1 && i < instr.length() - 1) {
4354                            info.setName(instr.substring(i + 1));
4355                            if(i == 0) info.setDirectoryPath("/");
4356                            else info.setDirectoryPath(instr.substring(0, i));
4357                    }
4358                    
4359                    return info;
4360            }
4361            
4362            /**
4363             * Gets the list of instruments in the specified directory.
4364             * @param dir The absolute path name of the directory.
4365             * @return A <code>DbInstrumentInfo</code> array providing
4366             * information about all instruments in the specified directory.
4367             * @throws IOException If some I/O error occurs.
4368             * @throws LscpException If LSCP protocol corruption occurs.
4369             * @throws LSException If the specified path name is invalid.
4370             */
4371            public synchronized DbInstrumentInfo[]
4372            getDbInstruments(String dir) throws IOException, LscpException, LSException {
4373                    String[] instrS = getDbInstrumentNames(dir);
4374                    if(dir.charAt(dir.length() - 1) != '/') dir += "/";
4375                    
4376                    DbInstrumentInfo[] infoS = new DbInstrumentInfo[instrS.length];
4377                    for(int i = 0; i < instrS.length; i++) {
4378                            infoS[i] = getDbInstrumentInfo(dir + instrS[i]);
4379                    }
4380                    return infoS;
4381            }
4382            
4383            /**
4384             * Gets the list of instruments in the specified directory.
4385             * @param dir The absolute path name of the directory.
4386             * @return A <code>DbInstrumentInfo</code> array providing
4387             * information about all instruments in the specified directory.
4388             * @throws IOException If some I/O error occurs.
4389             * @throws LscpException If LSCP protocol corruption occurs.
4390             * @throws LSException If the specified path name is invalid.
4391             *
4392            public synchronized DbInstrumentInfo[]
4393            getDbInstruments(String dir) throws IOException, LscpException, LSException {
4394                    String[] instrS = getDbInstrumentNames(dir);
4395                    if(instrS.length == 0) return new DbInstrumentInfo[0];
4396                    
4397                    if(dir.charAt(dir.length() - 1) != '/') dir += "/";
4398                    
4399                    for(int i = 0; i < instrS.length; i++) {
4400                            out.writeLine("GET DB_INSTRUMENT INFO '" + dir + instrS[i] + "'");
4401                    }
4402                    
4403                    if(getPrintOnlyMode()) return null;
4404                    
4405                    if(dir.length() > 1) dir = dir.substring(0, dir.length() - 1);
4406                    StringBuffer sb = new StringBuffer();
4407                    DbInstrumentInfo[] infoS = new DbInstrumentInfo[instrS.length];
4408                    for(int i = 0; i < instrS.length; i++) {
4409                            try {
4410                                    ResultSet rs = getMultiLineResultSet();
4411                                    infoS[i] = new DbInstrumentInfo(rs.getMultiLineResult());
4412                                    infoS[i].setName(instrS[i]);
4413                                    infoS[i].setDirectoryPath(dir);
4414                            } catch (SocketTimeoutException e) {
4415                                    getLogger().log(Level.FINE, e.getMessage(), e);
4416                                    sb.append(e.getMessage()).append("\n");
4417                                    break;
4418                            } catch (Exception e) {
4419                                    getLogger().log(Level.FINE, e.getMessage(), e);
4420                                    sb.append(e.getMessage()).append("\n");
4421                            }
4422                    }
4423                    
4424                    String details = sb.toString();
4425                    if(details.length() > 0) {
4426                            String err = LscpI18n.getLogMsg("Client.getInstrsInfoFailed!");
4427                            throw new LSException(0, err, details);
4428                    }
4429                    
4430                    return infoS;
4431            }*/
4432            
4433            /**
4434             * Renames the specified instrument.
4435             * @param instr The absolute path name of the instrument to rename.
4436             * @param name The new name for the instrument.
4437             * @throws IOException If some I/O error occurs.
4438             * @throws LSException If the renaming of the instrument failed.
4439             * @throws LscpException If LSCP protocol corruption occurs.
4440             */
4441            public synchronized void
4442            renameDbInstrument(String instr, String name)
4443                                    throws IOException, LSException, LscpException {
4444                    
4445                    verifyConnection();
4446                    out.writeLine("SET DB_INSTRUMENT NAME '" + instr + "' '" + name + "'");
4447                    if(getPrintOnlyMode()) return;
4448                    
4449                    ResultSet rs = getEmptyResultSet();
4450            }
4451            
4452            /**
4453             * Moves the specified instrument into the specified location.
4454             * @param instr The absolute path name of the instrument to move.
4455             * @param dst The directory where the specified instrument will be moved to.
4456             * @throws IOException If some I/O error occurs.
4457             * @throws LSException If the operation failed.
4458             * @throws LscpException If LSCP protocol corruption occurs.
4459             */
4460            public synchronized void
4461            moveDbInstrument(String instr, String dst) throws IOException, LSException, LscpException {
4462                    verifyConnection();
4463                    out.writeLine("MOVE DB_INSTRUMENT '" + instr + "' '" + dst + "'");
4464                    if(getPrintOnlyMode()) return;
4465                    
4466                    ResultSet rs = getEmptyResultSet();
4467            }
4468            
4469            /**
4470             * Moves the specified instruments into the specified location.
4471             * @param instrs The absolute path names of the instruments to move.
4472             * @param dst The directory where the specified instruments will be moved to.
4473             * @throws IOException If some I/O error occurs.
4474             * @throws LSException If the operation failed.
4475             * @throws LscpException If LSCP protocol corruption occurs.
4476             */
4477            public synchronized void
4478            moveDbInstruments(String[] instrs, String dst) throws IOException, LSException, LscpException {
4479                    verifyConnection();
4480                    for(String s : instrs) {
4481                            out.writeLine("MOVE DB_INSTRUMENT '" + s + "' '" + dst + "'");
4482                    }
4483                    if(getPrintOnlyMode()) return;
4484                    
4485                    getEmptyResultSets(instrs.length, "Client.instrMovingFailed!");
4486            }
4487            
4488            /**
4489             * Copies the specified instrument into the specified location.
4490             * @param instr The absolute path name of the instrument to copy.
4491             * @param dst The directory where the specified instrument will be copied to.
4492             * @throws IOException If some I/O error occurs.
4493             * @throws LSException If the operation failed.
4494             * @throws LscpException If LSCP protocol corruption occurs.
4495             */
4496            public synchronized void
4497            copyDbInstrument(String instr, String dst) throws IOException, LSException, LscpException {
4498                    verifyConnection();
4499                    out.writeLine("COPY DB_INSTRUMENT '" + instr + "' '" + dst + "'");
4500                    if(getPrintOnlyMode()) return;
4501                    
4502                    ResultSet rs = getEmptyResultSet();
4503            }
4504            
4505            /**
4506             * Copies the specified instruments into the specified location.
4507             * @param instrs The absolute path name of the instruments to copy.
4508             * @param dst The directory where the specified instruments will be copied to.
4509             * @throws IOException If some I/O error occurs.
4510             * @throws LSException If the operation failed.
4511             * @throws LscpException If LSCP protocol corruption occurs.
4512             */
4513            public synchronized void
4514            copyDbInstruments(String[] instrs, String dst) throws IOException, LSException, LscpException {
4515                    verifyConnection();
4516                    for(String s : instrs) {
4517                            out.writeLine("COPY DB_INSTRUMENT '" + s + "' '" + dst + "'");
4518                    }
4519                    if(getPrintOnlyMode()) return;
4520                    
4521                    getEmptyResultSets(instrs.length, "Client.instrCopyingFailed!");
4522            }
4523            
4524            /**
4525             * Changes the description of the specified instrument.
4526             * @param instr The absolute path name of the instrument.
4527             * @param desc The new description for the instrument.
4528             * @throws IOException If some I/O error occurs.
4529             * @throws LSException If failed to change the description.
4530             * @throws LscpException If LSCP protocol corruption occurs.
4531             */
4532            public synchronized void
4533            setDbInstrumentDescription(String instr, String desc)
4534                                    throws IOException, LSException, LscpException {
4535                    
4536                    verifyConnection();
4537                    out.writeLine("SET DB_INSTRUMENT DESCRIPTION '" + instr + "' '" + desc + "'");
4538                    if(getPrintOnlyMode()) return;
4539                    
4540                    ResultSet rs = getEmptyResultSet();
4541            }
4542            
4543            /**
4544             * Finds all directories in the specified directory
4545             * that corresponds to the specified search criterias.
4546             * @param dir The absolute path name of the directory to search.
4547             * @param query Provides the search criterias.
4548             * @return A <code>DbDirectoryInfo</code> array providing
4549             * information about all directories that are found in the specified directory.
4550             * @throws IOException If some I/O error occurs.
4551             * @throws LscpException If LSCP protocol corruption occurs.
4552             * @throws LSException If the specified path name is invalid.
4553             */
4554            public synchronized DbDirectoryInfo[]
4555            findDbDirectories(String dir, DbSearchQuery query)
4556                                    throws IOException, LscpException, LSException {
4557                    
4558                    return findDbDirectories(dir, query, false);
4559            }
4560            
4561            /**
4562             * Finds all directories in the specified directory
4563             * that corresponds to the specified search criterias.
4564             * @param dir The absolute path name of the directory to search.
4565             * @param query Provides the search criterias.
4566             * @param nonRecursive If <code>true</code>, the search will be non-recursive.
4567             * @return A <code>DbDirectoryInfo</code> array providing
4568             * information about all directories that are found in the specified directory.
4569             * @throws IOException If some I/O error occurs.
4570             * @throws LscpException If LSCP protocol corruption occurs.
4571             * @throws LSException If the specified path name is invalid.
4572             */
4573            public synchronized DbDirectoryInfo[]
4574            findDbDirectories(String dir, DbSearchQuery query, boolean nonRecursive)
4575                                    throws IOException, LscpException, LSException {
4576                    
4577                    verifyConnection();
4578                    StringBuffer sb = new StringBuffer();
4579                    sb.append("FIND DB_INSTRUMENT_DIRECTORIES");
4580                    if(nonRecursive) sb.append(" NON_RECURSIVE");
4581                    sb.append(" '").append(dir).append("'");
4582                    
4583                    if(query.name != null && query.name.length() > 0) {
4584                            sb.append(" NAME='").append(query.name).append("'");
4585                    }
4586                    
4587                    String s = query.getCreatedAfter();
4588                    String s2 = query.getCreatedBefore();
4589                    if(s != null || s2 != null) {
4590                            sb.append(" CREATED='");
4591                            if(s != null) sb.append(s);
4592                            sb.append("..");
4593                            if(s2 != null) sb.append(s2);
4594                            sb.append("'");
4595                    }
4596                    
4597                    s = query.getModifiedAfter();
4598                    s2 = query.getModifiedBefore();
4599                    if(s != null || s2 != null) {
4600                            sb.append(" MODIFIED='");
4601                            if(s != null) sb.append(s);
4602                            sb.append("..");
4603                            if(s2 != null) sb.append(s2);
4604                            sb.append("'");
4605                    }
4606                    
4607                    if(query.description != null && query.description.length() > 0) {
4608                            sb.append(" DESCRIPTION='").append(query.description).append("'");
4609                    }
4610                    
4611                    out.writeLine(sb.toString());
4612                    if(getPrintOnlyMode()) return null;
4613                    
4614                    String[] dirS = parseStringList(getSingleLineResultSet().getResult());
4615                    
4616                    DbDirectoryInfo[] infoS = new DbDirectoryInfo[dirS.length];
4617                    for(int i = 0; i < dirS.length; i++) {
4618                            infoS[i] = getDbDirectoryInfo(dirS[i]);
4619                    }
4620                    return infoS;
4621            }
4622            
4623            /**
4624             * Finds all instruments in the specified directory
4625             * that corresponds to the specified search criterias.
4626             * @param dir The absolute path name of the directory to search.
4627             * @param query Provides the search criterias.
4628             * @return A <code>DbInstrumentInfo</code> array providing
4629             * information about all instruments that are found in the specified directory.
4630             * @throws IOException If some I/O error occurs.
4631             * @throws LscpException If LSCP protocol corruption occurs.
4632             * @throws LSException If the specified path name is invalid.
4633             */
4634            public synchronized DbInstrumentInfo[]
4635            findDbInstruments(String dir, DbSearchQuery query)
4636                                    throws IOException, LscpException, LSException {
4637                    
4638                    return findDbInstruments(dir, query, false);
4639            }
4640            
4641            /**
4642             * Finds all instruments in the specified directory
4643             * that corresponds to the specified search criterias.
4644             * @param dir The absolute path name of the directory to search.
4645             * @param query Provides the search criterias.
4646             * @param nonRecursive If <code>true</code>, the search will be non-recursive.
4647             * @return A <code>DbInstrumentInfo</code> array providing
4648             * information about all instruments that are found in the specified directory.
4649             * @throws IOException If some I/O error occurs.
4650             * @throws LscpException If LSCP protocol corruption occurs.
4651             * @throws LSException If the specified path name is invalid.
4652             */
4653            public synchronized DbInstrumentInfo[]
4654            findDbInstruments(String dir, DbSearchQuery query, boolean nonRecursive)
4655                                    throws IOException, LscpException, LSException {
4656                    
4657                    verifyConnection();
4658                    StringBuffer sb = new StringBuffer();
4659                    sb.append("FIND DB_INSTRUMENTS");
4660                    if(nonRecursive) sb.append(" NON_RECURSIVE");
4661                    sb.append(" '").append(dir).append("'");
4662                    
4663                    if(query.name != null && query.name.length() > 0) {
4664                            sb.append(" NAME='").append(query.name).append("'");
4665                    }
4666                    
4667                    if(query.formatFamilies.size() > 0) {
4668                            sb.append(" FORMAT_FAMILIES='").append(query.formatFamilies.get(0));
4669                            for(int i = 1; i < query.formatFamilies.size(); i++) {
4670                                    sb.append(',').append(query.formatFamilies.get(i));
4671                            }
4672                            sb.append("'");
4673                    }
4674                    
4675                    if(query.minSize != -1 || query.maxSize != -1) {
4676                            sb.append(" SIZE='");
4677                            if(query.minSize != -1) sb.append(query.minSize);
4678                            sb.append("..");
4679                            if(query.maxSize != -1) sb.append(query.maxSize);
4680                            sb.append("'");
4681                    }
4682                    
4683                    String s = query.getCreatedAfter();
4684                    String s2 = query.getCreatedBefore();
4685                    if(s != null || s2 != null) {
4686                            sb.append(" CREATED='");
4687                            if(s != null) sb.append(s);
4688                            sb.append("..");
4689                            if(s2 != null) sb.append(s2);
4690                            sb.append("'");
4691                    }
4692                    
4693                    s = query.getModifiedAfter();
4694                    s2 = query.getModifiedBefore();
4695                    if(s != null || s2 != null) {
4696                            sb.append(" MODIFIED='");
4697                            if(s != null) sb.append(s);
4698                            sb.append("..");
4699                            if(s2 != null) sb.append(s2);
4700                            sb.append("'");
4701                    }
4702                    
4703                    if(query.description != null && query.description.length() > 0) {
4704                            sb.append(" DESCRIPTION='").append(query.description).append("'");
4705                    }
4706                    
4707                    if(query.instrumentType != DbSearchQuery.InstrumentType.BOTH) {
4708                            sb.append(" IS_DRUM=");
4709                            if(query.instrumentType == DbSearchQuery.InstrumentType.DRUM) {
4710                                    sb.append("'true'");
4711                            } else {
4712                                    sb.append("'false'");
4713                            }
4714                    }
4715                    
4716                    if(query.product != null && query.product.length() > 0) {
4717                            sb.append(" PRODUCT='").append(query.product).append("'");
4718                    }
4719                    
4720                    if(query.artists != null && query.artists.length() > 0) {
4721                            sb.append(" ARTISTS='").append(query.artists).append("'");
4722                    }
4723                    
4724                    if(query.keywords != null && query.keywords.length() > 0) {
4725                            sb.append(" KEYWORDS='").append(query.keywords).append("'");
4726                    }
4727                    
4728                    out.writeLine(sb.toString());
4729                    if(getPrintOnlyMode()) return null;
4730                    
4731                    String[] instrS = parseStringList(getSingleLineResultSet().getResult());
4732                    
4733                    DbInstrumentInfo[] infoS = new DbInstrumentInfo[instrS.length];
4734                    for(int i = 0; i < instrS.length; i++) {
4735                            infoS[i] = getDbInstrumentInfo(instrS[i]);
4736                    }
4737                    return infoS;
4738            }
4739            
4740            /**
4741             * Gets status information about the specified job.
4742             * @param jobId The ID of the job.
4743             * @return A <code>ScanJobInfo</code> instance providing information
4744             * about the specified job.
4745             * @throws IOException If some I/O error occurs.
4746             * @throws LscpException If LSCP protocol corruption occurs.
4747             * @throws LSException If the specified job is not found.
4748             */
4749            public synchronized ScanJobInfo
4750            getDbInstrumentsJobInfo(int jobId) throws IOException, LscpException, LSException {
4751                    verifyConnection();
4752                    out.writeLine("GET DB_INSTRUMENTS_JOB INFO " + String.valueOf(jobId));
4753                    if(getPrintOnlyMode()) return null;
4754                    
4755                    ResultSet rs = getMultiLineResultSet();
4756                    ScanJobInfo info = new ScanJobInfo(rs.getMultiLineResult());
4757                    
4758                    return info;
4759            }
4760            
4761          /**          /**
4762           * Resets the specified sampler channel.           * Resets the specified sampler channel.
4763           *           *
# Line 3692  public class Client { Line 4883  public class Client {
4883                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
4884          }          }
4885                    
4886            private void
4887            getEmptyResultSets(int count, String err) throws LSException {
4888                    StringBuffer sb = new StringBuffer();
4889                    for(int i = 0; i < count; i++) {
4890                            try { getEmptyResultSet(); }
4891                            catch (SocketTimeoutException e) {
4892                                    getLogger().log(Level.FINE, e.getMessage(), e);
4893                                    sb.append(e.getMessage()).append("\n");
4894                                    break;
4895                            } catch (Exception e) {
4896                                    getLogger().log(Level.FINE, e.getMessage(), e);
4897                                    sb.append(e.getMessage()).append("\n");
4898                            }
4899                    }
4900                    
4901                    String details = sb.toString();
4902                    if(details.length() > 0) {
4903                            String s = LscpI18n.getLogMsg(err);
4904                            throw new LSException(0, s, details);
4905                    }
4906            }
4907            
4908          /**          /**
4909           * Returns the logger for this library.           * Returns the logger for this library.
4910           * @return The logger for this library.           * @return The logger for this library.

Legend:
Removed from v.1139  
changed lines
  Added in v.1307

  ViewVC Help
Powered by ViewVC