⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 abstractconfigurator.java

📁 jxta_src_2.41b jxta 2.41b 最新版源码 from www.jxta.org
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        if (this.configurator == null) {            this.configurator = new Configurator(this.home, this.profile);                        if (this.platformConfig != null) {                this.configurator.setPlatformConfig(this.platformConfig);            }                        this.configurator.setReconfigure(this.reconfigure);        }                File cf = new File(f, Env.PLATFORM_CONFIG);        PlatformConfig pc = null;                try {            pc = this.configurator.load(cf);        } catch (ConfiguratorException ce) {            if (LOG.isEnabledFor(Level.INFO)) {                LOG.info("invalid platform config: " +                (cf != null ? cf.getAbsoluteFile() : null), ce);            }        }                if (pc == null) {            try {                pc = createPlatformConfig(this.configurator);            } catch (ConfiguratorException ce) {                if (LOG.isEnabledFor(Level.INFO)) {                    LOG.info("invalid PlatformConfig creation", ce);                }                                throw ce;            }        }                this.configurator.setPlatformConfig(pc);                try {            pc = updatePlatformConfig(this.configurator);        } catch (ConfiguratorException ce) {            if (LOG.isEnabledFor(Level.INFO)) {                LOG.info("invalid PlatformConfig update", ce);            }                        throw ce;        }                if (this.persist) {        try {            this.configurator.save(cf);        } catch (ConfiguratorException ce) {            if (LOG.isEnabledFor(Level.INFO)) {                LOG.info("unable to persist PlatformConfig: " +                    (cf != null ? cf.toString() : null), ce);            }                        throw ce;        }        }                return pc;    }            /**     * Acessor to backing Configurator     *     * @return Configurator     */        public Configurator getConfigurator() {        return this.configurator;    }        /**     * {@inheritDoc}     */        public void setPlatformConfig(PlatformConfig config) {        if (this.configurator != null) {            this.configurator.setPlatformConfig(config);        } else {            this.platformConfig = config;        }    }        /**     * {@inheritDoc}     */        public ConfigParams getConfigParams()    throws ConfiguratorException {        return this.configurator != null ?            this.configurator.getConfigParams() :            (ConfigParams)this.platformConfig;    }        /**     * {@inheritDoc}     */        public void setConfigParams(ConfigParams cp) {        setPlatformConfig((PlatformConfig)cp);    }        /**     * {@inheritDoc}     */        public void setReconfigure(boolean reconfigure) {        if (this.configurator != null) {            this.configurator.setReconfigure(reconfigure);        } else {            this.reconfigure = reconfigure;        }    }        /**     * {@inheritDoc}     */        public ConfigParams load()    throws ConfiguratorException {        ConfigParams cp = null;                if (this.configurator != null) {            cp = this.configurator.load();        } else {            throw new IllegalStateException("null configurator");        }                return cp;    }        /**     * {@inheritDoc}     */    public PlatformConfig load(File pc)    throws ConfiguratorException {        PlatformConfig p = null;                if (this.configurator != null) {            p = this.configurator.load(pc);        } else {            throw new IllegalStateException("null configurator");        }                return p;    }        /**     * {@inheritDoc}     */    public boolean isReconfigure() {        return this.configurator != null ?            this.configurator.isReconfigure() : this.reconfigure;    }        /**     * {@inheritDoc}     */    public boolean save()    throws ConfiguratorException {        URI jh = getJxtaHome();        // xxx: assume File based for the moment        File f = null;                try {            f = Conversion.toFile(jh);        } catch (ConversionException ce) {            if (LOG.isEnabledFor(Level.ERROR)) {                LOG.error("can't convert uri to file: " + jh, ce);            }        }                return save(f);    }        /**     * {@inheritDoc}     */    public boolean save(File f)    throws ConfiguratorException {        if (this.configurator == null) {            configure();        }                return this.configurator.save(f);    }        private void init() {	if (this.home == null) {	    URI u = null;            if (this.profile != null) {		try {                    u = this.profile.getProfile().getURI(Profile.Key.HOME_ADDRESS);                } catch (ConversionException ce) {		}	    }            this.home = u != null ? u : Env.JXTA_HOME.toURI(); //Default.HOME_ADDRESS;	}        // register the default resources	// xxx: should specify provided profile else default//        addResource(PROFILE_KEY, DEFAULT_PROFILE);//        addResource(JXTA_PROPERTIES_KEY, DEFAULT_JXTA_PROPERTIES);        // turn off the default Platform Configurator        Configurator.setConfigurator(NullConfigurator.class);    }    private void manageResources(File f) {               f.mkdirs();        for (Iterator r = getResourceKeys(); r.hasNext(); ) {            String key = (String)r.next();            String value = (String)getResource(key);            File fr = new File(f, key);            if (! fr.exists()) {                InputStream is = getClass().getResourceAsStream(value);		if (is == null) {		    try {                        is = new URL(value).openStream();		    } catch (MalformedURLException mue) {                        if (LOG.isEnabledFor(Level.DEBUG)) {                            LOG.debug("can't open resource: " + value, mue);                        }		    } catch (IOException ioe) {                        if (LOG.isEnabledFor(Level.DEBUG)) {                            LOG.debug("can't open resource: " + value, ioe);                        }		    }		}                                if (is != null) {                    BufferedOutputStream bos = null;                                        try {                        fr.createNewFile();                                                bos = new BufferedOutputStream(new FileOutputStream(fr));                                                int c = -1;                                                while ((c = is.read()) > -1) {                            bos.write(c);                        }                                                bos.flush();                    } catch (IOException ioe) {                        if (LOG.isEnabledFor(Level.ERROR)) {                            LOG.error("can't persist resource: " + fr.getName(),                                ioe);                        }                    } finally {                        if (is != null) {                            try {                                is.close();                            } catch (IOException ioe) {}                        }                                                if (bos != null) {                            try {                                bos.close();                            } catch (IOException ioe) {}                        }                    }                }            }        }                manageConfigProperties(f);    }        private void manageConfigProperties(File f) {        File cf = new File(f, CONFIG_PROPERTIES_KEY);        File pf = new File(f, PROFILE_KEY);               if (! cf.exists()) {            String nid = null;            String nidu = null;            String nnm = null;            String nds = null;                        if (this.configurator != null) {                PeerGroupID pgid = this.configurator.getInfrastructurePeerGroupId();                                nid = pgid != null ? pgid.toURI().toString() : null;                nidu = pgid != null ? pgid.getUniqueValue().toString() : null;                nnm = this.configurator.getInfrastructurePeerGroupName();                nds = this.configurator.getInfrastructurePeerGroupDescription();            }	    if (nid == null) {                Resource r = null;		String pk = getResource(PROFILE_KEY);				if (this.profile != null) {                    r = this.profile.getProfile();		} else if (pf.exists()) {                    r = new Resource();		    try {			r.load(pf);		    } catch (MalformedURLException mue) {                        if (LOG.isEnabledFor(Level.DEBUG)) {                            LOG.debug("invalid resource url: " + pf);                        }		    } catch (ResourceNotFoundException rnfe) {                        if (LOG.isEnabledFor(Level.DEBUG)) {                            LOG.debug("resource not found: " + pf);                        }		    }		} else if (pk != null) {                    r = new Resource();		    try {		        r.load(pk);		    } catch (ResourceNotFoundException rnfe) {                        if (LOG.isEnabledFor(Level.DEBUG)) {                            LOG.debug("resource not found: " + pk);                        }		    }		}                                nid = r.get(Profile.Key.NETWORK_ID);                nnm = r.get(Profile.Key.NETWORK_NAME);                nds = r.get(Profile.Key.NETWORK_DESCRIPTION);               	        if (nid != null) {                    ID id = null;                                        try {                        id = PeerGroupID.create(new URI(nid));                    } catch (URISyntaxException use) {                        if (LOG.isEnabledFor(Level.DEBUG)) {                            LOG.debug("invalid " + CONFIG_PROPERTIES_KEY + " " +                                Env.NETWORK_ID_KEY + ": " + nid, use);                        }                        nid = null;                    }                                    if (id != null) {                      nidu = id.getUniqueValue().toString();                  }		}	    }                        nid = nid != null ? nid.trim() : null;            nidu = nidu != null ? nidu.trim() : null;            nnm = nnm != null ? nnm.trim() : null;            nds = nds != null ? nds.trim() : null;             if (nidu != null) {                Properties p = new Properties();                                p.put(Env.NETWORK_ID_KEY, nidu);                if (nnm != null) {                    p.put(Env.NETWORK_NAME_KEY, nnm);                }                if (nds != null) {                    p.put(Env.NETWORK_DESCRIPTION_KEY, nds);                }                try {                    p.store(new FileOutputStream(cf), CONFIG_PROPERTIES_COMMENT);                } catch (FileNotFoundException fnfe) {                    if (LOG.isEnabledFor(Level.ERROR)) {                        LOG.error("can't write config.properties: " + cf, fnfe);                    }                } catch (IOException ioe) {                    if (LOG.isEnabledFor(Level.ERROR)) {                        LOG.error("can't write config.properties: " + cf, ioe);                    }                }            }         }     }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -