Class ObjectConverterService


  • public class ObjectConverterService
    extends BaseService
    Provides a utility object to covert between DataObject and ValueObject objects.

    DataObject classes extends CayenneDataObject and are used for server side persistence operations, while ValueObject objects are used by Adobe Flex to convert between Java objects and Flex ActionScript objects.

    The ValueObject support Flex serialization and deserialization of object graphs, providing an intermediary between Cayenne DataObjects and Flex ActionScript objects.

    An example useage of the ObjectCoverter isprovided below:

     public UserVO updateUser(UserVO userVO) {
    
         User user = (User) ObjectConverter.toDataObject(userVO);
    
         getDataContext().commitChanges();
    
         return (UserVO) ObjectConverter.toValueObject(user, "*");
     }
     
    See Also:
    ValueObject
    • Constructor Detail

      • ObjectConverterService

        public ObjectConverterService()
        Create an ObjectConverterService.
    • Method Detail

      • toDataObject

        public org.apache.cayenne.DataObject toDataObject​(ValueObject valueObject,
                                                          List<Pair<String,​String>> substitutionPairs)
        Convert the given value object into a Cayenne data object.

        Please note this method will not delete the data object corresponding to the given value object parameter. This method will however delete child data objects in one to many relationships.

        IMPORTANT NOTE: this method will not resolve circular dependencies between objects. You must ensure object graphs passed do not include circular dependencies beyond simple Cayenne bi-directional relationships.

        Parameters:
        valueObject - the value object to convert
        substitutionPairs - a list of String replace parameters to perform on the data object class name before looking it up (optional)
        Returns:
        the Cayenne data object
      • toValueObject

        public ValueObject toValueObject​(org.apache.cayenne.DataObject dataObject,
                                         String pathIncludes,
                                         List<Pair<String,​String>> substitutionPairs)
        Convert the given Cayenne data object into a value object, including the specified paths for object relationships.

        An example usage of the ObjectConverter is provided below:

         public UserVO updateUser(UserVO userVO) {
        
             User user = (User) ObjectConverter.toDataObject(userVO);
        
             getDataContext().commitChanges();
        
             return (UserVO) ObjectConverter.toValueObject(user, "contact, submissions");
         }
         
        Parameters:
        dataObject - the data object to convert
        pathIncludes - the data object property paths to include in the conversion
        substitutionPairs - a list of String replace parameters to perform on the value object class name before looking it up (optional)
        Returns:
        the value object
      • toValueObject

        public ValueObject toValueObject​(org.apache.cayenne.DataObject dataObject,
                                         Set pathIncludes,
                                         List<Pair<String,​String>> substitutionPairs)
        Convert the given Cayenne data object into a value object, including the specified paths for object relationships.

        An example useage of the ObjectCoverter is provided below:

         public UserVO updateUser(UserVO userVO) {
        
             User user = (User) ObjectConverter.toDataObject(userVO);
        
             getDataContext().commitChanges();
        
             Set includes = new HashSet();
             includes.add("contact");
             includes.add("submissions.groupMember.contact");
             includes.add("submissions.groupMember.secondaryContact");
        
             return (UserVO) ObjectConverter.toValueObject(user, includes);
         }
         
        If a null set of pathIncludes is specified no object relationships will be converted.
        Parameters:
        dataObject - the data object to convert
        pathIncludes - the data object property paths to include in the conversion
        substitutionPairs - a list of String replace parameters to perform on the value object class name before looking it up (optional)
        Returns:
        the value object
      • toValueObjects

        public List toValueObjects​(List dataObjects,
                                   String pathIncludes,
                                   List<Pair<String,​String>> substitutionPairs)
        Takes a list of DataObject instances and creates a corresponding list of equivalent ValueObject instances.
        Parameters:
        dataObjects - List of DataObject instances.
        pathIncludes - the included path string
        substitutionPairs - a list of String replace parameters to perform on the value object class name before looking it up (optional)
        Returns:
        List of ValueObject instances. n'th element is the value object equivalent of the n'th element of dataObjects.
      • toDataObjects

        public List toDataObjects​(List valueObjects,
                                  List<Pair<String,​String>> substitutionPairs)
        Convert a list of value objects to data objects.
        Parameters:
        valueObjects - a list of value objects
        substitutionPairs - a list of String replace parameters to perform on the data object class name before looking it up (optional)
        Returns:
        a list of data objects
      • getDataObjectProperties

        protected Map<String,​com.avoka.core.service.ObjectConverterService.Property> getDataObjectProperties​(org.apache.cayenne.DataObject dataObject,
                                                                                                                   Set includeProperties)
        Return the set of value object properties.
        Parameters:
        dataObject - the data object to get the properties of
        Returns:
        the set of data object include properties
      • getValueObjectProperties

        protected Map<String,​com.avoka.core.service.ObjectConverterService.Property> getValueObjectProperties​(ValueObject valueObject)
        Return the set of value object properties.
        Parameters:
        valueObject - the value object to get the properties of
        Returns:
        the set of value object properties