Package org.exolab.castor.mapping

Examples of org.exolab.castor.mapping.MappingException


        for ( int i = 0 ; i < _info.length ; ++i )
            if ( _info[ i ].javaClass.isAssignableFrom( javaClass ) )
                return _info[ i ].handler;
       
       
        throw new MappingException( "mapping.noCollectionHandler", javaClass.getName() );
    }
View Full Code Here


        if ( _info == null )
            loadInfo();
        for ( int i = 0 ; i < _info.length ; ++i )
            if ( _info[ i ].javaClass.equals( javaClass ) )
                return _info[ i ].getSetCollection;
        throw new MappingException( "mapping.noCollectionHandler", javaClass.getName() );
    }
View Full Code Here

                                    molder.getCacheParams(),
                                    cdResolver.getMappingLoader().getClassLoader());
                        } catch (CacheAcquireException e) {
                            String msg = Messages.message("persist.cacheCreationFailed");
                            _log.error(msg, e);
                            throw new MappingException(msg, e);
                        }
                        TypeInfo info = new TypeInfo(molder, new HashMap(), cache);
                        _typeInfo.put(molder.getName(), info);
                        itor.remove();
                        processedClasses.add(molder);

                    } else if (processedClasses.contains(molder.getExtends())) {
                        // use the base type to construct the new type
                        TypeInfo baseInfo = (TypeInfo) _typeInfo.get(extend.getName());
                        _typeInfo.put(molder.getName(), new TypeInfo(molder, baseInfo));
                        itor.remove();
                        processedClasses.add(molder);

                    } else {
                        // do nothing and wait for the next turn
                    }

                }
            } while ((freshClasses.size() > 0) && (counter != freshClasses.size()));

            // error if there is molder left.
            if (freshClasses.size() > 0) {
                Iterator itor = freshClasses.iterator();
                while (itor.hasNext()) {
                    ClassMolder molder = (ClassMolder) itor.next();
                    _log.error("The base class, " + (molder.getExtends().getName())
                        + ", of the extends class ," + molder.getName()
                        + " can not be resolved! ");
                }
                throw new MappingException("Some base class can not be resolved!");
            }
        } catch (ClassNotFoundException e) {
            throw new MappingException("Declared Class not found!");
        }
    }
View Full Code Here

                name = def.getName();
            }
           
            KeyGeneratorDescriptor desc = _keyGeneratorDescriptors.get(name);
            if (desc != null) {
                throw new MappingException(Messages.format("mapping.dupKeyGen", name));
            }
           
            Properties params = new Properties();
           
            Enumeration enumerateParam = def.enumerateParam();
View Full Code Here

        clsDesc.setMapping(classMapping);
       
        // Obtain the Java class.
        Class javaClass = resolveType(classMapping.getName());
        if (!Types.isConstructable(javaClass, true)) {
            throw new MappingException(
                    "mapping.classNotConstructable", javaClass.getName());
        }
        clsDesc.setJavaClass(javaClass);
       
        // If this class extends another class, we need to obtain the extended
        // class and make sure this class indeed extends it.
        ClassDescriptor extDesc = getExtended(classMapping, javaClass);
        if (extDesc != null) {
            if (!(extDesc.hasNature(ClassDescriptorJDONature.class.getName()))) {
                throw new IllegalArgumentException(
                        "Extended class does not have a JDO descriptor");
            }
           
            new ClassDescriptorJDONature(extDesc).addExtended(clsDesc);
        }
        clsDesc.setExtends(extDesc);
       
        // If this class depends on another class, obtain the depended class.
        clsDesc.setDepends(getDepended(classMapping, javaClass));
       
        // Create all field descriptors.
        FieldDescriptorImpl[] allFields = createFieldDescriptors(classMapping, javaClass);

        // Make sure there are no two fields with the same name.
        checkFieldNameDuplicates(allFields, javaClass);

        // Set class descriptor containing the field
        for (int i = 0; i < allFields.length; i++) {
            allFields[i].setContainingClassDescriptor(clsDesc);
        }
       
        // Identify identity and normal fields. Note that order must be preserved.
        List fieldList = new ArrayList(allFields.length);
        List idList = new ArrayList();
        if (extDesc == null) {
            // Sort fields into 2 lists based on identity definition of field.
            for (int i = 0; i < allFields.length; i++) {
                if (!allFields[i].isIdentity()) {
                    fieldList.add(allFields[i]);
                } else {
                    idList.add(allFields[i]);
                }
            }
           
            if (idList.size() == 0) {
                // Found no identities based on identity definition of field.
                // Try to find identities based on identity definition on class.
                String[] idNames = classMapping.getIdentity();
                if ((idNames == null) || (idNames.length == 0)) {
                    // There are also no identity definitions on class.
                    throw new MappingException("mapping.noIdentity", javaClass.getName());
                }

                FieldDescriptor identity;
                for (int i = 0; i < idNames.length; i++) {
                    identity = findIdentityByName(fieldList, idNames[i], javaClass);
                    if (identity != null) {
                        idList.add(identity);
                    } else {
                        throw new MappingException("mapping.identityMissing",
                                idNames[i], javaClass.getName());
                    }
                }
            }
        } else {
View Full Code Here

        Enumeration namedQueriesEnum = clsMap.enumerateNamedQuery();
        while (namedQueriesEnum.hasMoreElements()) {
            NamedQuery query = (NamedQuery) namedQueriesEnum.nextElement();
            String queryName = query.getName();
            if (_queryNames.contains(queryName)) {
                throw new MappingException(
                        "Duplicate entry for named query with name " + queryName);
            }
            _queryNames.add(queryName);

            jdoNature.addNamedQuery(queryName, query.getQuery());
View Full Code Here

                            "Identity field must be of type JDOFieldDescriptor");
                }
               
                String[] sqlName = new FieldDescriptorJDONature(field).getSQLName();
                if (sqlName == null) {
                    throw new MappingException("mapping.noSqlName",
                            field.getFieldName(), javaClass.getName());
                }

                fldList.remove(i);
                return field;
View Full Code Here

                    } catch (NoSuchMethodException nsmx) {
                        //-- Do nothing
                    }
                }
                if (!isTypeSafeEnum) {
                    throw new MappingException("mapping.noConvertor", sqlType.getName(),
                            internalFieldType.getName());
                }
            }
            convertorFrom = _typeConvertorRegistry.getConvertor(
                    internalFieldType, sqlType, sqlParam);
View Full Code Here

                    fieldMap.getCollection().toString());
            colHandler = CollectionHandlers.getHandler(colType);
           
            if (colType.getName().equals("java.util.Iterator") && fieldMap.getLazy()) {
                String err = "Lazy loading not supported for collection type 'iterator'";
                throw new MappingException(err);
            }

            if (colType.getName().equals("java.util.Enumeration") && fieldMap.getLazy()) {
                String err = "Lazy loading not supported for collection type 'enumerate'";
                throw new MappingException(err);
            }
        }
       
        TypeInfo typeInfo = getTypeInfo(fieldType, colHandler, fieldMap);
           
        ExtendedFieldHandler exfHandler = null;
        FieldHandler handler = null;
       
        //-- check for user supplied FieldHandler
        if (fieldMap.getHandler() != null) {
           
            Class handlerClass = resolveType(fieldMap.getHandler());
           
            if (!FieldHandler.class.isAssignableFrom(handlerClass)) {
                String err = "The class '" + fieldMap.getHandler()
                    + "' must implement " + FieldHandler.class.getName();
                throw new MappingException(err);
            }
           
            //-- get default constructor to invoke. We can't use the
            //-- newInstance method unfortunately becaue FieldHandler
            //-- overloads this method
            Constructor constructor = null;
            try {
                constructor = handlerClass.getConstructor(new Class[0]);
                handler = (FieldHandler)
                    constructor.newInstance(new Object[0]);
            } catch (Exception except) {
                String err = "The class '" + handlerClass.getName()
                    + "' must have a default public constructor.";
                throw new MappingException(err);
            }
           
           
            //-- ExtendedFieldHandler?
            if (handler instanceof ExtendedFieldHandler) {
View Full Code Here

                        idType[j] = (type == null) ? 0 : type[0];
                        FieldHandlerImpl fh = (FieldHandlerImpl) fd[j].getHandler();
                        idConvertTo[j] = fh.getConvertTo();
                        idConvertFrom[j] = fh.getConvertFrom();
                    } else {
                        throw new MappingException(
                                "Identity type must contains sql information: " + _name);
                    }
                }

                ClassDescriptor relDesc = null;
                try {
                    JDOClassDescriptorResolver jdoCDR;
                    jdoCDR = (JDOClassDescriptorResolver) classDescrResolver;
                    relDesc = jdoCDR.resolve(fmFields[i].getType());
                } catch (ResolverException e) {
                    throw new MappingException("Problem resolving class descriptor for class "
                            + fmFields.getClass(), e);
                }
                               
                if (relDesc.hasNature(ClassDescriptorJDONature.class.getName())) {
                    FieldDescriptor[] relatedIds = ((ClassDescriptorImpl) relDesc).getIdentities();
                    relatedIdSQL = new String[relatedIds.length];
                    relatedIdType = new int[relatedIds.length];
                    relatedIdConvertTo = new TypeConvertor[relatedIds.length];
                    relatedIdConvertFrom = new TypeConvertor[relatedIds.length];
                    for (int j = 0; j < relatedIdSQL.length; j++) {
                        if (relatedIds[j].hasNature(FieldDescriptorJDONature.class.getName())) {
                            FieldDescriptorJDONature nature;
                            nature = new FieldDescriptorJDONature(relatedIds[j]);
                            String[] tempId = nature.getSQLName();
                            relatedIdSQL[j] = (tempId == null) ? null : tempId[0];
                            int[] tempType =  nature.getSQLType();
                            relatedIdType[j] = (tempType == null) ? 0 : tempType[0];
                            FieldHandlerImpl fh = (FieldHandlerImpl) relatedIds[j].getHandler();
                            relatedIdConvertTo[j] = fh.getConvertTo();
                            relatedIdConvertFrom[j] = fh.getConvertFrom();
                        } else {
                            throw new MappingException(
                                    "Field type is not persistence-capable: "
                                    + relatedIds[j].getFieldName());
                        }
                    }
                }

                // if many-key exist, idSQL is overridden
                String[] manyKey = fmFields[i].getSql().getManyKey();
                if ((manyKey != null) && (manyKey.length != 0)) {
                    if (manyKey.length != idSQL.length) {
                        throw new MappingException(
                                "The number of many-keys doesn't match referred object: "
                                + clsDesc.getJavaClass().getName());
                    }
                    idSQL = manyKey;
                }

                // if name="" exist, relatedIdSQL is overridden
                String[] manyName = fmFields[i].getSql().getName();
                if ((manyName != null) && (manyName.length != 0)) {
                    if (manyName.length != relatedIdSQL.length) {
                        throw new MappingException(
                                "The number of many-keys doesn't match referred object: "
                                + relDesc.getJavaClass().getName());
                    }
                    relatedIdSQL = manyName;
                }
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.