Package org.apache.cayenne

Examples of org.apache.cayenne.CayenneRuntimeException


            xformer.setOutputProperty(OutputKeys.INDENT, "yes");
            xformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
            xformer.transform(source, result);
        }
        catch (Exception e) {
            throw new CayenneRuntimeException("XML transformation error", e);
        }

        return out.toString().trim() + System.getProperty("line.separator");
    }
View Full Code Here


            encodeObject(encoder, this.object, true);
        }
    }

    public void decodeFromXML(XMLDecoder decoder) {
        throw new CayenneRuntimeException("Decoding is not supported by this object");
    }
View Full Code Here

                Query query = (Query) queries.next();
                String name = query.getName();
                Object existingQuery = queryCache.put(name, query);

                if (existingQuery != null && query != existingQuery) {
                    throw new CayenneRuntimeException("More than one Query for name"
                            + name);
                }
            }
        }
    }
View Full Code Here

     *
     * @return the required DbEntity, or null if none matches the specifier
     */
    public synchronized DbEntity lookupDbEntity(Class aClass) {
        if (!indexedByClass) {
            throw new CayenneRuntimeException("Class index is disabled.");
        }
        return this._lookupDbEntity(aClass);
    }
View Full Code Here

     *
     * @return the required ObjEntity or null if there is none that matches the specifier
     */
    public synchronized ObjEntity lookupObjEntity(Class aClass) {
        if (!indexedByClass) {
            throw new CayenneRuntimeException("Class index is disabled.");
        }

        return this._lookupObjEntity(aClass);
    }
View Full Code Here

            constructCache();
            result = dbEntityCache.get(object);
        }

        if (result == DUPLICATE_MARKER) {
            throw new CayenneRuntimeException(
                    "Can't perform lookup. There is more than one DbEntity mapped to "
                            + object);
        }

        return (DbEntity) result;
View Full Code Here

            constructCache();
            result = objEntityCache.get(object);
        }

        if (result == DUPLICATE_MARKER) {
            throw new CayenneRuntimeException(
                    "Can't perform lookup. There is more than one ObjEntity mapped to "
                            + object);
        }

        return (ObjEntity) result;
View Full Code Here

        }

        String type = child.getAttribute("type");
        if (Util.isEmptyString(type)) {
            // TODO should we use String by default? Or guess from the property type?
            throw new CayenneRuntimeException("No type specified for tag '"
                    + child.getNodeName()
                    + "'.");
        }

        // temp hack to support primitives...
        Class objectClass = (Class) classMapping.get(type);
        if (null == objectClass) {
            try {
                objectClass = Class.forName(type);
            }
            catch (Exception e) {
                throw new CayenneRuntimeException("Unrecognized class '"
                        + objectClass
                        + "'", e);
            }
        }

        try {
            // This crazy conditional checks if we're decoding a collection. There are two
            // ways
            // to enter into this body:
            // 1) If there are two elements at the same level with the same name, then
            // they should
            // part of a collection.
            // 2) If a single occurring element has the "forceList" attribute set to
            // "YES", then it
            // too should be treated as a collection.
            //
            // The final part checks that we have not previously attempted to decode this
            // collection,
            // which is necessary to prevent infinite loops .
            if ((((null != child.getParentNode()) && (XMLUtil.getChildren(
                    child.getParentNode(),
                    child.getNodeName()).size() > 1)) || (child
                    .getAttribute("forceList")
                    .toUpperCase().equals("YES")))
                    && (!decodedCollections.contains(child))) {
                return decodeCollection(child);
            }

            // If the object implements XMLSerializable, delegate decoding to the class's
            // implementation of decodeFromXML().
            if (XMLSerializable.class.isAssignableFrom(objectClass)) {
                XMLSerializable ret = (XMLSerializable) objectClass.newInstance();
                ret.decodeFromXML(this);

                return ret;
            }

            // If we hit here, then we should be encoding "simple" properties, which are
            // basically
            // objects that take a single arg String constructor.
            Constructor c = objectClass.getConstructor(new Class[] {
                String.class
            });
            if (c != null) {
                // Create a new object of the type supplied as the "type" attribute
                // in the XML element that
                // represents the XML element's text value.
                // E.g., for <count type="java.lang.Integer">13</count>, this is
                // equivalent to new Integer("13");

                return c.newInstance(new Object[] {
                    XMLUtil.getText(child)
                });
            }
        }
        catch (Exception e) {
            throw new CayenneRuntimeException("Error decoding tag '"
                    + child.getNodeName()
                    + "'", e);
        }

        // If we hit here, then we're trying to decode something we're not equipped to
        // handle.
        // E.g., a complex object that does not implement XMLSerializable.

        throw new CayenneRuntimeException(
                "Error decoding tag '"
                        + child.getNodeName()
                        + "': "
                        + "specified class does not have a constructor taking either a String or an XMLDecoder");
    }
View Full Code Here

        try {
            object = decodeObject(element);
        }
        catch (Throwable th) {
            throw new CayenneRuntimeException("Error instantiating object", th);
        }

        if ((null != dataContext) && (object instanceof DataObject)) {
            dataContext.registerNewObject((DataObject) object);
        }
View Full Code Here

                    .getNodeName());

            ret = (Collection) c.getClass().newInstance();
        }
        catch (Exception ex) {
            throw new CayenneRuntimeException(
                    "Could not create collection with no-arg constructor.",
                    ex);
        }

        // Each child of the root corresponds to an XML representation of
View Full Code Here

TOP

Related Classes of org.apache.cayenne.CayenneRuntimeException

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.