Package org.jboss.metatype.api.types

Examples of org.jboss.metatype.api.types.MetaType


    return null;
  }

  public static Double doubleValue(MetaValue v1) throws Exception {
    if (v1 != null) {
      MetaType type = v1.getMetaType();
      if (type instanceof SimpleMetaType) {
        SimpleValue simple = (SimpleValue) v1;
        return Double.valueOf(simple.getValue().toString());
      }
      throw new Exception("Failed to convert value to double value"); //$NON-NLS-1$
View Full Code Here


    return null;
  }
 
  public static Long longValue(MetaValue v1) throws Exception {
    if (v1 != null) {
      MetaType type = v1.getMetaType();
      if (type instanceof SimpleMetaType) {
        SimpleValue simple = (SimpleValue) v1;
        return Long.valueOf(simple.getValue().toString());
      }
      throw new Exception("Failed to convert value to long value"); //$NON-NLS-1$
View Full Code Here

    return null;
  }
 
  public static Integer integerValue(MetaValue v1) throws Exception {
    if (v1 != null) {
      MetaType type = v1.getMetaType();
      if (type instanceof SimpleMetaType) {
        SimpleValue simple = (SimpleValue) v1;
        return Integer.valueOf(simple.getValue().toString());
      }
      throw new Exception("Failed to convert value to integer value"); //$NON-NLS-1$
View Full Code Here

 
  public static <T> T getSimpleValue(ManagedComponent mc, String prop,
      Class<T> expectedType) {
    ManagedProperty mp = mc.getProperty(prop);
    if (mp != null) {
      MetaType metaType = mp.getMetaType();
      if (metaType.isSimple()) {
        SimpleValue simpleValue = (SimpleValue) mp.getValue();
        return expectedType.cast((simpleValue != null) ? simpleValue
            .getValue() : null);
      } else if (metaType.isEnum()) {
        EnumValue enumValue = (EnumValue) mp.getValue();
        return expectedType.cast((enumValue != null) ? enumValue
            .getValue() : null);
      }
      throw new IllegalStateException(prop + " is not a simple type"); //$NON-NLS-1$
View Full Code Here

  }

  public static <T> T getSimpleValue(MetaValue prop,
      Class<T> expectedType) {
    if (prop != null) {
      MetaType metaType = prop.getMetaType();
      if (metaType.isSimple()) {
        SimpleValue simpleValue = (SimpleValue) prop;
        return expectedType.cast((simpleValue != null) ? simpleValue
            .getValue() : null);
      } else if (metaType.isEnum()) {
        EnumValue enumValue = (EnumValue) prop;
        return expectedType.cast((enumValue != null) ? enumValue
            .getValue() : null);
      }
      throw new IllegalStateException(prop + " is not a simple type"); //$NON-NLS-1$
View Full Code Here

 
  public static <T> T getSimpleValue(ManagedCommon mc, String prop,
      Class<T> expectedType) {
    ManagedProperty mp = mc.getProperty(prop);
    if (mp != null) {
      MetaType metaType = mp.getMetaType();
      if (metaType.isSimple()) {
        SimpleValue simpleValue = (SimpleValue) mp.getValue();
        return expectedType.cast((simpleValue != null) ? simpleValue
            .getValue() : null);
      } else if (metaType.isEnum()) {
        EnumValue enumValue = (EnumValue) mp.getValue();
        return expectedType.cast((enumValue != null) ? enumValue
            .getValue() : null);
      }
      throw new IllegalArgumentException(prop + " is not a simple type"); //$NON-NLS-1$
View Full Code Here

      propertyAdapter = PropertyAdapterFactory.getPropertyAdapter(metaValue);

      propertyAdapter.populateMetaValueFromProperty(configuration.getSimple(propertyDefinition.getName()), metaValue, propertyDefinition);
      managedProperty.setValue(metaValue);
    } else {
      MetaType metaType = managedProperty.getMetaType();
      propertyAdapter = PropertyAdapterFactory.getPropertyAdapter(metaType);
      LOG.trace("Converting property " + propertyDefinition.getName()   + " with definition " + propertyDefinition   + " to MetaValue of type " + metaType + "..."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
      metaValue = propertyAdapter.convertToMetaValue(configuration.getSimple(propertyDefinition.getName()),propertyDefinition, metaType);
      managedProperty.setValue(metaValue);
    }
View Full Code Here

      LOG.debug("Cannot update default value on non-simple property definition " //$NON-NLS-1$
              + propertyDefinition + "(default value is " //$NON-NLS-1$
              + defaultValue + ")."); //$NON-NLS-1$
      return;
    }
    MetaType metaType = defaultValue.getMetaType();
    if (!metaType.isSimple() && !metaType.isEnum()) {
      LOG.debug("Cannot update default value on " + propertyDefinition //$NON-NLS-1$
          + ", because default value's type (" + metaType //$NON-NLS-1$
          + ") is not simple or enum."); //$NON-NLS-1$
      return;
    }
    PropertyDefinitionSimple propertyDefinitionSimple = (PropertyDefinitionSimple) propertyDefinition;
    if (metaType.isSimple()) {
      SimpleValue defaultSimpleValue = (SimpleValue) defaultValue;
      Serializable value = defaultSimpleValue.getValue();
      propertyDefinitionSimple.setDefaultValue((value != null) ? value.toString() : null);
    } else { // defaultValueMetaType.isEnum()
      EnumValue defaultEnumValue = (EnumValue) defaultValue;
View Full Code Here

    }
  }

  public static MetaType convertPropertyDefinitionToMetaType(
      PropertyDefinition propDef) {
    MetaType memberMetaType;
    if (propDef instanceof PropertyDefinitionSimple) {
      PropertySimpleType propSimpleType = ((PropertyDefinitionSimple) propDef)
          .getType();
      memberMetaType = convertPropertySimpleTypeToSimpleMetaType(propSimpleType);
    } else if (propDef instanceof PropertyDefinitionList) {
      // TODO (very low priority, since lists of lists are not going to be
      // at all common)
      memberMetaType = null;
    } else if (propDef instanceof PropertyDefinitionMap) {
      Map<String, PropertyDefinition> memberPropDefs = ((PropertyDefinitionMap) propDef)
          .getPropertyDefinitions();
      if (memberPropDefs.isEmpty())
        throw new IllegalStateException(
            "PropertyDefinitionMap doesn't contain any member PropertyDefinitions."); //$NON-NLS-1$
      // NOTE: We assume member prop defs are all of the same type, since
      // for MapCompositeMetaTypes, they have to be.
      PropertyDefinition mapMemberPropDef = memberPropDefs.values()
          .iterator().next();
      MetaType mapMemberMetaType = convertPropertyDefinitionToMetaType(mapMemberPropDef);
      memberMetaType = new MapCompositeMetaType(mapMemberMetaType);
    } else {
      throw new IllegalStateException(
          "List member PropertyDefinition has unknown type: " //$NON-NLS-1$
              + propDef.getClass().getName());
View Full Code Here

    return memberMetaType;
  }

  private static MetaType convertPropertySimpleTypeToSimpleMetaType(
      PropertySimpleType memberSimpleType) {
    MetaType memberMetaType;
    Class memberClass;
    switch (memberSimpleType) {
    case BOOLEAN:
      memberClass = Boolean.class;
      break;
View Full Code Here

TOP

Related Classes of org.jboss.metatype.api.types.MetaType

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.