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.felix.karaf.features.management.codec;
 
 import java.util.List;
 import java.util.Map;
 
 
 
 public class JmxFeature {

    
The CompositeType which represents a single feature
 
     public final static CompositeType FEATURE;

    
The TabularType which represents a list of features
 
     public final static TabularType FEATURE_TABLE;
 
     public final static CompositeType FEATURE_IDENTIFIER;
 
     public final static TabularType FEATURE_IDENTIFIER_TABLE;
 
     public final static CompositeType FEATURE_CONFIG_ELEMENT;
 
     public final static TabularType FEATURE_CONFIG_ELEMENT_TABLE;
 
     public final static CompositeType FEATURE_CONFIG;
 
     public final static TabularType FEATURE_CONFIG_TABLE;
 
 
     private final CompositeData data;
 
     public JmxFeature(Feature featureboolean installed) {
         try {
             String[] itemNames = .;
             Object[] itemValues = new Object[itemNames.length];
             itemValues[0] = feature.getName();
             itemValues[1] = feature.getVersion();
             itemValues[2] = getFeatureIdentifierTable(feature.getDependencies());
             itemValues[3] = feature.getBundles().toArray(new String[feature.getBundles().size()]);
             itemValues[4]  = getConfigTable(feature.getConfigurations());
             itemValues[5] = installed;
              = new CompositeDataSupport(itemNamesitemValues);
         } catch (OpenDataException e) {
             throw new IllegalStateException("Cannot form feature open data"e);
         }
     }
 
     public CompositeData asCompositeData() {
         return ;
     }
 
     public static TabularData tableFrom(Collection<JmxFeaturefeatures) {
         TabularDataSupport table = new TabularDataSupport();
         for (JmxFeature feature : features) {
             table.put(feature.asCompositeData());
         }
         return table;
     }
 
     static TabularData getFeatureIdentifierTable(List<Featurefeaturesthrows OpenDataException {
         for (Feature feature : features) {
             String[] itemNames = new String[] { .. };
             Object[] itemValues = new Object[] { feature.getName(), feature.getVersion() };
             CompositeData ident = new CompositeDataSupport(itemNamesitemValues);
             table.put(ident);
         }
        return table;
    }
    static TabularData getConfigTable(Map<StringMap<StringString>> configsthrows OpenDataException {
        for (Map.Entry<StringMap<StringString>> entry : configs.entrySet()) {
            String[] itemNames = .;
            Object[] itemValues = new Object[2];
            itemValues[0] = entry.getKey();
            itemValues[1] = getConfigElementTable(entry.getValue());
            CompositeData config = new CompositeDataSupport(itemNamesitemValues);
            table.put(config);
        }
        return table;
    }
    static TabularData getConfigElementTable(Map<StringStringconfigthrows OpenDataException {
        for (Map.Entry<StringStringentry : config.entrySet()) {
            String[] itemNames = .;
            Object[] itemValues = { entry.getKey(), entry.getValue() };
            CompositeData element = new CompositeDataSupport(itemNamesitemValues);
            table.put(element);
        }
        return table;
    }
    static {
         = createFeatureType();
    }
    private static CompositeType createFeatureIdentifierType() {
        try {
            String description = "This type identify a Karaf features";
            String[] itemNames = .;
            OpenType[] itemTypes = new OpenType[itemNames.length];
            String[] itemDescriptions = new String[itemNames.length];
            itemTypes[0] = .;
            itemTypes[1] = .;
            itemDescriptions[0] = "The id of the feature";
            itemDescriptions[1] = "The version of the feature";
            return new CompositeType("FeatureIdentifier"descriptionitemNames,
                    itemDescriptionsitemTypes);
        } catch (OpenDataException e) {
            throw new IllegalStateException("Unable to build featureIdentifier type"e);
        }
    }
    private static TabularType createFeatureIdentifierTableType() {
        try {
            return new TabularType("Features""The table of featureIdentifiers",
                    new String[] { .. });
        } catch (OpenDataException e) {
            throw new IllegalStateException("Unable to build featureIdentifier table type"e);
        }
    }
    private static CompositeType createFeatureConfigElementType() {
        try {
            String description = "This type encapsulates Karaf feature config element";
            String[] itemNames = .;
            OpenType[] itemTypes = new OpenType[itemNames.length];
            String[] itemDescriptions = new String[itemNames.length];
            itemTypes[0] = .;
            itemTypes[1] = .;
            itemDescriptions[0] = "The key";
            itemDescriptions[1] = "The value";
            return new CompositeType("ConfigElement"descriptionitemNames,
                    itemDescriptionsitemTypes);
        } catch (OpenDataException e) {
            throw new IllegalStateException("Unable to build configElement type"e);
        }
    }
        try {
            return new TabularType("ConfigElement""The table of configurations elements",
                    new String[] { .});
        } catch (OpenDataException e) {
            throw new IllegalStateException("Unable to build feature table type"e);
        }
    }
    private static CompositeType createFeatureConfigType() {
        try {
            String description = "This type encapsulates Karaf feature config";
            String[] itemNames = .;
            OpenType[] itemTypes = new OpenType[itemNames.length];
            String[] itemDescriptions = new String[itemNames.length];
            itemTypes[0] = .;
            itemTypes[1] = ;
            itemDescriptions[0] = "The PID of the config";
            itemDescriptions[1] = "The configuration elements";
            return new CompositeType("Config"descriptionitemNames,
                    itemDescriptionsitemTypes);
        } catch (OpenDataException e) {
            throw new IllegalStateException("Unable to build configElement type"e);
        }
    }
    private static TabularType createFeatureConfigTableType() {
        try {
            return new TabularType("Features""The table of configurations",
                    new String[] { .});
        } catch (OpenDataException e) {
            throw new IllegalStateException("Unable to build feature table type"e);
        }
    }
    private static CompositeType createFeatureType() {
        try {
            String description = "This type encapsulates Karaf features";
            String[] itemNames = .;
            OpenType[] itemTypes = new OpenType[itemNames.length];
            String[] itemDescriptions = new String[itemNames.length];
            itemTypes[0] = .;
            itemTypes[1] = .;
            itemTypes[2] = ;
            itemTypes[3] = new ArrayType(1, .);
            itemTypes[4] = ;
            itemTypes[5] = .;
            itemDescriptions[0] = "The name of the feature";
            itemDescriptions[1] = "The version of the feature";
            itemDescriptions[2] = "The feature dependencies";
            itemDescriptions[3] = "The feature bundles";
            itemDescriptions[4] = "The feature configurations";
            itemDescriptions[5] = "Whether the feature is installed";
            return new CompositeType("Feature"descriptionitemNames,
                    itemDescriptionsitemTypes);
        } catch (OpenDataException e) {
            throw new IllegalStateException("Unable to build feature type"e);
        }
    }
    private static TabularType createFeatureTableType() {
        try {
            return new TabularType("Features""The table of all features",
                    new String[] { .. });
        } catch (OpenDataException e) {
            throw new IllegalStateException("Unable to build feature table type"e);
        }
    }
New to GrepCode? Check out our FAQ X