Examples of ArrayValueSupport


Examples of org.jboss.metatype.api.values.ArrayValueSupport

   @SuppressWarnings("unchecked")
   public void testCharacterArray() throws Exception
   {
      ArrayMetaType type = new ArrayMetaType(1, SimpleMetaType.CHARACTER);
      Character[] value = {'h', 'e', 'l', 'l', 'o'};
      ArrayValueSupport avs = new ArrayValueSupport(type, value);
      for(int n = 0; n < avs.getLength(); n ++)
      {
         Object element = avs.getValue(n);
         assertEquals(value[n], element);
      }
      // Validate the raw array
      Character[] raw = (Character[]) avs.getValue();
      for(int n = 0; n < value.length; n ++)
      {
         assertEquals(value[n], raw[n]);
      }
   }
View Full Code Here

Examples of org.jboss.metatype.api.values.ArrayValueSupport

   public void test2DCharArray() throws Exception
   {
      ArrayMetaType type = new ArrayMetaType(2, SimpleMetaType.CHARACTER, true);
      char[][] value = {{'h', 'e'}, {'l', 'l', 'o'}};
      ArrayValueSupport avs = new ArrayValueSupport(type, value);
      assertEquals(value.length, avs.getLength());
      for(int m = 0; m < value.length; m ++)
      {
         Object arraym = avs.getValue(m);
         for(int n = 0; n < value[m].length; n ++)
         {
            // Have to use the java.lang.reflect.Array to access nested elements
            Object valuenm = Array.get(arraym, n);
            assertEquals("["+m+"]["+n+"]", value[m][n], valuenm);
         }
      }

      /* FIXME: Use typesafe foreach Iterable: current broken with CCE on [C
      int i = 0, j = 0;
      for(Character[] carray : avs)
      {
         for(Character c : carray)
         {
            Character cij = value[i ++][j ++];
            assertEquals("["+i+"], ["+j+"]", cij , c);
         }
      }
      */

      // Validate the primitive 2d array
      char[][] raw = (char[][]) avs.getValue();
      for(int m = 0; m < value.length; m ++)
      {
         for(int n = 0; n < value[m].length; n ++)
         {
            assertEquals("["+m+"]["+n+"]", value[m][n], raw[m][n]);
View Full Code Here

Examples of org.jboss.metatype.api.values.ArrayValueSupport

   public ArrayValue createArrayValue(ArrayMetaType type, Object value, Map<Object, MetaValue> mapping)
   {
      if (value == null)
         return null;

      ArrayValueSupport result = new ArrayValueSupport(type);
      mapping.put(value, result);
     
      Object[] array;
     
      MetaType elementType = type.getElementType();
      int dimension = type.getDimension();
     
      Object[] oldArray;
      Class<?> componentType;
      try
      {
         componentType = Class.forName(type.getClassName());
      }
      catch (Exception e)
      {
         throw new RuntimeException("Unable to determine component type for " + type, e);
      }
     
      ClassInfo classInfo = configuration.getClassInfo(value.getClass());
      if (classInfo.isArray())
      {
         // See if this is a primitive array
         ArrayInfo arrayInfo = ArrayInfo.class.cast(classInfo);
         TypeInfo compInfo = arrayInfo.getComponentType();
         while(compInfo instanceof ArrayInfo)
         {
            arrayInfo = ArrayInfo.class.cast(compInfo);
            compInfo = arrayInfo.getComponentType();
         }
         // Translate
         if (compInfo.isPrimitive())
            oldArray = convertPrimativeArray(classInfo, value);
         else
            oldArray = (Object[]) value;
      }
      else
         throw new UnsupportedOperationException("Cannot construct array for " + value.getClass());
     
      array = createArray(elementType, componentType.getComponentType(), dimension, oldArray);
      result.setValue(array);
      return result;
   }
View Full Code Here

Examples of org.jboss.metatype.api.values.ArrayValueSupport

         {
            MetaValue value = createMetaValue(elementValue, type.getElementType());
            values.add(value);
         }
      }
      return new ArrayValueSupport(type, values.toArray());
   }
View Full Code Here

Examples of org.jboss.metatype.api.values.ArrayValueSupport

                     Iterator<?> i = bmdAliases.iterator();
                     for(int n = 0; i.hasNext(); n++)
                     {
                        aliases[n] = i.next().toString();
                     }
                     ArrayValueSupport value = new ArrayValueSupport(aliasType, aliases);
                     fields.setValue(value);
                     ManagedPropertyImpl aliasesMP = new ManagedPropertyImpl(bmdMO, fields);
                     newProps.put("alias", aliasesMP);
                  }
                  // Add a state property
View Full Code Here

Examples of org.jboss.metatype.api.values.ArrayValueSupport

   public ArrayValue createArrayValue(ArrayMetaType type, Object value, Map<Object, MetaValue> mapping)
   {
      if (value == null)
         return null;

      ArrayValueSupport result = new ArrayValueSupport(type);
      mapping.put(value, result);
     
      Object[] array;
     
      MetaType elementType = type.getElementType();
      int dimension = type.getDimension();
     
      Object[] oldArray;
      Class<?> componentType;
      try
      {
         componentType = Class.forName(type.getClassName());
      }
      catch (Exception e)
      {
         throw new RuntimeException("Unable to determine component type for " + type, e);
      }
     
      ClassInfo classInfo = configuration.getClassInfo(value.getClass());
      if (classInfo.isArray())
      {
         // See if this is a primitive array
         ArrayInfo arrayInfo = ArrayInfo.class.cast(classInfo);
         TypeInfo compInfo = arrayInfo.getComponentType();
         while(compInfo instanceof ArrayInfo)
         {
            arrayInfo = ArrayInfo.class.cast(compInfo);
            compInfo = arrayInfo.getComponentType();
         }
         // Translate
         if (compInfo.isPrimitive())
            oldArray = convertPrimativeArray(classInfo, value);
         else
            oldArray = (Object[]) value;
      }
      else
         throw new UnsupportedOperationException("Cannot construct array for " + value.getClass());
     
      array = createArray(elementType, componentType.getComponentType(), dimension, oldArray);
      result.setValue(array);
      return result;
   }
View Full Code Here

Examples of org.jboss.metatype.api.values.ArrayValueSupport

         ArrayMetaType arrayType = ArrayMetaType.class.cast(propertyType);
         if (AbstractManagedObjectFactory.MANAGED_OBJECT_META_TYPE == arrayType.getElementType())
         {
            Collection<?> cvalue = getAsCollection(value);
            ArrayMetaType moType = new ArrayMetaType(1, AbstractManagedObjectFactory.MANAGED_OBJECT_META_TYPE);
            ArrayValueSupport moArrayValue = new ArrayValueSupport(moType);
            List<GenericValueSupport> tmp = new ArrayList<GenericValueSupport>();
            for(Object element : cvalue)
            {
               ManagedObject mo = mof.initManagedObject((Serializable) element, null, null);
               tmp.add(new GenericValueSupport(AbstractManagedObjectFactory.MANAGED_OBJECT_META_TYPE, mo));
            }
            GenericValueSupport[] mos = new GenericValueSupport[tmp.size()];
            moArrayValue.setValue(tmp.toArray(mos));
            return moArrayValue;
         }
      }
      else if (propertyType.isCollection())
      {
View Full Code Here

Examples of org.jboss.metatype.api.values.ArrayValueSupport

         if (MANAGED_OBJECT_META_TYPE == arrayType.getElementType())
         {
            Collection<?> cvalue = getAsCollection(value);
            // todo - AJ: changed some generics by best guess
            ArrayMetaType moType = new ArrayMetaType(1, MANAGED_OBJECT_META_TYPE);
            ArrayValueSupport moArrayValue = new ArrayValueSupport(moType);
            List<GenericValueSupport> tmp = new ArrayList<GenericValueSupport>();
            for(Object element : cvalue)
            {
               ManagedObject mo = initManagedObject((Serializable) element, null, null);
               tmp.add(new GenericValueSupport(MANAGED_OBJECT_META_TYPE, mo));
            }
            GenericValueSupport[] mos = new GenericValueSupport[tmp.size()];
            moArrayValue.setValue(tmp.toArray(mos));
            return moArrayValue;
         }
      }
      else if (propertyType.isCollection())
      {
View Full Code Here

Examples of org.jboss.metatype.api.values.ArrayValueSupport

/* 723 */       if (MANAGED_OBJECT_META_TYPE == arrayType.getElementType())
/*     */       {
/* 725 */         Collection cvalue = getAsCollection(value);
/*     */
/* 727 */         ArrayMetaType moType = new ArrayMetaType(1, MANAGED_OBJECT_META_TYPE);
/* 728 */         ArrayValueSupport moArrayValue = new ArrayValueSupport(moType);
/* 729 */         List tmp = new ArrayList();
/* 730 */         for (Iterator i$ = cvalue.iterator(); i$.hasNext(); ) { Object element = i$.next();
/*     */
/* 732 */           ManagedObject mo = initManagedObject((Serializable)element, null, null);
/* 733 */           tmp.add(new GenericValueSupport(MANAGED_OBJECT_META_TYPE, mo));
/*     */         }
/* 735 */         GenericValueSupport[] mos = new GenericValueSupport[tmp.size()];
/* 736 */         moArrayValue.setValue(tmp.toArray(mos));
/* 737 */         return moArrayValue;
/*     */       }
/*     */     }
/* 740 */     else if (propertyType.isCollection())
/*     */     {
View Full Code Here

Examples of org.jboss.metatype.api.values.ArrayValueSupport

/*      */   public ArrayValue createArrayValue(ArrayMetaType type, Object value, Map<Object, MetaValue> mapping)
/*      */   {
/*  299 */     if (value == null) {
/*  300 */       return null;
/*      */     }
/*  302 */     ArrayValueSupport result = new ArrayValueSupport(type);
/*  303 */     mapping.put(value, result);
/*      */
/*  307 */     MetaType elementType = type.getElementType();
/*  308 */     int dimension = type.getDimension();
/*      */     Class componentType;
/*      */     try {
/*  314 */       componentType = Class.forName(type.getClassName());
/*      */     }
/*      */     catch (Exception e)
/*      */     {
/*  318 */       throw new RuntimeException("Unable to determine component type for " + type, e);
/*      */     }
/*      */
/*  321 */     ClassInfo classInfo = configuration.getClassInfo(value.getClass());
/*      */     Object[] oldArray;
/*  322 */     if (classInfo.isArray())
/*      */     {
/*  325 */       ArrayInfo arrayInfo = (ArrayInfo)ArrayInfo.class.cast(classInfo);
/*  326 */       TypeInfo compInfo = arrayInfo.getComponentType();
/*  327 */       while ((compInfo instanceof ArrayInfo))
/*      */       {
/*  329 */         arrayInfo = (ArrayInfo)ArrayInfo.class.cast(compInfo);
/*  330 */         compInfo = arrayInfo.getComponentType();
/*      */       }
/*      */       Object[] oldArray;
/*  333 */       if (compInfo.isPrimitive())
/*  334 */         oldArray = convertPrimativeArray(classInfo, value);
/*      */       else
/*  336 */         oldArray = (Object[])(Object[])value;
/*      */     }
/*      */     else {
/*  339 */       throw new UnsupportedOperationException("Cannot construct array for " + value.getClass());
/*      */     }
/*      */     Object[] oldArray;
/*  341 */     Object[] array = createArray(elementType, componentType.getComponentType(), dimension, oldArray);
/*  342 */     result.setValue(array);
/*  343 */     return result;
/*      */   }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.