Unstructured Data
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Unstructured Data

  1. #1
    Join Date
    Sep 2009
    Posts
    7

    Unstructured Data

    Hi,

    I'm wondering if there are existing frameworks or libraries to create unstructured data objects or DTO using unstructured models. Instead of using structured classes as a mechanism for transferring data, I'd like to use an unstructured one with similar functionality to document-based models (hierarchical structure or arrays of arrays of fields with and fields referenced by a field identifier). It would be similar to (or might even be) XML but is geared towards being the mode if transporting data within an application (as opposed to between systems).

    That way I'd have something like:

    String lastName = "foo";
    Model model = new Model();
    model.add(FieldLastName.instance(), lastName);

    Ideally it would have a toString() method that would dump the content to a String and maybe even create a model from a String, etc.

    My apologies if I'm not phrasing this more solidly. I just don't know how else to phrase it.

  2. #2
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: Unstructured Data

    It doesn't ring any bells...

    But why? what are you trying to achieve?

    Programming is an explanatory activity...
    R. Harper
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  3. #3
    Join Date
    Sep 2009
    Posts
    7

    Re: Unstructured Data

    Trying to come up with a DTO model that has unstructured data. Composed of fields where each field has a field type (made up of a name and associated field data type) and a field value (whose type is dictated by the field type). So from this model, I'd like to be able to add a field value like:

    public void add(FieldType fieldType, T value);

    One way to do this is to use polymorphism in the method, but I was hoping to do it with one method call and yet still be able to do type-checking at compile time (obviously fieldType has to be known at compile time, as well).

  4. #4
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: Unstructured Data

    I suspect you may be able to do something like that using generics, but without knowing exactly how you expect to use this Model, it's hard to say. Is it just a way of storing multiple types by typename?

    Maybe something like this is what you had in mind:
    Code:
    class FieldType<T> {
        String name;
        public FieldType(String name) {
            this.name = name;
        }
    }
    
    // Map type to type name
    class Element<T> {
        FieldType<T> fieldType;
        T field;
        public Element(FieldType<T> type, T value) {
            fieldType = type;
            field = value;
        }
    }
    
    class Model {
        ArrayList<Element> elements;
        
        public <T> void add(FieldType<T> type, T value) {
            Element<T> element = new Element<T>(type, value);
            elements.add(element);
        }
    }
    
    ...
    
    Model model = new Model();
    
    FieldType<String> stringType = new FieldType<String>("String");
    String field1 = "foo";
    model.add(stringType, field1);
    
    FieldType<Integer> integerType = new FieldType<Integer>("Integer");
    Integer field2 = 23;
    model.add(integerType, field2);
    ..
    You get compile time type checking with this, but the drawback is that you end up with a list of untyped Elements (although you do have the type name for each). This may or may not be what you're after...

    Don't ask what it means, but rather how it is used...
    L. Wittgenstein
    Please use &#91;CODE]...your code here...&#91;/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  5. #5
    Join Date
    Sep 2009
    Posts
    7

    Re: Unstructured Data

    Ever heard of the phrase "hit the nail on the head"?

    Thanks!

  6. #6
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: Unstructured Data

    You're welcome - it's nice to see generics working!

    Language serves not only to express thought but to make possible thoughts which could not exist without it...
    B. Russell
    Please use &#91;CODE]...your code here...&#91;/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center