aQute.lib.json.ObjectHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of biz.aQute.remote.api Show documentation
Show all versions of biz.aQute.remote.api Show documentation
A main program (executable JAR) that will listen to port 29998. At first, it can only answer that it is an Envoy (a limited agent). The only function it supports is installing a -runpath. It will then create a framework + agent and transfer the connection to the just installed agent who will then install the bundles. This JAR is a main command for JPM called bndremote. In JPM, it will start up with debug enabled. This JAR does some highly complicated class loading wizardy to ensure that it does not enforce any constraints on the -runpath.
The newest version!
package aQute.lib.json;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Supplier;
public class ObjectHandler extends Handler {
@SuppressWarnings("rawtypes")
final Class rawClass;
final Field fields[];
final Type types[];
final Object defaults[];
final Field extra;
final Supplier> factory;
ObjectHandler(JSONCodec codec, Class> c) throws Exception {
rawClass = c;
factory = newInstanceFunction(c);
List fields = new ArrayList<>();
for (Field f : c.getFields()) {
if (Modifier.isStatic(f.getModifiers()))
continue;
fields.add(f);
}
this.fields = fields.toArray(new Field[0]);
// Sort the fields so the output is canonical
Arrays.sort(this.fields, (o1, o2) -> o1.getName()
.compareTo(o2.getName()));
types = new Type[this.fields.length];
defaults = new Object[this.fields.length];
Field x = null;
for (int i = 0; i < this.fields.length; i++) {
if (this.fields[i].getName()
.equals("__extra"))
x = this.fields[i];
types[i] = this.fields[i].getGenericType();
}
if (x != null && Map.class.isAssignableFrom(x.getType()))
extra = x;
else
extra = null;
try {
Object template = factory.get();
for (int i = 0; i < this.fields.length; i++) {
defaults[i] = getField(this.fields[i], template);
}
} catch (Exception e) {
// Ignore
}
}
@Override
public void encode(Encoder app, Object object, Map
© 2015 - 2025 Weber Informatics LLC | Privacy Policy