Package org.exolab.castor.mapping

Examples of org.exolab.castor.mapping.MappingRuntimeException


                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;
                    }
                    else {
                        setCollection = collect.getClass().isArray();
                    }

                    Object tmp = _colHandler.add(collect, value);
                   
                    //-- make sure we do not overwrite collect unless
                    //-- the new collection is not null
                    if (tmp != null) collect = tmp;

                    if ( setCollection && (_setMethod != null))
                        _setMethod.invoke( object, new Object[] { collect } );
                }               
            } catch ( IllegalAccessException except ) {
                // This should never happen
                throw new IllegalStateException( Messages.format( "mapping.schemaChangeNoAccess", toString() ) );
            } catch ( InvocationTargetException except ) {
                // This should never happen
                throw new MappingRuntimeException(except.getTargetException());
            }
        }
    }
View Full Code Here


            } catch ( IllegalAccessException except ) {
                // This should never happen
                throw new IllegalStateException( Messages.format( "mapping.schemaChangeNoAccess", toString() ) );
            } catch ( InvocationTargetException except ) {
                // This should never happen
                throw new MappingRuntimeException(except.getTargetException());
            }

        } else {
            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 ) {
                    _handler.resetValue( object );
                } else if ( _field != null ) {
                    collect = _field.get( object );
                    collect = _colHandler.clear( collect );
                    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 );
                    collect = _colHandler.clear( collect );
                    if ( collect != null && _setMethod != null)
                        _setMethod.invoke( object, new Object[] { collect } );
                }               
            } catch ( IllegalAccessException except ) {
                // This should never happen
                throw new IllegalStateException( Messages.format( "mapping.schemaChangeNoAccess", toString() ) );
            } catch ( InvocationTargetException except ) {
                // This should never happen
                throw new MappingRuntimeException(except.getTargetException());
            }

        }
    }
View Full Code Here

            } catch ( IllegalAccessException except ) {
                // This should never happen
                throw new IllegalStateException( Messages.format( "mapping.schemaChangeNoAccess", toString() ) );
            } catch ( InvocationTargetException except ) {
                // This should never happen
                throw new MappingRuntimeException(except.getTargetException());
            }
        }
        return Types.newInstance( _fieldType, args );
    } //-- newInstance
View Full Code Here

            } catch ( IllegalAccessException except ) {
                // This should never happen
                throw new IllegalStateException( Messages.format( "mapping.schemaChangeNoAccess", toString() ) );
            } 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 IllegalStateException(err);
                                }
                            }
                        }
                    }
                    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, null );
                    collect = _getMethod.invoke( 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 IllegalStateException(err);
                                }
                            }
                        }
                        setCollection = true;
                    }
                    else {
                        setCollection = collect.getClass().isArray();
                    }

                    Object tmp = _colHandler.add(collect, value);
                   
                    //-- make sure we do not overwrite collect unless
                    //-- the new collection is not null
                    if (tmp != null) collect = tmp;

                    if ( setCollection && (_setMethod != null))
                        _setMethod.invoke( object, new Object[] { collect } );
                }               
            } catch ( IllegalAccessException except ) {
                // This should never happen
                throw new IllegalStateException( Messages.format( "mapping.schemaChangeNoAccess", toString() ) );
            } catch ( InvocationTargetException except ) {
                // This should never happen
                throw new MappingRuntimeException(except.getTargetException());
            }

        }
    }
View Full Code Here

            } catch ( IllegalAccessException except ) {
                // This should never happen
                throw new IllegalStateException( Messages.format( "mapping.schemaChangeNoAccess", toString() ) );
            } catch ( InvocationTargetException except ) {
                // This should never happen
                throw new MappingRuntimeException(except.getTargetException());
            }

        } else {
            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 ) {
                    _handler.resetValue( object );
                } else if ( _field != null ) {
                    collect = _field.get( object );
                    collect = _colHandler.clear( collect );
                    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, null );
                    collect = _getMethod.invoke( object, null );
                    collect = _colHandler.clear( collect );
                    if ( collect != null && _setMethod != null)
                        _setMethod.invoke( object, new Object[] { collect } );
                }               
            } catch ( IllegalAccessException except ) {
                // This should never happen
                throw new IllegalStateException( Messages.format( "mapping.schemaChangeNoAccess", toString() ) );
            } catch ( InvocationTargetException except ) {
                // This should never happen
                throw new MappingRuntimeException(except.getTargetException());
            }

        }
    }
View Full Code Here

            } catch ( IllegalAccessException except ) {
                // This should never happen
                throw new IllegalStateException( Messages.format( "mapping.schemaChangeNoAccess", toString() ) );
            } catch ( InvocationTargetException except ) {
                // This should never happen
                throw new MappingRuntimeException(except.getTargetException());
            }
        }
        return Types.newInstance( _fieldType, args );
    } //-- newInstance
View Full Code Here

            } catch ( IllegalAccessException except ) {
                // This should never happen
                throw new IllegalStateException( Messages.format( "mapping.schemaChangeNoAccess", toString() ) );
            } 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 IllegalStateException(err);
                                }
                            }
                        }
                    }
                    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, null );
                    collect = _getMethod.invoke( 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 IllegalStateException(err);
                                }
                            }
                        }
                        setCollection = true;
                    }
                    else {
                        setCollection = collect.getClass().isArray();
                    }

                    Object tmp = _colHandler.add(collect, value);
                   
                    //-- make sure we do not overwrite collect unless
                    //-- the new collection is not null
                    if (tmp != null) collect = tmp;

                    if ( setCollection && (_setMethod != null))
                        _setMethod.invoke( object, new Object[] { collect } );
                }               
            } catch ( IllegalAccessException except ) {
                // This should never happen
                throw new IllegalStateException( Messages.format( "mapping.schemaChangeNoAccess", toString() ) );
            } catch ( InvocationTargetException except ) {
                // This should never happen
                throw new MappingRuntimeException(except.getTargetException());
            }

        }
    }
View Full Code Here

            } catch ( IllegalAccessException except ) {
                // This should never happen
                throw new IllegalStateException( Messages.format( "mapping.schemaChangeNoAccess", toString() ) );
            } catch ( InvocationTargetException except ) {
                // This should never happen
                throw new MappingRuntimeException(except.getTargetException());
            }

        } else {
            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 ) {
                    _handler.resetValue( object );
                } else if ( _field != null ) {
                    collect = _field.get( object );
                    collect = _colHandler.clear( collect );
                    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, null );
                    collect = _getMethod.invoke( object, null );
                    collect = _colHandler.clear( collect );
                    if ( collect != null && _setMethod != null)
                        _setMethod.invoke( object, new Object[] { collect } );
                }               
            } catch ( IllegalAccessException except ) {
                // This should never happen
                throw new IllegalStateException( Messages.format( "mapping.schemaChangeNoAccess", toString() ) );
            } catch ( InvocationTargetException except ) {
                // This should never happen
                throw new MappingRuntimeException(except.getTargetException());
            }

        }
    }
View Full Code Here

            } catch ( IllegalAccessException except ) {
                // This should never happen
                throw new IllegalStateException( Messages.format( "mapping.schemaChangeNoAccess", toString() ) );
            } catch ( InvocationTargetException except ) {
                // This should never happen
                throw new MappingRuntimeException(except.getTargetException());
            }
        }
        return Types.newInstance( _fieldType, args );
    } //-- newInstance
View Full Code Here

TOP

Related Classes of org.exolab.castor.mapping.MappingRuntimeException

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.