Package org.apache.beehive.controls.api

Examples of org.apache.beehive.controls.api.ControlException


                        msg.setJMSCorrelationIDAsBytes((byte[]) value);
                    else if (value instanceof String)
                        msg.setJMSCorrelationID((String) value);
                }
                catch (javax.jms.JMSException e) {
                    throw new ControlException("Error setting JMSCorrelationID for message", e);
                }
                break;
            case JMSPriority:
                try {
                    if (value instanceof Integer)
                        msg.setJMSPriority((Integer)value);
                    else if (value instanceof String)
                        msg.setJMSPriority(Integer.getInteger((String) value));
                }
                catch (javax.jms.JMSException e) {
                    throw new ControlException("Error setting JMSPriority for message", e);
                }
                break;
            case JMSExpiration:
                try {
                    if (value instanceof Long)
                        msg.setJMSExpiration((Long)value);
                    else if (value instanceof String)
                        msg.setJMSExpiration(Long.parseLong((String) value));
                }
                catch (javax.jms.JMSException e) {
                    throw new ControlException("Error setting JMSExpiration for message", e);
                }
                break;
            case JMSType:
                try {
                    msg.setJMSType((String) value);
                }
                catch (javax.jms.JMSException e) {
                    throw new ControlException("Error setting JMSType for message", e);
                }
                break;
        }
    }
View Full Code Here


        try {
            InitialContext cntxt = getInitialContext();
            Object obj = cntxt.lookup(resource);
            if (resourceClass != null && !(resourceClass.isInstance(obj)))
                throw new ControlException("JNDI resource '" + resource + "' is not an instance of '" + resourceClass.getName() + "'");
            else return obj;
        }
        catch (NamingException e) {
            throw new ControlException("Cannot load JNDI resource '" + resource + "'", e);
        }
    }
View Full Code Here

        if (url == null && factory == null) {
            try {
                return new InitialContext();
            }
            catch (NamingException e) {
                throw new ControlException("Cannot get default JNDI initial context", e);
            }

        }
        if (url == null || factory == null) {
            throw new ControlException("Both the provider-url and jndi factory need to be provided");

        }
        Hashtable<String, String> env = new Hashtable<String, String>();
        env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, factory);
        env.put(javax.naming.Context.PROVIDER_URL, url);

        String username = nullIfEmpty(props.jndiSecurityPrincipal());
        if (username != null)
            env.put(javax.naming.Context.SECURITY_PRINCIPAL, username);

        String password = nullIfEmpty(props.jndiSecurityCredentials());
        if (password != null)
            env.put(javax.naming.Context.SECURITY_CREDENTIALS, password);

        try {
            return _initialContext = new InitialContext(env);
        }
        catch (NamingException e) {
            throw new ControlException("Cannot get JNDI initial context at provider '" + url + "' with factory '" + factory + "'", e);
        }
    }
View Full Code Here

        {
            beanInfo = Introspector.getBeanInfo(control.getClass());
        }
        catch (IntrospectionException ie)
        {
            throw new ControlException("Unable to locate BeanInfo", ie);
        }

        //
        // Cast the encoding stream to an XMLEncoder (only encoding supported) and then set
        // the stream owner to the bean being persisted
        //
        XMLEncoder xmlOut = (XMLEncoder)out;
        Object owner = xmlOut.getOwner();
        xmlOut.setOwner(control);
        try
        {

            //
            // The default implementation of property persistence will use BeanInfo to
            // incrementally compare oldInstance property values to newInstance property values.  
            // Because the bean instance PropertyMap holds only the values that have been
            // modified, this process can be optimized by directly writing out only the properties
            // found in the map.
            //
            BeanPropertyMap beanMap = control.getPropertyMap();
            PropertyDescriptor [] propDescriptors = beanInfo.getPropertyDescriptors();
            for (PropertyKey pk : beanMap.getPropertyKeys())
            {
                //
                // Locate the PropertyDescriptor for the modified property, and use it to write
                // the property value to the encoder stream
                //
                String propName = pk.getPropertyName();
                boolean found = false;
                for (int i = 0; i < propDescriptors.length; i++)
                {
                    if (propName.equals(propDescriptors[i].getName()))
                    {
                        found = true;

                        // Only write the property if it is not flagged as transient
                        Object transientVal = propDescriptors[i].getValue("transient");
                        if (transientVal == null || transientVal.equals(Boolean.FALSE))
                        {
                            xmlOut.writeStatement(
                                new Statement(oldInstance,
                                      propDescriptors[i].getWriteMethod().getName(),
                                      new Object [] {beanMap.getProperty(pk)}));
                        }
                    }
                }
                if (found == false)
                {
                    throw new ControlException("Unknown property in bean PropertyMap: " + pk);
                }
            }

            //
            // Get the bean context associated with the bean, and persist any nested controls
            //
            ControlBeanContext cbc = control.getControlBeanContext();
            if (cbc.size() != 0)
            {
                xmlOut.setPersistenceDelegate(ControlBeanContext.class,
                                              new ContextPersistenceDelegate());

                Iterator nestedIter = cbc.iterator();
                while (nestedIter.hasNext())
                {
                    Object bean = nestedIter.next();
                    if (bean instanceof ControlBean)
                    {
                        xmlOut.writeStatement(
                            new Statement(cbc, "add", new Object [] { bean } ));
                    }
                }
            }

            //
            // Restore any listeners associated with the control
            //
            EventSetDescriptor [] eventSetDescriptors = beanInfo.getEventSetDescriptors();
            for (int i = 0; i < eventSetDescriptors.length; i++)
            {
                EventSetDescriptor esd = eventSetDescriptors[i];
                Method listenersMethod = esd.getGetListenerMethod();
                String addListenerName = esd.getAddListenerMethod().getName();
                if (listenersMethod != null)
                {
                    //
                    // Get the list of listeners, and then add statements to incrementally
                    // add them in the same order
                    //
                    try
                    {
                        Object [] lstnrs = (Object [])listenersMethod.invoke(control,
                                                                             new Object []{});
                        for (int j = 0; j < lstnrs.length; j++)
                        {
                            //
                            // If this is a generated EventAdaptor class, then set the delegate
                            // explicitly
                            //
                            if (lstnrs[j] instanceof EventAdaptor)
                                xmlOut.setPersistenceDelegate(lstnrs[j].getClass(),
                                                              new AdaptorPersistenceDelegate());
                            xmlOut.writeStatement(
                                new Statement(control, addListenerName, new Object [] {lstnrs[j]}));
                        }
                    }
                    catch (Exception iae)
                    {
                        throw new ControlException("Unable to initialize listeners", iae);
                    }
                }
            }

            //
View Full Code Here

        }
        catch (TooManyListenersException tmle)
        {
            // This would be highly unusual... it implies that the registration for service
            // revocation notifications failed for some reason.
            throw new ControlException("Unable to register for service events", tmle);
        }
    }
View Full Code Here

            catch(NoSuchMethodException nsmEx)
            {
                // This can only happen if a PropertySet is incompatibly changed after
                // serialization of a PropertyKey (since it is initially validated in
                // the constructor).
                throw new ControlException("Unable to locate PropertyKey accessor method", nsmEx);
            }
        }
        return _getMethod;
    }
View Full Code Here

        final String[] paramNameQualifiers = ((ReflectionFragment) fragment).getParameterNameQualifiers();
        final String parameterName = ((ReflectionFragment) fragment).getParameterName();

        if (paramMap.containsKey(paramNameQualifiers[0]) == false) {
            throw new ControlException(buildMessage(parameterName, method.getSimpleName()));
        }

        ParameterDeclaration tpd = paramMap.get(paramNameQualifiers[0]);
        TypeMirror type = tpd.getType();

        MethodDeclaration getterMethod = null;
        FieldDeclaration field = null;

        for (int i = 1; i < paramNameQualifiers.length; i++) {

            getterMethod = null;
            field = null;

            // loop through superclasses until we find a match or run out of superclasses
            while (type != null) {

                if (type instanceof DeclaredType == false) {
                    throw new ControlException(buildMessage(parameterName, method.getSimpleName()));
                }

                TypeDeclaration td = ((DeclaredType) type).getDeclaration();
                //
                // abort if Map!!! No further checking can be done.
                //
                if (td.getQualifiedName().equals("java.util.Map")) {
                    return;
                }

                Collection<? extends MethodDeclaration> methods =
                        DeclarationFilter.FILTER_PUBLIC.filter(td.getMethods());
                for (MethodDeclaration m : methods) {
                    String upperFirst = paramNameQualifiers[i].substring(0,1).toUpperCase();
                    if (paramNameQualifiers[i].length() > 1) {
                        upperFirst = upperFirst + paramNameQualifiers[i].substring(1);
                    }
                    if (m.getSimpleName().equals("get" + upperFirst)
                        || m.getSimpleName().equals("is" + upperFirst)) {
                        getterMethod = m;
                    }
                }

                if (getterMethod == null) {
                    Collection<FieldDeclaration> fields =
                            DeclarationFilter.FILTER_PUBLIC.filter(td.getFields());
                    for (FieldDeclaration fd : fields) {
                        if (fd.getSimpleName().equals(paramNameQualifiers[i])) {
                            field = fd;
                        }
                    }
                }

                // try the super-class
                if (getterMethod == null && field == null) {
                    if (td instanceof ClassDeclaration) {
                        type = ((ClassDeclaration) td).getSuperclass();
                        continue;
                    }
                }

                break;
            } // while

            // found a match, get its type and continue within the for loop
            if (getterMethod != null) {
                type = getterMethod.getReturnType();
            } else if (field != null) {
                type = field.getType();
            } else {
                throw new ControlException(buildMessage(parameterName, method.getSimpleName()));
            }
        }
    }
View Full Code Here

        }

        try {
            getConnection();
        } catch (SQLException se) {
            throw new ControlException("SQL Exception while attempting to connect to database.", se);
        }
    }
View Full Code Here

        if (_connection != null) {
            try {
                _connection.close();
            } catch (SQLException e) {
                throw new ControlException("SQL Exception while attempting to close database connection.", e);
            }
        }

        _connection = null;
        _connectionDataSource = null;
View Full Code Here

                                                             _connectionDriver.databaseURL(),
                                                             _connectionDriver.userName(),
                                                             _connectionDriver.password(),
                                                             _connectionDriver.properties());
            } else {
                throw new ControlException("no @\'" + ConnectionDataSource.class.getName()
                                           + "\' or \'" + ConnectionDriver.class.getName() + "\' property found.");
            }

            //
            // set any specifed connection options
            //
            if (connectionOptions != null) {

                if (_connection.isReadOnly() != connectionOptions.readOnly()) {
                    _connection.setReadOnly(connectionOptions.readOnly());
                }

                DatabaseMetaData dbMetadata = _connection.getMetaData();

                final HoldabilityType holdability = connectionOptions.resultSetHoldability();
                if (holdability != HoldabilityType.DRIVER_DEFAULT) {
                    if (dbMetadata.supportsResultSetHoldability(holdability.getHoldability())) {
                        _connection.setHoldability(holdability.getHoldability());
                    } else {
                        throw new ControlException("Database does not support ResultSet holdability type: "
                                                   + holdability.toString());
                    }
                }

                setTypeMappers(connectionOptions.typeMappers());
View Full Code Here

TOP

Related Classes of org.apache.beehive.controls.api.ControlException

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.