Search in sources :

Example 1 with TopicConnectionFactory

use of com.sun.messaging.TopicConnectionFactory in project openmq by eclipse-ee4j.

the class CFObjectFactory method getObjectInstance.

/**
 * Creates an instance of the object represented by a Reference object.
 *
 * @param obj The Reference object.
 *
 * @return an instance of the class named in the Reference object <code>obj</code>,
 *         null if <code>obj</code> is not an instance of a Reference object.
 *
 * @throws MissingVersionNumberException if either <code>obj</code> references an object that is not an instance of a
 * <code>com.sun.messaging.Queue</code> object or the version number is missing from the Reference object.
 * @throws UnsupportedVersionNumberException if an unsupported version number is present in the Reference.
 * @throws CorruptedConfigurationPropertiesException if <code>obj</code> does not have the minimum information
 * neccessary to recreate an instance of a a valid <code>com.sun.messaging.AdministeredObject</code>.
 */
@Override
public Object getObjectInstance(Object obj, Name name, Context ctx, Hashtable env) throws Exception {
    if (obj instanceof Reference) {
        Reference ref = (Reference) obj;
        String refClassName = ref.getClassName();
        ConnectionFactory cf;
        if (refClassName.equals(com.sun.messaging.QueueConnectionFactory.class.getName())) {
            cf = new QueueConnectionFactory();
        } else {
            if (refClassName.equals(com.sun.messaging.TopicConnectionFactory.class.getName())) {
                cf = new TopicConnectionFactory();
            } else {
                throw new MissingVersionNumberException();
            }
        }
        // version number MUST exist and it MUST be the same as AO_VERSION_STR_JMQ1
        RefAddr versionAddr = ref.get(REF_VERSION);
        if (versionAddr == null) {
            // version number does not exist
            throw new MissingVersionNumberException();
        } else {
            // version number does not match
            String version = null;
            if (!AO_VERSION_STR_JMQ1.equals(version = (String) versionAddr.getContent())) {
                throw new UnsupportedVersionNumberException(version);
            }
            cf.setStoredVersion(version);
        }
        // retreive the security port value from the Reference
        RefAddr securityPortAddr = ref.get(REF_SECURITYPORT);
        if (securityPortAddr != null) {
            securityPortAddr.getContent();
        } else {
            // securityPort is missing - corrupted?
            throw new CorruptedConfigurationPropertiesException();
        }
        /*
             * try { parm = (String) (((RefAddr)ref.get(REF_PARM)).getContent()); host = (String)
             * (((RefAddr)ref.get(REF_HOST)).getContent()); subnet = (String) (((RefAddr)ref.get(REF_SUBNET)).getContent());
             * ackTimeout = (String) (((RefAddr)ref.get(REF_ACKTIMEOUT)).getContent()); } catch (NullPointerException e) { // this
             * should NOT happen under normal operations // this will happen when the object was modified outside // of its intended
             * use throw new CorruptedConfigurationPropertiesException(); }
             */
        recreateConfigurationObject(cf, ref);
        setJMSXProperties(cf, ref);
        return cf;
    }
    return null;
}
Also used : RefAddr(javax.naming.RefAddr) TopicConnectionFactory(com.sun.messaging.TopicConnectionFactory) TopicConnectionFactory(com.sun.messaging.TopicConnectionFactory) ConnectionFactory(com.sun.messaging.ConnectionFactory) QueueConnectionFactory(com.sun.messaging.QueueConnectionFactory) Reference(javax.naming.Reference) QueueConnectionFactory(com.sun.messaging.QueueConnectionFactory)

Aggregations

ConnectionFactory (com.sun.messaging.ConnectionFactory)1 QueueConnectionFactory (com.sun.messaging.QueueConnectionFactory)1 TopicConnectionFactory (com.sun.messaging.TopicConnectionFactory)1 RefAddr (javax.naming.RefAddr)1 Reference (javax.naming.Reference)1