public static void main(String[] args) throws Exception { boolean allOk = true; MidiDevice.Info[] infos; out("\nTesting MidiDevices retrieved via MidiSystem"); infos = MidiSystem.getMidiDeviceInfo(); allOk &= testDevices(infos, null); out("\nTesting MidiDevices retrieved from MidiDeviceProviders"); List providers = JDK13Services.getProviders(MidiDeviceProvider.class); for (int i = 0; i < providers.size(); i++) { MidiDeviceProvider provider = (MidiDeviceProvider)providers.get(i); infos = provider.getDeviceInfo(); allOk &= testDevices(infos, provider.getClass().getName()); } if (!allOk) { throw new Exception("Test failed"); } else { out("Test passed"); } }
public static void main(String[] args) throws Exception { boolean allCached = true; for (int i = 0; i < providerClasses.length; i++) { List list0 = JDK13Services.getProviders(providerClasses[i]); List list1 = JDK13Services.getProviders(providerClasses[i]); if (list0 == list1) { out("Providers should not be cached for " + providerClasses[i]); allCached = false; } } if (! allCached) { throw new Exception("Test failed"); } else { out("Test passed"); } }
public static void main(String[] args) throws Exception { boolean allOk = true; Mixer.Info[] infos; out("Testing Mixers retrieved via AudioSystem"); infos = AudioSystem.getMixerInfo(); allOk &= testMixers(infos, null); out("Testing MixerProviders"); List providers = JDK13Services.getProviders(MixerProvider.class); for (int i = 0; i < providers.size(); i++) { MixerProvider provider = (MixerProvider) providers.get(i); infos = provider.getMixerInfo(); allOk &= testMixers(infos, provider.getClass().getName()); } if (! allOk) { throw new Exception("Test failed"); } else { out("Test passed"); } }
/** Attempts to locate and return a default MidiDevice of the specified * type. * * @param deviceClass The requested device type, one of Synthesizer.class, * Sequencer.class, Receiver.class or Transmitter.class. * @throws IllegalArgumentException on failure. */ private static MidiDevice getDefaultDevice(Class deviceClass) { List providers = getMidiDeviceProviders(); String providerClassName = JDK13Services.getDefaultProviderClassName(deviceClass); String instanceName = JDK13Services.getDefaultInstanceName(deviceClass); MidiDevice device; if (providerClassName != null) { MidiDeviceProvider defaultProvider = getNamedProvider(providerClassName, providers); if (defaultProvider != null) { if (instanceName != null) { device = getNamedDevice(instanceName, defaultProvider, deviceClass); if (device != null) { return device; } } device = getFirstDevice(defaultProvider, deviceClass); if (device != null) { return device; } } } /* Provider class not specified or cannot be found, or provider class specified, and no appropriate device available or provider class and instance specified and instance cannot be found or is not appropriate */ if (instanceName != null) { device = getNamedDevice(instanceName, providers, deviceClass); if (device != null) { return device; } } /* No default are specified, or if something is specified, everything failed. */ device = getFirstDevice(providers, deviceClass); if (device != null) { return device; } throw new IllegalArgumentException("Requested device not installed"); }
/** Attempts to locate and return a default Mixer that provides lines * of the specified type. * * @param providers the installed mixer providers * @param info The requested line type * TargetDataLine.class, Clip.class or Port.class. * @return a Mixer that matches the requirements, or null if no default mixer found */ private static Mixer getDefaultMixer(List providers, Line.Info info) { Class lineClass = info.getLineClass(); String providerClassName = JDK13Services.getDefaultProviderClassName(lineClass); String instanceName = JDK13Services.getDefaultInstanceName(lineClass); Mixer mixer; if (providerClassName != null) { MixerProvider defaultProvider = getNamedProvider(providerClassName, providers); if (defaultProvider != null) { if (instanceName != null) { mixer = getNamedMixer(instanceName, defaultProvider, info); if (mixer != null) { return mixer; } } else { mixer = getFirstMixer(defaultProvider, info, false /* mixing not required*/); if (mixer != null) { return mixer; } } } } /* Provider class not specified or provider class cannot be found, or provider class and instance specified and instance cannot be found or is not appropriate */ if (instanceName != null) { mixer = getNamedMixer(instanceName, providers, info); if (mixer != null) { return mixer; } } /* No default are specified, or if something is specified, everything failed. */ return null; }
/** * Attempts to locate and return a default MidiDevice of the specified type. * * @param deviceClass The requested device type, one of Synthesizer.class, * Sequencer.class, Receiver.class or Transmitter.class * @return default MidiDevice of the specified type. * @throws IllegalArgumentException on failure */ private static MidiDevice getDefaultDevice(Class<?> deviceClass) { List<MidiDeviceProvider> providers = getMidiDeviceProviders(); String providerClassName = JDK13Services.getDefaultProviderClassName(deviceClass); String instanceName = JDK13Services.getDefaultInstanceName(deviceClass); MidiDevice device; if (providerClassName != null) { MidiDeviceProvider defaultProvider = getNamedProvider(providerClassName, providers); if (defaultProvider != null) { if (instanceName != null) { device = getNamedDevice(instanceName, defaultProvider, deviceClass); if (device != null) { return device; } } device = getFirstDevice(defaultProvider, deviceClass); if (device != null) { return device; } } } /* * - Provider class not specified or cannot be found, or * - provider class specified, and no appropriate device available, or * - provider class and instance specified and instance cannot be found * or is not appropriate */ if (instanceName != null) { device = getNamedDevice(instanceName, providers, deviceClass); if (device != null) { return device; } } /* * No defaults are specified, or if something is specified, everything * failed */ device = getFirstDevice(providers, deviceClass); if (device != null) { return device; } throw new IllegalArgumentException("Requested device not installed"); }
/** * Attempts to locate and return a default Mixer that provides lines of the * specified type. * * @param providers the installed mixer providers * @param info The requested line type TargetDataLine.class, Clip.class or * Port.class * @return a Mixer that matches the requirements, or null if no default * mixer found */ private static Mixer getDefaultMixer(List<MixerProvider> providers, Line.Info info) { Class<?> lineClass = info.getLineClass(); String providerClassName = JDK13Services.getDefaultProviderClassName(lineClass); String instanceName = JDK13Services.getDefaultInstanceName(lineClass); Mixer mixer; if (providerClassName != null) { MixerProvider defaultProvider = getNamedProvider(providerClassName, providers); if (defaultProvider != null) { if (instanceName != null) { mixer = getNamedMixer(instanceName, defaultProvider, info); if (mixer != null) { return mixer; } } else { mixer = getFirstMixer(defaultProvider, info, false /* mixing not required*/); if (mixer != null) { return mixer; } } } } /* * - Provider class not specified, or * - provider class cannot be found, or * - provider class and instance specified and instance cannot be found * or is not appropriate */ if (instanceName != null) { mixer = getNamedMixer(instanceName, providers, info); if (mixer != null) { return mixer; } } /* * No defaults are specified, or if something is specified, everything * failed */ return null; }
/** * Attempts to locate and return a default MidiDevice of the specified type. * * @param deviceClass The requested device type, one of Synthesizer.class, * Sequencer.class, Receiver.class or Transmitter.class * @throws IllegalArgumentException on failure */ private static MidiDevice getDefaultDevice(Class<?> deviceClass) { List<MidiDeviceProvider> providers = getMidiDeviceProviders(); String providerClassName = JDK13Services.getDefaultProviderClassName(deviceClass); String instanceName = JDK13Services.getDefaultInstanceName(deviceClass); MidiDevice device; if (providerClassName != null) { MidiDeviceProvider defaultProvider = getNamedProvider(providerClassName, providers); if (defaultProvider != null) { if (instanceName != null) { device = getNamedDevice(instanceName, defaultProvider, deviceClass); if (device != null) { return device; } } device = getFirstDevice(defaultProvider, deviceClass); if (device != null) { return device; } } } /* Provider class not specified or cannot be found, or provider class specified, and no appropriate device available or provider class and instance specified and instance cannot be found or is not appropriate */ if (instanceName != null) { device = getNamedDevice(instanceName, providers, deviceClass); if (device != null) { return device; } } /* No default are specified, or if something is specified, everything failed. */ device = getFirstDevice(providers, deviceClass); if (device != null) { return device; } throw new IllegalArgumentException("Requested device not installed"); }
/** * Attempts to locate and return a default Mixer that provides lines of the * specified type. * * @param providers the installed mixer providers * @param info The requested line type TargetDataLine.class, Clip.class or * Port.class * @return a Mixer that matches the requirements, or null if no default * mixer found */ private static Mixer getDefaultMixer(List<MixerProvider> providers, Line.Info info) { Class<?> lineClass = info.getLineClass(); String providerClassName = JDK13Services.getDefaultProviderClassName(lineClass); String instanceName = JDK13Services.getDefaultInstanceName(lineClass); Mixer mixer; if (providerClassName != null) { MixerProvider defaultProvider = getNamedProvider(providerClassName, providers); if (defaultProvider != null) { if (instanceName != null) { mixer = getNamedMixer(instanceName, defaultProvider, info); if (mixer != null) { return mixer; } } else { mixer = getFirstMixer(defaultProvider, info, false /* mixing not required*/); if (mixer != null) { return mixer; } } } } /* Provider class not specified or provider class cannot be found, or provider class and instance specified and instance cannot be found or is not appropriate */ if (instanceName != null) { mixer = getNamedMixer(instanceName, providers, info); if (mixer != null) { return mixer; } } /* No default are specified, or if something is specified, everything failed. */ return null; }
/** * Obtains the set of services currently installed on the system * using sun.misc.Service, the SPI mechanism in 1.3. * @return a List of instances of providers for the requested service. * If no providers are available, a List of length 0 will be returned. */ private static List getProviders(Class providerClass) { return JDK13Services.getProviders(providerClass); }
/** * Obtains the set of services currently installed on the system * using sun.misc.Service, the SPI mechanism in 1.3. * @return a List of instances of providers for the requested service. * If no providers are available, a vector of length 0 will be returned. */ private static List getProviders(Class providerClass) { return JDK13Services.getProviders(providerClass); }
/** * Obtains the set of services currently installed on the system using the * SPI mechanism in 1.3. * * @param providerClass The type of providers requested. This should be one * of AudioFileReader.class, AudioFileWriter.class, * FormatConversionProvider.class, MixerProvider.class, * MidiDeviceProvider.class, MidiFileReader.class, * MidiFileWriter.class or SoundbankReader.class. * @return a List of instances of providers for the requested service. If no * providers are available, a List of length 0 will be returned. */ private static List<?> getProviders(Class<?> providerClass) { return JDK13Services.getProviders(providerClass); }
/** * Obtains the set of services currently installed on the system using the * SPI mechanism in 1.3. * * @param providerClass The type of providers requested. This should be one * of AudioFileReader.class, AudioFileWriter.class, * FormatConversionProvider.class, MixerProvider.class, * MidiDeviceProvider.class, MidiFileReader.class, * MidiFileWriter.class or SoundbankReader.class. * @return a List of instances of providers for the requested service. If no * providers are available, a vector of length 0 will be returned. */ private static List<?> getProviders(Class<?> providerClass) { return JDK13Services.getProviders(providerClass); }
/** * Obtains the set of services currently installed on the system using the * SPI mechanism in 1.3. * * @return a List of instances of providers for the requested service. If no * providers are available, a List of length 0 will be returned. */ private static List<?> getProviders(Class<?> providerClass) { return JDK13Services.getProviders(providerClass); }
/** * Obtains the set of services currently installed on the system using the * SPI mechanism in 1.3. * * @return a List of instances of providers for the requested service. If no * providers are available, a vector of length 0 will be returned. */ private static List<?> getProviders(Class<?> providerClass) { return JDK13Services.getProviders(providerClass); }