Example usage for org.hibernate.collection.internal PersistentBag wasInitialized

List of usage examples for org.hibernate.collection.internal PersistentBag wasInitialized

Introduction

In this page you can find the example usage for org.hibernate.collection.internal PersistentBag wasInitialized.

Prototype

@Override
    public final boolean wasInitialized() 

Source Link

Usage

From source file:org.apache.struts2.json.JSONWriter.java

License:Apache License

/**
 * Instrospect bean and serialize its properties
 *///from w w  w  .ja  v a2s.  co  m
protected void bean(Object object) throws JSONException {

    this.add("{");

    BeanInfo info;

    try {
        Class clazz = object.getClass();

        info = ((object == this.root) && this.ignoreHierarchy) ? getBeanInfoIgnoreHierarchy(clazz)
                : getBeanInfo(clazz);

        PropertyDescriptor[] props = info.getPropertyDescriptors();

        boolean hasData = false;

        for (PropertyDescriptor prop : props) {
            String name = prop.getName();
            Method accessor = prop.getReadMethod();

            // ////System.out.println("===============================  +.......................................    +"+((accessor
            // != null)?accessor.getName(): ""));
            Method baseAccessor = findBaseAccessors(clazz, accessor);

            if (baseAccessor != null) {
                if (baseAccessor.isAnnotationPresent(JSON.class)) {
                    JSONAnnotationFinder jsonFinder = new JSONAnnotationFinder(baseAccessor).invoke();
                    if (!jsonFinder.shouldSerialize())
                        continue;
                    if (jsonFinder.getName() != null) {
                        name = jsonFinder.getName();
                    }
                }
                // ignore "class" and others
                if (this.shouldExcludeProperty(prop)) {
                    continue;
                }
                String expr = null;
                if (this.buildExpr) {
                    expr = this.expandExpr(name);

                    if (this.shouldExcludeProperty(expr)) {
                        continue;
                    }
                    expr = this.setExprStack(expr);
                }
                // ////System.out.println("==   "+name+"=========+++++++++++++++++++++++++++++++++  =>    "+object);
                Object value = accessor.invoke(object);
                //                    if(value !=null)
                //                    System.out.println("+++++++++++++++++++++++++ >  "+value.getClass().getName()) ;
                if (value != null && value instanceof PersistentBag) {
                    PersistentBag persistentBag = (PersistentBag) value;
                    if (persistentBag.wasInitialized()) {

                    } else {
                        value = null;
                    }

                }

                if (baseAccessor.isAnnotationPresent(JSONFieldBridge.class)) {
                    value = getBridgedValue(baseAccessor, value);
                }

                boolean propertyPrinted = this.add(name, value, accessor, hasData);
                hasData = hasData || propertyPrinted;
                if (this.buildExpr) {
                    this.setExprStack(expr);
                }
            }
        }

        // special-case handling for an Enumeration - include the name() as
        // a property */
        if (object instanceof Enum) {
            Object value = ((Enum) object).name();
            this.add("_name", value, object.getClass().getMethod("name"), hasData);
        }
    } catch (Exception e) {
        // Loggerfactory.error(logger, e);
        throw new JSONException(e);
    }

    this.add("}");
}