Package org.bifrost.xmlio.config

Examples of org.bifrost.xmlio.config.PropertyMap


   * the object property called 'string' and from the tag name 'theNumber' to
   * the object property called 'number'.
   */
  private void configSimpleTest()
  {
    PropertyMap map = new PropertyMap();
    map.setPropertyXmlName("theString");
    map.setPropertyName("string");
    map.setPropertyType(String.class);
    config.addPropertyMap(map);
   
    map = new PropertyMap();
    map.setPropertyXmlName("theNumber");
    map.setPropertyName("number");
    map.setPropertyType(Long.class);
    config.addPropertyMap(map);
  }
View Full Code Here


  private void configSimpleTestFromObject()
  {
    ObjectMap oMap = new ObjectMap();
    oMap.setName("TestHelperSimple");
    oMap.setXmlName("TestHelperSimple");
    PropertyMap map = new PropertyMap();
    map.setPropertyXmlName("theString");
    map.setPropertyName("string");
    map.setPropertyType(String.class);
    oMap.addPropertyMap(map);
   
    map = new PropertyMap();
    map.setPropertyXmlName("theNumber");
    map.setPropertyName("number");
    map.setPropertyType(Long.class);
    oMap.addPropertyMap(map);
    config.addObjectMap(oMap);
  }
View Full Code Here

  }
 
  public void testReadingGloballyMappedProperties()
  {
    configSimpleTest();
    PropertyMap map = new PropertyMap();
   
    String configString = SIMPLE_TEST;
    InputStream reader = new ByteArrayInputStream(configString.getBytes());
    XmlReader xmlReader = null;
    try
View Full Code Here

  }

  public void testReadingObjectMappedProperties()
  {
    configSimpleTestFromObject();
    PropertyMap map = new PropertyMap();
   
    String configString = SIMPLE_TEST;
    InputStream reader = new ByteArrayInputStream(configString.getBytes());
    XmlReader xmlReader = null;
    try
View Full Code Here

  {
    assertNull(ObjectMap.createFromClass(null));
    ObjectMap om = ObjectMap.createFromClass(TestHelperObjectMap.class);
    assertNotNull(om);
    assertNotNull(om.getPropertyMapFromAlias("id"));
    PropertyMap pm = om.getPropertyMapFromAlias("id");
    assertTrue("id".equals(pm.getPropertyName()));
    assertTrue("id".equals(pm.getPropertyXmlName()));
    assertTrue("long".equals(pm.getPropertyType().getName()));
  }
View Full Code Here

    throws XmlException, IllegalAccessException, InvocationTargetException
  {
    List properties = oMap.getPropertyMap();
    for (Iterator i = properties.iterator(); i.hasNext();)
    {
      PropertyMap pMap = (PropertyMap)i.next();
      // If there is a property map for this attribute at the 'global'
      // level, use that one instead
      if (config.getPropertyMapByName(pMap.getPropertyName()) != null)
        pMap = config.getPropertyMapByName(pMap.getPropertyName());

      if (pMap.getWriteAsAttribute() != attributes)
        continue;
      logger.fine("Writing object property " + pMap.getPropertyName() +
          " as xml element " + pMap.getPropertyXmlName() + ".");
      Method method = pMap.getGetter();
      if (method == null)
      {
        String name = pMap.getPropertyName();

        // If the setter method is undefined for this property map, then the
        // property map was probably added to config programmatically or through
        // a config file, rather than being generated from a class.
        if (method == null && pMap != null)
        {
          // Guess what the setter might be
          method = pMap.guessGetter(object);
          // And cache the method if it's not a global property map
          if (method != null)
            pMap.setGetter(method);
        }

        if (pMap == null)
          throw new XmlException("Lost property definition for " +
              name);
        if (method == null)
          throw new XmlException("Cannot find getter method for " + name +
              " in the object " + object.getClass().getName());
      }
      Object value = method.invoke(object, (Object[])null);
      String type = "unknown";
      Class typeClass = null;
      if (value == null)
      {
        typeClass = pMap.getPropertyType();
        type = typeClass.getName();
      }
      if (value != null)
      {
        type = value.getClass().getName();
        typeClass = value.getClass();
        // 'Correct' the type if we are dealing with a List or Set
        if ((value instanceof List || value instanceof Set) &&
            ((Collection)value).size() > 0 &&
            ((Collection)value).iterator().hasNext() == true)
        {
          if (((Collection)value).iterator().next() != null)
          {
            type =
              (((Collection)value).iterator().next()).getClass().getName();
            typeClass = (((Collection)value).iterator().next()).getClass();
          }
          // Yikes, we have a collection with at least one element, but the
          // first element is a NULL!  We should just skip this whole
          // property.
          else
            continue;
        }
        // 'Correct' the type if we are dealing with an array
        else if (value.getClass().isArray() == true &&
            ((Object[])value).length > 0)
        {
          type = ((Object[])value)[0].getClass().getName();
          typeClass = ((Object[])value)[0].getClass();
        }

        // If the properties 'actual' type is a primative, our getter will
        // actually return the Object wrapper for the primative so we must
        // update our PropertyMap to reflect this.
        if (pMap.getPropertyType() == null ||
            !type.equals(pMap.getPropertyType().getName()))
          pMap.setPropertyType(typeClass);
       
        type = pMap.getPropertyType().getName();
      }
      boolean isAttribute = (config.getConverter(type) != null);
      if (pMap.getConverter() != null)
        isAttribute = true;
     
      if (isAttribute == false && attributes == true)
      {
        pMap.setWriteAsAttribute(false);
        continue;
      }
     
      // If it's an object and it's null, don't write it out.
      if (value == null && isAttribute == false)
View Full Code Here

TOP

Related Classes of org.bifrost.xmlio.config.PropertyMap

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.