Package org.exolab.castor.core.exceptions

Examples of org.exolab.castor.core.exceptions.CastorIllegalStateException


                if (i > 0) err += ", ";
                err += argTypes[i].getName();
            }
            throw new InstantiationException(err);
        } catch(InvocationTargetException ite) {
            throw new CastorIllegalStateException(
                    ite.getMessage(), ite.getTargetException());
        }
    }
View Full Code Here


                }
            } else {
                value = null;
            }
        } catch (IllegalAccessException except) {
            throw new CastorIllegalStateException(
                    Messages.format("mapping.schemaChangeNoAccess", toString()),
                    except);
        } catch (InvocationTargetException except) {
            throw new CastorIllegalStateException(
                    Messages.format("mapping.schemaChangeInvocation", toString(), except),
                    except);
        }

        //-- If a collection, return an enumeration of it's values.
View Full Code Here

                throw new IllegalArgumentException(errorMessage, except);
            } catch (IllegalAccessException except) {
                // This should never happen
                String errorMessage =
                    Messages.format("mapping.schemaChangeNoAccess", toString());
                throw new CastorIllegalStateException(errorMessage, except);
            } catch (InvocationTargetException except) {
                // This should never happen
                throw new MappingRuntimeException(except.getTargetException());
            }
        } else if ( value != null ) {
            Object collect;
            try {
                // Get the field value (the collection), add the value to it,
                // possibly yielding a new collection (in the case of an array),
                // and set that collection back into the field.
                if ( _handler != null ) {
                    collect = _handler.getValue( object );
                    collect = _colHandler.add( collect, value );
                    if ( collect != null )
                        _handler.setValue( object, collect );
                } else if ( _field != null ) {
                    collect = _field.get( object );
                    if (collect == null) {
                        // The type of the collection.
                        Class type = _field.getType();
                        //-- Handle Arrays, we need to declare the array with
                        //-- the correct type. The other cases are handled in 
                        //-- the J1CollectionHandler during the
                        //-- add(collect,value) call
                        if (type.isArray()) {
                            Class componentType = type.getComponentType();
                            Class valueType = value.getClass();
                            if (componentType.isPrimitive() ||
                               ((!valueType.isArray()) && (valueType != componentType)))
                            {
                                try {
                                    collect = Array.newInstance(componentType, 0);
                                }
                                catch (Exception e) {
                                    String err = "Unable to instantiate an array of '" +
                                        componentType + "' : " + e;
                                    throw new CastorIllegalStateException(err, e);
                                }
                            }
                        }
                    }
                    collect = _colHandler.add( collect, value );
                    if ( collect != null )
                        _field.set( object, collect );
                       
                }
                else if ( _getMethod != null ) {
                    if ( _getSequence != null )
                        for ( int i = 0; i < _getSequence.length; i++ )
                            object = _getSequence[ i ].invoke( object, (Object[]) null );
                    collect = _getMethod.invoke( object, (Object[]) null );

                    // If we deal with a collection who is an array of primitive
                    // and that has not been instantiated, we have to handle the
                    // instantiation here rather than in J1CollectionHandler,
                    // because we have acces to the Field object here.
                    boolean setCollection = false;
                    if (collect == null) {
                        // The return type of the get method should be the type of the collection.
                        Class type = _getMethod.getReturnType();
                       
                        //-- Handle Arrays, we need to declare the array with
                        //-- the correct type. The other cases are handled in 
                        //-- the J1CollectionHandler during the
                        //-- add(collect,value) call
                        if (type.isArray()) {
                            Class componentType = type.getComponentType();
                            Class valueType = value.getClass();
                            if (componentType.isPrimitive() ||
                               ((!valueType.isArray()) && (valueType != componentType)))
                            {
                                try {
                                    collect = Array.newInstance(componentType, 0);
                                }
                                catch (Exception e) {
                                    String err = "Unable to instantiate an array of '" +
                                        componentType + "' : " + e;
                                    throw new CastorIllegalStateException(err, e);
                                }
                            }
                        }
                        setCollection = true;
                    }
View Full Code Here

                LOG.warn("Problem closing JDBC statement", except2);
            }
           
            throw new PersistenceException(Messages.format("persist.nested", except), except);
        } catch (NoSuchMethodException ex) {
            throw new CastorIllegalStateException(ex);
        } catch (NoSuchFieldException ex) {
            throw new CastorIllegalStateException(ex);
        } catch (IllegalAccessException ex) {
            throw new CastorIllegalStateException(ex);
        } catch (InvocationTargetException ex) {
            throw new CastorIllegalStateException(ex);
        }
    }
View Full Code Here

TOP

Related Classes of org.exolab.castor.core.exceptions.CastorIllegalStateException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.