commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 29833] New: - Enhancement on the documentation for non-public classes and inner classes
Date Mon, 28 Jun 2004 02:19:16 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=29833>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=29833

Enhancement on the documentation for non-public classes and inner classes

           Summary: Enhancement on the documentation for non-public classes
                    and inner classes
           Product: Commons
           Version: 1.0 Alpha
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Enhancement
          Priority: Other
         Component: Betwixt
        AssignedTo: commons-dev@jakarta.apache.org
        ReportedBy: daniel.amadei@click21.com.br


Hi All,

This is the doc I wrote about using inner classes / non-public classes. The 
inners classes approach is not so important but the other one I believe is of a 
great value because the Betwixt engine quietly ignores the attributes as it 
falls in the IllegalAccessException and I believe it will help a lot if it's 
well documented. 

If some native english speaker could review I'd thank very much as I'm from 
Brazil and my english is far from perfect.

--------------------------------------------------------------------------------
WORKING WITH INNER CLASSES:

When using a public inner class, static or not, the name of the element obey 
the Inner Classes naming semantics (using $). 

The example bellow show this behaviour:

	public class BetWixtWriter {

		public class TallTreeBean {

			private float heightOfTree;
    
			public TallTreeBean(float height) {
				setHeightOfTree(height);
			}
    
			public float getHeightOfTree() {
				return heightOfTree;
			}	
    
			public void setHeightOfTree(float heightOfTree) {
				this.heightOfTree = heightOfTree;
			}
		}


		public static final void main(String args[]) throws Exception{
        
			// create write and set basic properties
			BeanWriter writer = new BeanWriter();
			writer.getXMLIntrospector().setAttributesForPrimitives
(true);
			writer.enablePrettyPrint();
			writer.setWriteIDs(false);
        
			// set a custom name mapper for attributes
			writer.getXMLIntrospector().setAttributeNameMapper(new 
HyphenatedNameMapper());
			// set a custom name mapper for elements
			writer.getXMLIntrospector().setElementNameMapper(new 
DecapitalizeNameMapper());
        
			// write out the bean
			writer.write(new BetWixtWriter().new TallTreeBean
(15.1f));
			System.out.println("");
		}
	}

Now, the application should print out an xml fragment which looks like: 

<betWixtWriter$TallTreeBean height-of-tree="15.1"/>

--------------------------------------------------------------------------------
WORKING WITH NON-PUBLIC CLASSES:

When working with a non-public inner/normal class, it's attributes are not 
acessible even if the methods are public:

public class BetWixtWriter {

	public static final void main(String args[]) throws Exception{
        
		// create write and set basic properties
		BeanWriter writer = new BeanWriter();
		writer.getXMLIntrospector().setAttributesForPrimitives(true);
		writer.enablePrettyPrint();
		writer.setWriteIDs(false);

		// set a custom name mapper for attributes
		writer.getXMLIntrospector().setAttributeNameMapper(new 
HyphenatedNameMapper());
		// set a custom name mapper for elements
		writer.getXMLIntrospector().setElementNameMapper(new 
DecapitalizeNameMapper());

		// write out the bean
		TallTreeBean ttb = new TallTreeBean(15.1f);
			
		writer.write(ttb);
		System.out.println("");
	}
}

class TallTreeBean {

	private float heightOfTree;

	public TallTreeBean(float height) {
		setHeightOfTree(height);
	}
    
	public float getHeightOfTree() {
		return heightOfTree;
	}	
    
	public void setHeightOfTree(float heightOfTree) {
		this.heightOfTree = heightOfTree;
	}
}

Now, the application should print out an xml fragment which looks like the 
following, so only the name of the class is present, without the attribute: 

<tallTreeBean/> 

So, be aware when using non-public JavaBeans classes.

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message