Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package org.apache.aries.jmx.cm;
 
 import static org.osgi.jmx.JmxConstants.PROPERTIES_TYPE;
 
 import java.util.List;
 
 
Implementation of ConfigurationAdminMBean

Version:
$Rev: 953097 $ $Date: 2010-06-09 13:48:01 -0400 (Wed, 09 Jun 2010) $
 
 public class ConfigurationAdmin implements ConfigurationAdminMBean {
 
     private org.osgi.service.cm.ConfigurationAdmin configurationAdmin;
    
    
Constructs a ConfigurationAdmin implementation

Parameters:
configurationAdmin instance of org.osgi.service.cm.ConfigurationAdmin service
 
     public ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin configurationAdmin) {
         this. = configurationAdmin;
     }
    
    
    
 
     public String createFactoryConfiguration(String factoryPidthrows IOException {
         return createFactoryConfigurationForLocation(factoryPidnull); 
     }

    
 
     public String createFactoryConfigurationForLocation(String factoryPidString locationthrows IOException {
         if (factoryPid == null || factoryPid.length() < 1) {
             throw new IOException("Argument factoryPid cannot be null or empty");
         }
         Configuration config = .createFactoryConfiguration(factoryPid);
         config.setBundleLocation(location);
         return config.getPid();
     }

    
 
     public void delete(String pidthrows IOException {
        deleteForLocation(pidnull);
     }

    
 
     public void deleteForLocation(String pidString locationthrows IOException {
         if (pid == null || pid.length() < 1) {
             throw new IOException("Argument pid cannot be null or empty");
         }
         Configuration config = .getConfiguration(pidlocation);
         config.delete();
     }

    
 
     public void deleteConfigurations(String filterthrows IOException {
         if (filter == null || filter.length() < 1) {
             throw new IOException("Argument filter cannot be null or empty");
         }
        Configuration[] configuations = null;
        try {
            configuations = .listConfigurations(filter);
        } catch (InvalidSyntaxException e) {
            throw new IOException("Invalid filter [" + filter + "] : " + e);
        }
        if (configuations != null) {
            for (Configuration config : configuations) {
                config.delete();
            }
        }
    }

    
    public String getBundleLocation(String pidthrows IOException {
        if (pid == null || pid.length() < 1) {
            throw new IOException("Argument pid cannot be null or empty");
        }
        Configuration config = .getConfiguration(pidnull);
        String bundleLocation = (config.getBundleLocation() == null) ? "Configuration is not yet bound to a bundle location" : config.getBundleLocation();
        return bundleLocation;
    }

    
    public String[][] getConfigurations(String filterthrows IOException {
        if (filter == null || filter.length() < 1) {
            throw new IOException("Argument filter cannot be null or empty");
        }
        List<String[]> result = new ArrayList<String[]>();
        Configuration[] configurations = null;
        try {
            configurations = .listConfigurations(filter);
        } catch (InvalidSyntaxException e) {
            throw new IOException("Invalid filter [" + filter + "] : " + e);
        }
        if (configurations != null) {
            for (Configuration config : configurations) {
                result.add(new String[] { config.getPid(), config.getBundleLocation() });
            }
        }
        return result.toArray(new String[result.size()][]);
    }

    
    public String getFactoryPid(String pidthrows IOException {
       return getFactoryPidForLocation(pidnull);
    }

    
    public String getFactoryPidForLocation(String pidString locationthrows IOException {
        if (pid == null || pid.length() < 1) {
            throw new IOException("Argument pid cannot be null or empty");
        }
        Configuration config = .getConfiguration(pidlocation);
        return config.getFactoryPid();
    }

    
    public TabularData getProperties(String pidthrows IOException {
       return getPropertiesForLocation(pidnull);
    }

    
    @SuppressWarnings("unchecked")
    public TabularData getPropertiesForLocation(String pidString locationthrows IOException {
        if (pid == null || pid.length() < 1) {
            throw new IOException("Argument pid cannot be null or empty");
        }
        TabularData propertiesTable = null;
        Configuration config = .getConfiguration(pidlocation);
        Dictionary<StringObjectproperties = config.getProperties();
        if (properties != null) {
            propertiesTable = new TabularDataSupport();
            Enumeration<Stringkeys = properties.keys();
            while (keys.hasMoreElements()) {
                String key = keys.nextElement();
                propertiesTable.put(PropertyData.newInstance(keyproperties.get(key)).toCompositeData());
            }
        }
        return propertiesTable;
    }

    
    public void setBundleLocation(String pidString locationthrows IOException {
        if (pid == null || pid.length() < 1) {
            throw new IOException("Argument factoryPid cannot be null or empty");
        }
        Configuration config = .getConfiguration(pidnull);
        config.setBundleLocation(location);
    }

    
    public void update(String pidTabularData configurationTablethrows IOException {
        updateForLocation(pidnullconfigurationTable);
    }

    
    @SuppressWarnings("unchecked")
    public void updateForLocation(String pidString locationTabularData configurationTablethrows IOException {
        if (pid == null || pid.length() < 1) {
            throw new IOException("Argument pid cannot be null or empty");
        }
        if (configurationTable == null) {
            throw new IOException("Argument configurationTable cannot be null");
        }
                
        if (!.equals(configurationTable.getTabularType())) {
            throw new IOException("Invalid TabularType ["  + configurationTable.getTabularType() + "]");
        }
        Dictionary<StringObjectconfigurationProperties = new Hashtable<StringObject>();
        Collection<CompositeDatacompositeData = (Collection<CompositeData>) configurationTable.values();
        for (CompositeData rowcompositeData) {
            PropertyData<? extends ClasspropertyData = PropertyData.from(row);
            configurationProperties.put(propertyData.getKey(), propertyData.getValue());
        }
        Configuration config = .getConfiguration(pidlocation);
        config.update(configurationProperties);
    }
New to GrepCode? Check out our FAQ X