// JavaListenAddrArray converts Go rpc.ListenAddrs into a Java // ListenSpec$Address array. func JavaListenAddrArray(env jutil.Env, addrs rpc.ListenAddrs) (jutil.Object, error) { addrarr := make([]jutil.Object, len(addrs)) for i, addr := range addrs { var err error if addrarr[i], err = JavaListenAddr(env, addr.Protocol, addr.Address); err != nil { return jutil.NullObject, err } } return jutil.JObjectArray(env, addrarr, jListenSpecAddressClass) }
// JavaNetworkAddressArray converts a Go slice of net.Addr values into a Java // array of NetworkAddress objects. func JavaNetworkAddressArray(env jutil.Env, addrs []net.Addr) (jutil.Object, error) { arr := make([]jutil.Object, len(addrs)) for i, addr := range addrs { var err error if arr[i], err = JavaNetworkAddress(env, addr); err != nil { return jutil.NullObject, err } } return jutil.JObjectArray(env, arr, jNetworkAddressClass) }
// JavaCaveatArray converts the provided Go Caveat slice into a Java Caveat array. func JavaCaveatArray(env jutil.Env, caveats []security.Caveat) (jutil.Object, error) { if caveats == nil { return jutil.NullObject, nil } cavArr := make([]jutil.Object, len(caveats)) for i, caveat := range caveats { var err error if cavArr[i], err = JavaCaveat(env, caveat); err != nil { return jutil.NullObject, err } } return jutil.JObjectArray(env, cavArr, jCaveatClass) }
// JavaServerStatus converts the provided rpc.ServerStatus value into a Java // ServerStatus object. func JavaServerStatus(env jutil.Env, status rpc.ServerStatus) (jutil.Object, error) { // Create Java state enum value. jState, err := JavaServerState(env, status.State) if err != nil { return jutil.NullObject, err } // Create Java array of publisher entries. pubarr := make([]jutil.Object, len(status.PublisherStatus)) for i, e := range status.PublisherStatus { var err error if pubarr[i], err = JavaPublisherEntry(env, e); err != nil { return jutil.NullObject, err } } jPublisherStatus, err := jutil.JObjectArray(env, pubarr, jPublisherEntryClass) if err != nil { return jutil.NullObject, err } // Create an array of endpoint strings. eps := make([]string, len(status.Endpoints)) for i, ep := range status.Endpoints { eps[i] = ep.String() } lnErrors := make(map[jutil.Object]jutil.Object) for addr, lerr := range status.ListenErrors { jAddr, err := JavaListenAddr(env, addr.Protocol, addr.Address) if err != nil { return jutil.NullObject, err } jVExp, err := jutil.JVException(env, lerr) if err != nil { return jutil.NullObject, err } lnErrors[jAddr] = jVExp } jLnErrors, err := jutil.JObjectMap(env, lnErrors) if err != nil { return jutil.NullObject, err } proxyErrors := make(map[jutil.Object]jutil.Object) for s, perr := range status.ProxyErrors { jVExp, err := jutil.JVException(env, perr) if err != nil { return jutil.NullObject, err } proxyErrors[jutil.JString(env, s)] = jVExp } jProxyErrors, err := jutil.JObjectMap(env, proxyErrors) if err != nil { return jutil.NullObject, err } // Create final server status. publisherEntrySign := jutil.ClassSign("io.v.v23.rpc.PublisherEntry") jServerStatus, err := jutil.NewObject(env, jServerStatusClass, []jutil.Sign{serverStateSign, jutil.BoolSign, jutil.ArraySign(publisherEntrySign), jutil.ArraySign(jutil.StringSign), jutil.MapSign, jutil.MapSign}, jState, status.ServesMountTable, jPublisherStatus, eps, jLnErrors, jProxyErrors) if err != nil { return jutil.NullObject, err } return jServerStatus, nil }