Commit 8c83f64
committed
[Java.Interop] "Java Activation": API Declaration
Next can-o'-worms to start implementing: Java Activation:
http://docs.xamarin.com/guides/android/under_the_hood/architecture/#Java_Activation
There are logically two ways to create a "managed peer"/"native peer"
instance pair:
1. By creating the managed peer, which will automagically create the
native peer instance (see the JavaObject default constructor); or
2. By creating the native peer.
(1) is implemented. (2) has not been, meaning at present if Java code
were to create an instance of a "native peer", no corresponding
managed peer instance would be created, and thus any `native` methods
wouldn't be registered, and things would blow up rather quickly.
How should this be exposed?
Xamarin.Android has two related methods:
* mono.android.Runtime.register(): registers native methods for a
Java class.
* mono.android.TypeManager.Activate(): invoked by the Java
constructor, and responsible for associating the native peer with
a managed peer, creating a new managed peer if necessary.
The pattern for TypeManager.Activate() invocation is as follows:
// Xamarin.Android constructor style
public JavaPeerType(Args... args) {
super (args...);
if (getClass() == JavaPeerType.class)
TypeManager.Activate (
AssemblyQualifiedTypeName,
ConstructorSignature,
this,
new java.lang.Object[]{ args }
);
}
The need for the getClass() check is so that TypeManager.Activate() is
only executed once, on the most derived native peer type, and not once
per type in the inheritance chain.
My feeling is that Runtime.register() and TypeManager.Activate()
should be more closely related, because they both operate on peer
types. (Runtime.register() is also a semantically poor name, and the
it's only in Runtime for "where else should we put it?" reasons.)
The alternative Java.Interop API? ManagedPeer.runConstructor() (and
later, ManagedPeer.registerNativeMethods()), which also alters
parameter ordering and now takes the Class for the declaring class:
// Java.Interop constructor style:
public JavaPeerType(Args... args) {
super (args...);
ManagedPeer.runConstructor (
JavaPeerType.class,
this,
AssemblyQualifiedTypeName,
ConstructorSignature,
args...
);
}
This "moves" the getClass() check into ManagedPeer.runConstructor(),
allowing ManagedPeer methods to consistently take a Class instance,
and also provides possible future flexibility on behavior.
ManagedPeer.runConstructor() doesn't do anything at this time; this is
just stubbing out the API, adding the appropriate calls to our Java
"native peer" test types, and providing the initial C# implementation.1 parent 084a8f4 commit 8c83f64
File tree
11 files changed
+131
-1
lines changed- src/Java.Interop
- Java.Interop
- Tests
- java/com/xamarin/interop
- java/com/xamarin/android
11 files changed
+131
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| 94 | + | |
94 | 95 | | |
95 | 96 | | |
96 | 97 | | |
97 | 98 | | |
| 99 | + | |
98 | 100 | | |
99 | 101 | | |
100 | 102 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
177 | 177 | | |
178 | 178 | | |
179 | 179 | | |
| 180 | + | |
| 181 | + | |
180 | 182 | | |
181 | 183 | | |
182 | 184 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
99 | | - | |
| 99 | + | |
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
| |||
Lines changed: 9 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
5 | 14 | | |
6 | 15 | | |
7 | 16 | | |
| |||
Lines changed: 9 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
5 | 14 | | |
6 | 15 | | |
7 | 16 | | |
| |||
Lines changed: 9 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
4 | 13 | | |
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
6 | 13 | | |
7 | 14 | | |
8 | 15 | | |
| |||
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
7 | 14 | | |
8 | 15 | | |
9 | 16 | | |
| |||
Lines changed: 9 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
5 | 14 | | |
6 | 15 | | |
7 | 16 | | |
| |||
0 commit comments