Example usage for java.net URLClassLoader setPackageAssertionStatus

List of usage examples for java.net URLClassLoader setPackageAssertionStatus

Introduction

In this page you can find the example usage for java.net URLClassLoader setPackageAssertionStatus.

Prototype

public void setPackageAssertionStatus(String packageName, boolean enabled) 

Source Link

Document

Sets the package default assertion status for the named package.

Usage

From source file:org.sipfoundry.openfire.plugin.presence.SipXOpenfirePlugin.java

@SuppressWarnings("resource")
@Override//from  w w w. j a v  a2s. c  o  m
public void initializePlugin(PluginManager manager, File pluginDirectory) {
    SipXOpenfirePlugin.instance = this;

    InputStream in = getClass().getResourceAsStream("/config.properties");
    Properties properties = new Properties();

    try {
        properties.load(in);
    } catch (IOException ex) {
        log.error(ex);
    } finally {
        IOUtils.closeQuietly(in);
    }

    try {
        if (new File("/tmp/sipx.properties").exists()) {
            System.getProperties().load(new FileInputStream(new File("/tmp/sipx.properties")));
        }
    } catch (Exception ex) {
        log.error(ex);
        throw new SipXOpenfirePluginException("Error reading config file ", ex);
    }
    configurationPath = System.getProperty("conf.dir", "/etc/sipxpbx");

    try {
        UnfortunateLackOfSpringSupportFactory.initialize();
        initConferenceService();
    } catch (Exception e) {
        e.printStackTrace();
    }

    parseConfigurationFile();

    initializeLogging();
    log.info(">>>>>>>>STARTING " + SipXOpenfirePlugin.class + "<<<<<<<<");

    pluginManager = manager;
    ClassLoader classLoader = pluginManager.getPluginClassloader(this);

    try {
        // add this directory to classpath so ResouceBundle class can find
        // resources (language specific properties files) there
        URL url = new URL("file:" + configurationPath + "/openfire/");

        URLClassLoader urlClassLoader = new URLClassLoader(new URL[] { url }, classLoader);

        urlClassLoader.setPackageAssertionStatus("org.sipfoundry", true);

        Thread.currentThread().setContextClassLoader(urlClassLoader);

        String locale = watcherConfig.getLocale();
        this.localizer = new Localizer(locale, urlClassLoader);
    } catch (MalformedURLException e1) {
        log.error("can't update classpath: " + e1.getMessage());
    }

    server = XMPPServer.getInstance();

    userManager = server.getUserManager();
    presenceManager = server.getPresenceManager();

    hostname = server.getServerInfo().getXMPPDomain();
    log.info("HostName = " + hostname);

    probedPresence = new ConcurrentHashMap<String, Presence>();

    groupManager = GroupManager.getInstance();

    multiUserChatManager = server.getMultiUserChatManager();

    //Initialize BookmarkManager
    SipXBookmarkManager.initialize(pluginManager);
    log.info("Bookmark Manager initialized: " + SipXBookmarkManager.isInitialized());

    /*
     * Create default multi-user chat service (see XX-6913) and remove others
     */
    createChatRoomService(DEFAULT_MUC_SERVICE);
    Collection<String> defaultSubdomain = new ArrayList<String>();
    defaultSubdomain.add(DEFAULT_MUC_SERVICE);
    try {
        pruneChatServices(defaultSubdomain);
    } catch (Exception ex) {
        log.error("initializePlugin caught exception while pruning chat services list ", ex);
    }

    /*
     * Update the server to server (s2s) settings
     */
    try {
        // Get the object instance that stores the server to server
        // generated by the sipXconfig side.
        XmppS2sInfo xmppS2sInfo = watcherConfig.getS2sInfo();

        xmppS2sInfo.updateS2sSettings();
    } catch (Exception ex) {
        log.error("initializePlugin caught exception while updating s2s settings ", ex);
    }

    /*
     * Load up the database.
     */
    log.info("hostname " + hostname);
    String watchFile = configurationPath + "/xmpp-update.xml";
    this.accountsParser = new AccountsParser(watchFile, m_conferenceService, watcherConfig.isEnableParsing());
    this.accountsParser.startScanner();

    // config and instantiate and the presence unifier used to gather all presence info
    PresenceUnifier.setPlugin(this);
    PresenceUnifier.getInstance();

    addInterceptor(new DefaultMessagePacketInterceptor());

    // add packet interceptors found in extras directory.
    if (this.getClass().getClassLoader() instanceof PluginClassLoader) {

        String extrasDirNameForClassLoader = System.getProperty("openfire.home");
        if (extrasDirNameForClassLoader != null) {
            extrasDirNameForClassLoader += "/extras/sipXecs";
            log.info("extras directory is " + extrasDirNameForClassLoader);
            /* PluginClassLoader automatically adds /lib to the supplied directory
               so pass it a directory that does not already have it */
            PluginClassLoader pluginClassLoader = (PluginClassLoader) this.getClass().getClassLoader();
            pluginClassLoader.addDirectory(new File(extrasDirNameForClassLoader), false);

            String extrasDirName = extrasDirNameForClassLoader + "/lib";
            File extrasDir = new File(extrasDirName);
            loadExtras(pluginClassLoader, extrasDir);
        } else {
            log.error("Could not determine the extras directory name " + System.getProperties());
        }
    }

    if (watcherConfig.isImMessageLoggingEnabled()) {
        addInterceptor(new ImLogger(watcherConfig.getImMessageLoggingDirectory()));
    }

    log.info("plugin initializaton completed");
    log.info("DONE");

    isInitialized = true;
}