com.partnersoft.data.cog
Class CogLib

java.lang.Object
  extended by com.partnersoft.data.cog.CogLib

public class CogLib
extends java.lang.Object

Various handy cog functions.

Author:
Paul Reavis Copyright 2003 Partner Software, Inc.

Constructor Summary
CogLib()
           
 
Method Summary
static java.lang.Object convertMetaToCog(java.lang.Object victim, Naming classToDatatype)
          Converts an object structure into a Cog structure.
static CogStructure convertObjectToCogStructure(java.lang.Object object, java.util.Set<java.lang.String> fields)
          Using introspection, copies a list of fields into a cog.
static java.lang.Object convertToCog(java.lang.Object victim)
          Converts an object structure into a Cog structure.
static java.lang.Object convertToObject(Cog victim, Naming datatypeToClass)
          Converts a Cog structure into an object structure, using a datatype-to-java-classname mapping.
static void copyCogToObject(CogStructure cog, java.lang.Object object)
          Using introspection, copies the fields in a cog into an object.
static Cog ensureCog(java.lang.Object victim)
          Gives you an appropriate Cog object for the given argument.
static java.lang.String escape(java.lang.String pathPart)
          Removes slashes etc.
static java.lang.String[] splitPath(java.lang.String path)
          This is essentially a caching version of split(path, '/').
static java.lang.String unescape(java.lang.String pathPart)
          Unescapes slashes etc.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CogLib

public CogLib()
Method Detail

ensureCog

public static Cog ensureCog(java.lang.Object victim)
Gives you an appropriate Cog object for the given argument. If the argument is already a Cog, just returns it.


escape

public static java.lang.String escape(java.lang.String pathPart)
Removes slashes etc. from path parts.


unescape

public static java.lang.String unescape(java.lang.String pathPart)
Unescapes slashes etc. in a path part.


convertToObject

public static java.lang.Object convertToObject(Cog victim,
                                               Naming datatypeToClass)
Converts a Cog structure into an object structure, using a datatype-to-java-classname mapping. The classes specified must implement the Coggable interface.


convertToCog

public static java.lang.Object convertToCog(java.lang.Object victim)
Converts an object structure into a Cog structure. Non-collection classes must implement the Coggable interface. All Maps must be string-indexed.


convertMetaToCog

public static java.lang.Object convertMetaToCog(java.lang.Object victim,
                                                Naming classToDatatype)
Converts an object structure into a Cog structure. Converts MetaBeans to Coggables using the provided mapping.


convertObjectToCogStructure

public static CogStructure convertObjectToCogStructure(java.lang.Object object,
                                                       java.util.Set<java.lang.String> fields)
                                                throws java.lang.IllegalAccessException,
                                                       java.lang.NoSuchFieldException
Using introspection, copies a list of fields into a cog.

Parameters:
object -
fields -
Returns:
Throws:
java.lang.IllegalAccessException
java.lang.NoSuchFieldException

copyCogToObject

public static void copyCogToObject(CogStructure cog,
                                   java.lang.Object object)
                            throws java.lang.IllegalAccessException,
                                   java.lang.NoSuchFieldException
Using introspection, copies the fields in a cog into an object.

Parameters:
cog -
object -
Throws:
java.lang.IllegalAccessException
java.lang.NoSuchFieldException

splitPath

public static java.lang.String[] splitPath(java.lang.String path)
This is essentially a caching version of split(path, '/'). It keeps a single reference copy for each path it gets to reduce memory and computation overhead.