Package org.osgi.service.prefs

Examples of org.osgi.service.prefs.Preferences


        this.preferences = preferences;
    }

    public synchronized void afterPropertiesSet() throws Exception {
        try {
            Preferences prefs = preferences.getUserPreferences("AdminServiceState");
            Preferences child = prefs.node("Instances");
            int count = child.getInt("count", 0);
            Map<String, Instance> newInstances = new HashMap<String, Instance>();
            for (int i = 0; i < count; i++) {
                String name = child.get("item." + i + ".name", null);
                String loc = child.get("item." + i + ".loc", null);
                int pid = child.getInt("item." + i + ".pid", 0);
                if (name != null) {
                    InstanceImpl instance = new InstanceImpl(this, name, loc);
                    if (pid > 0) {
                        try {
                            instance.attach(pid);
View Full Code Here


        }
        File serviceMixBase = new File(location != null ? location : ("instances/" + name)).getCanonicalFile();
        int sshPort = port;
        if (sshPort <= 0) {
            try {
                Preferences prefs = preferences.getUserPreferences("AdminServiceState");
                sshPort = prefs.getInt("port", defaultPortStart + 1);
                prefs.putInt("port", sshPort + 1);
                prefs.flush();
                prefs.sync();
            } catch (Exception e) {
                try {
                    ServerSocket ss = new ServerSocket(0);
                    sshPort = ss.getLocalPort();
                    ss.close();
View Full Code Here

    synchronized void forget(String name) {
        instances.remove(name);
    }

    synchronized void saveState() throws IOException, BackingStoreException {
        Preferences prefs = preferences.getUserPreferences("AdminServiceState");
        Preferences child = prefs.node("Instances");
        child.clear();
        Instance[] data = getInstances();
        child.putInt("count", data.length);
        for (int i = 0; i < data.length; i++) {
            child.put("item." + i + ".name", data[i].getName());
            child.put("item." + i + ".loc", data[i].getLocation());
            child.putInt("item." + i + ".pid", data[i].getPid());
        }
        prefs.flush();
        prefs.sync();
    }
View Full Code Here

     * Helper method for login.
     */
    private Preferences getRepositoryPrefs(Preferences userPrefs, URL location, String customer, String name) {
        // Note: we can only use the getAuthority part of the URL for indexing, because the full URL will contain
        // in the protocol part.
        Preferences repoPref = userPrefs.node(location.getAuthority() + location.getPath());
        Preferences customerPref = repoPref.node(customer);
        return customerPref.node(name);
    }
View Full Code Here

            .setImplementation(repo)
            .add(m_dm.createServiceDependency()
                .setService(ConnectionFactory.class)
                .setRequired(true)));

        Preferences prefs = m_preferences.getUserPreferences(user.getName());
        prefs = prefs.node(m_sessionID);
        Preferences repoPrefs = getRepositoryPrefs(prefs, rsd.m_location, rsd.m_customer, rsd.m_name);

        return new RepositorySet(m_changeNotifier, m_log, user, repoPrefs, repos, getCachedRepositoryFromPreferences(repo, repoPrefs), rsd.m_name, rsd.m_writeAccess);
    }
View Full Code Here

        return new RepositorySet(m_changeNotifier, m_log, user, repoPrefs, repos, getCachedRepositoryFromPreferences(repo, repoPrefs), rsd.m_name, rsd.m_writeAccess);
    }

    private void unloadRepositorySet(User user) {
        Preferences prefs = m_preferences.getUserPreferences(user.getName());
        prefs.remove(m_sessionID);
    }
View Full Code Here

    /* ********
     * Preferences
     * ********/

    void savePreferences() {
        Preferences workingNode = m_prefs.node(PREFS_LOCAL_WORKING_STATE);
        try {
            workingNode.clear();
        }
        catch (BackingStoreException e) {
            // Something went wrong clearing the node... Too bad, this means we
            // cannot store the properties.
            m_log.log(LogService.LOG_WARNING, "Could not store all preferences for " + workingNode.absolutePath());
            e.printStackTrace();
        }
       
        for (Map.Entry<RepositoryObject, WorkingState> entry : m_workingState.entrySet()) {
            workingNode.node(entry.getKey().getDefinition()).put(PREFS_LOCAL_WORKING_STATE_VALUE, entry.getValue().toString());
        }

        m_prefs.putLong(PREFS_LOCAL_FILE_VERSION, m_repository.getMostRecentVersion());
    }
View Full Code Here

    /**
     * Only call this after the repository has been deserialized.
     */
    @SuppressWarnings("unchecked")
    void loadPreferences() {
        Preferences workingNode = m_prefs.node(PREFS_LOCAL_WORKING_STATE);
        Map<String, WorkingState> entries = new HashMap<String, WorkingState>();
        // First, get all nodes and their workingstate.
        try {
            String defaultWorkingState = WorkingState.Unchanged.toString();

            for (String node : workingNode.childrenNames()) {
                String state = workingNode.node(node).get(PREFS_LOCAL_WORKING_STATE_VALUE, defaultWorkingState);
                entries.put(node, WorkingState.valueOf(state));
            }
        }
        catch (BackingStoreException e) {
            // Something went wrong reading from the store, just work with whatever we have in the map.
            m_log.log(LogService.LOG_WARNING, "Could not load all preferences for " + workingNode.absolutePath());
            e.printStackTrace();
        }
        // Then, go through all objects and check whether they match a definition we know.
        // This prevents calling getDefinition more than once per object.
        for (ObjectRepository<RepositoryObject> repo : m_repos) {
View Full Code Here

            store.updated(isMaster, limitValue);
        }
    }

    private void createRepositoryPrefs(String pid, String customer, String name) throws ConfigurationException {
        Preferences systemPrefs = m_prefsService.getSystemPreferences();

        String[] nodes;
        try {
            nodes = systemPrefs.childrenNames();
        }
        catch (BackingStoreException e) {
            throw new ConfigurationException(null, "Internal error while validating configuration.");
        }
        for (String nodeName : nodes) {
            if (pid.equals(nodeName)) {
                // avoid failing on our own node (in case we're updating)...
                continue;
            }

            Preferences prefs = systemPrefs.node(nodeName);
            String repoName = prefs.get(REPOSITORY_NAME, "");
            String repoCustomer = prefs.get(REPOSITORY_CUSTOMER, "");

            if (name.equalsIgnoreCase(repoName) && name.equalsIgnoreCase(repoCustomer)) {
                throw new ConfigurationException(null, "Name and customer combination already exists");
            }
        }

        Preferences node = systemPrefs.node(pid);
        node.put(REPOSITORY_NAME, name);
        node.put(REPOSITORY_CUSTOMER, customer);
    }
View Full Code Here

        return store;
    }

    private void deleteRepositoryPrefs(String pid) {
        try {
            Preferences prefs = m_prefsService.getSystemPreferences();

            prefs.node(pid).removeNode();
            prefs.sync();
        }
        catch (BackingStoreException e) {
            // Not much we can do
        }
    }
View Full Code Here

TOP

Related Classes of org.osgi.service.prefs.Preferences

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.