This commit is contained in:
Tim Bell 2009-02-05 09:24:45 -08:00
commit 354177b550
587 changed files with 55316 additions and 4119 deletions

View File

@ -19,3 +19,4 @@ a2879b2837f5a4c87e9542efe69ef138194af8ff jdk7-b38
caf58ffa084568990cbb3441f9ae188e36b31770 jdk7-b42
41bd0a702bc8ec6feebd725a63e7c3227f82ab11 jdk7-b43
5843778bda89b1d5ac8e1aa05e26930ac90b3145 jdk7-b44
54dffad0bf066791a2793305875250c395011d5f jdk7-b45

View File

@ -19,3 +19,4 @@ ab523b49de1fc73fefe6855ce1e0349bdbd7af29 jdk7-b39
94052b87287303527125026fe4b2698cf867ea83 jdk7-b42
848e684279d2ba42577d9621d5b2e5af3823d12d jdk7-b43
a395e3aac4744cc9033fcd819fad1239a45add52 jdk7-b44
99846f001ca214015578d593802d26e27246a802 jdk7-b45

View File

@ -19,3 +19,4 @@ c90eeda9594ed2983403e2049aed8d503126c62e jdk7-b41
ccd6a16502e0650d91d85c4b86be05cbcd461a87 jdk7-b42
9cd740d48a4855321d69f137a7109c00bcda76be jdk7-b43
9803dac7254041b30ca65e3852d4c566b9757c3b jdk7-b44
68814aa5b44b1f16931a97e7cd4028c70eb9586b jdk7-b45

View File

@ -19,3 +19,4 @@ f9d938ede1960d18cb7cf23c645b026519c1a678 jdk7-b41
ad8c8ca4ab0f4c86e74c061958f44a8f4a930f2c jdk7-b42
fc6a5ae3fef5ebacfa896dbb3ae37715e388e282 jdk7-b43
809e899c638bd9b21836abf9d09ab2a30ff3900b jdk7-b44
945bf754069766e76873c53102fae48abf04cf5b jdk7-b45

View File

@ -19,3 +19,4 @@ e9f750f0a3a00413a7b77028b2ecdabb7129ae32 jdk7-b38
036e0dca841a5a17f784d15c86a9da88d2a6f1e6 jdk7-b42
96fe28d4a9131e1a97bfe00f779e5626cd09c4d0 jdk7-b43
b203df0741af3eb08687bc5eb798bac87363758d jdk7-b44
0f113667880d335cfa2c35721b1b45144fb757f5 jdk7-b45

View File

@ -19,3 +19,4 @@ a8379d24aa03386610169cb0f4e4b8ed266a2e8d jdk7-b41
621c02d83abc850c170fb6726d57b19f1eaf5033 jdk7-b42
1ad2f51564db6ca4c6d95760cf13fb083d3dec94 jdk7-b43
344485a03674b6950a7a23d01a6efb8055afb6ec jdk7-b44
dea7753d713936c5b6fd942a91811b0676537fd0 jdk7-b45

View File

@ -911,14 +911,6 @@ initial-image-jdk:: initial-image-jdk-setup \
fi; \
done
ifeq ($(PLATFORM), windows)
@#
@# Audio soundbank - Bug# 4236400
@# Windows only: adding audio files to JDK's jre/lib directory.
@#
($(CD) $(LIBDIR) && $(TAR) cf - \
`$(FIND) audio -depth -print`) | \
($(CD) $(JDK_IMAGE_DIR)/jre/lib && $(TAR) xf -)
@#
@#
@# lib/
@#

View File

@ -29,9 +29,7 @@
# Names of native shared libraries
PLUG_JSOUND_LIBRARY=$(LIB_PREFIX)jsoundhs.$(LIBRARY_SUFFIX)
PLUG_LIBRARY_NAMES = \
$(PLUG_JSOUND_LIBRARY)
PLUG_LIBRARY_NAMES=
# Sub-directory where native shared libraries are located (e.g. jre/bin or...)
@ -74,62 +72,10 @@ com/sun/jmx/snmp/daemon/SnmpSocket.class \
com/sun/jmx/snmp/daemon/SnmpTimerServer.class \
com/sun/jmx/snmp/daemon/WaitQ.class
PLUG_SOUND_CLASS_NAMES = \
com/sun/media/sound/AbstractPlayer.class \
com/sun/media/sound/CircularBuffer.class \
com/sun/media/sound/HeadspaceInstrument.class \
com/sun/media/sound/HeadspaceMixer\$$1.class \
com/sun/media/sound/HeadspaceMixer\$$MidiLine.class \
com/sun/media/sound/HeadspaceMixer\$$MidiLineInfo.class \
com/sun/media/sound/HeadspaceMixer\$$MixerInfo.class \
com/sun/media/sound/HeadspaceMixer\$$MixerReverbControl\$$MixerReverbType.class \
com/sun/media/sound/HeadspaceMixer\$$MixerReverbControl.class \
com/sun/media/sound/HeadspaceMixer.class \
com/sun/media/sound/HeadspaceMixerProvider.class \
com/sun/media/sound/HeadspaceSample.class \
com/sun/media/sound/HeadspaceSoundbank.class \
com/sun/media/sound/HsbParser.class \
com/sun/media/sound/MixerClip\$$1.class \
com/sun/media/sound/MixerClip\$$MixerClipApplyReverbControl.class \
com/sun/media/sound/MixerClip\$$MixerClipGainControl.class \
com/sun/media/sound/MixerClip\$$MixerClipMuteControl.class \
com/sun/media/sound/MixerClip\$$MixerClipPanControl.class \
com/sun/media/sound/MixerClip\$$MixerClipSampleRateControl.class \
com/sun/media/sound/MixerClip.class \
com/sun/media/sound/MixerMidiChannel.class \
com/sun/media/sound/MixerSequencer\$$1.class \
com/sun/media/sound/MixerSequencer\$$ControllerVectorElement.class \
com/sun/media/sound/MixerSequencer\$$MixerSequencerInfo.class \
com/sun/media/sound/MixerSequencer\$$RecordingTrack.class \
com/sun/media/sound/MixerSequencer.class \
com/sun/media/sound/MixerSequencerProvider.class \
com/sun/media/sound/MixerSourceLine\$$1.class \
com/sun/media/sound/MixerSourceLine\$$MixerSourceLineApplyReverbControl.class \
com/sun/media/sound/MixerSourceLine\$$MixerSourceLineGainControl.class \
com/sun/media/sound/MixerSourceLine\$$MixerSourceLineMuteControl.class \
com/sun/media/sound/MixerSourceLine\$$MixerSourceLinePanControl.class \
com/sun/media/sound/MixerSourceLine\$$MixerSourceLineSampleRateControl.class \
com/sun/media/sound/MixerSourceLine.class \
com/sun/media/sound/MixerSynth\$$1.class \
com/sun/media/sound/MixerSynth\$$MixerSynthInfo.class \
com/sun/media/sound/MixerSynth\$$SynthReceiver.class \
com/sun/media/sound/MixerSynth.class \
com/sun/media/sound/MixerSynthProvider.class \
com/sun/media/sound/MixerThread.class \
com/sun/media/sound/RmfFileReader.class \
com/sun/media/sound/SimpleInputDevice\$$1.class \
com/sun/media/sound/SimpleInputDevice\$$InputDeviceDataLine.class \
com/sun/media/sound/SimpleInputDevice\$$InputDevicePort.class \
com/sun/media/sound/SimpleInputDevice\$$InputDevicePortInfo.class \
com/sun/media/sound/SimpleInputDevice.class \
com/sun/media/sound/SimpleInputDeviceProvider\$$1.class \
com/sun/media/sound/SimpleInputDeviceProvider\$$InputDeviceInfo.class \
com/sun/media/sound/SimpleInputDeviceProvider.class
# Class list temp files (used by both import and export of plugs)
PLUG_TEMPDIR=$(ABS_TEMPDIR)/plugs
PLUG_CLASS_AREAS = jmf sound
PLUG_CLASS_AREAS = jmf
PLUG_CLISTS = $(PLUG_CLASS_AREAS:%=$(PLUG_TEMPDIR)/%.clist)
# Create jargs file command
@ -147,18 +93,11 @@ $(PLUG_TEMPDIR)/jmf.clist:
@for i in $(PLUG_JMF_CLASS_NAMES) ; do \
$(ECHO) "$$i" >> $@; \
done
$(PLUG_TEMPDIR)/sound.clist:
@$(prep-target)
@for i in $(PLUG_SOUND_CLASS_NAMES) ; do \
$(ECHO) "$$i" >> $@ ; \
done
$(PLUG_TEMPDIR)/all.clist: $(PLUG_CLISTS)
@$(prep-target)
$(CAT) $(PLUG_CLISTS) > $@
$(PLUG_TEMPDIR)/jmf.jargs: $(PLUG_TEMPDIR)/jmf.clist
$(plug-create-jargs)
$(PLUG_TEMPDIR)/sound.jargs: $(PLUG_TEMPDIR)/sound.clist
$(plug-create-jargs)
$(PLUG_TEMPDIR)/all.jargs: $(PLUG_TEMPDIR)/all.clist
$(plug-create-jargs)
@ -193,25 +132,11 @@ endef # import-binary-plug-classes
import-binary-plug-jmf-classes: $(PLUG_IMPORT_JARFILE) $(PLUG_TEMPDIR)/jmf.clist
$(call import-binary-plug-classes,$(PLUG_TEMPDIR)/jmf.clist)
import-binary-plug-sound-classes: $(PLUG_IMPORT_JARFILE) $(PLUG_TEMPDIR)/sound.clist
$(call import-binary-plug-classes,$(PLUG_TEMPDIR)/sound.clist)
# Import all classes from the jar file
import-binary-plug-jar: \
import-binary-plug-jmf-classes \
import-binary-plug-sound-classes
# Import native libraries
$(LIB_LOCATION)/$(PLUG_JSOUND_LIBRARY): \
$(PLUG_IMPORT_DIR)/$(PLUG_LOCATION_SUBDIR)/$(PLUG_JSOUND_LIBRARY)
$(import-binary-plug-file)
# Rules only used by lower level makefiles
import-binary-plug-jsound-library: \
$(LIB_LOCATION)/$(PLUG_JSOUND_LIBRARY)
import-binary-plug-jmf-classes
# Binary plug start/complete messages
@ -241,9 +166,7 @@ import-binary-plugs: \
import-binary-plugs-libs \
import-binary-plugs \
import-binary-plug-jar \
import-binary-plug-jmf-classes \
import-binary-plug-sound-classes \
import-binary-plug-jsound-library
import-binary-plug-jmf-classes
else # !OPENJDK
@ -280,12 +203,6 @@ $(PLUG_EXPORT_JARFILE): $(PLUG_TEMPDIR)/all.clist $(PLUG_TEMPDIR)/all.jargs
@$(java-vm-cleanup)
export-binary-plugs-jar: $(PLUG_EXPORT_JARFILE)
# Export native libraries
$(PLUG_EXPORT_DIR)/$(PLUG_LOCATION_SUBDIR)/$(PLUG_JSOUND_LIBRARY): \
$(LIB_LOCATION)/$(PLUG_JSOUND_LIBRARY)
$(export-binary-plug-file)
# Export binary plug start/complete messages
export-binary-plugs-started:

View File

@ -53,18 +53,6 @@ include FILES_c.gmk
# add java files
AUTO_FILES_JAVA_DIRS = javax/sound com/sun/media/sound
#
# Specific to OpenJDK building
#
ifdef OPENJDK
# copy closed .class files
build: import-binary-plug-sound-classes
include $(BUILDDIR)/common/internal/BinaryPlugs.gmk
endif # OPENJDK
#
# Files that just need cp.
#
@ -79,13 +67,11 @@ FILES_copy = \
$(SERVICEDIR)/javax.sound.sampled.spi.AudioFileReader \
$(SERVICEDIR)/javax.sound.sampled.spi.FormatConversionProvider \
$(SERVICEDIR)/javax.sound.sampled.spi.MixerProvider \
$(LIBDIR)/audio/soundbank.gm \
$(LIBDIR)/sound.properties
FILES_mkdirs = \
$(CLASSBINDIR)/META-INF \
$(CLASSBINDIR)/META-INF/services \
$(LIBDIR)/audio
$(CLASSBINDIR)/META-INF/services
FILES_copydirs = \
$(CLASSBINDIR) \
@ -95,11 +81,6 @@ FILES_copydirs = \
FILES_c += $(FILES_$(PLATFORM))
#
# add "closed" library
#
SUBDIRS += jsoundhs
#
# system dependent flags
#

View File

@ -1,91 +0,0 @@
#
# Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation. Sun designates this
# particular file as subject to the "Classpath" exception as provided
# by Sun in the LICENSE file that accompanied this code.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
# CA 95054 USA or visit www.sun.com if you need additional information or
# have any questions.
#
FILES_c = \
Utilities.c \
MixerThread.c \
HeadspaceMixer.c \
MixerClip.c \
MixerSourceLine.c \
SimpleInputDevice.c \
SimpleInputDeviceProvider.c \
HeadspaceSoundbank.c \
MixerMidiChannel.c \
AbstractPlayer.c \
MixerSequencer.c \
MixerSynth.c
FILES_engine = \
DriverTools.c \
GenAudioCaptureStreams.c \
GenAudioStreams.c \
GenOutput.c \
GenPatch.c \
GenReverb.c \
GenSample.c \
GenSeq.c \
GenSetup.c \
GenSong.c \
GenSynth.c \
GenSynthFilters.c \
GenSynthInterp2.c \
GenSynthResample.c \
NewNewLZSS.c \
SampleTools.c \
SMOD_Volume_Scaler.c \
X_API.c \
X_Decompress.c \
X_IMA.c \
GenFiltersReverb.c \
GenInterp2Reverb.c \
GenSoundFiles.c \
SincResample.c
FILES_solaris = \
HAE_API_SolarisOS.c \
HAE_API_SolarisOS_Capture.c
FILES_linux = \
HAE_API_LinuxOS.c \
HAE_API_LinuxOS_Capture.c
FILES_windows = \
HAE_API_WinOS.c \
HAE_API_WinOS_Capture.c \
HAE_API_WinOS_Synth.c
FILES_export = \
com/sun/media/sound/AbstractPlayer.java \
com/sun/media/sound/HeadspaceMixer.java \
com/sun/media/sound/HeadspaceSoundbank.java \
com/sun/media/sound/MixerClip.java \
com/sun/media/sound/MixerMidiChannel.java \
com/sun/media/sound/MixerSequencer.java \
com/sun/media/sound/MixerSourceLine.java \
com/sun/media/sound/MixerSynth.java \
com/sun/media/sound/MixerThread.java \
com/sun/media/sound/SimpleInputDevice.java \
com/sun/media/sound/SimpleInputDeviceProvider.java

View File

@ -1,100 +0,0 @@
#
# Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation. Sun designates this
# particular file as subject to the "Classpath" exception as provided
# by Sun in the LICENSE file that accompanied this code.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
# CA 95054 USA or visit www.sun.com if you need additional information or
# have any questions.
#
BUILDDIR = ../../..
PACKAGE = javax.sound
LIBRARY = jsoundhs
PRODUCT = sun
CPLUSPLUSLIBRARY = true
include $(BUILDDIR)/common/Defs.gmk
# this Makefile compiles "closed" JavaSound library
ifdef OPENJDK
# precompiled lib will be copied by the rules in Library.gmk instead of compiling.
USE_BINARY_PLUG_LIBRARY=true
build: import-binary-plug-jsound-library
include $(BUILDDIR)/common/internal/BinaryPlugs.gmk
else # OPENJDK
# include defines for sound
include ../SoundDefs.gmk
#
# Add use of mapfile
#
FILES_m = mapfile-vers
include $(BUILDDIR)/common/Mapfile-vers.gmk
#
# Files
#
include FILES.gmk
FILES_c += $(FILES_engine) $(FILES_$(PLATFORM))
#
# Extra cc/linker flags.
#
# flags needed for all platforms
CPPFLAGS += \
-DJAVA_SOUND -DJAVA_THREAD \
-I$(CLOSED_SHARE_SRC)/native/com/sun/media/sound \
-I$(CLOSED_SHARE_SRC)/native/com/sun/media/sound/engine
# system dependent flags
ifeq ($(PLATFORM), windows)
CPPFLAGS += -DUSE_DIRECTSOUND=0 \
-DUSE_EXTERNAL_SYNTH=TRUE
LDLIBS += winmm.lib
endif # PLATFORM windows
ifeq ($(PLATFORM), linux)
endif # PLATFORM linux
ifeq ($(PLATFORM), solaris)
endif # PLATFORM solaris
#
# Add to the ambient VPATH.
#
vpath %.c $(CLOSED_SHARE_SRC)/native/com/sun/media/sound
vpath %.c $(CLOSED_SHARE_SRC)/native/com/sun/media/sound/engine
vpath %.c $(CLOSED_PLATFORM_SRC)/native/com/sun/media/sound/engine
endif # OPENJDK
#
# Include rules
#
include $(BUILDDIR)/common/Library.gmk

View File

@ -1,153 +0,0 @@
#
# Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation. Sun designates this
# particular file as subject to the "Classpath" exception as provided
# by Sun in the LICENSE file that accompanied this code.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
# CA 95054 USA or visit www.sun.com if you need additional information or
# have any questions.
#
# Define library interface.
SUNWprivate_1.1 {
global:
Java_com_sun_media_sound_AbstractPlayer_nAddReceiver;
Java_com_sun_media_sound_AbstractPlayer_nClose;
Java_com_sun_media_sound_AbstractPlayer_nLoadInstrument;
Java_com_sun_media_sound_AbstractPlayer_nRemapInstrument;
Java_com_sun_media_sound_AbstractPlayer_nRemoveReceiver;
Java_com_sun_media_sound_AbstractPlayer_nUnloadInstrument;
Java_com_sun_media_sound_HeadspaceMixer_nAllocateVoices;
Java_com_sun_media_sound_HeadspaceMixer_nCloseMixer;
Java_com_sun_media_sound_HeadspaceMixer_nCreateLinkedStreams;
Java_com_sun_media_sound_HeadspaceMixer_nDrain;
Java_com_sun_media_sound_HeadspaceMixer_nFlush;
Java_com_sun_media_sound_HeadspaceMixer_nGetCpuLoad;
Java_com_sun_media_sound_HeadspaceMixer_nGetDefaultBufferSize;
Java_com_sun_media_sound_HeadspaceMixer_nGetLevel;
Java_com_sun_media_sound_HeadspaceMixer_nGetPosition;
Java_com_sun_media_sound_HeadspaceMixer_nGetTotalVoices;
Java_com_sun_media_sound_HeadspaceMixer_nOpenMixer;
Java_com_sun_media_sound_HeadspaceMixer_nPause;
Java_com_sun_media_sound_HeadspaceMixer_nResume;
Java_com_sun_media_sound_HeadspaceMixer_nSetInterpolation;
Java_com_sun_media_sound_HeadspaceMixer_nSetMixerFormat;
Java_com_sun_media_sound_HeadspaceMixer_nSetMixLevel;
Java_com_sun_media_sound_HeadspaceMixer_nSetReverb;
Java_com_sun_media_sound_HeadspaceMixer_nStartLinkedStreams;
Java_com_sun_media_sound_HeadspaceMixer_nStopLinkedStreams;
Java_com_sun_media_sound_HeadspaceSoundbank_nCloseResource;
Java_com_sun_media_sound_HeadspaceSoundbank_nGetInstruments;
Java_com_sun_media_sound_HeadspaceSoundbank_nGetName;
Java_com_sun_media_sound_HeadspaceSoundbank_nGetSamples;
Java_com_sun_media_sound_HeadspaceSoundbank_nGetVersionMajor;
Java_com_sun_media_sound_HeadspaceSoundbank_nGetVersionMinor;
Java_com_sun_media_sound_HeadspaceSoundbank_nGetVersionSubMinor;
Java_com_sun_media_sound_HeadspaceSoundbank_nOpenResource;
Java_com_sun_media_sound_HeadspaceSoundbank_nOpenResourceFromByteArray;
Java_com_sun_media_sound_MixerClip_nClose;
Java_com_sun_media_sound_MixerClip_nDrain;
Java_com_sun_media_sound_MixerClip_nFlush;
Java_com_sun_media_sound_MixerClip_nGetPosition;
Java_com_sun_media_sound_MixerClip_nOpen;
Java_com_sun_media_sound_MixerClip_nSetLinearGain;
Java_com_sun_media_sound_MixerClip_nSetPan;
Java_com_sun_media_sound_MixerClip_nSetSampleRate;
Java_com_sun_media_sound_MixerClip_nSetup;
Java_com_sun_media_sound_MixerClip_nStart;
Java_com_sun_media_sound_MixerClip_nStop;
Java_com_sun_media_sound_MixerMidiChannel_nAllNotesOff;
Java_com_sun_media_sound_MixerMidiChannel_nControlChange;
Java_com_sun_media_sound_MixerMidiChannel_nGetController;
Java_com_sun_media_sound_MixerMidiChannel_nGetPitchBend;
Java_com_sun_media_sound_MixerMidiChannel_nGetSolo;
Java_com_sun_media_sound_MixerMidiChannel_nNoteOff;
Java_com_sun_media_sound_MixerMidiChannel_nNoteOn;
Java_com_sun_media_sound_MixerMidiChannel_nProgramChange__JIIIJ;
Java_com_sun_media_sound_MixerMidiChannel_nProgramChange__JIIJ;
Java_com_sun_media_sound_MixerMidiChannel_nResetAllControllers;
Java_com_sun_media_sound_MixerMidiChannel_nSetMute;
Java_com_sun_media_sound_MixerMidiChannel_nSetPitchBend;
Java_com_sun_media_sound_MixerMidiChannel_nSetSolo;
Java_com_sun_media_sound_MixerSequencer_nAddControllerEventCallback;
Java_com_sun_media_sound_MixerSequencer_nGetMasterTempo;
Java_com_sun_media_sound_MixerSequencer_nGetSequenceMicrosecondLength;
Java_com_sun_media_sound_MixerSequencer_nGetSequencerMicrosecondPosition;
Java_com_sun_media_sound_MixerSequencer_nGetSequencerTickPosition;
Java_com_sun_media_sound_MixerSequencer_nGetSequenceTickLength;
Java_com_sun_media_sound_MixerSequencer_nGetTempoInBPM;
Java_com_sun_media_sound_MixerSequencer_nGetTempoInMPQ;
Java_com_sun_media_sound_MixerSequencer_nGetTrackMute;
Java_com_sun_media_sound_MixerSequencer_nGetTrackSolo;
Java_com_sun_media_sound_MixerSequencer_nOpenMidiSequencer;
Java_com_sun_media_sound_MixerSequencer_nOpenRmfSequencer;
Java_com_sun_media_sound_MixerSequencer_nPauseSequencer;
Java_com_sun_media_sound_MixerSequencer_nResumeSequencer;
Java_com_sun_media_sound_MixerSequencer_nSetMasterTempo;
Java_com_sun_media_sound_MixerSequencer_nSetSequencerMicrosecondPosition;
Java_com_sun_media_sound_MixerSequencer_nSetSequencerTickPosition;
Java_com_sun_media_sound_MixerSequencer_nSetTempoInBPM;
Java_com_sun_media_sound_MixerSequencer_nSetTempoInMPQ;
Java_com_sun_media_sound_MixerSequencer_nSetTrackMute;
Java_com_sun_media_sound_MixerSequencer_nSetTrackSolo;
Java_com_sun_media_sound_MixerSequencer_nStartSequencer;
Java_com_sun_media_sound_MixerSourceLine_nClose;
Java_com_sun_media_sound_MixerSourceLine_nDrain;
Java_com_sun_media_sound_MixerSourceLine_nFlush;
Java_com_sun_media_sound_MixerSourceLine_nGetLevel;
Java_com_sun_media_sound_MixerSourceLine_nGetPosition;
Java_com_sun_media_sound_MixerSourceLine_nOpen;
Java_com_sun_media_sound_MixerSourceLine_nPause;
Java_com_sun_media_sound_MixerSourceLine_nResume;
Java_com_sun_media_sound_MixerSourceLine_nSetLinearGain;
Java_com_sun_media_sound_MixerSourceLine_nSetPan;
Java_com_sun_media_sound_MixerSourceLine_nSetSampleRate;
Java_com_sun_media_sound_MixerSourceLine_nStart;
Java_com_sun_media_sound_MixerSynth_nCreateSynthesizer;
Java_com_sun_media_sound_MixerSynth_nDestroySynthesizer;
Java_com_sun_media_sound_MixerSynth_nGetLatency;
Java_com_sun_media_sound_MixerSynth_nLoadInstrument;
Java_com_sun_media_sound_MixerSynth_nRemapInstrument;
Java_com_sun_media_sound_MixerSynth_nStartSynthesizer;
Java_com_sun_media_sound_MixerSynth_nUnloadInstrument;
Java_com_sun_media_sound_MixerThread_runNative;
Java_com_sun_media_sound_SimpleInputDevice_nClose;
Java_com_sun_media_sound_SimpleInputDevice_nDrain;
Java_com_sun_media_sound_SimpleInputDevice_nFlush;
Java_com_sun_media_sound_SimpleInputDevice_nGetBufferSizeInFrames;
Java_com_sun_media_sound_SimpleInputDevice_nGetFormats;
Java_com_sun_media_sound_SimpleInputDevice_nGetNumPorts;
Java_com_sun_media_sound_SimpleInputDevice_nGetPortName;
Java_com_sun_media_sound_SimpleInputDevice_nGetPosition;
Java_com_sun_media_sound_SimpleInputDevice_nOpen;
Java_com_sun_media_sound_SimpleInputDevice_nPause;
Java_com_sun_media_sound_SimpleInputDevice_nResume;
Java_com_sun_media_sound_SimpleInputDevice_nStart;
Java_com_sun_media_sound_SimpleInputDevice_nStop;
Java_com_sun_media_sound_SimpleInputDevice_nSupportsChannels;
Java_com_sun_media_sound_SimpleInputDevice_nSupportsSampleRate;
Java_com_sun_media_sound_SimpleInputDevice_nSupportsSampleSizeInBits;
Java_com_sun_media_sound_SimpleInputDeviceProvider_nGetDescription;
Java_com_sun_media_sound_SimpleInputDeviceProvider_nGetName;
Java_com_sun_media_sound_SimpleInputDeviceProvider_nGetNumDevices;
Java_com_sun_media_sound_SimpleInputDeviceProvider_nGetVendor;
Java_com_sun_media_sound_SimpleInputDeviceProvider_nGetVersion;
local:
*;
};

View File

@ -21,4 +21,4 @@
# CA 95054 USA or visit www.sun.com if you need additional information or
# have any questions.
#
tzdata2008e
tzdata2009a

View File

@ -458,11 +458,36 @@ Zone Africa/Nouakchott -1:03:48 - LMT 1912
# http://www.worldtimezone.com/dst_news/dst_news_mauritius02.html
# </a>
# From Riad M. Hossen Ally (2008-08-03):
# The Government of Mauritius weblink
# <a href="http://www.gov.mu/portal/site/pmosite/menuitem.4ca0efdee47462e7440a600248a521ca/?content_id=3D4728ca68b2a5b110VgnVCM1000000a04a8c0RCRD">
# http://www.gov.mu/portal/site/pmosite/menuitem.4ca0efdee47462e7440a600248a521ca/?content_id=3D4728ca68b2a5b110VgnVCM1000000a04a8c0RCRD
# </a>
# Cabinet Decision of July 18th, 2008 states as follows:
#
# 4. ...Cabinet has agreed to the introduction into the National Assembly
# of the Time Bill which provides for the introduction of summer time in
# Mauritius. The summer time period which will be of one hour ahead of
# the standard time, will be aligned with that in Europe and the United
# States of America. It will start at two o'clock in the morning on the
# last Sunday of October and will end at two o'clock in the morning on
# the last Sunday of March the following year. The summer time for the
# year 2008 - 2009 will, therefore, be effective as from 26 October 2008
# and end on 29 March 2009.
# From Ed Maste (2008-10-07):
# THE TIME BILL (No. XXVII of 2008) Explanatory Memorandum states the
# beginning / ending of summer time is 2 o'clock standard time in the
# morning of the last Sunday of October / last Sunday of March.
# <a href="http://www.gov.mu/portal/goc/assemblysite/file/bill2708.pdf">
# http://www.gov.mu/portal/goc/assemblysite/file/bill2708.pdf
# </a>
# Rule NAME FROM TO TYPE IN ON AT SAVE LETTER/S
Rule Mauritius 1982 only - Oct 10 0:00 1:00 S
Rule Mauritius 1983 only - Mar 21 0:00 0 -
Rule Mauritius 2008 only - Oct 26 2:00s 1:00 S
Rule Mauritius 2009 only - Mar 27 2:00s 0 -
Rule Mauritius 2008 max - Oct lastSun 2:00s 1:00 S
Rule Mauritius 2009 max - Mar lastSun 2:00s 0 -
# Zone NAME GMTOFF RULES FORMAT [UNTIL]
Zone Indian/Mauritius 3:50:00 - LMT 1907 # Port Louis
4:00 Mauritius MU%sT # Mauritius Time
@ -547,7 +572,22 @@ Zone Indian/Mayotte 3:00:56 - LMT 1911 Jul # Mamoutzou
# From Arthur David Olson (2008-05-09):
# XXX--guess that it is only Morocco for now; guess only 2008 for now.
# From Steffen Thorsen (2008-08-27):
# Morocco will change the clocks back on the midnight between August 31
# and September 1. They originally planned to observe DST to near the end
# of September:
#
# One article about it (in French):
# <a href="http://www.menara.ma/fr/Actualites/Maroc/Societe/ci.retour_a_l_heure_gmt_a_partir_du_dimanche_31_aout_a_minuit_officiel_.default">
# http://www.menara.ma/fr/Actualites/Maroc/Societe/ci.retour_a_l_heure_gmt_a_partir_du_dimanche_31_aout_a_minuit_officiel_.default
# </a>
#
# We have some further details posted here:
# <a href="http://www.timeanddate.com/news/time/morocco-ends-dst-early-2008.html">
# http://www.timeanddate.com/news/time/morocco-ends-dst-early-2008.html
# </a>
# RULE NAME FROM TO TYPE IN ON AT SAVE LETTER/S
Rule Morocco 1939 only - Sep 12 0:00 1:00 S
Rule Morocco 1939 only - Nov 19 0:00 0 -
Rule Morocco 1940 only - Feb 25 0:00 1:00 S
@ -564,7 +604,7 @@ Rule Morocco 1977 only - Sep 28 0:00 0 -
Rule Morocco 1978 only - Jun 1 0:00 1:00 S
Rule Morocco 1978 only - Aug 4 0:00 0 -
Rule Morocco 2008 only - Jun 1 0:00 1:00 S
Rule Morocco 2008 only - Sep 28 0:00 0 -
Rule Morocco 2008 only - Sep 1 0:00 0 -
# Zone NAME GMTOFF RULES FORMAT [UNTIL]
Zone Africa/Casablanca -0:30:20 - LMT 1913 Oct 26
0:00 Morocco WE%sT 1984 Mar 16

View File

@ -1496,7 +1496,7 @@ Zone Asia/Choibalsan 7:38:00 - LMT 1905 Aug
# Nepal
# Zone NAME GMTOFF RULES FORMAT [UNTIL]
Zone Asia/Katmandu 5:41:16 - LMT 1920
Zone Asia/Kathmandu 5:41:16 - LMT 1920
5:30 - IST 1986
5:45 - NPT # Nepal Time
@ -1563,11 +1563,24 @@ Zone Asia/Muscat 3:54:20 - LMT 1920
# From Arthur David Olson (2008-05-19):
# XXX--midnight transitions is a guess; 2008 only is a guess.
# From Alexander Krivenyshev (2008-08-28):
# Pakistan government has decided to keep the watches one-hour advanced
# for another 2 months--plan to return to Standard Time on October 31
# instead of August 31.
#
# <a href="http://www.worldtimezone.com/dst_news/dst_news_pakistan02.html">
# http://www.worldtimezone.com/dst_news/dst_news_pakistan02.html
# </a>
# OR
# <a href="http://dailymailnews.com/200808/28/news/dmbrn03.html">
# http://dailymailnews.com/200808/28/news/dmbrn03.html
# </a>
# Rule NAME FROM TO TYPE IN ON AT SAVE LETTER/S
Rule Pakistan 2002 only - Apr Sun>=2 0:01 1:00 S
Rule Pakistan 2002 only - Oct Sun>=2 0:01 0 -
Rule Pakistan 2008 only - Jun 1 0:00 1:00 S
Rule Pakistan 2008 only - Sep 1 0:00 0 -
Rule Pakistan 2008 only - Nov 1 0:00 0 -
# Zone NAME GMTOFF RULES FORMAT [UNTIL]
Zone Asia/Karachi 4:28:12 - LMT 1907
5:30 - IST 1942 Sep
@ -1687,6 +1700,23 @@ Zone Asia/Karachi 4:28:12 - LMT 1907
# For lack of better information, predict that future changes will be
# the 2nd Thursday of September at 02:00.
# From Alexander Krivenyshev (2008-08-28):
# Here is an article, that Mideast running on different clocks at Ramadan.
#
# Gaza Strip (as Egypt) ended DST at midnight Thursday (Aug 28, 2008), while
# the West Bank will end Daylight Saving Time at midnight Sunday (Aug 31, 2008).
#
# <a href="http://www.guardian.co.uk/world/feedarticle/7759001">
# http://www.guardian.co.uk/world/feedarticle/7759001
# </a>
# <a href="http://www.abcnews.go.com/International/wireStory?id=5676087">
# http://www.abcnews.go.com/International/wireStory?id=5676087
# </a>
# or
# <a href="http://www.worldtimezone.com/dst_news/dst_news_gazastrip01.html">
# http://www.worldtimezone.com/dst_news/dst_news_gazastrip01.html
# </a>
# The rules for Egypt are stolen from the `africa' file.
# Rule NAME FROM TO TYPE IN ON AT SAVE LETTER/S
Rule EgyptAsia 1957 only - May 10 0:00 1:00 S
@ -1702,7 +1732,8 @@ Rule Palestine 2004 only - Oct 1 1:00 0 -
Rule Palestine 2005 only - Oct 4 2:00 0 -
Rule Palestine 2006 max - Apr 1 0:00 1:00 S
Rule Palestine 2006 only - Sep 22 0:00 0 -
Rule Palestine 2007 max - Sep Thu>=8 2:00 0 -
Rule Palestine 2007 only - Sep Thu>=8 2:00 0 -
Rule Palestine 2008 max - Aug lastThu 2:00 0 -
# Zone NAME GMTOFF RULES FORMAT [UNTIL]
Zone Asia/Gaza 2:17:52 - LMT 1900 Oct
@ -1948,8 +1979,20 @@ Rule Syria 2007 only - Nov Fri>=1 0:00 0 -
# compilers can't handle or having multiple Rules (a la Israel).
# For now, use "Apr Fri>=1", and go with IATA on a uniform Sep 30 end.
# From Steffen Thorsen (2008-10-07):
# Syria has now officially decided to end DST on 2008-11-01 this year,
# according to the following article in the Syrian Arab News Agency (SANA).
#
# The article is in Arabic, and seems to tell that they will go back to
# winter time on 2008-11-01 at 00:00 local daylight time (delaying/setting
# clocks back 60 minutes).
#
# <a href="http://sana.sy/ara/2/2008/10/07/195459.htm">
# http://sana.sy/ara/2/2008/10/07/195459.htm
# </a>
Rule Syria 2008 max - Apr Fri>=1 0:00 1:00 S
Rule Syria 2008 max - Oct 1 0:00 0 -
Rule Syria 2008 max - Nov 1 0:00 0 -
# Zone NAME GMTOFF RULES FORMAT [UNTIL]
Zone Asia/Damascus 2:25:12 - LMT 1920 # Dimashq

View File

@ -46,6 +46,7 @@ Link America/St_Thomas America/Virgin
Link Asia/Ashgabat Asia/Ashkhabad
Link Asia/Chongqing Asia/Chungking
Link Asia/Dhaka Asia/Dacca
Link Asia/Kathmandu Asia/Katmandu
Link Asia/Kolkata Asia/Calcutta
Link Asia/Macau Asia/Macao
Link Asia/Jerusalem Asia/Tel_Aviv

View File

@ -2335,11 +2335,64 @@ Zone Europe/Stockholm 1:12:12 - LMT 1879 Jan 1
# mean time in preference to apparent time -- Geneva from 1780 ....
# Rule NAME FROM TO TYPE IN ON AT SAVE LETTER/S
# From Whitman (who writes ``Midnight?''):
Rule Swiss 1940 only - Nov 2 0:00 1:00 S
Rule Swiss 1940 only - Dec 31 0:00 0 -
# Rule Swiss 1940 only - Nov 2 0:00 1:00 S
# Rule Swiss 1940 only - Dec 31 0:00 0 -
# From Shanks & Pottenger:
Rule Swiss 1941 1942 - May Sun>=1 2:00 1:00 S
Rule Swiss 1941 1942 - Oct Sun>=1 0:00 0 -
# Rule Swiss 1941 1942 - May Sun>=1 2:00 1:00 S
# Rule Swiss 1941 1942 - Oct Sun>=1 0:00 0 -
# From Alois Treindl (2008-12-17):
# I have researched the DST usage in Switzerland during the 1940ies.
#
# As I wrote in an earlier message, I suspected the current tzdata values
# to be wrong. This is now verified.
#
# I have found copies of the original ruling by the Swiss Federal
# government, in 'Eidgen[o]ssische Gesetzessammlung 1941 and 1942' (Swiss
# federal law collection)...
#
# DST began on Monday 5 May 1941, 1:00 am by shifting the clocks to 2:00 am
# DST ended on Monday 6 Oct 1941, 2:00 am by shifting the clocks to 1:00 am.
#
# DST began on Monday, 4 May 1942 at 01:00 am
# DST ended on Monday, 5 Oct 1942 at 02:00 am
#
# There was no DST in 1940, I have checked the law collection carefully.
# It is also indicated by the fact that the 1942 entry in the law
# collection points back to 1941 as a reference, but no reference to any
# other years are made.
#
# Newspaper articles I have read in the archives on 6 May 1941 reported
# about the introduction of DST (Sommerzeit in German) during the previous
# night as an absolute novelty, because this was the first time that such
# a thing had happened in Switzerland.
#
# I have also checked 1916, because one book source (Gabriel, Traite de
# l'heure dans le monde) claims that Switzerland had DST in 1916. This is
# false, no official document could be found. Probably Gabriel got misled
# by references to Germany, which introduced DST in 1916 for the first time.
#
# The tzdata rules for Switzerland must be changed to:
# Rule Swiss 1941 1942 - May Mon>=1 1:00 1:00 S
# Rule Swiss 1941 1942 - Oct Mon>=1 2:00 0 -
#
# The 1940 rules must be deleted.
#
# One further detail for Switzerland, which is probably out of scope for
# most users of tzdata:
# The zone file
# Zone Europe/Zurich 0:34:08 - LMT 1848 Sep 12
# 0:29:44 - BMT 1894 Jun #Bern Mean Time
# 1:00 Swiss CE%sT 1981
# 1:00 EU CE%sT
# describes all of Switzerland correctly, with the exception of
# the Cantone Geneve (Geneva, Genf). Between 1848 and 1894 Geneve did not
# follow Bern Mean Time but kept its own local mean time.
# To represent this, an extra zone would be needed.
# Rule NAME FROM TO TYPE IN ON AT SAVE LETTER/S
Rule Swiss 1941 1942 - May Mon>=1 1:00 1:00 S
Rule Swiss 1941 1942 - Oct Mon>=1 2:00 0 -
# Zone NAME GMTOFF RULES FORMAT [UNTIL]
Zone Europe/Zurich 0:34:08 - LMT 1848 Sep 12
0:29:44 - BMT 1894 Jun # Bern Mean Time
@ -2375,6 +2428,27 @@ Zone Europe/Zurich 0:34:08 - LMT 1848 Sep 12
# (on a non-government server though) describing dates between 2002 and 2006:
# http://www.alomaliye.com/bkk_2002_3769.htm
# From Sue Williams (2008-08-11):
# I spotted this news article about a potential change in Turkey.
#
# <a href="http://www.hurriyet.com.tr/english/domestic/9626174.asp?scr=1">
# http://www.hurriyet.com.tr/english/domestic/9626174.asp?scr=1
# </a>
# From Sue Williams (2008-08-20):
# This article says that around the end of March 2011, Turkey wants to
# adjust the clocks forward by 1/2 hour and stay that way permanently.
# The article indicates that this is a change in timezone offset in addition
# to stopping observance of DST.
# This proposal has not yet been approved.
#
# Read more here...
#
# Turkey to abandon daylight saving time in 2011
# <a href="http://www.turkishdailynews.com.tr/article.php?enewsid=112989">
# http://www.turkishdailynews.com.tr/article.php?enewsid=112989
# </a>
# Rule NAME FROM TO TYPE IN ON AT SAVE LETTER/S
Rule Turkey 1916 only - May 1 0:00 1:00 S
Rule Turkey 1916 only - Oct 1 0:00 0 -

View File

@ -1764,9 +1764,13 @@ Zone America/Dawson_Creek -8:00:56 - LMT 1884
# The individual that answered the phone confirmed that the clocks did not
# move at the end of daylight saving on October 29/2006. He also told me that
# the clocks did not move this past weekend (March 11/2007)....
#
# America/Resolute should use the "Canada" Rule up to October 29/2006.
# After that it should be fixed on Eastern Standard Time until further notice.
# From Chris Walton (2008-11-13):
# ...the residents of Resolute believe that they are changing "time zones"
# twice a year. In winter months, local time is qualified with "Eastern
# Time" which is really "Eastern Standard Time (UTC-5)". In summer
# months, local time is qualified with "Central Time" which is really
# "Central Daylight Time (UTC-5)"...
# Rule NAME FROM TO TYPE IN ON AT SAVE LETTER/S
Rule NT_YK 1918 only - Apr 14 2:00 1:00 D
@ -1794,11 +1798,14 @@ Zone America/Iqaluit 0 - zzz 1942 Aug # Frobisher Bay est.
-6:00 Canada C%sT 2000 Oct 29 2:00
-5:00 Canada E%sT
# aka Qausuittuq
# Rule NAME FROM TO TYPE IN ON AT SAVE LETTER/S
Rule Resolute 2006 max - Nov Sun>=1 2:00 0 ES
Rule Resolute 2007 max - Mar Sun>=8 2:00 0 CD
Zone America/Resolute 0 - zzz 1947 Aug 31 # Resolute founded
-6:00 NT_YK C%sT 2000 Oct 29 2:00
-5:00 - EST 2001 Apr 1 3:00
-6:00 Canada C%sT 2006 Oct 29 2:00
-5:00 - EST
-5:00 Resolute %sT
# aka Kangiqiniq
Zone America/Rankin_Inlet 0 - zzz 1957 # Rankin Inlet founded
-6:00 NT_YK C%sT 2000 Oct 29 2:00
@ -2302,7 +2309,7 @@ Rule Cuba 1996 only - Oct 6 0:00s 0 S
Rule Cuba 1997 only - Oct 12 0:00s 0 S
Rule Cuba 1998 1999 - Mar lastSun 0:00s 1:00 D
Rule Cuba 1998 2003 - Oct lastSun 0:00s 0 S
Rule Cuba 2000 2006 - Apr Sun>=1 0:00s 1:00 D
Rule Cuba 2000 2004 - Apr Sun>=1 0:00s 1:00 D
Rule Cuba 2006 max - Oct lastSun 0:00s 0 S
Rule Cuba 2007 only - Mar Sun>=8 0:00s 1:00 D
Rule Cuba 2008 max - Mar Sun>=15 0:00s 1:00 D

View File

@ -186,9 +186,58 @@ Rule Arg 2000 only - Mar 3 0:00 0 -
# From Paul Eggert (2007-12-22):
# For dates after mid-2008, the following rules are my guesses and
# are quite possibly wrong, but are more likely than no DST at all.
# From Alexander Krivenyshev (2008-09-05):
# As per message from Carlos Alberto Fonseca Arauz (Nicaragua),
# Argentina will start DST on Sunday October 19, 2008.
#
# <a href="http://www.worldtimezone.com/dst_news/dst_news_argentina03.html">
# http://www.worldtimezone.com/dst_news/dst_news_argentina03.html
# </a>
# OR
# <a href="http://www.impulsobaires.com.ar/nota.php?id=57832 (in spanish)">
# http://www.impulsobaires.com.ar/nota.php?id=57832 (in spanish)
# </a>
# From Rodrigo Severo (2008-10-06):
# Here is some info available at a Gentoo bug related to TZ on Argentina's DST:
# ...
# ------- Comment #1 from [jmdocile] 2008-10-06 16:28 0000 -------
# Hi, there is a problem with timezone-data-2008e and maybe with
# timezone-data-2008f
# Argentinian law [Number] 25.155 is no longer valid.
# <a href="http://www.infoleg.gov.ar/infolegInternet/anexos/60000-64999/60036/norma.htm">
# http://www.infoleg.gov.ar/infolegInternet/anexos/60000-64999/60036/norma.htm
# </a>
# The new one is law [Number] 26.350
# <a href="http://www.infoleg.gov.ar/infolegInternet/anexos/135000-139999/136191/norma.htm">
# http://www.infoleg.gov.ar/infolegInternet/anexos/135000-139999/136191/norma.htm
# </a>
# So there is no summer time in Argentina for now.
# From Mariano Absatz (2008-10-20):
# Decree 1693/2008 applies Law 26.350 for the summer 2008/2009 establishing DST in Argentina
# From 2008-10-19 until 2009-03-15
# <a href="http://www.boletinoficial.gov.ar/Bora.Portal/CustomControls/PdfContent.aspx?fp=16102008&pi=3&pf=4&s=0&sec=01">
# http://www.boletinoficial.gov.ar/Bora.Portal/CustomControls/PdfContent.aspx?fp=16102008&pi=3&pf=4&s=0&sec=01
# </a>
#
# Decree 1705/2008 excepting 12 Provinces from applying DST in the summer 2008/2009:
# Catamarca, La Rioja, Mendoza, Salta, San Juan, San Luis, La Pampa, Neuquen, Rio Negro, Chubut, Santa Cruz
# and Tierra del Fuego
# <a href="http://www.boletinoficial.gov.ar/Bora.Portal/CustomControls/PdfContent.aspx?fp=17102008&pi=1&pf=1&s=0&sec=01">
# http://www.boletinoficial.gov.ar/Bora.Portal/CustomControls/PdfContent.aspx?fp=17102008&pi=1&pf=1&s=0&sec=01
# </a>
#
# Press release 235 dated Saturday October 18th, from the Government of the Province of Jujuy saying
# it will not apply DST either (even when it was not included in Decree 1705/2008)
# <a href="http://www.jujuy.gov.ar/index2/partes_prensa/18_10_08/235-181008.doc">
# http://www.jujuy.gov.ar/index2/partes_prensa/18_10_08/235-181008.doc
# </a>
Rule Arg 2007 only - Dec 30 0:00 1:00 S
Rule Arg 2008 max - Mar Sun>=15 0:00 0 -
Rule Arg 2008 max - Oct Sun>=1 0:00 1:00 S
Rule Arg 2008 max - Oct Sun>=15 0:00 1:00 S
# From Mariano Absatz (2004-05-21):
# Today it was officially published that the Province of Mendoza is changing
@ -336,9 +385,8 @@ Zone America/Argentina/Buenos_Aires -3:53:48 - LMT 1894 Oct 31
-4:00 Arg AR%sT 2000 Mar 3
-3:00 Arg AR%sT
#
# Santa Fe (SF), Entre Rios (ER), Corrientes (CN), Misiones (MN), Chaco (CC),
# Formosa (FM), Salta (SA), Santiago del Estero (SE), Cordoba (CB),
# La Pampa (LP), Neuquen (NQ), Rio Negro (RN)
# Cordoba (CB), Santa Fe (SF), Entre Rios (ER), Corrientes (CN), Misiones (MN),
# Chaco (CC), Formosa (FM), Santiago del Estero (SE)
#
# Shanks & Pottenger also make the following claims, which we haven't verified:
# - Formosa switched to -3:00 on 1991-01-07.
@ -357,6 +405,18 @@ Zone America/Argentina/Cordoba -4:16:48 - LMT 1894 Oct 31
-4:00 Arg AR%sT 2000 Mar 3
-3:00 Arg AR%sT
#
# Salta (SA), La Pampa (LP), Neuquen (NQ), Rio Negro (RN)
Zone America/Argentina/Salta -4:21:40 - LMT 1894 Oct 31
-4:16:48 - CMT 1920 May
-4:00 - ART 1930 Dec
-4:00 Arg AR%sT 1969 Oct 5
-3:00 Arg AR%sT 1991 Mar 3
-4:00 - WART 1991 Oct 20
-3:00 Arg AR%sT 1999 Oct 3
-4:00 Arg AR%sT 2000 Mar 3
-3:00 Arg AR%sT 2008 Oct 18
-3:00 - ART
#
# Tucuman (TM)
Zone America/Argentina/Tucuman -4:20:52 - LMT 1894 Oct 31
-4:16:48 - CMT 1920 May
@ -381,7 +441,8 @@ Zone America/Argentina/La_Rioja -4:27:24 - LMT 1894 Oct 31
-4:00 Arg AR%sT 2000 Mar 3
-3:00 - ART 2004 Jun 1
-4:00 - WART 2004 Jun 20
-3:00 Arg AR%sT
-3:00 Arg AR%sT 2008 Oct 18
-3:00 - ART
#
# San Juan (SJ)
Zone America/Argentina/San_Juan -4:34:04 - LMT 1894 Oct 31
@ -394,7 +455,8 @@ Zone America/Argentina/San_Juan -4:34:04 - LMT 1894 Oct 31
-4:00 Arg AR%sT 2000 Mar 3
-3:00 - ART 2004 May 31
-4:00 - WART 2004 Jul 25
-3:00 Arg AR%sT
-3:00 Arg AR%sT 2008 Oct 18
-3:00 - ART
#
# Jujuy (JY)
Zone America/Argentina/Jujuy -4:21:12 - LMT 1894 Oct 31
@ -408,7 +470,8 @@ Zone America/Argentina/Jujuy -4:21:12 - LMT 1894 Oct 31
-3:00 1:00 ARST 1992
-3:00 Arg AR%sT 1999 Oct 3
-4:00 Arg AR%sT 2000 Mar 3
-3:00 Arg AR%sT
-3:00 Arg AR%sT 2008 Oct 18
-3:00 - ART
#
# Catamarca (CT), Chubut (CH)
Zone America/Argentina/Catamarca -4:23:08 - LMT 1894 Oct 31
@ -421,7 +484,8 @@ Zone America/Argentina/Catamarca -4:23:08 - LMT 1894 Oct 31
-4:00 Arg AR%sT 2000 Mar 3
-3:00 - ART 2004 Jun 1
-4:00 - WART 2004 Jun 20
-3:00 Arg AR%sT
-3:00 Arg AR%sT 2008 Oct 18
-3:00 - ART
#
# Mendoza (MZ)
Zone America/Argentina/Mendoza -4:35:16 - LMT 1894 Oct 31
@ -438,7 +502,8 @@ Zone America/Argentina/Mendoza -4:35:16 - LMT 1894 Oct 31
-4:00 Arg AR%sT 2000 Mar 3
-3:00 - ART 2004 May 23
-4:00 - WART 2004 Sep 26
-3:00 Arg AR%sT
-3:00 Arg AR%sT 2008 Oct 18
-3:00 - ART
#
# San Luis (SL)
Zone America/Argentina/San_Luis -4:25:24 - LMT 1894 Oct 31
@ -466,7 +531,8 @@ Zone America/Argentina/Rio_Gallegos -4:36:52 - LMT 1894 Oct 31
-4:00 Arg AR%sT 2000 Mar 3
-3:00 - ART 2004 Jun 1
-4:00 - WART 2004 Jun 20
-3:00 Arg AR%sT
-3:00 Arg AR%sT 2008 Oct 18
-3:00 - ART
#
# Tierra del Fuego, Antartida e Islas del Atlantico Sur (TF)
Zone America/Argentina/Ushuaia -4:33:12 - LMT 1894 Oct 31
@ -477,7 +543,8 @@ Zone America/Argentina/Ushuaia -4:33:12 - LMT 1894 Oct 31
-4:00 Arg AR%sT 2000 Mar 3
-3:00 - ART 2004 May 30
-4:00 - WART 2004 Jun 20
-3:00 Arg AR%sT
-3:00 Arg AR%sT 2008 Oct 18
-3:00 - ART
# Aruba
# Zone NAME GMTOFF RULES FORMAT [UNTIL]
@ -613,6 +680,36 @@ Zone America/La_Paz -4:32:36 - LMT 1890
# Decretos sobre o Horario de Verao no Brasil
# </a>.
# From Steffen Thorsen (2008-08-29):
# As announced by the government and many newspapers in Brazil late
# yesterday, Brazil will start DST on 2008-10-19 (need to change rule) and
# it will end on 2009-02-15 (current rule for Brazil is fine). Based on
# past years experience with the elections, there was a good chance that
# the start was postponed to November, but it did not happen this year.
#
# It has not yet been posted to http://pcdsh01.on.br/DecHV.html
#
# An official page about it:
# <a href="http://www.mme.gov.br/site/news/detail.do?newsId=16722">
# http://www.mme.gov.br/site/news/detail.do?newsId=16722
# </a>
# Note that this link does not always work directly, but must be accessed
# by going to
# <a href="http://www.mme.gov.br/first">
# http://www.mme.gov.br/first
# </a>
#
# One example link that works directly:
# <a href="http://jornale.com.br/index.php?option=com_content&task=view&id=13530&Itemid=54">
# http://jornale.com.br/index.php?option=com_content&task=view&id=13530&Itemid=54
# (Portuguese)
# </a>
#
# We have a written a short article about it as well:
# <a href="http://www.timeanddate.com/news/time/brazil-dst-2008-2009.html">
# http://www.timeanddate.com/news/time/brazil-dst-2008-2009.html
# </a>
# Rule NAME FROM TO TYPE IN ON AT SAVE LETTER/S
# Decree <a href="http://pcdsh01.on.br/HV20466.htm">20,466</a> (1931-10-01)
# Decree <a href="http://pcdsh01.on.br/HV21896.htm">21,896</a> (1932-01-10)
@ -746,12 +843,34 @@ Rule Brazil 2006 only - Nov 5 0:00 1:00 S
Rule Brazil 2007 only - Feb 25 0:00 0 -
# Decree <a href="http://pcdsh01.on.br/DecHV6212.gif">6,212</a> (2007-09-26),
# adopted by the same states as before.
Rule Brazil 2007 max - Oct Sun>=8 0:00 1:00 S
Rule Brazil 2008 max - Feb Sun>=15 0:00 0 -
Rule Brazil 2007 only - Oct Sun>=8 0:00 1:00 S
# From Frederico A. C. Neves (2008-09-10):
# Acording to this decree
# <a href="http://www.planalto.gov.br/ccivil_03/_Ato2007-2010/2008/Decreto/D6558.htm">
# http://www.planalto.gov.br/ccivil_03/_Ato2007-2010/2008/Decreto/D6558.htm
# </a>
# [t]he DST period in Brazil now on will be from the 3rd Oct Sunday to the
# 3rd Feb Sunday. There is an exception on the return date when this is
# the Carnival Sunday then the return date will be the next Sunday...
Rule Brazil 2008 max - Oct Sun>=15 0:00 1:00 S
Rule Brazil 2008 2011 - Feb Sun>=15 0:00 0 -
Rule Brazil 2012 only - Feb Sun>=22 0:00 0 -
Rule Brazil 2013 2014 - Feb Sun>=15 0:00 0 -
Rule Brazil 2015 only - Feb Sun>=22 0:00 0 -
Rule Brazil 2016 2022 - Feb Sun>=15 0:00 0 -
Rule Brazil 2023 only - Feb Sun>=22 0:00 0 -
Rule Brazil 2024 2025 - Feb Sun>=15 0:00 0 -
Rule Brazil 2026 only - Feb Sun>=22 0:00 0 -
Rule Brazil 2027 2033 - Feb Sun>=15 0:00 0 -
Rule Brazil 2034 only - Feb Sun>=22 0:00 0 -
Rule Brazil 2035 2036 - Feb Sun>=15 0:00 0 -
Rule Brazil 2037 only - Feb Sun>=22 0:00 0 -
# From Arthur David Olson (2008-09-29):
# The next is wrong in some years but is better than nothing.
Rule Brazil 2038 max - Feb Sun>=15 0:00 0 -
# The latest ruleset listed above says that the following states observe DST:
# DF, ES, GO, MG, MS, MT, PR, RJ, RS, SC, SP.
# For dates after mid-2008, the above rules with TO="max" are guesses
# and are quite possibly wrong, but are more likely than no DST at all.
# Zone NAME GMTOFF RULES FORMAT [UNTIL]
#

View File

@ -64,14 +64,15 @@ AQ -7824+10654 Antarctica/Vostok Vostok Station, S Magnetic Pole
AQ -6640+14001 Antarctica/DumontDUrville Dumont-d'Urville Station, Terre Adelie
AQ -690022+0393524 Antarctica/Syowa Syowa Station, E Ongul I
AR -3436-05827 America/Argentina/Buenos_Aires Buenos Aires (BA, CF)
AR -3124-06411 America/Argentina/Cordoba most locations (CB, CC, CN, ER, FM, LP, MN, NQ, RN, SA, SE, SF)
AR -3319-06621 America/Argentina/San_Luis San Luis (SL)
AR -3124-06411 America/Argentina/Cordoba most locations (CB, CC, CN, ER, FM, MN, SE, SF)
AR -2447-06525 America/Argentina/Salta (SA, LP, NQ, RN)
AR -2411-06518 America/Argentina/Jujuy Jujuy (JY)
AR -2649-06513 America/Argentina/Tucuman Tucuman (TM)
AR -2828-06547 America/Argentina/Catamarca Catamarca (CT), Chubut (CH)
AR -2926-06651 America/Argentina/La_Rioja La Rioja (LR)
AR -3132-06831 America/Argentina/San_Juan San Juan (SJ)
AR -3253-06849 America/Argentina/Mendoza Mendoza (MZ)
AR -3319-06621 America/Argentina/San_Luis San Luis (SL)
AR -5138-06913 America/Argentina/Rio_Gallegos Santa Cruz (SC)
AR -5448-06818 America/Argentina/Ushuaia Tierra del Fuego (TF)
AS -1416-17042 Pacific/Pago_Pago
@ -137,7 +138,7 @@ CA +4901-08816 America/Nipigon Eastern Time - Ontario & Quebec - places that did
CA +4823-08915 America/Thunder_Bay Eastern Time - Thunder Bay, Ontario
CA +6344-06828 America/Iqaluit Eastern Time - east Nunavut - most locations
CA +6608-06544 America/Pangnirtung Eastern Time - Pangnirtung, Nunavut
CA +744144-0944945 America/Resolute Eastern Time - Resolute, Nunavut
CA +744144-0944945 America/Resolute Eastern Standard Time - Resolute, Nunavut
CA +484531-0913718 America/Atikokan Eastern Standard Time - Atikokan, Ontario and Southampton I, Nunavut
CA +624900-0920459 America/Rankin_Inlet Central Time - central Nunavut
CA +4953-09709 America/Winnipeg Central Time - Manitoba & west Ontario
@ -313,9 +314,9 @@ NG +0627+00324 Africa/Lagos
NI +1209-08617 America/Managua
NL +5222+00454 Europe/Amsterdam
NO +5955+01045 Europe/Oslo
NP +2743+08519 Asia/Katmandu
NP +2743+08519 Asia/Kathmandu
NR -0031+16655 Pacific/Nauru
NU -1901+16955 Pacific/Niue
NU -1901-16955 Pacific/Niue
NZ -3652+17446 Pacific/Auckland most locations
NZ -4357-17633 Pacific/Chatham Chatham Islands
OM +2336+05835 Asia/Muscat
@ -406,13 +407,13 @@ US +381515-0854534 America/Kentucky/Louisville Eastern Time - Kentucky - Louisvi
US +364947-0845057 America/Kentucky/Monticello Eastern Time - Kentucky - Wayne County
US +394606-0860929 America/Indiana/Indianapolis Eastern Time - Indiana - most locations
US +384038-0873143 America/Indiana/Vincennes Eastern Time - Indiana - Daviess, Dubois, Knox & Martin Counties
US +411745-0863730 America/Indiana/Knox Eastern Time - Indiana - Starke County
US +410305-0863611 America/Indiana/Winamac Eastern Time - Indiana - Pulaski County
US +382232-0862041 America/Indiana/Marengo Eastern Time - Indiana - Crawford County
US +382931-0871643 America/Indiana/Petersburg Eastern Time - Indiana - Pike County
US +384452-0850402 America/Indiana/Vevay Eastern Time - Indiana - Switzerland County
US +415100-0873900 America/Chicago Central Time
US +375711-0864541 America/Indiana/Tell_City Central Time - Indiana - Perry County
US +382931-0871643 America/Indiana/Petersburg Central Time - Indiana - Pike County
US +411745-0863730 America/Indiana/Knox Central Time - Indiana - Starke County
US +450628-0873651 America/Menominee Central Time - Michigan - Dickinson, Gogebic, Iron & Menominee Counties
US +470659-1011757 America/North_Dakota/Center Central Time - North Dakota - Oliver County
US +465042-1012439 America/North_Dakota/New_Salem Central Time - North Dakota - Morton County (except Mandan area)

View File

@ -1,479 +0,0 @@
/*
* Copyright 2003-2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.beans;
import com.sun.beans.finder.ClassFinder;
import java.beans.*;
import java.util.*;
import org.xml.sax.*;
import static java.util.Locale.ENGLISH;
/**
* <b>WARNING</b>: This class is an implementation detail and only meant
* for use within the core platform. You should NOT depend upon it! This
* API may change drastically between dot dot release, and it may even be
* removed.
*
* @see java.beans.XMLEncoder
* @see java.io.ObjectInputStream
*
* @since 1.4
*
* @author Philip Milne
*/
public class ObjectHandler extends HandlerBase {
public static Class typeNameToClass(String typeName) {
typeName = typeName.intern();
if (typeName == "boolean") return Boolean.class;
if (typeName == "byte") return Byte.class;
if (typeName == "char") return Character.class;
if (typeName == "short") return Short.class;
if (typeName == "int") return Integer.class;
if (typeName == "long") return Long.class;
if (typeName == "float") return Float.class;
if (typeName == "double") return Double.class;
if (typeName == "void") return Void.class;
return null;
}
public static Class typeNameToPrimitiveClass(String typeName) {
typeName = typeName.intern();
if (typeName == "boolean") return boolean.class;
if (typeName == "byte") return byte.class;
if (typeName == "char") return char.class;
if (typeName == "short") return short.class;
if (typeName == "int") return int.class;
if (typeName == "long") return long.class;
if (typeName == "float") return float.class;
if (typeName == "double") return double.class;
if (typeName == "void") return void.class;
return null;
}
/**
* Returns the <code>Class</code> object associated with
* the class or interface with the given string name,
* using the default class loader.
*
* @param name fully qualified name of the desired class
* @param cl class loader from which the class must be loaded
* @return class object representing the desired class
*
* @exception ClassNotFoundException if the class cannot be located
* by the specified class loader
*
* @deprecated As of JDK version 7, replaced by
* {@link ClassFinder#resolveClass(String)}.
*/
@Deprecated
public static Class classForName(String name) throws ClassNotFoundException {
return ClassFinder.resolveClass(name);
}
/**
* Returns the <code>Class</code> object associated with
* the class or interface with the given string name,
* using the given class loader.
*
* @param name fully qualified name of the desired class
* @param cl class loader from which the class must be loaded
* @return class object representing the desired class
*
* @exception ClassNotFoundException if the class cannot be located
* by the specified class loader
*
* @deprecated As of JDK version 7, replaced by
* {@link ClassFinder#resolveClass(String,ClassLoader)}.
*/
@Deprecated
public static Class classForName(String name, ClassLoader cl)
throws ClassNotFoundException {
return ClassFinder.resolveClass(name, cl);
}
private Hashtable environment;
private Vector expStack;
private StringBuffer chars;
private XMLDecoder is;
private ClassLoader ldr;
private int itemsRead = 0;
private boolean isString;
public ObjectHandler() {
environment = new Hashtable();
expStack = new Vector();
chars = new StringBuffer();
}
public ObjectHandler(XMLDecoder is) {
this();
this.is = is;
}
/* loader can be null */
public ObjectHandler(XMLDecoder is, ClassLoader loader) {
this(is);
this.ldr = loader;
}
public void reset() {
expStack.clear();
chars.setLength(0);
MutableExpression e = new MutableExpression();
e.setTarget(classForName2("java.lang.Object"));
e.setMethodName("null");
expStack.add(e);
}
private Object getValue(Expression exp) {
try {
return exp.getValue();
}
catch (Exception e) {
if (is != null) {
is.getExceptionListener().exceptionThrown(e);
}
return null;
}
}
private void addArg(Object arg) {
lastExp().addArg(arg);
}
private Object pop(Vector v) {
int last = v.size()-1;
Object result = v.get(last);
v.remove(last);
return result;
}
private Object eval() {
return getValue(lastExp());
}
private MutableExpression lastExp() {
return (MutableExpression)expStack.lastElement();
}
public Object dequeueResult() {
Object[] results = lastExp().getArguments();
return results[itemsRead++];
}
private boolean isPrimitive(String name) {
return name != "void" && typeNameToClass(name) != null;
}
private void simulateException(String message) {
Exception e = new Exception(message);
e.fillInStackTrace();
if (is != null) {
is.getExceptionListener().exceptionThrown(e);
}
}
private Class classForName2(String name) {
try {
return ClassFinder.resolveClass(name, this.ldr);
}
catch (ClassNotFoundException e) {
if (is != null) {
is.getExceptionListener().exceptionThrown(e);
}
}
return null;
}
private HashMap getAttributes(AttributeList attrs) {
HashMap attributes = new HashMap();
if (attrs != null && attrs.getLength() > 0) {
for(int i = 0; i < attrs.getLength(); i++) {
attributes.put(attrs.getName(i), attrs.getValue(i));
}
}
return attributes;
}
public void startElement(String name, AttributeList attrs) throws SAXException {
name = name.intern(); // Xerces parser does not supply unique tag names.
if (this.isString) {
parseCharCode(name, getAttributes(attrs));
return;
}
chars.setLength(0);
HashMap attributes = getAttributes(attrs);
MutableExpression e = new MutableExpression();
// Target
String className = (String)attributes.get("class");
if (className != null) {
e.setTarget(classForName2(className));
}
// Property
Object property = attributes.get("property");
String index = (String)attributes.get("index");
if (index != null) {
property = new Integer(index);
e.addArg(property);
}
e.setProperty(property);
// Method
String methodName = (String)attributes.get("method");
if (methodName == null && property == null) {
methodName = "new";
}
e.setMethodName(methodName);
// Tags
if (name == "string") {
e.setTarget(String.class);
e.setMethodName("new");
this.isString = true;
}
else if (isPrimitive(name)){
Class wrapper = typeNameToClass(name);
e.setTarget(wrapper);
e.setMethodName("new");
parseCharCode(name, attributes);
}
else if (name == "class") {
e.setTarget(Class.class);
e.setMethodName("forName");
}
else if (name == "null") {
// Create an arbitrary expression that has a value of null - for
// consistency.
e.setTarget(Object.class);
e.setMethodName("getSuperclass");
e.setValue(null);
}
else if (name == "void") {
if (e.getTarget() == null) { // this check is for "void class="foo" method= ..."
e.setTarget(eval());
}
}
else if (name == "array") {
// The class attribute means sub-type for arrays.
String subtypeName = (String)attributes.get("class");
Class subtype = (subtypeName == null) ? Object.class : classForName2(subtypeName);
String length = (String)attributes.get("length");
if (length != null) {
e.setTarget(java.lang.reflect.Array.class);
e.addArg(subtype);
e.addArg(new Integer(length));
}
else {
Class arrayClass = java.lang.reflect.Array.newInstance(subtype, 0).getClass();
e.setTarget(arrayClass);
}
}
else if (name == "java") {
e.setValue(is); // The outermost scope is the stream itself.
}
else if (name == "object") {
}
else {
simulateException("Unrecognized opening tag: " + name + " " + attrsToString(attrs));
return;
}
// ids
String idName = (String)attributes.get("id");
if (idName != null) {
environment.put(idName, e);
}
// idrefs
String idrefName = (String)attributes.get("idref");
if (idrefName != null) {
e.setValue(lookup(idrefName));
}
// fields
String fieldName = (String)attributes.get("field");
if (fieldName != null) {
e.setValue(getFieldValue(e.getTarget(), fieldName));
}
expStack.add(e);
}
private Object getFieldValue(Object target, String fieldName) {
try {
Class type = target.getClass();
if (type == Class.class) {
type = (Class)target;
}
java.lang.reflect.Field f = sun.reflect.misc.FieldUtil.getField(type, fieldName);
return f.get(target);
}
catch (Exception e) {
if (is != null) {
is.getExceptionListener().exceptionThrown(e);
}
return null;
}
}
private String attrsToString(AttributeList attrs) {
StringBuffer b = new StringBuffer();
for (int i = 0; i < attrs.getLength (); i++) {
b.append(attrs.getName(i)+"=\""+attrs.getValue(i)+"\" ");
}
return b.toString();
}
public void characters(char buf [], int offset, int len) throws SAXException {
chars.append(new String(buf, offset, len));
}
private void parseCharCode(String name, Map map) {
if (name == "char") {
String value = (String) map.get("code");
if (value != null) {
int code = Integer.decode(value);
for (char ch : Character.toChars(code)) {
this.chars.append(ch);
}
}
}
}
public Object lookup(String s) {
Expression e = (Expression)environment.get(s);
if (e == null) {
simulateException("Unbound variable: " + s);
}
return getValue(e);
}
public void register(String id, Object value) {
Expression e = new MutableExpression();
e.setValue(value);
environment.put(id, e);
}
public void endElement(String name) throws SAXException {
name = name.intern(); // Xerces parser does not supply unique tag names.
if (name == "string") {
this.isString = false;
} else if (this.isString) {
return;
}
if (name == "java") {
return;
}
if (isPrimitive(name) || name == "string" || name == "class") {
addArg(chars.toString());
}
if (name == "object" || name == "array" || name == "void" ||
isPrimitive(name) || name == "string" || name == "class" ||
name == "null") {
Expression e = (Expression)pop(expStack);
Object value = getValue(e);
if (name != "void") {
addArg(value);
}
}
else {
simulateException("Unrecognized closing tag: " + name);
}
}
}
class MutableExpression extends Expression {
private Object target;
private String methodName;
private Object property;
private Vector argV = new Vector();
private String capitalize(String propertyName) {
if (propertyName.length() == 0) {
return propertyName;
}
return propertyName.substring(0, 1).toUpperCase(ENGLISH) + propertyName.substring(1);
}
public MutableExpression() {
super(null, null, null);
}
public Object[] getArguments() {
return argV.toArray();
}
public String getMethodName() {
if (property == null) {
return methodName;
}
int setterArgs = (property instanceof String) ? 1 : 2;
String methodName = (argV.size() == setterArgs) ? "set" : "get";
if (property instanceof String) {
return methodName + capitalize((String)property);
}
else {
return methodName;
}
}
public void addArg(Object arg) {
argV.add(arg);
}
public void setTarget(Object target) {
this.target = target;
}
public Object getTarget() {
return target;
}
public void setMethodName(String methodName) {
this.methodName = methodName;
}
public void setProperty(Object property) {
this.property = property;
}
public void setValue(Object value) {
super.setValue(value);
}
public Object getValue() throws Exception {
return super.getValue();
}
}

View File

@ -0,0 +1,105 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.beans.decoder;
/**
* This is base class that simplifies access to entities (fields or properties).
* The {@code name} attribute specifies the name of the accessible entity.
* The element defines getter if it contains no argument
* or setter if it contains one argument.
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
abstract class AccessorElementHandler extends ElementHandler {
private String name;
private ValueObject value;
/**
* Parses attributes of the element.
* The following atributes are supported:
* <dl>
* <dt>name
* <dd>the name of the accessible entity
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @param name the attribute name
* @param value the attribute value
*/
@Override
public void addAttribute(String name, String value) {
if (name.equals("name")) { // NON-NLS: the attribute name
this.name = value;
} else {
super.addAttribute(name, value);
}
}
/**
* Adds the argument that is used to set the value of this element.
*
* @param argument the value of the element that contained in this one
*/
@Override
protected final void addArgument(Object argument) {
if (this.value != null) {
throw new IllegalStateException("Could not add argument to evaluated element");
}
setValue(this.name, argument);
this.value = ValueObjectImpl.VOID;
}
/**
* Returns the value of this element.
*
* @return the value of this element
*/
@Override
protected final ValueObject getValueObject() {
if (this.value == null) {
this.value = ValueObjectImpl.create(getValue(this.name));
}
return this.value;
}
/**
* Returns the value of the entity with specified {@code name}.
*
* @param name the name of the accessible entity
* @return the value of the specified entity
*/
protected abstract Object getValue(String name);
/**
* Sets the new value for the entity with specified {@code name}.
*
* @param name the name of the accessible entity
* @param value the new value for the specified entity
*/
protected abstract void setValue(String name, Object value);
}

View File

@ -0,0 +1,133 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.beans.decoder;
import java.lang.reflect.Array;
/**
* This class is intended to handle &lt;array&gt; element,
* that is used to array creation.
* The {@code length} attribute specifies the length of the array.
* The {@code class} attribute specifies the elements type.
* The {@link Object} type is used by default.
* For example:<pre>
* &lt;array length="10"/&gt;</pre>
* is equivalent to {@code new Component[10]} in Java code.
* The {@code set} and {@code get} methods,
* as defined in the {@link java.util.List} interface,
* can be used as if they could be applied to array instances.
* The {@code index} attribute can thus be used with arrays.
* For example:<pre>
* &lt;array length="3" class="java.lang.String"&gt;
* &lt;void index="1"&gt;
* &lt;string&gt;Hello, world&lt;/string&gt;
* &lt;/void&gt;
* &lt;/array&gt;</pre>
* is equivalent to the following Java code:<pre>
* String[] s = new String[3];
* s[1] = "Hello, world";</pre>
* It is possible to omit the {@code length} attribute and
* specify the values directly, without using {@code void} tags.
* The length of the array is equal to the number of values specified.
* For example:<pre>
* &lt;array id="array" class="int"&gt;
* &lt;int&gt;123&lt;/int&gt;
* &lt;int&gt;456&lt;/int&gt;
* &lt;/array&gt;</pre>
* is equivalent to {@code int[] array = {123, 456}} in Java code.
* <p>The following atributes are supported:
* <dl>
* <dt>length
* <dd>the array length
* <dt>class
* <dd>the type of object for instantiation
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
final class ArrayElementHandler extends NewElementHandler {
private Integer length;
/**
* Parses attributes of the element.
* The following atributes are supported:
* <dl>
* <dt>length
* <dd>the array length
* <dt>class
* <dd>the type of object for instantiation
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @param name the attribute name
* @param value the attribute value
*/
@Override
public void addAttribute(String name, String value) {
if (name.equals("length")) { // NON-NLS: the attribute name
this.length = Integer.valueOf(value);
} else {
super.addAttribute(name, value);
}
}
/**
* Calculates the value of this element
* if the lentgh attribute is set.
*/
@Override
public void startElement() {
if (this.length != null) {
getValueObject();
}
}
/**
* Creates an instance of the array.
*
* @param type the base class
* @param args the array of arguments
* @return the value of this element
*/
@Override
protected ValueObject getValueObject(Class<?> type, Object[] args) {
if (type == null) {
type = Object.class;
}
if (this.length != null) {
return ValueObjectImpl.create(Array.newInstance(type, this.length));
}
Object array = Array.newInstance(type, args.length);
for (int i = 0; i < args.length; i++) {
Array.set(array, i, args[i]);
}
return ValueObjectImpl.create(array);
}
}

View File

@ -0,0 +1,69 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.beans.decoder;
/**
* This class is intended to handle &lt;boolean&gt; element.
* This element specifies {@code boolean} values.
* The class {@link Boolean} is used as wrapper for these values.
* The result value is created from text of the body of this element.
* The body parsing is described in the class {@link StringElementHandler}.
* For example:<pre>
* &lt;boolean&gt;true&lt;/boolean&gt;</pre>
* is shortcut to<pre>
* &lt;method name="valueOf" class="java.lang.Boolean"&gt;
* &lt;string&gt;true&lt;/string&gt;
* &lt;/method&gt;</pre>
* which is equivalent to {@code Boolean.valueOf("true")} in Java code.
* <p>The following atribute is supported:
* <dl>
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
final class BooleanElementHandler extends StringElementHandler {
/**
* Creates {@code boolean} value from
* the text of the body of this element.
*
* @param argument the text of the body
* @return evaluated {@code boolean} value
*/
@Override
public Object getValue(String argument) {
if (Boolean.TRUE.toString().equalsIgnoreCase(argument)) {
return Boolean.TRUE;
}
if (Boolean.FALSE.toString().equalsIgnoreCase(argument)) {
return Boolean.FALSE;
}
throw new IllegalArgumentException("Unsupported boolean argument: " + argument);
}
}

View File

@ -0,0 +1,63 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.beans.decoder;
/**
* This class is intended to handle &lt;byte&gt; element.
* This element specifies {@code byte} values.
* The class {@link Byte} is used as wrapper for these values.
* The result value is created from text of the body of this element.
* The body parsing is described in the class {@link StringElementHandler}.
* For example:<pre>
* &lt;byte&gt;127&lt;/byte&gt;</pre>
* is shortcut to<pre>
* &lt;method name="decode" class="java.lang.Byte"&gt;
* &lt;string&gt;127&lt;/string&gt;
* &lt;/method&gt;</pre>
* which is equivalent to {@code Byte.decode("127")} in Java code.
* <p>The following atribute is supported:
* <dl>
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
final class ByteElementHandler extends StringElementHandler {
/**
* Creates {@code byte} value from
* the text of the body of this element.
*
* @param argument the text of the body
* @return evaluated {@code byte} value
*/
@Override
public Object getValue(String argument) {
return Byte.decode(argument);
}
}

View File

@ -0,0 +1,92 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.beans.decoder;
/**
* This class is intended to handle &lt;char&gt; element.
* This element specifies {@code char} values.
* The class {@link Character} is used as wrapper for these values.
* The result value is created from text of the body of this element.
* The body parsing is described in the class {@link StringElementHandler}.
* For example:<pre>
* &lt;char&gt;X&lt;/char&gt;</pre>
* which is equivalent to {@code Character.valueOf('X')} in Java code.
* <p>The following atributes are supported:
* <dl>
* <dt>code
* <dd>this attribute specifies character code
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
* The {@code code} attribute can be used for characters
* that are illegal in XML document, for example:<pre>
* &lt;char code="0"/&gt;</pre>
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
final class CharElementHandler extends StringElementHandler {
/**
* Parses attributes of the element.
* The following atributes are supported:
* <dl>
* <dt>code
* <dd>this attribute specifies character code
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @param name the attribute name
* @param value the attribute value
*/
@Override
public void addAttribute(String name, String value) {
if (name.equals("code")) { // NON-NLS: the attribute name
int code = Integer.decode(value);
for (char ch : Character.toChars(code)) {
addCharacter(ch);
}
} else {
super.addAttribute(name, value);
}
}
/**
* Creates {@code char} value from
* the text of the body of this element.
*
* @param argument the text of the body
* @return evaluated {@code char} value
*/
@Override
public Object getValue(String argument) {
if (argument.length() != 1) {
throw new IllegalArgumentException("Wrong characters count");
}
return Character.valueOf(argument.charAt(0));
}
}

View File

@ -0,0 +1,62 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.beans.decoder;
/**
* This class is intended to handle &lt;class&gt; element.
* This element specifies {@link Class} values.
* The result value is created from text of the body of this element.
* The body parsing is described in the class {@link StringElementHandler}.
* For example:<pre>
* &lt;class&gt;java.lang.Class&lt;/class&gt;</pre>
* is shortcut to<pre>
* &lt;method name="forName" class="java.lang.Class"&gt;
* &lt;string&gt;java.lang.Class&lt;/string&gt;
* &lt;/method&gt;</pre>
* which is equivalent to {@code Class.forName("java.lang.Class")} in Java code.
* <p>The following atribute is supported:
* <dl>
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
final class ClassElementHandler extends StringElementHandler {
/**
* Creates class by the name from
* the text of the body of this element.
*
* @param argument the text of the body
* @return evaluated {@code Class} value
*/
@Override
public Object getValue(String argument) {
return getOwner().findClass(argument);
}
}

View File

@ -0,0 +1,389 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.beans.decoder;
import com.sun.beans.finder.ClassFinder;
import java.beans.ExceptionListener;
import java.io.IOException;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
/**
* The main class to parse JavaBeans XML archive.
*
* @since 1.7
*
* @author Sergey A. Malenkov
*
* @see ElementHandler
*/
public final class DocumentHandler extends DefaultHandler {
private final Map<String, Class<? extends ElementHandler>> handlers = new HashMap<String, Class<? extends ElementHandler>>();
private final Map<String, Object> environment = new HashMap<String, Object>();
private final List<Object> objects = new ArrayList<Object>();
private Reference<ClassLoader> loader;
private ExceptionListener listener;
private Object owner;
private ElementHandler handler;
/**
* Creates new instance of document handler.
*/
public DocumentHandler() {
setElementHandler("java", JavaElementHandler.class); // NON-NLS: the element name
setElementHandler("null", NullElementHandler.class); // NON-NLS: the element name
setElementHandler("array", ArrayElementHandler.class); // NON-NLS: the element name
setElementHandler("class", ClassElementHandler.class); // NON-NLS: the element name
setElementHandler("string", StringElementHandler.class); // NON-NLS: the element name
setElementHandler("object", ObjectElementHandler.class); // NON-NLS: the element name
setElementHandler("void", VoidElementHandler.class); // NON-NLS: the element name
setElementHandler("char", CharElementHandler.class); // NON-NLS: the element name
setElementHandler("byte", ByteElementHandler.class); // NON-NLS: the element name
setElementHandler("short", ShortElementHandler.class); // NON-NLS: the element name
setElementHandler("int", IntElementHandler.class); // NON-NLS: the element name
setElementHandler("long", LongElementHandler.class); // NON-NLS: the element name
setElementHandler("float", FloatElementHandler.class); // NON-NLS: the element name
setElementHandler("double", DoubleElementHandler.class); // NON-NLS: the element name
setElementHandler("boolean", BooleanElementHandler.class); // NON-NLS: the element name
// some handlers for new elements
setElementHandler("new", NewElementHandler.class); // NON-NLS: the element name
setElementHandler("var", VarElementHandler.class); // NON-NLS: the element name
setElementHandler("true", TrueElementHandler.class); // NON-NLS: the element name
setElementHandler("false", FalseElementHandler.class); // NON-NLS: the element name
setElementHandler("field", FieldElementHandler.class); // NON-NLS: the element name
setElementHandler("method", MethodElementHandler.class); // NON-NLS: the element name
setElementHandler("property", PropertyElementHandler.class); // NON-NLS: the element name
}
/**
* Returns the class loader used to instantiate objects.
* If the class loader has not been explicitly set
* then {@code null} is returned.
*
* @return the class loader used to instantiate objects
*/
public ClassLoader getClassLoader() {
return (this.loader != null)
? this.loader.get()
: null;
}
/**
* Sets the class loader used to instantiate objects.
* If the class loader is not set
* then default class loader will be used.
*
* @param loader a classloader to use
*/
public void setClassLoader(ClassLoader loader) {
this.loader = new WeakReference<ClassLoader>(loader);
}
/**
* Returns the exception listener for parsing.
* The exception listener is notified
* when handler catches recoverable exceptions.
* If the exception listener has not been explicitly set
* then default exception listener is returned.
*
* @return the exception listener for parsing
*/
public ExceptionListener getExceptionListener() {
return this.listener;
}
/**
* Sets the exception listener for parsing.
* The exception listener is notified
* when handler catches recoverable exceptions.
*
* @param listener the exception listener for parsing
*/
public void setExceptionListener(ExceptionListener listener) {
this.listener = listener;
}
/**
* Returns the owner of this document handler.
*
* @return the owner of this document handler
*/
public Object getOwner() {
return this.owner;
}
/**
* Sets the owner of this document handler.
*
* @param owner the owner of this document handler
*/
public void setOwner(Object owner) {
this.owner = owner;
}
/**
* Returns the handler for the element with specified name.
*
* @param name the name of the element
* @return the corresponding element handler
*/
public Class<? extends ElementHandler> getElementHandler(String name) {
Class<? extends ElementHandler> type = this.handlers.get(name);
if (type == null) {
throw new IllegalArgumentException("Unsupported element: " + name);
}
return type;
}
/**
* Sets the handler for the element with specified name.
*
* @param name the name of the element
* @param handler the corresponding element handler
*/
public void setElementHandler(String name, Class<? extends ElementHandler> handler) {
this.handlers.put(name, handler);
}
/**
* Indicates whether the variable with specified identifier is defined.
*
* @param id the identifier
* @return @{code true} if the variable is defined;
* @{code false} otherwise
*/
public boolean hasVariable(String id) {
return this.environment.containsKey(id);
}
/**
* Returns the value of the variable with specified identifier.
*
* @param id the identifier
* @return the value of the variable
*/
public Object getVariable(String id) {
if (!this.environment.containsKey(id)) {
throw new IllegalArgumentException("Unbound variable: " + id);
}
return this.environment.get(id);
}
/**
* Sets new value of the variable with specified identifier.
*
* @param id the identifier
* @param value new value of the variable
*/
public void setVariable(String id, Object value) {
this.environment.put(id, value);
}
/**
* Returns the array of readed objects.
*
* @return the array of readed objects
*/
public Object[] getObjects() {
return this.objects.toArray();
}
/**
* Adds the object to the list of readed objects.
*
* @param object the object that is readed from XML document
*/
void addObject(Object object) {
this.objects.add(object);
}
/**
* Prepares this handler to read objects from XML document.
*/
@Override
public void startDocument() {
this.objects.clear();
this.handler = null;
}
/**
* Parses opening tag of XML element
* using corresponding element handler.
*
* @param uri the namespace URI, or the empty string
* if the element has no namespace URI or
* if namespace processing is not being performed
* @param localName the local name (without prefix), or the empty string
* if namespace processing is not being performed
* @param qName the qualified name (with prefix), or the empty string
* if qualified names are not available
* @param attributes the attributes attached to the element
*/
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
ElementHandler parent = this.handler;
try {
this.handler = getElementHandler(qName).newInstance();
this.handler.setOwner(this);
this.handler.setParent(parent);
}
catch (Exception exception) {
throw new SAXException(exception);
}
for (int i = 0; i < attributes.getLength(); i++)
try {
String name = attributes.getQName(i);
String value = attributes.getValue(i);
this.handler.addAttribute(name, value);
}
catch (RuntimeException exception) {
handleException(exception);
}
this.handler.startElement();
}
/**
* Parses closing tag of XML element
* using corresponding element handler.
*
* @param uri the namespace URI, or the empty string
* if the element has no namespace URI or
* if namespace processing is not being performed
* @param localName the local name (without prefix), or the empty string
* if namespace processing is not being performed
* @param qName the qualified name (with prefix), or the empty string
* if qualified names are not available
*/
@Override
public void endElement(String uri, String localName, String qName) {
try {
this.handler.endElement();
}
catch (RuntimeException exception) {
handleException(exception);
}
finally {
this.handler = this.handler.getParent();
}
}
/**
* Parses character data inside XML element.
*
* @param chars the array of characters
* @param start the start position in the character array
* @param length the number of characters to use
*/
@Override
public void characters(char[] chars, int start, int length) {
if (this.handler != null) {
try {
while (0 < length--) {
this.handler.addCharacter(chars[start++]);
}
}
catch (RuntimeException exception) {
handleException(exception);
}
}
}
/**
* Handles an exception using current exception listener.
*
* @param exception an exception to handle
* @see #setExceptionListener
*/
public void handleException(Exception exception) {
if (this.listener == null) {
throw new IllegalStateException(exception);
}
this.listener.exceptionThrown(exception);
}
/**
* Starts parsing of the specified input source.
*
* @param input the input source to parse
*/
public void parse(InputSource input) {
try {
SAXParserFactory.newInstance().newSAXParser().parse(input, this);
}
catch (ParserConfigurationException exception) {
handleException(exception);
}
catch (SAXException wrapper) {
Exception exception = wrapper.getException();
if (exception == null) {
exception = wrapper;
}
handleException(exception);
}
catch (IOException exception) {
handleException(exception);
}
}
/**
* Resolves class by name using current class loader.
* This method handles exception using current exception listener.
*
* @param name the name of the class
* @return the object that represents the class
*/
public Class<?> findClass(String name) {
try {
return ClassFinder.resolveClass(name, getClassLoader());
}
catch (ClassNotFoundException exception) {
handleException(exception);
return null;
}
}
}

View File

@ -0,0 +1,63 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.beans.decoder;
/**
* This class is intended to handle &lt;double&gt; element.
* This element specifies {@code double} values.
* The class {@link Double} is used as wrapper for these values.
* The result value is created from text of the body of this element.
* The body parsing is described in the class {@link StringElementHandler}.
* For example:<pre>
* &lt;double&gt;1.23e45&lt;/double&gt;</pre>
* is shortcut to<pre>
* &lt;method name="valueOf" class="java.lang.Double"&gt;
* &lt;string&gt;1.23e45&lt;/string&gt;
* &lt;/method&gt;</pre>
* which is equivalent to {@code Double.valueOf("1.23e45")} in Java code.
* <p>The following atribute is supported:
* <dl>
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
final class DoubleElementHandler extends StringElementHandler {
/**
* Creates {@code double} value from
* the text of the body of this element.
*
* @param argument the text of the body
* @return evaluated {@code double} value
*/
@Override
public Object getValue(String argument) {
return Double.valueOf(argument);
}
}

View File

@ -0,0 +1,224 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.beans.decoder;
/**
* The base class for element handlers.
*
* @since 1.7
*
* @author Sergey A. Malenkov
*
* @see DocumentHandler
*/
public abstract class ElementHandler {
private DocumentHandler owner;
private ElementHandler parent;
private String id;
/**
* Returns the document handler that creates this element handler.
*
* @return the owner document handler
*/
public final DocumentHandler getOwner() {
return this.owner;
}
/**
* Sets the document handler that creates this element handler.
* The owner document handler should be set after instantiation.
* Such approach is used to simplify the extensibility.
*
* @param owner the owner document handler
* @see DocumentHandler#startElement
*/
final void setOwner(DocumentHandler owner) {
if (owner == null) {
throw new IllegalArgumentException("Every element should have owner");
}
this.owner = owner;
}
/**
* Returns the element handler that contains this one.
*
* @return the parent element handler
*/
public final ElementHandler getParent() {
return this.parent;
}
/**
* Sets the element handler that contains this one.
* The parent element handler should be set after instantiation.
* Such approach is used to simplify the extensibility.
*
* @param parent the parent element handler
* @see DocumentHandler#startElement
*/
final void setParent(ElementHandler parent) {
this.parent = parent;
}
/**
* Returns the value of the variable with specified identifier.
*
* @param id the identifier
* @return the value of the variable
*/
protected final Object getVariable(String id) {
if (id.equals(this.id)) {
ValueObject value = getValueObject();
if (value.isVoid()) {
throw new IllegalStateException("The element does not return value");
}
return value.getValue();
}
return (this.parent != null)
? this.parent.getVariable(id)
: this.owner.getVariable(id);
}
/**
* Returns the value of the parent element.
*
* @return the value of the parent element
*/
protected Object getContextBean() {
if (this.parent != null) {
ValueObject value = this.parent.getValueObject();
if (!value.isVoid()) {
return value.getValue();
}
throw new IllegalStateException("The outer element does not return value");
} else {
Object value = this.owner.getOwner();
if (value != null) {
return value;
}
throw new IllegalStateException("The topmost element does not have context");
}
}
/**
* Parses attributes of the element.
* By default, the following atribute is supported:
* <dl>
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @param name the attribute name
* @param value the attribute value
*/
public void addAttribute(String name, String value) {
if (name.equals("id")) { // NON-NLS: the attribute name
this.id = value;
} else {
throw new IllegalArgumentException("Unsupported attribute: " + name);
}
}
/**
* This method is called before parsing of the element's body.
* All attributes are parsed at this point.
* By default, do nothing.
*/
public void startElement() {
}
/**
* This method is called after parsing of the element's body.
* By default, it calculates the value of this element.
* The following tasks are executing for any non-void value:
* <ol>
* <li>If the {@code id} attribute is set
* the value of the variable with the specified identifier
* is set to the value of this element.</li>
* <li>This element is used as an argument of parent element if it is possible.</li>
* </ol>
*
* @see #isArgument
*/
public void endElement() {
// do nothing if no value returned
ValueObject value = getValueObject();
if (!value.isVoid()) {
if (this.id != null) {
this.owner.setVariable(this.id, value.getValue());
}
if (isArgument()) {
if (this.parent != null) {
this.parent.addArgument(value.getValue());
} else {
this.owner.addObject(value.getValue());
}
}
}
}
/**
* Adds the character that contained in this element.
* By default, only whitespaces are acceptable.
*
* @param ch the character
*/
public void addCharacter(char ch) {
if ((ch != ' ') && (ch != '\n') && (ch != '\t') && (ch != '\r')) {
throw new IllegalStateException("Illegal character with code " + (int) ch);
}
}
/**
* Adds the argument that is used to calculate the value of this element.
* By default, no arguments are acceptable.
*
* @param argument the value of the element that contained in this one
*/
protected void addArgument(Object argument) {
throw new IllegalStateException("Could not add argument to simple element");
}
/**
* Tests whether the value of this element can be used
* as an argument of the element that contained in this one.
*
* @return {@code true} if the value of this element can be used
* as an argument of the element that contained in this one,
* {@code false} otherwise
*/
protected boolean isArgument() {
return this.id == null;
}
/**
* Returns the value of this element.
*
* @return the value of this element
*/
protected abstract ValueObject getValueObject();
}

View File

@ -0,0 +1,56 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.beans.decoder;
/**
* This class is intended to handle &lt;false&gt; element.
* This element specifies {@code false} value.
* It should not contain body or inner elements.
* For example:<pre>
* &lt;false/&gt;</pre>
* is equivalent to {@code false} in Java code.
* <p>The following atribute is supported:
* <dl>
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
final class FalseElementHandler extends NullElementHandler {
/**
* Returns {@code Boolean.FALSE}
* as a value of &lt;false&gt; element.
*
* @return {@code Boolean.FALSE} by default
*/
@Override
public Object getValue() {
return Boolean.FALSE;
}
}

View File

@ -0,0 +1,189 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.beans.decoder;
import com.sun.beans.finder.FieldFinder;
import java.lang.reflect.Field;
/**
* This class is intended to handle &lt;field&gt; element.
* This element simplifies access to the fields.
* If the {@code class} attribute is specified
* this element accesses static field of specified class.
* This element defines getter if it contains no argument.
* It returns the value of the field in this case.
* For example:<pre>
* &lt;field name="TYPE" class="java.lang.Long"/&gt;</pre>
* is equivalent to {@code Long.TYPE} in Java code.
* This element defines setter if it contains one argument.
* It does not return the value of the field in this case.
* For example:<pre>
* &lt;field name="id"&gt;&lt;int&gt;0&lt;/int&gt;&lt;/field&gt;</pre>
* is equivalent to {@code id = 0} in Java code.
* <p>The following atributes are supported:
* <dl>
* <dt>name
* <dd>the field name
* <dt>class
* <dd>the type is used for static fields only
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
final class FieldElementHandler extends AccessorElementHandler {
private Class<?> type;
/**
* Parses attributes of the element.
* The following atributes are supported:
* <dl>
* <dt>name
* <dd>the field name
* <dt>class
* <dd>the type is used for static fields only
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @param name the attribute name
* @param value the attribute value
*/
@Override
public void addAttribute(String name, String value) {
if (name.equals("class")) { // NON-NLS: the attribute name
this.type = getOwner().findClass(value);
} else {
super.addAttribute(name, value);
}
}
/**
* Tests whether the value of this element can be used
* as an argument of the element that contained in this one.
*
* @return {@code true} if the value of this element should be used
* as an argument of the element that contained in this one,
* {@code false} otherwise
*/
@Override
protected boolean isArgument() {
return super.isArgument() && (this.type != null); // only static accessor can be used an argument
}
/**
* Returns the context of the field.
* The context of the static field is the class object.
* The context of the non-static field is the value of the parent element.
*
* @return the context of the field
*/
@Override
protected Object getContextBean() {
return (this.type != null)
? this.type
: super.getContextBean();
}
/**
* Returns the value of the field with specified {@code name}.
*
* @param name the name of the field
* @return the value of the specified field
*/
@Override
protected Object getValue(String name) {
try {
return getFieldValue(getContextBean(), name);
}
catch (Exception exception) {
getOwner().handleException(exception);
}
return null;
}
/**
* Sets the new value for the field with specified {@code name}.
*
* @param name the name of the field
* @param value the new value for the specified field
*/
@Override
protected void setValue(String name, Object value) {
try {
setFieldValue(getContextBean(), name, value);
}
catch (Exception exception) {
getOwner().handleException(exception);
}
}
/**
* Performs the search of the field with specified {@code name}
* in specified context and returns its value.
*
* @param bean the context bean that contains field
* @param name the name of the field
* @return the value of the field
* @throws IllegalAccessException if the field is not accesible
* @throws NoSuchFieldException if the field is not found
*/
static Object getFieldValue(Object bean, String name) throws IllegalAccessException, NoSuchFieldException {
return findField(bean, name).get(bean);
}
/**
* Performs the search of the field with specified {@code name}
* in specified context and updates its value.
*
* @param bean the context bean that contains field
* @param name the name of the field
* @param value the new value for the field
* @throws IllegalAccessException if the field is not accesible
* @throws NoSuchFieldException if the field is not found
*/
private static void setFieldValue(Object bean, String name, Object value) throws IllegalAccessException, NoSuchFieldException {
findField(bean, name).set(bean, value);
}
/**
* Performs the search of the field
* with specified {@code name} in specified context.
*
* @param bean the context bean that contains field
* @param name the name of the field
* @return field object that represents found field
* @throws NoSuchFieldException if the field is not found
*/
private static Field findField(Object bean, String name) throws NoSuchFieldException {
return (bean instanceof Class<?>)
? FieldFinder.findStaticField((Class<?>) bean, name)
: FieldFinder.findField(bean.getClass(), name);
}
}

View File

@ -0,0 +1,63 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.beans.decoder;
/**
* This class is intended to handle &lt;float&gt; element.
* This element specifies {@code float} values.
* The class {@link Float} is used as wrapper for these values.
* The result value is created from text of the body of this element.
* The body parsing is described in the class {@link StringElementHandler}.
* For example:<pre>
* &lt;float&gt;-1.23&lt;/float&gt;</pre>
* is shortcut to<pre>
* &lt;method name="valueOf" class="java.lang.Float"&gt;
* &lt;string&gt;-1.23&lt;/string&gt;
* &lt;/method&gt;</pre>
* which is equivalent to {@code Float.valueOf("-1.23")} in Java code.
* <p>The following atribute is supported:
* <dl>
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
final class FloatElementHandler extends StringElementHandler {
/**
* Creates {@code float} value from
* the text of the body of this element.
*
* @param argument the text of the body
* @return evaluated {@code float} value
*/
@Override
public Object getValue(String argument) {
return Float.valueOf(argument);
}
}

View File

@ -0,0 +1,63 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.beans.decoder;
/**
* This class is intended to handle &lt;int&gt; element.
* This element specifies {@code int} values.
* The class {@link Integer} is used as wrapper for these values.
* The result value is created from text of the body of this element.
* The body parsing is described in the class {@link StringElementHandler}.
* For example:<pre>
* &lt;int&gt;-1&lt;/int&gt;</pre>
* is shortcut to<pre>
* &lt;method name="decode" class="java.lang.Integer"&gt;
* &lt;string&gt;-1&lt;/string&gt;
* &lt;/method&gt;</pre>
* which is equivalent to {@code Integer.decode("-1")} in Java code.
* <p>The following atribute is supported:
* <dl>
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
final class IntElementHandler extends StringElementHandler {
/**
* Creates {@code int} value from
* the text of the body of this element.
*
* @param argument the text of the body
* @return evaluated {@code int} value
*/
@Override
public Object getValue(String argument) {
return Integer.decode(argument);
}
}

View File

@ -0,0 +1,151 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.beans.decoder;
import java.beans.XMLDecoder;
/**
* This class is intended to handle &lt;java&gt; element.
* Each element that appears in the body of this element
* is evaluated in the context of the decoder itself.
* Typically this outer context is used to retrieve the owner of the decoder,
* which can be set before reading the archive.
* <p>The following atributes are supported:
* <dl>
* <dt>version
* <dd>the Java version (not supported)
* <dt>class
* <dd>the type of preferable parser (not supported)
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @see DocumentHandler#getOwner
* @see DocumentHandler#setOwner
* @since 1.7
*
* @author Sergey A. Malenkov
*/
final class JavaElementHandler extends ElementHandler {
private Class<?> type;
private ValueObject value;
/**
* Parses attributes of the element.
* The following atributes are supported:
* <dl>
* <dt>version
* <dd>the Java version (not supported)
* <dt>class
* <dd>the type of preferable parser (not supported)
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @param name the attribute name
* @param value the attribute value
*/
@Override
public void addAttribute(String name, String value) {
if (name.equals("version")) { // NON-NLS: the attribute name
// unsupported attribute
} else if (name.equals("class")) { // NON-NLS: the attribute name
// check class for owner
this.type = getOwner().findClass(value);
} else {
super.addAttribute(name, value);
}
}
/**
* Adds the argument to the list of readed objects.
*
* @param argument the value of the element that contained in this one
*/
@Override
protected void addArgument(Object argument) {
getOwner().addObject(argument);
}
/**
* Tests whether the value of this element can be used
* as an argument of the element that contained in this one.
*
* @return {@code true} if the value of this element should be used
* as an argument of the element that contained in this one,
* {@code false} otherwise
*/
@Override
protected boolean isArgument() {
return false; // do not use owner as object
}
/**
* Returns the value of this element.
*
* @return the value of this element
*/
@Override
protected ValueObject getValueObject() {
if (this.value == null) {
this.value = ValueObjectImpl.create(getValue());
}
return this.value;
}
/**
* Returns the owner of the owner document handler
* as a value of &lt;java&gt; element.
*
* @return the owner of the owner document handler
*/
private Object getValue() {
Object owner = getOwner().getOwner();
if ((this.type == null) || isValid(owner)) {
return owner;
}
if (owner instanceof XMLDecoder) {
XMLDecoder decoder = (XMLDecoder) owner;
owner = decoder.getOwner();
if (isValid(owner)) {
return owner;
}
}
throw new IllegalStateException("Unexpected owner class: " + owner.getClass().getName());
}
/**
* Validates the owner of the &lt;java&gt; element.
* The owner is valid if it is {@code null} or an instance
* of the class specified by the {@code class} attribute.
*
* @param owner the owner of the &lt;java&gt; element
* @return {@code true} if the {@code owner} is valid;
* {@code false} otherwise
*/
private boolean isValid(Object owner) {
return (owner == null) || this.type.isInstance(owner);
}
}

View File

@ -0,0 +1,63 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.beans.decoder;
/**
* This class is intended to handle &lt;long&gt; element.
* This element specifies {@code long} values.
* The class {@link Long} is used as wrapper for these values.
* The result value is created from text of the body of this element.
* The body parsing is described in the class {@link StringElementHandler}.
* For example:<pre>
* &lt;long&gt;0xFFFF&lt;/long&gt;</pre>
* is shortcut to<pre>
* &lt;method name="decode" class="java.lang.Long"&gt;
* &lt;string&gt;0xFFFF&lt;/string&gt;
* &lt;/method&gt;</pre>
* which is equivalent to {@code Long.decode("0xFFFF")} in Java code.
* <p>The following atribute is supported:
* <dl>
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
final class LongElementHandler extends StringElementHandler {
/**
* Creates {@code long} value from
* the text of the body of this element.
*
* @param argument the text of the body
* @return evaluated {@code long} value
*/
@Override
public Object getValue(String argument) {
return Long.decode(argument);
}
}

View File

@ -0,0 +1,109 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.beans.decoder;
import com.sun.beans.finder.MethodFinder;
import java.lang.reflect.Method;
/**
* This class is intended to handle &lt;method&gt; element.
* It describes invocation of the method.
* The {@code name} attribute denotes
* the name of the method to invoke.
* If the {@code class} attribute is specified
* this element invokes static method of specified class.
* The inner elements specifies the arguments of the method.
* For example:<pre>
* &lt;method name="valueOf" class="java.lang.Long"&gt;
* &lt;string&gt;10&lt;/string&gt;
* &lt;/method&gt;</pre>
* is equivalent to {@code Long.valueOf("10")} in Java code.
* <p>The following atributes are supported:
* <dl>
* <dt>name
* <dd>the method name
* <dt>class
* <dd>the type of object for instantiation
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
final class MethodElementHandler extends NewElementHandler {
private String name;
/**
* Parses attributes of the element.
* The following atributes are supported:
* <dl>
* <dt>name
* <dd>the method name
* <dt>class
* <dd>the type of object for instantiation
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @param name the attribute name
* @param value the attribute value
*/
@Override
public void addAttribute(String name, String value) {
if (name.equals("name")) { // NON-NLS: the attribute name
this.name = value;
} else {
super.addAttribute(name, value);
}
}
/**
* Returns the result of method execution.
*
* @param type the base class
* @param args the array of arguments
* @return the value of this element
* @throws Exception if calculation is failed
*/
@Override
protected ValueObject getValueObject(Class<?> type, Object[] args) throws Exception {
Object bean = getContextBean();
Class<?>[] types = getArgumentTypes(args);
Method method = (type != null)
? MethodFinder.findStaticMethod(type, this.name, types)
: MethodFinder.findMethod(bean.getClass(), this.name, types);
if (method.isVarArgs()) {
args = getArguments(args, method.getParameterTypes());
}
Object value = method.invoke(bean, args);
return method.getReturnType().equals(void.class)
? ValueObjectImpl.VOID
: ValueObjectImpl.create(value);
}
}

View File

@ -0,0 +1,205 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.beans.decoder;
import com.sun.beans.finder.ConstructorFinder;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.List;
/**
* This class is intended to handle &lt;new&gt; element.
* It describes instantiation of the object.
* The {@code class} attribute denotes
* the name of the class to instantiate.
* The inner elements specifies the arguments of the constructor.
* For example:<pre>
* &lt;new class="java.lang.Long"&gt;
* &lt;string&gt;10&lt;/string&gt;
* &lt;/new&gt;</pre>
* is equivalent to {@code new Long("10")} in Java code.
* <p>The following atributes are supported:
* <dl>
* <dt>class
* <dd>the type of object for instantiation
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
class NewElementHandler extends ElementHandler {
private List<Object> arguments = new ArrayList<Object>();
private ValueObject value = ValueObjectImpl.VOID;
private Class<?> type;
/**
* Parses attributes of the element.
* The following atributes are supported:
* <dl>
* <dt>class
* <dd>the type of object for instantiation
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @param name the attribute name
* @param value the attribute value
*/
@Override
public void addAttribute(String name, String value) {
if (name.equals("class")) { // NON-NLS: the attribute name
this.type = getOwner().findClass(value);
} else {
super.addAttribute(name, value);
}
}
/**
* Adds the argument to the list of arguments
* that is used to calculate the value of this element.
*
* @param argument the value of the element that contained in this one
*/
@Override
protected final void addArgument(Object argument) {
if (this.arguments == null) {
throw new IllegalStateException("Could not add argument to evaluated element");
}
this.arguments.add(argument);
}
/**
* Returns the context of the method.
* The context of the static method is the class object.
* The context of the non-static method is the value of the parent element.
*
* @return the context of the method
*/
@Override
protected final Object getContextBean() {
return (this.type != null)
? this.type
: super.getContextBean();
}
/**
* Returns the value of this element.
*
* @return the value of this element
*/
@Override
protected final ValueObject getValueObject() {
if (this.arguments != null) {
try {
this.value = getValueObject(this.type, this.arguments.toArray());
}
catch (Exception exception) {
getOwner().handleException(exception);
}
finally {
this.arguments = null;
}
}
return this.value;
}
/**
* Calculates the value of this element
* using the base class and the array of arguments.
* By default, it creates an instance of the base class.
* This method should be overridden in those handlers
* that extend behavior of this element.
*
* @param type the base class
* @param args the array of arguments
* @return the value of this element
* @throws Exception if calculation is failed
*/
ValueObject getValueObject(Class<?> type, Object[] args) throws Exception {
if (type == null) {
throw new IllegalArgumentException("Class name is not set");
}
Class<?>[] types = getArgumentTypes(args);
Constructor<?> constructor = ConstructorFinder.findConstructor(type, types);
if (constructor.isVarArgs()) {
args = getArguments(args, constructor.getParameterTypes());
}
return ValueObjectImpl.create(constructor.newInstance(args));
}
/**
* Converts the array of arguments to the array of corresponding classes.
* If argument is {@code null} the class is {@code null} too.
*
* @param arguments the array of arguments
* @return the array of corresponding classes
*/
static Class<?>[] getArgumentTypes(Object[] arguments) {
Class<?>[] types = new Class<?>[arguments.length];
for (int i = 0; i < arguments.length; i++) {
if (arguments[i] != null) {
types[i] = arguments[i].getClass();
}
}
return types;
}
/**
* Resolves variable arguments.
*
* @param arguments the array of arguments
* @param types the array of parameter types
* @return the resolved array of arguments
*/
static Object[] getArguments(Object[] arguments, Class<?>[] types) {
int index = types.length - 1;
if (types.length == arguments.length) {
Object argument = arguments[index];
if (argument == null) {
return arguments;
}
Class<?> type = types[index];
if (type.isAssignableFrom(argument.getClass())) {
return arguments;
}
}
int length = arguments.length - index;
Class<?> type = types[index].getComponentType();
Object array = Array.newInstance(type, length);
System.arraycopy(arguments, index, array, 0, length);
Object[] args = new Object[types.length];
System.arraycopy(arguments, 0, args, 0, index);
args[index] = array;
return args;
}
}

View File

@ -0,0 +1,76 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.beans.decoder;
/**
* This class is intended to handle &lt;null&gt; element.
* This element specifies {@code null} value.
* It should not contain body or inner elements.
* For example:<pre>
* &lt;null/&gt;</pre>
* is equivalent to {@code null} in Java code.
* <p>The following atribute is supported:
* <dl>
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
class NullElementHandler extends ElementHandler implements ValueObject {
/**
* Returns the value of this element.
*
* @return the value of this element
*/
@Override
protected final ValueObject getValueObject() {
return this;
}
/**
* Returns {@code null}
* as a value of &lt;null&gt; element.
* This method should be overridden in those handlers
* that extend behavior of this element.
*
* @return {@code null} by default
*/
public Object getValue() {
return null;
}
/**
* Returns {@code void} state of this value object.
*
* @return {@code false} always
*/
public final boolean isVoid() {
return false;
}
}

View File

@ -0,0 +1,168 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.beans.decoder;
import java.beans.Expression;
import static java.util.Locale.ENGLISH;
/**
* This class is intended to handle &lt;object&gt; element.
* This element looks like &lt;void&gt; element,
* but its value is always used as an argument for element
* that contains this one.
* <p>The following atributes are supported:
* <dl>
* <dt>class
* <dd>the type is used for static methods and fields
* <dt>method
* <dd>the method name
* <dt>property
* <dd>the property name
* <dt>index
* <dd>the property index
* <dt>field
* <dd>the field name
* <dt>idref
* <dd>the identifier to refer to the variable
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
class ObjectElementHandler extends NewElementHandler {
private String idref;
private String field;
private Integer index;
private String property;
private String method;
/**
* Parses attributes of the element.
* The following atributes are supported:
* <dl>
* <dt>class
* <dd>the type is used for static methods and fields
* <dt>method
* <dd>the method name
* <dt>property
* <dd>the property name
* <dt>index
* <dd>the property index
* <dt>field
* <dd>the field name
* <dt>idref
* <dd>the identifier to refer to the variable
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @param name the attribute name
* @param value the attribute value
*/
@Override
public final void addAttribute(String name, String value) {
if (name.equals("idref")) { // NON-NLS: the attribute name
this.idref = value;
} else if (name.equals("field")) { // NON-NLS: the attribute name
this.field = value;
} else if (name.equals("index")) { // NON-NLS: the attribute name
this.index = Integer.valueOf(value);
addArgument(this.index); // hack for compatibility
} else if (name.equals("property")) { // NON-NLS: the attribute name
this.property = value;
} else if (name.equals("method")) { // NON-NLS: the attribute name
this.method = value;
} else {
super.addAttribute(name, value);
}
}
/**
* Calculates the value of this element
* if the field attribute or the idref attribute is set.
*/
@Override
public final void startElement() {
if ((this.field != null) || (this.idref != null)) {
getValueObject();
}
}
/**
* Tests whether the value of this element can be used
* as an argument of the element that contained in this one.
*
* @return {@code true} if the value of this element can be used
* as an argument of the element that contained in this one,
* {@code false} otherwise
*/
@Override
protected boolean isArgument() {
return true; // hack for compatibility
}
/**
* Creates the value of this element.
*
* @param type the base class
* @param args the array of arguments
* @return the value of this element
* @throws Exception if calculation is failed
*/
@Override
protected final ValueObject getValueObject(Class<?> type, Object[] args) throws Exception {
if (this.field != null) {
return ValueObjectImpl.create(FieldElementHandler.getFieldValue(getContextBean(), this.field));
}
if (this.idref != null) {
return ValueObjectImpl.create(getVariable(this.idref));
}
Object bean = getContextBean();
String name;
if (this.index != null) {
name = (args.length == 2)
? PropertyElementHandler.SETTER
: PropertyElementHandler.GETTER;
} else if (this.property != null) {
name = (args.length == 1)
? PropertyElementHandler.SETTER
: PropertyElementHandler.GETTER;
if (0 < this.property.length()) {
name += this.property.substring(0, 1).toUpperCase(ENGLISH) + this.property.substring(1);
}
} else {
name = (this.method != null) && (0 < this.method.length())
? this.method
: "new"; // NON-NLS: the constructor marker
}
Expression expression = new Expression(bean, name, args);
return ValueObjectImpl.create(expression.getValue());
}
}

View File

@ -0,0 +1,287 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.beans.decoder;
import com.sun.beans.finder.MethodFinder;
import java.beans.IndexedPropertyDescriptor;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
/**
* This class is intended to handle &lt;property&gt; element.
* This element simplifies access to the properties.
* If the {@code index} attribute is specified
* this element uses additional {@code int} parameter.
* If the {@code name} attribute is not specified
* this element uses method "get" as getter
* and method "set" as setter.
* This element defines getter if it contains no argument.
* It returns the value of the property in this case.
* For example:<pre>
* &lt;property name="object" index="10"/&gt;</pre>
* is shortcut to<pre>
* &lt;method name="getObject"&gt;
* &lt;int&gt;10&lt;/int&gt;
* &lt;/method&gt;</pre>
* which is equivalent to {@code getObject(10)} in Java code.
* This element defines setter if it contains one argument.
* It does not return the value of the property in this case.
* For example:<pre>
* &lt;property&gt;&lt;int&gt;0&lt;/int&gt;&lt;/property&gt;</pre>
* is shortcut to<pre>
* &lt;method name="set"&gt;
* &lt;int&gt;0&lt;/int&gt;
* &lt;/method&gt;</pre>
* which is equivalent to {@code set(0)} in Java code.
* <p>The following atributes are supported:
* <dl>
* <dt>name
* <dd>the property name
* <dt>index
* <dd>the property index
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
final class PropertyElementHandler extends AccessorElementHandler {
static final String GETTER = "get"; // NON-NLS: the getter prefix
static final String SETTER = "set"; // NON-NLS: the setter prefix
private Integer index;
/**
* Parses attributes of the element.
* The following atributes are supported:
* <dl>
* <dt>name
* <dd>the property name
* <dt>index
* <dd>the property index
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @param name the attribute name
* @param value the attribute value
*/
@Override
public void addAttribute(String name, String value) {
if (name.equals("index")) { // NON-NLS: the attribute name
this.index = Integer.valueOf(value);
} else {
super.addAttribute(name, value);
}
}
/**
* Tests whether the value of this element can be used
* as an argument of the element that contained in this one.
*
* @return {@code true} if the value of this element should be used
* as an argument of the element that contained in this one,
* {@code false} otherwise
*/
@Override
protected boolean isArgument() {
return false; // non-static accessor cannot be used an argument
}
/**
* Returns the value of the property with specified {@code name}.
*
* @param name the name of the property
* @return the value of the specified property
*/
@Override
protected Object getValue(String name) {
try {
return getPropertyValue(getContextBean(), name, this.index);
}
catch (Exception exception) {
getOwner().handleException(exception);
}
return null;
}
/**
* Sets the new value for the property with specified {@code name}.
*
* @param name the name of the property
* @param value the new value for the specified property
*/
@Override
protected void setValue(String name, Object value) {
try {
setPropertyValue(getContextBean(), name, this.index, value);
}
catch (Exception exception) {
getOwner().handleException(exception);
}
}
/**
* Performs the search of the getter for the property
* with specified {@code name} in specified class
* and returns value of the property.
*
* @param bean the context bean that contains property
* @param name the name of the property
* @param index the index of the indexed property
* @return the value of the property
* @throws IllegalAccessException if the property is not accesible
* @throws IntrospectionException if the bean introspection is failed
* @throws InvocationTargetException if the getter cannot be invoked
* @throws NoSuchMethodException if the getter is not found
*/
private static Object getPropertyValue(Object bean, String name, Integer index) throws IllegalAccessException, IntrospectionException, InvocationTargetException, NoSuchMethodException {
Class<?> type = bean.getClass();
if (index == null) {
return findGetter(type, name).invoke(bean);
} else if (type.isArray() && (name == null)) {
return Array.get(bean, index);
} else {
return findGetter(type, name, int.class).invoke(bean, index);
}
}
/**
* Performs the search of the setter for the property
* with specified {@code name} in specified class
* and updates value of the property.
*
* @param bean the context bean that contains property
* @param name the name of the property
* @param index the index of the indexed property
* @param value the new value for the property
* @throws IllegalAccessException if the property is not accesible
* @throws IntrospectionException if the bean introspection is failed
* @throws InvocationTargetException if the setter cannot be invoked
* @throws NoSuchMethodException if the setter is not found
*/
private static void setPropertyValue(Object bean, String name, Integer index, Object value) throws IllegalAccessException, IntrospectionException, InvocationTargetException, NoSuchMethodException {
Class<?> type = bean.getClass();
Class<?> param = (value != null)
? value.getClass()
: null;
if (index == null) {
findSetter(type, name, param).invoke(bean, value);
} else if (type.isArray() && (name == null)) {
Array.set(bean, index, value);
} else {
findSetter(type, name, int.class, param).invoke(bean, index, value);
}
}
/**
* Performs the search of the getter for the property
* with specified {@code name} in specified class.
*
* @param type the class that contains method
* @param name the name of the property
* @param args the method arguments
* @return method object that represents found getter
* @throws IntrospectionException if the bean introspection is failed
* @throws NoSuchMethodException if method is not found
*/
private static Method findGetter(Class<?> type, String name, Class<?>...args) throws IntrospectionException, NoSuchMethodException {
if (name == null) {
return MethodFinder.findInstanceMethod(type, GETTER, args);
}
PropertyDescriptor pd = getProperty(type, name);
if (args.length == 0) {
Method method = pd.getReadMethod();
if (method != null) {
return method;
}
} else if (pd instanceof IndexedPropertyDescriptor) {
IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
Method method = ipd.getIndexedReadMethod();
if (method != null) {
return method;
}
}
throw new IntrospectionException("Could not find getter for the " + name + " property");
}
/**
* Performs the search of the setter for the property
* with specified {@code name} in specified class.
*
* @param type the class that contains method
* @param name the name of the property
* @param args the method arguments
* @return method object that represents found setter
* @throws IntrospectionException if the bean introspection is failed
* @throws NoSuchMethodException if method is not found
*/
private static Method findSetter(Class<?> type, String name, Class<?>...args) throws IntrospectionException, NoSuchMethodException {
if (name == null) {
return MethodFinder.findInstanceMethod(type, SETTER, args);
}
PropertyDescriptor pd = getProperty(type, name);
if (args.length == 1) {
Method method = pd.getWriteMethod();
if (method != null) {
return method;
}
} else if (pd instanceof IndexedPropertyDescriptor) {
IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
Method method = ipd.getIndexedWriteMethod();
if (method != null) {
return method;
}
}
throw new IntrospectionException("Could not find setter for the " + name + " property");
}
/**
* Performs the search of the descriptor for the property
* with specified {@code name} in specified class.
*
* @param type the class to introspect
* @param name the property name
* @return descriptor for the named property
* @throws IntrospectionException if property descriptor is not found
*/
private static PropertyDescriptor getProperty(Class<?> type, String name) throws IntrospectionException {
for (PropertyDescriptor pd : Introspector.getBeanInfo(type).getPropertyDescriptors()) {
if (name.equals(pd.getName())) {
return pd;
}
}
throw new IntrospectionException("Could not find the " + name + " property descriptor");
}
}

View File

@ -0,0 +1,63 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.beans.decoder;
/**
* This class is intended to handle &lt;short&gt; element.
* This element specifies {@code short} values.
* The class {@link Short} is used as wrapper for these values.
* The result value is created from text of the body of this element.
* The body parsing is described in the class {@link StringElementHandler}.
* For example:<pre>
* &lt;short&gt;200&lt;/short&gt;</pre>
* is shortcut to<pre>
* &lt;method name="decode" class="java.lang.Short"&gt;
* &lt;string&gt;200&lt;/string&gt;
* &lt;/method&gt;</pre>
* which is equivalent to {@code Short.decode("200")} in Java code.
* <p>The following atribute is supported:
* <dl>
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
final class ShortElementHandler extends StringElementHandler {
/**
* Creates {@code short} value from
* the text of the body of this element.
*
* @param argument the text of the body
* @return evaluated {@code short} value
*/
@Override
public Object getValue(String argument) {
return Short.decode(argument);
}
}

View File

@ -0,0 +1,116 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.beans.decoder;
/**
* This class is intended to handle &lt;string&gt; element.
* This element specifies {@link String} values.
* The result value is created from text of the body of this element.
* For example:<pre>
* &lt;string&gt;description&lt;/string&gt;</pre>
* is equivalent to {@code "description"} in Java code.
* The value of inner element is calculated
* before adding to the string using {@link String#valueOf(Object)}.
* Note that all characters are used including whitespaces (' ', '\t', '\n', '\r').
* So the value of the element<pre>
* &lt;string&gt&lt;true&gt&lt;/string&gt;</pre>
* is not equal to the value of the element<pre>
* &lt;string&gt;
* &lt;true&gt;
* &lt;/string&gt;</pre>
* <p>The following atribute is supported:
* <dl>
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
public class StringElementHandler extends ElementHandler {
private StringBuilder sb = new StringBuilder();
private ValueObject value = ValueObjectImpl.NULL;
/**
* Adds the character that contained in this element.
*
* @param ch the character
*/
@Override
public final void addCharacter(char ch) {
if (this.sb == null) {
throw new IllegalStateException("Could not add chararcter to evaluated string element");
}
this.sb.append(ch);
}
/**
* Adds the string value of the argument to the string value of this element.
*
* @param argument the value of the element that contained in this one
*/
@Override
protected final void addArgument(Object argument) {
if (this.sb == null) {
throw new IllegalStateException("Could not add argument to evaluated string element");
}
this.sb.append(argument);
}
/**
* Returns the value of this element.
*
* @return the value of this element
*/
@Override
protected final ValueObject getValueObject() {
if (this.sb != null) {
try {
this.value = ValueObjectImpl.create(getValue(this.sb.toString()));
}
catch (RuntimeException exception) {
getOwner().handleException(exception);
}
finally {
this.sb = null;
}
}
return this.value;
}
/**
* Returns the text of the body of this element.
* This method evaluates value from text of the body,
* and should be overridden in those handlers
* that extend behavior of this element.
*
* @param argument the text of the body
* @return evaluated value
*/
protected Object getValue(String argument) {
return argument;
}
}

View File

@ -0,0 +1,56 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.beans.decoder;
/**
* This class is intended to handle &lt;true&gt; element.
* This element specifies {@code true} value.
* It should not contain body or inner elements.
* For example:<pre>
* &lt;true/&gt;</pre>
* is equivalent to {@code true} in Java code.
* <p>The following atribute is supported:
* <dl>
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
final class TrueElementHandler extends NullElementHandler {
/**
* Returns {@code Boolean.TRUE}
* as a value of &lt;true&gt; element.
*
* @return {@code Boolean.TRUE} by default
*/
@Override
public Object getValue() {
return Boolean.TRUE;
}
}

View File

@ -0,0 +1,50 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.beans.decoder;
/**
* This interface represents the result of method execution.
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
public interface ValueObject {
/**
* Returns the result of method execution.
*
* @return the result of method execution
*/
Object getValue();
/**
* Returns {@code void} state of this value object.
*
* @return {@code true} if value can be ignored,
* {@code false} otherwise
*/
boolean isVoid();
}

View File

@ -0,0 +1,88 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.beans.decoder;
/**
* This utility class provides {@code static} method
* to create the object that contains the result of method execution.
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
final class ValueObjectImpl implements ValueObject {
static final ValueObject NULL = new ValueObjectImpl(null);
static final ValueObject VOID = new ValueObjectImpl();
/**
* Returns the object that describes returning value.
*
* @param value the result of method execution
* @return the object that describes value
*/
static ValueObject create(Object value) {
return (value != null)
? new ValueObjectImpl(value)
: NULL;
}
private Object value;
private boolean isVoid;
/**
* Creates the object that describes returning void value.
*/
private ValueObjectImpl() {
this.isVoid = true;
}
/**
* Creates the object that describes returning non-void value.
*
* @param value the result of method execution
*/
private ValueObjectImpl(Object value) {
this.value = value;
}
/**
* Returns the result of method execution.
*
* @return the result of method execution
*/
public Object getValue() {
return this.value;
}
/**
* Returns {@code void} state of this value object.
*
* @return {@code true} if value should be ignored,
* {@code false} otherwise
*/
public boolean isVoid() {
return this.isVoid;
}
}

View File

@ -0,0 +1,82 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.beans.decoder;
/**
* This class is intended to handle &lt;var&gt; element.
* This element retrieves the value of specified variable.
* For example:<pre>
* &lt;var id="id1" idref="id2"/&gt;</pre>
* is equivalent to {@code id1 = id2} in Java code.
* <p>The following atributes are supported:
* <dl>
* <dt>idref
* <dd>the identifier to refer to the variable
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
final class VarElementHandler extends ElementHandler {
private ValueObject value;
/**
* Parses attributes of the element.
* The following atributes are supported:
* <dl>
* <dt>idref
* <dd>the identifier to refer to the variable
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @param name the attribute name
* @param value the attribute value
*/
@Override
public void addAttribute(String name, String value) {
if (name.equals("idref")) { // NON-NLS: the attribute name
this.value = ValueObjectImpl.create(getVariable(value));
} else {
super.addAttribute(name, value);
}
}
/**
* Returns the value of this element.
*
* @return the value of this element
*/
@Override
protected ValueObject getValueObject() {
if (this.value == null) {
throw new IllegalArgumentException("Variable name is not set");
}
return this.value;
}
}

View File

@ -0,0 +1,68 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.beans.decoder;
/**
* This class is intended to handle &lt;void&gt; element.
* This element looks like &lt;object&gt; element,
* but its value is not used as an argument for element
* that contains this one.
* <p>The following atributes are supported:
* <dl>
* <dt>class
* <dd>the type is used for static methods and fields
* <dt>method
* <dd>the method name
* <dt>property
* <dd>the property name
* <dt>index
* <dd>the property index
* <dt>field
* <dd>the field name
* <dt>idref
* <dd>the identifier to refer to the variable
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
final class VoidElementHandler extends ObjectElementHandler {
/**
* Tests whether the value of this element can be used
* as an argument of the element that contained in this one.
*
* @return {@code true} if the value of this element should be used
* as an argument of the element that contained in this one,
* {@code false} otherwise
*/
@Override
protected boolean isArgument() {
return false; // hack for compatibility
}
}

View File

@ -0,0 +1,213 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.beans.finder;
import java.util.HashMap;
import java.util.Map;
/**
* This abstract class provides functionality
* to find a public method or constructor
* with specified parameter types.
* It supports a variable number of parameters.
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
abstract class AbstractFinder<T> {
private final Class<?>[] args;
/**
* Creates finder for array of classes of arguments.
* If a particular element of array equals {@code null},
* than the appropriate pair of classes
* does not take into consideration.
*
* @param args array of classes of arguments
*/
protected AbstractFinder(Class<?>[] args) {
this.args = args;
}
/**
* Returns an array of {@code Class} objects
* that represent the formal parameter types of the method
* Returns an empty array if the method takes no parameters.
*
* @param method the object that represents method
* @return the parameter types of the method
*/
protected abstract Class<?>[] getParameters(T method);
/**
* Returns {@code true} if and only if the method
* was declared to take a variable number of arguments.
*
* @param method the object that represents method
* @return {@code true} if the method was declared
* to take a variable number of arguments;
* {@code false} otherwise
*/
protected abstract boolean isVarArgs(T method);
/**
* Checks validness of the method.
* At least the valid method should be public.
*
* @param method the object that represents method
* @return {@code true} if the method is valid,
* {@code false} otherwise
*/
protected abstract boolean isValid(T method);
/**
* Performs a search in the {@code methods} array.
* The one method is selected from the array of the valid methods.
* The list of parameters of the selected method shows
* the best correlation with the list of arguments
* specified at class initialization.
* If more than one method is both accessible and applicable
* to a method invocation, it is necessary to choose one
* to provide the descriptor for the run-time method dispatch.
* The most specific method should be chosen.
*
* @param methods the array of methods to search within
* @return the object that represents found method
* @throws NoSuchMethodException if no method was found or several
* methods meet the search criteria
* @see #isAssignable
*/
final T find(T[] methods) throws NoSuchMethodException {
Map<T, Class<?>[]> map = new HashMap<T, Class<?>[]>();
T oldMethod = null;
Class<?>[] oldParams = null;
boolean ambiguous = false;
for (T newMethod : methods) {
if (isValid(newMethod)) {
Class<?>[] newParams = getParameters(newMethod);
if (newParams.length == this.args.length) {
PrimitiveWrapperMap.replacePrimitivesWithWrappers(newParams);
if (isAssignable(newParams, this.args)) {
if (oldMethod == null) {
oldMethod = newMethod;
oldParams = newParams;
} else {
boolean useNew = isAssignable(oldParams, newParams);
boolean useOld = isAssignable(newParams, oldParams);
if (useOld == useNew) {
ambiguous = true;
} else if (useNew) {
oldMethod = newMethod;
oldParams = newParams;
ambiguous = false;
}
}
}
}
if (isVarArgs(newMethod)) {
int length = newParams.length - 1;
if (length <= this.args.length) {
Class<?>[] array = new Class<?>[this.args.length];
System.arraycopy(newParams, 0, array, 0, length);
if (length < this.args.length) {
Class<?> type = newParams[length].getComponentType();
if (type.isPrimitive()) {
type = PrimitiveWrapperMap.getType(type.getName());
}
for (int i = length; i < this.args.length; i++) {
array[i] = type;
}
}
map.put(newMethod, array);
}
}
}
}
for (T newMethod : methods) {
Class<?>[] newParams = map.get(newMethod);
if (newParams != null) {
if (isAssignable(newParams, this.args)) {
if (oldMethod == null) {
oldMethod = newMethod;
oldParams = newParams;
} else {
boolean useNew = isAssignable(oldParams, newParams);
boolean useOld = isAssignable(newParams, oldParams);
if (useOld == useNew) {
if (oldParams == map.get(oldMethod)) {
ambiguous = true;
}
} else if (useNew) {
oldMethod = newMethod;
oldParams = newParams;
ambiguous = false;
}
}
}
}
}
if (ambiguous) {
throw new NoSuchMethodException("Ambiguous methods are found");
}
if (oldMethod == null) {
throw new NoSuchMethodException("Method is not found");
}
return oldMethod;
}
/**
* Determines if every class in {@code min} array is either the same as,
* or is a superclass of, the corresponding class in {@code max} array.
* The length of every array must equal the number of arguments.
* This comparison is performed in the {@link #find} method
* before the first call of the isAssignable method.
* If an argument equals {@code null}
* the appropriate pair of classes does not take into consideration.
*
* @param min the array of classes to be checked
* @param max the array of classes that is used to check
* @return {@code true} if all classes in {@code min} array
* are assignable from corresponding classes in {@code max} array,
* {@code false} otherwise
*
* @see Class#isAssignableFrom
*/
private boolean isAssignable(Class<?>[] min, Class<?>[] max) {
for (int i = 0; i < this.args.length; i++) {
if (null != this.args[i]) {
if (!min[i].isAssignableFrom(max[i])) {
return false;
}
}
}
return true;
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 2006-2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,7 +25,7 @@
package com.sun.beans.finder;
/**
* This is utility class that provides <code>static</code> methods
* This is utility class that provides {@code static} methods
* to find a class with the specified name using the specified class loader.
*
* @since 1.7
@ -33,137 +33,138 @@ package com.sun.beans.finder;
* @author Sergey A. Malenkov
*/
public final class ClassFinder {
/**
* Returns the <code>Class</code> object associated
* Returns the {@code Class} object associated
* with the class or interface with the given string name,
* using the default class loader.
* <p>
* The <code>name</code> can denote an array class
* The {@code name} can denote an array class
* (see {@link Class#getName} for details).
*
* @param name fully qualified name of the desired class
* @return class object representing the desired class
*
* @exception ClassNotFoundException if the class cannot be located
* by the specified class loader
* @throws ClassNotFoundException if the class cannot be located
* by the specified class loader
*
* @see Class#forName(String)
* @see Class#forName(String,boolean,ClassLoader)
* @see ClassLoader#getSystemClassLoader()
* @see Thread#getContextClassLoader()
*/
public static Class findClass( String name ) throws ClassNotFoundException {
public static Class<?> findClass(String name) throws ClassNotFoundException {
try {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
if ( loader == null ) {
if (loader == null) {
// can be null in IE (see 6204697)
loader = ClassLoader.getSystemClassLoader();
}
if ( loader != null ) {
return Class.forName( name, false, loader );
if (loader != null) {
return Class.forName(name, false, loader);
}
} catch ( ClassNotFoundException exception ) {
} catch (ClassNotFoundException exception) {
// use current class loader instead
} catch ( SecurityException exception ) {
} catch (SecurityException exception) {
// use current class loader instead
}
return Class.forName( name );
return Class.forName(name);
}
/**
* Returns the <code>Class</code> object associated with
* Returns the {@code Class} object associated with
* the class or interface with the given string name,
* using the given class loader.
* <p>
* The <code>name</code> can denote an array class
* The {@code name} can denote an array class
* (see {@link Class#getName} for details).
* <p>
* If the parameter <code>loader</code> is null,
* If the parameter {@code loader} is null,
* the class is loaded through the default class loader.
*
* @param name fully qualified name of the desired class
* @param loader class loader from which the class must be loaded
* @return class object representing the desired class
*
* @exception ClassNotFoundException if the class cannot be located
* by the specified class loader
* @throws ClassNotFoundException if the class cannot be located
* by the specified class loader
*
* @see #findClass(String,ClassLoader)
* @see Class#forName(String,boolean,ClassLoader)
*/
public static Class findClass( String name, ClassLoader loader ) throws ClassNotFoundException {
if ( loader != null ) {
public static Class<?> findClass(String name, ClassLoader loader) throws ClassNotFoundException {
if (loader != null) {
try {
return Class.forName( name, false, loader );
} catch ( ClassNotFoundException exception ) {
return Class.forName(name, false, loader);
} catch (ClassNotFoundException exception) {
// use default class loader instead
} catch ( SecurityException exception ) {
} catch (SecurityException exception) {
// use default class loader instead
}
}
return findClass( name );
return findClass(name);
}
/**
* Returns the <code>Class</code> object associated
* Returns the {@code Class} object associated
* with the class or interface with the given string name,
* using the default class loader.
* <p>
* The <code>name</code> can denote an array class
* The {@code name} can denote an array class
* (see {@link Class#getName} for details).
* <p>
* This method can be used to obtain
* any of the <code>Class</code> objects
* representing <code>void</code> or primitive Java types:
* <code>char</code>, <code>byte</code>, <code>short</code>,
* <code>int</code>, <code>long</code>, <code>float</code>,
* <code>double</code> and <code>boolean</code>.
* any of the {@code Class} objects
* representing {@code void} or primitive Java types:
* {@code char}, {@code byte}, {@code short},
* {@code int}, {@code long}, {@code float},
* {@code double} and {@code boolean}.
*
* @param name fully qualified name of the desired class
* @return class object representing the desired class
*
* @exception ClassNotFoundException if the class cannot be located
* by the specified class loader
* @throws ClassNotFoundException if the class cannot be located
* by the specified class loader
*
* @see #resolveClass(String,ClassLoader)
*/
public static Class resolveClass( String name ) throws ClassNotFoundException {
return resolveClass( name, null );
public static Class<?> resolveClass(String name) throws ClassNotFoundException {
return resolveClass(name, null);
}
/**
* Returns the <code>Class</code> object associated with
* Returns the {@code Class} object associated with
* the class or interface with the given string name,
* using the given class loader.
* <p>
* The <code>name</code> can denote an array class
* The {@code name} can denote an array class
* (see {@link Class#getName} for details).
* <p>
* If the parameter <code>loader</code> is null,
* If the parameter {@code loader} is null,
* the class is loaded through the default class loader.
* <p>
* This method can be used to obtain
* any of the <code>Class</code> objects
* representing <code>void</code> or primitive Java types:
* <code>char</code>, <code>byte</code>, <code>short</code>,
* <code>int</code>, <code>long</code>, <code>float</code>,
* <code>double</code> and <code>boolean</code>.
* any of the {@code Class} objects
* representing {@code void} or primitive Java types:
* {@code char}, {@code byte}, {@code short},
* {@code int}, {@code long}, {@code float},
* {@code double} and {@code boolean}.
*
* @param name fully qualified name of the desired class
* @param loader class loader from which the class must be loaded
* @return class object representing the desired class
*
* @exception ClassNotFoundException if the class cannot be located
* by the specified class loader
* @throws ClassNotFoundException if the class cannot be located
* by the specified class loader
*
* @see #findClass(String,ClassLoader)
* @see PrimitiveTypeMap#getType(String)
*/
public static Class resolveClass( String name, ClassLoader loader ) throws ClassNotFoundException {
Class type = PrimitiveTypeMap.getType( name );
return ( type == null )
? findClass( name, loader )
public static Class<?> resolveClass(String name, ClassLoader loader) throws ClassNotFoundException {
Class<?> type = PrimitiveTypeMap.getType(name);
return (type == null)
? findClass(name, loader)
: type;
}

View File

@ -0,0 +1,127 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.beans.finder;
import com.sun.beans.WeakCache;
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
/**
* This utility class provides {@code static} methods
* to find a public constructor with specified parameter types
* in specified class.
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
public final class ConstructorFinder extends AbstractFinder<Constructor<?>> {
private static final WeakCache<Signature, Constructor<?>> CACHE = new WeakCache<Signature, Constructor<?>>();
/**
* Finds public constructor
* that is declared in public class.
*
* @param type the class that can have constructor
* @param args parameter types that is used to find constructor
* @return object that represents found constructor
* @throws NoSuchMethodException if constructor could not be found
* or some constructors are found
*/
public static Constructor<?> findConstructor(Class<?> type, Class<?>...args) throws NoSuchMethodException {
if (type.isPrimitive()) {
throw new NoSuchMethodException("Primitive wrapper does not contain constructors");
}
if (type.isInterface()) {
throw new NoSuchMethodException("Interface does not contain constructors");
}
if (Modifier.isAbstract(type.getModifiers())) {
throw new NoSuchMethodException("Abstract class cannot be instantiated");
}
if (!Modifier.isPublic(type.getModifiers())) {
throw new NoSuchMethodException("Class is not accessible");
}
PrimitiveWrapperMap.replacePrimitivesWithWrappers(args);
Signature signature = new Signature(type, args);
Constructor<?> constructor = CACHE.get(signature);
if (constructor != null) {
return constructor;
}
constructor = new ConstructorFinder(args).find(type.getConstructors());
CACHE.put(signature, constructor);
return constructor;
}
/**
* Creates constructor finder with specified array of parameter types.
*
* @param args the array of parameter types
*/
private ConstructorFinder(Class<?>[] args) {
super(args);
}
/**
* Returns an array of {@code Class} objects
* that represent the formal parameter types of the constructor
* Returns an empty array if the constructor takes no parameters.
*
* @param constructor the object that represents constructor
* @return the parameter types of the constructor
*/
@Override
protected Class<?>[] getParameters(Constructor<?> constructor) {
return constructor.getParameterTypes();
}
/**
* Returns {@code true} if and only if the constructor
* was declared to take a variable number of arguments.
*
* @param constructor the object that represents constructor
* @return {@code true} if the constructor was declared
* to take a variable number of arguments;
* {@code false} otherwise
*/
@Override
protected boolean isVarArgs(Constructor<?> constructor) {
return constructor.isVarArgs();
}
/**
* Checks validness of the constructor.
* The valid constructor should be public.
*
* @param constructor the object that represents constructor
* @return {@code true} if the constructor is valid,
* {@code false} otherwise
*/
@Override
protected boolean isValid(Constructor<?> constructor) {
return Modifier.isPublic(constructor.getModifiers());
}
}

View File

@ -0,0 +1,106 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.beans.finder;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
/**
* This utility class provides {@code static} methods
* to find a public field with specified name
* in specified class.
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
public final class FieldFinder {
/**
* Finds public field (static or non-static)
* that is declared in public class.
*
* @param type the class that can have field
* @param name the name of field to find
* @return object that represents found field
* @throws NoSuchFieldException if field is not found
* @see Class#getField
*/
public static Field findField(Class<?> type, String name) throws NoSuchFieldException {
if (name == null) {
throw new IllegalArgumentException("Field name is not set");
}
Field field = type.getField(name);
if (!Modifier.isPublic(field.getModifiers())) {
throw new NoSuchFieldException("Field '" + name + "' is not public");
}
if (!Modifier.isPublic(field.getDeclaringClass().getModifiers())) {
throw new NoSuchFieldException("Field '" + name + "' is not accessible");
}
return field;
}
/**
* Finds public non-static field
* that is declared in public class.
*
* @param type the class that can have field
* @param name the name of field to find
* @return object that represents found field
* @throws NoSuchFieldException if field is not found
* @see Class#getField
*/
public static Field findInstanceField(Class<?> type, String name) throws NoSuchFieldException {
Field field = findField(type, name);
if (Modifier.isStatic(field.getModifiers())) {
throw new NoSuchFieldException("Field '" + name + "' is static");
}
return field;
}
/**
* Finds public static field
* that is declared in public class.
*
* @param type the class that can have field
* @param name the name of field to find
* @return object that represents found field
* @throws NoSuchFieldException if field is not found
* @see Class#getField
*/
public static Field findStaticField(Class<?> type, String name) throws NoSuchFieldException {
Field field = findField(type, name);
if (!Modifier.isStatic(field.getModifiers())) {
throw new NoSuchFieldException("Field '" + name + "' is not static");
}
return field;
}
/**
* Disable instantiation.
*/
private FieldFinder() {
}
}

View File

@ -0,0 +1,231 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.beans.finder;
import com.sun.beans.TypeResolver;
import com.sun.beans.WeakCache;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Arrays;
/**
* This utility class provides {@code static} methods
* to find a public method with specified name and parameter types
* in specified class.
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
public final class MethodFinder extends AbstractFinder<Method> {
private static final WeakCache<Signature, Method> CACHE = new WeakCache<Signature, Method>();
/**
* Finds public method (static or non-static)
* that is accessible from public class.
*
* @param type the class that can have method
* @param name the name of method to find
* @param args parameter types that is used to find method
* @return object that represents found method
* @throws NoSuchMethodException if method could not be found
* or some methods are found
*/
public static Method findMethod(Class<?> type, String name, Class<?>...args) throws NoSuchMethodException {
if (name == null) {
throw new IllegalArgumentException("Method name is not set");
}
PrimitiveWrapperMap.replacePrimitivesWithWrappers(args);
Signature signature = new Signature(type, name, args);
Method method = CACHE.get(signature);
if (method != null) {
return method;
}
method = findAccessibleMethod(new MethodFinder(name, args).find(type.getMethods()));
CACHE.put(signature, method);
return method;
}
/**
* Finds public non-static method
* that is accessible from public class.
*
* @param type the class that can have method
* @param name the name of method to find
* @param args parameter types that is used to find method
* @return object that represents found method
* @throws NoSuchMethodException if method could not be found
* or some methods are found
*/
public static Method findInstanceMethod(Class<?> type, String name, Class<?>... args) throws NoSuchMethodException {
Method method = findMethod(type, name, args);
if (Modifier.isStatic(method.getModifiers())) {
throw new NoSuchMethodException("Method '" + name + "' is static");
}
return method;
}
/**
* Finds public static method
* that is accessible from public class.
*
* @param type the class that can have method
* @param name the name of method to find
* @param args parameter types that is used to find method
* @return object that represents found method
* @throws NoSuchMethodException if method could not be found
* or some methods are found
*/
public static Method findStaticMethod(Class<?> type, String name, Class<?>...args) throws NoSuchMethodException {
Method method = findMethod(type, name, args);
if (!Modifier.isStatic(method.getModifiers())) {
throw new NoSuchMethodException("Method '" + name + "' is not static");
}
return method;
}
/**
* Finds method that is accessible from public class or interface through class hierarchy.
*
* @param method object that represents found method
* @return object that represents accessible method
* @throws NoSuchMethodException if method is not accessible or is not found
* in specified superclass or interface
*/
private static Method findAccessibleMethod(Method method) throws NoSuchMethodException {
Class<?> type = method.getDeclaringClass();
if (Modifier.isPublic(type.getModifiers())) {
return method;
}
if (Modifier.isStatic(method.getModifiers())) {
throw new NoSuchMethodException("Method '" + method.getName() + "' is not accessible");
}
for (Type generic : type.getGenericInterfaces()) {
try {
return findAccessibleMethod(method, generic);
}
catch (NoSuchMethodException exception) {
// try to find in superclass or another interface
}
}
return findAccessibleMethod(method, type.getGenericSuperclass());
}
/**
* Finds method that accessible from specified class.
*
* @param method object that represents found method
* @param generic generic type that is used to find accessible method
* @return object that represents accessible method
* @throws NoSuchMethodException if method is not accessible or is not found
* in specified superclass or interface
*/
private static Method findAccessibleMethod(Method method, Type generic) throws NoSuchMethodException {
String name = method.getName();
Class<?>[] params = method.getParameterTypes();
if (generic instanceof Class) {
Class<?> type = (Class<?>) generic;
return findAccessibleMethod(type.getMethod(name, params));
}
if (generic instanceof ParameterizedType) {
ParameterizedType pt = (ParameterizedType) generic;
Class<?> type = (Class<?>) pt.getRawType();
for (Method m : type.getMethods()) {
if (m.getName().equals(name)) {
Class<?>[] pts = m.getParameterTypes();
if (pts.length == params.length) {
if (Arrays.equals(params, pts)) {
return findAccessibleMethod(m);
}
Type[] gpts = m.getGenericParameterTypes();
if (Arrays.equals(params, TypeResolver.erase(TypeResolver.resolve(pt, gpts)))) {
return findAccessibleMethod(m);
}
}
}
}
}
throw new NoSuchMethodException("Method '" + name + "' is not accessible");
}
private final String name;
/**
* Creates method finder with specified array of parameter types.
*
* @param name the name of method to find
* @param args the array of parameter types
*/
private MethodFinder(String name, Class<?>[] args) {
super(args);
this.name = name;
}
/**
* Returns an array of {@code Class} objects
* that represent the formal parameter types of the method
* Returns an empty array if the method takes no parameters.
*
* @param method the object that represents method
* @return the parameter types of the method
*/
@Override
protected Class<?>[] getParameters(Method method) {
return method.getParameterTypes();
}
/**
* Returns {@code true} if and only if the method
* was declared to take a variable number of arguments.
*
* @param method the object that represents method
* @return {@code true} if the method was declared
* to take a variable number of arguments;
* {@code false} otherwise
*/
@Override
protected boolean isVarArgs(Method method) {
return method.isVarArgs();
}
/**
* Checks validness of the method.
* The valid method should be public and
* should have the specified name.
*
* @param method the object that represents method
* @return {@code true} if the method is valid,
* {@code false} otherwise
*/
@Override
protected boolean isValid(Method method) {
return Modifier.isPublic(method.getModifiers()) && method.getName().equals(this.name);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 2006-2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -36,29 +36,30 @@ import java.util.Map;
* @author Sergey A. Malenkov
*/
final class PrimitiveTypeMap {
/**
* Returns primitive type class by its name.
*
* @param name the name of primitive type
* @return found primitive type class,
* or <code>null</code> if not found
* or {@code null} if not found
*/
static Class getType( String name ) {
return map.get( name );
static Class<?> getType(String name) {
return map.get(name);
}
private static final Map<String, Class> map = new HashMap<String, Class>( 9 );
private static final Map<String, Class<?>> map = new HashMap<String, Class<?>>(9);
static {
map.put( boolean.class.getName(), boolean.class );
map.put( char.class.getName(), char.class );
map.put( byte.class.getName(), byte.class );
map.put( short.class.getName(), short.class );
map.put( int.class.getName(), int.class );
map.put( long.class.getName(), long.class );
map.put( float.class.getName(), float.class );
map.put( double.class.getName(), double.class );
map.put( void.class.getName(), void.class );
map.put(boolean.class.getName(), boolean.class);
map.put(char.class.getName(), char.class);
map.put(byte.class.getName(), byte.class);
map.put(short.class.getName(), short.class);
map.put(int.class.getName(), int.class);
map.put(long.class.getName(), long.class);
map.put(float.class.getName(), float.class);
map.put(double.class.getName(), double.class);
map.put(void.class.getName(), void.class);
}
/**

View File

@ -0,0 +1,86 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.beans.finder;
import java.util.HashMap;
import java.util.Map;
/**
* This utility class associates
* name of primitive type with appropriate wrapper.
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
public final class PrimitiveWrapperMap {
/**
* Replaces all primitive types in specified array with wrappers.
*
* @param types array of classes where all primitive types
* will be replaced by appropriate wrappers
*/
static void replacePrimitivesWithWrappers(Class<?>[] types) {
for (int i = 0; i < types.length; i++) {
if (types[i] != null) {
if (types[i].isPrimitive()) {
types[i] = getType(types[i].getName());
}
}
}
}
/**
* Returns wrapper for primitive type by its name.
*
* @param name the name of primitive type
* @return found wrapper for primitive type,
* or {@code null} if not found
*/
public static Class<?> getType(String name) {
return map.get(name);
}
private static final Map<String, Class<?>> map = new HashMap<String, Class<?>>(9);
static {
map.put(Boolean.TYPE.getName(), Boolean.class);
map.put(Character.TYPE.getName(), Character.class);
map.put(Byte.TYPE.getName(), Byte.class);
map.put(Short.TYPE.getName(), Short.class);
map.put(Integer.TYPE.getName(), Integer.class);
map.put(Long.TYPE.getName(), Long.class);
map.put(Float.TYPE.getName(), Float.class);
map.put(Double.TYPE.getName(), Double.class);
map.put(Void.TYPE.getName(), Void.class);
}
/**
* Disable instantiation.
*/
private PrimitiveWrapperMap() {
}
}

View File

@ -0,0 +1,169 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.beans.finder;
/**
* This class is designed to be a key of a cache
* of constructors or methods.
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
final class Signature {
private final Class<?> type;
private final String name;
private final Class<?>[] args;
private volatile int code;
/**
* Constructs signature for constructor.
*
* @param type the class that contains constructor
* @param args the types of constructor's parameters
*/
Signature(Class<?> type, Class<?>[] args) {
this(type, null, args);
}
/**
* Constructs signature for method.
*
* @param type the class that contains method
* @param name the name of the method
* @param args the types of method's parameters
*/
Signature(Class<?> type, String name, Class<?>[] args) {
this.type = type;
this.name = name;
this.args = args;
}
/**
* Indicates whether some other object is "equal to" this one.
*
* @param object the reference object with which to compare
* @return {@code true} if this object is the same as the
* {@code object} argument, {@code false} otherwise
* @see #hashCode()
*/
@Override
public boolean equals(Object object) {
if (this == object) {
return true;
}
if (object instanceof Signature) {
Signature signature = (Signature) object;
return isEqual(signature.type, this.type)
&& isEqual(signature.name, this.name)
&& isEqual(signature.args, this.args);
}
return false;
}
/**
* Indicates whether some object is "equal to" another one.
* This method supports {@code null} values.
*
* @param obj1 the first reference object that will compared
* @param obj2 the second reference object that will compared
* @return {@code true} if first object is the same as the second object,
* {@code false} otherwise
*/
private static boolean isEqual(Object obj1, Object obj2) {
return (obj1 == null)
? obj2 == null
: obj1.equals(obj2);
}
/**
* Indicates whether some array is "equal to" another one.
* This method supports {@code null} values.
*
* @param args1 the first reference array that will compared
* @param args2 the second reference array that will compared
* @return {@code true} if first array is the same as the second array,
* {@code false} otherwise
*/
private static boolean isEqual(Class<?>[] args1, Class<?>[] args2) {
if ((args1 == null) || (args2 == null)) {
return args1 == args2;
}
if (args1.length != args2.length) {
return false;
}
for (int i = 0; i < args1.length; i++) {
if (!isEqual(args1[i], args2[i])) {
return false;
}
}
return true;
}
/**
* Returns a hash code value for the object.
* This method is supported for the benefit of hashtables
* such as {@link java.util.HashMap} or {@link java.util.HashSet}.
* Hash code computed using algorithm
* suggested in Effective Java, Item 8.
*
* @return a hash code value for this object
* @see #equals(Object)
*/
@Override
public int hashCode() {
if (this.code == 0) {
int code = 17;
code = addHashCode(code, this.type);
code = addHashCode(code, this.name);
if (this.args != null) {
for (Class<?> arg : this.args) {
code = addHashCode(code, arg);
}
}
this.code = code;
}
return this.code;
}
/**
* Adds hash code value if specified object.
* This is a part of the algorithm
* suggested in Effective Java, Item 8.
*
* @param code current hash code value
* @param object object that updates hash code value
* @return updated hash code value
* @see #hashCode()
*/
private static int addHashCode(int code, Object object) {
code *= 37;
return (object != null)
? code + object.hashCode()
: code;
}
}

View File

@ -799,9 +799,9 @@ class GTKColorChooserPanel extends AbstractColorChooserPanel implements
Graphics g = triangleImage.getGraphics();
g.setColor(new Color(0, 0, 0, 0));
g.fillRect(0, 0, a, a);
g.translate((int)(a / 2), 0);
g.translate(a / 2, 0);
paintTriangle(g, triangleSize, getColor());
g.translate((int)(-a / 2), 0);
g.translate(-a / 2, 0);
g.dispose();
g = wheelImage.getGraphics();
@ -897,7 +897,7 @@ class GTKColorChooserPanel extends AbstractColorChooserPanel implements
return false;
}
// Rotate to origin and and verify x is valid.
int triangleSize = (int)innerR * 3 / 2;
int triangleSize = innerR * 3 / 2;
double x1 = Math.cos(angle) * x - Math.sin(angle) * y;
double y1 = Math.sin(angle) * x + Math.cos(angle) * y;
if (x1 < -(innerR / 2)) {
@ -960,7 +960,7 @@ class GTKColorChooserPanel extends AbstractColorChooserPanel implements
*/
private void setSaturationAndBrightness(float s, float b) {
int innerR = getTriangleCircumscribedRadius();
int triangleSize = (int)innerR * 3 / 2;
int triangleSize = innerR * 3 / 2;
double x = b * triangleSize;
double maxY = x * Math.tan(Math.toRadians(30.0));
double y = 2 * maxY * s - maxY;
@ -1156,7 +1156,7 @@ class GTKColorChooserPanel extends AbstractColorChooserPanel implements
* @param x X location to get color for
* @param y Y location to get color for
* @param rad Radius from center of color wheel
* @param integer with red, green and blue components
* @return integer with red, green and blue components
*/
private int colorWheelLocationToRGB(int x, int y, double rad) {
double angle = Math.acos((double)x / rad);
@ -1165,12 +1165,12 @@ class GTKColorChooserPanel extends AbstractColorChooserPanel implements
if (angle < PI_3) {
if (y < 0) {
// FFFF00 - FF0000
rgb = 0xFF0000 | (int)Math.min(255,
rgb = 0xFF0000 | Math.min(255,
(int)(255 * angle / PI_3)) << 8;
}
else {
// FF0000 - FF00FF
rgb = 0xFF0000 | (int)Math.min(255,
rgb = 0xFF0000 | Math.min(255,
(int)(255 * angle / PI_3));
}
}
@ -1178,12 +1178,12 @@ class GTKColorChooserPanel extends AbstractColorChooserPanel implements
angle -= PI_3;
if (y < 0) {
// 00FF00 - FFFF00
rgb = 0x00FF00 | (int)Math.max(0, 255 -
rgb = 0x00FF00 | Math.max(0, 255 -
(int)(255 * angle / PI_3)) << 16;
}
else {
// FF00FF - 0000FF
rgb = 0x0000FF | (int)Math.max(0, 255 -
rgb = 0x0000FF | Math.max(0, 255 -
(int)(255 * angle / PI_3)) << 16;
}
}
@ -1191,12 +1191,12 @@ class GTKColorChooserPanel extends AbstractColorChooserPanel implements
angle -= 2 * PI_3;
if (y < 0) {
// 00FFFF - 00FF00
rgb = 0x00FF00 | (int)Math.min(255,
rgb = 0x00FF00 | Math.min(255,
(int)(255 * angle / PI_3));
}
else {
// 0000FF - 00FFFF
rgb = 0x0000FF | (int)Math.min(255,
rgb = 0x0000FF | Math.min(255,
(int)(255 * angle / PI_3)) << 8;
}
}

View File

@ -112,7 +112,7 @@ class GTKEngine {
}
private static HashMap regionToWidgetTypeMap;
private static HashMap<Region, Object> regionToWidgetTypeMap;
private ImageCache cache = new ImageCache(CACHE_SIZE);
private int x0, y0, w0, h0;
private Graphics graphics;
@ -178,7 +178,7 @@ class GTKEngine {
Toolkit.getDefaultToolkit();
// Initialize regionToWidgetTypeMap
regionToWidgetTypeMap = new HashMap(50);
regionToWidgetTypeMap = new HashMap<Region, Object>(50);
regionToWidgetTypeMap.put(Region.ARROW_BUTTON, new WidgetType[] {
WidgetType.SPINNER_ARROW_BUTTON,
WidgetType.COMBO_BOX_ARROW_BUTTON,

View File

@ -148,7 +148,7 @@ class GTKFileChooserUI extends SynthFileChooserUI {
directoryList : fileList;
Object[] files = list.getSelectedValues();
int len = files.length;
Vector result = new Vector(len + 1);
Vector<String> result = new Vector<String>(len + 1);
// we return all selected file names
for (int i = 0; i < len; i++) {
@ -263,13 +263,13 @@ class GTKFileChooserUI extends SynthFileChooserUI {
ListSelectionModel sm = directoryList.getSelectionModel();
if (sm instanceof DefaultListSelectionModel) {
((DefaultListSelectionModel)sm).moveLeadSelectionIndex(0);
((DefaultListSelectionModel)sm).setAnchorSelectionIndex(0);
sm.setAnchorSelectionIndex(0);
}
fileList.clearSelection();
sm = fileList.getSelectionModel();
if (sm instanceof DefaultListSelectionModel) {
((DefaultListSelectionModel)sm).moveLeadSelectionIndex(0);
((DefaultListSelectionModel)sm).setAnchorSelectionIndex(0);
sm.setAnchorSelectionIndex(0);
}
File currentDirectory = getFileChooser().getCurrentDirectory();
@ -425,16 +425,16 @@ class GTKFileChooserUI extends SynthFileChooserUI {
setDirectorySelected(true);
setDirectory(((File)objects[0]));
} else {
ArrayList fList = new ArrayList(objects.length);
for (int i = 0; i < objects.length; i++) {
File f = (File)objects[i];
ArrayList<File> fList = new ArrayList<File>(objects.length);
for (Object object : objects) {
File f = (File) object;
if ((chooser.isFileSelectionEnabled() && f.isFile())
|| (chooser.isDirectorySelectionEnabled() && f.isDirectory())) {
fList.add(f);
}
}
if (fList.size() > 0) {
files = (File[])fList.toArray(new File[fList.size()]);
files = fList.toArray(new File[fList.size()]);
}
setDirectorySelected(false);
}
@ -671,9 +671,9 @@ class GTKFileChooserUI extends SynthFileChooserUI {
pathFieldLabel.setLabelFor(fileNameTextField);
Set forwardTraversalKeys = fileNameTextField.getFocusTraversalKeys(
Set<AWTKeyStroke> forwardTraversalKeys = fileNameTextField.getFocusTraversalKeys(
KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
forwardTraversalKeys = new HashSet(forwardTraversalKeys);
forwardTraversalKeys = new HashSet<AWTKeyStroke>(forwardTraversalKeys);
forwardTraversalKeys.remove(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0));
fileNameTextField.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, forwardTraversalKeys);
@ -895,10 +895,9 @@ class GTKFileChooserUI extends SynthFileChooserUI {
private class GTKDirectoryModel extends BasicDirectoryModel {
FileSystemView fsv;
private Comparator fileComparator = new Comparator() {
public int compare(Object o, Object o1) {
return fsv.getSystemDisplayName((File) o).compareTo
(fsv.getSystemDisplayName((File) o1));
private Comparator<File> fileComparator = new Comparator<File>() {
public int compare(File o, File o1) {
return fsv.getSystemDisplayName(o).compareTo(fsv.getSystemDisplayName(o1));
}
};
@ -1074,7 +1073,7 @@ class GTKFileChooserUI extends SynthFileChooserUI {
* Data model for a type-face selection combo-box.
*/
protected class DirectoryComboBoxModel extends AbstractListModel implements ComboBoxModel {
Vector directories = new Vector();
Vector<File> directories = new Vector<File>();
File selectedDirectory = null;
JFileChooser chooser = getFileChooser();
FileSystemView fsv = chooser.getFileSystemView();
@ -1216,7 +1215,7 @@ class GTKFileChooserUI extends SynthFileChooserUI {
ListSelectionModel sm = fileList.getSelectionModel();
if (sm instanceof DefaultListSelectionModel) {
((DefaultListSelectionModel)sm).moveLeadSelectionIndex(0);
((DefaultListSelectionModel)sm).setAnchorSelectionIndex(0);
sm.setAnchorSelectionIndex(0);
}
rescanCurrentDirectory(getFileChooser());
return;
@ -1352,8 +1351,8 @@ class GTKFileChooserUI extends SynthFileChooserUI {
FileFilter currentFilter = getFileChooser().getFileFilter();
boolean found = false;
if (currentFilter != null) {
for (int i = 0; i < filters.length; i++) {
if (filters[i] == currentFilter) {
for (FileFilter filter : filters) {
if (filter == currentFilter) {
found = true;
}
}

View File

@ -1470,7 +1470,7 @@ public class GTKLookAndFeel extends SynthLookAndFeel {
aaTextInfo = SwingUtilities2.AATextInfo.getAATextInfo(gtkAAFontSettingsCond);
}
static ReferenceQueue queue = new ReferenceQueue();
static ReferenceQueue<GTKLookAndFeel> queue = new ReferenceQueue<GTKLookAndFeel>();
private static void flushUnreferenced() {
WeakPCL pcl;
@ -1480,12 +1480,12 @@ public class GTKLookAndFeel extends SynthLookAndFeel {
}
}
static class WeakPCL extends WeakReference implements
static class WeakPCL extends WeakReference<GTKLookAndFeel> implements
PropertyChangeListener {
private Toolkit kit;
private String key;
WeakPCL(Object target, Toolkit kit, String key) {
WeakPCL(GTKLookAndFeel target, Toolkit kit, String key) {
super(target, queue);
this.kit = kit;
this.key = key;
@ -1494,7 +1494,7 @@ public class GTKLookAndFeel extends SynthLookAndFeel {
public String getKey() { return key; }
public void propertyChange(final PropertyChangeEvent pce) {
final GTKLookAndFeel lnf = (GTKLookAndFeel)get();
final GTKLookAndFeel lnf = get();
if (lnf == null || UIManager.getLookAndFeel() != lnf) {
// The property was GC'ed, we're no longer interested in

View File

@ -299,7 +299,7 @@ class GTKPainter extends SynthPainter {
// Paint the default indicator
GTKStyle style = (GTKStyle)context.getStyle();
if (defaultCapable && !toolButton) {
Insets defaultInsets = (Insets)style.getClassSpecificInsetsValue(
Insets defaultInsets = style.getClassSpecificInsetsValue(
context, "default-border",
GTKStyle.BUTTON_DEFAULT_BORDER_INSETS);

View File

@ -124,7 +124,7 @@ class Metacity implements SynthConstants {
}
// Initialize constants
variables = new HashMap();
variables = new HashMap<String, Integer>();
NodeList nodes = xmlDoc.getElementsByTagName("constant");
int n = nodes.getLength();
for (int i = 0; i < n; i++) {
@ -144,14 +144,14 @@ class Metacity implements SynthConstants {
}
// Cache frame geometries
frameGeometries = new HashMap();
frameGeometries = new HashMap<String, Map<String, Object>>();
nodes = xmlDoc.getElementsByTagName("frame_geometry");
n = nodes.getLength();
for (int i = 0; i < n; i++) {
Node node = nodes.item(i);
String name = getStringAttr(node, "name");
if (name != null) {
HashMap<String, Object> gm = new HashMap();
HashMap<String, Object> gm = new HashMap<String, Object>();
frameGeometries.put(name, gm);
String parentGM = getStringAttr(node, "parent");
@ -458,7 +458,7 @@ class Metacity implements SynthConstants {
private static class Privileged implements PrivilegedAction {
private static class Privileged implements PrivilegedAction<Object> {
private static int GET_THEME_DIR = 0;
private static int GET_USER_THEME = 1;
private static int GET_IMAGE = 2;
@ -598,7 +598,7 @@ class Metacity implements SynthConstants {
g2.setComposite(oldComp);
}
private HashMap<String, Image> images = new HashMap();
private HashMap<String, Image> images = new HashMap<String, Image>();
protected Image getImage(String key, Color c) {
Image image = images.get(key+"-"+c.getRGB());
@ -1530,8 +1530,8 @@ class Metacity implements SynthConstants {
DocumentBuilderFactory.newInstance().newDocumentBuilder();
}
InputStream inputStream =
(InputStream)AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
AccessController.doPrivileged(new PrivilegedAction<InputStream>() {
public InputStream run() {
try {
return new BufferedInputStream(xmlFile.openStream());
} catch (IOException ex) {
@ -1551,7 +1551,7 @@ class Metacity implements SynthConstants {
protected Node[] getNodesByName(Node parent, String name) {
NodeList nodes = parent.getChildNodes(); // ElementNode
int n = nodes.getLength();
ArrayList<Node> list = new ArrayList();
ArrayList<Node> list = new ArrayList<Node>();
for (int i=0; i < n; i++) {
Node node = nodes.item(i);
if (name.equals(node.getNodeName())) {
@ -1603,7 +1603,7 @@ class Metacity implements SynthConstants {
String aValue = attrs[a * 2 + 1];
Node attr = nodeAttrs.getNamedItem(aName);
if (attr == null ||
aValue != null && !aValue.equals((String)attr.getNodeValue())) {
aValue != null && !aValue.equals(attr.getNodeValue())) {
matches = false;
break;
}
@ -1642,7 +1642,7 @@ class Metacity implements SynthConstants {
protected String getStringAttr(NamedNodeMap attrs, String name) {
Node item = attrs.getNamedItem(name);
return (item != null) ? (String)item.getNodeValue() : null;
return (item != null) ? item.getNodeValue() : null;
}
protected boolean getBooleanAttr(Node node, String name, boolean fallback) {

View File

@ -70,7 +70,6 @@ public class WindowsFileChooserUI extends BasicFileChooserUI {
private JTextField filenameTextField;
private FilePane filePane;
private WindowsPlacesBar placesBar;
private boolean useShellFolder;
private JButton approveButton;
private JButton cancelButton;
@ -210,10 +209,6 @@ public class WindowsFileChooserUI extends BasicFileChooserUI {
public ListSelectionListener createListSelectionListener() {
return WindowsFileChooserUI.this.createListSelectionListener(getFileChooser());
}
public boolean usesShellFolder() {
return useShellFolder;
}
}
public void installComponents(JFileChooser fc) {
@ -625,15 +620,8 @@ public class WindowsFileChooserUI extends BasicFileChooserUI {
// Decide whether to use the ShellFolder class to populate shortcut
// panel and combobox.
JFileChooser fc = getFileChooser();
Boolean prop =
(Boolean)fc.getClientProperty("FileChooser.useShellFolder");
if (prop != null) {
useShellFolder = prop.booleanValue();
} else {
useShellFolder = fc.getFileSystemView().equals(FileSystemView.getFileSystemView());
}
if (OS_VERSION.compareTo(OSInfo.WINDOWS_ME) >= 0) {
if (useShellFolder) {
if (FilePane.usesShellFolder(fc)) {
if (placesBar == null && !UIManager.getBoolean("FileChooser.noPlacesBar")) {
placesBar = new WindowsPlacesBar(fc, XPStyle.getXP() != null);
fc.add(placesBar, BorderLayout.BEFORE_LINE_BEGINS);
@ -1149,6 +1137,8 @@ public class WindowsFileChooserUI extends BasicFileChooserUI {
return;
}
boolean useShellFolder = FilePane.usesShellFolder(chooser);
directories.clear();
File[] baseFolders;

View File

@ -1554,10 +1554,10 @@ public class WindowsLookAndFeel extends BasicLookAndFeel
"Tree.selectionBackground", SelectionBackgroundColor,
"Tree.expandedIcon", treeExpandedIcon,
"Tree.collapsedIcon", treeCollapsedIcon,
"Tree.openIcon", new ActiveWindowsIcon("win.icon.shellIconBPP", "shell32Icon 5",
(Icon)table.get("Tree.openIcon")),
"Tree.closedIcon", new ActiveWindowsIcon("win.icon.shellIconBPP", "shell32Icon 4",
(Icon)table.get("Tree.closedIcon")),
"Tree.openIcon", new ActiveWindowsIcon("win.icon.shellIconBPP",
"shell32Icon 5", "icons/TreeOpen.gif"),
"Tree.closedIcon", new ActiveWindowsIcon("win.icon.shellIconBPP",
"shell32Icon 4", "icons/TreeClosed.gif"),
"Tree.focusInputMap",
new UIDefaults.LazyInputMap(new Object[] {
"ADD", "expand",
@ -2205,21 +2205,21 @@ public class WindowsLookAndFeel extends BasicLookAndFeel
*/
private class ActiveWindowsIcon implements UIDefaults.ActiveValue {
private Icon icon;
private Icon fallback;
private String nativeImageName;
private String fallbackName;
private DesktopProperty desktopProperty;
ActiveWindowsIcon(String desktopPropertyName,
String nativeImageName, Icon fallback) {
String nativeImageName, String fallbackName) {
this.nativeImageName = nativeImageName;
this.fallback = fallback;
this.fallbackName = fallbackName;
if (OSInfo.getOSType() == OSInfo.OSType.WINDOWS &&
OSInfo.getWindowsVersion().compareTo(OSInfo.WINDOWS_XP) < 0) {
// This desktop property is needed to trigger reloading the icon.
// It is kept in member variable to avoid GC.
this.desktopProperty = new TriggerDesktopProperty(desktopPropertyName) {
protected void updateUI() {
@Override protected void updateUI() {
icon = null;
super.updateUI();
}
@ -2227,6 +2227,7 @@ public class WindowsLookAndFeel extends BasicLookAndFeel
}
}
@Override
public Object createValue(UIDefaults table) {
if (icon == null) {
Image image = (Image)ShellFolder.get(nativeImageName);
@ -2234,8 +2235,11 @@ public class WindowsLookAndFeel extends BasicLookAndFeel
icon = new ImageIconUIResource(image);
}
}
if (icon == null && fallback != null) {
icon = fallback;
if (icon == null && fallbackName != null) {
UIDefaults.LazyValue fallback = (UIDefaults.LazyValue)
SwingUtilities2.makeIcon(WindowsLookAndFeel.class,
BasicLookAndFeel.class, fallbackName);
icon = (Icon) fallback.createValue(table);
}
return icon;
}

View File

@ -75,13 +75,6 @@ abstract class AbstractMidiDevice implements MidiDevice, ReferenceCountingDevice
/**
* This is the device handle returned from native code
*/
/*
* $$rratta Solaris 64 bit holds pointer must be long
*
* $$mp 2003-08-07:
* 'id' is a really bad name. The variable should
* be called nativePointer or something similar.
*/
protected long id = 0;
@ -586,7 +579,6 @@ abstract class AbstractMidiDevice implements MidiDevice, ReferenceCountingDevice
private ArrayList<Transmitter> transmitters = new ArrayList<Transmitter>();
private MidiOutDevice.MidiOutReceiver midiOutReceiver;
private MixerSynth.SynthReceiver mixerSynthReceiver;
// how many transmitters must be present for optimized
// handling
@ -621,22 +613,14 @@ abstract class AbstractMidiDevice implements MidiDevice, ReferenceCountingDevice
if (midiOutReceiver == oldR) {
midiOutReceiver = null;
}
if (mixerSynthReceiver == oldR) {
mixerSynthReceiver = null;
}
if (newR != null) {
if ((newR instanceof MidiOutDevice.MidiOutReceiver)
&& (midiOutReceiver == null)) {
midiOutReceiver = ((MidiOutDevice.MidiOutReceiver) newR);
}
if ((newR instanceof MixerSynth.SynthReceiver)
&& (mixerSynthReceiver == null)) {
mixerSynthReceiver = ((MixerSynth.SynthReceiver) newR);
}
}
optimizedReceiverCount =
((midiOutReceiver!=null)?1:0)
+ ((mixerSynthReceiver!=null)?1:0);
((midiOutReceiver!=null)?1:0);
}
// more potential for optimization here
}
@ -670,10 +654,6 @@ abstract class AbstractMidiDevice implements MidiDevice, ReferenceCountingDevice
if (TRACE_TRANSMITTER) Printer.println("Sending packed message to MidiOutReceiver");
midiOutReceiver.sendPackedMidiMessage(packedMessage, timeStamp);
}
if (mixerSynthReceiver != null) {
if (TRACE_TRANSMITTER) Printer.println("Sending packed message to MixerSynthReceiver");
mixerSynthReceiver.sendPackedMidiMessage(packedMessage, timeStamp);
}
} else {
if (TRACE_TRANSMITTER) Printer.println("Sending packed message to "+size+" transmitter's receivers");
for (int i = 0; i < size; i++) {
@ -682,9 +662,6 @@ abstract class AbstractMidiDevice implements MidiDevice, ReferenceCountingDevice
if (optimizedReceiverCount > 0) {
if (receiver instanceof MidiOutDevice.MidiOutReceiver) {
((MidiOutDevice.MidiOutReceiver) receiver).sendPackedMidiMessage(packedMessage, timeStamp);
}
else if (receiver instanceof MixerSynth.SynthReceiver) {
((MixerSynth.SynthReceiver) receiver).sendPackedMidiMessage(packedMessage, timeStamp);
} else {
receiver.send(new FastShortMessage(packedMessage), timeStamp);
}
@ -739,10 +716,6 @@ abstract class AbstractMidiDevice implements MidiDevice, ReferenceCountingDevice
if (TRACE_TRANSMITTER) Printer.println("Sending MIDI message to MidiOutReceiver");
midiOutReceiver.send(message, timeStamp);
}
if (mixerSynthReceiver != null) {
if (TRACE_TRANSMITTER) Printer.println("Sending MIDI message to MixerSynthReceiver");
mixerSynthReceiver.send(message, timeStamp);
}
} else {
if (TRACE_TRANSMITTER) Printer.println("Sending MIDI message to "+size+" transmitter's receivers");
for (int i = 0; i < size; i++) {

View File

@ -0,0 +1,131 @@
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import javax.sound.midi.InvalidMidiDataException;
import javax.sound.midi.Soundbank;
import javax.sound.midi.spi.SoundbankReader;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.UnsupportedAudioFileException;
/**
* Soundbank reader that uses audio files as soundbanks.
*
* @author Karl Helgason
*/
public class AudioFileSoundbankReader extends SoundbankReader {
public Soundbank getSoundbank(URL url)
throws InvalidMidiDataException, IOException {
try {
AudioInputStream ais = AudioSystem.getAudioInputStream(url);
Soundbank sbk = getSoundbank(ais);
ais.close();
return sbk;
} catch (UnsupportedAudioFileException e) {
return null;
} catch (IOException e) {
return null;
}
}
public Soundbank getSoundbank(InputStream stream)
throws InvalidMidiDataException, IOException {
stream.mark(512);
try {
AudioInputStream ais = AudioSystem.getAudioInputStream(stream);
Soundbank sbk = getSoundbank(ais);
if (sbk != null)
return sbk;
} catch (UnsupportedAudioFileException e) {
} catch (IOException e) {
}
stream.reset();
return null;
}
public Soundbank getSoundbank(AudioInputStream ais)
throws InvalidMidiDataException, IOException {
try {
byte[] buffer;
if (ais.getFrameLength() == -1) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buff = new byte[1024
- (1024 % ais.getFormat().getFrameSize())];
int ret;
while ((ret = ais.read(buff)) != -1) {
baos.write(buff, 0, ret);
}
ais.close();
buffer = baos.toByteArray();
} else {
buffer = new byte[(int) (ais.getFrameLength()
* ais.getFormat().getFrameSize())];
new DataInputStream(ais).readFully(buffer);
}
ModelByteBufferWavetable osc = new ModelByteBufferWavetable(
new ModelByteBuffer(buffer), ais.getFormat(), -4800);
ModelPerformer performer = new ModelPerformer();
performer.getOscillators().add(osc);
SimpleSoundbank sbk = new SimpleSoundbank();
SimpleInstrument ins = new SimpleInstrument();
ins.add(performer);
sbk.addInstrument(ins);
return sbk;
} catch (Exception e) {
return null;
}
}
public Soundbank getSoundbank(File file)
throws InvalidMidiDataException, IOException {
try {
AudioInputStream ais = AudioSystem.getAudioInputStream(file);
ais.close();
ModelByteBufferWavetable osc = new ModelByteBufferWavetable(
new ModelByteBuffer(file, 0, file.length()), -4800);
ModelPerformer performer = new ModelPerformer();
performer.getOscillators().add(osc);
SimpleSoundbank sbk = new SimpleSoundbank();
SimpleInstrument ins = new SimpleInstrument();
ins.add(performer);
sbk.addInstrument(ins);
return sbk;
} catch (UnsupportedAudioFileException e1) {
return null;
} catch (IOException e) {
return null;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,617 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.AudioFormat.Encoding;
import javax.sound.sampled.spi.FormatConversionProvider;
/**
* This class is used to convert between 8,16,24,32 bit signed/unsigned
* big/litle endian fixed/floating stereo/mono/multi-channel audio streams and
* perform sample-rate conversion if needed.
*
* @author Karl Helgason
*/
public class AudioFloatFormatConverter extends FormatConversionProvider {
private static class AudioFloatFormatConverterInputStream extends
InputStream {
private AudioFloatConverter converter;
private AudioFloatInputStream stream;
private float[] readfloatbuffer;
private int fsize = 0;
public AudioFloatFormatConverterInputStream(AudioFormat targetFormat,
AudioFloatInputStream stream) {
this.stream = stream;
converter = AudioFloatConverter.getConverter(targetFormat);
fsize = ((targetFormat.getSampleSizeInBits() + 7) / 8);
}
public int read() throws IOException {
byte[] b = new byte[1];
int ret = read(b);
if (ret < 0)
return ret;
return b[0] & 0xFF;
}
public int read(byte[] b, int off, int len) throws IOException {
int flen = len / fsize;
if (readfloatbuffer == null || readfloatbuffer.length < flen)
readfloatbuffer = new float[flen];
int ret = stream.read(readfloatbuffer, 0, flen);
if (ret < 0)
return ret;
converter.toByteArray(readfloatbuffer, 0, ret, b, off);
return ret * fsize;
}
public int available() throws IOException {
int ret = stream.available();
if (ret < 0)
return ret;
return ret * fsize;
}
public void close() throws IOException {
stream.close();
}
public synchronized void mark(int readlimit) {
stream.mark(readlimit * fsize);
}
public boolean markSupported() {
return stream.markSupported();
}
public synchronized void reset() throws IOException {
stream.reset();
}
public long skip(long n) throws IOException {
long ret = stream.skip(n / fsize);
if (ret < 0)
return ret;
return ret * fsize;
}
}
private static class AudioFloatInputStreamChannelMixer extends
AudioFloatInputStream {
private int targetChannels;
private int sourceChannels;
private AudioFloatInputStream ais;
private AudioFormat targetFormat;
private float[] conversion_buffer;
public AudioFloatInputStreamChannelMixer(AudioFloatInputStream ais,
int targetChannels) {
this.sourceChannels = ais.getFormat().getChannels();
this.targetChannels = targetChannels;
this.ais = ais;
AudioFormat format = ais.getFormat();
targetFormat = new AudioFormat(format.getEncoding(), format
.getSampleRate(), format.getSampleSizeInBits(),
targetChannels, (format.getFrameSize() / sourceChannels)
* targetChannels, format.getFrameRate(), format
.isBigEndian());
}
public int available() throws IOException {
return (ais.available() / sourceChannels) * targetChannels;
}
public void close() throws IOException {
ais.close();
}
public AudioFormat getFormat() {
return targetFormat;
}
public long getFrameLength() {
return ais.getFrameLength();
}
public void mark(int readlimit) {
ais.mark((readlimit / targetChannels) * sourceChannels);
}
public boolean markSupported() {
return ais.markSupported();
}
public int read(float[] b, int off, int len) throws IOException {
int len2 = (len / targetChannels) * sourceChannels;
if (conversion_buffer == null || conversion_buffer.length < len2)
conversion_buffer = new float[len2];
int ret = ais.read(conversion_buffer, 0, len2);
if (ret < 0)
return ret;
if (sourceChannels == 1) {
int cs = targetChannels;
for (int c = 0; c < targetChannels; c++) {
for (int i = 0, ix = off + c; i < len2; i++, ix += cs) {
b[ix] = conversion_buffer[i];
;
}
}
} else if (targetChannels == 1) {
int cs = sourceChannels;
for (int i = 0, ix = off; i < len2; i += cs, ix++) {
b[ix] = conversion_buffer[i];
}
for (int c = 1; c < sourceChannels; c++) {
for (int i = c, ix = off; i < len2; i += cs, ix++) {
b[ix] += conversion_buffer[i];
;
}
}
float vol = 1f / ((float) sourceChannels);
for (int i = 0, ix = off; i < len2; i += cs, ix++) {
b[ix] *= vol;
}
} else {
int minChannels = Math.min(sourceChannels, targetChannels);
int off_len = off + len;
int ct = targetChannels;
int cs = sourceChannels;
for (int c = 0; c < minChannels; c++) {
for (int i = off + c, ix = c; i < off_len; i += ct, ix += cs) {
b[i] = conversion_buffer[ix];
}
}
for (int c = minChannels; c < targetChannels; c++) {
for (int i = off + c; i < off_len; i += ct) {
b[i] = 0;
}
}
}
return (ret / sourceChannels) * targetChannels;
}
public void reset() throws IOException {
ais.reset();
}
public long skip(long len) throws IOException {
long ret = ais.skip((len / targetChannels) * sourceChannels);
if (ret < 0)
return ret;
return (ret / sourceChannels) * targetChannels;
}
}
private static class AudioFloatInputStreamResampler extends
AudioFloatInputStream {
private AudioFloatInputStream ais;
private AudioFormat targetFormat;
private float[] skipbuffer;
private SoftAbstractResampler resampler;
private float[] pitch = new float[1];
private float[] ibuffer2;
private float[][] ibuffer;
private float ibuffer_index = 0;
private int ibuffer_len = 0;
private int nrofchannels = 0;
private float[][] cbuffer;
private int buffer_len = 512;
private int pad;
private int pad2;
private float[] ix = new float[1];
private int[] ox = new int[1];
private float[][] mark_ibuffer = null;
private float mark_ibuffer_index = 0;
private int mark_ibuffer_len = 0;
public AudioFloatInputStreamResampler(AudioFloatInputStream ais,
AudioFormat format) {
this.ais = ais;
AudioFormat sourceFormat = ais.getFormat();
targetFormat = new AudioFormat(sourceFormat.getEncoding(), format
.getSampleRate(), sourceFormat.getSampleSizeInBits(),
sourceFormat.getChannels(), sourceFormat.getFrameSize(),
format.getSampleRate(), sourceFormat.isBigEndian());
nrofchannels = targetFormat.getChannels();
Object interpolation = format.getProperty("interpolation");
if (interpolation != null && (interpolation instanceof String)) {
String resamplerType = (String) interpolation;
if (resamplerType.equalsIgnoreCase("point"))
this.resampler = new SoftPointResampler();
if (resamplerType.equalsIgnoreCase("linear"))
this.resampler = new SoftLinearResampler2();
if (resamplerType.equalsIgnoreCase("linear1"))
this.resampler = new SoftLinearResampler();
if (resamplerType.equalsIgnoreCase("linear2"))
this.resampler = new SoftLinearResampler2();
if (resamplerType.equalsIgnoreCase("cubic"))
this.resampler = new SoftCubicResampler();
if (resamplerType.equalsIgnoreCase("lanczos"))
this.resampler = new SoftLanczosResampler();
if (resamplerType.equalsIgnoreCase("sinc"))
this.resampler = new SoftSincResampler();
}
if (resampler == null)
resampler = new SoftLinearResampler2(); // new
// SoftLinearResampler2();
pitch[0] = sourceFormat.getSampleRate() / format.getSampleRate();
pad = resampler.getPadding();
pad2 = pad * 2;
ibuffer = new float[nrofchannels][buffer_len + pad2];
ibuffer2 = new float[nrofchannels * buffer_len];
ibuffer_index = buffer_len + pad;
ibuffer_len = buffer_len;
}
public int available() throws IOException {
return 0;
}
public void close() throws IOException {
ais.close();
}
public AudioFormat getFormat() {
return targetFormat;
}
public long getFrameLength() {
return AudioSystem.NOT_SPECIFIED; // ais.getFrameLength();
}
public void mark(int readlimit) {
ais.mark((int) (readlimit * pitch[0]));
mark_ibuffer_index = ibuffer_index;
mark_ibuffer_len = ibuffer_len;
if (mark_ibuffer == null) {
mark_ibuffer = new float[ibuffer.length][ibuffer[0].length];
}
for (int c = 0; c < ibuffer.length; c++) {
float[] from = ibuffer[c];
float[] to = mark_ibuffer[c];
for (int i = 0; i < to.length; i++) {
to[i] = from[i];
}
}
}
public boolean markSupported() {
return ais.markSupported();
}
private void readNextBuffer() throws IOException {
if (ibuffer_len == -1)
return;
for (int c = 0; c < nrofchannels; c++) {
float[] buff = ibuffer[c];
int buffer_len_pad = ibuffer_len + pad2;
for (int i = ibuffer_len, ix = 0; i < buffer_len_pad; i++, ix++) {
buff[ix] = buff[i];
}
}
ibuffer_index -= (ibuffer_len);
ibuffer_len = ais.read(ibuffer2);
if (ibuffer_len >= 0) {
while (ibuffer_len < ibuffer2.length) {
int ret = ais.read(ibuffer2, ibuffer_len, ibuffer2.length
- ibuffer_len);
if (ret == -1)
break;
ibuffer_len += ret;
}
Arrays.fill(ibuffer2, ibuffer_len, ibuffer2.length, 0);
ibuffer_len /= nrofchannels;
} else {
Arrays.fill(ibuffer2, 0, ibuffer2.length, 0);
}
int ibuffer2_len = ibuffer2.length;
for (int c = 0; c < nrofchannels; c++) {
float[] buff = ibuffer[c];
for (int i = c, ix = pad2; i < ibuffer2_len; i += nrofchannels, ix++) {
buff[ix] = ibuffer2[i];
}
}
}
public int read(float[] b, int off, int len) throws IOException {
if (cbuffer == null || cbuffer[0].length < len / nrofchannels) {
cbuffer = new float[nrofchannels][len / nrofchannels];
}
if (ibuffer_len == -1)
return -1;
if (len < 0)
return 0;
int remain = len / nrofchannels;
int destPos = 0;
int in_end = ibuffer_len;
while (remain > 0) {
if (ibuffer_len >= 0) {
if (ibuffer_index >= (ibuffer_len + pad))
readNextBuffer();
in_end = ibuffer_len + pad;
}
if (ibuffer_len < 0) {
in_end = pad2;
if (ibuffer_index >= in_end)
break;
}
if (ibuffer_index < 0)
break;
int preDestPos = destPos;
for (int c = 0; c < nrofchannels; c++) {
ix[0] = ibuffer_index;
ox[0] = destPos;
float[] buff = ibuffer[c];
resampler.interpolate(buff, ix, in_end, pitch, 0,
cbuffer[c], ox, len / nrofchannels);
}
ibuffer_index = ix[0];
destPos = ox[0];
remain -= destPos - preDestPos;
}
for (int c = 0; c < nrofchannels; c++) {
int ix = 0;
float[] buff = cbuffer[c];
for (int i = c; i < b.length; i += nrofchannels) {
b[i] = buff[ix++];
}
}
return len - remain * nrofchannels;
}
public void reset() throws IOException {
ais.reset();
if (mark_ibuffer == null)
return;
ibuffer_index = mark_ibuffer_index;
ibuffer_len = mark_ibuffer_len;
for (int c = 0; c < ibuffer.length; c++) {
float[] from = mark_ibuffer[c];
float[] to = ibuffer[c];
for (int i = 0; i < to.length; i++) {
to[i] = from[i];
}
}
}
public long skip(long len) throws IOException {
if (len > 0)
return 0;
if (skipbuffer == null)
skipbuffer = new float[1024 * targetFormat.getFrameSize()];
float[] l_skipbuffer = skipbuffer;
long remain = len;
while (remain > 0) {
int ret = read(l_skipbuffer, 0, (int) Math.min(remain,
skipbuffer.length));
if (ret < 0) {
if (remain == len)
return ret;
break;
}
remain -= ret;
}
return len - remain;
}
}
private Encoding[] formats = { Encoding.PCM_SIGNED, Encoding.PCM_UNSIGNED,
AudioFloatConverter.PCM_FLOAT };
public AudioInputStream getAudioInputStream(Encoding targetEncoding,
AudioInputStream sourceStream) {
if (sourceStream.getFormat().getEncoding().equals(targetEncoding))
return sourceStream;
AudioFormat format = sourceStream.getFormat();
int channels = format.getChannels();
Encoding encoding = targetEncoding;
float samplerate = format.getSampleRate();
int bits = format.getSampleSizeInBits();
boolean bigendian = format.isBigEndian();
if (targetEncoding.equals(AudioFloatConverter.PCM_FLOAT))
bits = 32;
AudioFormat targetFormat = new AudioFormat(encoding, samplerate, bits,
channels, channels * bits / 8, samplerate, bigendian);
return getAudioInputStream(targetFormat, sourceStream);
}
public AudioInputStream getAudioInputStream(AudioFormat targetFormat,
AudioInputStream sourceStream) {
if (!isConversionSupported(targetFormat, sourceStream.getFormat()))
throw new IllegalArgumentException("Unsupported conversion: "
+ sourceStream.getFormat().toString() + " to "
+ targetFormat.toString());
return getAudioInputStream(targetFormat, AudioFloatInputStream
.getInputStream(sourceStream));
}
public AudioInputStream getAudioInputStream(AudioFormat targetFormat,
AudioFloatInputStream sourceStream) {
if (!isConversionSupported(targetFormat, sourceStream.getFormat()))
throw new IllegalArgumentException("Unsupported conversion: "
+ sourceStream.getFormat().toString() + " to "
+ targetFormat.toString());
if (targetFormat.getChannels() != sourceStream.getFormat()
.getChannels())
sourceStream = new AudioFloatInputStreamChannelMixer(sourceStream,
targetFormat.getChannels());
if (Math.abs(targetFormat.getSampleRate()
- sourceStream.getFormat().getSampleRate()) > 0.000001)
sourceStream = new AudioFloatInputStreamResampler(sourceStream,
targetFormat);
return new AudioInputStream(new AudioFloatFormatConverterInputStream(
targetFormat, sourceStream), targetFormat, sourceStream
.getFrameLength());
}
public Encoding[] getSourceEncodings() {
return new Encoding[] { Encoding.PCM_SIGNED, Encoding.PCM_UNSIGNED,
AudioFloatConverter.PCM_FLOAT };
}
public Encoding[] getTargetEncodings() {
return new Encoding[] { Encoding.PCM_SIGNED, Encoding.PCM_UNSIGNED,
AudioFloatConverter.PCM_FLOAT };
}
public Encoding[] getTargetEncodings(AudioFormat sourceFormat) {
if (AudioFloatConverter.getConverter(sourceFormat) == null)
return new Encoding[0];
return new Encoding[] { Encoding.PCM_SIGNED, Encoding.PCM_UNSIGNED,
AudioFloatConverter.PCM_FLOAT };
}
public AudioFormat[] getTargetFormats(Encoding targetEncoding,
AudioFormat sourceFormat) {
if (AudioFloatConverter.getConverter(sourceFormat) == null)
return new AudioFormat[0];
int channels = sourceFormat.getChannels();
ArrayList<AudioFormat> formats = new ArrayList<AudioFormat>();
if (targetEncoding.equals(Encoding.PCM_SIGNED))
formats.add(new AudioFormat(Encoding.PCM_SIGNED,
AudioSystem.NOT_SPECIFIED, 8, channels, channels,
AudioSystem.NOT_SPECIFIED, false));
if (targetEncoding.equals(Encoding.PCM_UNSIGNED))
formats.add(new AudioFormat(Encoding.PCM_UNSIGNED,
AudioSystem.NOT_SPECIFIED, 8, channels, channels,
AudioSystem.NOT_SPECIFIED, false));
for (int bits = 16; bits < 32; bits += 8) {
if (targetEncoding.equals(Encoding.PCM_SIGNED)) {
formats.add(new AudioFormat(Encoding.PCM_SIGNED,
AudioSystem.NOT_SPECIFIED, bits, channels, channels
* bits / 8, AudioSystem.NOT_SPECIFIED, false));
formats.add(new AudioFormat(Encoding.PCM_SIGNED,
AudioSystem.NOT_SPECIFIED, bits, channels, channels
* bits / 8, AudioSystem.NOT_SPECIFIED, true));
}
if (targetEncoding.equals(Encoding.PCM_UNSIGNED)) {
formats.add(new AudioFormat(Encoding.PCM_UNSIGNED,
AudioSystem.NOT_SPECIFIED, bits, channels, channels
* bits / 8, AudioSystem.NOT_SPECIFIED, true));
formats.add(new AudioFormat(Encoding.PCM_UNSIGNED,
AudioSystem.NOT_SPECIFIED, bits, channels, channels
* bits / 8, AudioSystem.NOT_SPECIFIED, false));
}
}
if (targetEncoding.equals(AudioFloatConverter.PCM_FLOAT)) {
formats.add(new AudioFormat(AudioFloatConverter.PCM_FLOAT,
AudioSystem.NOT_SPECIFIED, 32, channels, channels * 4,
AudioSystem.NOT_SPECIFIED, false));
formats.add(new AudioFormat(AudioFloatConverter.PCM_FLOAT,
AudioSystem.NOT_SPECIFIED, 32, channels, channels * 4,
AudioSystem.NOT_SPECIFIED, true));
formats.add(new AudioFormat(AudioFloatConverter.PCM_FLOAT,
AudioSystem.NOT_SPECIFIED, 64, channels, channels * 8,
AudioSystem.NOT_SPECIFIED, false));
formats.add(new AudioFormat(AudioFloatConverter.PCM_FLOAT,
AudioSystem.NOT_SPECIFIED, 64, channels, channels * 8,
AudioSystem.NOT_SPECIFIED, true));
}
return formats.toArray(new AudioFormat[formats.size()]);
}
public boolean isConversionSupported(AudioFormat targetFormat,
AudioFormat sourceFormat) {
if (AudioFloatConverter.getConverter(sourceFormat) == null)
return false;
if (AudioFloatConverter.getConverter(targetFormat) == null)
return false;
if (sourceFormat.getChannels() <= 0)
return false;
if (targetFormat.getChannels() <= 0)
return false;
return true;
}
public boolean isConversionSupported(Encoding targetEncoding,
AudioFormat sourceFormat) {
if (AudioFloatConverter.getConverter(sourceFormat) == null)
return false;
for (int i = 0; i < formats.length; i++) {
if (targetEncoding.equals(formats[i]))
return true;
}
return false;
}
}

View File

@ -0,0 +1,281 @@
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.UnsupportedAudioFileException;
/**
* This class is used to create AudioFloatInputStream from AudioInputStream and
* byte buffers.
*
* @author Karl Helgason
*/
public abstract class AudioFloatInputStream {
private static class BytaArrayAudioFloatInputStream
extends AudioFloatInputStream {
private int pos = 0;
private int markpos = 0;
private AudioFloatConverter converter;
private AudioFormat format;
private byte[] buffer;
private int buffer_offset;
private int buffer_len;
private int framesize_pc;
public BytaArrayAudioFloatInputStream(AudioFloatConverter converter,
byte[] buffer, int offset, int len) {
this.converter = converter;
this.format = converter.getFormat();
this.buffer = buffer;
this.buffer_offset = offset;
framesize_pc = format.getFrameSize() / format.getChannels();
this.buffer_len = len / framesize_pc;
}
public AudioFormat getFormat() {
return format;
}
public long getFrameLength() {
return buffer_len;// / format.getFrameSize();
}
public int read(float[] b, int off, int len) throws IOException {
if (b == null)
throw new NullPointerException();
if (off < 0 || len < 0 || len > b.length - off)
throw new IndexOutOfBoundsException();
if (pos >= buffer_len)
return -1;
if (len == 0)
return 0;
if (pos + len > buffer_len)
len = buffer_len - pos;
converter.toFloatArray(buffer, buffer_offset + pos * framesize_pc,
b, off, len);
pos += len;
return len;
}
public long skip(long len) throws IOException {
if (pos >= buffer_len)
return -1;
if (len <= 0)
return 0;
if (pos + len > buffer_len)
len = buffer_len - pos;
pos += len;
return len;
}
public int available() throws IOException {
return buffer_len - pos;
}
public void close() throws IOException {
}
public void mark(int readlimit) {
markpos = pos;
}
public boolean markSupported() {
return true;
}
public void reset() throws IOException {
pos = markpos;
}
}
private static class DirectAudioFloatInputStream
extends AudioFloatInputStream {
private AudioInputStream stream;
private AudioFloatConverter converter;
private int framesize_pc; // framesize / channels
private byte[] buffer;
public DirectAudioFloatInputStream(AudioInputStream stream) {
converter = AudioFloatConverter.getConverter(stream.getFormat());
if (converter == null) {
AudioFormat format = stream.getFormat();
AudioFormat newformat;
AudioFormat[] formats = AudioSystem.getTargetFormats(
AudioFormat.Encoding.PCM_SIGNED, format);
if (formats.length != 0) {
newformat = formats[0];
} else {
float samplerate = format.getSampleRate();
int samplesizeinbits = format.getSampleSizeInBits();
int framesize = format.getFrameSize();
float framerate = format.getFrameRate();
samplesizeinbits = 16;
framesize = format.getChannels() * (samplesizeinbits / 8);
framerate = samplerate;
newformat = new AudioFormat(
AudioFormat.Encoding.PCM_SIGNED, samplerate,
samplesizeinbits, format.getChannels(), framesize,
framerate, false);
}
stream = AudioSystem.getAudioInputStream(newformat, stream);
converter = AudioFloatConverter.getConverter(stream.getFormat());
}
framesize_pc = stream.getFormat().getFrameSize()
/ stream.getFormat().getChannels();
this.stream = stream;
}
public AudioFormat getFormat() {
return stream.getFormat();
}
public long getFrameLength() {
return stream.getFrameLength();
}
public int read(float[] b, int off, int len) throws IOException {
int b_len = len * framesize_pc;
if (buffer == null || buffer.length < b_len)
buffer = new byte[b_len];
int ret = stream.read(buffer, 0, b_len);
if (ret == -1)
return -1;
converter.toFloatArray(buffer, b, off, ret / framesize_pc);
return ret / framesize_pc;
}
public long skip(long len) throws IOException {
long b_len = len * framesize_pc;
long ret = stream.skip(b_len);
if (ret == -1)
return -1;
return ret / framesize_pc;
}
public int available() throws IOException {
return stream.available() / framesize_pc;
}
public void close() throws IOException {
stream.close();
}
public void mark(int readlimit) {
stream.mark(readlimit * framesize_pc);
}
public boolean markSupported() {
return stream.markSupported();
}
public void reset() throws IOException {
stream.reset();
}
}
public static AudioFloatInputStream getInputStream(URL url)
throws UnsupportedAudioFileException, IOException {
return new DirectAudioFloatInputStream(AudioSystem
.getAudioInputStream(url));
}
public static AudioFloatInputStream getInputStream(File file)
throws UnsupportedAudioFileException, IOException {
return new DirectAudioFloatInputStream(AudioSystem
.getAudioInputStream(file));
}
public static AudioFloatInputStream getInputStream(InputStream stream)
throws UnsupportedAudioFileException, IOException {
return new DirectAudioFloatInputStream(AudioSystem
.getAudioInputStream(stream));
}
public static AudioFloatInputStream getInputStream(
AudioInputStream stream) {
return new DirectAudioFloatInputStream(stream);
}
public static AudioFloatInputStream getInputStream(AudioFormat format,
byte[] buffer, int offset, int len) {
AudioFloatConverter converter = AudioFloatConverter
.getConverter(format);
if (converter != null)
return new BytaArrayAudioFloatInputStream(converter, buffer,
offset, len);
InputStream stream = new ByteArrayInputStream(buffer, offset, len);
long aLen = format.getFrameSize() == AudioSystem.NOT_SPECIFIED
? AudioSystem.NOT_SPECIFIED : len / format.getFrameSize();
AudioInputStream astream = new AudioInputStream(stream, format, aLen);
return getInputStream(astream);
}
public abstract AudioFormat getFormat();
public abstract long getFrameLength();
public abstract int read(float[] b, int off, int len) throws IOException;
public int read(float[] b) throws IOException {
return read(b, 0, b.length);
}
public float read() throws IOException {
float[] b = new float[1];
int ret = read(b, 0, 1);
if (ret == -1 || ret == 0)
return 0;
return b[0];
}
public abstract long skip(long len) throws IOException;
public abstract int available() throws IOException;
public abstract void close() throws IOException;
public abstract void mark(int readlimit);
public abstract boolean markSupported();
public abstract void reset() throws IOException;
}

View File

@ -0,0 +1,128 @@
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
import java.util.Map;
import javax.sound.midi.MidiUnavailableException;
import javax.sound.midi.Synthesizer;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.SourceDataLine;
/**
* <code>AudioSynthesizer</code> is a <code>Synthesizer</code>
* which renders it's output audio into <code>SourceDataLine</code>
* or <code>AudioInputStream</code>.
*
* @see MidiSystem#getSynthesizer
* @see Synthesizer
*
* @author Karl Helgason
*/
public interface AudioSynthesizer extends Synthesizer {
/**
* Obtains the current format (encoding, sample rate, number of channels,
* etc.) of the synthesizer audio data.
*
* <p>If the synthesizer is not open and has never been opened, it returns
* the default format.
*
* @return current audio data format
* @see AudioFormat
*/
public AudioFormat getFormat();
/**
* Gets information about the possible properties for the synthesizer.
*
* @param info a proposed list of tag/value pairs that will be sent on open.
* @return an array of <code>AudioSynthesizerPropertyInfo</code> objects
* describing possible properties. This array may be an empty array if
* no properties are required.
*/
public AudioSynthesizerPropertyInfo[] getPropertyInfo(
Map<String, Object> info);
/**
* Opens the synthesizer and starts rendering audio into
* <code>SourceDataLine</code>.
*
* <p>An application opening a synthesizer explicitly with this call
* has to close the synthesizer by calling {@link #close}. This is
* necessary to release system resources and allow applications to
* exit cleanly.
*
* <p>Note that some synthesizers, once closed, cannot be reopened.
* Attempts to reopen such a synthesizer will always result in
* a <code>MidiUnavailableException</code>.
*
* @param line which <code>AudioSynthesizer</code> writes output audio into.
* If <code>line</code> is null, then line from system default mixer is used.
* @param info a <code>Map<String,Object></code> object containing
* properties for additional configuration supported by synthesizer.
* If <code>info</code> is null then default settings are used.
*
* @throws MidiUnavailableException thrown if the synthesizer cannot be
* opened due to resource restrictions.
* @throws SecurityException thrown if the synthesizer cannot be
* opened due to security restrictions.
*
* @see #close
* @see #isOpen
*/
public void open(SourceDataLine line, Map<String, Object> info)
throws MidiUnavailableException;
/**
* Opens the synthesizer and renders audio into returned
* <code>AudioInputStream</code>.
*
* <p>An application opening a synthesizer explicitly with this call
* has to close the synthesizer by calling {@link #close}. This is
* necessary to release system resources and allow applications to
* exit cleanly.
*
* <p>Note that some synthesizers, once closed, cannot be reopened.
* Attempts to reopen such a synthesizer will always result in
* a <code>MidiUnavailableException<code>.
*
* @param targetFormat specifies the <code>AudioFormat</code>
* used in returned <code>AudioInputStream</code>.
* @param info a <code>Map<String,Object></code> object containing
* properties for additional configuration supported by synthesizer.
* If <code>info</code> is null then default settings are used.
*
* @throws MidiUnavailableException thrown if the synthesizer cannot be
* opened due to resource restrictions.
* @throws SecurityException thrown if the synthesizer cannot be
* opened due to security restrictions.
*
* @see #close
* @see #isOpen
*/
public AudioInputStream openStream(AudioFormat targetFormat,
Map<String, Object> info) throws MidiUnavailableException;
}

View File

@ -0,0 +1,76 @@
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
/**
* Information about property used in opening <code>AudioSynthesizer</code>.
*
* @author Karl Helgason
*/
public class AudioSynthesizerPropertyInfo {
/**
* Constructs a <code>AudioSynthesizerPropertyInfo</code> object with a given
* name and value. The <code>description</code> and <code>choices</code>
* are intialized by <code>null</code> values.
*
* @param name the name of the property
* @param value the current value or class used for values.
*
*/
public AudioSynthesizerPropertyInfo(String name, Object value) {
this.name = name;
this.value = value;
if (value instanceof Class)
valueClass = (Class)value;
else if (value != null)
valueClass = value.getClass();
}
/**
* The name of the property.
*/
public String name;
/**
* A brief description of the property, which may be null.
*/
public String description = null;
/**
* The <code>value</code> field specifies the current value of
* the property.
*/
public Object value = null;
/**
* The <code>valueClass</code> field specifies class
* used in <code>value</code> field.
*/
public Class valueClass = null;
/**
* An array of possible values if the value for the field
* <code>AudioSynthesizerPropertyInfo.value</code> may be selected
* from a particular set of values; otherwise null.
*/
public Object[] choices = null;
}

View File

@ -0,0 +1,109 @@
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
/**
* This class is used to store information to describe soundbanks, instruments
* and samples. It is stored inside a "INFO" List Chunk inside DLS files.
*
* @author Karl Helgason
*/
public class DLSInfo {
/**
* (INAM) Title or subject.
*/
public String name = "untitled";
/**
* (ICRD) Date of creation, the format is: YYYY-MM-DD.
* For example 2007-01-01 for 1. january of year 2007.
*/
public String creationDate = null;
/**
* (IENG) Name of engineer who created the object.
*/
public String engineers = null;
/**
* (IPRD) Name of the product which the object is intended for.
*/
public String product = null;
/**
* (ICOP) Copyright information.
*/
public String copyright = null;
/**
* (ICMT) General comments. Doesn't contain newline characters.
*/
public String comments = null;
/**
* (ISFT) Name of software package used to create the file.
*/
public String tools = null;
/**
* (IARL) Where content is archived.
*/
public String archival_location = null;
/**
* (IART) Artists of original content.
*/
public String artist = null;
/**
* (ICMS) Names of persons or orginizations who commissioned the file.
*/
public String commissioned = null;
/**
* (IGNR) Genre of the work.
* Example: jazz, classical, rock, etc.
*/
public String genre = null;
/**
* (IKEY) List of keyword that describe the content.
* Examples: FX, bird, piano, etc.
*/
public String keywords = null;
/**
* (IMED) Describes original medium of the data.
* For example: record, CD, etc.
*/
public String medium = null;
/**
* (ISBJ) Description of the content.
*/
public String subject = null;
/**
* (ISRC) Name of person or orginization who supplied
* orginal material for the file.
*/
public String source = null;
/**
* (ISRF) Source media for sample data is from.
* For example: CD, TV, etc.
*/
public String source_form = null;
/**
* (ITCH) Technician who sample the file/object.
*/
public String technician = null;
}

View File

@ -0,0 +1,448 @@
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.sound.midi.Patch;
/**
* This class is used to store information to describe instrument.
* It contains list of regions and modulators.
* It is stored inside a "ins " List Chunk inside DLS files.
* In the DLS documentation a modulator is called articulator.
*
* @author Karl Helgason
*/
public class DLSInstrument extends ModelInstrument {
protected int preset = 0;
protected int bank = 0;
protected boolean druminstrument = false;
protected byte[] guid = null;
protected DLSInfo info = new DLSInfo();
protected List<DLSRegion> regions = new ArrayList<DLSRegion>();
protected List<DLSModulator> modulators = new ArrayList<DLSModulator>();
public DLSInstrument() {
super(null, null, null, null);
}
public DLSInstrument(DLSSoundbank soundbank) {
super(soundbank, null, null, null);
}
public DLSInfo getInfo() {
return info;
}
public String getName() {
return info.name;
}
public void setName(String name) {
info.name = name;
}
public ModelPatch getPatch() {
return new ModelPatch(bank, preset, druminstrument);
}
public void setPatch(Patch patch) {
if (patch instanceof ModelPatch && ((ModelPatch)patch).isPercussion()) {
druminstrument = true;
bank = patch.getBank();
preset = patch.getProgram();
} else {
druminstrument = false;
bank = patch.getBank();
preset = patch.getProgram();
}
}
public Object getData() {
return null;
}
public List<DLSRegion> getRegions() {
return regions;
}
public List<DLSModulator> getModulators() {
return modulators;
}
public String toString() {
if (druminstrument)
return "Drumkit: " + info.name
+ " bank #" + bank + " preset #" + preset;
else
return "Instrument: " + info.name
+ " bank #" + bank + " preset #" + preset;
}
private ModelIdentifier convertToModelDest(int dest) {
if (dest == DLSModulator.CONN_DST_NONE)
return null;
if (dest == DLSModulator.CONN_DST_GAIN)
return ModelDestination.DESTINATION_GAIN;
if (dest == DLSModulator.CONN_DST_PITCH)
return ModelDestination.DESTINATION_PITCH;
if (dest == DLSModulator.CONN_DST_PAN)
return ModelDestination.DESTINATION_PAN;
if (dest == DLSModulator.CONN_DST_LFO_FREQUENCY)
return ModelDestination.DESTINATION_LFO1_FREQ;
if (dest == DLSModulator.CONN_DST_LFO_STARTDELAY)
return ModelDestination.DESTINATION_LFO1_DELAY;
if (dest == DLSModulator.CONN_DST_EG1_ATTACKTIME)
return ModelDestination.DESTINATION_EG1_ATTACK;
if (dest == DLSModulator.CONN_DST_EG1_DECAYTIME)
return ModelDestination.DESTINATION_EG1_DECAY;
if (dest == DLSModulator.CONN_DST_EG1_RELEASETIME)
return ModelDestination.DESTINATION_EG1_RELEASE;
if (dest == DLSModulator.CONN_DST_EG1_SUSTAINLEVEL)
return ModelDestination.DESTINATION_EG1_SUSTAIN;
if (dest == DLSModulator.CONN_DST_EG2_ATTACKTIME)
return ModelDestination.DESTINATION_EG2_ATTACK;
if (dest == DLSModulator.CONN_DST_EG2_DECAYTIME)
return ModelDestination.DESTINATION_EG2_DECAY;
if (dest == DLSModulator.CONN_DST_EG2_RELEASETIME)
return ModelDestination.DESTINATION_EG2_RELEASE;
if (dest == DLSModulator.CONN_DST_EG2_SUSTAINLEVEL)
return ModelDestination.DESTINATION_EG2_SUSTAIN;
// DLS2 Destinations
if (dest == DLSModulator.CONN_DST_KEYNUMBER)
return ModelDestination.DESTINATION_KEYNUMBER;
if (dest == DLSModulator.CONN_DST_CHORUS)
return ModelDestination.DESTINATION_CHORUS;
if (dest == DLSModulator.CONN_DST_REVERB)
return ModelDestination.DESTINATION_REVERB;
if (dest == DLSModulator.CONN_DST_VIB_FREQUENCY)
return ModelDestination.DESTINATION_LFO2_FREQ;
if (dest == DLSModulator.CONN_DST_VIB_STARTDELAY)
return ModelDestination.DESTINATION_LFO2_DELAY;
if (dest == DLSModulator.CONN_DST_EG1_DELAYTIME)
return ModelDestination.DESTINATION_EG1_DELAY;
if (dest == DLSModulator.CONN_DST_EG1_HOLDTIME)
return ModelDestination.DESTINATION_EG1_HOLD;
if (dest == DLSModulator.CONN_DST_EG1_SHUTDOWNTIME)
return ModelDestination.DESTINATION_EG1_SHUTDOWN;
if (dest == DLSModulator.CONN_DST_EG2_DELAYTIME)
return ModelDestination.DESTINATION_EG2_DELAY;
if (dest == DLSModulator.CONN_DST_EG2_HOLDTIME)
return ModelDestination.DESTINATION_EG2_HOLD;
if (dest == DLSModulator.CONN_DST_FILTER_CUTOFF)
return ModelDestination.DESTINATION_FILTER_FREQ;
if (dest == DLSModulator.CONN_DST_FILTER_Q)
return ModelDestination.DESTINATION_FILTER_Q;
return null;
}
private ModelIdentifier convertToModelSrc(int src) {
if (src == DLSModulator.CONN_SRC_NONE)
return null;
if (src == DLSModulator.CONN_SRC_LFO)
return ModelSource.SOURCE_LFO1;
if (src == DLSModulator.CONN_SRC_KEYONVELOCITY)
return ModelSource.SOURCE_NOTEON_VELOCITY;
if (src == DLSModulator.CONN_SRC_KEYNUMBER)
return ModelSource.SOURCE_NOTEON_KEYNUMBER;
if (src == DLSModulator.CONN_SRC_EG1)
return ModelSource.SOURCE_EG1;
if (src == DLSModulator.CONN_SRC_EG2)
return ModelSource.SOURCE_EG2;
if (src == DLSModulator.CONN_SRC_PITCHWHEEL)
return ModelSource.SOURCE_MIDI_PITCH;
if (src == DLSModulator.CONN_SRC_CC1)
return new ModelIdentifier("midi_cc", "1", 0);
if (src == DLSModulator.CONN_SRC_CC7)
return new ModelIdentifier("midi_cc", "7", 0);
if (src == DLSModulator.CONN_SRC_CC10)
return new ModelIdentifier("midi_cc", "10", 0);
if (src == DLSModulator.CONN_SRC_CC11)
return new ModelIdentifier("midi_cc", "11", 0);
if (src == DLSModulator.CONN_SRC_RPN0)
return new ModelIdentifier("midi_rpn", "0", 0);
if (src == DLSModulator.CONN_SRC_RPN1)
return new ModelIdentifier("midi_rpn", "1", 0);
if (src == DLSModulator.CONN_SRC_POLYPRESSURE)
return ModelSource.SOURCE_MIDI_POLY_PRESSURE;
if (src == DLSModulator.CONN_SRC_CHANNELPRESSURE)
return ModelSource.SOURCE_MIDI_CHANNEL_PRESSURE;
if (src == DLSModulator.CONN_SRC_VIBRATO)
return ModelSource.SOURCE_LFO2;
if (src == DLSModulator.CONN_SRC_MONOPRESSURE)
return ModelSource.SOURCE_MIDI_CHANNEL_PRESSURE;
if (src == DLSModulator.CONN_SRC_CC91)
return new ModelIdentifier("midi_cc", "91", 0);
if (src == DLSModulator.CONN_SRC_CC93)
return new ModelIdentifier("midi_cc", "93", 0);
return null;
}
private ModelConnectionBlock convertToModel(DLSModulator mod) {
ModelIdentifier source = convertToModelSrc(mod.getSource());
ModelIdentifier control = convertToModelSrc(mod.getControl());
ModelIdentifier destination_id =
convertToModelDest(mod.getDestination());
int scale = mod.getScale();
double f_scale;
if (scale == Integer.MIN_VALUE)
f_scale = Double.NEGATIVE_INFINITY;
else
f_scale = scale / 65536.0;
if (destination_id != null) {
ModelSource src = null;
ModelSource ctrl = null;
ModelConnectionBlock block = new ModelConnectionBlock();
if (control != null) {
ModelSource s = new ModelSource();
if (control == ModelSource.SOURCE_MIDI_PITCH) {
((ModelStandardTransform)s.getTransform()).setPolarity(
ModelStandardTransform.POLARITY_BIPOLAR);
} else if (control == ModelSource.SOURCE_LFO1
|| control == ModelSource.SOURCE_LFO2) {
((ModelStandardTransform)s.getTransform()).setPolarity(
ModelStandardTransform.POLARITY_BIPOLAR);
}
s.setIdentifier(control);
block.addSource(s);
ctrl = s;
}
if (source != null) {
ModelSource s = new ModelSource();
if (source == ModelSource.SOURCE_MIDI_PITCH) {
((ModelStandardTransform)s.getTransform()).setPolarity(
ModelStandardTransform.POLARITY_BIPOLAR);
} else if (source == ModelSource.SOURCE_LFO1
|| source == ModelSource.SOURCE_LFO2) {
((ModelStandardTransform)s.getTransform()).setPolarity(
ModelStandardTransform.POLARITY_BIPOLAR);
}
s.setIdentifier(source);
block.addSource(s);
src = s;
}
ModelDestination destination = new ModelDestination();
destination.setIdentifier(destination_id);
block.setDestination(destination);
if (mod.getVersion() == 1) {
//if (mod.getTransform() == DLSModulator.CONN_TRN_CONCAVE) {
// ((ModelStandardTransform)destination.getTransform())
// .setTransform(
// ModelStandardTransform.TRANSFORM_CONCAVE);
//}
if (mod.getTransform() == DLSModulator.CONN_TRN_CONCAVE) {
if (src != null) {
((ModelStandardTransform)src.getTransform())
.setTransform(
ModelStandardTransform.TRANSFORM_CONCAVE);
((ModelStandardTransform)src.getTransform())
.setDirection(
ModelStandardTransform.DIRECTION_MAX2MIN);
}
if (ctrl != null) {
((ModelStandardTransform)ctrl.getTransform())
.setTransform(
ModelStandardTransform.TRANSFORM_CONCAVE);
((ModelStandardTransform)ctrl.getTransform())
.setDirection(
ModelStandardTransform.DIRECTION_MAX2MIN);
}
}
} else if (mod.getVersion() == 2) {
int transform = mod.getTransform();
int src_transform_invert = (transform >> 15) & 1;
int src_transform_bipolar = (transform >> 14) & 1;
int src_transform = (transform >> 10) & 8;
int ctr_transform_invert = (transform >> 9) & 1;
int ctr_transform_bipolar = (transform >> 8) & 1;
int ctr_transform = (transform >> 4) & 8;
if (src != null) {
int trans = ModelStandardTransform.TRANSFORM_LINEAR;
if (src_transform == DLSModulator.CONN_TRN_SWITCH)
trans = ModelStandardTransform.TRANSFORM_SWITCH;
if (src_transform == DLSModulator.CONN_TRN_CONCAVE)
trans = ModelStandardTransform.TRANSFORM_CONCAVE;
if (src_transform == DLSModulator.CONN_TRN_CONVEX)
trans = ModelStandardTransform.TRANSFORM_CONVEX;
((ModelStandardTransform)src.getTransform())
.setTransform(trans);
((ModelStandardTransform)src.getTransform())
.setPolarity(src_transform_bipolar == 1);
((ModelStandardTransform)src.getTransform())
.setDirection(src_transform_invert == 1);
}
if (ctrl != null) {
int trans = ModelStandardTransform.TRANSFORM_LINEAR;
if (ctr_transform == DLSModulator.CONN_TRN_SWITCH)
trans = ModelStandardTransform.TRANSFORM_SWITCH;
if (ctr_transform == DLSModulator.CONN_TRN_CONCAVE)
trans = ModelStandardTransform.TRANSFORM_CONCAVE;
if (ctr_transform == DLSModulator.CONN_TRN_CONVEX)
trans = ModelStandardTransform.TRANSFORM_CONVEX;
((ModelStandardTransform)ctrl.getTransform())
.setTransform(trans);
((ModelStandardTransform)ctrl.getTransform())
.setPolarity(ctr_transform_bipolar == 1);
((ModelStandardTransform)ctrl.getTransform())
.setDirection(ctr_transform_invert == 1);
}
/* No output transforms are defined the DLS Level 2
int out_transform = transform % 8;
int trans = ModelStandardTransform.TRANSFORM_LINEAR;
if (out_transform == DLSModulator.CONN_TRN_SWITCH)
trans = ModelStandardTransform.TRANSFORM_SWITCH;
if (out_transform == DLSModulator.CONN_TRN_CONCAVE)
trans = ModelStandardTransform.TRANSFORM_CONCAVE;
if (out_transform == DLSModulator.CONN_TRN_CONVEX)
trans = ModelStandardTransform.TRANSFORM_CONVEX;
if (ctrl != null) {
((ModelStandardTransform)destination.getTransform())
.setTransform(trans);
}
*/
}
block.setScale(f_scale);
return block;
}
return null;
}
public ModelPerformer[] getPerformers() {
List<ModelPerformer> performers = new ArrayList<ModelPerformer>();
Map<String, DLSModulator> modmap = new HashMap<String, DLSModulator>();
for (DLSModulator mod: getModulators()) {
modmap.put(mod.getSource() + "x" + mod.getControl() + "=" +
mod.getDestination(), mod);
}
Map<String, DLSModulator> insmodmap =
new HashMap<String, DLSModulator>();
for (DLSRegion zone: regions) {
ModelPerformer performer = new ModelPerformer();
performer.setName(zone.getSample().getName());
performer.setSelfNonExclusive((zone.getFusoptions() &
DLSRegion.OPTION_SELFNONEXCLUSIVE) != 0);
performer.setExclusiveClass(zone.getExclusiveClass());
performer.setKeyFrom(zone.getKeyfrom());
performer.setKeyTo(zone.getKeyto());
performer.setVelFrom(zone.getVelfrom());
performer.setVelTo(zone.getVelto());
insmodmap.clear();
insmodmap.putAll(modmap);
for (DLSModulator mod: zone.getModulators()) {
insmodmap.put(mod.getSource() + "x" + mod.getControl() + "=" +
mod.getDestination(), mod);
}
List<ModelConnectionBlock> blocks = performer.getConnectionBlocks();
for (DLSModulator mod: insmodmap.values()) {
ModelConnectionBlock p = convertToModel(mod);
if (p != null)
blocks.add(p);
}
DLSSample sample = zone.getSample();
DLSSampleOptions sampleopt = zone.getSampleoptions();
if (sampleopt == null)
sampleopt = sample.getSampleoptions();
ModelByteBuffer buff = sample.getDataBuffer();
float pitchcorrection = (-sampleopt.unitynote * 100) +
sampleopt.finetune;
ModelByteBufferWavetable osc = new ModelByteBufferWavetable(buff,
sample.getFormat(), pitchcorrection);
osc.setAttenuation(osc.getAttenuation() / 65536f);
if (sampleopt.getLoops().size() != 0) {
DLSSampleLoop loop = sampleopt.getLoops().get(0);
osc.setLoopStart((int)loop.getStart());
osc.setLoopLength((int)loop.getLength());
if (loop.getType() == DLSSampleLoop.LOOP_TYPE_FORWARD)
osc.setLoopType(ModelWavetable.LOOP_TYPE_FORWARD);
if (loop.getType() == DLSSampleLoop.LOOP_TYPE_RELEASE)
osc.setLoopType(ModelWavetable.LOOP_TYPE_RELEASE);
else
osc.setLoopType(ModelWavetable.LOOP_TYPE_FORWARD);
}
performer.getConnectionBlocks().add(
new ModelConnectionBlock(SoftFilter.FILTERTYPE_LP12,
new ModelDestination(
new ModelIdentifier("filter", "type", 1))));
performer.getOscillators().add(osc);
performers.add(performer);
}
return performers.toArray(new ModelPerformer[performers.size()]);
}
public byte[] getGuid() {
return guid;
}
public void setGuid(byte[] guid) {
this.guid = guid;
}
}

View File

@ -0,0 +1,351 @@
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
/**
* This class is used to store modulator/artiuclation data.
* A modulator connects one synthesizer source to
* a destination. For example a note on velocity
* can be mapped to the gain of the synthesized voice.
* It is stored as a "art1" or "art2" chunk inside DLS files.
*
* @author Karl Helgason
*/
public class DLSModulator {
// DLS1 Destinations
public static final int CONN_DST_NONE = 0x000; // 0
public static final int CONN_DST_GAIN = 0x001; // cB
public static final int CONN_DST_PITCH = 0x003; // cent
public static final int CONN_DST_PAN = 0x004; // 0.1%
public static final int CONN_DST_LFO_FREQUENCY = 0x104; // cent (default 5 Hz)
public static final int CONN_DST_LFO_STARTDELAY = 0x105; // timecent
public static final int CONN_DST_EG1_ATTACKTIME = 0x206; // timecent
public static final int CONN_DST_EG1_DECAYTIME = 0x207; // timecent
public static final int CONN_DST_EG1_RELEASETIME = 0x209; // timecent
public static final int CONN_DST_EG1_SUSTAINLEVEL = 0x20A; // 0.1%
public static final int CONN_DST_EG2_ATTACKTIME = 0x30A; // timecent
public static final int CONN_DST_EG2_DECAYTIME = 0x30B; // timecent
public static final int CONN_DST_EG2_RELEASETIME = 0x30D; // timecent
public static final int CONN_DST_EG2_SUSTAINLEVEL = 0x30E; // 0.1%
// DLS2 Destinations
public static final int CONN_DST_KEYNUMBER = 0x005;
public static final int CONN_DST_LEFT = 0x010; // 0.1%
public static final int CONN_DST_RIGHT = 0x011; // 0.1%
public static final int CONN_DST_CENTER = 0x012; // 0.1%
public static final int CONN_DST_LEFTREAR = 0x013; // 0.1%
public static final int CONN_DST_RIGHTREAR = 0x014; // 0.1%
public static final int CONN_DST_LFE_CHANNEL = 0x015; // 0.1%
public static final int CONN_DST_CHORUS = 0x080; // 0.1%
public static final int CONN_DST_REVERB = 0x081; // 0.1%
public static final int CONN_DST_VIB_FREQUENCY = 0x114; // cent
public static final int CONN_DST_VIB_STARTDELAY = 0x115; // dB
public static final int CONN_DST_EG1_DELAYTIME = 0x20B; // timecent
public static final int CONN_DST_EG1_HOLDTIME = 0x20C; // timecent
public static final int CONN_DST_EG1_SHUTDOWNTIME = 0x20D; // timecent
public static final int CONN_DST_EG2_DELAYTIME = 0x30F; // timecent
public static final int CONN_DST_EG2_HOLDTIME = 0x310; // timecent
public static final int CONN_DST_FILTER_CUTOFF = 0x500; // cent
public static final int CONN_DST_FILTER_Q = 0x501; // dB
// DLS1 Sources
public static final int CONN_SRC_NONE = 0x000; // 1
public static final int CONN_SRC_LFO = 0x001; // linear (sine wave)
public static final int CONN_SRC_KEYONVELOCITY = 0x002; // ??db or velocity??
public static final int CONN_SRC_KEYNUMBER = 0x003; // ??cent or keynumber??
public static final int CONN_SRC_EG1 = 0x004; // linear direct from eg
public static final int CONN_SRC_EG2 = 0x005; // linear direct from eg
public static final int CONN_SRC_PITCHWHEEL = 0x006; // linear -1..1
public static final int CONN_SRC_CC1 = 0x081; // linear 0..1
public static final int CONN_SRC_CC7 = 0x087; // linear 0..1
public static final int CONN_SRC_CC10 = 0x08A; // linear 0..1
public static final int CONN_SRC_CC11 = 0x08B; // linear 0..1
public static final int CONN_SRC_RPN0 = 0x100; // ?? // Pitch Bend Range
public static final int CONN_SRC_RPN1 = 0x101; // ?? // Fine Tune
public static final int CONN_SRC_RPN2 = 0x102; // ?? // Course Tune
// DLS2 Sources
public static final int CONN_SRC_POLYPRESSURE = 0x007; // linear 0..1
public static final int CONN_SRC_CHANNELPRESSURE = 0x008; // linear 0..1
public static final int CONN_SRC_VIBRATO = 0x009; // linear 0..1
public static final int CONN_SRC_MONOPRESSURE = 0x00A; // linear 0..1
public static final int CONN_SRC_CC91 = 0x0DB; // linear 0..1
public static final int CONN_SRC_CC93 = 0x0DD; // linear 0..1
// DLS1 Transforms
public static final int CONN_TRN_NONE = 0x000;
public static final int CONN_TRN_CONCAVE = 0x001;
// DLS2 Transforms
public static final int CONN_TRN_CONVEX = 0x002;
public static final int CONN_TRN_SWITCH = 0x003;
public static final int DST_FORMAT_CB = 1;
public static final int DST_FORMAT_CENT = 1;
public static final int DST_FORMAT_TIMECENT = 2;
public static final int DST_FORMAT_PERCENT = 3;
protected int source;
protected int control;
protected int destination;
protected int transform;
protected int scale;
protected int version = 1;
public int getControl() {
return control;
}
public void setControl(int control) {
this.control = control;
}
public static int getDestinationFormat(int destination) {
if (destination == CONN_DST_GAIN)
return DST_FORMAT_CB;
if (destination == CONN_DST_PITCH)
return DST_FORMAT_CENT;
if (destination == CONN_DST_PAN)
return DST_FORMAT_PERCENT;
if (destination == CONN_DST_LFO_FREQUENCY)
return DST_FORMAT_CENT;
if (destination == CONN_DST_LFO_STARTDELAY)
return DST_FORMAT_TIMECENT;
if (destination == CONN_DST_EG1_ATTACKTIME)
return DST_FORMAT_TIMECENT;
if (destination == CONN_DST_EG1_DECAYTIME)
return DST_FORMAT_TIMECENT;
if (destination == CONN_DST_EG1_RELEASETIME)
return DST_FORMAT_TIMECENT;
if (destination == CONN_DST_EG1_SUSTAINLEVEL)
return DST_FORMAT_PERCENT;
if (destination == CONN_DST_EG2_ATTACKTIME)
return DST_FORMAT_TIMECENT;
if (destination == CONN_DST_EG2_DECAYTIME)
return DST_FORMAT_TIMECENT;
if (destination == CONN_DST_EG2_RELEASETIME)
return DST_FORMAT_TIMECENT;
if (destination == CONN_DST_EG2_SUSTAINLEVEL)
return DST_FORMAT_PERCENT;
if (destination == CONN_DST_KEYNUMBER)
return DST_FORMAT_CENT; // NOT SURE WITHOUT DLS 2 SPEC
if (destination == CONN_DST_LEFT)
return DST_FORMAT_CB;
if (destination == CONN_DST_RIGHT)
return DST_FORMAT_CB;
if (destination == CONN_DST_CENTER)
return DST_FORMAT_CB;
if (destination == CONN_DST_LEFTREAR)
return DST_FORMAT_CB;
if (destination == CONN_DST_RIGHTREAR)
return DST_FORMAT_CB;
if (destination == CONN_DST_LFE_CHANNEL)
return DST_FORMAT_CB;
if (destination == CONN_DST_CHORUS)
return DST_FORMAT_PERCENT;
if (destination == CONN_DST_REVERB)
return DST_FORMAT_PERCENT;
if (destination == CONN_DST_VIB_FREQUENCY)
return DST_FORMAT_CENT;
if (destination == CONN_DST_VIB_STARTDELAY)
return DST_FORMAT_TIMECENT;
if (destination == CONN_DST_EG1_DELAYTIME)
return DST_FORMAT_TIMECENT;
if (destination == CONN_DST_EG1_HOLDTIME)
return DST_FORMAT_TIMECENT;
if (destination == CONN_DST_EG1_SHUTDOWNTIME)
return DST_FORMAT_TIMECENT;
if (destination == CONN_DST_EG2_DELAYTIME)
return DST_FORMAT_TIMECENT;
if (destination == CONN_DST_EG2_HOLDTIME)
return DST_FORMAT_TIMECENT;
if (destination == CONN_DST_FILTER_CUTOFF)
return DST_FORMAT_CENT;
if (destination == CONN_DST_FILTER_Q)
return DST_FORMAT_CB;
return -1;
}
public static String getDestinationName(int destination) {
if (destination == CONN_DST_GAIN)
return "gain";
if (destination == CONN_DST_PITCH)
return "pitch";
if (destination == CONN_DST_PAN)
return "pan";
if (destination == CONN_DST_LFO_FREQUENCY)
return "lfo1.freq";
if (destination == CONN_DST_LFO_STARTDELAY)
return "lfo1.delay";
if (destination == CONN_DST_EG1_ATTACKTIME)
return "eg1.attack";
if (destination == CONN_DST_EG1_DECAYTIME)
return "eg1.decay";
if (destination == CONN_DST_EG1_RELEASETIME)
return "eg1.release";
if (destination == CONN_DST_EG1_SUSTAINLEVEL)
return "eg1.sustain";
if (destination == CONN_DST_EG2_ATTACKTIME)
return "eg2.attack";
if (destination == CONN_DST_EG2_DECAYTIME)
return "eg2.decay";
if (destination == CONN_DST_EG2_RELEASETIME)
return "eg2.release";
if (destination == CONN_DST_EG2_SUSTAINLEVEL)
return "eg2.sustain";
if (destination == CONN_DST_KEYNUMBER)
return "keynumber";
if (destination == CONN_DST_LEFT)
return "left";
if (destination == CONN_DST_RIGHT)
return "right";
if (destination == CONN_DST_CENTER)
return "center";
if (destination == CONN_DST_LEFTREAR)
return "leftrear";
if (destination == CONN_DST_RIGHTREAR)
return "rightrear";
if (destination == CONN_DST_LFE_CHANNEL)
return "lfe_channel";
if (destination == CONN_DST_CHORUS)
return "chorus";
if (destination == CONN_DST_REVERB)
return "reverb";
if (destination == CONN_DST_VIB_FREQUENCY)
return "vib.freq";
if (destination == CONN_DST_VIB_STARTDELAY)
return "vib.delay";
if (destination == CONN_DST_EG1_DELAYTIME)
return "eg1.delay";
if (destination == CONN_DST_EG1_HOLDTIME)
return "eg1.hold";
if (destination == CONN_DST_EG1_SHUTDOWNTIME)
return "eg1.shutdown";
if (destination == CONN_DST_EG2_DELAYTIME)
return "eg2.delay";
if (destination == CONN_DST_EG2_HOLDTIME)
return "eg.2hold";
if (destination == CONN_DST_FILTER_CUTOFF)
return "filter.cutoff"; // NOT SURE WITHOUT DLS 2 SPEC
if (destination == CONN_DST_FILTER_Q)
return "filter.q"; // NOT SURE WITHOUT DLS 2 SPEC
return null;
}
public static String getSourceName(int source) {
if (source == CONN_SRC_NONE)
return "none";
if (source == CONN_SRC_LFO)
return "lfo";
if (source == CONN_SRC_KEYONVELOCITY)
return "keyonvelocity";
if (source == CONN_SRC_KEYNUMBER)
return "keynumber";
if (source == CONN_SRC_EG1)
return "eg1";
if (source == CONN_SRC_EG2)
return "eg2";
if (source == CONN_SRC_PITCHWHEEL)
return "pitchweel";
if (source == CONN_SRC_CC1)
return "cc1";
if (source == CONN_SRC_CC7)
return "cc7";
if (source == CONN_SRC_CC10)
return "c10";
if (source == CONN_SRC_CC11)
return "cc11";
if (source == CONN_SRC_POLYPRESSURE)
return "polypressure";
if (source == CONN_SRC_CHANNELPRESSURE)
return "channelpressure";
if (source == CONN_SRC_VIBRATO)
return "vibrato";
if (source == CONN_SRC_MONOPRESSURE)
return "monopressure";
if (source == CONN_SRC_CC91)
return "cc91";
if (source == CONN_SRC_CC93)
return "cc93";
return null;
}
public int getDestination() {
return destination;
}
public void setDestination(int destination) {
this.destination = destination;
}
public int getScale() {
return scale;
}
public void setScale(int scale) {
this.scale = scale;
}
public int getSource() {
return source;
}
public void setSource(int source) {
this.source = source;
}
public int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
public int getTransform() {
return transform;
}
public void setTransform(int transform) {
this.transform = transform;
}
}

View File

@ -0,0 +1,150 @@
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
import java.util.ArrayList;
import java.util.List;
/**
* This class is used to store region parts for instrument.
* A region has a velocity and key range which it response to.
* And it has a list of modulators/articulators which
* is used how to synthesize a single voice.
* It is stored inside a "rgn " List Chunk inside DLS files.
*
* @author Karl Helgason
*/
public class DLSRegion {
public final static int OPTION_SELFNONEXCLUSIVE = 0x0001;
protected List<DLSModulator> modulators = new ArrayList<DLSModulator>();
protected int keyfrom;
protected int keyto;
protected int velfrom;
protected int velto;
protected int options;
protected int exclusiveClass;
protected int fusoptions;
protected int phasegroup;
protected long channel;
protected DLSSample sample = null;
protected DLSSampleOptions sampleoptions;
public List<DLSModulator> getModulators() {
return modulators;
}
public long getChannel() {
return channel;
}
public void setChannel(long channel) {
this.channel = channel;
}
public int getExclusiveClass() {
return exclusiveClass;
}
public void setExclusiveClass(int exclusiveClass) {
this.exclusiveClass = exclusiveClass;
}
public int getFusoptions() {
return fusoptions;
}
public void setFusoptions(int fusoptions) {
this.fusoptions = fusoptions;
}
public int getKeyfrom() {
return keyfrom;
}
public void setKeyfrom(int keyfrom) {
this.keyfrom = keyfrom;
}
public int getKeyto() {
return keyto;
}
public void setKeyto(int keyto) {
this.keyto = keyto;
}
public int getOptions() {
return options;
}
public void setOptions(int options) {
this.options = options;
}
public int getPhasegroup() {
return phasegroup;
}
public void setPhasegroup(int phasegroup) {
this.phasegroup = phasegroup;
}
public DLSSample getSample() {
return sample;
}
public void setSample(DLSSample sample) {
this.sample = sample;
}
public int getVelfrom() {
return velfrom;
}
public void setVelfrom(int velfrom) {
this.velfrom = velfrom;
}
public int getVelto() {
return velto;
}
public void setVelto(int velto) {
this.velto = velto;
}
public void setModulators(List<DLSModulator> modulators) {
this.modulators = modulators;
}
public DLSSampleOptions getSampleoptions() {
return sampleoptions;
}
public void setSampleoptions(DLSSampleOptions sampleOptions) {
this.sampleoptions = sampleOptions;
}
}

View File

@ -0,0 +1,122 @@
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
import java.io.InputStream;
import javax.sound.midi.Soundbank;
import javax.sound.midi.SoundbankResource;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
/**
* This class is used to store the sample data itself.
* A sample is encoded as PCM audio stream
* and in DLS Level 1 files it is always a mono 8/16 bit stream.
* They are stored just like RIFF WAVE files are stored.
* It is stored inside a "wave" List Chunk inside DLS files.
*
* @author Karl Helgason
*/
public class DLSSample extends SoundbankResource {
protected byte[] guid = null;
protected DLSInfo info = new DLSInfo();
protected DLSSampleOptions sampleoptions;
protected ModelByteBuffer data;
protected AudioFormat format;
public DLSSample(Soundbank soundBank) {
super(soundBank, null, AudioInputStream.class);
}
public DLSSample() {
super(null, null, AudioInputStream.class);
}
public DLSInfo getInfo() {
return info;
}
public Object getData() {
AudioFormat format = getFormat();
InputStream is = data.getInputStream();
if (is == null)
return null;
return new AudioInputStream(is, format, data.capacity());
}
public ModelByteBuffer getDataBuffer() {
return data;
}
public AudioFormat getFormat() {
return format;
}
public void setFormat(AudioFormat format) {
this.format = format;
}
public void setData(ModelByteBuffer data) {
this.data = data;
}
public void setData(byte[] data) {
this.data = new ModelByteBuffer(data);
}
public void setData(byte[] data, int offset, int length) {
this.data = new ModelByteBuffer(data, offset, length);
}
public String getName() {
return info.name;
}
public void setName(String name) {
info.name = name;
}
public DLSSampleOptions getSampleoptions() {
return sampleoptions;
}
public void setSampleoptions(DLSSampleOptions sampleOptions) {
this.sampleoptions = sampleOptions;
}
public String toString() {
return "Sample: " + info.name;
}
public byte[] getGuid() {
return guid;
}
public void setGuid(byte[] guid) {
this.guid = guid;
}
}

View File

@ -0,0 +1,63 @@
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
/**
* This class is used to store loop points inside DLSSampleOptions class.
*
* @author Karl Helgason
*/
public class DLSSampleLoop {
public final static int LOOP_TYPE_FORWARD = 0;
public final static int LOOP_TYPE_RELEASE = 1;
protected long type;
protected long start;
protected long length;
public long getLength() {
return length;
}
public void setLength(long length) {
this.length = length;
}
public long getStart() {
return start;
}
public void setStart(long start) {
this.start = start;
}
public long getType() {
return type;
}
public void setType(long type) {
this.type = type;
}
}

View File

@ -0,0 +1,80 @@
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
import java.util.ArrayList;
import java.util.List;
/**
* This class stores options how to playback sampled data like pitch/tuning,
* attenuation and loops.
* It is stored as a "wsmp" chunk inside DLS files.
*
* @author Karl Helgason
*/
public class DLSSampleOptions {
protected int unitynote;
protected short finetune;
protected int attenuation;
protected long options;
protected List<DLSSampleLoop> loops = new ArrayList<DLSSampleLoop>();
public int getAttenuation() {
return attenuation;
}
public void setAttenuation(int attenuation) {
this.attenuation = attenuation;
}
public short getFinetune() {
return finetune;
}
public void setFinetune(short finetune) {
this.finetune = finetune;
}
public List<DLSSampleLoop> getLoops() {
return loops;
}
public long getOptions() {
return options;
}
public void setOptions(long options) {
this.options = options;
}
public int getUnitynote() {
return unitynote;
}
public void setUnitynote(int unitynote) {
this.unitynote = unitynote;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,74 @@
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import javax.sound.midi.InvalidMidiDataException;
import javax.sound.midi.Soundbank;
import javax.sound.midi.spi.SoundbankReader;
/**
* This class is used to connect the DLSSoundBank class
* to the SoundbankReader SPI interface.
*
* @author Karl Helgason
*/
public class DLSSoundbankReader extends SoundbankReader {
public Soundbank getSoundbank(URL url)
throws InvalidMidiDataException, IOException {
try {
return new DLSSoundbank(url);
} catch (RIFFInvalidFormatException e) {
return null;
} catch(IOException ioe) {
return null;
}
}
public Soundbank getSoundbank(InputStream stream)
throws InvalidMidiDataException, IOException {
try {
stream.mark(512);
return new DLSSoundbank(stream);
} catch (RIFFInvalidFormatException e) {
stream.reset();
return null;
}
}
public Soundbank getSoundbank(File file)
throws InvalidMidiDataException, IOException {
try {
return new DLSSoundbank(file);
} catch (RIFFInvalidFormatException e) {
return null;
}
}
}

View File

@ -394,7 +394,12 @@ class DirectAudioDevice extends AbstractMixer {
private float leftGain, rightGain;
protected volatile boolean noService = false; // do not run the nService method
// Guards all native calls.
protected Object lockNative = new Object();
// Guards the lastOpened static variable in implOpen and implClose.
protected static Object lockLast = new Object();
// Keeps track of last opened line, see implOpen "trick".
protected static DirectDL lastOpened;
// CONSTRUCTOR
protected DirectDL(DataLine.Info info,
@ -496,20 +501,50 @@ class DirectAudioDevice extends AbstractMixer {
// align buffer to full frames
bufferSize = ((int) bufferSize / format.getFrameSize()) * format.getFrameSize();
id = nOpen(mixerIndex, deviceID, isSource,
encoding,
hardwareFormat.getSampleRate(),
hardwareFormat.getSampleSizeInBits(),
hardwareFormat.getFrameSize(),
hardwareFormat.getChannels(),
hardwareFormat.getEncoding().equals(AudioFormat.Encoding.PCM_SIGNED),
hardwareFormat.isBigEndian(),
bufferSize);
synchronized(lockLast) {
id = nOpen(mixerIndex, deviceID, isSource,
encoding,
hardwareFormat.getSampleRate(),
hardwareFormat.getSampleSizeInBits(),
hardwareFormat.getFrameSize(),
hardwareFormat.getChannels(),
hardwareFormat.getEncoding().equals(
AudioFormat.Encoding.PCM_SIGNED),
hardwareFormat.isBigEndian(),
bufferSize);
if (id == 0) {
// TODO: nicer error messages...
throw new LineUnavailableException("line with format "+format+" not supported.");
if (id == 0) {
// Bah... Dirty trick. The most likely cause is an application
// already having a line open for this particular hardware
// format and forgetting about it. If so, silently close that
// implementation and try again. Unfortuantely we can only
// open one line per hardware format currently.
if (lastOpened != null
&& hardwareFormat.matches(lastOpened.hardwareFormat)) {
lastOpened.implClose();
lastOpened = null;
id = nOpen(mixerIndex, deviceID, isSource,
encoding,
hardwareFormat.getSampleRate(),
hardwareFormat.getSampleSizeInBits(),
hardwareFormat.getFrameSize(),
hardwareFormat.getChannels(),
hardwareFormat.getEncoding().equals(
AudioFormat.Encoding.PCM_SIGNED),
hardwareFormat.isBigEndian(),
bufferSize);
}
if (id == 0) {
// TODO: nicer error messages...
throw new LineUnavailableException(
"line with format "+format+" not supported.");
}
}
lastOpened = this;
}
this.bufferSize = nGetBufferSize(id, isSource);
if (this.bufferSize < 1) {
// this is an error!
@ -580,12 +615,12 @@ class DirectAudioDevice extends AbstractMixer {
}
synchronized (lockNative) {
nStop(id, isSource);
}
// need to set doIO to false before notifying the
// read/write thread, that's why isStartedRunning()
// cannot be used
doIO = false;
// need to set doIO to false before notifying the
// read/write thread, that's why isStartedRunning()
// cannot be used
doIO = false;
}
// wake up any waiting threads
synchronized(lock) {
lock.notifyAll();
@ -614,8 +649,12 @@ class DirectAudioDevice extends AbstractMixer {
doIO = false;
long oldID = id;
id = 0;
synchronized (lockNative) {
nClose(oldID, isSource);
synchronized (lockLast) {
synchronized (lockNative) {
nClose(oldID, isSource);
if (lastOpened == this)
lastOpened = null;
}
}
bytePosition = 0;
softwareConversionSize = 0;
@ -630,7 +669,8 @@ class DirectAudioDevice extends AbstractMixer {
}
int a = 0;
synchronized (lockNative) {
a = nAvailable(id, isSource);
if (doIO)
a = nAvailable(id, isSource);
}
return a;
}
@ -644,9 +684,9 @@ class DirectAudioDevice extends AbstractMixer {
int counter = 0;
long startPos = getLongFramePosition();
boolean posChanged = false;
while (!drained && doIO) {
while (!drained) {
synchronized (lockNative) {
if ((id == 0) || !nIsStillDraining(id, isSource))
if ((id == 0) || (!doIO) || !nIsStillDraining(id, isSource))
break;
}
// check every now and then for a new position
@ -686,7 +726,7 @@ class DirectAudioDevice extends AbstractMixer {
lock.notifyAll();
}
synchronized (lockNative) {
if (id != 0) {
if (id != 0 && doIO) {
// then flush native buffers
nFlush(id, isSource);
}
@ -697,9 +737,10 @@ class DirectAudioDevice extends AbstractMixer {
// replacement for getFramePosition (see AbstractDataLine)
public long getLongFramePosition() {
long pos;
long pos = 0;
synchronized (lockNative) {
pos = nGetBytePosition(id, isSource, bytePosition);
if (doIO)
pos = nGetBytePosition(id, isSource, bytePosition);
}
// hack because ALSA sometimes reports wrong framepos
if (pos < 0) {
@ -745,11 +786,12 @@ class DirectAudioDevice extends AbstractMixer {
}
int written = 0;
while (!flushing) {
int thisWritten;
int thisWritten = 0;
synchronized (lockNative) {
thisWritten = nWrite(id, b, off, len,
softwareConversionSize,
leftGain, rightGain);
if (doIO)
thisWritten = nWrite(id, b, off, len,
softwareConversionSize,
leftGain, rightGain);
if (thisWritten < 0) {
// error in native layer
break;
@ -972,9 +1014,10 @@ class DirectAudioDevice extends AbstractMixer {
}
int read = 0;
while (doIO && !flushing) {
int thisRead;
int thisRead = 0;
synchronized (lockNative) {
thisRead = nRead(id, b, off, len, softwareConversionSize);
if (doIO)
thisRead = nRead(id, b, off, len, softwareConversionSize);
if (thisRead < 0) {
// error in native layer
break;
@ -1209,7 +1252,8 @@ class DirectAudioDevice extends AbstractMixer {
// set new native position (if necessary)
// this must come after the flush!
synchronized (lockNative) {
nSetBytePosition(id, isSource, frames * frameSize);
if (doIO)
nSetBytePosition(id, isSource, frames * frameSize);
}
if (Printer.debug) Printer.debug(" DirectClip.setFramePosition: "

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,748 @@
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
/**
* Fast Fourier Transformer.
*
* @author Karl Helgason
*/
public final class FFT {
private double[] w;
private int fftFrameSize;
private int sign;
private int[] bitm_array;
private int fftFrameSize2;
// Sign = -1 is FFT, 1 is IFFT (inverse FFT)
// Data = Interlaced double array to be transformed.
// The order is: real (sin), complex (cos)
// Framesize must be power of 2
public FFT(int fftFrameSize, int sign) {
w = computeTwiddleFactors(fftFrameSize, sign);
this.fftFrameSize = fftFrameSize;
this.sign = sign;
fftFrameSize2 = fftFrameSize << 1;
// Pre-process Bit-Reversal
bitm_array = new int[fftFrameSize2];
for (int i = 2; i < fftFrameSize2; i += 2) {
int j;
int bitm;
for (bitm = 2, j = 0; bitm < fftFrameSize2; bitm <<= 1) {
if ((i & bitm) != 0)
j++;
j <<= 1;
}
bitm_array[i] = j;
}
}
public void transform(double[] data) {
bitreversal(data);
calc(fftFrameSize, data, sign, w);
}
private final static double[] computeTwiddleFactors(int fftFrameSize,
int sign) {
int imax = (int) (Math.log(fftFrameSize) / Math.log(2.));
double[] warray = new double[(fftFrameSize - 1) * 4];
int w_index = 0;
for (int i = 0, nstep = 2; i < imax; i++) {
int jmax = nstep;
nstep <<= 1;
double wr = 1.0;
double wi = 0.0;
double arg = Math.PI / (jmax >> 1);
double wfr = Math.cos(arg);
double wfi = sign * Math.sin(arg);
for (int j = 0; j < jmax; j += 2) {
warray[w_index++] = wr;
warray[w_index++] = wi;
double tempr = wr;
wr = tempr * wfr - wi * wfi;
wi = tempr * wfi + wi * wfr;
}
}
// PRECOMPUTATION of wwr1, wwi1 for factor 4 Decomposition (3 * complex
// operators and 8 +/- complex operators)
{
w_index = 0;
int w_index2 = warray.length >> 1;
for (int i = 0, nstep = 2; i < (imax - 1); i++) {
int jmax = nstep;
nstep *= 2;
int ii = w_index + jmax;
for (int j = 0; j < jmax; j += 2) {
double wr = warray[w_index++];
double wi = warray[w_index++];
double wr1 = warray[ii++];
double wi1 = warray[ii++];
warray[w_index2++] = wr * wr1 - wi * wi1;
warray[w_index2++] = wr * wi1 + wi * wr1;
}
}
}
return warray;
}
private final static void calc(int fftFrameSize, double[] data, int sign,
double[] w) {
final int fftFrameSize2 = fftFrameSize << 1;
int nstep = 2;
if (nstep >= fftFrameSize2)
return;
int i = nstep - 2;
if (sign == -1)
calcF4F(fftFrameSize, data, i, nstep, w);
else
calcF4I(fftFrameSize, data, i, nstep, w);
}
private final static void calcF2E(int fftFrameSize, double[] data, int i,
int nstep, double[] w) {
int jmax = nstep;
for (int n = 0; n < jmax; n += 2) {
double wr = w[i++];
double wi = w[i++];
int m = n + jmax;
double datam_r = data[m];
double datam_i = data[m + 1];
double datan_r = data[n];
double datan_i = data[n + 1];
double tempr = datam_r * wr - datam_i * wi;
double tempi = datam_r * wi + datam_i * wr;
data[m] = datan_r - tempr;
data[m + 1] = datan_i - tempi;
data[n] = datan_r + tempr;
data[n + 1] = datan_i + tempi;
}
return;
}
// Perform Factor-4 Decomposition with 3 * complex operators and 8 +/-
// complex operators
private final static void calcF4F(int fftFrameSize, double[] data, int i,
int nstep, double[] w) {
final int fftFrameSize2 = fftFrameSize << 1; // 2*fftFrameSize;
// Factor-4 Decomposition
int w_len = w.length >> 1;
while (nstep < fftFrameSize2) {
if (nstep << 2 == fftFrameSize2) {
// Goto Factor-4 Final Decomposition
// calcF4E(data, i, nstep, -1, w);
calcF4FE(fftFrameSize, data, i, nstep, w);
return;
}
int jmax = nstep;
int nnstep = nstep << 1;
if (nnstep == fftFrameSize2) {
// Factor-4 Decomposition not possible
calcF2E(fftFrameSize, data, i, nstep, w);
return;
}
nstep <<= 2;
int ii = i + jmax;
int iii = i + w_len;
{
i += 2;
ii += 2;
iii += 2;
for (int n = 0; n < fftFrameSize2; n += nstep) {
int m = n + jmax;
double datam1_r = data[m];
double datam1_i = data[m + 1];
double datan1_r = data[n];
double datan1_i = data[n + 1];
n += nnstep;
m += nnstep;
double datam2_r = data[m];
double datam2_i = data[m + 1];
double datan2_r = data[n];
double datan2_i = data[n + 1];
double tempr = datam1_r;
double tempi = datam1_i;
datam1_r = datan1_r - tempr;
datam1_i = datan1_i - tempi;
datan1_r = datan1_r + tempr;
datan1_i = datan1_i + tempi;
double n2w1r = datan2_r;
double n2w1i = datan2_i;
double m2ww1r = datam2_r;
double m2ww1i = datam2_i;
tempr = m2ww1r - n2w1r;
tempi = m2ww1i - n2w1i;
datam2_r = datam1_r + tempi;
datam2_i = datam1_i - tempr;
datam1_r = datam1_r - tempi;
datam1_i = datam1_i + tempr;
tempr = n2w1r + m2ww1r;
tempi = n2w1i + m2ww1i;
datan2_r = datan1_r - tempr;
datan2_i = datan1_i - tempi;
datan1_r = datan1_r + tempr;
datan1_i = datan1_i + tempi;
data[m] = datam2_r;
data[m + 1] = datam2_i;
data[n] = datan2_r;
data[n + 1] = datan2_i;
n -= nnstep;
m -= nnstep;
data[m] = datam1_r;
data[m + 1] = datam1_i;
data[n] = datan1_r;
data[n + 1] = datan1_i;
}
}
for (int j = 2; j < jmax; j += 2) {
double wr = w[i++];
double wi = w[i++];
double wr1 = w[ii++];
double wi1 = w[ii++];
double wwr1 = w[iii++];
double wwi1 = w[iii++];
// double wwr1 = wr * wr1 - wi * wi1; // these numbers can be
// precomputed!!!
// double wwi1 = wr * wi1 + wi * wr1;
for (int n = j; n < fftFrameSize2; n += nstep) {
int m = n + jmax;
double datam1_r = data[m];
double datam1_i = data[m + 1];
double datan1_r = data[n];
double datan1_i = data[n + 1];
n += nnstep;
m += nnstep;
double datam2_r = data[m];
double datam2_i = data[m + 1];
double datan2_r = data[n];
double datan2_i = data[n + 1];
double tempr = datam1_r * wr - datam1_i * wi;
double tempi = datam1_r * wi + datam1_i * wr;
datam1_r = datan1_r - tempr;
datam1_i = datan1_i - tempi;
datan1_r = datan1_r + tempr;
datan1_i = datan1_i + tempi;
double n2w1r = datan2_r * wr1 - datan2_i * wi1;
double n2w1i = datan2_r * wi1 + datan2_i * wr1;
double m2ww1r = datam2_r * wwr1 - datam2_i * wwi1;
double m2ww1i = datam2_r * wwi1 + datam2_i * wwr1;
tempr = m2ww1r - n2w1r;
tempi = m2ww1i - n2w1i;
datam2_r = datam1_r + tempi;
datam2_i = datam1_i - tempr;
datam1_r = datam1_r - tempi;
datam1_i = datam1_i + tempr;
tempr = n2w1r + m2ww1r;
tempi = n2w1i + m2ww1i;
datan2_r = datan1_r - tempr;
datan2_i = datan1_i - tempi;
datan1_r = datan1_r + tempr;
datan1_i = datan1_i + tempi;
data[m] = datam2_r;
data[m + 1] = datam2_i;
data[n] = datan2_r;
data[n + 1] = datan2_i;
n -= nnstep;
m -= nnstep;
data[m] = datam1_r;
data[m + 1] = datam1_i;
data[n] = datan1_r;
data[n + 1] = datan1_i;
}
}
i += jmax << 1;
}
calcF2E(fftFrameSize, data, i, nstep, w);
}
// Perform Factor-4 Decomposition with 3 * complex operators and 8 +/-
// complex operators
private final static void calcF4I(int fftFrameSize, double[] data, int i,
int nstep, double[] w) {
final int fftFrameSize2 = fftFrameSize << 1; // 2*fftFrameSize;
// Factor-4 Decomposition
int w_len = w.length >> 1;
while (nstep < fftFrameSize2) {
if (nstep << 2 == fftFrameSize2) {
// Goto Factor-4 Final Decomposition
// calcF4E(data, i, nstep, 1, w);
calcF4IE(fftFrameSize, data, i, nstep, w);
return;
}
int jmax = nstep;
int nnstep = nstep << 1;
if (nnstep == fftFrameSize2) {
// Factor-4 Decomposition not possible
calcF2E(fftFrameSize, data, i, nstep, w);
return;
}
nstep <<= 2;
int ii = i + jmax;
int iii = i + w_len;
{
i += 2;
ii += 2;
iii += 2;
for (int n = 0; n < fftFrameSize2; n += nstep) {
int m = n + jmax;
double datam1_r = data[m];
double datam1_i = data[m + 1];
double datan1_r = data[n];
double datan1_i = data[n + 1];
n += nnstep;
m += nnstep;
double datam2_r = data[m];
double datam2_i = data[m + 1];
double datan2_r = data[n];
double datan2_i = data[n + 1];
double tempr = datam1_r;
double tempi = datam1_i;
datam1_r = datan1_r - tempr;
datam1_i = datan1_i - tempi;
datan1_r = datan1_r + tempr;
datan1_i = datan1_i + tempi;
double n2w1r = datan2_r;
double n2w1i = datan2_i;
double m2ww1r = datam2_r;
double m2ww1i = datam2_i;
tempr = n2w1r - m2ww1r;
tempi = n2w1i - m2ww1i;
datam2_r = datam1_r + tempi;
datam2_i = datam1_i - tempr;
datam1_r = datam1_r - tempi;
datam1_i = datam1_i + tempr;
tempr = n2w1r + m2ww1r;
tempi = n2w1i + m2ww1i;
datan2_r = datan1_r - tempr;
datan2_i = datan1_i - tempi;
datan1_r = datan1_r + tempr;
datan1_i = datan1_i + tempi;
data[m] = datam2_r;
data[m + 1] = datam2_i;
data[n] = datan2_r;
data[n + 1] = datan2_i;
n -= nnstep;
m -= nnstep;
data[m] = datam1_r;
data[m + 1] = datam1_i;
data[n] = datan1_r;
data[n + 1] = datan1_i;
}
}
for (int j = 2; j < jmax; j += 2) {
double wr = w[i++];
double wi = w[i++];
double wr1 = w[ii++];
double wi1 = w[ii++];
double wwr1 = w[iii++];
double wwi1 = w[iii++];
// double wwr1 = wr * wr1 - wi * wi1; // these numbers can be
// precomputed!!!
// double wwi1 = wr * wi1 + wi * wr1;
for (int n = j; n < fftFrameSize2; n += nstep) {
int m = n + jmax;
double datam1_r = data[m];
double datam1_i = data[m + 1];
double datan1_r = data[n];
double datan1_i = data[n + 1];
n += nnstep;
m += nnstep;
double datam2_r = data[m];
double datam2_i = data[m + 1];
double datan2_r = data[n];
double datan2_i = data[n + 1];
double tempr = datam1_r * wr - datam1_i * wi;
double tempi = datam1_r * wi + datam1_i * wr;
datam1_r = datan1_r - tempr;
datam1_i = datan1_i - tempi;
datan1_r = datan1_r + tempr;
datan1_i = datan1_i + tempi;
double n2w1r = datan2_r * wr1 - datan2_i * wi1;
double n2w1i = datan2_r * wi1 + datan2_i * wr1;
double m2ww1r = datam2_r * wwr1 - datam2_i * wwi1;
double m2ww1i = datam2_r * wwi1 + datam2_i * wwr1;
tempr = n2w1r - m2ww1r;
tempi = n2w1i - m2ww1i;
datam2_r = datam1_r + tempi;
datam2_i = datam1_i - tempr;
datam1_r = datam1_r - tempi;
datam1_i = datam1_i + tempr;
tempr = n2w1r + m2ww1r;
tempi = n2w1i + m2ww1i;
datan2_r = datan1_r - tempr;
datan2_i = datan1_i - tempi;
datan1_r = datan1_r + tempr;
datan1_i = datan1_i + tempi;
data[m] = datam2_r;
data[m + 1] = datam2_i;
data[n] = datan2_r;
data[n + 1] = datan2_i;
n -= nnstep;
m -= nnstep;
data[m] = datam1_r;
data[m + 1] = datam1_i;
data[n] = datan1_r;
data[n + 1] = datan1_i;
}
}
i += jmax << 1;
}
calcF2E(fftFrameSize, data, i, nstep, w);
}
// Perform Factor-4 Decomposition with 3 * complex operators and 8 +/-
// complex operators
private final static void calcF4FE(int fftFrameSize, double[] data, int i,
int nstep, double[] w) {
final int fftFrameSize2 = fftFrameSize << 1; // 2*fftFrameSize;
// Factor-4 Decomposition
int w_len = w.length >> 1;
while (nstep < fftFrameSize2) {
int jmax = nstep;
int nnstep = nstep << 1;
if (nnstep == fftFrameSize2) {
// Factor-4 Decomposition not possible
calcF2E(fftFrameSize, data, i, nstep, w);
return;
}
nstep <<= 2;
int ii = i + jmax;
int iii = i + w_len;
for (int n = 0; n < jmax; n += 2) {
double wr = w[i++];
double wi = w[i++];
double wr1 = w[ii++];
double wi1 = w[ii++];
double wwr1 = w[iii++];
double wwi1 = w[iii++];
// double wwr1 = wr * wr1 - wi * wi1; // these numbers can be
// precomputed!!!
// double wwi1 = wr * wi1 + wi * wr1;
int m = n + jmax;
double datam1_r = data[m];
double datam1_i = data[m + 1];
double datan1_r = data[n];
double datan1_i = data[n + 1];
n += nnstep;
m += nnstep;
double datam2_r = data[m];
double datam2_i = data[m + 1];
double datan2_r = data[n];
double datan2_i = data[n + 1];
double tempr = datam1_r * wr - datam1_i * wi;
double tempi = datam1_r * wi + datam1_i * wr;
datam1_r = datan1_r - tempr;
datam1_i = datan1_i - tempi;
datan1_r = datan1_r + tempr;
datan1_i = datan1_i + tempi;
double n2w1r = datan2_r * wr1 - datan2_i * wi1;
double n2w1i = datan2_r * wi1 + datan2_i * wr1;
double m2ww1r = datam2_r * wwr1 - datam2_i * wwi1;
double m2ww1i = datam2_r * wwi1 + datam2_i * wwr1;
tempr = m2ww1r - n2w1r;
tempi = m2ww1i - n2w1i;
datam2_r = datam1_r + tempi;
datam2_i = datam1_i - tempr;
datam1_r = datam1_r - tempi;
datam1_i = datam1_i + tempr;
tempr = n2w1r + m2ww1r;
tempi = n2w1i + m2ww1i;
datan2_r = datan1_r - tempr;
datan2_i = datan1_i - tempi;
datan1_r = datan1_r + tempr;
datan1_i = datan1_i + tempi;
data[m] = datam2_r;
data[m + 1] = datam2_i;
data[n] = datan2_r;
data[n + 1] = datan2_i;
n -= nnstep;
m -= nnstep;
data[m] = datam1_r;
data[m + 1] = datam1_i;
data[n] = datan1_r;
data[n + 1] = datan1_i;
}
i += jmax << 1;
}
}
// Perform Factor-4 Decomposition with 3 * complex operators and 8 +/-
// complex operators
private final static void calcF4IE(int fftFrameSize, double[] data, int i,
int nstep, double[] w) {
final int fftFrameSize2 = fftFrameSize << 1; // 2*fftFrameSize;
// Factor-4 Decomposition
int w_len = w.length >> 1;
while (nstep < fftFrameSize2) {
int jmax = nstep;
int nnstep = nstep << 1;
if (nnstep == fftFrameSize2) {
// Factor-4 Decomposition not possible
calcF2E(fftFrameSize, data, i, nstep, w);
return;
}
nstep <<= 2;
int ii = i + jmax;
int iii = i + w_len;
for (int n = 0; n < jmax; n += 2) {
double wr = w[i++];
double wi = w[i++];
double wr1 = w[ii++];
double wi1 = w[ii++];
double wwr1 = w[iii++];
double wwi1 = w[iii++];
// double wwr1 = wr * wr1 - wi * wi1; // these numbers can be
// precomputed!!!
// double wwi1 = wr * wi1 + wi * wr1;
int m = n + jmax;
double datam1_r = data[m];
double datam1_i = data[m + 1];
double datan1_r = data[n];
double datan1_i = data[n + 1];
n += nnstep;
m += nnstep;
double datam2_r = data[m];
double datam2_i = data[m + 1];
double datan2_r = data[n];
double datan2_i = data[n + 1];
double tempr = datam1_r * wr - datam1_i * wi;
double tempi = datam1_r * wi + datam1_i * wr;
datam1_r = datan1_r - tempr;
datam1_i = datan1_i - tempi;
datan1_r = datan1_r + tempr;
datan1_i = datan1_i + tempi;
double n2w1r = datan2_r * wr1 - datan2_i * wi1;
double n2w1i = datan2_r * wi1 + datan2_i * wr1;
double m2ww1r = datam2_r * wwr1 - datam2_i * wwi1;
double m2ww1i = datam2_r * wwi1 + datam2_i * wwr1;
tempr = n2w1r - m2ww1r;
tempi = n2w1i - m2ww1i;
datam2_r = datam1_r + tempi;
datam2_i = datam1_i - tempr;
datam1_r = datam1_r - tempi;
datam1_i = datam1_i + tempr;
tempr = n2w1r + m2ww1r;
tempi = n2w1i + m2ww1i;
datan2_r = datan1_r - tempr;
datan2_i = datan1_i - tempi;
datan1_r = datan1_r + tempr;
datan1_i = datan1_i + tempi;
data[m] = datam2_r;
data[m + 1] = datam2_i;
data[n] = datan2_r;
data[n + 1] = datan2_i;
n -= nnstep;
m -= nnstep;
data[m] = datam1_r;
data[m + 1] = datam1_i;
data[n] = datan1_r;
data[n + 1] = datan1_i;
}
i += jmax << 1;
}
}
private final void bitreversal(double[] data) {
if (fftFrameSize < 4)
return;
int inverse = fftFrameSize2 - 2;
for (int i = 0; i < fftFrameSize; i += 4) {
int j = bitm_array[i];
// Performing Bit-Reversal, even v.s. even, O(2N)
if (i < j) {
int n = i;
int m = j;
// COMPLEX: SWAP(data[n], data[m])
// Real Part
double tempr = data[n];
data[n] = data[m];
data[m] = tempr;
// Imagery Part
n++;
m++;
double tempi = data[n];
data[n] = data[m];
data[m] = tempi;
n = inverse - i;
m = inverse - j;
// COMPLEX: SWAP(data[n], data[m])
// Real Part
tempr = data[n];
data[n] = data[m];
data[m] = tempr;
// Imagery Part
n++;
m++;
tempi = data[n];
data[n] = data[m];
data[m] = tempi;
}
// Performing Bit-Reversal, odd v.s. even, O(N)
int m = j + fftFrameSize; // bitm_array[i+2];
// COMPLEX: SWAP(data[n], data[m])
// Real Part
int n = i + 2;
double tempr = data[n];
data[n] = data[m];
data[m] = tempr;
// Imagery Part
n++;
m++;
double tempi = data[n];
data[n] = data[m];
data[m] = tempi;
}
}
}

View File

@ -0,0 +1,45 @@
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
import java.io.IOException;
/**
* This exception is used when a file contains illegal or unexpected data.
*
* @author Karl Helgason
*/
public class InvalidDataException extends IOException {
private static final long serialVersionUID = 1L;
public InvalidDataException() {
super("Invalid Data!");
}
public InvalidDataException(String s) {
super(s);
}
}

View File

@ -0,0 +1,44 @@
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
/**
* This exception is used when a reader is used to read file of a format
* it doesn't unterstand or support.
*
* @author Karl Helgason
*/
public class InvalidFormatException extends InvalidDataException {
private static final long serialVersionUID = 1L;
public InvalidFormatException() {
super("Invalid format!");
}
public InvalidFormatException(String s) {
super(s);
}
}

View File

@ -0,0 +1,120 @@
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import javax.sound.midi.InvalidMidiDataException;
import javax.sound.midi.Soundbank;
import javax.sound.midi.spi.SoundbankReader;
/**
* JarSoundbankReader is used to read sounbank object from jar files.
*
* @author Karl Helgason
*/
public class JARSoundbankReader extends SoundbankReader {
public boolean isZIP(URL url) {
boolean ok = false;
try {
InputStream stream = url.openStream();
try {
byte[] buff = new byte[4];
ok = stream.read(buff) == 4;
if (ok) {
ok = (buff[0] == 0x50
&& buff[1] == 0x4b
&& buff[2] == 0x03
&& buff[3] == 0x04);
}
} finally {
stream.close();
}
} catch (IOException e) {
}
return ok;
}
public Soundbank getSoundbank(URL url)
throws InvalidMidiDataException, IOException {
if (!isZIP(url))
return null;
ArrayList<Soundbank> soundbanks = new ArrayList<Soundbank>();
URLClassLoader ucl = URLClassLoader.newInstance(new URL[]{url});
InputStream stream = ucl.getResourceAsStream(
"META-INF/services/javax.sound.midi.Soundbank");
if (stream == null)
return null;
try
{
BufferedReader r = new BufferedReader(new InputStreamReader(stream));
String line = r.readLine();
while (line != null) {
if (!line.startsWith("#")) {
try {
Class c = Class.forName(line.trim(), true, ucl);
Object o = c.newInstance();
if (o instanceof Soundbank) {
soundbanks.add((Soundbank) o);
}
} catch (ClassNotFoundException e) {
} catch (InstantiationException e) {
} catch (IllegalAccessException e) {
}
}
line = r.readLine();
}
}
finally
{
stream.close();
}
if (soundbanks.size() == 0)
return null;
if (soundbanks.size() == 1)
return soundbanks.get(0);
SimpleSoundbank sbk = new SimpleSoundbank();
for (Soundbank soundbank : soundbanks)
sbk.addAllInstruments(soundbank);
return sbk;
}
public Soundbank getSoundbank(InputStream stream)
throws InvalidMidiDataException, IOException {
return null;
}
public Soundbank getSoundbank(File file)
throws InvalidMidiDataException, IOException {
return getSoundbank(file.toURI().toURL());
}
}

View File

@ -0,0 +1,126 @@
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
/**
* ModelAbstractChannelMixer is ready for use class to implement
* ModelChannelMixer interface.
*
* @author Karl Helgason
*/
public abstract class ModelAbstractChannelMixer implements ModelChannelMixer {
public abstract boolean process(float[][] buffer, int offset, int len);
public abstract void stop();
public void allNotesOff() {
}
public void allSoundOff() {
}
public void controlChange(int controller, int value) {
}
public int getChannelPressure() {
return 0;
}
public int getController(int controller) {
return 0;
}
public boolean getMono() {
return false;
}
public boolean getMute() {
return false;
}
public boolean getOmni() {
return false;
}
public int getPitchBend() {
return 0;
}
public int getPolyPressure(int noteNumber) {
return 0;
}
public int getProgram() {
return 0;
}
public boolean getSolo() {
return false;
}
public boolean localControl(boolean on) {
return false;
}
public void noteOff(int noteNumber) {
}
public void noteOff(int noteNumber, int velocity) {
}
public void noteOn(int noteNumber, int velocity) {
}
public void programChange(int program) {
}
public void programChange(int bank, int program) {
}
public void resetAllControllers() {
}
public void setChannelPressure(int pressure) {
}
public void setMono(boolean on) {
}
public void setMute(boolean mute) {
}
public void setOmni(boolean on) {
}
public void setPitchBend(int bend) {
}
public void setPolyPressure(int noteNumber, int pressure) {
}
public void setSolo(boolean soloState) {
}
}

View File

@ -0,0 +1,200 @@
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
import java.io.IOException;
import javax.sound.midi.Instrument;
import javax.sound.midi.MidiChannel;
import javax.sound.midi.Patch;
import javax.sound.midi.Soundbank;
import javax.sound.midi.SoundbankResource;
import javax.sound.midi.VoiceStatus;
/**
* A abstract class used to simplify creating custom ModelOscillator.
*
* @author Karl Helgason
*/
public abstract class ModelAbstractOscillator
implements ModelOscillator, ModelOscillatorStream, Soundbank {
protected float pitch = 6000;
protected float samplerate;
protected MidiChannel channel;
protected VoiceStatus voice;
protected int noteNumber;
protected int velocity;
protected boolean on = false;
public void init() {
}
public void close() throws IOException {
}
public void noteOff(int velocity) {
on = false;
}
public void noteOn(MidiChannel channel, VoiceStatus voice, int noteNumber,
int velocity) {
this.channel = channel;
this.voice = voice;
this.noteNumber = noteNumber;
this.velocity = velocity;
on = true;
}
public int read(float[][] buffer, int offset, int len) throws IOException {
return -1;
}
public MidiChannel getChannel() {
return channel;
}
public VoiceStatus getVoice() {
return voice;
}
public int getNoteNumber() {
return noteNumber;
}
public int getVelocity() {
return velocity;
}
public boolean isOn() {
return on;
}
public void setPitch(float pitch) {
this.pitch = pitch;
}
public float getPitch() {
return pitch;
}
public void setSampleRate(float samplerate) {
this.samplerate = samplerate;
}
public float getSampleRate() {
return samplerate;
}
public float getAttenuation() {
return 0;
}
public int getChannels() {
return 1;
}
public String getName() {
return getClass().getName();
}
public Patch getPatch() {
return new Patch(0, 0);
}
public ModelOscillatorStream open(float samplerate) {
ModelAbstractOscillator oscs;
try {
oscs = this.getClass().newInstance();
} catch (InstantiationException e) {
throw new IllegalArgumentException(e);
} catch (IllegalAccessException e) {
throw new IllegalArgumentException(e);
}
oscs.setSampleRate(samplerate);
oscs.init();
return oscs;
}
public ModelPerformer getPerformer() {
// Create performer for my custom oscillirator
ModelPerformer performer = new ModelPerformer();
performer.getOscillators().add(this);
return performer;
}
public ModelInstrument getInstrument() {
// Create Instrument object around my performer
SimpleInstrument ins = new SimpleInstrument();
ins.setName(getName());
ins.add(getPerformer());
ins.setPatch(getPatch());
return ins;
}
public Soundbank getSoundBank() {
// Create Soundbank object around the instrument
SimpleSoundbank sbk = new SimpleSoundbank();
sbk.addInstrument(getInstrument());
return sbk;
}
public String getDescription() {
return getName();
}
public Instrument getInstrument(Patch patch) {
Instrument ins = getInstrument();
Patch p = ins.getPatch();
if (p.getBank() != patch.getBank())
return null;
if (p.getProgram() != patch.getProgram())
return null;
if (p instanceof ModelPatch && patch instanceof ModelPatch) {
if (((ModelPatch)p).isPercussion()
!= ((ModelPatch)patch).isPercussion()) {
return null;
}
}
return ins;
}
public Instrument[] getInstruments() {
return new Instrument[]{getInstrument()};
}
public SoundbankResource[] getResources() {
return new SoundbankResource[0];
}
public String getVendor() {
return null;
}
public String getVersion() {
return null;
}
}

View File

@ -0,0 +1,329 @@
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.util.Collection;
/**
* This class is a pointer to a binary array either in memory or on disk.
*
* @author Karl Helgason
*/
public class ModelByteBuffer {
private ModelByteBuffer root = this;
private File file;
private long fileoffset;
private byte[] buffer;
private long offset;
private final long len;
private class RandomFileInputStream extends InputStream {
private RandomAccessFile raf;
private long left;
private long mark = 0;
private long markleft = 0;
public RandomFileInputStream() throws IOException {
raf = new RandomAccessFile(root.file, "r");
raf.seek(root.fileoffset + arrayOffset());
left = capacity();
}
public int available() throws IOException {
if (left > Integer.MAX_VALUE)
return Integer.MAX_VALUE;
return (int)left;
}
public synchronized void mark(int readlimit) {
try {
mark = raf.getFilePointer();
markleft = left;
} catch (IOException e) {
//e.printStackTrace();
}
}
public boolean markSupported() {
return true;
}
public synchronized void reset() throws IOException {
raf.seek(mark);
left = markleft;
}
public long skip(long n) throws IOException {
if( n < 0)
return 0;
if (n > left)
n = left;
long p = raf.getFilePointer();
raf.seek(p + n);
left -= n;
return n;
}
public int read(byte b[], int off, int len) throws IOException {
if (len > left)
len = (int)left;
if (left == 0)
return -1;
len = raf.read(b, off, len);
if (len == -1)
return -1;
left -= len;
return len;
}
public int read(byte[] b) throws IOException {
int len = b.length;
if (len > left)
len = (int)left;
if (left == 0)
return -1;
len = raf.read(b, 0, len);
if (len == -1)
return -1;
left -= len;
return len;
}
public int read() throws IOException {
if (left == 0)
return -1;
int b = raf.read();
if (b == -1)
return -1;
left--;
return b;
}
public void close() throws IOException {
raf.close();
}
}
private ModelByteBuffer(ModelByteBuffer parent,
long beginIndex, long endIndex, boolean independent) {
this.root = parent.root;
this.offset = 0;
long parent_len = parent.len;
if (beginIndex < 0)
beginIndex = 0;
if (beginIndex > parent_len)
beginIndex = parent_len;
if (endIndex < 0)
endIndex = 0;
if (endIndex > parent_len)
endIndex = parent_len;
if (beginIndex > endIndex)
beginIndex = endIndex;
offset = beginIndex;
len = endIndex - beginIndex;
if (independent) {
buffer = root.buffer;
if (root.file != null) {
file = root.file;
fileoffset = root.fileoffset + arrayOffset();
offset = 0;
} else
offset = arrayOffset();
root = this;
}
}
public ModelByteBuffer(byte[] buffer) {
this.buffer = buffer;
this.offset = 0;
this.len = buffer.length;
}
public ModelByteBuffer(byte[] buffer, int offset, int len) {
this.buffer = buffer;
this.offset = offset;
this.len = len;
}
public ModelByteBuffer(File file) {
this.file = file;
this.fileoffset = 0;
this.len = file.length();
}
public ModelByteBuffer(File file, long offset, long len) {
this.file = file;
this.fileoffset = offset;
this.len = len;
}
public void writeTo(OutputStream out) throws IOException {
if (root.file != null && root.buffer == null) {
InputStream is = getInputStream();
byte[] buff = new byte[1024];
int ret;
while ((ret = is.read(buff)) != -1)
out.write(buff, 0, ret);
} else
out.write(array(), (int) arrayOffset(), (int) capacity());
}
public InputStream getInputStream() {
if (root.file != null && root.buffer == null) {
try {
return new RandomFileInputStream();
} catch (IOException e) {
//e.printStackTrace();
return null;
}
}
return new ByteArrayInputStream(array(),
(int)arrayOffset(), (int)capacity());
}
public ModelByteBuffer subbuffer(long beginIndex) {
return subbuffer(beginIndex, capacity());
}
public ModelByteBuffer subbuffer(long beginIndex, long endIndex) {
return subbuffer(beginIndex, endIndex, false);
}
public ModelByteBuffer subbuffer(long beginIndex, long endIndex,
boolean independent) {
return new ModelByteBuffer(this, beginIndex, endIndex, independent);
}
public byte[] array() {
return root.buffer;
}
public long arrayOffset() {
if (root != this)
return root.arrayOffset() + offset;
return offset;
}
public long capacity() {
return len;
}
public ModelByteBuffer getRoot() {
return root;
}
public File getFile() {
return file;
}
public long getFilePointer() {
return fileoffset;
}
public static void loadAll(Collection<ModelByteBuffer> col)
throws IOException {
File selfile = null;
RandomAccessFile raf = null;
try {
for (ModelByteBuffer mbuff : col) {
mbuff = mbuff.root;
if (mbuff.file == null)
continue;
if (mbuff.buffer != null)
continue;
if (selfile == null || !selfile.equals(mbuff.file)) {
if (raf != null) {
raf.close();
raf = null;
}
selfile = mbuff.file;
raf = new RandomAccessFile(mbuff.file, "r");
}
raf.seek(mbuff.fileoffset);
byte[] buffer = new byte[(int) mbuff.capacity()];
int read = 0;
int avail = buffer.length;
while (read != avail) {
if (avail - read > 65536) {
raf.readFully(buffer, read, 65536);
read += 65536;
} else {
raf.readFully(buffer, read, avail - read);
read = avail;
}
}
mbuff.buffer = buffer;
mbuff.offset = 0;
}
} finally {
if (raf != null)
raf.close();
}
}
public void load() throws IOException {
if (root != this) {
root.load();
return;
}
if (buffer != null)
return;
if (file == null) {
throw new IllegalStateException(
"No file associated with this ByteBuffer!");
}
DataInputStream is = new DataInputStream(getInputStream());
buffer = new byte[(int) capacity()];
offset = 0;
is.readFully(buffer);
is.close();
}
public void unload() {
if (root != this) {
root.unload();
return;
}
if (file == null) {
throw new IllegalStateException(
"No file associated with this ByteBuffer!");
}
root.buffer = null;
}
}

View File

@ -0,0 +1,281 @@
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
import java.io.IOException;
import java.io.InputStream;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.AudioFormat.Encoding;
/**
* Wavetable oscillator for pre-loaded data.
*
* @author Karl Helgason
*/
public class ModelByteBufferWavetable implements ModelWavetable {
private class Buffer8PlusInputStream extends InputStream {
private boolean bigendian;
private int framesize_pc;
int pos = 0;
int pos2 = 0;
int markpos = 0;
int markpos2 = 0;
public Buffer8PlusInputStream() {
framesize_pc = format.getFrameSize() / format.getChannels();
bigendian = format.isBigEndian();
}
public int read(byte[] b, int off, int len) throws IOException {
int avail = available();
if (avail <= 0)
return -1;
if (len > avail)
len = avail;
byte[] buff1 = buffer.array();
byte[] buff2 = buffer8.array();
pos += buffer.arrayOffset();
pos2 += buffer8.arrayOffset();
if (bigendian) {
for (int i = 0; i < len; i += (framesize_pc + 1)) {
System.arraycopy(buff1, pos, b, i, framesize_pc);
System.arraycopy(buff2, pos2, b, i + framesize_pc, 1);
pos += framesize_pc;
pos2 += 1;
}
} else {
for (int i = 0; i < len; i += (framesize_pc + 1)) {
System.arraycopy(buff2, pos2, b, i, 1);
System.arraycopy(buff1, pos, b, i + 1, framesize_pc);
pos += framesize_pc;
pos2 += 1;
}
}
pos -= buffer.arrayOffset();
pos2 -= buffer8.arrayOffset();
return len;
}
public long skip(long n) throws IOException {
int avail = available();
if (avail <= 0)
return -1;
if (n > avail)
n = avail;
pos += (n / (framesize_pc + 1)) * (framesize_pc);
pos2 += n / (framesize_pc + 1);
return super.skip(n);
}
public int read(byte[] b) throws IOException {
return read(b, 0, b.length);
}
public int read() throws IOException {
byte[] b = new byte[1];
int ret = read(b, 0, 1);
if (ret == -1)
return -1;
return 0 & 0xFF;
}
public boolean markSupported() {
return true;
}
public int available() throws IOException {
return (int)buffer.capacity() + (int)buffer8.capacity() - pos - pos2;
}
public synchronized void mark(int readlimit) {
markpos = pos;
markpos2 = pos2;
}
public synchronized void reset() throws IOException {
pos = markpos;
pos2 = markpos2;
}
}
private float loopStart = -1;
private float loopLength = -1;
private ModelByteBuffer buffer;
private ModelByteBuffer buffer8 = null;
private AudioFormat format = null;
private float pitchcorrection = 0;
private float attenuation = 0;
private int loopType = LOOP_TYPE_OFF;
public ModelByteBufferWavetable(ModelByteBuffer buffer) {
this.buffer = buffer;
}
public ModelByteBufferWavetable(ModelByteBuffer buffer,
float pitchcorrection) {
this.buffer = buffer;
this.pitchcorrection = pitchcorrection;
}
public ModelByteBufferWavetable(ModelByteBuffer buffer, AudioFormat format) {
this.format = format;
this.buffer = buffer;
}
public ModelByteBufferWavetable(ModelByteBuffer buffer, AudioFormat format,
float pitchcorrection) {
this.format = format;
this.buffer = buffer;
this.pitchcorrection = pitchcorrection;
}
public void set8BitExtensionBuffer(ModelByteBuffer buffer) {
buffer8 = buffer;
}
public ModelByteBuffer get8BitExtensionBuffer() {
return buffer8;
}
public ModelByteBuffer getBuffer() {
return buffer;
}
public AudioFormat getFormat() {
if (format == null) {
if (buffer == null)
return null;
InputStream is = buffer.getInputStream();
AudioFormat format = null;
try {
format = AudioSystem.getAudioFileFormat(is).getFormat();
} catch (Exception e) {
//e.printStackTrace();
}
try {
is.close();
} catch (IOException e) {
//e.printStackTrace();
}
return format;
}
return format;
}
public AudioFloatInputStream openStream() {
if (buffer == null)
return null;
if (format == null) {
InputStream is = buffer.getInputStream();
AudioInputStream ais = null;
try {
ais = AudioSystem.getAudioInputStream(is);
} catch (Exception e) {
//e.printStackTrace();
return null;
}
return AudioFloatInputStream.getInputStream(ais);
}
if (buffer.array() == null) {
return AudioFloatInputStream.getInputStream(new AudioInputStream(
buffer.getInputStream(), format, buffer.capacity()));
}
if (buffer8 != null) {
if (format.getEncoding().equals(Encoding.PCM_SIGNED)
|| format.getEncoding().equals(Encoding.PCM_UNSIGNED)) {
InputStream is = new Buffer8PlusInputStream();
AudioFormat format2 = new AudioFormat(
format.getEncoding(),
format.getSampleRate(),
format.getSampleSizeInBits() + 8,
format.getChannels(),
format.getFrameSize() + (1 * format.getChannels()),
format.getFrameRate(),
format.isBigEndian());
AudioInputStream ais = new AudioInputStream(is, format2,
buffer.capacity() / format.getFrameSize());
return AudioFloatInputStream.getInputStream(ais);
}
}
return AudioFloatInputStream.getInputStream(format, buffer.array(),
(int)buffer.arrayOffset(), (int)buffer.capacity());
}
public int getChannels() {
return getFormat().getChannels();
}
public ModelOscillatorStream open(float samplerate) {
// ModelWavetableOscillator doesn't support ModelOscillatorStream
return null;
}
// attenuation is in cB
public float getAttenuation() {
return attenuation;
}
// attenuation is in cB
public void setAttenuation(float attenuation) {
this.attenuation = attenuation;
}
public float getLoopLength() {
return loopLength;
}
public void setLoopLength(float loopLength) {
this.loopLength = loopLength;
}
public float getLoopStart() {
return loopStart;
}
public void setLoopStart(float loopStart) {
this.loopStart = loopStart;
}
public void setLoopType(int loopType) {
this.loopType = loopType;
}
public int getLoopType() {
return loopType;
}
public float getPitchcorrection() {
return pitchcorrection;
}
public void setPitchcorrection(float pitchcorrection) {
this.pitchcorrection = pitchcorrection;
}
}

View File

@ -0,0 +1,50 @@
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
import javax.sound.midi.MidiChannel;
/**
* ModelChannelMixer is used to process channel voice mix output before going
* to master output.<br>
* It can be used to:<br>
* <ul>
* <li>Implement non-voice oriented instruments.</li>
* <li>Add insert effect to instruments; for example distortion effect.</li>
* </ui>
* <p>
* <b>Warning! Classes that implements ModelChannelMixer must be thread-safe.</b>
*
* @author Karl Helgason
*/
public interface ModelChannelMixer extends MidiChannel {
// Used to process input audio from voices mix.
public boolean process(float[][] buffer, int offset, int len);
// Is used to trigger that this mixer is not be used
// and it should fade out.
public void stop();
}

View File

@ -0,0 +1,135 @@
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
/**
* Connection blocks are used to connect source variable
* to a destination variable.
* For example Note On velocity can be connected to output gain.
* In DLS this is called articulator and in SoundFonts (SF2) a modulator.
*
* @author Karl Helgason
*/
public class ModelConnectionBlock {
//
// source1 * source2 * scale -> destination
//
private final static ModelSource[] no_sources = new ModelSource[0];
private ModelSource[] sources = no_sources;
private double scale = 1;
private ModelDestination destination;
public ModelConnectionBlock() {
}
public ModelConnectionBlock(double scale, ModelDestination destination) {
this.scale = scale;
this.destination = destination;
}
public ModelConnectionBlock(ModelSource source,
ModelDestination destination) {
if (source != null) {
this.sources = new ModelSource[1];
this.sources[0] = source;
}
this.destination = destination;
}
public ModelConnectionBlock(ModelSource source, double scale,
ModelDestination destination) {
if (source != null) {
this.sources = new ModelSource[1];
this.sources[0] = source;
}
this.scale = scale;
this.destination = destination;
}
public ModelConnectionBlock(ModelSource source, ModelSource control,
ModelDestination destination) {
if (source != null) {
if (control == null) {
this.sources = new ModelSource[1];
this.sources[0] = source;
} else {
this.sources = new ModelSource[2];
this.sources[0] = source;
this.sources[1] = control;
}
}
this.destination = destination;
}
public ModelConnectionBlock(ModelSource source, ModelSource control,
double scale, ModelDestination destination) {
if (source != null) {
if (control == null) {
this.sources = new ModelSource[1];
this.sources[0] = source;
} else {
this.sources = new ModelSource[2];
this.sources[0] = source;
this.sources[1] = control;
}
}
this.scale = scale;
this.destination = destination;
}
public ModelDestination getDestination() {
return destination;
}
public void setDestination(ModelDestination destination) {
this.destination = destination;
}
public double getScale() {
return scale;
}
public void setScale(double scale) {
this.scale = scale;
}
public ModelSource[] getSources() {
return sources;
}
public void setSources(ModelSource[] source) {
this.sources = source;
}
public void addSource(ModelSource source) {
ModelSource[] oldsources = sources;
sources = new ModelSource[oldsources.length + 1];
for (int i = 0; i < oldsources.length; i++) {
sources[i] = oldsources[i];
}
sources[sources.length - 1] = source;
}
}

View File

@ -0,0 +1,117 @@
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
/**
* This class is used to identify destinations in connection blocks,
* see ModelConnectionBlock.
*
* @author Karl Helgason
*/
public class ModelDestination {
public static final ModelIdentifier DESTINATION_NONE = null;
public static final ModelIdentifier DESTINATION_KEYNUMBER
= new ModelIdentifier("noteon", "keynumber");
public static final ModelIdentifier DESTINATION_VELOCITY
= new ModelIdentifier("noteon", "velocity");
public static final ModelIdentifier DESTINATION_PITCH
= new ModelIdentifier("osc", "pitch"); // cent
public static final ModelIdentifier DESTINATION_GAIN
= new ModelIdentifier("mixer", "gain"); // cB
public static final ModelIdentifier DESTINATION_PAN
= new ModelIdentifier("mixer", "pan"); // 0.1 %
public static final ModelIdentifier DESTINATION_REVERB
= new ModelIdentifier("mixer", "reverb"); // 0.1 %
public static final ModelIdentifier DESTINATION_CHORUS
= new ModelIdentifier("mixer", "chorus"); // 0.1 %
public static final ModelIdentifier DESTINATION_LFO1_DELAY
= new ModelIdentifier("lfo", "delay", 0); // timecent
public static final ModelIdentifier DESTINATION_LFO1_FREQ
= new ModelIdentifier("lfo", "freq", 0); // cent
public static final ModelIdentifier DESTINATION_LFO2_DELAY
= new ModelIdentifier("lfo", "delay", 1); // timecent
public static final ModelIdentifier DESTINATION_LFO2_FREQ
= new ModelIdentifier("lfo", "freq", 1); // cent
public static final ModelIdentifier DESTINATION_EG1_DELAY
= new ModelIdentifier("eg", "delay", 0); // timecent
public static final ModelIdentifier DESTINATION_EG1_ATTACK
= new ModelIdentifier("eg", "attack", 0); // timecent
public static final ModelIdentifier DESTINATION_EG1_HOLD
= new ModelIdentifier("eg", "hold", 0); // timecent
public static final ModelIdentifier DESTINATION_EG1_DECAY
= new ModelIdentifier("eg", "decay", 0); // timecent
public static final ModelIdentifier DESTINATION_EG1_SUSTAIN
= new ModelIdentifier("eg", "sustain", 0);
// 0.1 % (I want this to be value not %)
public static final ModelIdentifier DESTINATION_EG1_RELEASE
= new ModelIdentifier("eg", "release", 0); // timecent
public static final ModelIdentifier DESTINATION_EG1_SHUTDOWN
= new ModelIdentifier("eg", "shutdown", 0); // timecent
public static final ModelIdentifier DESTINATION_EG2_DELAY
= new ModelIdentifier("eg", "delay", 1); // timecent
public static final ModelIdentifier DESTINATION_EG2_ATTACK
= new ModelIdentifier("eg", "attack", 1); // timecent
public static final ModelIdentifier DESTINATION_EG2_HOLD
= new ModelIdentifier("eg", "hold", 1); // 0.1 %
public static final ModelIdentifier DESTINATION_EG2_DECAY
= new ModelIdentifier("eg", "decay", 1); // timecent
public static final ModelIdentifier DESTINATION_EG2_SUSTAIN
= new ModelIdentifier("eg", "sustain", 1);
// 0.1 % ( I want this to be value not %)
public static final ModelIdentifier DESTINATION_EG2_RELEASE
= new ModelIdentifier("eg", "release", 1); // timecent
public static final ModelIdentifier DESTINATION_EG2_SHUTDOWN
= new ModelIdentifier("eg", "shutdown", 1); // timecent
public static final ModelIdentifier DESTINATION_FILTER_FREQ
= new ModelIdentifier("filter", "freq", 0); // cent
public static final ModelIdentifier DESTINATION_FILTER_Q
= new ModelIdentifier("filter", "q", 0); // cB
private ModelIdentifier destination = DESTINATION_NONE;
private ModelTransform transform = new ModelStandardTransform();
public ModelDestination() {
}
public ModelDestination(ModelIdentifier id) {
destination = id;
}
public ModelIdentifier getIdentifier() {
return destination;
}
public void setIdentifier(ModelIdentifier destination) {
this.destination = destination;
}
public ModelTransform getTransform() {
return transform;
}
public void setTransform(ModelTransform transform) {
this.transform = transform;
}
}

View File

@ -0,0 +1,36 @@
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
/**
* ModelDirectedPlayer is the one who is directed by ModelDirector
* to play ModelPerformer objects.
*
* @author Karl Helgason
*/
public interface ModelDirectedPlayer {
public void play(int performerIndex, ModelConnectionBlock[] connectionBlocks);
}

View File

@ -0,0 +1,46 @@
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
/**
* A director chooses what performers should be played for each note on
* and note off events.
*
* ModelInstrument can implement custom performer who chooses what performers
* to play for example by sustain pedal is off or on.
*
* The default director (ModelStandardDirector) chooses performers
* by there keyfrom,keyto,velfrom,velto properties.
*
* @author Karl Helgason
*/
public interface ModelDirector {
public void noteOn(int noteNumber, int velocity);
public void noteOff(int noteNumber, int velocity);
public void close();
}

View File

@ -0,0 +1,169 @@
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
/**
* This class stores the identity of source and destinations in connection
* blocks, see ModelConnectionBlock.
*
* @author Karl Helgason
*/
public class ModelIdentifier {
/*
* Object Variable
* ------ --------
*
* // INPUT parameters
* noteon keynumber 7 bit midi value
* velocity 7 bit midi vale
* on 1 or 0
*
* midi pitch 14 bit midi value
* channel_pressure 7 bit midi value
* poly_pressure 7 bit midi value
*
* midi_cc 0 (midi control #0 7 bit midi value
* 1 (midi control #1 7 bit midi value
* ...
* 127 (midi control #127 7 bit midi value
*
* midi_rpn 0 (midi rpn control #0) 14 bit midi value
* 1 (midi rpn control #1) 14 bit midi value
* ....
*
* // DAHDSR envelope generator
* eg (null)
* delay timecent
* attack timecent
* hold timecent
* decay timecent
* sustain 0.1 %
* release timecent
*
* // Low frequency oscillirator (sine wave)
* lfo (null)
* delay timcent
* freq cent
*
* // Resonance LowPass Filter 6dB slope
* filter (null) (output/input)
* freq cent
* q cB
*
* // The oscillator with preloaded wavetable data
* osc (null)
* pitch cent
*
* // Output mixer pins
* mixer gain cB
* pan 0.1 %
* reverb 0.1 %
* chorus 0.1 %
*
*/
private String object = null;
private String variable = null;
private int instance = 0;
public ModelIdentifier(String object) {
this.object = object;
}
public ModelIdentifier(String object, int instance) {
this.object = object;
this.instance = instance;
}
public ModelIdentifier(String object, String variable) {
this.object = object;
this.variable = variable;
}
public ModelIdentifier(String object, String variable, int instance) {
this.object = object;
this.variable = variable;
this.instance = instance;
}
public int getInstance() {
return instance;
}
public void setInstance(int instance) {
this.instance = instance;
}
public String getObject() {
return object;
}
public void setObject(String object) {
this.object = object;
}
public String getVariable() {
return variable;
}
public void setVariable(String variable) {
this.variable = variable;
}
public int hashCode() {
int hashcode = instance;
if(object != null) hashcode |= object.hashCode();
if(variable != null) hashcode |= variable.hashCode();
return hashcode;
}
public boolean equals(Object obj) {
if (!(obj instanceof ModelIdentifier))
return false;
ModelIdentifier mobj = (ModelIdentifier)obj;
if ((object == null) != (mobj.object == null))
return false;
if ((variable == null) != (mobj.variable == null))
return false;
if (mobj.getInstance() != getInstance())
return false;
if (!(object == null || object.equals(mobj.object)))
return false;
if (!(variable == null || variable.equals(mobj.variable)))
return false;
return true;
}
public String toString() {
if (variable == null) {
return object + "[" + instance + "]";
} else {
return object + "[" + instance + "]" + "." + variable;
}
}
}

View File

@ -0,0 +1,136 @@
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
import javax.sound.midi.Instrument;
import javax.sound.midi.MidiChannel;
import javax.sound.midi.Patch;
import javax.sound.midi.Soundbank;
import javax.sound.sampled.AudioFormat;
/**
* The model instrument class.
*
* <p>The main methods to override are:<br>
* getPerformer, getDirector, getChannelMixer.
*
* <p>Performers are used to define what voices which will
* playback when using the instrument.<br>
*
* ChannelMixer is used to add channel-wide processing
* on voices output or to define non-voice oriented instruments.<br>
*
* Director is used to change how the synthesizer
* chooses what performers to play on midi events.
*
* @author Karl Helgason
*/
public abstract class ModelInstrument extends Instrument {
protected ModelInstrument(Soundbank soundbank, Patch patch, String name,
Class<?> dataClass) {
super(soundbank, patch, name, dataClass);
}
public ModelDirector getDirector(ModelPerformer[] performers,
MidiChannel channel, ModelDirectedPlayer player) {
return new ModelStandardDirector(performers, player);
}
public ModelPerformer[] getPerformers() {
return new ModelPerformer[0];
}
public ModelChannelMixer getChannelMixer(MidiChannel channel,
AudioFormat format) {
return null;
}
// Get General MIDI 2 Alias patch for this instrument.
public Patch getPatchAlias() {
Patch patch = getPatch();
int program = patch.getProgram();
int bank = patch.getBank();
if (bank != 0)
return patch;
boolean percussion = false;
if (getPatch() instanceof ModelPatch)
percussion = ((ModelPatch)getPatch()).isPercussion();
if (percussion)
return new Patch(0x78 << 7, program);
else
return new Patch(0x79 << 7, program);
}
// Return name of all the keys.
// This information is generated from ModelPerformer.getName()
// returned from getPerformers().
public String[] getKeys() {
String[] keys = new String[128];
for (ModelPerformer performer : getPerformers()) {
for (int k = performer.getKeyFrom(); k <= performer.getKeyTo(); k++) {
if (k >= 0 && k < 128 && keys[k] == null) {
String name = performer.getName();
if (name == null)
name = "untitled";
keys[k] = name;
}
}
}
return keys;
}
// Return what channels this instrument will probably response
// on General MIDI synthesizer.
public boolean[] getChannels() {
boolean percussion = false;
if (getPatch() instanceof ModelPatch)
percussion = ((ModelPatch)getPatch()).isPercussion();
// Check if instrument is percussion.
if (percussion) {
boolean[] ch = new boolean[16];
for (int i = 0; i < ch.length; i++)
ch[i] = false;
ch[9] = true;
return ch;
}
// Check if instrument uses General MIDI 2 default banks.
int bank = getPatch().getBank();
if (bank >> 7 == 0x78 || bank >> 7 == 0x79) {
boolean[] ch = new boolean[16];
for (int i = 0; i < ch.length; i++)
ch[i] = true;
return ch;
}
boolean[] ch = new boolean[16];
for (int i = 0; i < ch.length; i++)
ch[i] = true;
ch[9] = false;
return ch;
}
}

View File

@ -0,0 +1,52 @@
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
import java.util.Comparator;
import javax.sound.midi.Instrument;
import javax.sound.midi.Patch;
/**
* Instrument comparator class.
* Used to order instrument by program, bank, percussion.
*
* @author Karl Helgason
*/
public class ModelInstrumentComparator implements Comparator<Instrument> {
public int compare(Instrument arg0, Instrument arg1) {
Patch p0 = arg0.getPatch();
Patch p1 = arg1.getPatch();
int a = p0.getBank() * 128 + p0.getProgram();
int b = p1.getBank() * 128 + p1.getProgram();
if (p0 instanceof ModelPatch) {
a += ((ModelPatch)p0).isPercussion() ? 2097152 : 0;
}
if (p1 instanceof ModelPatch) {
b += ((ModelPatch)p1).isPercussion() ? 2097152 : 0;
}
return a - b;
}
}

View File

@ -0,0 +1,62 @@
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
import javax.sound.midi.MidiChannel;
import javax.sound.midi.Patch;
import javax.sound.sampled.AudioFormat;
/**
* This class is used to map instrument to another patch.
*
* @author Karl Helgason
*/
public class ModelMappedInstrument extends ModelInstrument {
private ModelInstrument ins;
public ModelMappedInstrument(ModelInstrument ins, Patch patch) {
super(ins.getSoundbank(), patch, ins.getName(), ins.getDataClass());
this.ins = ins;
}
public Object getData() {
return ins.getData();
}
public ModelPerformer[] getPerformers() {
return ins.getPerformers();
}
public ModelDirector getDirector(ModelPerformer[] performers,
MidiChannel channel, ModelDirectedPlayer player) {
return ins.getDirector(performers, channel, player);
}
public ModelChannelMixer getChannelMixer(MidiChannel channel,
AudioFormat format) {
return ins.getChannelMixer(channel, format);
}
}

View File

@ -0,0 +1,44 @@
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
/**
* This interface is used for oscillators.
* See example in ModelDefaultOscillator which is a wavetable oscillator.
*
* @author Karl Helgason
*/
public interface ModelOscillator {
public int getChannels();
/**
* Attenuation is in cB.
* @return
*/
public float getAttenuation();
public ModelOscillatorStream open(float samplerate);
}

Some files were not shown because too many files have changed in this diff Show More