/** * Limit the objects to which {@link Policy} instances are applied. This * reduces the overhead of creating a {@link HashSet} for every object in * a returned graph. * * @param obj e.g. the argument to {@link #listActiveRestrictions(IObject)}. * @return true if the given object should <em>not</em> be restricted. */ protected boolean filterObject(IObject obj) { if (obj == null) { return true; } return !types.contains( Utils.trueClass(obj.getClass())); // Fix javassist }
/** * instantiates an object using the trueClass. * * @param source * Regular or CGLIB-based class. * @return the regular Java instance. */ public static <T extends IObject> T trueInstance(Class<T> source) { final Class<T> trueClass = trueClass(source); final T result; try { result = trueClass.newInstance(); } catch (InstantiationException e) { throw new RuntimeException(String.format(msg, trueClass), e); } catch (IllegalAccessException e) { throw new RuntimeException("Not allowed to create class:" + trueClass, e); } return result; }
/** * Return the short type name of an {@link Annotation}. If the instance is * an {@link ome.model.annotations.TextAnnotation} the returned value will * be "TextAnnotation". * * @param annotation * @return See above. */ private String annotationTypeString(Annotation annotation) { Class ac = Utils.trueClass(annotation.getClass()); int dot = ac.getName().lastIndexOf('.'); if (dot < 0) { dot = -1; } String at = ac.getName().substring(dot + 1, ac.getName().length()); return at; }
protected Class findClass(Class source) { return (Class) c2c().get(Utils.trueClass(source)); }
@SuppressWarnings("unchecked") public static <T extends IObject> T reflectiveNewInstance(T f) { Method m; T iobj; try { Class<T> c = (Class<T>) Utils.trueClass(f.getClass()); iobj = c.newInstance(); } catch (Exception e) { InternalException ie = new InternalException(e.getMessage()); ie.setStackTrace(e.getStackTrace()); throw ie; } return iobj; }
@SuppressWarnings("unchecked") public void onApplicationEvent(ApplicationEvent arg0) { if (arg0 instanceof ReindexMessage) { ReindexMessage<? extends IObject> rm = (ReindexMessage<? extends IObject>) arg0; for (IObject obj : rm.objects) { Class trueClass = Utils.trueClass(obj.getClass()); addEventLog(trueClass, obj.getId()); } } }
protected void internalDelete(IObject obj, UpdateFilter filter, Session session) { if (getBeanHelper().getLogger().isDebugEnabled()) { getBeanHelper().getLogger().debug(" Internal delete. "); } session.delete(session.load(Utils.trueClass(obj.getClass()), obj .getId())); }
public Map<String, Long> getLockingIds(final Class<IObject> type, final long id, final Long groupId) { String groupClause = ""; if (groupId != null) { groupClause = "and details.group.id <> " + groupId; } // since it's a managed entity it's class.getName() might // contain // some byte-code generation string final Class<? extends IObject> klass = Utils.trueClass(type); // the values that could possibly link to this instance. final String[][] checks = metadata.getLockChecks(klass); return this.metadata.countLocks(osf.getSession(), id, checks, groupClause); }
@RolesAllowed("user") public boolean canAnnotate(final IObject obj) { if (obj == null) { throw new ApiUsageException("Argument cannot be null"); } final Class<? extends IObject> c = Utils.trueClass(obj.getClass()); IObject trusted = iQuery.get(c, obj.getId()); return aclVoter.allowAnnotate(trusted, trusted.getDetails()); }
@RolesAllowed("user") public boolean canUpdate(final IObject obj) { if (obj == null) { throw new ApiUsageException("Argument cannot be null"); } final Class<? extends IObject> c = Utils.trueClass(obj.getClass()); IObject trusted = iQuery.get(c, obj.getId()); return aclVoter.allowUpdate(trusted, trusted.getDetails()); }
/** * Default implementation of the * {@link #set(String, Object, Document, LuceneOptions)} * method which calls * {@link #set_file(String, IObject, Document, LuceneOptions)} * {@link #set_annotations(String, IObject, Document, LuceneOptions)}, * {@link #set_details(String, IObject, Document, LuceneOptions)}, * and finally * {@link #set_custom(String, IObject, Document, LuceneOptions)}. * as well as all {@link Annotation annotations}. */ @Override public void set(String name, Object value, Document document, LuceneOptions opts) { IObject object = (IObject) value; // Store class in COMBINED String cls = Utils.trueClass(object.getClass()).getName(); add(document, null, cls, opts); set_file(name, object, document, opts); set_annotations(name, object, document, opts); set_details(name, object, document, opts); set_folders(name, object, document, opts); set_custom(name, object, document, opts); }
@RolesAllowed("user") @SuppressWarnings("unchecked") @Transactional(readOnly = false) public void moveToCommonSpace(IObject... iObjects) { // ticket:1794 final AdminPrivilege modifyGroup = adminPrivileges.getPrivilege(AdminPrivilege.VALUE_MODIFY_GROUP); for (IObject object : iObjects) { if (object != null) { Long id = object.getId(); Class<IObject> c = (Class<IObject>) Utils.trueClass(object.getClass()); IObject o = iQuery.get(c, id); ExperimenterGroup g = o.getDetails().getGroup(); if (!g.getId().equals(getSecurityRoles().getUserGroupId())) { adminOrPiOfGroups(modifyGroup, g); internalMoveToCommonSpace(o); } } } }
@Override @SuppressWarnings("unchecked") protected void entityIsDetached(MergeEvent event, Map copyCache) { final IObject orig = (IObject) event.getOriginal(); final EventSource source = event.getSession(); if (HibernateUtils.isUnloaded(orig)) { log("Reloading unloaded entity:", event.getEntityName(), ":", orig .getId()); Class<?> k = Utils.trueClass(orig.getClass()); Object obj = source.load(k, orig.getId()); event.setResult(obj); copyCache.put(event.getEntity(), obj); // TODO this was maybe a bug. check if findDirty is superfluous. } else if (orig instanceof Event) { final Object obj = source.load(Event.class, orig.getId()); event.setResult(obj); copyCache.put(event.getEntity(), obj); } else { super.entityIsDetached(event, copyCache); } fillReplacement(event); }