commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sameer Nanda <sam5...@gmail.com>
Subject Re: Managing XML Output from Betwixt
Date Sun, 02 Oct 2005 17:12:02 GMT
Guys,

I tried different things, but still not getting the perfect XML output what
I need from Betwixt... Did anyone get a change to look at my problem?

Thanks
Sam

On 9/30/05, Sameer Nanda <sam504u@gmail.com> wrote:
>
> HI All,
>
> I have this scenario where I want an XML document to be generated by
> BEtwixt which should look like this:
> ------------------------------
>
> <user>
> <authorizations>
>
> <authorization>
> <functionName>read</functionName>
> <objectType>employee</objectType>
> </authorization>
>
> <authorization>
> <functionName>read</functionName>
> <objectType>customer</objectType>
> </authorization>
>
> <authorization>
> <functionName>write</functionName>
> <objectType>employee</objectType>
> </authorization>
>
> <authorization>
> <functionName>write</functionName>
> <objectType>customer</objectType>
> </authorization>
>
> </authorizations>
> <firstName>sameer</firstName>
> <id>1</id>
> <lastName>nanda</lastName>
> </user>
> ------------------------------
>
>
>
> So I have a User Bean which has an id, firstName,lastName and
> authorizations of type Authorizations :
> ------------------------------
>
> import java.util.ArrayList;
> import java.util.List;
>
> public class User {
>
> private int id;
> private String firstName;
> private String lastName;
> private Authorizations authorizations;
>
> public User() {}
>
> public User(int id, String firstName, String lastName, Authorizations
> authorizations) {
> this.id <http://this.id> = id;
> this.firstName = firstName;
> this.lastName = lastName;
> this.authorizations = authorizations;
> }
>
> public int getId() {
> return this.id <http://this.id>;
> }
> public void setId(int id) {
> this.id <http://this.id> = id;
> }
>
> public String getFirstName()
> {
> return this.firstName;
> }
> public void setFirstName(String firstName)
> {
> this.firstName = firstName;
> }
>
> public String getLastName()
> {
> return this.lastName;
> }
> public void setLastName(java.lang.String lastName)
> {
> this.lastName = lastName;
> }
>
> public Authorizations getAuthorizations() {
> return this.authorizations;
> }
> public void setAuthorizations(Authorizations auhtorizations) {
> this.authorizations = authorizations;
> }
>
> }
> ------------------------------
>
>
> Then, I have an Authorizations class which has a list of authorization of
> type Authorization (shown below)
>
> code:
> ------------------------------
>
>
>
> package mms.Objects;
> import java.util.Iterator
> ;
> import java.util.List;
>
> public class Authorizations {
> 	
> 	private Authorization[] authorization = new Authorizations[50];
> 	
> 	public Authorizations() {}
> 	
> 	public Authorizations(List l1, List l2) {
>
> 		for(int i=0; i < l1.size(); i++) {
> 				String object_type = (String)l1.get(i);
> 				String function_name = (String)l2.get(i);
> 				authorization[i] = new Authorization(object_type,function_name);
> 		 }
>
> 	}
> 	
> 	public Authorization[] getAuthorization() {
>     	return this.authorization;
>     }
>     public void setAuthorization(Authorization[] auhtorization) {
>     	this.authorization = authorization;
>     }
>
>
> ------------------------------
>
>
> And finally my Authorization class has a String object_type and String
> function_name. Here's how the Authorization class looks like:
>
> code:
> ------------------------------
>
>
>
> package mms.Objects;
>
> import java.util.List
> ;
>
> public class Authorization {
> 	
> 	private String objectType;
> 	private String functionName;
> 	
> 	public Authorization() {}
> 	public Authorization(String objectType,String functionName) {
> 		this.objectType
>  = objectType;
> 		this.functionName = functionName;
> 	}
> 	
> 	public String getObjectType() {
> 		return this.objectType;
> 	}
> 	public void setObjectType(String objectType) {
> 		this.objectType = objectType;
>
> 	}
> 	
> 	public String getFunctionName() {
> 		return this.functionName;
> 	}
> 	public void setFunctionName(String functionName) {
> 		this.functionName = functionName;
> 	}
>
>
> ------------------------------
>
>
>
> And now when I call the Authorizations Class passsing two Lists l1 and l2
> (which are records fetched from the DB) and make a call to Betwixt to
> generate XML documents,
>
> Authorizations a = new Authorizations(l1,l2);
>
> beanWriter.write("user", new User(1, "abc", "xyz", a));
> my_result = outputWriter.toString();
>
> the XML output that is generated by Betwixt is :
>
>  ------------------------------
>
>
> <user>
> <authorizations>
> <authorization>
> <Authorization>
> <functionName>read</functionName>
> <objectType>employee</objectType>
>  </Authorization>
>  <Authorization>
> <functionName>read</functionName>
> <objectType>customer</objectType>
> </Authorization>
>  <Authorization>
> <functionName>write</functionName>
> <objectType>employee</objectType>
> </Authorization>
>  <Authorization>
> <functionName>write</functionName>
> <objectType>customer</objectType>
>  </Authorization>
> </authorization>
> </authorizations>
> <firstName>sameer</firstName>
> <id>1</id>
> <lastName>nanda</lastName>
> </user>
>
>  ------------------------------
>
> which is not really what I want. All I want is a root element <user> to
> have a <authorizations> which has a bunch of <authorization> in them.
>
> <user>
>
> <authorizations>
>
>  <authorization>
>  .........
>  </authorization>
>
>  <authorization>
>  ......
>  </authorization>
>
> <authorization>
>  .......
>  </authorization>
>
>  </authorizations>
>
> </user>
>
>
>
> Can someone help me solve this ???? This is bugging me since long .....
> ALso if anybody could guide to me some working examples on Betwixt that
> would be great.
>
> Thanks for all the help. Looking forward to hear from someone ASAP.
>
> Regards
> -Sam
>
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message