Package org.apache.beehive.controls.api

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


        // Services are always provided by the parent context.
        //
        ControlBeanContext cbc = getControlBeanContext();
        BeanContext bc = cbc.getBeanContext();
        if (bc == null || !(bc instanceof BeanContextServices))
            throw new ControlException("Can't locate service context: " + bc);

        //
        // Call getService on the parent context, using this bean as the requestor and the
        // associated peer context instance as the child and event listener parameters.
        //
View Full Code Here


                    break;
                }
            }
            if (!found)
            {
                throw new ControlException("Can't find base control interface for " + controlIntf);
            }
        }
        return controlIntf;
    }
View Full Code Here

            }

            //
            // Version requirement failed
            //
            throw new ControlException( "Control extension " + intfName + " fails version requirement: requires interface version " +
                    majorRequired + "." + minorRequired + ", found interface version " +
                    majorPresent + "." + minorPresent + "." );
        }
    }
View Full Code Here

     * Called during XMLDecoder reconstruction of a ControlBean.
     */
    public void decodeImpl(Object impl)
    {
        if (impl != _control)
            throw new ControlException("Cannot change implementation");
    }
View Full Code Here

                        createQueueSession();
                        break;
                }
            }
            catch (JMSException e) {
                throw new ControlException("Failure to get JMS connection or session", e);
            }
        }
        return _session;
    }
View Full Code Here

                    type = MessageType.Text;
                else if (body instanceof javax.jms.Message)
                    type = MessageType.JMSMessage;
                else if (body instanceof Serializable)
                    type = MessageType.Object;
                else throw new ControlException("Cannot determine message type from body");
            }
            switch (type) {
                case Object:
                    checkBody(body, Serializable.class);
                    m = session.createObjectMessage((Serializable) body);
                    break;
                case Bytes:
                    BytesMessage sm;
                    checkBody(body, byte[].class);
                    m = sm = session.createBytesMessage();
                    sm.writeBytes((byte[]) body);
                    break;
                case Text:
                    if (XMLOBJ_CLASS != null && XMLOBJ_CLASS.isAssignableFrom(body.getClass())) {
                        try {
                            Method xmlText = XMLOBJ_CLASS.getMethod("xmlText", new Class[]{});
                            body = xmlText.invoke(body, new Object[]{});
                        }
                        catch (NoSuchMethodException e) {
                            throw new ControlException(e.getMessage(), e);
                        }
                        catch (IllegalAccessException e) {
                            throw new ControlException(e.getMessage(), e);
                        }
                        catch (InvocationTargetException e) {
                            throw new ControlException(e.getMessage(), e);
                        }
                    }
                    checkBody(body, String.class);
                    m = session.createTextMessage((String) body);
                    break;
                case Map:
                    MapMessage mm;
                    checkBody(body, Map.class);
                    m = mm = session.createMapMessage();
                    Map map = (Map)body;
                    Iterator iter = map.keySet().iterator();
                    while (iter.hasNext()) {
                        String key = (String) iter.next();
                        mm.setObject(key, map.get(key));
                    }
                    break;
                case JMSMessage:
                    checkBody(body, javax.jms.Message.class);
                    m = (javax.jms.Message) body;
                    break;
            }
            /*
                * Set the correlation id if given.
                */
            String correlationProp = props.sendCorrelationProperty();
            if (correlationProp != null && correlationProp.length() == 0)
                correlationProp = null;

            if (correlationId == null)
                correlationId = getHeaderAsString(HeaderType.JMSCorrelationID);

            Properties jmsProps = (Properties)_context.getMethodPropertySet(method, Properties.class);
            if (jmsProps != null && jmsProps.value() != null) {
                PropertyValue[] jprops = jmsProps.value();
                for (int i = 0; i < jprops.length; i++) {
                    PropertyValue jprop = jprops[i];
                    Class cls = jprop.type();
                    if (cls.equals(String.class))
                        m.setStringProperty(jprop.name(), jprop.value());
                    else if (cls.equals(Integer.class))
                        m.setIntProperty(jprop.name(), valueAsInteger(jprop.value()));
                    else if (cls.equals(Long.class))
                        m.setLongProperty(jprop.name(), valueAsLong(jprop.value()));
                    else
                        throw new IllegalArgumentException("Invalid type for property-value");
                }
            }
            /*
                * Set the properties/headers of the message from
                * the parameters to the invoke.
                */
            if (hasAnnotation) {
                for (int i = 0; i < args.length; i++) {
                    Property jmsProp = (Property) _context.getParameterPropertySet(method, i, Property.class);
                    if (jmsProp != null)
                        m.setObjectProperty(jmsProp.name(), args[i]);

                    Priority jmsPriority = (Priority) _context.getParameterPropertySet(method, i, Priority.class);
                    if (jmsPriority != null) {
                        Integer p = valueAsInteger(args[i]);
                        if (p != null)
                            priority = p.intValue();
                    }
                    Expiration jmsExpiration = (Expiration) _context.getParameterPropertySet(method, i, Expiration.class);
                    if (jmsExpiration != null) {
                        Long e = valueAsLong(args[i]);
                        if (e != null)
                            expiration = e.longValue();
                    }
                    Delivery jmsDelivery = (Delivery) _context.getParameterPropertySet(method, i, Delivery.class);
                    if (jmsDelivery != null && args[i] != null) {
                        deliveryMode = deliveryModeToJmsMode(args[i]);
                    }
                    t = (Type) _context.getParameterPropertySet(method, i, Type.class);
                    if (t != null && args[i] != null)
                        jmsType = (String) args[i];

                    CorrelationId jmsId = (CorrelationId)_context.getParameterPropertySet(method, i, CorrelationId.class);
                    if (jmsId != null && args[i] != null)
                        correlationId = (String) args[i];
                }
            }
            if (correlationProp != null)
                m.setStringProperty(correlationProp, correlationId);
            else
                m.setJMSCorrelationID(correlationId);

            /* Set the headers and properties from maps provided by setProperties() and setHeaders() */
            m.setJMSExpiration(expiration);
            m.setJMSDeliveryMode(deliveryMode);
            m.setJMSPriority(priority);
            setMessageHeaders(m);
            setMessageProperties(m);
            expiration = m.getJMSExpiration();
            deliveryMode = m.getJMSDeliveryMode();
            priority = m.getJMSPriority();

            _headers = null;
            _properties = null;

            /* Send the message. */
            switch (getDestinationType()) {
                case Topic:
                    ((TopicPublisher) getProducer()).publish(m, deliveryMode, priority, expiration);
                    break;
                case Queue:
                    getProducer().send(m, deliveryMode, priority, expiration);
                    break;
            }
        }
        catch (JMSException e) {
            throw new ControlException("Error in sending message", e);
        }
        return m;
    }
View Full Code Here

                _connection.close();
                _connection = null;
            }
        }
        catch (JMSException e) {
            throw new ControlException("Unable to release JMS resource", e);
        }
    }
View Full Code Here

                        _producer = ((QueueSession) sess).createSender((Queue)getDestination());
                        break;
                }
            }
            catch (JMSException e) {
                throw new ControlException("Unable to acquire JMS resource", e);
            }
        }
        return _producer;
    }
View Full Code Here

     */
    protected void checkBody(Object value, Class cls)
        throws ControlException {

        if (!cls.isInstance(value))
            throw new ControlException("Message body is not of correct type expected " + cls.getName());
    }
View Full Code Here

            Object value = _properties.get(name);
            try {
                msg.setObjectProperty(name, value);
            }
            catch (JMSException e) {
                throw new ControlException("Cannot set property '" + name + "' into JMS message");
            }
        }
    }
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.