/[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 1202 by iliev, Thu May 24 20:17:25 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 3567  public class Client { Line 3717  public class Client {
3717                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
3718          }          }
3719                    
3720            
3721            
3722            /**
3723             * Adds the specified directory to the instruments database.
3724             * @param dir The absolute path name of the directory to add.
3725             * @throws IOException If some I/O error occurs.
3726             * @throws LSException If the creation of the directory failed.
3727             * @throws LscpException If LSCP protocol corruption occurs.
3728             */
3729            public synchronized void
3730            addDbDirectory(String dir) throws IOException, LSException, LscpException {
3731                    verifyConnection();
3732                    out.writeLine("ADD DB_INSTRUMENT_DIRECTORY '" + dir + "'");
3733                    if(getPrintOnlyMode()) return;
3734                    
3735                    ResultSet rs = getEmptyResultSet();
3736            }
3737            
3738            /**
3739             * Removes the specified directory from the instruments database.
3740             * @param dir The absolute path name of the directory to remove.
3741             * @throws IOException If some I/O error occurs.
3742             * @throws LscpException If LSCP protocol corruption occurs.
3743             * @throws LSException If the specified directory is not
3744             * empty or if the removal of the directory failed.
3745             */
3746            public synchronized void
3747            removeDbDirectory(String dir) throws IOException, LscpException, LSException {
3748                    removeDbDirectory(dir, false);
3749            }
3750            
3751            /**
3752             * Removes the specified directory from the instruments database.
3753             * @param dir The absolute path name of the directory to remove.
3754             * @param force If <code>true</code> forces the removal of non-empty
3755             * directory and all its content.
3756             * @throws IOException If some I/O error occurs.
3757             * @throws LscpException If LSCP protocol corruption occurs.
3758             * @throws LSException If the removing of the directory failed.
3759             */
3760            public synchronized void
3761            removeDbDirectory(String dir, boolean force)
3762                                    throws IOException, LscpException, LSException {
3763                    
3764                    verifyConnection();
3765                    String s = "REMOVE DB_INSTRUMENT_DIRECTORY ";
3766                    if(force) s += "FORCE ";
3767                    out.writeLine(s + "'" + dir + "'");
3768                    if(getPrintOnlyMode()) return;
3769                    
3770                    ResultSet rs = getEmptyResultSet();
3771            }
3772            
3773            /**
3774             * Removes the specified directories from the instruments database.
3775             * @param dirs The absolute path names of the directories to remove.
3776             * @param force If <code>true</code> forces the removal of non-empty
3777             * directories.
3778             * @throws IOException If some I/O error occurs.
3779             * @throws LscpException If LSCP protocol corruption occurs.
3780             * @throws LSException If the removing of the directores failed.
3781             */
3782            public synchronized void
3783            removeDbDirectories(String[] dirs, boolean force)
3784                                    throws IOException, LscpException, LSException {
3785                    
3786                    verifyConnection();
3787                    String cmd = "REMOVE DB_INSTRUMENT_DIRECTORY ";
3788                    if(force) cmd += "FORCE ";
3789                    
3790                    for(String s : dirs) out.writeLine(cmd + "'" + s + "'");
3791                    
3792                    if(getPrintOnlyMode()) return;
3793                    
3794                    getEmptyResultSets(dirs.length, "Client.dirDeletionFailed!");
3795            }
3796            
3797            /**
3798             * Gets the number of directories in the specified directory.
3799             * @return The current number of directories in the specified directory.
3800             * @param dir The absolute path name of the directory.
3801             * @throws IOException If some I/O error occurs.
3802             * @throws LscpException If LSCP protocol corruption occurs.
3803             * @throws LSException If some other error occurs.
3804             */
3805            public synchronized int
3806            getDbDirectoryCount(String dir) throws IOException, LscpException, LSException {
3807                    return getDbDirectoryCount(dir, false);
3808            }
3809            
3810            /**
3811             * Gets the number of directories in the specified directory.
3812             * @return The current number of directories in the specified directory.
3813             * @param dir The absolute path name of the directory.
3814             * @param recursive If <code>true</code>, the number of all directories
3815             * in the specified subtree will be returned.
3816             * @throws IOException If some I/O error occurs.
3817             * @throws LscpException If LSCP protocol corruption occurs.
3818             * @throws LSException If some other error occurs.
3819             */
3820            public synchronized int
3821            getDbDirectoryCount(String dir, boolean recursive)
3822                                    throws IOException, LscpException, LSException {
3823                    
3824                    verifyConnection();
3825                    String s;
3826                    if(recursive) s = "GET DB_INSTRUMENT_DIRECTORIES RECURSIVE '";
3827                    else s = "GET DB_INSTRUMENT_DIRECTORIES '";
3828                    out.writeLine(s + dir + "'");
3829                    if(getPrintOnlyMode()) return -1;
3830                    
3831                    s = getSingleLineResultSet().getResult();
3832                    return parseInt(s);
3833            }
3834            
3835            /**
3836             * Gets the list of directories in the specified directory.
3837             * @param dir The absolute path name of the directory.
3838             * @return A <code>String</code> array providing the names of
3839             * all directories in the specified directory.
3840             * @throws IOException If some I/O error occurs.
3841             * @throws LscpException If LSCP protocol corruption occurs.
3842             * @throws LSException If the specified path name is invalid.
3843             */
3844            public synchronized String[]
3845            getDbDirectoryNames(String dir) throws IOException, LscpException, LSException {
3846                    verifyConnection();
3847                    out.writeLine("LIST DB_INSTRUMENT_DIRECTORIES '" + dir + "'");
3848                    if(getPrintOnlyMode()) return null;
3849                    
3850                    return parseStringList(getSingleLineResultSet().getResult());
3851            }
3852            
3853            /**
3854             * Gets information about the specified directory.
3855             * @param dir The absolute path name of the directory.
3856             * @return A <code>DbDirectoryInfo</code> instance providing information
3857             * about the specified directory.
3858             * @throws IOException If some I/O error occurs.
3859             * @throws LscpException If LSCP protocol corruption occurs.
3860             * @throws LSException If the specified directory is not found.
3861             */
3862            public synchronized DbDirectoryInfo
3863            getDbDirectoryInfo(String dir) throws IOException, LscpException, LSException {
3864                    verifyConnection();
3865                    out.writeLine("GET DB_INSTRUMENT_DIRECTORY INFO '" + dir + "'");
3866                    if(getPrintOnlyMode()) return null;
3867                    
3868                    ResultSet rs = getMultiLineResultSet();
3869                    DbDirectoryInfo info = new DbDirectoryInfo(rs.getMultiLineResult());
3870                    if(dir.equals("/")) {
3871                            info.setName("/");
3872                    } else if(dir.length() > 1 && dir.charAt(dir.length() - 1) == '/') {
3873                            dir = dir.substring(0, dir.length() - 1);
3874                    }
3875                    int i = dir.lastIndexOf('/');
3876                    if(i != -1 && i < dir.length() - 1) {
3877                            info.setName(dir.substring(i + 1));
3878                            if(i == 0) info.setParentDirectoryPath("/");
3879                            else info.setParentDirectoryPath(dir.substring(0, i));
3880                    }
3881                    
3882                    return info;
3883            }
3884            
3885            /**
3886             * Gets the list of directories in the specified directory.
3887             * @param dir The absolute path name of the directory.
3888             * @return A <code>DbDirectoryInfo</code> array providing
3889             * information about all directories in the specified directory.
3890             * @throws IOException If some I/O error occurs.
3891             * @throws LscpException If LSCP protocol corruption occurs.
3892             * @throws LSException If the specified path name is invalid.
3893             */
3894            public synchronized DbDirectoryInfo[]
3895            getDbDirectories(String dir) throws IOException, LscpException, LSException {
3896                    String[] dirS = getDbDirectoryNames(dir);
3897                    if(dir.charAt(dir.length() - 1) != '/') dir += "/";
3898                    DbDirectoryInfo[] infoS = new DbDirectoryInfo[dirS.length];
3899                    for(int i = 0; i < dirS.length; i++) infoS[i] = getDbDirectoryInfo(dir + dirS[i]);
3900                    return infoS;
3901            }
3902            
3903            /**
3904             * Gets the list of directories in the specified directory.
3905             * @param dir The absolute path name of the directory.
3906             * @return A <code>DbDirectoryInfo</code> array providing
3907             * information about all directories in the specified directory.
3908             * @throws IOException If some I/O error occurs.
3909             * @throws LscpException If LSCP protocol corruption occurs.
3910             * @throws LSException If the specified path name is invalid.
3911             *
3912            public synchronized DbDirectoryInfo[]
3913            getDbDirectories(String dir) throws IOException, LscpException, LSException {
3914                    String[] dirS = getDbDirectoryNames(dir);
3915                    if(dirS.length == 0) return new DbDirectoryInfo[0];
3916                    
3917                    if(dir.charAt(dir.length() - 1) != '/') dir += "/";
3918                    
3919                    for(int i = 0; i < dirS.length; i++) {
3920                            out.writeLine("GET DB_INSTRUMENT_DIRECTORY INFO '" + dir + dirS[i] + "'");
3921                    }
3922                    
3923                    if(getPrintOnlyMode()) return null;
3924                    
3925                    if(dir.length() > 1) dir = dir.substring(0, dir.length() - 1);
3926                    StringBuffer sb = new StringBuffer();
3927                    DbDirectoryInfo[] infoS = new DbDirectoryInfo[dirS.length];
3928                    for(int i = 0; i < dirS.length; i++) {
3929                            try {
3930                                    ResultSet rs = getMultiLineResultSet();
3931                                    infoS[i] = new DbDirectoryInfo(rs.getMultiLineResult());
3932                                    infoS[i].setName(dirS[i]);
3933                                    infoS[i].setParentDirectoryPath(dir);
3934                            } catch (SocketTimeoutException e) {
3935                                    getLogger().log(Level.FINE, e.getMessage(), e);
3936                                    sb.append(e.getMessage()).append("\n");
3937                                    break;
3938                            } catch (Exception e) {
3939                                    getLogger().log(Level.FINE, e.getMessage(), e);
3940                                    sb.append(e.getMessage()).append("\n");
3941                            }
3942                    }
3943                    
3944                    String details = sb.toString();
3945                    if(details.length() > 0) {
3946                            String err = LscpI18n.getLogMsg("Client.getInstrsInfoFailed!");
3947                            throw new LSException(0, err, details);
3948                    }
3949                    
3950                    return infoS;
3951            }*/
3952            
3953            /**
3954             * Renames the specified directory.
3955             * @param dir The absolute path name of the directory to rename.
3956             * @param name The new name for the directory.
3957             * @throws IOException If some I/O error occurs.
3958             * @throws LSException If the renaming of the directory failed.
3959             * @throws LscpException If LSCP protocol corruption occurs.
3960             */
3961            public synchronized void
3962            renameDbDirectory(String dir, String name) throws IOException, LSException, LscpException {
3963                    verifyConnection();
3964                    out.writeLine("SET DB_INSTRUMENT_DIRECTORY NAME '" + dir + "' '" + name + "'");
3965                    if(getPrintOnlyMode()) return;
3966                    
3967                    ResultSet rs = getEmptyResultSet();
3968            }
3969            
3970            /**
3971             * Moves the specified directory into the specified location.
3972             * @param dir The absolute path name of the directory to move.
3973             * @param dst The location where the directory will be moved to.
3974             * @throws IOException If some I/O error occurs.
3975             * @throws LSException If the operation failed.
3976             * @throws LscpException If LSCP protocol corruption occurs.
3977             */
3978            public synchronized void
3979            moveDbDirectory(String dir, String dst) throws IOException, LSException, LscpException {
3980                    verifyConnection();
3981                    out.writeLine("MOVE DB_INSTRUMENT_DIRECTORY '" + dir + "' '" + dst + "'");
3982                    if(getPrintOnlyMode()) return;
3983                    
3984                    ResultSet rs = getEmptyResultSet();
3985            }
3986            
3987            /**
3988             * Moves the specified directories into the specified location.
3989             * @param dirs The absolute path names of the directories to move.
3990             * @param dst The location where the directories will be moved to.
3991             * @throws IOException If some I/O error occurs.
3992             * @throws LSException If the operation failed.
3993             * @throws LscpException If LSCP protocol corruption occurs.
3994             */
3995            public synchronized void
3996            moveDbDirectories(String dirs[], String dst) throws IOException, LSException, LscpException {
3997                    verifyConnection();
3998                    for(String s : dirs) {
3999                            out.writeLine("MOVE DB_INSTRUMENT_DIRECTORY '" + s + "' '" + dst + "'");
4000                    }
4001                    if(getPrintOnlyMode()) return;
4002                    
4003                    getEmptyResultSets(dirs.length, "Client.dirMovingFailed!");
4004            }
4005            
4006            /**
4007             * Copies the specified directory into the specified location.
4008             * @param dir The absolute path name of the directory to copy.
4009             * @param dst The location where the directory will be copied to.
4010             * @throws IOException If some I/O error occurs.
4011             * @throws LSException If the operation failed.
4012             * @throws LscpException If LSCP protocol corruption occurs.
4013             */
4014            public synchronized void
4015            copyDbDirectory(String dir, String dst) throws IOException, LSException, LscpException {
4016                    verifyConnection();
4017                    out.writeLine("COPY DB_INSTRUMENT_DIRECTORY '" + dir + "' '" + dst + "'");
4018                    if(getPrintOnlyMode()) return;
4019                    
4020                    ResultSet rs = getEmptyResultSet();
4021            }
4022            
4023            /**
4024             * Copies the specified directories into the specified location.
4025             * @param dirs The absolute path names of the directories to copy.
4026             * @param dst The location where the directories will be copied to.
4027             * @throws IOException If some I/O error occurs.
4028             * @throws LSException If the operation failed.
4029             * @throws LscpException If LSCP protocol corruption occurs.
4030             */
4031            public synchronized void
4032            copyDbDirectories(String[] dirs, String dst) throws IOException, LSException, LscpException {
4033                    verifyConnection();
4034                    for(String s : dirs) {
4035                            out.writeLine("COPY DB_INSTRUMENT_DIRECTORY '" + s + "' '" + dst + "'");
4036                    }
4037                    if(getPrintOnlyMode()) return;
4038                    
4039                    getEmptyResultSets(dirs.length, "Client.dirCopyingFailed!");
4040            }
4041            
4042            /**
4043             * Changes the description of the specified directory.
4044             * @param dir The absolute path name of the directory.
4045             * @param desc The new description for the directory.
4046             * @throws IOException If some I/O error occurs.
4047             * @throws LSException If failed to change the description.
4048             * @throws LscpException If LSCP protocol corruption occurs.
4049             */
4050            public synchronized void
4051            setDbDirectoryDescription(String dir, String desc)
4052                                    throws IOException, LSException, LscpException {
4053                    
4054                    verifyConnection();
4055                    String s = "SET DB_INSTRUMENT_DIRECTORY DESCRIPTION '";
4056                    out.writeLine(s + dir + "' '" + desc + "'");
4057                    if(getPrintOnlyMode()) return;
4058                    
4059                    ResultSet rs = getEmptyResultSet();
4060            }
4061            
4062            public static enum ScanMode {
4063                    RECURSIVE, NON_RECURSIVE, FLAT
4064            }
4065            
4066            /**
4067             * Adds the specified instrument to the specified instruments database directory.
4068             * @param dbDir The absolute path name of the database directory in which the
4069             * specified instrument will be added.
4070             * @param filePath The absolute path name of the instrument file.
4071             * @param instrIndex The index of the instrument (in the given instrument file) to add.
4072             * @throws IOException If some I/O error occurs.
4073             * @throws LSException If the operation failed.
4074             * @throws LscpException If LSCP protocol corruption occurs.
4075             */
4076            public synchronized void
4077            addDbInstrument(String dbDir, String filePath, int instrIndex)
4078                                            throws IOException, LSException, LscpException {
4079                    
4080                    addDbInstrument(dbDir, filePath, instrIndex, false);
4081            }
4082            
4083            /**
4084             * Adds the specified instrument to the specified instruments database directory.
4085             * @param dbDir The absolute path name of the database directory in which the
4086             * specified instrument will be added.
4087             * @param filePath The absolute path name of the instrument file.
4088             * @param instrIndex The index of the instrument (in the given instrument file) to add.
4089             * @param background If <code>true</code>, the scan will be done
4090             * in background and this method may return before the job is finished.
4091             * @return If <code>background</code> is <code>true</code>, the ID
4092             * of the scan job.
4093             * @throws IOException If some I/O error occurs.
4094             * @throws LSException If the operation failed.
4095             * @throws LscpException If LSCP protocol corruption occurs.
4096             * @see #addInstrumentsDbListener
4097             */
4098            public synchronized int
4099            addDbInstrument(String dbDir, String filePath, int instrIndex, boolean background)
4100                                            throws IOException, LSException, LscpException {
4101                    
4102                    verifyConnection();
4103                    String s = "ADD DB_INSTRUMENTS";
4104                    if(background) s += " NON_MODAL";
4105                    s += " '" + dbDir + "' '" + filePath + "' ";
4106                    out.writeLine(s + String.valueOf(instrIndex));
4107                    if(getPrintOnlyMode()) return -1;
4108                    
4109                    ResultSet rs = getEmptyResultSet();
4110                    return rs.getIndex();
4111            }
4112            
4113            /**
4114             * Adds the instruments in the specified file to the specified
4115             * instruments database directory.
4116             * @param dbDir The absolute path name of the database directory
4117             * in which the the supported instruments will be added.
4118             * @param filePath The absolute path name of the file to scan for instruments.
4119             * @throws IOException If some I/O error occurs.
4120             * @throws LSException If the operation failed.
4121             * @throws LscpException If LSCP protocol corruption occurs.
4122             */
4123            public synchronized void
4124            addDbInstruments(String dbDir, String filePath)
4125                                            throws IOException, LSException, LscpException {
4126                    
4127                    addDbInstruments(dbDir, filePath, false);
4128            }
4129            
4130            /**
4131             * Adds the instruments in the specified file to the specified
4132             * instruments database directory.
4133             * @param dbDir The absolute path name of the database directory
4134             * in which the the supported instruments will be added.
4135             * @param filePath The absolute path name of the file to scan for instruments.
4136             * @param background If <code>true</code>, the scan will be done
4137             * in background and this method may return before the job is finished.
4138             * @return If <code>background</code> is <code>true</code>, the ID
4139             * of the scan job.
4140             * @throws IOException If some I/O error occurs.
4141             * @throws LSException If the operation failed.
4142             * @throws LscpException If LSCP protocol corruption occurs.
4143             * @see #addInstrumentsDbListener
4144             */
4145            public synchronized int
4146            addDbInstruments(String dbDir, String filePath, boolean background)
4147                                            throws IOException, LSException, LscpException {
4148                    
4149                    verifyConnection();
4150                    String s = "ADD DB_INSTRUMENTS";
4151                    if(background) s += " NON_MODAL";
4152                    out.writeLine(s + " '" + dbDir + "' '" + filePath + "'");
4153                    if(getPrintOnlyMode()) return -1;
4154                    
4155                    ResultSet rs = getEmptyResultSet();
4156                    return rs.getIndex();
4157            }
4158            
4159            /**
4160             * Adds the instruments in the specified file system directory
4161             * to the specified instruments database directory.
4162             * @param mode Determines the scanning mode. If RECURSIVE is
4163             * specified, all supported instruments in the specified file system
4164             * direcotry will be added to the specified instruments database
4165             * directory, including the instruments in subdirectories
4166             * of the supplied directory. If NON_RECURSIVE is specified,
4167             * the instruments in the subdirectories will not be processed.
4168             * If FLAT is specified, all supported instruments in the specified
4169             * file system direcotry will be added, including the instruments in
4170             * subdirectories of the supplied directory, but the respective
4171             * subdirectory structure will not be recreated in the instruments
4172             * database and all instruments will be added directly in the
4173             * specified database directory.
4174             * @param dbDir The absolute path name of the database directory
4175             * in which the supported instruments will be added.
4176             * @param fsDir The absolute path name of the file system directory.
4177             * @throws IOException If some I/O error occurs.
4178             * @throws LSException If the operation failed.
4179             * @throws LscpException If LSCP protocol corruption occurs.
4180             */
4181            public synchronized void
4182            addDbInstruments(ScanMode mode, String dbDir, String fsDir)
4183                                            throws IOException, LSException, LscpException {
4184                    
4185                    addDbInstruments(mode, dbDir, fsDir, false);
4186            }
4187            
4188            /**
4189             * Adds the instruments in the specified file system directory
4190             * to the specified instruments database directory.
4191             * @param mode Determines the scanning mode. If RECURSIVE is
4192             * specified, all supported instruments in the specified file system
4193             * direcotry will be added to the specified instruments database
4194             * directory, including the instruments in subdirectories
4195             * of the supplied directory. If NON_RECURSIVE is specified,
4196             * the instruments in the subdirectories will not be processed.
4197             * If FLAT is specified, all supported instruments in the specified
4198             * file system direcotry will be added, including the instruments in
4199             * subdirectories of the supplied directory, but the respective
4200             * subdirectory structure will not be recreated in the instruments
4201             * database and all instruments will be added directly in the
4202             * specified database directory.
4203             * @param dbDir The absolute path name of the database directory
4204             * in which the supported instruments will be added.
4205             * @param fsDir The absolute path name of the file system directory.
4206             * @param background If <code>true</code>, the scan will be done
4207             * in background and this method may return before the job is finished.
4208             * @return If <code>background</code> is <code>true</code>, the ID
4209             * of the scan job.
4210             * @throws IOException If some I/O error occurs.
4211             * @throws LSException If the operation failed.
4212             * @throws LscpException If LSCP protocol corruption occurs.
4213             * @see #addInstrumentsDbListener
4214             */
4215            public synchronized int
4216            addDbInstruments(ScanMode mode, String dbDir, String fsDir, boolean background)
4217                                            throws IOException, LSException, LscpException {
4218                    
4219                    verifyConnection();
4220                    StringBuffer sb = new StringBuffer("ADD DB_INSTRUMENTS");
4221                    if(background) sb.append(" NON_MODAL");
4222                    
4223                    switch(mode) {
4224                            case RECURSIVE:
4225                                    sb.append(" RECURSIVE");
4226                                    break;
4227                            case NON_RECURSIVE:
4228                                    sb.append(" NON_RECURSIVE");
4229                                    break;
4230                            case FLAT:
4231                                    sb.append(" FLAT");
4232                                    break;
4233                    }
4234                    
4235                    sb.append(" '").append(dbDir).append("' '").append(fsDir).append("'");
4236                    out.writeLine(sb.toString());
4237                    if(getPrintOnlyMode()) return -1;
4238                    
4239                    ResultSet rs = getEmptyResultSet();
4240                    return rs.getIndex();
4241            }
4242            
4243            /**
4244             * Removes the specified instrument from the instruments database.
4245             * @param instr The absolute path name of the instrument to remove.
4246             * @throws IOException If some I/O error occurs.
4247             * @throws LscpException If LSCP protocol corruption occurs.
4248             * @throws LSException If the removing of the instrument failed.
4249             */
4250            public synchronized void
4251            removeDbInstrument(String instr) throws IOException, LscpException, LSException {
4252                    
4253                    verifyConnection();
4254                    out.writeLine("REMOVE DB_INSTRUMENT '" + instr + "'");
4255                    if(getPrintOnlyMode()) return;
4256                    
4257                    ResultSet rs = getEmptyResultSet();
4258            }
4259            
4260            /**
4261             * Removes the specified instruments from the instruments database.
4262             * @param instrs The absolute path names of the instruments to remove.
4263             * @throws IOException If some I/O error occurs.
4264             * @throws LscpException If LSCP protocol corruption occurs.
4265             * @throws LSException If the removing of the instruments failed.
4266             */
4267            public synchronized void
4268            removeDbInstruments(String[] instrs) throws IOException, LscpException, LSException {
4269                    verifyConnection();
4270                    for(String s : instrs) {
4271                            out.writeLine("REMOVE DB_INSTRUMENT '" + s + "'");
4272                    }
4273                    if(getPrintOnlyMode()) return;
4274                    
4275                    getEmptyResultSets(instrs.length, "Client.instrDeletionFailed!");
4276            }
4277            
4278            /**
4279             * Gets the number of instruments in the specified directory.
4280             * @return The current number of instruments in the specified directory.
4281             * @param dir The absolute path name of the directory.
4282             * @throws IOException If some I/O error occurs.
4283             * @throws LscpException If LSCP protocol corruption occurs.
4284             * @throws LSException If some other error occurs.
4285             */
4286            public synchronized int
4287            getDbInstrumentCount(String dir) throws IOException, LscpException, LSException {
4288                    return getDbInstrumentCount(dir, false);
4289            }
4290            
4291            /**
4292             * Gets the number of instruments in the specified directory.
4293             * @return The current number of instruments in the specified directory.
4294             * @param dir The absolute path name of the directory.
4295             * @param recursive If <code>true</code>, the number of all instruments
4296             * in the specified subtree will be returned.
4297             * @throws IOException If some I/O error occurs.
4298             * @throws LscpException If LSCP protocol corruption occurs.
4299             * @throws LSException If some other error occurs.
4300             */
4301            public synchronized int
4302            getDbInstrumentCount(String dir, boolean recursive)
4303                                    throws IOException, LscpException, LSException {
4304                    
4305                    verifyConnection();
4306                    String s;
4307                    if(recursive) s = "GET DB_INSTRUMENTS RECURSIVE '";
4308                    else s = "GET DB_INSTRUMENTS '";
4309                    out.writeLine(s + dir + "'");
4310                    if(getPrintOnlyMode()) return -1;
4311                    
4312                    s = getSingleLineResultSet().getResult();
4313                    return parseInt(s);
4314            }
4315            
4316            /**
4317             * Gets the list of instruments in the specified directory.
4318             * @param dir The absolute path name of the directory.
4319             * @return A <code>String</code> array providing the names of
4320             * all instruments in the specified directory.
4321             * @throws IOException If some I/O error occurs.
4322             * @throws LscpException If LSCP protocol corruption occurs.
4323             * @throws LSException If the specified path name is invalid.
4324             */
4325            public synchronized String[]
4326            getDbInstrumentNames(String dir) throws IOException, LscpException, LSException {
4327                    verifyConnection();
4328                    out.writeLine("LIST DB_INSTRUMENTS '" + dir + "'");
4329                    if(getPrintOnlyMode()) return null;
4330                    
4331                    return parseStringList(getSingleLineResultSet().getResult());
4332            }
4333            
4334            /**
4335             * Gets information about the specified instrument.
4336             * @param instr The absolute path name of the instrument.
4337             * @return A <code>DbInstrumentInfo</code> instance providing information
4338             * about the specified instrument.
4339             * @throws IOException If some I/O error occurs.
4340             * @throws LscpException If LSCP protocol corruption occurs.
4341             * @throws LSException If the specified instrument is not found.
4342             */
4343            public synchronized DbInstrumentInfo
4344            getDbInstrumentInfo(String instr) throws IOException, LscpException, LSException {
4345                    verifyConnection();
4346                    out.writeLine("GET DB_INSTRUMENT INFO '" + instr + "'");
4347                    if(getPrintOnlyMode()) return null;
4348                    
4349                    ResultSet rs = getMultiLineResultSet();
4350                    DbInstrumentInfo info = new DbInstrumentInfo(rs.getMultiLineResult());
4351                    int i = instr.lastIndexOf('/');
4352                    if(i != -1 && i < instr.length() - 1) {
4353                            info.setName(instr.substring(i + 1));
4354                            if(i == 0) info.setDirectoryPath("/");
4355                            else info.setDirectoryPath(instr.substring(0, i));
4356                    }
4357                    
4358                    return info;
4359            }
4360            
4361            /**
4362             * Gets the list of instruments in the specified directory.
4363             * @param dir The absolute path name of the directory.
4364             * @return A <code>DbInstrumentInfo</code> array providing
4365             * information about all instruments in the specified directory.
4366             * @throws IOException If some I/O error occurs.
4367             * @throws LscpException If LSCP protocol corruption occurs.
4368             * @throws LSException If the specified path name is invalid.
4369             */
4370            public synchronized DbInstrumentInfo[]
4371            getDbInstruments(String dir) throws IOException, LscpException, LSException {
4372                    String[] instrS = getDbInstrumentNames(dir);
4373                    if(dir.charAt(dir.length() - 1) != '/') dir += "/";
4374                    
4375                    DbInstrumentInfo[] infoS = new DbInstrumentInfo[instrS.length];
4376                    for(int i = 0; i < instrS.length; i++) {
4377                            infoS[i] = getDbInstrumentInfo(dir + instrS[i]);
4378                    }
4379                    return infoS;
4380            }
4381            
4382            /**
4383             * Gets the list of instruments in the specified directory.
4384             * @param dir The absolute path name of the directory.
4385             * @return A <code>DbInstrumentInfo</code> array providing
4386             * information about all instruments in the specified directory.
4387             * @throws IOException If some I/O error occurs.
4388             * @throws LscpException If LSCP protocol corruption occurs.
4389             * @throws LSException If the specified path name is invalid.
4390             *
4391            public synchronized DbInstrumentInfo[]
4392            getDbInstruments(String dir) throws IOException, LscpException, LSException {
4393                    String[] instrS = getDbInstrumentNames(dir);
4394                    if(instrS.length == 0) return new DbInstrumentInfo[0];
4395                    
4396                    if(dir.charAt(dir.length() - 1) != '/') dir += "/";
4397                    
4398                    for(int i = 0; i < instrS.length; i++) {
4399                            out.writeLine("GET DB_INSTRUMENT INFO '" + dir + instrS[i] + "'");
4400                    }
4401                    
4402                    if(getPrintOnlyMode()) return null;
4403                    
4404                    if(dir.length() > 1) dir = dir.substring(0, dir.length() - 1);
4405                    StringBuffer sb = new StringBuffer();
4406                    DbInstrumentInfo[] infoS = new DbInstrumentInfo[instrS.length];
4407                    for(int i = 0; i < instrS.length; i++) {
4408                            try {
4409                                    ResultSet rs = getMultiLineResultSet();
4410                                    infoS[i] = new DbInstrumentInfo(rs.getMultiLineResult());
4411                                    infoS[i].setName(instrS[i]);
4412                                    infoS[i].setDirectoryPath(dir);
4413                            } catch (SocketTimeoutException e) {
4414                                    getLogger().log(Level.FINE, e.getMessage(), e);
4415                                    sb.append(e.getMessage()).append("\n");
4416                                    break;
4417                            } catch (Exception e) {
4418                                    getLogger().log(Level.FINE, e.getMessage(), e);
4419                                    sb.append(e.getMessage()).append("\n");
4420                            }
4421                    }
4422                    
4423                    String details = sb.toString();
4424                    if(details.length() > 0) {
4425                            String err = LscpI18n.getLogMsg("Client.getInstrsInfoFailed!");
4426                            throw new LSException(0, err, details);
4427                    }
4428                    
4429                    return infoS;
4430            }*/
4431            
4432            /**
4433             * Renames the specified instrument.
4434             * @param instr The absolute path name of the instrument to rename.
4435             * @param name The new name for the instrument.
4436             * @throws IOException If some I/O error occurs.
4437             * @throws LSException If the renaming of the instrument failed.
4438             * @throws LscpException If LSCP protocol corruption occurs.
4439             */
4440            public synchronized void
4441            renameDbInstrument(String instr, String name)
4442                                    throws IOException, LSException, LscpException {
4443                    
4444                    verifyConnection();
4445                    out.writeLine("SET DB_INSTRUMENT NAME '" + instr + "' '" + name + "'");
4446                    if(getPrintOnlyMode()) return;
4447                    
4448                    ResultSet rs = getEmptyResultSet();
4449            }
4450            
4451            /**
4452             * Moves the specified instrument into the specified location.
4453             * @param instr The absolute path name of the instrument to move.
4454             * @param dst The directory where the specified instrument will be moved to.
4455             * @throws IOException If some I/O error occurs.
4456             * @throws LSException If the operation failed.
4457             * @throws LscpException If LSCP protocol corruption occurs.
4458             */
4459            public synchronized void
4460            moveDbInstrument(String instr, String dst) throws IOException, LSException, LscpException {
4461                    verifyConnection();
4462                    out.writeLine("MOVE DB_INSTRUMENT '" + instr + "' '" + dst + "'");
4463                    if(getPrintOnlyMode()) return;
4464                    
4465                    ResultSet rs = getEmptyResultSet();
4466            }
4467            
4468            /**
4469             * Moves the specified instruments into the specified location.
4470             * @param instrs The absolute path names of the instruments to move.
4471             * @param dst The directory where the specified instruments will be moved to.
4472             * @throws IOException If some I/O error occurs.
4473             * @throws LSException If the operation failed.
4474             * @throws LscpException If LSCP protocol corruption occurs.
4475             */
4476            public synchronized void
4477            moveDbInstruments(String[] instrs, String dst) throws IOException, LSException, LscpException {
4478                    verifyConnection();
4479                    for(String s : instrs) {
4480                            out.writeLine("MOVE DB_INSTRUMENT '" + s + "' '" + dst + "'");
4481                    }
4482                    if(getPrintOnlyMode()) return;
4483                    
4484                    getEmptyResultSets(instrs.length, "Client.instrMovingFailed!");
4485            }
4486            
4487            /**
4488             * Copies the specified instrument into the specified location.
4489             * @param instr The absolute path name of the instrument to copy.
4490             * @param dst The directory where the specified instrument will be copied to.
4491             * @throws IOException If some I/O error occurs.
4492             * @throws LSException If the operation failed.
4493             * @throws LscpException If LSCP protocol corruption occurs.
4494             */
4495            public synchronized void
4496            copyDbInstrument(String instr, String dst) throws IOException, LSException, LscpException {
4497                    verifyConnection();
4498                    out.writeLine("COPY DB_INSTRUMENT '" + instr + "' '" + dst + "'");
4499                    if(getPrintOnlyMode()) return;
4500                    
4501                    ResultSet rs = getEmptyResultSet();
4502            }
4503            
4504            /**
4505             * Copies the specified instruments into the specified location.
4506             * @param instrs The absolute path name of the instruments to copy.
4507             * @param dst The directory where the specified instruments will be copied to.
4508             * @throws IOException If some I/O error occurs.
4509             * @throws LSException If the operation failed.
4510             * @throws LscpException If LSCP protocol corruption occurs.
4511             */
4512            public synchronized void
4513            copyDbInstruments(String[] instrs, String dst) throws IOException, LSException, LscpException {
4514                    verifyConnection();
4515                    for(String s : instrs) {
4516                            out.writeLine("COPY DB_INSTRUMENT '" + s + "' '" + dst + "'");
4517                    }
4518                    if(getPrintOnlyMode()) return;
4519                    
4520                    getEmptyResultSets(instrs.length, "Client.instrCopyingFailed!");
4521            }
4522            
4523            /**
4524             * Changes the description of the specified instrument.
4525             * @param instr The absolute path name of the instrument.
4526             * @param desc The new description for the instrument.
4527             * @throws IOException If some I/O error occurs.
4528             * @throws LSException If failed to change the description.
4529             * @throws LscpException If LSCP protocol corruption occurs.
4530             */
4531            public synchronized void
4532            setDbInstrumentDescription(String instr, String desc)
4533                                    throws IOException, LSException, LscpException {
4534                    
4535                    verifyConnection();
4536                    out.writeLine("SET DB_INSTRUMENT DESCRIPTION '" + instr + "' '" + desc + "'");
4537                    if(getPrintOnlyMode()) return;
4538                    
4539                    ResultSet rs = getEmptyResultSet();
4540            }
4541            
4542            /**
4543             * Finds all directories in the specified directory
4544             * that corresponds to the specified search criterias.
4545             * @param dir The absolute path name of the directory to search.
4546             * @param query Provides the search criterias.
4547             * @return A <code>DbDirectoryInfo</code> array providing
4548             * information about all directories that are found in the specified directory.
4549             * @throws IOException If some I/O error occurs.
4550             * @throws LscpException If LSCP protocol corruption occurs.
4551             * @throws LSException If the specified path name is invalid.
4552             */
4553            public synchronized DbDirectoryInfo[]
4554            findDbDirectories(String dir, DbSearchQuery query)
4555                                    throws IOException, LscpException, LSException {
4556                    
4557                    return findDbDirectories(dir, query, false);
4558            }
4559            
4560            /**
4561             * Finds all directories in the specified directory
4562             * that corresponds to the specified search criterias.
4563             * @param dir The absolute path name of the directory to search.
4564             * @param query Provides the search criterias.
4565             * @param nonRecursive If <code>true</code>, the search will be non-recursive.
4566             * @return A <code>DbDirectoryInfo</code> array providing
4567             * information about all directories that are found in the specified directory.
4568             * @throws IOException If some I/O error occurs.
4569             * @throws LscpException If LSCP protocol corruption occurs.
4570             * @throws LSException If the specified path name is invalid.
4571             */
4572            public synchronized DbDirectoryInfo[]
4573            findDbDirectories(String dir, DbSearchQuery query, boolean nonRecursive)
4574                                    throws IOException, LscpException, LSException {
4575                    
4576                    verifyConnection();
4577                    StringBuffer sb = new StringBuffer();
4578                    sb.append("FIND DB_INSTRUMENT_DIRECTORIES");
4579                    if(nonRecursive) sb.append(" NON_RECURSIVE");
4580                    sb.append(" '").append(dir).append("'");
4581                    
4582                    if(query.name != null && query.name.length() > 0) {
4583                            sb.append(" NAME='").append(query.name).append("'");
4584                    }
4585                    
4586                    String s = query.getCreatedAfter();
4587                    String s2 = query.getCreatedBefore();
4588                    if(s != null || s2 != null) {
4589                            sb.append(" CREATED='");
4590                            if(s != null) sb.append(s);
4591                            sb.append("..");
4592                            if(s2 != null) sb.append(s2);
4593                            sb.append("'");
4594                    }
4595                    
4596                    s = query.getModifiedAfter();
4597                    s2 = query.getModifiedBefore();
4598                    if(s != null || s2 != null) {
4599                            sb.append(" MODIFIED='");
4600                            if(s != null) sb.append(s);
4601                            sb.append("..");
4602                            if(s2 != null) sb.append(s2);
4603                            sb.append("'");
4604                    }
4605                    
4606                    if(query.description != null && query.description.length() > 0) {
4607                            sb.append(" DESCRIPTION='").append(query.description).append("'");
4608                    }
4609                    
4610                    out.writeLine(sb.toString());
4611                    if(getPrintOnlyMode()) return null;
4612                    
4613                    String[] dirS = parseStringList(getSingleLineResultSet().getResult());
4614                    
4615                    DbDirectoryInfo[] infoS = new DbDirectoryInfo[dirS.length];
4616                    for(int i = 0; i < dirS.length; i++) {
4617                            infoS[i] = getDbDirectoryInfo(dirS[i]);
4618                    }
4619                    return infoS;
4620            }
4621            
4622            /**
4623             * Finds all instruments in the specified directory
4624             * that corresponds to the specified search criterias.
4625             * @param dir The absolute path name of the directory to search.
4626             * @param query Provides the search criterias.
4627             * @return A <code>DbInstrumentInfo</code> array providing
4628             * information about all instruments that are found in the specified directory.
4629             * @throws IOException If some I/O error occurs.
4630             * @throws LscpException If LSCP protocol corruption occurs.
4631             * @throws LSException If the specified path name is invalid.
4632             */
4633            public synchronized DbInstrumentInfo[]
4634            findDbInstruments(String dir, DbSearchQuery query)
4635                                    throws IOException, LscpException, LSException {
4636                    
4637                    return findDbInstruments(dir, query, false);
4638            }
4639            
4640            /**
4641             * Finds all instruments in the specified directory
4642             * that corresponds to the specified search criterias.
4643             * @param dir The absolute path name of the directory to search.
4644             * @param query Provides the search criterias.
4645             * @param nonRecursive If <code>true</code>, the search will be non-recursive.
4646             * @return A <code>DbInstrumentInfo</code> array providing
4647             * information about all instruments that are found in the specified directory.
4648             * @throws IOException If some I/O error occurs.
4649             * @throws LscpException If LSCP protocol corruption occurs.
4650             * @throws LSException If the specified path name is invalid.
4651             */
4652            public synchronized DbInstrumentInfo[]
4653            findDbInstruments(String dir, DbSearchQuery query, boolean nonRecursive)
4654                                    throws IOException, LscpException, LSException {
4655                    
4656                    verifyConnection();
4657                    StringBuffer sb = new StringBuffer();
4658                    sb.append("FIND DB_INSTRUMENTS");
4659                    if(nonRecursive) sb.append(" NON_RECURSIVE");
4660                    sb.append(" '").append(dir).append("'");
4661                    
4662                    if(query.name != null && query.name.length() > 0) {
4663                            sb.append(" NAME='").append(query.name).append("'");
4664                    }
4665                    
4666                    if(query.formatFamilies.size() > 0) {
4667                            sb.append(" FORMAT_FAMILIES='").append(query.formatFamilies.get(0));
4668                            for(int i = 1; i < query.formatFamilies.size(); i++) {
4669                                    sb.append(',').append(query.formatFamilies.get(i));
4670                            }
4671                            sb.append("'");
4672                    }
4673                    
4674                    if(query.minSize != -1 || query.maxSize != -1) {
4675                            sb.append(" SIZE='");
4676                            if(query.minSize != -1) sb.append(query.minSize);
4677                            sb.append("..");
4678                            if(query.maxSize != -1) sb.append(query.maxSize);
4679                            sb.append("'");
4680                    }
4681                    
4682                    String s = query.getCreatedAfter();
4683                    String s2 = query.getCreatedBefore();
4684                    if(s != null || s2 != null) {
4685                            sb.append(" CREATED='");
4686                            if(s != null) sb.append(s);
4687                            sb.append("..");
4688                            if(s2 != null) sb.append(s2);
4689                            sb.append("'");
4690                    }
4691                    
4692                    s = query.getModifiedAfter();
4693                    s2 = query.getModifiedBefore();
4694                    if(s != null || s2 != null) {
4695                            sb.append(" MODIFIED='");
4696                            if(s != null) sb.append(s);
4697                            sb.append("..");
4698                            if(s2 != null) sb.append(s2);
4699                            sb.append("'");
4700                    }
4701                    
4702                    if(query.description != null && query.description.length() > 0) {
4703                            sb.append(" DESCRIPTION='").append(query.description).append("'");
4704                    }
4705                    
4706                    if(query.instrumentType != DbSearchQuery.InstrumentType.BOTH) {
4707                            sb.append(" IS_DRUM=");
4708                            if(query.instrumentType == DbSearchQuery.InstrumentType.DRUM) {
4709                                    sb.append("'true'");
4710                            } else {
4711                                    sb.append("'false'");
4712                            }
4713                    }
4714                    
4715                    if(query.product != null && query.product.length() > 0) {
4716                            sb.append(" PRODUCT='").append(query.product).append("'");
4717                    }
4718                    
4719                    if(query.artists != null && query.artists.length() > 0) {
4720                            sb.append(" ARTISTS='").append(query.artists).append("'");
4721                    }
4722                    
4723                    if(query.keywords != null && query.keywords.length() > 0) {
4724                            sb.append(" KEYWORDS='").append(query.keywords).append("'");
4725                    }
4726                    
4727                    out.writeLine(sb.toString());
4728                    if(getPrintOnlyMode()) return null;
4729                    
4730                    String[] instrS = parseStringList(getSingleLineResultSet().getResult());
4731                    
4732                    DbInstrumentInfo[] infoS = new DbInstrumentInfo[instrS.length];
4733                    for(int i = 0; i < instrS.length; i++) {
4734                            infoS[i] = getDbInstrumentInfo(instrS[i]);
4735                    }
4736                    return infoS;
4737            }
4738            
4739            /**
4740             * Gets status information about the specified job.
4741             * @param jobId The ID of the job.
4742             * @return A <code>ScanJobInfo</code> instance providing information
4743             * about the specified job.
4744             * @throws IOException If some I/O error occurs.
4745             * @throws LscpException If LSCP protocol corruption occurs.
4746             * @throws LSException If the specified job is not found.
4747             */
4748            public synchronized ScanJobInfo
4749            getDbInstrumentsJobInfo(int jobId) throws IOException, LscpException, LSException {
4750                    verifyConnection();
4751                    out.writeLine("GET DB_INSTRUMENTS_JOB INFO " + String.valueOf(jobId));
4752                    if(getPrintOnlyMode()) return null;
4753                    
4754                    ResultSet rs = getMultiLineResultSet();
4755                    ScanJobInfo info = new ScanJobInfo(rs.getMultiLineResult());
4756                    
4757                    return info;
4758            }
4759            
4760          /**          /**
4761           * Resets the specified sampler channel.           * Resets the specified sampler channel.
4762           *           *
# Line 3692  public class Client { Line 4882  public class Client {
4882                  ResultSet rs = getEmptyResultSet();                  ResultSet rs = getEmptyResultSet();
4883          }          }
4884                    
4885            private void
4886            getEmptyResultSets(int count, String err) throws LSException {
4887                    StringBuffer sb = new StringBuffer();
4888                    for(int i = 0; i < count; i++) {
4889                            try { getEmptyResultSet(); }
4890                            catch (SocketTimeoutException e) {
4891                                    getLogger().log(Level.FINE, e.getMessage(), e);
4892                                    sb.append(e.getMessage()).append("\n");
4893                                    break;
4894                            } catch (Exception e) {
4895                                    getLogger().log(Level.FINE, e.getMessage(), e);
4896                                    sb.append(e.getMessage()).append("\n");
4897                            }
4898                    }
4899                    
4900                    String details = sb.toString();
4901                    if(details.length() > 0) {
4902                            String s = LscpI18n.getLogMsg(err);
4903                            throw new LSException(0, s, details);
4904                    }
4905            }
4906            
4907          /**          /**
4908           * Returns the logger for this library.           * Returns the logger for this library.
4909           * @return The logger for this library.           * @return The logger for this library.

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

  ViewVC Help
Powered by ViewVC