Package com.buschmais.xo.api

Examples of com.buschmais.xo.api.XOException


    public static <T> Class<T> getType(String name) {
        Class<T> type;
        try {
            type = (Class<T>) Class.forName(name);
        } catch (ClassNotFoundException e) {
            throw new XOException("Cannot find class with name '" + name + "'");
        }
        return type;
    }
View Full Code Here


    public static <T> T newInstance(Class<T> type) {
        try {
            return type.newInstance();
        } catch (InstantiationException e) {
            throw new XOException("Cannot create instance of type '" + type.getName() + "'");
        } catch (IllegalAccessException e) {
            throw new XOException("Access denied to type '" + type.getName() + "'");
        }
    }
View Full Code Here

     * @param type   The type of the property.
     */
    public SetPropertyMethod(Method setter, GetPropertyMethod getter, String name, Class<?> type, Type genericType) {
        super(setter, name, type, genericType);
        if (getter == null) {
            throw new XOException("No getter defined for property '" + name + "' of type '" + type.getName() + "'");
        }
        this.getter = getter;
    }
View Full Code Here

    }

    public <T> T removeInterceptor(T instance) {
        InvocationHandler invocationHandler = Proxy.getInvocationHandler(instance);
        if (!InterceptorInvocationHandler.class.isAssignableFrom(invocationHandler.getClass())) {
            throw new XOException(invocationHandler + " implementing " + Arrays.asList(invocationHandler.getClass().getInterfaces()) + " is not of expected type " + InterceptorInvocationHandler.class.getName());
        }
        return (T) ((InterceptorInvocationHandler) invocationHandler).getInstance();
    }
View Full Code Here

    @Override
    public T getSingleResult() {
        ResultIterator<T> iterator = iterator();
        if (!iterator.hasNext()) {
            throw new XOException("No result available.");
        }
        try {
            T singleResult = iterator.next();
            if (iterator.hasNext()) {
                throw new XOException("More than one result available.");
            }
            return singleResult;
        } finally {
            iterator.close();
        }
View Full Code Here

            transactionAttribute = this.defaultTransactionAttribute;
        }
        switch (transactionAttribute) {
            case MANDATORY:
                if (!this.xoTransaction.isActive()) {
                    throw new XOException("An active transaction is MANDATORY when calling method '" +
                            method.getDeclaringClass().getName() + "#" + method.getName() + "'");
                }
                return context.proceed();
            case REQUIRES: {
                if (!this.xoTransaction.isActive()) {
                    try {
                        this.xoTransaction.begin();
                        Object result = context.proceed();
                        this.xoTransaction.commit();
                        return result;
                    } catch (RuntimeException e) {
                        if (this.xoTransaction.isActive()) {
                            this.xoTransaction.rollback();
                        }
                        throw e;
                    } catch (Exception e) {
                        if (this.xoTransaction.isActive()) {
                            this.xoTransaction.commit();
                        }
                        throw e;
                    }
                } else {
                    return context.proceed();
                }
            }
            case NOT_SUPPORTED:
                return context.proceed();
            default: {
                throw new XOException("Unsupported transaction attribute '" + transactionAttribute + "'");
            }
        }
    }
View Full Code Here

    @Override
    public Object invoke(E element, Object instance, Method method, Object[] args) throws Exception {
        ProxyMethod<E> proxyMethod = proxyMethods.get(method);
        if (proxyMethod == null) {
            throw new XOException("Cannot find proxy for method '" + method.toGenericString() + "'");
        }
        return proxyMethod.invoke(element, instance, args);
    }
View Full Code Here

    protected void addMethod(ProxyMethod<E> proxyMethod, Class<?> type, String name, Class<?>... argumentTypes) {
        Method method;
        try {
            method = type.getDeclaredMethod(name, argumentTypes);
        } catch (NoSuchMethodException e) {
            throw new XOException("Cannot resolve method '" + name + "' (" + Arrays.asList(argumentTypes) + ")");
        }
        addProxyMethod(proxyMethod, method);
    }
View Full Code Here

        DatastoreSession<?, Entity, ?, EntityDiscriminator, RelationId, Relation, ?, RelationDiscriminator> datastoreSession = sessionContext.getDatastoreSession();
        Entity source = datastoreSession.getDatastorePropertyManager().getFrom(relation);
        Entity target = datastoreSession.getDatastorePropertyManager().getTo(relation);
        RelationDiscriminator discriminator = datastoreSession.getRelationDiscriminator(relation);
        if (discriminator == null) {
            throw new XOException("Cannot determine type discriminators for relation '" + relation + "'");
        }
        return sessionContext.getMetadataProvider().getRelationTypes(datastoreSession.getEntityDiscriminators(source), discriminator, datastoreSession.getEntityDiscriminators(target));
    }
View Full Code Here

        for (Class<?> type : instance.getClass().getInterfaces()) {
            if (targetType.isAssignableFrom(type)) {
                return getInstance(datastoreType);
            }
        }
        throw new XOException(instance + " cannot be cast to " + targetType.getName());
    }
View Full Code Here

TOP

Related Classes of com.buschmais.xo.api.XOException

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.