Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2004-2010 Oracle Corporation. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: Kohsuke Kawaguchi /
  
 
 package org.kohsuke.stapler.export;
 
 
 import java.util.List;
Writes all the property of one ExportedBean to DataWriter.

Author(s):
Kohsuke Kawaguchi
 
 public class Model<T> {
    
The class being modeled.
 
     public final Class<T> type;

    
Model for the super class.
 
     public final Model<? super T> superModel;
 
     private final Property[] properties;
 
     /*package*/ final ModelBuilder parent;
     /*package*/ final int defaultVisibility;

    
Lazily loaded "*.javadoc" file for this model.
 
     private volatile Properties javadoc;
 
     /*package*/ Model(ModelBuilder parentClass<T> type) {
         this. = parent;
         this. = type;
         ExportedBean eb = type.getAnnotation(ExportedBean.class);
         if(eb ==null)
             throw new NotExportableException(type);
         this. = eb.defaultVisibility();
         
         Class<? super T> sc = type.getSuperclass();
         if(sc!=null && sc.getAnnotation(ExportedBean.class)!=null)
              = parent.get(sc);
         else
              = null;
 
         List<Propertyproperties = new ArrayList<Property>();
 
         // Use reflection to find out what properties are exposed.
         forField f : type.getFields() ) {
             if(f.getDeclaringClass()!=typecontinue;
             Exported exported = f.getAnnotation(Exported.class);
             if(exported !=null)
                 properties.add(new FieldProperty(this,fexported));
         }
 
         forMethod m : type.getMethods() ) {
             if(m.getDeclaringClass()!=typecontinue;
             Exported exported = m.getAnnotation(Exported.class);
             if(exported !=null)
                 properties.add(new MethodProperty(this,mexported));
         }
 
         this. = properties.toArray(new Property[properties.size()]);
         Arrays.sort(this.);
 
         parent.models.put(type,this);
     }

    
Gets all the exported properties.
 
     public List<PropertygetProperties() {
         return Collections.unmodifiableList(Arrays.asList());
     }

    
Loads the javadoc list and returns it as java.util.Properties.

Returns:
always non-null.
    /*package*/ Properties getJavadoc() {
        if(!=null)    return ;
        synchronized(this) {
            if(!=null)    return ;
            // load
            Properties p = new Properties();
            InputStream is = .getClassLoader().getResourceAsStream(.getName().replace('$''/').replace('.''/') + ".javadoc");
            if(is!=null) {
                try {
                    try {
                        p.load(is);
                    } finally {
                        is.close();
                    }
                } catch (IOException e) {
                    throw new RuntimeException("Unable to load javadoc for "+,e);
                }
            }
             = p;
            return ;
        }
    }

    
Writes the property values of the given object to the writer.
    public void writeTo(T objectDataWriter writerthrows IOException {
        writeTo(object,0,writer);
    }

    
Writes the property values of the given object to the writer.

Parameters:
pruner Controls which portion of the object graph will be sent to the writer.
    public void writeTo(T objectTreePruner prunerDataWriter writerthrows IOException {
        writer.startObject();
        writeNestedObjectTo(object,pruner,writer);
        writer.endObject();
    }

    
Writes the property values of the given object to the writer.

Deprecated:
as of 1.139
Parameters:
baseVisibility This parameters controls how much data we'd be writing, by adding bias to the sub tree cutting. A property with visibility X will be written if the current depth Y and baseVisibility Z satisfies X+Z>Y. 0 is the normal value. Positive value means writing bigger tree, and negative value means writing smaller trees.
    public void writeTo(T objectint baseVisibilityDataWriter writerthrows IOException {
        writeTo(object,new ByDepth(1-baseVisibility),writer);
    }
    void writeNestedObjectTo(T objectTreePruner prunerDataWriter writerthrows IOException {
        if( !=null)
            .writeNestedObjectTo(object,pruner,writer);
        for (Property p : )
            p.writeTo(object,pruner,writer);
    }
New to GrepCode? Check out our FAQ X