protected boolean isWrapped(Object obj) { return AutoBeanUtils.getAutoBean(obj) != null; }
public void encode(EncodeState state, Object value) { if (value == null) { state.sb.append("null"); return; } doEncode(state, AutoBeanUtils.getAutoBean(value)); }
static Splittable tryExtractSplittable(Object value) { AutoBean<?> bean = AutoBeanUtils.getAutoBean(value); if (bean != null) { value = bean; } if (bean instanceof HasSplittable) { return ((HasSplittable) bean).getSplittable(); } return null; }
protected <W> W getFromWrapper(W obj) { // Some versions of javac have problem inferring the generics here return AutoBeanUtils.<W, W> getAutoBean(obj).as(); }
/** * This method checks that a proxy object is either immutable, or already edited by this context. */ private <T> AutoBean<T> checkStreamsNotCrossed(T object) { AutoBean<T> bean = AutoBeanUtils.getAutoBean(object); if (bean == null) { // Unexpected; some kind of foreign implementation? throw new IllegalArgumentException(object.getClass().getName()); } State otherState = bean.getTag(REQUEST_CONTEXT_STATE); if (!bean.isFrozen() && otherState != this.state) { /* * This means something is way off in the weeds. If a bean is editable, it's supposed to be * associated with a RequestContext. */ assert otherState != null : "Unfrozen bean with null RequestContext"; /* * Already editing the object in another context or it would have been in the editing map. */ throw new IllegalArgumentException("Attempting to edit an EntityProxy" + " previously edited by another RequestContext"); } return bean; }
public BaseProxy getOriginalProxy() { AutoBean<? extends BaseProxy> parent = AutoBeanUtils.getAutoBean(v.getRootBean()).getTag(Constants.PARENT_OBJECT); return parent == null ? null : parent.as(); }
AutoBean<?> maybeValue = AutoBeanUtils.getAutoBean(value); AutoBean<?> maybeOther = AutoBeanUtils.getAutoBean(otherValue); if (maybeValue != null && maybeOther != null) { value = maybeValue;
ProxyAutoBean<Object> toReturn = (ProxyAutoBean<Object>) AutoBeanUtils.getAutoBean(toWrap); if (toReturn == null) {
AutoBean<BaseProxy> bean = AutoBeanUtils.getAutoBean((BaseProxy) maybeEntityProxy); Object domain = bean.getTag(Constants.DOMAIN_OBJECT); if (domain == null && detectDeadEntities) {
public Object key(Object object) { if (object instanceof EntityProxy) { return ((EntityProxy) object).stableId(); } else if (object instanceof ValueProxy) { AutoBean<?> bean = AutoBeanUtils.getAutoBean(object); // Possibly replace an editable ValueProxy with its immutable base AutoBean<?> parent = bean.getTag(Constants.PARENT_OBJECT); if (parent != null) { object = parent.as(); } return new ValueProxyHolder((ValueProxy) object); } return null; } };
/** * ValueProxies are equal if they are from the same RequestContext and all of * their properties are equal. */ public static boolean equals(AutoBean<? extends ValueProxy> bean, Object o) { if (!(o instanceof ValueProxy)) { return false; } AutoBean<ValueProxy> other = AutoBeanUtils.getAutoBean((ValueProxy) o); if (other == null) { // Unexpected, could be an user-provided implementation? return false; } if (!stableId(bean).getProxyClass().equals(stableId(other).getProxyClass())) { // Compare AppleProxies to AppleProxies return false; } // Compare the entire object graph return AutoBeanUtils.deepEquals(bean, other); }
private Splittable nonCollectionEncode(Object obj) { if (obj instanceof Collection) { // TODO: Allow for the encoding of nested collections. See issue 5974. // Once we do this, this can turn into an assert. throw new RuntimeException( "Unable to encode request as JSON payload; Request methods must have parameters of the form List<T> or Set<T>, where T is a scalar (non-collection) type."); } Splittable value; if (obj instanceof Enum && getAutoBeanFactory() instanceof EnumMap) { value = ValueCodex.encode(((EnumMap) getAutoBeanFactory()).getToken((Enum<?>) obj)); } else if (ValueCodex.canDecode(obj.getClass())) { value = ValueCodex.encode(obj); } else { // XXX user-provided implementation of interface? value = AutoBeanCodex.encode(AutoBeanUtils.getAutoBean(obj)); } return value; } }
private Object maybeWrap(Class<?> intf, Object toReturn) { if (toReturn == null) { return null; } AutoBean<?> returnBean = AutoBeanUtils.getAutoBean(toReturn); if (returnBean != null) { return returnBean.as(); } if (TypeUtils.isValueType(intf) || TypeUtils.isValueType(toReturn.getClass()) || bean.getConfiguration().getNoWrap().contains(intf)) { return toReturn; } if (toReturn.getClass().isArray()) { /* * We can't reliably wrap arrays, but the only time we typically see an * array is with toArray() call on a collection, since arrays aren't * supported property types. */ return toReturn; } ProxyAutoBean<Object> newBean = new ProxyAutoBean<Object>(bean.getFactory(), intf, bean.getConfiguration(), toReturn); return newBean.as(); } }
AutoBeanUtils.<Collection<?>, Collection<?>> getAutoBean((Collection<?>) values .get(propertyName)); if (value != null) {
AutoBean temp = AutoBeanUtils.getAutoBean((Collection) value); @SuppressWarnings("unchecked") AutoBean<Collection<?>> bean = (AutoBean<Collection<?>>) temp; AutoBean temp = AutoBeanUtils.getAutoBean((Map) value); @SuppressWarnings("unchecked") AutoBean<Map<?, ?>> bean = (AutoBean<Map<?, ?>>) temp; ProxyAutoBean<?> bean = (ProxyAutoBean<?>) AutoBeanUtils.getAutoBean(value); if (visitor.visitReferenceProperty(name, bean, x)) { if (value != null) {
/** * EntityProxies are equal if they are from the same RequestContext and their * stableIds are equal. */ public static boolean equals(AutoBean<? extends EntityProxy> bean, Object o) { if (!(o instanceof EntityProxy)) { return false; } AutoBean<EntityProxy> other = AutoBeanUtils.getAutoBean((EntityProxy) o); if (other == null) { // Unexpected, could be an user-provided implementation? return false; } // Object comparison intentional. True if both null or both the same return stableId(bean).equals(stableId(other)) && nonDiffingRequestContext(bean) == nonDiffingRequestContext(other); }
/** * Given a domain object, return a value that can be encoded by the client. * * @param domainValue the domain object to be converted into a client-side * value * @param assignableTo the type in the client to which the resolved value * should be assignable. A value of {@code null} indicates that any * resolution will suffice. * @param propertyRefs the property references requested by the client */ public Object resolveClientValue(Object domainValue, Type assignableTo, Set<String> propertyRefs) { Resolution toReturn = resolveClientValue(domainValue, assignableTo); if (toReturn == null) { return null; } addPathsToResolution(toReturn, "", expandPropertyRefs(propertyRefs)); while (!toProcess.isEmpty()) { List<Resolution> working = new ArrayList<Resolution>(toProcess); toProcess.clear(); for (Resolution resolution : working) { if (resolution.hasWork()) { AutoBean<BaseProxy> bean = AutoBeanUtils.getAutoBean((BaseProxy) resolution.getClientObject()); bean.accept(new PropertyResolver(resolution)); } } } return toReturn.getClientObject(); }
@Override public boolean visitReferenceProperty(String propertyName, AutoBean<?> value, PropertyContext ctx) { value = AutoBeanUtils.getAutoBean(values.get(propertyName)); if (value != null) { if (isValueType(ctx.getType()) || isEntityType(ctx.getType())) { /* * Value proxies must be cloned upfront, since the value is replaced outright. */ @SuppressWarnings("unchecked") AutoBean<BaseProxy> valueBean = (AutoBean<BaseProxy>) value; ctx.set(editProxy(valueBean.as())); } else { ctx.set(value.as()); } } return false; }
final AutoBean<? extends BaseProxy> root = AutoBeanUtils.getAutoBean(rootObject); if (root == null) {
AutoBean<T> otherBean = AutoBeanUtils.getAutoBean(returnValue); if (otherBean != null) { otherBean.setTag(REQUEST_CONTEXT_STATE, bean.getTag(REQUEST_CONTEXT_STATE));