polyglot.util
Class TypeEncoder
java.lang.Object
polyglot.util.TypeEncoder
public class TypeEncoder
- extends java.lang.Object
The TypeEncoder
gives the ability to encode a polyglot
Type
as a Java string.
It uses a form of serialization to encode the Type
into
a byte stream and then converts the byte stream to a standard Java string.
The difference between the encoder and a normal serialization process is
that in order to encode this type, we need to sever any links to other types
in the current environment. So any ClassType
other than the
the type being encoded is replaced in the stream with a
PlaceHolder
that contains the name of the class. To aid
in the decoding process, placeholders for member classes user their
"mangled" name; non-member classes use their fully qualified name.
Method Summary |
TypeObject |
decode(java.lang.String s,
java.lang.String name)
Decode a serialized type object. |
java.lang.String |
encode(TypeObject t)
Serialize a type object into a string. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ts
protected TypeSystem ts
zip
protected final boolean zip
- See Also:
- Constant Field Values
base64
protected final boolean base64
- See Also:
- Constant Field Values
test
protected final boolean test
- See Also:
- Constant Field Values
placeHolderCache
protected java.util.Map placeHolderCache
dependencies
protected java.util.Map dependencies
depth
protected int depth
TypeEncoder
public TypeEncoder(TypeSystem ts)
encode
public java.lang.String encode(TypeObject t)
throws java.io.IOException
- Serialize a type object into a string.
- Parameters:
t
- The TypeObject to encode.
- Returns:
- String containing the encoded type object.
- Throws:
java.io.IOException
- If the encoding fails.
decode
public TypeObject decode(java.lang.String s,
java.lang.String name)
throws java.io.InvalidClassException
- Decode a serialized type object. If deserialization fails because
a type could not be resolved, the method returns null. The calling
pass should abort in that case.
- Parameters:
s
- String containing the encoded type object.
- Returns:
- The decoded TypeObject, or null if deserialization fails.
- Throws:
java.io.InvalidClassException
- If the string is malformed.