You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Sameer Nanda <sa...@gmail.com> on 2005/09/30 23:37:07 UTC

Managing XML Output from Betwixt

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

Re: Managing XML Output from Betwixt

Posted by Russell Simpkins <ru...@hotmail.com>.
I think it is the way you have designed your classes that is causing you the problem. Bitwix is only outputting what you have created. If you want your xml to appear as you have requested, you must re-design your class code. I think you need to drop the Authorizations class, and let User have an array of Authorization and you should get the xml you desire.


  ----- Original Message ----- 
  From: Sameer Nanda 
  To: commons-user@jakarta.apache.org 
  Sent: Sunday, October 02, 2005 1:12 PM
  Subject: Re: Managing XML Output from Betwixt


  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 <sa...@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
  >
  >
  >

Re: Managing XML Output from Betwixt

Posted by Sameer Nanda <sa...@gmail.com>.
Hi Remi,

Thanks for your reply. But I have already tried doing the exact same this...
in that case I get an XML o/p as follows:

<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>Demo</firstName>
<id>569</id>
<lastName>Demo</lastName>
</user>


So the problem is its taking the name of the Class (i.e. Authorization ) to
create an element and inserts it into <authorizations> tag !!!
Which is my I am more frustrated ..... Do you have any idea how this can be
resolved ???

Thanks in advance again

-Sameer

On 10/2/05, Rémi Dewitte <re...@gide.net> wrote:
>
> Maybe you should have a list of Authorization inside of your main class
> and
> get rid of the class Authorizations.
> Rémi
>
> Le Dimanche 2 Octobre 2005 19:12, Sameer Nanda a écrit:
> > 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 <sa...@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:
> > > ------------------------------
> > >Hi Remi,
>
> Thanks for your reply. But I have alrea
> > > <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> <http://this.id> = id;
> > > this.firstName = firstName;
> > > this.lastName = lastName;
> > > this.authorizations = authorizations;
> > > }
> > >
> > > public int getId() {
> > > return this.id <http://this.id> <http://this.id>;
> > > }
> > > public void setId(int id) {
> > > this.id <http://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
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>

Re: Managing XML Output from Betwixt

Posted by Rémi Dewitte <re...@gide.net>.
Maybe you should have a list of Authorization inside of your main class and 
get rid of the class Authorizations.
Rémi

Le Dimanche 2 Octobre 2005 19:12, Sameer Nanda a écrit :
> 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 <sa...@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

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


Re: Managing XML Output from Betwixt

Posted by Sameer Nanda <sa...@gmail.com>.
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 <sa...@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
>
>
>