Commit 6ca84a80 by Michael Koch

[multiple changes]

2005-02-19  Michael Koch  <konqueror@gmx.de>

	* Makefile.am: Added new files in gnu/java/beans and
	java/beans/XMLDecoder.java.
	* Makefile.in: Regenerated.

2005-02-19  Robert Schuster  <thebohemian@gmx.net>

	* gnu/java/beans/decoder/GrowableArrayContext.java: Fixed
	assignment behavior by using java.lang.reflect.Array.set()
	directly.

2005-02-19  Dalibor Topic  <robilad@kaffe.org>

	* gnu/java/beans/EmptyBeanInfo.java,
	gnu/java/beans/info/ComponentBeanInfo.java:
	Removed unused files.

2005-02-19  Robert Schuster <thebohemian@gmx.net>

	* gnu/java/beans/DummyAppletStub.java: Add dummy implementation
	of AppletStub for java.beans.Beans.instantiate.
	* gnu/java/beans/DummyAppletContext.java: Add dummy implementation
	of AppletContext.
	* java/beans/Beans: Added 1.4 functionality, fixed user documentation
	to be conformant with Javadoc guidelines.
	(instantiate): Added two more overloaded variants, reworked user
	documentation, fixed exception behavior, fixed behavior when
	deserializing null.

2005-02-19  Mark Wielaard  <mark@klomp.org>

	* gnu/java/beans/decoder/DummyHandler.java: Add return statements for
	failing methods.
	* gnu/java/beans/decoder/DummyContext.java: Likewise.

2005-02-19  Robert Schuster  <theBohemian@gmx.net>

	* gnu/java/beans/decoder/AbstractContext.java,
	gnu/java/beans/decoder/AbstractCreatableContext.java,
	gnu/java/beans/decoder/AbstractElementHandler.java,
	gnu/java/beans/decoder/AbstractObjectContext.java,
	gnu/java/beans/decoder/ArrayContext.java,
	gnu/java/beans/decoder/ArrayHandler.java,
	gnu/java/beans/decoder/AssemblyException.java,
	gnu/java/beans/decoder/BooleanHandler.java,
	gnu/java/beans/decoder/ByteHandler.java,
	gnu/java/beans/decoder/CharHandler.java,
	gnu/java/beans/decoder/ClassHandler.java,
	gnu/java/beans/decoder/ConstructorContext.java,
	gnu/java/beans/decoder/Context.java,
	gnu/java/beans/decoder/DecoderContext.java,
	gnu/java/beans/decoder/DefaultExceptionListener.java,
	gnu/java/beans/decoder/DoubleHandler.java,
	gnu/java/beans/decoder/DummyContext.java,
	gnu/java/beans/decoder/DummyHandler.java,
	gnu/java/beans/decoder/ElementHandler.java,
	gnu/java/beans/decoder/FloatHandler.java,
	gnu/java/beans/decoder/GrowableArrayContext.java,
	gnu/java/beans/decoder/IndexContext.java,
	gnu/java/beans/decoder/IntHandler.java,
	gnu/java/beans/decoder/JavaHandler.java,
	gnu/java/beans/decoder/LongHandler.java,
	gnu/java/beans/decoder/MethodContext.java,
	gnu/java/beans/decoder/MethodFinder.java,
	gnu/java/beans/decoder/NullHandler.java,
	gnu/java/beans/decoder/ObjectContext.java,
	gnu/java/beans/decoder/ObjectHandler.java,
	gnu/java/beans/decoder/PersistenceParser.java,
	gnu/java/beans/decoder/PropertyContext.java,
	gnu/java/beans/decoder/ShortHandler.java,
	gnu/java/beans/decoder/SimpleHandler.java,
	gnu/java/beans/decoder/StaticMethodContext.java,
	gnu/java/beans/decoder/StringHandler.java,
	gnu/java/beans/decoder/VoidHandler.java: New class
	implementing java.beans.XMLDecoder decoding functionality.
	* java/beans/XMLDecoder.java: New class.

From-SVN: r95287
parent 2cdc2073
2005-02-19 Michael Koch <konqueror@gmx.de>
* Makefile.am: Added new files in gnu/java/beans and
java/beans/XMLDecoder.java.
* Makefile.in: Regenerated.
2005-02-19 Robert Schuster <thebohemian@gmx.net>
* gnu/java/beans/decoder/GrowableArrayContext.java: Fixed
assignment behavior by using java.lang.reflect.Array.set()
directly.
2005-02-19 Dalibor Topic <robilad@kaffe.org>
* gnu/java/beans/EmptyBeanInfo.java,
gnu/java/beans/info/ComponentBeanInfo.java:
Removed unused files.
2005-02-19 Robert Schuster <thebohemian@gmx.net>
* gnu/java/beans/DummyAppletStub.java: Add dummy implementation
of AppletStub for java.beans.Beans.instantiate.
* gnu/java/beans/DummyAppletContext.java: Add dummy implementation
of AppletContext.
* java/beans/Beans: Added 1.4 functionality, fixed user documentation
to be conformant with Javadoc guidelines.
(instantiate): Added two more overloaded variants, reworked user
documentation, fixed exception behavior, fixed behavior when
deserializing null.
2005-02-19 Mark Wielaard <mark@klomp.org>
* gnu/java/beans/decoder/DummyHandler.java: Add return statements for
failing methods.
* gnu/java/beans/decoder/DummyContext.java: Likewise.
2005-02-19 Robert Schuster <theBohemian@gmx.net>
* gnu/java/beans/decoder/AbstractContext.java,
gnu/java/beans/decoder/AbstractCreatableContext.java,
gnu/java/beans/decoder/AbstractElementHandler.java,
gnu/java/beans/decoder/AbstractObjectContext.java,
gnu/java/beans/decoder/ArrayContext.java,
gnu/java/beans/decoder/ArrayHandler.java,
gnu/java/beans/decoder/AssemblyException.java,
gnu/java/beans/decoder/BooleanHandler.java,
gnu/java/beans/decoder/ByteHandler.java,
gnu/java/beans/decoder/CharHandler.java,
gnu/java/beans/decoder/ClassHandler.java,
gnu/java/beans/decoder/ConstructorContext.java,
gnu/java/beans/decoder/Context.java,
gnu/java/beans/decoder/DecoderContext.java,
gnu/java/beans/decoder/DefaultExceptionListener.java,
gnu/java/beans/decoder/DoubleHandler.java,
gnu/java/beans/decoder/DummyContext.java,
gnu/java/beans/decoder/DummyHandler.java,
gnu/java/beans/decoder/ElementHandler.java,
gnu/java/beans/decoder/FloatHandler.java,
gnu/java/beans/decoder/GrowableArrayContext.java,
gnu/java/beans/decoder/IndexContext.java,
gnu/java/beans/decoder/IntHandler.java,
gnu/java/beans/decoder/JavaHandler.java,
gnu/java/beans/decoder/LongHandler.java,
gnu/java/beans/decoder/MethodContext.java,
gnu/java/beans/decoder/MethodFinder.java,
gnu/java/beans/decoder/NullHandler.java,
gnu/java/beans/decoder/ObjectContext.java,
gnu/java/beans/decoder/ObjectHandler.java,
gnu/java/beans/decoder/PersistenceParser.java,
gnu/java/beans/decoder/PropertyContext.java,
gnu/java/beans/decoder/ShortHandler.java,
gnu/java/beans/decoder/SimpleHandler.java,
gnu/java/beans/decoder/StaticMethodContext.java,
gnu/java/beans/decoder/StringHandler.java,
gnu/java/beans/decoder/VoidHandler.java: New class
implementing java.beans.XMLDecoder decoding functionality.
* java/beans/XMLDecoder.java: New class.
2005-02-19 Michael Koch <konqueror@gmx.de>
* javax/swing/JTextField.java
(notfiyAction): Added javadoc.
......
......@@ -1077,6 +1077,43 @@ gnu/java/awt/peer/EmbeddedWindowPeer.java \
gnu/java/awt/peer/GLightweightPeer.java \
gnu/java/awt/peer/ClasspathFontPeer.java \
gnu/java/awt/peer/ClasspathTextLayoutPeer.java \
gnu/java/beans/decoder/AbstractContext.java \
gnu/java/beans/decoder/AbstractCreatableObjectContext.java \
gnu/java/beans/decoder/AbstractElementHandler.java \
gnu/java/beans/decoder/AbstractObjectContext.java \
gnu/java/beans/decoder/ArrayContext.java \
gnu/java/beans/decoder/ArrayHandler.java \
gnu/java/beans/decoder/AssemblyException.java \
gnu/java/beans/decoder/BooleanHandler.java \
gnu/java/beans/decoder/ByteHandler.java \
gnu/java/beans/decoder/CharHandler.java \
gnu/java/beans/decoder/ClassHandler.java \
gnu/java/beans/decoder/ConstructorContext.java \
gnu/java/beans/decoder/Context.java \
gnu/java/beans/decoder/DecoderContext.java \
gnu/java/beans/decoder/DefaultExceptionListener.java \
gnu/java/beans/decoder/DoubleHandler.java \
gnu/java/beans/decoder/DummyContext.java \
gnu/java/beans/decoder/DummyHandler.java \
gnu/java/beans/decoder/ElementHandler.java \
gnu/java/beans/decoder/FloatHandler.java \
gnu/java/beans/decoder/GrowableArrayContext.java \
gnu/java/beans/decoder/IndexContext.java \
gnu/java/beans/decoder/IntHandler.java \
gnu/java/beans/decoder/JavaHandler.java \
gnu/java/beans/decoder/LongHandler.java \
gnu/java/beans/decoder/MethodContext.java \
gnu/java/beans/decoder/MethodFinder.java \
gnu/java/beans/decoder/NullHandler.java \
gnu/java/beans/decoder/ObjectContext.java \
gnu/java/beans/decoder/ObjectHandler.java \
gnu/java/beans/decoder/PersistenceParser.java \
gnu/java/beans/decoder/PropertyContext.java \
gnu/java/beans/decoder/ShortHandler.java \
gnu/java/beans/decoder/SimpleHandler.java \
gnu/java/beans/decoder/StaticMethodContext.java \
gnu/java/beans/decoder/StringHandler.java \
gnu/java/beans/decoder/VoidHandler.java \
gnu/java/beans/editors/ColorEditor.java \
gnu/java/beans/editors/FontEditor.java \
gnu/java/beans/editors/NativeBooleanEditor.java \
......@@ -1087,9 +1124,9 @@ gnu/java/beans/editors/NativeIntEditor.java \
gnu/java/beans/editors/NativeLongEditor.java \
gnu/java/beans/editors/NativeShortEditor.java \
gnu/java/beans/editors/StringEditor.java \
gnu/java/beans/info/ComponentBeanInfo.java \
gnu/java/beans/BeanInfoEmbryo.java \
gnu/java/beans/EmptyBeanInfo.java \
gnu/java/beans/DummyAppletContext.java \
gnu/java/beans/DummyAppletStub.java \
gnu/java/beans/ExplicitBeanInfo.java \
gnu/java/beans/IntrospectionIncubator.java \
java/applet/Applet.java \
......@@ -1469,6 +1506,7 @@ java/beans/VetoableChangeListenerProxy.java \
java/beans/VetoableChangeSupport.java \
java/beans/Visibility.java \
java/beans/AppletInitializer.java \
java/beans/XMLDecoder.java \
javax/swing/border/AbstractBorder.java \
javax/swing/border/BevelBorder.java \
javax/swing/border/Border.java \
......
/* gnu.java.beans.DummyAppletContext
Copyright (C) 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.java.beans;
import java.applet.Applet;
import java.applet.AppletContext;
import java.applet.AudioClip;
import java.awt.Image;
import java.awt.Toolkit;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Iterator;
/** A placeholder <code>AppletContext</code> implementation that does nothing.
*
* <p>This is the default implementation for GNU Classpath and is used for <code>Applet</code>
* beans being created with {@link java.beans.Beans.instantiate}.</p>
*
* <p>It has no functionality in order to allow it to be used without any dependencies
* (e.g. sound, network access, ...).</p>
*
* @author Robert Schuster
*/
class DummyAppletContext implements AppletContext
{
private static final Enumeration EMPTY_ENUMERATION = Collections.enumeration(Collections.EMPTY_SET);
private static final AudioClip DUMMY_CLIP = new DummyAudioClip();
DummyAppletContext()
{
}
/** Implementation is VM neutral and returns a dummy {@link AudioClip} instance
* for every URL that returns a non-<code>null</code> object on
* <code>URL.openConnection()</code>.
*
* @see java.applet.AppletContext#getAudioClip(java.net.URL)
*
* FIXME: When Java Sound API (javax.sound) is included in Classpath or URL is able to handle
* sampled sound this should be adjusted.
*/
public AudioClip getAudioClip(URL url)
{
try
{
return (url.openConnection() != null ? DUMMY_CLIP : null);
}
catch (IOException ioe)
{
return null;
}
}
/** Loads the <code>Image</code> instance by delegating to
* {@link java.awt.Toolkit.createImage(URL) }.
*
* @see java.applet.AppletContext#getImage(java.net.URL)
* @see java.awt.Toolkit#createImage(java.net.URL)
*/
public Image getImage(URL url)
{
return Toolkit.getDefaultToolkit().createImage(url);
}
/** Returns <code>null</code> for every argument.
*
* @see java.applet.AppletContext#getApplet(java.lang.String)
*/
public Applet getApplet(String name)
{
return null;
}
/** Returns always an empty <code>Enumeration</code>.
*
* @see java.applet.AppletContext#getApplets()
*/
public Enumeration getApplets()
{
return EMPTY_ENUMERATION;
}
/** Does nothing.
*
* @see java.applet.AppletContext#showDocument(java.net.URL)
*/
public void showDocument(URL url)
{
}
/** Does nothing.
*
* @see java.applet.AppletContext#showDocument(java.net.URL, java.lang.String)
*/
public void showDocument(URL url, String target)
{
}
/** Does nothing.
*
* @see java.applet.AppletContext#showStatus(java.lang.String)
*/
public void showStatus(String message)
{
}
/** Does nothing.
*
* @see java.applet.AppletContext#setStream(java.lang.String, java.io.InputStream)
*/
public void setStream(String key, InputStream stream)
throws IOException
{
throw new IOException("Dummy implementation imposes zero InputStream associations.");
}
/** Returns <code>null</code> for every argument.
*
* @see java.applet.AppletContext#getStream(java.lang.String)
*/
public InputStream getStream(String key)
{
return null;
}
/** Returns always an empty iterator.
*
* @see java.applet.AppletContext#getStreamKeys()
*/
public Iterator getStreamKeys()
{
return Collections.EMPTY_SET.iterator();
}
/** Dummy <code>AudioClip</code> implementation that does nothing but
* preventing <code>NullPointerException</code>S being thrown in programs
* that expect a valid <code>AudioClip</code> instance to be returned by
* their Applet.
*
* @author Robert Schuster
*/
static class DummyAudioClip implements AudioClip
{
public void play()
{
}
public void stop()
{
}
public void loop()
{
}
public String toString()
{
return "DummyAudioClip never plays anything - implement javax.sound and make us happy :)";
}
}
}
/* gnu.java.beans.DummyAppletStub
Copyright (C) 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.java.beans;
import java.applet.AppletContext;
import java.applet.AppletStub;
import java.net.URL;
/** Placeholder implementation of <code>AppletStub</code> providing no functionality.
* <p>This class is used for <code>Applet</code> being created with
* {@link java.beans.Bean.instantiate}.</p>
*
* @author Robert Schuster
*/
public class DummyAppletStub implements AppletStub
{
private URL documentBase;
private URL codeBase;
private DummyAppletContext context;
public DummyAppletStub(URL newCodeBase, URL newDocumentBase)
{
codeBase = newCodeBase;
documentBase = newDocumentBase;
context = new DummyAppletContext();
}
/** Returns always <code>true</code>.
*
* @see java.applet.AppletStub#isActive()
*/
public boolean isActive()
{
return true;
}
/**
* @see java.applet.AppletStub#getDocumentBase()
*/
public URL getDocumentBase()
{
return documentBase;
}
/**
* @see java.applet.AppletStub#getCodeBase()
*/
public URL getCodeBase()
{
return codeBase;
}
/** Implementation returns <code>null</code> for every parameter name.
*
* @see java.applet.AppletStub#getParameter(java.lang.String)
*/
public String getParameter(String name)
{
return null;
}
/** Returns a non-functional context instance.
*
* @see java.applet.AppletStub#getAppletContext()
*/
public AppletContext getAppletContext()
{
return context;
}
/** Does nothing.
*
* @see java.applet.AppletStub#appletResize(int, int)
*/
public void appletResize(int width, int height)
{
}
}
/* gnu.java.beans.decoder.AbstractContext
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.java.beans.decoder;
/** AbstractContext implements some basic functionality of the Context
* interface and is therefore the base of all Context implementations.
*
* @author Robert Schuster
*/
abstract class AbstractContext implements Context
{
private boolean isStatement;
private String id;
public String getId()
{
return id;
}
public void setId(String newId)
{
id = newId;
}
public boolean isStatement()
{
return isStatement;
}
public void setStatement(boolean b)
{
isStatement = b;
}
}
/* gnu.java.beans.decoder.AbstractCreatableContext
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.java.beans.decoder;
/** AbstractCreatableObjectContext is the base class for all Context implementations
* which create a result object in their lifetime. It provides means for preventing
* to create the object twice.
*
* @author Robert Schuster
*
*/
abstract class AbstractCreatableObjectContext extends AbstractObjectContext
{
AbstractCreatableObjectContext()
{
}
/** Adds a parameter object to this Context if the result object has not been
* created yet. Otherwise an AssemblyException is thrown that indicates a wrong
* behavior of the decoder.
*/
public final void addParameterObject(Object o) throws AssemblyException
{
if (object == null)
addParameterObjectImpl(o);
else
throw new AssemblyException(new IllegalStateException("No more parameter objects are allowed when the object as already been created."));
}
/** Adds a parameter object to this Context. Implement this without caring
* for illegal states because this has been done already.
*
* @param obj The parameter object to be added.
*/
protected abstract void addParameterObjectImpl(Object obj);
/** Creates the result object if it does not exist already.
*/
public final void notifyStatement(Context outerContext)
throws AssemblyException
{
if (object != null)
return;
object = createObject(outerContext);
}
/** Creates the result object. This method is called only once. Implement this
* without checking for double invocations as this is already being prevented.
*
* @param outerContext The Context that exists around this one.
* @return The result object.
* @throws AssemblerException if the object creation fails somehow.
*/
protected abstract Object createObject(Context outerContext)
throws AssemblyException;
/* (non-Javadoc)
* @see gnu.java.beans.decoder.Context#endContext(gnu.java.beans.decoder.Context)
*/
public final Object endContext(Context outerContext)
throws AssemblyException
{
notifyStatement(outerContext);
return object;
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.Context#subContextFailed()
*/
public boolean subContextFailed()
{
/* Returns true when the AbstractCreatableObjectContext has not created the result object yet
* (A failed subcontext automatically lets this context fail too.)
*/
return object == null;
}
}
/* gnu.java.beans.decoder.AbstractObjectContext
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.java.beans.decoder;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
/** AbstractObjectContext is the base for all Context implementations which
* create or provide a result object during their lifetime.
*
* <p>This class provides the implementation for an indexed get and set method.
* But this does not mean that the result object supports these operation.</p>
*
* @author Robert Schuster
*
*/
abstract class AbstractObjectContext extends AbstractContext
{
protected Object object;
AbstractObjectContext()
{}
/** Sets the result object of the Context.
*
* @param obj The result object to be set.
*/
protected final void setObject(Object obj)
{
object = obj;
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.Context#set(int, java.lang.Object)
*/
public final void set(int index, Object o) throws AssemblyException
{
try
{
Method method =
object.getClass().getMethod(
"set",
new Class[] { Integer.TYPE, Object.class });
method.invoke(object, new Object[] { new Integer(index), o });
}
catch (NoSuchMethodException nsme)
{
throw new AssemblyException(nsme);
}
catch (InvocationTargetException ite)
{
throw new AssemblyException(ite.getCause());
}
catch (IllegalAccessException iae)
{
throw new AssemblyException(iae);
}
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.Context#get(int)
*/
public final Object get(int index) throws AssemblyException
{
try
{
Method method =
object.getClass().getMethod(
"get",
new Class[] { Integer.TYPE });
return method.invoke(object, new Object[] { new Integer(index)});
}
catch (NoSuchMethodException nsme)
{
throw new AssemblyException(nsme);
}
catch (InvocationTargetException ite)
{
throw new AssemblyException(ite.getCause());
}
catch (IllegalAccessException iae)
{
throw new AssemblyException(iae);
}
}
public final Object getResult()
{
return object;
}
}
/* gnu.java.beans.decoder.ArrayContext
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.java.beans.decoder;
import java.lang.reflect.Array;
/** A Context implementation for a fixed size array. The array
* elements have to be set using IndexContext instances.
*
* @author Robert Schuster
*/
class ArrayContext extends AbstractContext
{
private Object array;
ArrayContext(String id, Class klass, int length)
{
setId(id);
array = Array.newInstance(klass, length);
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.Context#addObject(java.lang.Object)
*/
public void addParameterObject(Object o) throws AssemblyException
{
throw new AssemblyException(new IllegalStateException("Adding objects without an index to a fixed array is not possible."));
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.Context#reportStatement()
*/
public void notifyStatement(Context outerContext)
{
// method call intentionally ignored because there is not any useful effect
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.Context#endContext(gnu.java.beans.decoder.Context)
*/
public Object endContext(Context outerContext) throws AssemblyException
{
return array;
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.Context#subContextFailed()
*/
public boolean subContextFailed()
{
// returns false to indicate that assembling the array does not fail only because
// a subelement failed.
return false;
}
public void set(int index, Object o) throws AssemblyException
{
try
{
Array.set(array, index, o);
}
catch (ArrayIndexOutOfBoundsException aioobe)
{
throw new AssemblyException(aioobe);
}
}
public Object get(int index) throws AssemblyException
{
try
{
return Array.get(array, index);
}
catch (ArrayIndexOutOfBoundsException aioobe)
{
throw new AssemblyException(aioobe);
}
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.Context#getResult()
*/
public Object getResult()
{
return array;
}
}
/* gnu.java.beans.decoder.ArrayHandler
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.java.beans.decoder;
import java.beans.ExceptionListener;
import java.util.HashMap;
import org.xml.sax.Attributes;
/** ArrayHandler processes the &lt;array&gt; tag. Depending on the existance of the 'length' attribute a Context for
* a fixed-size or growable array is created.
*
* @author Robert Schuster
*/
class ArrayHandler extends AbstractElementHandler
{
/** Contains a mapping between a textual description of a primitive type (like "byte") and
* its corresponding wrapper class. This allows it to easily construct Array objects for
* primitive data types.
*/
private static HashMap typeMap = new HashMap();
static
{
typeMap.put("byte", Byte.TYPE);
typeMap.put("short", Short.TYPE);
typeMap.put("int", Integer.TYPE);
typeMap.put("long", Long.TYPE);
typeMap.put("float", Float.TYPE);
typeMap.put("double", Double.TYPE);
typeMap.put("boolean", Boolean.TYPE);
typeMap.put("char", Character.TYPE);
}
/**
* @param PersistenceParser
*/
ArrayHandler(ElementHandler parent)
{
super(parent, true);
}
protected Context startElement(Attributes attributes, ExceptionListener exceptionListener)
throws AssemblyException, AssemblyException
{
String id = attributes.getValue("id");
String className = attributes.getValue("class");
if (className != null)
{
try
{
Class klass;
if (typeMap.containsKey(className))
klass = (Class) typeMap.get(className);
else
klass = instantiateClass(className);
String length = attributes.getValue("length");
if (length != null)
// creates Array with predefined length
return new ArrayContext(id, klass, Integer.parseInt(length));
else
// creates Array without length restriction
return new GrowableArrayContext(id, klass);
}
catch (ClassNotFoundException cnfe)
{
throw new AssemblyException(cnfe);
}
catch (NumberFormatException nfe)
{
throw new AssemblyException(nfe);
}
}
throw new AssemblyException(new IllegalArgumentException("Missing 'class' attribute in <array> tag."));
}
}
/* gnu.java.beans.decoder.AssemblyException
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.java.beans.decoder;
/** The AssemblyException is used to wrap the cause of problems when assembling objects.
* In all cases only the wrapped exception is given to the PersistenceParser's
* ExceptionListener instance (never the AssemblyException itself).
*
* <p>Note: Often multiple steps are needed to construct a fully usuable object instance.
* Such a construction can be called assembly and thats why this exception was
* named AssemblyException.</p>
*
* @author Robert Schuster
*/
class AssemblyException extends Exception
{
AssemblyException(Throwable cause)
{
super(cause);
}
}
/* gnu.java.beans.decoder.BooleanHandler
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.java.beans.decoder;
/** Creates a Boolean instance from the character data in a &lt;boolean&gt; tag.
*
* @author Robert Schuster
*/
class BooleanHandler extends SimpleHandler
{
/**
* @param PersistenceParser
*/
BooleanHandler(ElementHandler parent)
{
super(parent);
// TODO Auto-generated constructor stub
}
protected Object parse(String number) throws AssemblyException
{
if (number.equals("true"))
return new Boolean(true);
if (number.equals("false"))
return new Boolean(false);
throw new AssemblyException(new IllegalArgumentException("Element contained no valid boolean value."));
}
}
/* gnu.java.beans.decoder.ByteHandler
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.java.beans.decoder;
/** Creates a Byte instance from the character data in a &lt;byte&gt; tag.
*
* @author Robert Schuster
*/
class ByteHandler extends SimpleHandler
{
/**
* @param PersistenceParser
*/
ByteHandler(ElementHandler parent)
{
super(parent);
}
protected Object parse(String number) throws NumberFormatException
{
return Byte.valueOf(number);
}
}
/* gnu.java.beans.decoder.CharHandler
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.java.beans.decoder;
/** Creates a Character instance from the character data in a &lt;char&gt; tag.
*
* @author Robert Schuster
*/
class CharHandler extends SimpleHandler
{
/**
* @param PersistenceParser
*/
CharHandler(ElementHandler parent)
{
super(parent);
}
protected Object parse(String number) throws AssemblyException
{
if (number.length() > 1)
throw new AssemblyException(new IllegalArgumentException("Element contained no valid character."));
return new Character(number.charAt(0));
}
}
/* gnu.java.beans.info.ComponentBeanInfo
Copyright (C) 1998 Free Software Foundation, Inc.
/* gnu.java.beans.decoder.ClassHandler
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
......@@ -35,41 +35,32 @@ this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.java.beans.decoder;
package gnu.java.beans.info;
import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.beans.SimpleBeanInfo;
/** Creates a Class instance from the character data in a &lt;class&gt; tag.
*
* @author Robert Schuster
*/
class ClassHandler extends SimpleHandler
{
/**
* @param PersistenceParser
*/
ClassHandler(ElementHandler parent)
{
super(parent);
}
/** BeanInfo class for java.awt.Component.
** This provides a few properties, but that's
** it.
** @author John Keiser
** @version 1.1.0, Aug 1 1998
**/
public class ComponentBeanInfo extends SimpleBeanInfo {
static PropertyDescriptor[] properties;
static {
try {
properties = new PropertyDescriptor[6];
properties[0] = new PropertyDescriptor("name",java.awt.Component.class);
properties[1] = new PropertyDescriptor("background",java.awt.Component.class);
properties[2] = new PropertyDescriptor("foreground",java.awt.Component.class);
properties[3] = new PropertyDescriptor("font",java.awt.Component.class);
properties[4] = new PropertyDescriptor("enabled",java.awt.Component.class);
properties[5] = new PropertyDescriptor("visible",java.awt.Component.class);
} catch(IntrospectionException E) {
properties = null;
throw new UnknownError("Could not introspect some java.awt.Component properties.");
}
}
public ComponentBeanInfo() {
super();
}
public PropertyDescriptor[] getPropertyDescriptors() {
return properties;
}
protected Object parse(String characters) throws AssemblyException
{
try
{
return instantiateClass(characters);
}
catch (ClassNotFoundException cnfe)
{
throw new AssemblyException(cnfe);
}
}
}
/* gnu.java.beans.decoder.ConstructorContext
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.java.beans.decoder;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
/** A ConstructorContext is a {@link Context} implementation which collects the parameters for a constructor
* call and instantiates the result object using that constructor. After that sub-contexts can invoke
* methods on the result object.
*
* <p>The constructor is invoked when a sub-context is a statement or the Context ends.</p>
*
* @author Robert Schuster
*/
class ConstructorContext extends AbstractCreatableObjectContext
{
private ArrayList arguments = new ArrayList();
private Class klass;
ConstructorContext(String id, Class newClass)
{
setId(id);
// sets superclass field
klass = newClass;
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.Context#addObject(java.lang.Object)
*/
protected void addParameterObjectImpl(Object o)
{
arguments.add(o);
}
protected Object createObject(Context outerContext)
throws AssemblyException
{
Object[] args = arguments.toArray();
try
{
Constructor constructor = MethodFinder.getConstructor(klass, args);
// instantiates object (klass field gets re-set by superclass)
return constructor.newInstance(args);
}
catch (NoSuchMethodException nsme)
{
throw new AssemblyException(nsme);
}
catch (InvocationTargetException ite)
{
throw new AssemblyException(ite.getCause());
}
catch (IllegalAccessException iae)
{
throw new AssemblyException(iae);
}
catch (InstantiationException ie)
{
throw new AssemblyException(ie);
}
}
}
/* gnu.java.beans.decoder.Context
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.java.beans.decoder;
/** A Context is the environment for an object which is being assembler. If there
* are no errors each handler creates one Context.
* <p>Depending on the result of isStatement() a Context can be statement or an
* expression. An expression returns a value to the Context of its parent handler,
* a statement does not. Whenever a Context is a statement the parent handler's
* Context is informed about that through the {@link notifyStatement}-method.</p>
*
* @author Robert Schuster
*/
interface Context
{
/** Adds a parameter object to the context. This method is used when
* sub-Contexts return their result.
*
* Some Contexts do not accept more than a certain amount of objects
* and throw an AssemblerException if the amount is exceeded.
*
* @param o The object added to this context.
*/
void addParameterObject(Object o) throws AssemblyException;
/** Notifies that the next element is a statement. This can mean
* that an argument list is complete to be called.
*
*/
void notifyStatement(Context outerContext) throws AssemblyException;
/** Notifies that the context ends and the returns the appropriate result
* object.
*
* @param outerContext
* @return
*/
Object endContext(Context outerContext) throws AssemblyException;
/** Notifies that the assembly of a subcontext failed and returns
* whether this Context is affected in a way that it fails too.
*
* @return Whether the failure of a subcontext lets this context fail, too.
*/
boolean subContextFailed();
/** Calls an appropriate indexed set method if it is available or
* throws an AssemblerException if that is not allowed on this Context.
*
* The behaviour of this method is equal to List.set(int, Object).
*
* @param index Index position to be set.
* @param o Object to be set at the given index position.
* @throws AssemblerException Indexed set is not allowed or otherwise failed.
*/
void set(int index, Object o) throws AssemblyException;
/** Calls an appropriate indexed get method if it is available or
* throws an AssemblerException if that is not allowed on this Context.
*
* The behaviour of this method is equal to List.get(int).
*
* @param index Index position of the object return.
* @throws AssemblerException Indexed get is not allowed or otherwise failed.
*/
Object get(int index) throws AssemblyException;
/** Returns the result which was calculated by calling endContext() or reportStatement().
* Its the handler's responsibility to care that any of these two methods was called.
*
* This is used by sub-Contexts to access this Context's result.
*
* @return
*/
Object getResult();
/** Gives this Context a unique id. For convenience the id may be null which means
* that no id exists at all.
*
* @param id
*/
void setId(String id);
/** Returns this Context's unique id or null if does not have such an id.
*
* @return This Context's id or null.
*/
String getId();
/** Returns whether this Context is a statement (not returning result back
* to parent handler's Context) or not (= expression).
*
* @return
*/
boolean isStatement();
/** Sets whether this Context is a statement or not.
*
* @param b
*/
void setStatement(boolean b);
}
/* gnu.java.beans.decoder.DecoderContext
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.java.beans.decoder;
import java.beans.XMLDecoder;
import java.util.ArrayList;
import java.util.Iterator;
/** DecoderContext is a Context implementation which allows access to
* the XMLDecoder instance itself. This is used for the &lt;java&gt; tag.
*
* @author Robert Schuster
*/
public class DecoderContext extends AbstractContext
{
private XMLDecoder decoder;
public DecoderContext(XMLDecoder xmlDecoder)
{
decoder = xmlDecoder;
}
private ArrayList objects = new ArrayList();
/* (non-Javadoc)
* @see gnu.java.beans.decoder.Context#addObject(java.lang.Object)
*/
public void addParameterObject(Object o) throws AssemblyException
{
objects.add(o);
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.Context#reportStatement()
*/
public void notifyStatement(Context outerContext) throws AssemblyException
{
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.Context#endContext(gnu.java.beans.decoder.Context)
*/
public Object endContext(Context outerContext) throws AssemblyException
{
return decoder;
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.Context#subContextFailed()
*/
public boolean subContextFailed()
{
return false;
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.Context#set(int, java.lang.Object)
*/
public void set(int index, Object o) throws AssemblyException
{
throw new AssemblyException(new IllegalArgumentException("Set method is not allowed in decoder context."));
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.Context#get(int)
*/
public Object get(int index) throws AssemblyException
{
throw new AssemblyException(new IllegalArgumentException("Get method is not allowed in decoder context."));
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.Context#getResult()
*/
public Object getResult()
{
return decoder;
}
/** Returns an Iterator that retrieves the assembled objects.
*
* @return An Iterator retrieving assembled objects.
*/
public Iterator iterator()
{
return objects.iterator();
}
}
/* gnu.java.beans.DefaultExceptionListener
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.java.beans.decoder;
import java.beans.ExceptionListener;
/** The DefaultExceptionListener is the default implementation of the ExceptionListener
* interface. An instance of this class is used whenever the user provided no
* ExceptionListener instance on its own.
*
* <p>The implementation just writes the exception's message to <code>System.err</code>.</p>
*
* @author Robert Schuster
*/
public class DefaultExceptionListener implements ExceptionListener
{
public void exceptionThrown(Exception e)
{
System.err.println("non-critical exception: " + e + " - message: "
+ e.getMessage());
}
}
/* gnu.java.beans.decoder.DoubleHandler
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.java.beans.decoder;
/** Creates a Double instance from the character data in a &lt;double&gt; tag.
*
* @author Robert Schuster
*/
class DoubleHandler extends SimpleHandler
{
/**
* @param PersistenceParser
*/
DoubleHandler(ElementHandler parent)
{
super(parent);
}
protected Object parse(String number) throws NumberFormatException
{
return Double.valueOf(number);
}
}
/* gnu.java.beans.decoder.DummyContext
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.java.beans.decoder;
/** The DummyContext is used as the Context implementation for the DummyHandler. It
* just prevents having a null-reference.
*
* <p>When the implementation is correct none of this class' methods
* (except <code>notifyStatement()</code>) is called.</p>
*
* @author Robert Schuster
*/
public class DummyContext extends AbstractContext
{
/* (non-Javadoc)
* @see gnu.java.beans.decoder.Context#addObject(java.lang.Object)
*/
public void addParameterObject(Object o) throws AssemblyException
{
fail();
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.Context#reportStatement()
*/
public void notifyStatement(Context outerContext) throws AssemblyException
{
// intentionally ignored
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.Context#endContext(gnu.java.beans.decoder.Context)
*/
public Object endContext(Context outerContext) throws AssemblyException
{
fail();
return null;
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.Context#subContextFailed()
*/
public boolean subContextFailed()
{
fail();
return false;
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.Context#set(int, java.lang.Object)
*/
public void set(int index, Object o) throws AssemblyException
{
fail();
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.Context#get(int)
*/
public Object get(int index) throws AssemblyException
{
fail();
return null;
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.Context#getResult()
*/
public Object getResult()
{
fail();
return null;
}
private void fail()
{
throw new InternalError("Invoking the DummyContext is not expected"
+ " - Please file a bug report at"
+ " http://www/gnu.org/software/classpath/.");
}
}
/* gnu.java.beans.decoder.DummyHandler
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.java.beans.decoder;
import java.beans.ExceptionListener;
import org.xml.sax.Attributes;
/** An ElementHandler implementation that is used as an artificial root
* element. This avoids having to check for a null element.
*
* @author Robert Schuster
*/
class DummyHandler implements ElementHandler
{
/* (non-Javadoc)
* @see gnu.java.beans.decoder.ElementHandler#start(org.xml.sax.Attributes, java.beans.ExceptionListener)
*/
public void start(
Attributes attributes,
ExceptionListener exceptionListener)
{
fail();
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.ElementHandler#end(java.beans.ExceptionListener)
*/
public void end(ExceptionListener exceptionListener)
{
fail();
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.ElementHandler#characters(char[], int, int)
*/
public void characters(char[] ch, int start, int length)
{
fail();
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.ElementHandler#isSubelementAllowed(java.lang.String)
*/
public boolean isSubelementAllowed(String subElementName)
{
return true;
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.ElementHandler#instantiateClass(java.lang.String)
*/
public Class instantiateClass(String className)
throws ClassNotFoundException
{
fail();
return null;
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.ElementHandler#reportStatement(java.beans.ExceptionListener)
*/
public void notifyStatement(ExceptionListener exceptionListener)
{
// ignore
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.ElementHandler#hasFailed()
*/
public boolean hasFailed()
{
return false;
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.ElementHandler#getContext()
*/
public Context getContext()
{
return new DummyContext();
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.ElementHandler#contextFailed()
*/
public void notifyContextFailed()
{
fail();
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.ElementHandler#putObject(java.lang.String, java.lang.Object)
*/
public void putObject(String objectId, Object o)
{
fail();
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.ElementHandler#getObject(java.lang.String)
*/
public Object getObject(String objectId)
{
fail();
return null;
}
public ElementHandler getParent()
{
fail();
return null;
}
private void fail()
{
throw new InternalError("Invoking the DummyHandler is not expected"
+ " - Please file a bug report at "
+ " http://www.gnu.org/software/classpath/.");
}
}
/* gnu.java.beans.decoder.ElementHandler
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.java.beans.decoder;
import java.beans.ExceptionListener;
import org.xml.sax.Attributes;
/** ElementHandler manages a Context instance and interacts with
* its parent and child handlers.
*
* @author Robert Schuster
*/
interface ElementHandler
{
/** Evaluates the attributes and creates a Context instance.
* If the creation of the Context instance fails the ElementHandler
* is marked as failed which may affect the parent handler other.
*
* @param attributes Attributes of the XML tag.
*/
void start(Attributes attributes, ExceptionListener exceptionListener);
/** Post-processes the Context.
*/
void end(ExceptionListener exceptionListener);
/** Adds characters from the body of the XML tag to the buffer.
*
* @param ch
* @param start
* @param length
* @throws SAXException
*/
void characters(char[] ch, int start, int length);
/** Returns whether a subelement of the given name is allowed. The rules
* for evaluating this are derived from the javabeans.dtd which can be found
* here: <a href="http://java.sun.com/products/jfc/tsc/articles/persistence3">Java Persistence Article</a>.
*
* @param subElementName
* @return
*/
boolean isSubelementAllowed(String subElementName);
/** Provides the same functionality as Class.forName() but allows the decoder
* to use a different class loader.
*
* @param className
* @return
* @throws ClassNotFoundException
*/
Class instantiateClass(String className) throws ClassNotFoundException;
/** Notifies the handler's Context that its child Context will not return
* a value back. Some Context variants need this information to know when
* a method or a constructor call can be made.
*
* This method is called by a child handler.
*/
void notifyStatement(ExceptionListener exceptionListener);
/** Returns whether this handler has failed.
*
* This is used to skip child elements.
*
* @return Whether this handler has failed.
*/
boolean hasFailed();
/** Returns the Context instance this handler is working on.
*
* @return The handler's Context instance.
*/
Context getContext();
/** Notifies the handler that its Context failed and starts a recursive
* invocation of the parent handler if it is affected by that failure.
*
* Although the method is a public API member it is only used internally.
*/
void notifyContextFailed();
/** Stores the object under the given id. The object is not stored if the
* id is null.
*
* @param objectId
* @param o
*/
void putObject(String objectId, Object o);
Object getObject(String objectId) throws AssemblyException;
ElementHandler getParent();
}
/* gnu.java.beans.decoder.FloatHandler
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.java.beans.decoder;
/** Creates a Float instance from the character data in a &lt;float&gt; tag.
*
* @author Robert Schuster
*/
class FloatHandler extends SimpleHandler
{
/**
* @param PersistenceParser
*/
FloatHandler(ElementHandler parent)
{
super(parent);
}
protected Object parse(String number) throws NumberFormatException
{
return Float.valueOf(number);
}
}
/* gnu.java.beans.decoder.GrowableArrayContext
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.java.beans.decoder;
import java.lang.reflect.Array;
/** A Context implementation for a growable array. The array
* elements have to be set using expressions.
*
* @author Robert Schuster
*/
class GrowableArrayContext extends AbstractContext
{
private static final int INITIAL_SIZE = 16;
private Class klass;
private Object array;
private int length;
GrowableArrayContext(String id, Class newClass)
{
setId(id);
klass = newClass;
array = Array.newInstance(klass, INITIAL_SIZE);
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.Context#addObject(java.lang.Object)
*/
public void addParameterObject(Object o) throws AssemblyException
{
if (length == Array.getLength(array))
{
Object tmp = Array.newInstance(klass, length * 2);
System.arraycopy(array, 0, tmp, 0, length);
array = tmp;
}
try {
Array.set(array, length++, o);
} catch(IllegalArgumentException iae) {
throw new AssemblyException(iae);
}
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.Context#reportStatement()
*/
public void notifyStatement(Context outerContext) throws AssemblyException
{
throw new AssemblyException(
new IllegalArgumentException("Statements inside a growable array are not allowed."));
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.Context#endContext(gnu.java.beans.decoder.Context)
*/
public Object endContext(Context outerContext) throws AssemblyException
{
if (length != Array.getLength(array))
{
Object tmp = Array.newInstance(klass, length);
System.arraycopy(array, 0, tmp, 0, length);
array = tmp;
}
return array;
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.Context#subContextFailed()
*/
public boolean subContextFailed()
{
// returns false to indicate that assembling the array does not fail only because
// a subelement failed
return false;
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.Context#set(int, java.lang.Object)
*/
public void set(int index, Object o) throws AssemblyException
{
try {
Array.set(array, index, o);
} catch(IllegalArgumentException iae) {
throw new AssemblyException(iae);
}
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.Context#get(int)
*/
public Object get(int index) throws AssemblyException
{
return Array.get(array, index);
}
public Object getResult()
{
return array;
}
}
/* gnu.java.beans.decoder.IndexContext
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.java.beans.decoder;
/** IndexContext is Context implementation that senses whether it is an indexed get or set
* operation and invokes this operation.
*
* <p>An IndexContent is a get operation when no argument is provided and a set operation if one
* argument is provided.</p>
*
* @author Robert Schuster
*/
class IndexContext extends AbstractContext
{
private Object result;
private Object argument;
private int index;
private boolean isSetter;
IndexContext(String id, int newIndex)
{
setId(id);
index = newIndex;
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.Context#addObject(java.lang.Object)
*/
public void addParameterObject(Object o) throws AssemblyException
{
if (! isSetter)
{
argument = o;
isSetter = true;
}
else
throw new AssemblyException(new IllegalStateException("More than one argument for indiced access is not possible."));
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.Context#reportStatement()
*/
public void notifyStatement(Context outerContext) throws AssemblyException
{
throw new AssemblyException(new IllegalStateException("Statements inside indiced access are not allowed."));
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.Context#endContext(gnu.java.beans.decoder.Context)
*/
public Object endContext(Context outerContext) throws AssemblyException
{
if (isSetter)
{
// setter
outerContext.set(index, argument);
return null;
}
else
// getter
return result = outerContext.get(index);
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.Context#subContextFailed()
*/
public boolean subContextFailed()
{
// returns true to indicate that indiced access assembly fails when one of its
// argument could not be assembled
return true;
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.Context#set(int, java.lang.Object)
*/
public void set(int index, Object o) throws AssemblyException
{
throw new AssemblyException(new IllegalStateException("Setter is not allowed inside indiced access."));
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.Context#get(int)
*/
public Object get(int index) throws AssemblyException
{
throw new AssemblyException(new IllegalStateException("getter is not allowed insided indiced access."));
}
public Object getResult()
{
return result;
}
}
/* gnu.java.beans.decoder.IntHandler
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.java.beans.decoder;
/** Creates a Integer instance from the character data in a &lt;int&gt; tag.
*
* @author Robert Schuster
*/
class IntHandler extends SimpleHandler
{
/**
* @param PersistenceParser
*/
IntHandler(ElementHandler parent)
{
super(parent);
}
protected Object parse(String number) throws NumberFormatException
{
return Integer.valueOf(number);
}
}
/* gnu.java.beans.decoder.JavaHandler
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.java.beans.decoder;
import java.beans.ExceptionListener;
import java.util.HashMap;
import org.xml.sax.Attributes;
/** Wraps a DecoderContext instance.
*
* @author Robert Schuster
*/
public class JavaHandler extends AbstractElementHandler
{
private Context context;
private HashMap objectMap = new HashMap();
private ClassLoader classLoader;
/**
* @param PersistenceParser
*/
JavaHandler(DummyHandler parent, Context decoderContext,
ClassLoader cl)
{
super(parent, true);
classLoader = cl;
context = decoderContext;
}
protected Context startElement(Attributes attributes, ExceptionListener exceptionListener)
throws AssemblyException
{
// may expect version and class attribute but it not used in JDK
// so we do either
return context;
}
public Object getObject(String objectId)
{
return objectMap.get(objectId);
}
public void putObject(String objectId, Object o)
{
if (objectId != null)
objectMap.put(objectId, o);
}
public Class instantiateClass(String className)
throws ClassNotFoundException
{
return Class.forName(className, false, classLoader);
}
}
/* gnu.java.beans.decoder.LongHandler
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.java.beans.decoder;
/** Creates a Long instance from the character data in a &lt;long&gt; tag.
*
* @author Robert Schuster
*/
class LongHandler extends SimpleHandler
{
/**
* @param PersistenceParser
*/
LongHandler(ElementHandler parent)
{
super(parent);
}
protected Object parse(String number) throws NumberFormatException
{
return Long.valueOf(number);
}
}
/* gnu.java.beans.decoder.MethodContext
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.java.beans.decoder;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
/** MethodContext collects arguments for a method call and creates the result object
* using it. The method is called using the result object of the parent Context.
*
* <p>When the result object is available methods can be called on it using sub-Contexts.</p>
*
* @author Robert Schuster
*/
class MethodContext extends AbstractCreatableObjectContext
{
private ArrayList arguments = new ArrayList();
private String methodName;
MethodContext(String id, String newMethodName)
{
setId(id);
setStatement(true);
methodName = newMethodName;
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.Context#addObject(java.lang.Object)
*/
public void addParameterObjectImpl(Object o)
{
arguments.add(o);
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.Context#endContext(gnu.java.beans.decoder.Context)
*/
protected Object createObject(Context outerContext)
throws AssemblyException
{
Object outerObject = outerContext.getResult();
if (outerObject == null)
throw new AssemblyException(
new NullPointerException(
"No object to invoke method " + methodName));
Object[] args = arguments.toArray();
try
{
Method method =
MethodFinder.getMethod(
outerObject.getClass(),
methodName,
args);
return method.invoke(outerObject, args);
}
catch (NoSuchMethodException nsme)
{
throw new AssemblyException(nsme);
}
catch (InvocationTargetException ite)
{
throw new AssemblyException(ite.getCause());
}
catch (IllegalAccessException iae)
{
throw new AssemblyException(iae);
}
}
}
/* gnu.java.beans.decoder.MethodFinder
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.java.beans.decoder;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.HashMap;
class MethodFinder
{
/** Provides a mapping between a wrapper class and its corresponding primitive's type. */
private static HashMap typeMapping = new HashMap();
static {
typeMapping.put(Byte.class, Byte.TYPE);
typeMapping.put(Short.class, Short.TYPE);
typeMapping.put(Integer.class, Integer.TYPE);
typeMapping.put(Long.class, Long.TYPE);
typeMapping.put(Float.class, Float.TYPE);
typeMapping.put(Double.class, Double.TYPE);
typeMapping.put(Character.class, Character.TYPE);
typeMapping.put(Boolean.class, Boolean.TYPE);
}
private MethodFinder()
{
}
/** Searches a Method which can accept the given arguments.
*
* @param klass
* @param name
* @param arguments
* @return
* @throws NoSuchMethodException
*/
static Method getMethod(Class klass, String name, Object[] arguments)
throws NoSuchMethodException
{
// prepares array containing the types of the arguments
Class[] argumentTypes = getArgumentTypes(arguments);
Method[] methods = klass.getMethods();
// iterates over all public methods
for (int i = 0; i < methods.length; i++)
{
if (methods[i].getName().equals(name))
{
if (matchingArgumentTypes(methods[i].getParameterTypes(),
argumentTypes))
return methods[i];
}
}
throw new NoSuchMethodException(
"Could not find a matching method named "
+ name
+ "() in class "
+ klass);
}
static Constructor getConstructor(Class klass, Object[] arguments)
throws NoSuchMethodException
{
Class[] argumentTypes = getArgumentTypes(arguments);
Constructor[] constructors = klass.getConstructors();
// iterates over all public methods
for (int i = 0; i < constructors.length; i++)
{
if (matchingArgumentTypes(constructors[i].getParameterTypes(),
argumentTypes))
return constructors[i];
}
throw new NoSuchMethodException(
"Could not find a matching constructor in class " + klass);
}
/** Transforms an array of argument objects into an array of argument types.
* For each argument being null the argument is null, too. An argument type
* being null means: Accepts everything (although this can be ambigous).
*
* @param arguments
* @return
*/
private static Class[] getArgumentTypes(Object[] arguments)
{
if (arguments == null)
return new Class[0];
// prepares array containing the types of the arguments
Class[] argumentTypes = new Class[arguments.length];
for (int i = 0; i < arguments.length; i++)
argumentTypes[i] =
(arguments[i] == null) ? null : arguments[i].getClass();
return argumentTypes;
}
/** Tests whether the argument types supplied to the method argument types
* are assignable. In addition to the assignment specifications this method
* handles the primitive's wrapper classes as if they were of their
* primitive type (e.g Boolean.class equals Boolean.TYPE).
* When a supplied argument type is null it is assumed that no argument
* object was supplied for it and the test for this particular parameter will
* pass.
*
* @param methodArgTypes
* @param suppliedArgTypes
* @return
*/
private static boolean matchingArgumentTypes(
Class[] methodArgTypes,
Class[] suppliedArgTypes)
{
if (methodArgTypes.length != suppliedArgTypes.length)
return false;
for (int i = 0; i < methodArgTypes.length; i++)
{
if (suppliedArgTypes[i] == null)
{
// by definition a non-existant argument type (null) can be converted to everything
continue;
}
else if (typeMapping.containsKey(suppliedArgTypes[i]))
{
Class primitiveType =
(Class) typeMapping.get(suppliedArgTypes[i]);
if (!(methodArgTypes[i].isAssignableFrom(suppliedArgTypes[i])
|| methodArgTypes[i].isAssignableFrom(primitiveType)))
return false;
}
else if (!methodArgTypes[i].isAssignableFrom(suppliedArgTypes[i]))
return false;
}
return true;
}
}
/* gnu.java.beans.decoder.NullHandler
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.java.beans.decoder;
/** Just provides the 'null' object.
*
* @author Robert Schuster
*/
class NullHandler extends SimpleHandler
{
/**
* @param PersistenceParser
*/
NullHandler(ElementHandler parent)
{
super(parent);
}
protected Object parse(String characters) throws AssemblyException
{
if (! characters.equals(""))
throw new AssemblyException(new IllegalArgumentException("No characters inside <void> tag allowed."));
return null;
}
}
/* gnu.java.beans.decoder.ObjectHandler
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.java.beans.decoder;
/** ObjectContext is a {@link Context} implementation that wraps a simple Object instance.
* The instance can be provided when the Context is created (due to an 'idref'
* attribute) or later (eg. &lt;int&gt; tag)
*
* <p>The ObjectContext does not accept any parameter object and ignores notifications
* about sub-contexts being statements.</p>
*
* @author Robert Schuster
*/
final class ObjectContext extends AbstractObjectContext
{
ObjectContext(Object newObject)
{
setObject(newObject);
}
ObjectContext(String id, Object newObject)
{
setId(id);
setObject(newObject);
}
ObjectContext()
{
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.Context#addObject(java.lang.Object)
*/
public void addParameterObject(Object o) throws AssemblyException
{
throw new AssemblyException(new IllegalArgumentException("Adding objects to an ObjectContext is not allowed."));
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.Context#reportStatement()
*/
public void notifyStatement(Context outerContext) throws AssemblyException
{
// can ignore that
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.Context#endContext(gnu.java.beans.decoder.Context)
*/
public Object endContext(Context outerContext) throws AssemblyException
{
// just returns the object which is encapsuled (may be null)
return getResult();
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.Context#subContextFailed()
*/
public boolean subContextFailed()
{
// this context will not fail when a subcontext fails because the result is
// already available when the context is created.
return false;
}
}
/* gnu.java.beans.decoder.ObjectHandler
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.java.beans.decoder;
import java.beans.ExceptionListener;
import org.xml.sax.Attributes;
/** An ObjectHandler parses the &lt;object&gt; tag and thereby creates various
* Context implementations.
*
* @author Robert Schuster
*
*/
public class ObjectHandler extends AbstractElementHandler
{
/**
* XXX: Can all results be stored with an object id?
*
*
* @param PersistenceParser
*/
ObjectHandler(ElementHandler parent)
{
super(parent, true);
}
protected Context startElement(Attributes attributes, ExceptionListener exceptionListener)
throws AssemblyException
{
String className = attributes.getValue("class");
String methodName = attributes.getValue("method");
String fieldName = attributes.getValue("field");
String index = attributes.getValue("index");
String propertyName = attributes.getValue("property");
String id = attributes.getValue("id");
String idRef = attributes.getValue("idref");
/* first check if we just want to access an existing object (idref present)
*
* note: <object idref="foo" method="bar"/> is not valid to call method "bar"
* on the object with id "foo". Instead this should return the object "foo"
* itself. The right way to this is:
* <object idref="foo">
* <object method="bar"/>
* </object>
*
* This means that if idref is present class, method, field, index and
* property are obsolete.
*/
if (idRef != null)
// reactivates an existing object and giving it another name if id exists
return new ObjectContext(id, getObject(idRef));
// decides whether we are in a static (className present) or dynamic context
if (className != null)
{
try
{
Class klass = instantiateClass(className);
// class name exists which means that we are in a static context.
// so we may want to ...
// access a static field if the fieldName exists
if (fieldName != null)
{
try
{
return new ObjectContext(id,
klass.getField(fieldName).get(null));
}
catch (NoSuchFieldException nsfe)
{
throw new AssemblyException(nsfe);
}
catch (IllegalAccessException iae)
{
throw new AssemblyException(iae);
}
}
// (falling through is important!)
// run a constructor if methodName is "new" or null
if (methodName == null || methodName.equals("new"))
return new ConstructorContext(id, klass);
// (falling through is important!)
// run a static method on the given class (if methodName exists, which is implied already)
return new StaticMethodContext(id, klass, methodName);
// XXX: should fail if unexpected attributes are present?
}
catch (ClassNotFoundException cnfe)
{
throw new AssemblyException(cnfe);
}
}
else
{
// className does not exist which means we are in the context of
// some object and want to ...
// access the get(int index) method if index != null
if (index != null)
{
try
{
// Note: http://java.sun.com/products/jfc/tsc/articles/persistence3/ says
// that <void index="4"/> will make up a get()-call. But this is wrong because
// <void/> tags never return values (to the surrounding context)
return new IndexContext(id, Integer.parseInt(index));
}
catch (NumberFormatException nfe)
{
throw new AssemblyException(nfe);
}
}
// access a method if methodName exists
if (methodName != null)
return new MethodContext(id, methodName);
// (falling through is important!)
// access a property if a propertyName exists
if (propertyName != null && propertyName.length() > 0)
// this is reported as an ordinary method access where the propertyName is
// converted into a 'getter'-method name: convert first character of property name
// to upper case and prepend 'get'
// Note: This will be a getter-method because the <object> tag implies that a return
// value is expected.
return new PropertyContext(id, propertyName);
}
throw new AssemblyException(new IllegalArgumentException("Wrong or missing attributes for <object> tag."));
}
}
/* gnu.java.beans.decoder.PropertyContext
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.java.beans.decoder;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
/** PropertyContext is a Context implementation that is very similar to MethodContext
* and IndexContext. The sole purpose of PropertyContext to find out whether it should
* 'set' or 'get' a certain property. This decision is made using the number of
* arguments.
* <p>When the method call has to be made and there is no argument we 'get' the property.
* With one argument it is 'set'.</p>
*
* @author Robert Schuster
*/
class PropertyContext extends AbstractObjectContext
{
private Object argument;
private String propertyName;
private String prefix = "get";
private boolean methodCalled;
PropertyContext(String id, String newPropertyName)
{
setId(id);
propertyName = newPropertyName;
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.Context#addObject(java.lang.Object)
*/
public void addParameterObject(Object o) throws AssemblyException
{
if (methodCalled)
throw new AssemblyException(new IllegalArgumentException("Cannot add parameter object when method was already called."));
if (argument != null)
throw new AssemblyException(new IllegalArgumentException("Property attribut allows zero or one argument only."));
argument = o;
setStatement(true);
prefix = "set";
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.Context#endContext(gnu.java.beans.decoder.Context)
*/
public void notifyStatement(Context outerContext) throws AssemblyException
{
if (methodCalled)
return;
methodCalled = true;
Object outerObject = outerContext.getResult();
if (outerObject == null)
throw new AssemblyException(new NullPointerException("No object to access property "
+ propertyName));
// converts property name into a method name
String methodName = prefix + propertyName.substring(0, 1).toUpperCase()
+ propertyName.substring(1);
// prepares the argument
Object[] args = (argument != null) ? new Object[] { argument } : null;
try
{
Method method = MethodFinder.getMethod(outerObject.getClass(),
methodName, args);
// stores the result whether it is available or not
setObject(method.invoke(outerObject, args));
}
catch (NoSuchMethodException nsme)
{
throw new AssemblyException(nsme);
}
catch (InvocationTargetException ite)
{
throw new AssemblyException(ite.getCause());
}
catch (IllegalAccessException iae)
{
throw new AssemblyException(iae);
}
}
public Object endContext(Context outerContext) throws AssemblyException
{
notifyStatement(outerContext);
return getResult();
}
public boolean subContextFailed()
{
return ! methodCalled;
}
}
/* gnu.java.beans.decoder.ShortHandler
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.java.beans.decoder;
/** Creates a Short instance from the character data in a &lt;short&gt; tag.
*
* @author Robert Schuster
*/
class ShortHandler extends SimpleHandler
{
/**
* @param PersistenceParser
*/
ShortHandler(ElementHandler parent)
{
super(parent);
}
protected Object parse(String number) throws NumberFormatException
{
return Short.valueOf(number);
}
}
/* gnu.java.beans.decoder.SimpleHandler
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.java.beans.decoder;
import java.beans.ExceptionListener;
import org.xml.sax.Attributes;
/** XML element handler that is specialized on tags that contains a simple string in their
* body which has to be parsed in a specific way.
* <p>All of these tags have in common that they do not accept attributes. A warning is
* send to the parser's ExceptionListener when one or more attributes exist.</p>
*
* @author Robert Schuster
*/
abstract class SimpleHandler extends AbstractElementHandler
{
private ObjectContext context;
/**
* @param PersistenceParser
*/
SimpleHandler(ElementHandler parent)
{
super(parent, false);
// SimpleHandler do not accept any subelements
}
protected final Context startElement(Attributes attributes, ExceptionListener exceptionListener)
throws AssemblyException
{
// note: simple elements should not have any attributes. We inform
// the user of this syntactical but uncritical problem by sending
// an IllegalArgumentException for each unneccessary attribute
int size = attributes.getLength();
for (int i = 0; i < size; i++) {
String attributeName = attributes.getQName(i);
Exception e =
new IllegalArgumentException(
"Unneccessary attribute '"
+ attributeName
+ "' discarded.");
exceptionListener.exceptionThrown(e);
}
return context = new ObjectContext();
}
public void endElement(String characters)
throws AssemblyException, AssemblyException
{
// reports the number when the character data can be parsed
try
{
context.setObject(parse(characters));
}
catch (NumberFormatException nfe)
{
throw new AssemblyException(nfe);
}
}
/** Returns an object that is created from the given characters. If the string is
* converted into a number a NumberFormatException is cathed and reported
* appropriately.
*
* @param characters A string of characters that has to be processed in some way.
* @return An Object instance generated from the given data.
* @throws AssemblerException When the string was invalid.
* @throws NumberFormatException When the string could not be parsed into a number.
*/
protected abstract Object parse(String characters)
throws AssemblyException, NumberFormatException;
}
/* gnu.java.beans.decoder.StaticMethodContext
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.java.beans.decoder;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
/**
* @author Robert Schuster
*/
class StaticMethodContext extends AbstractCreatableObjectContext
{
private ArrayList arguments = new ArrayList();
private Class klass;
private String methodName;
StaticMethodContext(String id, Class newClass, String newMethodName)
{
setId(id);
klass = newClass;
methodName = newMethodName;
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.Context#addObject(java.lang.Object)
*/
public void addParameterObjectImpl(Object o)
{
arguments.add(o);
}
/* (non-Javadoc)
* @see gnu.java.beans.decoder.Context#endContext(gnu.java.beans.decoder.Context)
*/
protected Object createObject(Context outerContext)
throws AssemblyException
{
Object[] args = arguments.toArray();
try
{
Method method = MethodFinder.getMethod(klass, methodName, args);
return method.invoke(null, args);
}
catch (NoSuchMethodException nsme)
{
throw new AssemblyException(nsme);
}
catch (InvocationTargetException ite)
{
// rethrows the reason for the InvocationTargetsException (ie. the exception in the called code)
throw new AssemblyException(ite.getCause());
}
catch (IllegalAccessException iae)
{
throw new AssemblyException(iae);
}
}
}
/* gnu.java.beans.EmptyBeanInfo
Copyright (C) 1998 Free Software Foundation, Inc.
/* gnu.java.beans.decoder.StringHandler
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
......@@ -35,36 +35,20 @@ this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.java.beans;
import java.beans.*;
/**
** EmptyBeanInfo is a BeanInfo that discloses no
** information about the Bean and does not allow
** Introspection. The Introspector uses instances of this
** class to create empty BeanInfos, but it could also be
** used as a base class for BeanInfos that do not allow
** Introspection and provide only a little bit of
** information.<P>
**
** @author John Keiser
** @version 1.1.0, 30 Jul 1998
** @see gnu.java.beans.ExplicitBeanInfo
** @see java.beans.BeanInfo
**/
public class EmptyBeanInfo extends ExplicitBeanInfo {
/** Create a new EmptyBeanInfo. **/
public EmptyBeanInfo(Class beanClass) {
super(new BeanDescriptor(beanClass,null),
new BeanInfo[0],
new PropertyDescriptor[0],
-1,
new EventSetDescriptor[0],
-1,
new MethodDescriptor[0],
null);
}
package gnu.java.beans.decoder;
class StringHandler extends SimpleHandler
{
/**
* @param PersistenceParser
*/
StringHandler(ElementHandler parent)
{
super(parent);
}
protected Object parse(String characters)
{
return characters;
}
}
/* gnu.java.beans.decoder.VoidHandler
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.java.beans.decoder;
import java.beans.ExceptionListener;
import org.xml.sax.Attributes;
public class VoidHandler extends AbstractElementHandler
{
/**
* @param PersistenceParser
*/
VoidHandler(ElementHandler parent)
{
super(parent, true);
}
protected Context startElement(
Attributes attributes,
ExceptionListener exceptionListener)
throws AssemblyException
{
Context ctx = startElementImpl(attributes);
ctx.setStatement(true);
return ctx;
}
private Context startElementImpl(Attributes attributes)
throws AssemblyException
{
String id = attributes.getValue("id");
String className = attributes.getValue("class");
String methodName = attributes.getValue("method");
String propertyName = attributes.getValue("property");
String index = attributes.getValue("index");
if (className != null)
{
try
{
Class klass = instantiateClass(className);
// class name exists which means that we are in a static context.
// so we may want to ...
// run a constructor if methodName is "new" or null
if (methodName == null || methodName.equals("new"))
// if the id is null the result cannot be by the decoder accessed but the
// constructor may have side effects (e.g. registering itself in a global registry)
return new ConstructorContext(id, klass);
// (falling through is important!)
// run a static method on the given class (if methodName exists, which is implied already)
return new StaticMethodContext(id, klass, methodName);
}
catch (ClassNotFoundException cnfe)
{
throw new AssemblyException(cnfe);
}
}
else
{
// className does not exist which means we are in the context of
// some object and want to ...
// access an element by index
if (index != null)
{
// note: whether this resolves into get(i) or set(i, o) depends on the
// number of arguments and is decided by the ObjectAssembler
try
{
return new IndexContext(id, Integer.parseInt(index));
}
catch (NumberFormatException nfe)
{
throw new AssemblyException(nfe);
}
}
// access a method if methodName exists
if (methodName != null)
return new MethodContext(id, methodName);
// (falling through is important!)
// access a property if a propertyName exists
if (propertyName != null && propertyName.length() > 0)
// this is reported as an ordinary method invocation where the propertyName is
// converted into a 'setter'-method name: convert first character of property name
// to upper case and prepend 'set'
// Note: This will be a setter-method because the <void> tag implies that no return
// value is expected (but a side effect)
return new PropertyContext(id, propertyName);
}
// if code reaches this point the tag has wrong attributes. The following test
// does not make it better but can provide are more specific error message for
// a common mistake: <void> tags are not allowed to have an idref attribute
throw new AssemblyException(
new IllegalArgumentException(
(attributes.getValue("idref") == null)
? "Missing attributes for <void> tag"
: "<void> does not support 'idref' attribute."));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment