/** * Constructor for when there is an associated {@link JClass}. * * @param jclass Java model class * @param annotationType annotation to scan for */ protected AnnotationScanner(JClass<T> jclass, Class<A> annotationType) { super(jclass.getType(), annotationType); this.jclass = jclass; }
@ProvidesProperty(TypeContainer.NAME_PROPERTY) public String propertyName() { return this.jclass != null ? this.jclass.getName() : this.type.getSimpleName(); }
/** * Get the {@link JField}s that are common to all of the given types. * * @param jclasses types to inspect * @return map containing common {@link JField}s, or null if {@code jclasses} is empty */ static SortedMap<Integer, JField> getCommonJFields(Iterable<? extends JClass<?>> jclasses) { Preconditions.checkArgument(jclasses != null, "null jclasses"); TreeMap<Integer, JField> jfields = null; for (JClass<?> jclass : jclasses) { // TODO: keep only fields with the same name; prefer indexed (sub-)fields if (jfields == null) jfields = new TreeMap<>(jclass.getJFieldsByStorageId()); else jfields.keySet().retainAll(jclass.getJFieldsByStorageId().keySet()); } return jfields; } }
super(ui, (jobj != null ? "Edit " : "New ") + jclass.getName()); this.setWidth(600, Sizeable.Unit.PIXELS); this.setHeight(450, Sizeable.Unit.PIXELS); final SortedMap<String, JField> jfieldMap = jclass.getJFieldsByName(); for (Map.Entry<String, JField> entry : jfieldMap.entrySet()) { final String fieldName = entry.getKey();
jclass.createFields(this); + supertype + ": use of uniqueExclude() requires unique = true"); jclass.addCompositeIndex(this, supertype, annotation); jclass.getClassGenerator().generateClass();
private JField getJField(final JObject jobj) { return JObjectContainer.this.jdb.getJClass(jobj.getObjId()).getJField(this.storageId, JField.class); }
final JField jfield = jclass.getJFieldsByName().get(name); if (jfield == null) throw new IllegalArgumentException("error accessing field `" + name + "': there is no such field in " + objType);
private <T> JClass<T> createJClass(String name, int storageId, Class<T> type) { return new JClass<>(this, name, storageId, type); }
/** * Quick lookup for the {@link JField} corresponding to the given object and field storage ID. * * @param id object ID * @param storageId field storage ID * @param <T> expected field type * @return list of {@link JClass}es whose type is {@code type} or a sub-type, ordered by storage ID * @throws TypeNotInSchemaVersionException if {@code id} has a type that does not exist in this instance's schema version * @throws UnknownFieldException if {@code storageId} does not correspond to any field in the object's type */ @SuppressWarnings("unchecked") <T extends JField> T getJField(ObjId id, int storageId, Class<T> type) { final JField jfield = this.typeFieldMap.get(this.getTypeFieldKey(id.getStorageId(), storageId)); if (jfield == null) { this.getJClass(id.getStorageId()).getJField(storageId, type); // should always throw the appropriate exception assert false; } try { return type.cast(jfield); } catch (ClassCastException e) { throw new UnknownFieldException(storageId, jfield + "' is not a " + type.getSimpleName().replaceAll("^J(.*)Field$", "").toLowerCase() + " field"); } }
SortKeyContainer(Permazen jdb, JClass<?> jclass) { this(jdb, jclass, jclass.getType()); }
/** * Get "invalid annotation" error message prefix that describes the annotation on the specified method. * * @param method the method to check * @return error message prefix */ protected String getErrorPrefix(Method method) { return "invalid " + this.getAnnotationDescription() + " annotation on method " + method + " for type `" + this.jclass.getName() + "': "; } }
for (JField jfield : this.getJClass(id).getJFieldsByStorageId().values()) { jfield.visit(new JFieldSwitchAdapter<Void>() {
public Node(JClass<?> jclass) { this(jclass.getType(), jclass); }
private String getTypeExpression(ParseSession session, boolean defaultJObject) { return this.jclass != null ? this.jclass.getName() : this.type != null ? session.relativizeClassName(this.type) + ".class" : defaultJObject ? session.relativizeClassName(Object.class) + ".class" : ""; }
/** * Constructor. * * @param jdb underlying database * @param type type restrictions, or null for none */ public TypeContainer(Permazen jdb, Class<?> type) { super(Node.class); Preconditions.checkArgument(jdb != null, "null jdb"); this.jdb = jdb; // Get the types of all JClasses assignable to the given type, and use lowest common ancestor as the "top type" final HashSet<Class<?>> types = this.jdb.getJClasses().values().stream() .filter(jclass -> type == null || type.isAssignableFrom(jclass.getType())) .map(JClass::getType) .collect(Collectors.toCollection(HashSet::new)); this.rootType = !types.isEmpty() ? Util.findLowestCommonAncestorOfClasses(types).getRawType() : Object.class; }
/** * Constructor. * * <p> * Uses a default {@code objectMapper} that creates new exported objects using the default constructor of the model class. * * @param jtx the transaction from which to export objects * @throws IllegalArgumentException if {@code jtx} is null */ public ExportContext(JTransaction jtx) { Preconditions.checkArgument(jtx != null); this.jtx = jtx; this.objectMapper = id -> { final Class<?> type = this.jtx.jdb.getJClass(id).getType(); try { return type.newInstance(); } catch (Exception e) { throw new IllegalArgumentException("can't instatiate " + type + " using default constructor for POJO export", e); } }; }
/** * Create a new instance of the given type in this transaction. * * @param jclass object type * @param <T> Java model type * @return newly created instance * @throws IllegalArgumentException if {@code jclass} is not valid for this instance * @throws StaleTransactionException if this transaction is no longer usable */ public <T> T create(JClass<T> jclass) { final ObjId id = this.tx.create(jclass.storageId); return jclass.getType().cast(this.get(id)); }
@Override public Object get(ParseSession session) { return JTransaction.getCurrent().getAll(jclass.getType()); } };
@Override public Class<?> getType(ParseSession session) { try { return session.getPermazen().getJClass(id).getType(); } catch (TypeNotInSchemaVersionException e) { return UntypedJObject.class; } catch (IllegalArgumentException e) { return Object.class; } } };
private void newButtonClicked() { final JClass<?> jclass = this.objectChooser.getJClass(); if (jclass == null) { Notification.show("Can't create object having unknown type", "Please select an object type first", Notification.Type.WARNING_MESSAGE); return; } this.log.info("creating new object of type " + jclass.getType().getName()); new JObjectEditorWindow(this.getUI(), this.session, jclass).show(); }