/**
* Copyright 1999-2001 by Nordija <www.nordija.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
**/
package com.nordija.portal.entity;
import com.nordija.midtier.ejb.BaseEntityBean;
import com.nordija.midtier.ejb.EntityVersionException;
// TODO move into separate class
import com.nordija.midtier.utilitybeans.sequence.sessionbean.SequenceServiceHome;
import com.nordija.midtier.utilitybeans.sequence.sessionbean.SequenceService;
import com.nordija.midtier.utilitybeans.sequence.entitybean.Range;
import java.rmi.RemoteException;
import javax.naming.*;
import javax.ejb.*;
/**
* Core bean code for the Portlet bean.
*
* Entity Bean - Container Managed Persistence
*
* Generated by Nordija BeanBuilder - www.nordija.com
*
* @author Nordija ApS
*/
public class PortletBean extends BaseEntityBean implements PortletBusiness
{
/** Name of portal portlet - Persisted by container */
public String name;
/** Unique portal portlet id - Persisted by container */
public long id;
/** Filename of JavaServer Page acting as UI for the portal portlet - Persisted by container */
public String jspfile;
/** Description of the portal portlet - Persisted by container */
public String description;
/** Specifies whether the portal portlet requires a wide or a narrow space in the HTML page */
public int widenarrow;
/**
* Should have been a boolean but too much of a hassle
* 1=true, 0=false
*/
public int deletable;
/**
* Should have been a boolean but too much of a hassle
* 1=true, 0=false
*/
public int editable;
/**
* This method corresponds to a create method in the home interface
*
*/
public PortletPK ejbCreate() throws RemoteException
{
try {
// TODO: Reuse at central point
Context ctx = new InitialContext();
SequenceServiceHome home = (SequenceServiceHome)ctx.lookup("nordija.portal.sequence");
SequenceService seq = home.create();
Range range = seq.getSequenceRange("Portlet",true,1);
// Init values
this.id = range.getNextUniqueNumber();
this.name = "No name";
this.jspfile = "none.jsp";
this.description = "No description";
this.widenarrow = Portlet.WIDE_PORTLET;
this.deletable=1;
this.editable=0;
} catch(javax.naming.NamingException ne) {
throw new RemoteException("Error while looking up the Sequence service",ne);
} catch(javax.ejb.CreateException ce) {
throw new RemoteException("Error while trying to create new instance. Check the SequenceService is installed and running correctly",ce);
}
ejbCreateDone();
return new PortletPK(id);
}
/**
* This method is required by the EJB Specification, but is not used here.
*
*/
public void ejbPostCreate()
{
}
public PortletPK ejbCreate(PortletPK pk, String name, int widenarrow) throws RemoteException
{
if(widenarrow != Portlet.WIDE_PORTLET && widenarrow != Portlet.NARROW_PORTLET)
throw new RemoteException("Illegal portlet size (widenarrow)");
this.id = pk.id;
this.name = name;
this.jspfile = "none.jsp";
this.description = "No description";
this.widenarrow = widenarrow;
this.deletable=1;
this.editable=0;
ejbCreateDone();
return new PortletPK(id);
}
public void ejbPostCreate(PortletPK pk, String name, int widenarrow)
{
}
/**
* Get the value of the name attribute.
* (Name of portal portlet)
*
* @return Value of name attribute
*/
public String getName()
{
return name;
}
/**
* Get the value of the id attribute.
* (Unique portal portlet id)
*
* @return Value of id attribute
*/
public long getId()
{
return id;
}
/**
* Get the value of the jspfile attribute.
* (Filename of JavaServer Page acting as UI for the portal portlet)
*
* @return Value of jspfile attribute
*/
public String getJspfile()
{
return jspfile;
}
/**
* Get the value of the description attribute.
* (Description of the portal portlet)
*
* @return Value of description attribute
*/
public String getDescription()
{
return description;
}
/**
* Set name (Name of portal portlet)
*
* @param name New value for name
*/
public void setName(String name)
{
this.name = name;
setModified(true);
}
/**
* Set id (Unique portal portlet id)
*
* @param id New value for id
*/
private void setId(long id)
{
this.id = id;
setModified(true);
}
/**
* Set jspfile (Filename of JavaServer Page acting as UI for the portal portlet)
*
* @param jspfile New value for jspfile
*/
public void setJspfile(String jspfile)
{
this.jspfile = jspfile;
setModified(true);
}
/**
* Set description (Description of the portal portlet)
*
* @param description New value for description
*/
public void setDescription(String description)
{
this.description = description;
setModified(true);
}
/**
* Determined whether the portlet expects a wide column or not in
* the HTML page.
* @return true if a wide HTML space is required
*/
public boolean isWide() {
return (widenarrow == Portlet.WIDE_PORTLET);
}
/**
* Specifies that the portlet will require a wide space in the HTML page
* A portlet cannot be both wide and narrow, so this changes the state of
* both values.
*/
public void setWide() {
widenarrow = Portlet.WIDE_PORTLET;
setModified(true);
}
/**
* Determined whether the portlet can exist in a narrow column or not in
* the HTML page.
* @return true if a narrow HTML space can be used
*/
public boolean isNarrow() {
return (widenarrow == Portlet.NARROW_PORTLET);
}
/**
* Specifies that the portlet can use a narrow space in the HTML page
* A portlet cannot be both wide and narrow, so this changes the state of
* both values.
*/
public void setNarrow() {
widenarrow = Portlet.NARROW_PORTLET;
setModified(true);
}
/**
* Set the value of editable.
* @param v Value to assign to editable.
*/
public void setEditable(boolean v) {
if(v)
editable=1;
else
editable=0;
setModified(true);
}
/**
* Get the value of editable.
* @return Value of editable.
*/
public boolean getEditable() {
return (editable==1);
}
/**
* Set the value of deletable.
* @param v Value to assign to deletable.
*/
public void setDeletable(boolean v) {
if(v)
deletable=1;
else
deletable=0;
setModified(true);
}
/**
* Get the value of deletable.
* @return Value of deletable.
*/
public boolean getDeletable() {
return (deletable==1);
}
/**
* Get all attributes of the bean in a single data structure
*
* @return An instance of PortletData
*/
public PortletData getAll()
{
return new PortletData(name, id, jspfile, description, widenarrow, getDeletable(), getEditable());
}
// This might be a good place to add methods that are more specific to
// your application. Don't forget to add methods to the PortletBusiness
// class if you want them to be remotely accessible.
// Please also consider additional get/set method that operate on several
// attributes in a single method - in particular if you plan to use this
// bean across a network connection.
}