forked from tcalmant/python-javaobj
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.py
More file actions
97 lines (71 loc) · 3.06 KB
/
api.py
File metadata and controls
97 lines (71 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env python3
"""
Definition of the object transformer API
:authors: Thomas Calmant
:license: Apache License 2.0
:version: 0.4.0
:status: Alpha
..
Copyright 2019 Thomas Calmant
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
from __future__ import absolute_import
from typing import Optional
from .beans import JavaClassDesc, JavaInstance
from .stream import DataStreamReader
from ..constants import TypeCode
# ------------------------------------------------------------------------------
# Module version
__version_info__ = (0, 4, 0)
__version__ = ".".join(str(x) for x in __version_info__)
# Documentation strings format
__docformat__ = "restructuredtext en"
# ------------------------------------------------------------------------------
class ObjectTransformer(object):
"""
Representation of an object transformer
"""
def create_instance(self, classdesc):
# type: (JavaClassDesc) -> Optional[JavaInstance]
"""
Transforms a parsed Java object into a Python object.
The result must be a JavaInstance bean, or None if the transformer
doesn't support this kind of instance.
:param classdesc: The description of a Java class
:return: The Python form of the object, or the original JavaObject
"""
return None
def load_array(self, reader, type_code, size):
# type: (DataStreamReader, TypeCode, int) -> Optional[list]
"""
Loads and returns the content of a Java array, if possible.
The result of this method must be the content of the array, i.e. a list
or an array. It will be stored in a JavaArray bean created by the
parser.
This method must return None if it can't handle the array.
:param reader: The data stream reader
:param type_code: Type of the elements of the array
:param size: Number of elements in the array
"""
return None
def load_custom_writeObject(self, parser, reader, name):
# type: (JavaStreamParser, DataStreamReader, str) -> Optional[JavaClassDesc]
"""
Reads content stored from a custom writeObject.
This method is called only if the class description has both the
``SC_SERIALIZABLE`` and ``SC_WRITE_METHOD`` flags set.
The stream parsing will stop and fail if this method returns None.
:param parser: The JavaStreamParser in use
:param reader: The data stream reader
:param name: The class description name
:return: A JavaClassDesc instance or None
"""
return None