Package org.exolab.castor.mapping

Examples of org.exolab.castor.mapping.MappingException


                }
            }
        } catch (MappingException ex) {
            throw ex;
        } catch (Exception ex) {
            throw new MappingException(ex);
        }
    }
View Full Code Here


        }
       
        if (factory == null) {
            String msg = Messages.format("jdo.noSuchEngine", engine);
            LOG.error(msg);
            throw new MappingException(msg);
        }
       
        MappingUnmarshaller mappingUnmarshaller = new MappingUnmarshaller();
        if (_classDescriptorResolver == null) {
            _classDescriptorResolver = (JDOClassDescriptorResolver)
View Full Code Here

        DatabaseChoice choice = jdoConf.getDatabase(index).getDatabaseChoice();
        if (choice == null) {
            String name = jdoConf.getDatabase(index).getName();
            String msg = Messages.format("jdo.missingDataSource", name);
            LOG.error(msg);
            throw new MappingException(msg);
        }
       
        if (choice.getDriver() != null) {
            // JDO configuration file specifies a driver, use the driver
            // properties to create a new registry object.
            factory = new DriverConnectionFactory(jdoConf, index, mapping);
        } else if (choice.getDataSource() != null) {
            // JDO configuration file specifies a DataSource object, use the
            // DataSource which was configured from the JDO configuration file
            // to create a new registry object.
            factory = new DataSourceConnectionFactory(jdoConf, index, mapping);
        } else if (choice.getJndi() != null) {
            // JDO configuration file specifies a DataSource lookup through JNDI,
            // locate the DataSource object frome the JNDI namespace and use it.
            factory = new JNDIConnectionFactory(jdoConf, index, mapping);
        } else {
            String name = jdoConf.getDatabase(index).getName();
            String msg = Messages.format("jdo.missingDataSource", name);
            LOG.error(msg);
            throw new MappingException(msg);
        }
       
        return factory;
    }
View Full Code Here

        factory = (AbstractConnectionFactory) FACTORIES.get(name);
       
        if (factory == null) {
            String msg = Messages.format("jdo.missingDataSource", name);
            LOG.error(msg);
            throw new MappingException(msg);
        }
       
        factory.initialize();
        return factory;
    }
View Full Code Here

        } else if (demarcation.getTransactionManager() != null) {
            return demarcation.getTransactionManager().getName();
        } else {
            String msg = "Missing configuration of TransactionManager.";
            LOG.error(msg);
            throw new MappingException(msg);
        }
    }
View Full Code Here

            if (sqlTypeNum == TYPEINFO[i]._sqlTypeNum) {
                return TYPEINFO[i]._javaType;
            }
        }
       
        throw new MappingException("jdo.sqlTypeNotSupported", new Integer(sqlTypeNum));
    }
View Full Code Here

            if (sqlTypeName.equals(TYPEINFO[i]._sqlTypeName)) {
                return TYPEINFO[i]._javaType;
            }
        }
       
        throw new MappingException("jdo.sqlTypeNotSupported", sqlTypeName);
    }
View Full Code Here

        for (Field field : type.getDeclaredFields()) {
            if (field.getAnnotations().length != 0) {
                if (isDescribeable(type, field)) {
                    buildFieldInfo(classInfo, field);
                } else {
                    throw new MappingException(
                            "Invalid field annotated, field is not describeable!");
                }
            }
        }

        /*
         * process annotations for all declared (not inherited) getter methods
         */

        for (Method method : type.getDeclaredMethods()) {
            if (isGetter(method) && method.getAnnotations().length != 0) {
                if (isDescribeable(type, method)) {
                    buildFieldInfo(classInfo, method);
                } else {
                    throw new MappingException(
                            "Invalid method annotated, method is not describeable!");
                }
            }
        }

View Full Code Here

        FieldInfo fieldInfo = classInfo.getFieldInfoByName(fieldName);
        if (fieldInfo == null) {
            fieldInfo = classInfo.getKeyFieldInfoByName(fieldName);
            if (fieldInfo != null) {
                throw new MappingException("Can not annotate field and method!");
            }
        }

        Class<?> fieldType = method.getReturnType();
        TypeInfo typeInfo = new TypeInfo(fieldType);
        FieldHandlerImpl fieldHandler;
        try {
            fieldHandler = new FieldHandlerImpl(fieldName, null, null, method,
                    getSetterMethodFromGetter(method), typeInfo);
        } catch (SecurityException e) {
            throw new MappingException("Setter method for field " + fieldName
                    + " is not accessible!");
        } catch (NoSuchMethodException e) {
            throw new MappingException("Setter method for field " + fieldName
                    + " does not exist!");
        }
        fieldInfo = new FieldInfo(classInfo, fieldType, fieldName, fieldHandler);

        fieldInfo.addNature(JPAFieldNature.class.getName());
View Full Code Here

            _transient = fieldMap.getTransient();
           
            if (fieldMap.getSql() != null) {
                boolean isSQLTransient = fieldMap.getSql().getTransient();
                if (_transient && !isSQLTransient) {
                    throw new MappingException (Messages.message("persist.transient.conflict"));
                }
                _transient = isSQLTransient; 
            }
           
            if (fieldMap.getCollection() != null) {
                _multi = true;
            }

            // Set collection type
            if (fieldMap.getCollection() != null) {
              // simple arrays support
              if (COLLECTION_TYPE_ARRAY.equals(fieldMap.getCollection().toString())) {
                String arrayClassName = "[L" + fieldMap.getType() + ";";
                try {
                  _colClass = ds.resolve(arrayClassName);
                } catch (ClassNotFoundException e) {
                  throw new MappingException("mapping.classNotFound",
                                             arrayClassName);
                }

              } else {
                _colClass = getCollectionType(fieldMap.getCollection().toString(),
                                              _lazy);
               
                if (_colClass != SortedSet.class && _comparator != null) {
                    throw new MappingException(Messages.message(
                            "mapping.wrong.use.of.comparator"));               
                }
              }
              _store = false;
            }
            // Set field name, if it is null, we try to discover it with
            // return type of set/get method.
            _fType = fieldMap.getType();

            Class javaClass;
            try {
                javaClass = ds.resolve(eMold.getName());
            } catch (ClassNotFoundException e) {
                throw new MappingException("mapping.classNotFound", eMold.getName());
            }
            // ssa, multi classloader feature
            // set the default classloader to the hash table
            // ssa, FIXME : Shoudln't we have a ref to the Classloader used
            // instead of asking it to the newly created class ?
            _defaultReflectService._loader = javaClass.getClassLoader();
            if (null != _defaultReflectService._loader) {
                _reflectServices.put (_defaultReflectService._loader, this._defaultReflectService);
            }

            String fieldName = fieldMap.getName();
            String fieldType = fieldMap.getType();
            Class  declaredClass = null;
            if (fieldType != null) {
                try {
                    declaredClass = Types.typeFromName(javaClass.getClassLoader(), fieldType);
                    _defaultReflectService._fClass = declaredClass;
                } catch (ClassNotFoundException cnfe) {
                    throw new MappingException("mapping.classNotFound", declaredClass);
                }
            }

            if (fieldMap.getDirect()) {

                // No accessor, map field directly.
                Class  fieldClass = (_colClass != null) ? _colClass : null;
                _defaultReflectService._field = findField(javaClass, fieldName, fieldClass);
                if (_defaultReflectService._field == null) {
                    throw new MappingException(Messages.format(
                            "mapping.fieldNotAccessible", fieldName, javaClass.getName()));
                }
                _defaultReflectService._fClass = _defaultReflectService._field.getType();
                if ((_defaultReflectService._field.getModifiers() != Modifier.PUBLIC)
                        && (_defaultReflectService._field.getModifiers()
                                != (Modifier.PUBLIC | Modifier.VOLATILE))) {
                    throw new MappingException(Messages.format(
                            "mapping.fieldNotAccessible", _defaultReflectService._field.getName(),
                            _defaultReflectService._field.getDeclaringClass().getName()));
                }
            } else if ((fieldMap.getGetMethod() == null) && (fieldMap.getSetMethod() == null)) {

                // Container object, map field to fields of the container
                int point;
                ArrayList getSeq = new ArrayList();
                ArrayList setSeq = new ArrayList();
                String name = fieldMap.getName();
                Class last;
                Method method = null;
                String methodName = null;

                try {
                    while (true) {
                        point = name.indexOf('.');
                        if (point < 0) {
                            break;
                        }
                        last = javaClass;
                       
                        if (fieldMap.getType().compareTo("boolean") == 0) {
                            try {
                                methodName = METHOD_IS_PREFIX
                                           + capitalize(name.substring(0, point));
                                method = javaClass.getMethod(methodName, (Class[]) null);
                            } catch (NoSuchMethodException nsme) {
                                if (_log.isDebugEnabled()) {
                                    _log.debug (Messages.format("mapping.accessorNotFound",
                                            methodName, "boolean", getName()));
                                }
                            }
                        }
                       
                        if (method == null) {
                            methodName = METHOD_GET_PREFIX + capitalize(name.substring(0, point));
                            method = javaClass.getMethod(methodName, (Class[]) null);
                        }
                       
                        name = name.substring(point + 1);
                        // Make sure method is not abstract/static
                        // (note: Class.getMethod() returns only public methods).
                        if (((method.getModifiers() & Modifier.ABSTRACT) != 0)
                                || ((method.getModifiers() & Modifier.STATIC) != 0)) {
                            throw new MappingException("mapping.accessorNotAccessible",
                                    methodName, javaClass.getName());
                        }
                        getSeq.add(method);
                        javaClass = method.getReturnType();
                        // setter;   Note: javaClass already changed, use "last"
                        if (fieldMap.getType().compareTo("boolean") == 0) {
                            methodName = METHOD_SET_PREFIX + methodName.substring(2);
                        } else {
                            methodName = METHOD_SET_PREFIX + methodName.substring(3);
                        }

                        try {
                            method = last.getMethod(methodName, new Class[] {javaClass});
                            if (((method.getModifiers() & Modifier.ABSTRACT) != 0)
                                    || ((method.getModifiers() & Modifier.STATIC) != 0)) {
                                method = null;
                            }
                        } catch (Exception except) {
                            method = null;
                        }
                        setSeq.add(method);
                        method = null;
                       
                    }
                } catch (Exception ex) {
                    throw new MappingException(Messages.format ("mapping.accessorNotFound",
                           methodName, null, javaClass.getName()), ex);
                }
                if (getSeq.size() > 0) {
                    _defaultReflectService._getSequence =
                        (Method[]) getSeq.toArray(new Method[getSeq.size()]);
                    _defaultReflectService._setSequence =
                        (Method[]) setSeq.toArray(new Method[setSeq.size()]);
                }
                Class methodClass = (_colClass != null) ? _colClass : declaredClass;
                _defaultReflectService._getMethod = null;
               
                // if field is of type boolean, check whether is<Field>() is defined.
                if (fieldMap.getType() != null && fieldMap.getType().compareTo("boolean") == 0) {
                    _defaultReflectService._getMethod =
                        findAccessor(
                                javaClass, METHOD_IS_PREFIX + capitalize(name), methodClass, true);
                }
               
                if (_defaultReflectService._getMethod == null) {
                    _defaultReflectService._getMethod =
                        findAccessor(
                                javaClass, METHOD_GET_PREFIX + capitalize(name), methodClass, true);
                }

                if (_defaultReflectService._getMethod == null) {
                    if (fieldMap.getType().compareTo("boolean") == 0) {
                        throw new MappingException("mapping.accessorNotFound",
                                METHOD_GET_PREFIX + "/" + METHOD_IS_PREFIX + capitalize(name),
                                fieldMap.getType(), eMold.getName());
                    }
                    throw new MappingException("mapping.accessorNotFound",
                            METHOD_GET_PREFIX + capitalize(name),
                            fieldMap.getType(), eMold.getName());
                }
               
                // update fClass, because we can't tell between primitive
                // and primitive wrapper from the mapping
                if (_colClass == null) {
                    _defaultReflectService._fClass =
                        _defaultReflectService._getMethod.getReturnType();
                }

                _defaultReflectService._setMethod = findAccessor(
                        javaClass, METHOD_SET_PREFIX + capitalize(name), methodClass, false);

                if (_defaultReflectService._setMethod == null) {
                    _defaultReflectService._addMethod = findAccessor(
                            javaClass, METHOD_ADD_PREFIX + capitalize(name), declaredClass, false);

                    // look again, but this time without a trailing 's'
                    if ((_defaultReflectService._addMethod == null) && (name.endsWith("s"))) {
                        _defaultReflectService._addMethod = findAccessor(
                                javaClass, METHOD_ADD_PREFIX
                                + capitalize(name).substring(0, name.length() - 1),
                                declaredClass, false);
                    }

                    // if add<FieldName>() has been found, set _addable to true
                    if (_defaultReflectService._addMethod != null) {
                        _addable = true;
                    }
                }
               
                if ((_defaultReflectService._setMethod == null)
                        && (_defaultReflectService._addMethod == null)) {
                    throw new MappingException("mapping.accessorNotFound",
                            METHOD_SET_PREFIX + "/" + METHOD_ADD_PREFIX + capitalize(name),
                            declaredClass, javaClass.getName());
                }
               
            } else {

                // Bean type object, map field to get<Method>/set<Method>

                Class methodClass = _defaultReflectService._fClass;

                // First look up the get accessors
                if (fieldMap.getGetMethod() != null) {
                    if (_colClass != null) {
                        _defaultReflectService._getMethod = findAccessor(
                                javaClass, fieldMap.getGetMethod(), _colClass, true);
                    } else {
                        _defaultReflectService._getMethod = findAccessor(
                                javaClass, fieldMap.getGetMethod(), methodClass, true);
                    }

                    if (_defaultReflectService._getMethod == null) {
                        throw new MappingException("mapping.accessorNotFound",
                                fieldMap.getGetMethod(), methodClass, javaClass.getName());
                    }

                    // set/reset the fClass to actual field class
                    if (_colClass == null) {
                        _defaultReflectService._fClass =
                            _defaultReflectService._getMethod.getReturnType();
                    }

                } else {
                    throw new MappingException("mapping.getMethodMappingNotFound",
                            (_colClass != null) ? _colClass : methodClass, javaClass.getName());
                }

                // Second look up the set/add accessor
                if (fieldMap.getSetMethod() != null) {

                    if (_colClass != null) {
                        _defaultReflectService._setMethod = findAccessor(
                                javaClass, fieldMap.getSetMethod(), _colClass, false);

                        // find addXXX method only if lazy loading is turned off
                        if ((_defaultReflectService._setMethod == null) && !fieldMap.getLazy()) {
                            _defaultReflectService._addMethod = findAccessor(
                                    javaClass, fieldMap.getSetMethod(), declaredClass, false);
                            if (_defaultReflectService._addMethod != null) {
                                _addable = true;
                            }
                        }

                    } else {
                        // find setXXX method
                        _defaultReflectService._setMethod = findAccessor(
                                javaClass, fieldMap.getSetMethod(), methodClass, false);
                    }


                    if ((_defaultReflectService._setMethod == null)
                            && (_defaultReflectService._addMethod == null)) {
                        throw new MappingException("mapping.accessorNotFound",
                                fieldMap.getSetMethod(), methodClass, javaClass.getName());
                    }

                        if (_defaultReflectService._fClass == null) {
                            _defaultReflectService._fClass =
                                _defaultReflectService._setMethod.getParameterTypes()[0];
                        }
                    } else {
                        throw new MappingException("mapping.setMethodMappingNotFound",
                                (_colClass != null) ? _colClass : methodClass, javaClass.getName());
                }
            }


            // If there is a create method, add it to the field handler

            // Note: create method is used for enclosing object of this field to determine
            // what exact instance to be created.
            if (fieldMap.getCreateMethod() != null) {
                try {
                    _defaultReflectService._createMethod = javaClass.getMethod(
                            fieldMap.getCreateMethod(), (Class[]) null);
                } catch (Exception except) {
                    // No such/access to method
                    throw new MappingException("mapping.createMethodNotFound",
                                                fieldMap.getCreateMethod(), javaClass.getName());
                }
            } else if ((fieldMap.getName() != null)
                    && !Types.isSimpleType(_defaultReflectService._fClass)) {
                try {
                    Method method;

                    method = javaClass.getMethod(
                            METHOD_CREATE_PREFIX + capitalize(fieldMap.getName()), (Class[]) null);
                    _defaultReflectService._createMethod = method;
                } catch (Exception except) {
                    // no explicit exception handling
                }
            }

            // If there is an has/delete method, add them to field handler
            if (fieldMap.getName() != null) {
                Method hasMethod = null;
                Method deleteMethod = null;

                try {
                    hasMethod = javaClass.getMethod(
                            METHOD_HAS_PREFIX + capitalize(fieldMap.getName()), (Class[]) null);
                    if (((hasMethod.getModifiers() & Modifier.PUBLIC) == 0)
                            || ((hasMethod.getModifiers() & Modifier.STATIC) != 0)) {
                        hasMethod = null;
                    }
                    try {
                        if (((hasMethod.getModifiers() & Modifier.PUBLIC) == 0)
                                || ((hasMethod.getModifiers() & Modifier.STATIC) != 0)) {
                            deleteMethod = null;
                        }
                        deleteMethod = javaClass.getMethod(
                                METHOD_DELETE_PREFIX + capitalize(fieldMap.getName()),
                                (Class[]) null);
                    } catch (Exception except) {
                        // no explicit exception handling
                    }
                    _defaultReflectService._hasMethod = hasMethod;
                    _defaultReflectService._deleteMethod = deleteMethod;
                } catch (Exception except) {
                    // no explicit exception handling
                }
            }

            if ((_defaultReflectService._field == null)
                    && (_defaultReflectService._setMethod == null)
                    && (_defaultReflectService._getMethod == null)) {
                throw new MappingException("_field or _setMethod can't be created");
            }

            ds.pairFieldClass(this, _fType);
        } catch (NullPointerException e) {
            _log.fatal("Caught unexpected NullPointerException: ", e);
            throw new MappingException("Unexpected Null pointer!\n" + e);
        }
        _fieldName = fieldMap.getName();

        // If the field is of a primitive type we use the default value
        _default = Types.getDefault(_defaultReflectService._fClass);
View Full Code Here

TOP

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

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.