119 @return The value of the provider class name part of the property 120 (the part before the hash sign), if available. If the property is 121 not set or the value has no provider class name part, null is returned. 122 */ 123 public static synchronized String getDefaultProviderClassName(Class<?> typeClass) { 124 String value = null; 125 String defaultProviderSpec = getDefaultProvider(typeClass); 126 if (defaultProviderSpec != null) { 127 int hashpos = defaultProviderSpec.indexOf('#'); 128 if (hashpos == 0) { 129 // instance name only; leave value as null 130 } else if (hashpos > 0) { 131 value = defaultProviderSpec.substring(0, hashpos); 132 } else { 133 value = defaultProviderSpec; 134 } 135 } 136 return value; 137 } 138 139 140 /** Obtain the instance name part of a default provider property. 141 @param typeClass The type of the default provider property. This 142 should be one of Receiver.class, Transmitter.class, Sequencer.class, 143 Synthesizer.class, SourceDataLine.class, TargetDataLine.class, 144 Clip.class or Port.class. 145 @return The value of the instance name part of the property (the 146 part after the hash sign), if available. If the property is not set 147 or the value has no instance name part, null is returned. 148 */ 149 public static synchronized String getDefaultInstanceName(Class<?> typeClass) { 150 String value = null; 151 String defaultProviderSpec = getDefaultProvider(typeClass); 152 if (defaultProviderSpec != null) { 153 int hashpos = defaultProviderSpec.indexOf('#'); 154 if (hashpos >= 0 && hashpos < defaultProviderSpec.length() - 1) { 155 value = defaultProviderSpec.substring(hashpos + 1); 156 } 157 } 158 return value; 159 } 160 161 162 /** Obtain the value of a default provider property. 163 @param typeClass The type of the default provider property. This 164 should be one of Receiver.class, Transmitter.class, Sequencer.class, 165 Synthesizer.class, SourceDataLine.class, TargetDataLine.class, 166 Clip.class or Port.class. 167 @return The complete value of the property, if available. 168 If the property is not set, null is returned. 169 */ 170 private static synchronized String getDefaultProvider(Class<?> typeClass) { 171 if (!SourceDataLine.class.equals(typeClass) 172 && !TargetDataLine.class.equals(typeClass) 173 && !Clip.class.equals(typeClass) 174 && !Port.class.equals(typeClass) 175 && !Receiver.class.equals(typeClass) 176 && !Transmitter.class.equals(typeClass) 177 && !Synthesizer.class.equals(typeClass) 178 && !Sequencer.class.equals(typeClass)) { 179 return null; 180 } 181 String name = typeClass.getName(); 182 String value = AccessController.doPrivileged( 183 (PrivilegedAction<String>) () -> System.getProperty(name)); 184 if (value == null) { 185 value = getProperties().getProperty(name); 186 } 187 if ("".equals(value)) { 188 value = null; 189 } 190 return value; 191 } 192 193 194 /** Obtain a properties bundle containing property values from the 195 properties file. If the properties file could not be loaded, 196 the properties bundle is empty. 197 */ 198 private static synchronized Properties getProperties() { 199 if (properties == null) { 200 properties = new Properties(); 201 JSSecurityManager.loadProperties(properties, PROPERTIES_FILENAME); 202 } 203 return properties; 204 } 205 } | 119 @return The value of the provider class name part of the property 120 (the part before the hash sign), if available. If the property is 121 not set or the value has no provider class name part, null is returned. 122 */ 123 public static synchronized String getDefaultProviderClassName(Class<?> typeClass) { 124 String value = null; 125 String defaultProviderSpec = getDefaultProvider(typeClass); 126 if (defaultProviderSpec != null) { 127 int hashpos = defaultProviderSpec.indexOf('#'); 128 if (hashpos == 0) { 129 // instance name only; leave value as null 130 } else if (hashpos > 0) { 131 value = defaultProviderSpec.substring(0, hashpos); 132 } else { 133 value = defaultProviderSpec; 134 } 135 } 136 return value; 137 } 138 139 /** Obtain the instance name part of a default provider property. 140 @param typeClass The type of the default provider property. This 141 should be one of Receiver.class, Transmitter.class, Sequencer.class, 142 Synthesizer.class, SourceDataLine.class, TargetDataLine.class, 143 Clip.class or Port.class. 144 @return The value of the instance name part of the property (the 145 part after the hash sign), if available. If the property is not set 146 or the value has no instance name part, null is returned. 147 */ 148 public static synchronized String getDefaultInstanceName(Class<?> typeClass) { 149 String value = null; 150 String defaultProviderSpec = getDefaultProvider(typeClass); 151 if (defaultProviderSpec != null) { 152 int hashpos = defaultProviderSpec.indexOf('#'); 153 if (hashpos >= 0 && hashpos < defaultProviderSpec.length() - 1) { 154 value = defaultProviderSpec.substring(hashpos + 1); 155 } 156 } 157 return value; 158 } 159 160 /** Obtain the value of a default provider property. 161 @param typeClass The type of the default provider property. This 162 should be one of Receiver.class, Transmitter.class, Sequencer.class, 163 Synthesizer.class, SourceDataLine.class, TargetDataLine.class, 164 Clip.class or Port.class. 165 @return The complete value of the property, if available. 166 If the property is not set, null is returned. 167 */ 168 private static synchronized String getDefaultProvider(Class<?> typeClass) { 169 if (!SourceDataLine.class.equals(typeClass) 170 && !TargetDataLine.class.equals(typeClass) 171 && !Clip.class.equals(typeClass) 172 && !Port.class.equals(typeClass) 173 && !Receiver.class.equals(typeClass) 174 && !Transmitter.class.equals(typeClass) 175 && !Synthesizer.class.equals(typeClass) 176 && !Sequencer.class.equals(typeClass)) { 177 return null; 178 } 179 String name = typeClass.getName(); 180 String value = AccessController.doPrivileged( 181 (PrivilegedAction<String>) () -> System.getProperty(name)); 182 if (value == null) { 183 value = getProperties().getProperty(name); 184 } 185 if ("".equals(value)) { 186 value = null; 187 } 188 return value; 189 } 190 191 /** Obtain a properties bundle containing property values from the 192 properties file. If the properties file could not be loaded, 193 the properties bundle is empty. 194 */ 195 private static synchronized Properties getProperties() { 196 if (properties == null) { 197 properties = new Properties(); 198 JSSecurityManager.loadProperties(properties, PROPERTIES_FILENAME); 199 } 200 return properties; 201 } 202 } |