Package net.sf.jeters.configuration

Examples of net.sf.jeters.configuration.Configuration


   
  }
 
  private void readComponentConfiguration(Class <? extends Component> componentClass) {
   
    Configuration classConf = retrieveBaseConfiguration(componentClass);
 
    for (ConfigurationReader configReader : configurationReaders) {
      Configuration newClassConf = configReader.read(componentClass);
      if (newClassConf != null) {
        classConf.setValuesFrom(newClassConf);
      }
    }
   
View Full Code Here


   * uses defaults where necessary
   */
  private Configuration retrieveBaseConfiguration(Class <? extends Component> componentClass) {
   
    //get defaults
    Configuration baseConf;
    try {
      baseConf = new Configuration((Class<Component>)componentClass, (Component)componentClass.newInstance());
    } catch (InstantiationException e) {
      throw new Error(e);
    } catch (IllegalAccessException e) {
      throw new Error(e);
    }
   
    //get values from component storage and overwrite defaults 
    if (configurationStorage != null) {
      Configuration confFromStorage = configurationStorage.read(componentClass);
      if (confFromStorage != null) {
        baseConf.setValuesFrom(confFromStorage);
      } else if (baseConf.getConfigurableFields().size() > 0) {
        System.out.println("no configuration found for " + componentClass.getSimpleName());
      }
View Full Code Here

   * in the configuration storage
   */
  public void writeAllComponentBaseConfigurations() {
   
    for (Class<? extends Component> componentClass : availableComponentClasses) {
      Configuration baseConf = retrieveBaseConfiguration(componentClass);
      writeComponentConfiguration(baseConf);
    }
   
  }
View Full Code Here

   */
  private void configureComponent(Component component) {

    assert component != null;

    Configuration configuration = configurationMap.get(component.getClass());
    if (configuration != null) {
      configuration.applyTo(component);
    }
   
  }
View Full Code Here

  }

  private void setChangedConfiguration() {

    Configuration configuration = new Configuration(configuredClass);

    for (int row = 0; row < table.getRowCount(); row++) {

      String fieldName = (String)table.getValueAt(row, 0);
      String valueString = (String)table.getValueAt(row, 1);

      Field field = null;
      for (Field f : configuration.getConfigurableFields()) {
        if (f.getName().equals(fieldName)) {
          field = f;
          break;
        }
      }

      if (field != null) {

        Object value = getValueForString(field, valueString);

        configuration.setValue(field, value);

      } else {
        throw new Error("unknown field in configuration table: " + fieldName);
      }
View Full Code Here

     
    if (!configFile.exists()) {
      return null;
    } else{
 
      Configuration configuration = new Configuration(configuredClass);
     
      try {
     
        //get a xml-document object from the file       
       
        Builder builder = new Builder();
       
        Document configurationDocument = builder.build(configFile);
       
        //get configuration set from the xml document
       
        Element xmlRootElement = configurationDocument.getRootElement();
       
        if( xmlRootElement == null ){
          System.out.println("error: file \"" + configFile + "\" is not a valid configuration file: <configuration>-tags missing");
        }
       
        else{
       
          Elements xmlConfigurationElements = xmlRootElement.getChildElements("conf");
         
          for( int xmlConfigurationElementIndex = 0; xmlConfigurationElementIndex < xmlConfigurationElements.size(); ++ xmlConfigurationElementIndex ){
           
            Element xmlConfigurationElement = xmlConfigurationElements.get(xmlConfigurationElementIndex);       
           
            String name = null;
            String type = null;
            boolean list = false;
           
            Attribute attributeName = xmlConfigurationElement.getAttribute("name");
            if( attributeName != null ){
              name = attributeName.getValue();
            }
            else{
              System.out.println("warning: configuration data partially invalid: no name attribute at \"conf\" child element " + String.valueOf(xmlConfigurationElementIndex) );
            }
           
            Attribute attributeType = xmlConfigurationElement.getAttribute("type");
            if( attributeType != null ){
              type = attributeType.getValue();
            }
            else{
              System.out.println("warning: configuration data partially invalid: no type attribute at \"conf\" child element " + String.valueOf(xmlConfigurationElementIndex) );
            }

            Attribute attributeList = xmlConfigurationElement.getAttribute("list");
            if( attributeList != null ){
              list = stringToBoolean(attributeList.getValue());
            }
           
            if (name != null && type != null) {
             
              Field field = null;
              for (Field f : configuration.getConfigurableFields()) {
                if (f.getName().equals(name)) {
                  field = f;
                  break;
                }
              }
             
              if (field != null) {
             
                if (!list) {
                       
                  String data = null;
                 
                  if( xmlConfigurationElement.getChildCount() > 0 ){             
                    Node dataText = xmlConfigurationElement.getChild(0);             
                    if( dataText != null ){
                      data = ((Text)dataText).getValue();
                    }
                  }
                                   
                  if (data == null) {
                    data = "";
                  }
                 
                  if (type.toLowerCase().equals("integer")) {
                    configuration.setValue(field, Integer.parseInt(data));
                  } else if (type.toLowerCase().equals("float")) {
                    configuration.setValue(field, Float.parseFloat(data));
                  } else if (type.toLowerCase().equals("string")) {
                    configuration.setValue(field, data);
                  } else if (type.toLowerCase().equals("boolean")) {
                    configuration.setValue(field, stringToBoolean(data))
                  }
                 
                } else { // list
                 
                  List<String> dataList = new LinkedList<String>();
                 
                  Elements childs = xmlConfigurationElement.getChildElements("entry");
                 
                  if (childs.size() > 0) {
                    for (int i = 0; i < childs.size(); i++) {
                      dataList.add(childs.get(i).getValue());           
                    }
                  } else {
                    //note: getChild also returns the element's text
                    Text text = (Text)xmlConfigurationElement.getChild(0);
                    if (text != null) {
                      dataList.add(text.getValue());
                    }
                  }
                 
                  if (type.toLowerCase().equals("integer")) { 
 
                    List<Integer> ints = new LinkedList<Integer>();
                    for (String data : dataList) {
                      ints.add(Integer.parseInt(data));
                    }
                   
                    configuration.setValue(field,
                        ints.toArray(new Integer[ints.size()]));
 
                  } else if (type.toLowerCase().equals("float")) {
                   
                    List<Float> floats = new LinkedList<Float>();
                    for (String data : dataList) {
                      floats.add(Float.parseFloat(data));
                    }
                   
                    configuration.setValue(field,
                        floats.toArray(new Float[floats.size()]));
 
                  } else if (type.toLowerCase().equals("string")) {
 
                    configuration.setValue(field,
                        dataList.toArray(new String[dataList.size()]));
 
                  } else if (type.toLowerCase().equals("boolean")) {
 
                    List<Boolean> bools = new LinkedList<Boolean>();
                    for (String data : dataList) {
                      bools.add(stringToBoolean(data));
                    }

                    configuration.setValue(field,
                        bools.toArray(new Boolean[bools.size()]));
 
                  }
                 
                }
View Full Code Here

   
     */
       
    ConfigurationStorage xmlConfigStorage = new XMLConfigurationWriter();
   
    Configuration coreConf = xmlConfigStorage.read(Core.class);
    if (coreConf != null) {
      coreConf.applyTo(this);
    }
   
    //FIXME: remove as soon as collection handling with the configs possible
    processCommandLineArguments(args);
   
    /* create component manager */
   
    File componentDir = new File(componentDirectoryPath);
   
    ConfigurationReader[] configReaders =
        { /*TODO: uncomment (see above) | commandLineConfigReader */ };
   
    TranslationReader transReader
      = new TranslationReader(localeFromConfiguration());
   
    componentManager =
      new ComponentManager(componentDir,
          xmlConfigStorage, configReaders, transReader);

    /* make sure there is a configuration file for all components
     * as well as for the core */
    componentManager.writeAllComponentBaseConfigurations();
    componentManager.writeComponentConfiguration(new Configuration(Core.class, this)); //TODO: only defaults

    /* set own translation */
    componentManager.setTranslation(this);
       
    /* create the default components */
 
View Full Code Here

TOP

Related Classes of net.sf.jeters.configuration.Configuration

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.