Package ca.nengo.config.impl

Examples of ca.nengo.config.impl.ConfigurationImpl


 
  /**
   * @return Custom Configuration (to more cleanly handle properties in 1D)
   */
  public Configuration getConfiguration() {
    ConfigurationImpl result = ConfigUtil.defaultConfiguration(this);
    result.removeProperty("units");
    result.removeProperty("units1D");
    result.removeProperty("values");
    result.removeProperty("values1D");
    result.removeProperty("labels");
   
    try {
      Method unitsGetter = this.getClass().getMethod("getUnits1D", new Class[0]);
      Method unitsSetter = this.getClass().getMethod("setUnits", new Class[]{Units.class});
      result.defineProperty(new SingleValuedPropertyImpl(result, "units", Units.class, unitsGetter, unitsSetter));
     
      Method valuesGetter = this.getClass().getMethod("getValues1D", new Class[0]);
      result.defineProperty(new SingleValuedPropertyImpl(result, "values", float[].class, valuesGetter));

      final Method labelGetter = this.getClass().getMethod("getLabels", new Class[0]);
      Method labelSetter = this.getClass().getMethod("setLabel", new Class[]{String.class});
      SingleValuedProperty labelProp = new SingleValuedPropertyImpl(result, "label", String.class, labelGetter, labelSetter) {

        @Override
        public Object getValue() {
          Object result = null;
          try {
            Object configurable = getConfiguration().getConfigurable();
            String[] labels = (String[]) labelGetter.invoke(configurable, new Object[0]);
            result = labels[0];
          } catch (Exception e) {
            throw new RuntimeException("Can't get label value", e);
          }
          return result;
        }
       
      };
      result.defineProperty(labelProp);
    } catch (SecurityException e) {
      throw new RuntimeException("Can't access getter/setter -- this is a bug", e);
    } catch (NoSuchMethodException e) {
      throw new RuntimeException("Can't access getter/setter -- this is a bug", e);
    }
View Full Code Here


   * @param configurable An Object
   * @return A default Configuration with properties of the object, based on reflection of the
   *     object's getters and setters.
   */
  public static ConfigurationImpl defaultConfiguration(Object configurable) {
    ConfigurationImpl result = new ConfigurationImpl(configurable);

    Method[] methods = configurable.getClass().getMethods();
    for (int i = 0; i < methods.length; i++) {
      Class<?> returnType = methods[i].getReturnType();
      String propName = getPropertyName(methods[i]);

      if (isSingleValueGetter(methods[i])
          && !methods[i].getName().equals("getClass")
          && !methods[i].getName().equals("getConfiguration")
          && !isCounter(methods[i])) {

        result.defineSingleValuedProperty(propName, returnType, false);
      } else if (isIndexedGetter(methods[i]) && !result.getPropertyNames().contains(propName)) {
        Property p = ListPropertyImpl.getListProperty(result, propName, returnType);
        if (p != null) {
                    result.defineProperty(p);
                }
      } else if (isNamedGetter(methods[i]) && !result.getPropertyNames().contains(propName)) {
        Property p = NamedValuePropertyImpl.getNamedValueProperty(result, propName, returnType);
        if (p != null) {
                    result.defineProperty(p);
                }
      }
    }

    //look for additional array, list, and map getters
    for (int i = 0; i < methods.length; i++) {
      Type returnType = methods[i].getGenericReturnType();
      String propName = getPropertyName(methods[i]);

      if (isGetter(methods[i]) && !isNamesGetter(methods[i]) && !result.getPropertyNames().contains(propName)
          && !result.getPropertyNames().contains(stripSuffix(propName, "s"))
          && !result.getPropertyNames().contains(stripSuffix(propName, "es"))) {

        Property p = null;
        if (returnType instanceof Class<?> && MainHandler.getInstance().canHandle((Class<?>) returnType)) {
          p = SingleValuedPropertyImpl.getSingleValuedProperty(result, propName, (Class<?>) returnType);
        } else if (returnType instanceof Class<?> && ((Class<?>) returnType).isArray()) {
          p = ListPropertyImpl.getListProperty(result, propName, ((Class<?>) returnType).getComponentType());
        } else if (returnType instanceof ParameterizedType) {
          Type rawType = ((ParameterizedType) returnType).getRawType();
          Type[] typeArgs = ((ParameterizedType) returnType).getActualTypeArguments();
          if (rawType instanceof Class<?> && List.class.isAssignableFrom((Class<?>) rawType)
              && typeArgs[0] instanceof Class<?>) {
            p = ListPropertyImpl.getListProperty(result, propName, (Class<?>) typeArgs[0]);
          } else if (rawType instanceof Class<?> && Map.class.isAssignableFrom((Class<?>) rawType)
              && typeArgs[0] instanceof Class<?> && typeArgs[1] instanceof Class<?>) {
            p = NamedValuePropertyImpl.getNamedValueProperty(result, propName, (Class<?>) typeArgs[1]);
          }
        }
        if (p != null) {
                    result.defineProperty(p);
                }
      }
    }

    return result;
View Full Code Here

 
  /**
   * @return Custom configuration
   */
  public Configuration getConfiguration() {
    ConfigurationImpl result = ConfigUtil.defaultConfiguration(this);
    result.removeProperty("basisDimension");
    try {
      Method getter = this.getClass().getMethod("getFunction", new Class[]{Integer.TYPE});
      Method countGetter = this.getClass().getMethod("getBasisDimension", new Class[0]);
      result.defineProperty(new ListPropertyImpl(result, "functions", Function.class, getter, countGetter));     
    } catch (Exception e) {
      throw new RuntimeException("Can't find function-related methods (this is a bug)", e);
    }
    return result;
  }
View Full Code Here

  private ConfigurationImpl myConfiguration;
 
  protected void setUp() throws Exception {
    super.setUp();
    myObject = new MockObject();
    myConfiguration = new ConfigurationImpl(myObject);
    myConfiguration.defineProperty(NamedValuePropertyImpl.getNamedValueProperty(myConfiguration, "A", String.class));
    myConfiguration.defineProperty(NamedValuePropertyImpl.getNamedValueProperty(myConfiguration, "B", MockNamedObject.class));
    myConfiguration.defineProperty(NamedValuePropertyImpl.getNamedValueProperty(myConfiguration, "C", String.class));
    myConfiguration.defineProperty(NamedValuePropertyImpl.getNamedValueProperty(myConfiguration, "D", MockNamedObject.class));
    myConfiguration.defineProperty(NamedValuePropertyImpl.getNamedValueProperty(myConfiguration, "E", String.class));
View Full Code Here

  /**
   * @return Custom configuration
   */
  public Configuration getConfiguration() {
    ConfigurationImpl result = ConfigUtil.defaultConfiguration(this);
    result.defineProperty(SingleValuedPropertyImpl.getSingleValuedProperty(result, "numDiscontinuities", Integer.TYPE));
    return result;
  }
View Full Code Here

    myPopupListener = new ConfigurationTreePopupListener(myConfigurationTree, model);
    myConfigurationTree.addMouseListener(myPopupListener);
  }

  private static Configuration makeTemplate(Constructor<?> constructor) {
    ConfigurationImpl result = new ConfigurationImpl(null);
    Class<?>[] types = constructor.getParameterTypes();
    String[] names = JavaSourceParser.getArgNames(constructor);
    for (int i = 0; i < types.length; i++) {
      if (types[i].isPrimitive()) {
                types[i] = ConfigUtil.getPrimitiveWrapperClass(types[i]);
            }
      AbstractProperty p = null;
      if (types[i].isArray() && !MainHandler.getInstance().canHandle(types[i])) {
        p = new TemplateArrayProperty(result, names[i], types[i].getComponentType());
      } else {
        p = new TemplateProperty(result, names[i], types[i], ConfigUtil.getDefaultValue(types[i]));
      }
      p.setDocumentation(JavaSourceParser.getArgDocs(constructor, i));
      result.defineProperty(p);
    }
    return result;
  }
View Full Code Here

    myConfigurableField = new MockLittleConfigurable();
   
    myMultiValuedField = new ArrayList<String>(10);
    myFixedCardinalityField = new String[]{"test1", "test2"};
   
    myConfiguration = new ConfigurationImpl(this);
    myConfiguration.defineSingleValuedProperty("immutableField", String.class, false);
   
    myConfiguration.defineSingleValuedProperty("intField", Integer.TYPE, true);
    myConfiguration.defineSingleValuedProperty("floatField", Float.TYPE, true);
    myConfiguration.defineSingleValuedProperty("booleanField", Boolean.TYPE, true);
View Full Code Here

//    myConfiguration.defineProperty(fcp);
   
  }
 
  public static Configuration getConstructionTemplate() {
    ConfigurationImpl template = new ConfigurationImpl(null);
    template.defineTemplateProperty("immutableField", String.class, "immutable");
    return template;
  }
View Full Code Here

    private String myField;
    private ConfigurationImpl myConfiguration;
   
    public MockLittleConfigurable() {
      myField = "test";
      myConfiguration = new ConfigurationImpl(this);
      myConfiguration.defineSingleValuedProperty("field", String.class, true);
    }
View Full Code Here

      ((ConfigurationImpl) configuration).defineTemplateProperty("immutableField", String.class, "foo");
      return configuration;
    }
   
    public static Configuration getConstructionTemplate() {
      ConfigurationImpl template = new ConfigurationImpl(null);
      template.defineTemplateProperty("immutableFoo", String.class, "foo");
      return template;
    }
View Full Code Here

TOP

Related Classes of ca.nengo.config.impl.ConfigurationImpl

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.