[jboss-cvs] jboss-seam/seam-gen/icefaces/src ...
Michael Yuan
michael.yuan at jboss.com
Sun Jul 15 20:54:17 EDT 2007
User: myuan
Date: 07/07/15 20:54:17
Added: seam-gen/icefaces/src EntityHome.java.ftl
EntityList.java.ftl TimerBean.java
TimerBeanImpl.java
Log:
Support for icefaces
Revision Changes Path
1.1 date: 2007/07/16 00:54:17; author: myuan; state: Exp;jboss-seam/seam-gen/icefaces/src/EntityHome.java.ftl
Index: EntityHome.java.ftl
===================================================================
${pojo.packageDeclaration}
<#assign classbody>
<#assign entityName = pojo.shortName>
<#assign componentName = util.lower(entityName)>
<#assign homeName = componentName + "Home">
@${pojo.importType("org.jboss.seam.annotations.Name")}("${homeName}")
public class ${entityName}Home extends ${pojo.importType("org.jboss.seam.framework.EntityHome")}<${entityName}>
{
<#foreach property in pojo.allPropertiesIterator>
<#if c2h.isManyToOne(property)>
<#assign parentPojo = c2j.getPOJOClass(cfg.getClassMapping(property.value.referencedEntityName))>
<#assign parentHomeName = util.lower(parentPojo.shortName) + "Home">
@${pojo.importType("org.jboss.seam.annotations.In")}(create=true)
${parentPojo.shortName}Home ${parentHomeName};
</#if>
</#foreach>
<#assign idName = entityName + util.upper(pojo.identifierProperty.name)>
<#if c2j.isComponent(pojo.identifierProperty)>
<#assign idType = entityName + "Id">
<#else>
<#assign idType = pojo.importType(pojo.identifierProperty.type.returnedClass.name)>
</#if>
public void set${idName}(${idType} id)
{
setId(id);
}
public ${idType} get${idName}()
{
return (${idType}) getId();
}
<#if pojo.isComponent(pojo.identifierProperty)>
public ${entityName}Home()
{
set${idName}( new ${entityName}Id() );
}
@Override
public boolean isIdDefined()
{
<#foreach property in pojo.identifierProperty.value.propertyIterator>
<#assign getter = pojo.getGetterSignature(property)>
<#if !c2j.isPrimitive( pojo.getJavaTypeName(property, true) )>
if ( get${idName}().${getter}()==null ) return false;
<#else>
if ( get${idName}().${getter}()==0 ) return false;
</#if>
</#foreach>
return true;
}
</#if>
@Override
protected ${entityName} createInstance()
{
${entityName} ${componentName} = new ${entityName}();
<#if pojo.isComponent(pojo.identifierProperty)>
${componentName}.setId( new ${entityName}Id() );
</#if>
return ${componentName};
}
public void wire()
{
<#foreach property in pojo.allPropertiesIterator>
<#if c2h.isManyToOne(property)>
<#assign parentPojo = c2j.getPOJOClass(cfg.getClassMapping(property.value.referencedEntityName))>
<#if parentPojo.shortName!=pojo.shortName>
<#assign parentHomeName = util.lower(parentPojo.shortName) + "Home">
<#assign setter = "set" + pojo.getPropertyName(property)>
${parentPojo.shortName} ${property.name}=${parentHomeName}.getDefinedInstance();
if ( ${property.name}!=null )
{
getInstance().${setter}(${property.name});
}
</#if>
</#if>
</#foreach>
}
public boolean isWired()
{
<#foreach property in pojo.allPropertiesIterator>
<#if (c2h.isManyToOne(property) && !property.optional)>
<#assign getter = pojo.getGetterSignature(property)>
if ( getInstance().${getter}()==null ) return false;
</#if>
</#foreach>
return true;
}
public ${entityName} getDefinedInstance()
{
return isIdDefined() ? getInstance() : null;
}
<#foreach property in pojo.allPropertiesIterator>
<#assign getter = pojo.getGetterSignature(property)>
<#if c2h.isOneToManyCollection(property)>
<#assign childPojo = c2j.getPOJOClass(property.value.element.associatedClass)>
public ${pojo.importType("java.util.List")}<${childPojo.shortName}> ${getter}() {
return getInstance() == null ?
null : new ${pojo.importType("java.util.ArrayList")}<${childPojo.shortName}>( getInstance().${getter}() );
}
</#if>
</#foreach>
}
</#assign>
${pojo.generateImports()}
${classbody}
1.1 date: 2007/07/16 00:54:17; author: myuan; state: Exp;jboss-seam/seam-gen/icefaces/src/EntityList.java.ftl
Index: EntityList.java.ftl
===================================================================
<#assign entityName = pojo.shortName>
<#assign componentName = util.lower(entityName)>
<#assign listName = componentName + "List">
${pojo.packageDeclaration}
import org.jboss.seam.annotations.Name;
import org.jboss.seam.framework.EntityQuery;
import java.util.List;
import java.util.Arrays;
@Name("${listName}")
public class ${entityName}List extends EntityQuery
{
private static final String[] RESTRICTIONS = {
<#foreach property in pojo.allPropertiesIterator>
<#if !c2h.isCollection(property) && !c2h.isManyToOne(property)>
<#if c2j.isComponent(property)>
<#foreach componentProperty in property.value.propertyIterator>
<#if componentProperty.value.typeName == "string">
"lower(${componentName}.${property.name}.${componentProperty.name}) like concat(lower(${'#'}{${listName}.${componentName}.${property.name}.${componentProperty.name}}),'%')",
</#if>
</#foreach>
<#else>
<#if property.value.typeName == "string">
"lower(${componentName}.${property.name}) like concat(lower(${'#'}{${listName}.${componentName}.${property.name}}),'%')",
</#if>
</#if>
</#if>
</#foreach>
};
<#if pojo.isComponent(pojo.identifierProperty)>
private ${entityName} ${componentName};
public ${entityName}List()
{
${componentName} = new ${entityName}();
${componentName}.setId( new ${entityName}Id() );
}
<#else>
private ${entityName} ${componentName} = new ${entityName}();
</#if>
@Override
public String getEjbql()
{
return "select ${componentName} from ${entityName} ${componentName}";
}
@Override
public Integer getMaxResults()
{
return 25;
}
public ${entityName} get${entityName}()
{
return ${componentName};
}
@Override
public List<String> getRestrictions()
{
return Arrays.asList(RESTRICTIONS);
}
}
1.1 date: 2007/07/16 00:54:17; author: myuan; state: Exp;jboss-seam/seam-gen/icefaces/src/TimerBean.java
Index: TimerBean.java
===================================================================
/*
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* "The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations under
* the License.
*
* The Original Code is ICEfaces 1.5 open source software code, released
* November 5, 2006. The Initial Developer of the Original Code is ICEsoft
* Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
* 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
*
* Contributor(s): _____________________.
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
* License), in which case the provisions of the LGPL License are
* applicable instead of those above. If you wish to allow use of your
* version of this file only under the terms of the LGPL License and not to
* allow others to use your version of this file under the MPL, indicate
* your decision by deleting the provisions above and replace them with
* the notice and other provisions required by the LGPL License. If you do
* not delete the provisions above, a recipient may use your version of
* this file under either the MPL or the LGPL License."
*
*/
package @actionPackage@;
import javax.ejb.Local;
/**
* @author ICEsoft Technologies, Inc.
*/
@Local
public interface TimerBean {
public String getCurrentTime();
public String getRenderMode();
public void remove();
public String getCurrentConversation();
public String getLongRunning();
}
1.1 date: 2007/07/16 00:54:17; author: myuan; state: Exp;jboss-seam/seam-gen/icefaces/src/TimerBeanImpl.java
Index: TimerBeanImpl.java
===================================================================
/*
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* "The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations under
* the License.
*
* The Original Code is ICEfaces 1.5 open source software code, released
* November 5, 2006. The Initial Developer of the Original Code is ICEsoft
* Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
* 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
*
* Contributor(s): _____________________.
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
* License), in which case the provisions of the LGPL License are
* applicable instead of those above. If you wish to allow use of your
* version of this file only under the terms of the LGPL License and not to
* allow others to use your version of this file under the MPL, indicate
* your decision by deleting the provisions above and replace them with
* the notice and other provisions required by the LGPL License. If you do
* not delete the provisions above, a recipient may use your version of
* this file under either the MPL or the LGPL License."
*
*/
package @actionPackage@;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Destroy;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.Begin;
import org.jboss.seam.annotations.In;
import org.jboss.seam.ScopeType;
import org.jboss.seam.core.Manager;
import javax.faces.context.FacesContext;
import javax.ejb.Stateful;
import javax.ejb.Remove;
import java.util.Date;
import java.text.DateFormat;
import java.io.Serializable;
import javax.faces.event.ActionEvent;
import com.icesoft.faces.webapp.xmlhttp.PersistentFacesState;
import com.icesoft.faces.webapp.xmlhttp.RenderingException;
import com.icesoft.faces.async.render.RenderManager;
import com.icesoft.faces.async.render.IntervalRenderer;
import com.icesoft.faces.async.render.Renderable;
import com.icesoft.faces.context.ViewListener;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* @author ICEsoft Technologies, Inc.
*
*/
@Name("timer")
@Scope(ScopeType.PAGE)
public class TimerBeanImpl implements Renderable, ViewListener, Serializable {
private DateFormat dateFormatter;
private static Log log = LogFactory.getLog(TimerBeanImpl.class);
@In
private RenderManager renderManager;
private boolean doneSetup;
private IntervalRenderer ir;
private PersistentFacesState state = PersistentFacesState.getInstance();
private String synchronous;
private int myId;
private static int id;
public PersistentFacesState getState() {
return state;
}
public void renderingException( RenderingException re) {
// System.out.println("Exception in rendering: " + re);
// re.printStackTrace();
if(log.isTraceEnabled() ) {
log.trace("*** View obsoleted: " + myId );
}
cleanup();
}
public TimerBeanImpl() {
dateFormatter = DateFormat.getDateTimeInstance();
myId = ++id;
}
public String getCurrentTime() {
state = PersistentFacesState.getInstance();
if (!doneSetup) {
if(log.isTraceEnabled() ) {
log.trace("*** new TimerBean renderable... " + myId );
}
state.addViewListener(this );
FacesContext fc = FacesContext.getCurrentInstance();
synchronous = (String) fc.getExternalContext().getInitParameterMap().
get( "com.icesoft.faces.synchronousUpdate" );
boolean timed = Boolean.valueOf( (String) fc.getExternalContext().getInitParameterMap().
get("org.icesoft.examples.serverClock"));
if (timed) {
ir = renderManager.getIntervalRenderer("org.icesoft.clock.clockRenderer");
ir.setInterval(5000);
ir.add(this);
ir.requestRender();
}
}
doneSetup = true;
return dateFormatter.format( new Date( System.currentTimeMillis() ) );
}
public String getRenderMode() {
return synchronous + " " + myId;
}
// Don't make this begin a conversation as this class is
// intended to be used in a footer.
// If this method starts a conversation
// it can't be added to the foot of applications that don't
// expect conversations to already be in progress
public String getCurrentConversation() {
Manager m = Manager.instance();
return m.getCurrentConversationId();
}
public String getLongRunning() {
Manager m = Manager.instance();
return Boolean.toString( m.isLongRunningConversation() );
}
@Remove
@Destroy
public void remove() {
if(log.isTraceEnabled() ) {
log.trace("*** View removed: " + myId );
}
cleanup();
}
public void viewCreated() {
}
public void viewDisposed() {
if(log.isTraceEnabled() ) {
log.trace("*** View disposed: " + myId );
}
cleanup();
}
private void cleanup() {
if (ir != null) {
ir.remove(this);
if (ir.isEmpty() ) {
if(log.isTraceEnabled() ) {
log.trace("*** IntervalRenderer Stopped " );
}
ir.requestStop();
}
}
}
}
More information about the jboss-cvs-commits
mailing list