Hello.
We decided to start using GWT Ent in out project. There are so many
features in it, but we started from using reflection and annotations.
Everything worked perfectly for the first glance except that after
using this library we started to get "Stop running script?" error in
IE 8:
--------------------------
Windows Internet Explorer
---------------------------
Stop running this script?
A script on this page is causing Internet Explorer to run slowly.
If it continues to run, your computer might become
unresponsive.
---------------------------
Yes No
---------------------------
The strange thing is that this error is not always being reproduced,
but quite frequently: ~80% of the times. Also when we run it locally
on Jetty server it isn't reporoduced. If we run it in Hosted Mode it
isn't reproduced neither locally nor remotely. So the problem is in
compiled JavaScrpt, and Explorer doesn't like it.
Few words about the part of our app where we use reflection and
annotations (our own annotations which assist us in serialization/
deserialization). We have entities every of which inherits some
abstract entity: Send, Reseive or SendReceive. These parent classes
are responsible for serializing the entity, deserializing the entity
and both respectively. Parent class has logic which looks for the
annotated fields in the current object and puts their values into XML
or gets their values from XML and populates the fields - depends on
whether we send or receive the XML.
Below is the entity which, most likely, causes the error:
package com.npq.fm.client.entity.visitor;
import com.google.gwt.xml.client.Node;
import com.gwtent.client.reflection.Reflectable;
import com.npq.fm.client.entity.EntityBase;
import com.npq.fm.client.entity.EntityBaseSendReceive;
import com.npq.fm.client.entity.InheritedFieldMapping;
import com.npq.fm.client.entity.Mappable;
import
com.npq.fm.client.entity.requesterandcontact.businesspartner.BusinessPartner;
import com.npq.fm.client.entity.roomreservation.RoomReservation;
import com.npq.fm.client.entity.user.UserDetails;
import com.npq.fm.client.util.ConversionException;
import com.npq.fm.client.util.Utils;
import java.util.Date;
/**
* The Entity describes Visitor.
*
* @author Tetyana Naumova
* @version 8 Apr 2010
*/
@Reflectable(assignableClasses = true, superClasses = true)
@InheritedFieldMapping(fieldNames = {"id"}, tagNames = {"VISITOR_ID"},
shortDates = {false})
public class Visitor extends EntityBaseSendReceive {
/* --- Static Fields --- */
/** The list of objects node name. */
public final static String VISITORS_LIST = "VISITORS_LIST";
/** Object node name. */
public final static String NPQVISITOR_STR = "NPQVISITOR_STR";
/** Object node name. */
public final static String VISITOR_STR = "VISITOR_STR";
/* --- Instance Fields --- */
/** Telephone number of the person. */
@Mappable("PHONE")
private String telephone;
/** Email of the person. */
@Mappable("EMAIL")
private String eMail;
/** The first name. */
@Mappable("FIRSTNAME")
private String firstName;
/** The title. */
@Mappable("TITLE")
private String title;
/** The title. */
@Mappable("TITLE_DESC")
private String titleDescription;
/** The gender. */
@Mappable("SEX")
private String gender;
/** The gender description. */
@Mappable("SEX_DESC")
private String genderDescription;
/** The company. */
@Mappable("EMPLOYER")
private String company;
/** The family name. */
@Mappable("LASTNAME")
private String familyName;
/** The remark. */
@Mappable("XCOMMENT")
private String remark;
/** The requester. */
@Mappable("REQUESTER_ID")
private String requester;
/** The requester. */
@Mappable("PARTNER")
private String partner;
/** The pass number. */
@Mappable("VISDOCUMENTDATA")
private String passNumber;
/** The time from. */
@Mappable("CHECKINDATETIME")
private Date timeFrom;
/** The time to. */
@Mappable("TIME_TO")
private Date timeTo;
/** The reservation id. */
@Mappable("RESERVATION_ID")
private String reservationId;
/** The room id. */
@Mappable("ROOM_ID")
private String roomId;
/** The is business partner. */
private boolean isBusinessPartner;
/** The full name. */
@Mappable("FULLNAME")
private String fullName;
/**
* The link to connected room reservation. This field is declared
as EntityBase because of problem in GWT ENT
* library with java.math package.
*/
private EntityBase roomReservation;
/* --- Constructors --- */
/**
* Instantiates a new visitor.
*/
public Visitor() {
nodeName = NPQVISITOR_STR;
}
/**
* Copy constructor.
*
* @param visitor the instance to be copied.
*/
public Visitor(Visitor visitor) {
this();
setBusinessPartner(visitor.isBusinessPartner);
setCompany(visitor.getCompany());
setEMail(visitor.getEMail());
setFullName(visitor.getFullName());
setFirstName(visitor.getFirstName());
setFamilyName(visitor.getFamilyName());
setGender(visitor.getGender());
setGenderDescription(visitor.getGenderDescription());
setId(visitor.getId());
setRemark(visitor.getRemark());
setRequester(visitor.getRequester());
setRoomId(visitor.getRoomId());
setTelephone(visitor.getTelephone());
setTimeFrom(visitor.getTimeFrom());
setTimeTo(visitor.getTimeTo());
setTitle(visitor.getTitle());
setTitleDescription(visitor.getTitleDescription());
setPartner(visitor.getPartner());
}
/**
* Creates visitor from the specified {@link BusinessPartner
business partner}.
*
* @param businessPartner the {@link BusinessPartner business
partner} where the data to be taken from.
*/
public Visitor(BusinessPartner businessPartner) {
this();
setId(businessPartner.getId());
setFullName(businessPartner.getFullName());
setFirstName(businessPartner.getFirstName());
setFamilyName(businessPartner.getFamilyName());
setName(businessPartner.getName());
isBusinessPartner = true;
}
/**
* Creates visitor from the specified business {@link UserDetails
user details}.
*
* @param data the {@link UserDetails user details} object where
the data to be taken from.
*/
public Visitor(UserDetails data) {
this();
setPartner(data.getId());
setFullName(data.getName());
setFirstName(data.getFirstName());
setFamilyName(data.getFamilyName());
setBusinessPartner(true);
setCompany(data.getDepartmentName());
setEMail(data.getEMail());
setGender(data.getSex());
setTitle(data.getTitle());
setTelephone(data.getTelephone());
setRoomId(data.getRefRoom());
}
/**
* Instantiates a new visitor.
*
* @param nodeName the node name
*/
public Visitor(String nodeName) {
this.nodeName = nodeName;
}
/* --- Methods --- */
/**
* Gets the first name.
*
* @return the first name
*/
public String getFirstName() {
return firstName;
}
/**
* Gets the family name.
*
* @return the family name
*/
public String getFamilyName() {
return familyName;
}
/**
* Sets the first name.
*
* @param firstName the firstName to set
*/
public void setFirstName(String firstName) {
this.firstName = firstName;
}
/**
* Sets the family name.
*
* @param familyName the familyName to set
*/
public void setFamilyName(String familyName) {
this.familyName = familyName;
}
/**
* @return the telephone
*/
public String getTelephone() {
return telephone;
}
/**
* @param telephone the telephone to set
*/
public void setTelephone(String telephone) {
this.telephone = telephone;
}
/**
* @return the eMail
*/
public String getEMail() {
return eMail;
}
/**
* @param mail the eMail to set
*/
public void setEMail(String mail) {
eMail = mail;
}
/**
* @return the title
*/
public String getTitle() {
return title;
}
/**
* @param title the title to set
*/
public void setTitle(String title) {
this.title = title;
}
/**
* @return the gender
*/
public String getGender() {
return gender;
}
/**
* @param gender the gender to set
*/
public void setGender(String gender) {
this.gender = gender;
}
/**
* @return the company
*/
public String getCompany() {
return company;
}
/**
* @param company the company to set
*/
public void setCompany(String company) {
this.company = company;
}
/**
* @return the timeFrom
*/
public Date getTimeFrom() {
return timeFrom;
}
/**
* @param timeFrom the timeFrom to set
*/
public void setTimeFrom(Date timeFrom) {
this.timeFrom = timeFrom;
}
/**
* @return the timeTo
*/
public Date getTimeTo() {
return timeTo;
}
/**
* @param timeTo the timeTo to set
*/
public void setTimeTo(Date timeTo) {
this.timeTo = timeTo;
}
/**
* @return the remark
*/
public String getRemark() {
return remark;
}
/**
* @param remark the remark to set
*/
public void setRemark(String remark) {
this.remark = remark;
}
/**
* @return the requester
*/
public String getRequester() {
return requester;
}
/**
* @param requester the requester to set
*/
public void setRequester(String requester) {
this.requester = requester;
}
/**
* @return the isBusinessPartner
*/
public boolean isBusinessPartner() {
return isBusinessPartner;
}
/**
* @param isBusinessPartner the isBusinessPartner to set
*/
public void setBusinessPartner(boolean isBusinessPartner) {
this.isBusinessPartner = isBusinessPartner;
}
/**
* Getter for the property {@link #fullName}.
*
* @return the value of the property.
*/
public String getFullName() {
return fullName;
}
/**
* Setter for the property {@link #fullName}.
*
* @param fullName the value to be set.
*/
public void setFullName(String fullName) {
this.fullName = fullName;
}
/**
* @return the titleDescription
*/
public String getTitleDescription() {
return titleDescription;
}
/**
* @param titleDescription the titleDescription to set
*/
public void setTitleDescription(String titleDescription) {
this.titleDescription = titleDescription;
}
/**
* @return the genderDescription
*/
public String getGenderDescription() {
return genderDescription;
}
/**
* @param genderDescription the genderDescription to set
*/
public void setGenderDescription(String genderDescription) {
this.genderDescription = genderDescription;
}
/**
* @param nodeName the nodeName to set
*/
public void setNodeName(String nodeName) {
this.nodeName = nodeName;
}
/**
* @return the reservationId
*/
public String getReservationId() {
return reservationId;
}
/**
* @param reservationId the reservationId to set
*/
public void setReservationId(String reservationId) {
this.reservationId = reservationId;
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (telephone != null ?
telephone.hashCode() : 0);
result = 31 * result + (eMail != null ? eMail.hashCode() : 0);
result = 31 * result + (firstName != null ?
firstName.hashCode() : 0);
result = 31 * result + (title != null ? title.hashCode() : 0);
result = 31 * result + (titleDescription != null ?
titleDescription.hashCode() : 0);
result = 31 * result + (gender != null ? gender.hashCode() :
0);
result = 31 * result + (genderDescription != null ?
genderDescription.hashCode() : 0);
result = 31 * result + (company != null ? company.hashCode() :
0);
result = 31 * result + (familyName != null ?
familyName.hashCode() : 0);
result = 31 * result + (remark != null ? remark.hashCode() :
0);
result = 31 * result + (requester != null ?
requester.hashCode() : 0);
result = 31 * result + (timeFrom != null ?
timeFrom.hashCode() : 0);
result = 31 * result + (timeTo != null ? timeTo.hashCode() :
0);
result = 31 * result + (reservationId != null ?
reservationId.hashCode() : 0);
result = 31 * result + (isBusinessPartner ? 1 : 0);
result = 31 * result + (fullName != null ?
fullName.hashCode() : 0);
return result;
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
return false;
}
Visitor visitor = (Visitor) o;
if (isBusinessPartner != visitor.isBusinessPartner) {
return false;
}
if (company != null ? !company.equals(visitor.company) :
visitor.company != null) {
return false;
}
if (eMail != null ? !eMail.equals(visitor.eMail) :
visitor.eMail != null) {
return false;
}
if (familyName != null ? !
familyName.equals(visitor.familyName) : visitor.familyName != null) {
return false;
}
if (firstName != null ? !firstName.equals(visitor.firstName) :
visitor.firstName != null) {
return false;
}
if (fullName != null ? !fullName.equals(visitor.fullName) :
visitor.fullName != null) {
return false;
}
if (gender != null ? !gender.equals(visitor.gender) :
visitor.gender != null) {
return false;
}
if (genderDescription != null ? !
genderDescription.equals(visitor.genderDescription)
: visitor.genderDescription != null) {
return false;
}
if (remark != null ? !remark.equals(visitor.remark) :
visitor.remark != null) {
return false;
}
if (requester != null ? !requester.equals(visitor.requester) :
visitor.requester != null) {
return false;
}
if (reservationId != null ? !
reservationId.equals(visitor.reservationId) : visitor.reservationId !=
null) {
return false;
}
if (telephone != null ? !telephone.equals(visitor.telephone) :
visitor.telephone != null) {
return false;
}
if (timeFrom != null ? !timeFrom.equals(visitor.timeFrom) :
visitor.timeFrom != null) {
return false;
}
if (timeTo != null ? !timeTo.equals(visitor.timeTo) :
visitor.timeTo != null) {
return false;
}
if (title != null ? !title.equals(visitor.title) :
visitor.title != null) {
return false;
}
if (titleDescription != null ? !
titleDescription.equals(visitor.titleDescription)
: visitor.titleDescription != null) {
return false;
}
return true;
}
/**
* @return the roomId
*/
public String getRoomId() {
return roomId;
}
/**
* @param roomId the roomId to set
*/
public void setRoomId(String roomId) {
this.roomId = roomId;
}
/**
* @return the passNumber
*/
public String getPassNumber() {
return passNumber;
}
/**
* @param passNumber the passNumber to set
*/
public void setPassNumber(String passNumber) {
this.passNumber = passNumber;
}
/**
* Gets the {@link #roomReservation} property.
* <p/>
* Needs to be casted to {@link RoomReservation}.
*
* @return the roomReservation
*/
public EntityBase getRoomReservation() {
return roomReservation;
}
/**
* Sets the room reservation.
*
* @param roomReservation the roomReservation to set
*/
public void setRoomReservation(RoomReservation roomReservation) {
this.roomReservation = roomReservation;
}
/**
* {@inheritDoc}
*/
@Override
public void decode(Node xmlNode) throws ConversionException
{
super.decode(xmlNode);
setBusinessPartner(Utils.notNullAndNotEmpty(id));
}
/**
* @return the partner
*/
public String getPartner() {
return partner;
}
/**
* @param partner the partner to set
*/
public void setPartner(String partner) {
this.partner = partner;
}
}
Parent class:
package com.npq.fm.client.entity;
import com.npq.fm.client.model.remote.net.obj.NetworkObjectReceive;
import com.npq.fm.client.model.remote.net.obj.NetworkObjectSend;
/**
* The Class that implements {@link NetworkObjectReceive} and {@link
NetworkObjectSend}.
*
* @author Tetyana Naumova
* @version 8 Apr 2010
*/
public class EntityBaseSendReceive extends EntityBaseSendReceivePart
implements NetworkObjectReceive,
NetworkObjectSend {
/* --- Instance Fields --- */
/** The node name. */
protected String nodeName = "";
/* --- Constructors --- */
/**
* Instantiates a new entity base send receive.
*/
public EntityBaseSendReceive() {
}
/**
* Instantiates a new entity base send receive.
*
* @param nodeName the node name
*/
public EntityBaseSendReceive(String nodeName) {
this.nodeName = nodeName;
}
/* --- Methods --- */
/**
* {@inheritDoc}
*/
@Override
public String getNodeName() {
return nodeName;
}
}
Parent class:
package com.npq.fm.client.entity;
import com.google.gwt.xml.client.Node;
import com.gwtent.client.reflection.ClassType;
import
com.npq.fm.client.model.remote.net.obj.NetworkObjectReceivePart;
import com.npq.fm.client.model.remote.net.obj.NetworkObjectSendPart;
import com.npq.fm.client.util.ConversionException;
import com.npq.fm.client.util.XmlNodeEncoder;
/**
* Base class for all entities for request sending and receiving with
ability so serialize automatically.
*
* @author Victor Kovtun
* @version 6 Apr 2010
*/
public class EntityBaseSendReceivePart extends EntityBaseEx implements
Entity, NetworkObjectSendPart,
NetworkObjectReceivePart {
/* --- Instance Fields --- */
/** Delegate for behavior as {@link NetworkObjectSendPart}. */
private EntityBaseSendPart entityBaseSendPart;
/** Delegate for behavior as {@link NetworkObjectReceivePart}. */
private EntityBaseReceivePart entityBaseReceivePart;
/* --- Constructors --- */
/**
* Default constructor.
*/
public EntityBaseSendReceivePart() {
entityBaseSendPart = new EntityBaseSendPart() {
/**
* {@inheritDoc}
*/
@Override
protected ClassType getClassType() {
return EntityBaseSendReceivePart.this.getClassType();
}
/**
* {@inheritDoc}
*/
@Override
protected boolean isNotBaseClass(ClassType
currentClassType) {
return
EntityBaseSendReceivePart.this.isNotBaseClass(currentClassType);
}
/**
* {@inheritDoc}
*/
@Override
protected Entity getCurrentEntity() {
return EntityBaseSendReceivePart.this;
}
};
entityBaseReceivePart = new EntityBaseReceivePart() {
/**
* {@inheritDoc}
*/
@Override
protected ClassType getClassType() {
return EntityBaseSendReceivePart.this.getClassType();
}
/**
* {@inheritDoc}
*/
@Override
protected boolean isNotBaseClass(ClassType
currentClassType) {
return
EntityBaseSendReceivePart.this.isNotBaseClass(currentClassType);
}
/**
* {@inheritDoc}
*/
@Override
protected Entity getCurrentEntity() {
return EntityBaseSendReceivePart.this;
}
};
}
/* --- Methods --- */
/**
* {@inheritDoc}
*/
@Override
public void encode(XmlNodeEncoder node) {
entityBaseSendPart.encode(node);
}
/**
* {@inheritDoc}
*/
@Override
public void decode(Node xmlNode) throws ConversionException {
entityBaseReceivePart.decode(xmlNode);
id = entityBaseReceivePart.getId();
name = entityBaseReceivePart.getName();
entityBaseSendPart.setId(id);
entityBaseSendPart.setName(name);
}
/**
* {@inheritDoc}
*/
@Override
public String getId() {
return id;
}
/**
* {@inheritDoc}
*/
@Override
public String getName() {
return name;
}
/**
* {@inheritDoc}
*/
@Override
public void setId(String id) {
this.id = id;
entityBaseSendPart.setId(id);
entityBaseReceivePart.setId(id);
}
/**
* {@inheritDoc}
*/
@Override
public void setName(String name) {
this.name = name;
entityBaseSendPart.setName(name);
entityBaseReceivePart.setName(name);
}
/**
* @param currentClassType
* @return
*/
private boolean isNotBaseClass(ClassType currentClassType) {
return !
currentClassType.getDeclaringClass().equals(EntityBaseSendReceivePart.class);
}
}
Parent class:
package com.npq.fm.client.entity;
import com.gwtent.client.reflection.ClassType;
import com.gwtent.client.reflection.Field;
import com.gwtent.client.reflection.Reflectable;
import com.gwtent.client.reflection.TypeOracle;
import java.util.Map;
/**
* Base class for entity base classes with automatic serialization/
deserialization.
*
* @author Victor Kovtun
* @version 5 Apr 2010
*/
@Reflectable(constructors = false, fields = true, methods = true,
fieldAnnotations = true, classAnnotations = true,
assignableClasses = true, relationTypes = false, superClasses
= true)
public class EntityBaseEx implements Entity, HasId, HasName {
/* --- Instance Fields --- */
/** Class type of instance of this class. */
private ClassType classType =
TypeOracle.Instance.getClassType(this.getClass());
/** ID of this entity. */
protected String id;
/** Name of this entity. */
protected String name;
/* --- Methods --- */
/**
* Returns the type of the current class.
* <p/>
* This method is overridden for correct behavior during
delegation.
*
* @return the type of the current class.
*/
protected ClassType getClassType() {
return classType;
}
/**
* {@inheritDoc}
*/
@Override
public String getId() {
return id;
}
/**
* Setter for the field {@link #id}.
*
* @param id the value to be set.
*/
public void setId(String id) {
this.id = id;
}
/**
* {@inheritDoc}
*/
@Override
public String getName() {
return name;
}
/**
* Setter for the field {@link #name}.
*
* @param name the value to be set.
*/
public void setName(String name) {
this.name = name;
}
/**
* Adds the fields inherited from the parent classes and marked
with {@link InheritedFieldMapping} annotation to the
* map for subsequent encoding.
*
* @param fieldNameToTagNameMap the map where the values to be
put.
* @param currentClassType represents the current class to be
processed.
*/
protected void addInheritedFieldsToMap(Map<String, Tag>
fieldNameToTagNameMap, ClassType currentClassType) {
InheritedFieldMapping inheritedFieldMappingAnnotation =
currentClassType.getAnnotation(InheritedFieldMapping
.class);
if (inheritedFieldMappingAnnotation != null) {
String[] fieldNames =
inheritedFieldMappingAnnotation.fieldNames();
String[] tagNames =
inheritedFieldMappingAnnotation.tagNames();
boolean[] shortDates =
inheritedFieldMappingAnnotation.shortDates();
if (fieldNames.length != tagNames.length ||
fieldNames.length != shortDates.length) {
throw new EntityConversionException(
"Number of field names and tag names should be
equal in annotation.");
}
for (int i = 0; i < fieldNames.length; i++) {
String fieldName = fieldNames[i];
if (!fieldNameToTagNameMap.containsKey(fieldName)) {
fieldNameToTagNameMap.put(fieldName, new
Tag(tagNames[i], shortDates[i]));
}
}
}
}
/**
* Adds the fields of this very class to the map for subsequemt
processing.
*
* @param fieldNameToTagNameMap the map where the values to be
put.
* @param currentClassType represents the current class to be
processed.
*/
protected void addNativeFieldsToMap(Map<String, Tag>
fieldNameToTagNameMap, ClassType currentClassType) {
for (Field field : currentClassType.getFields()) {
Mappable mappableAnnotation =
field.getAnnotation(Mappable.class);
if (mappableAnnotation != null) {
String tagName = mappableAnnotation.value();
boolean shortDate = mappableAnnotation.shortDate();
String fieldName = field.getName();
if (!fieldNameToTagNameMap.containsKey(fieldName)) {
fieldNameToTagNameMap.put(fieldName, new
Tag(tagName, shortDate));
}
}
}
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object o) {
if (id == null) {
return super.equals(o);
}
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
return id.equals(((EntityBaseEx) o).id);
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return id != null ? id.hashCode() : super.hashCode();
}
/* --- Entities --- */
/**
* Value object which represents tag.
*
* @author Victor Kovtun
* @version 5 Apr 2010
*/
protected class Tag {
/* --- Instance Fields --- */
/** Name of the tag. */
private String name;
/** Whether this tag should be encoded in short date format.
*/
private boolean shortDate;
/* --- Constructors --- */
/**
* Creates instance of this class.
*
* @param name the value to be set to the field {@link #name}.
* @param shortDate the value to be set to the field {@link
#shortDate}.
*/
protected Tag(String name, boolean shortDate) {
this.name = name;
this.shortDate = shortDate;
}
/* --- Methods --- */
/**
* Getter for the field {@link #name}.
*
* @return the value of the field.
*/
protected String getName() {
return name;
}
/**
* Getter for the field {@link #shortDate}.
*
* @return the value of the field.
*/
protected boolean isShortDate() {
return shortDate;
}
}
}
Important classes used in EntityBaseSendReceivePart:
package com.npq.fm.client.entity;
import com.gwtent.client.reflection.ClassType;
import com.gwtent.client.reflection.Field;
import com.npq.fm.client.model.remote.net.obj.NetworkObjectSendPart;
import com.npq.fm.client.util.Price;
import com.npq.fm.client.util.XmlNodeEncoder;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* Base class for all entities for request sending with ability so
serialize automatically.
*
* @author Victor Kovtun
* @version 4 Apr 2010
*/
public class EntityBaseSendPart extends EntityBaseEx implements
NetworkObjectSendPart {
/* --- Methods --- */
/**
* {@inheritDoc}
*/
@Override
public void encode(XmlNodeEncoder node) {
Map<String, Tag> fieldNameToTagNameMap = new
LinkedHashMap<String, Tag>();
ClassType currentClassType = getClassType();
/* Going from current class to super all the time until we
reach this class - EntityBaseSendPart. */
while (currentClassType != null &&
isNotBaseClass(currentClassType)) {
addInheritedFieldsToMap(fieldNameToTagNameMap,
currentClassType);
addNativeFieldsToMap(fieldNameToTagNameMap,
currentClassType);
currentClassType = currentClassType.getSuperclass();
}
encodeFields(node, fieldNameToTagNameMap);
}
/**
* Encodes the fields from the specified map.
*
* @param node the node to be used for encoding.
* @param fieldNameToTagNameMap the map from field name to tag
name to be used in encoding.
*/
private void encodeFields(XmlNodeEncoder node, Map<String, Tag>
fieldNameToTagNameMap) {
for (String fieldName : fieldNameToTagNameMap.keySet()) {
Field field = getClassType().getField(fieldName);
if (field == null) {
throw new EntityConversionException("The specified
field not found. [fieldName=" + fieldName
+ ", getClassType().getName()=" +
getClassType().getName() + "]");
}
Object fieldValue =
field.getFieldValue(getCurrentEntity());
Tag tag = fieldNameToTagNameMap.get(fieldName);
encodeField(node, field, tag.getName(), fieldValue,
tag.isShortDate());
}
}
/**
* Returns the current entity.
* <p/>
* This method is overridden for the case when this class plays a
role of delegate.
*
* @return the instance of current entity.
*/
protected Entity getCurrentEntity() {
return this;
}
/**
* Encodes the specified field.
*
* @param node the node to be used for encoding.
* @param field the name of the field to be encoded.
* @param tagName the name of the tag to be used for encoding.
* @param fieldValue the value of the field to be set.
* @param shortDate defines if the date should have short format.
*/
private void encodeField(XmlNodeEncoder node, Field field, String
tagName, Object fieldValue, boolean shortDate) {
if (fieldValue == null) {
node.addTag(tagName, (String) null);
} else if (fieldValue instanceof String) {
node.addTag(tagName, (String) fieldValue);
} else if (fieldValue instanceof Date) {
if (!shortDate) {
node.addTag(tagName, (Date) fieldValue);
} else {
node.addShortDateTag(tagName, (Date) fieldValue);
}
} else if (fieldValue instanceof Integer) {
node.addTag(tagName, (Integer) fieldValue);
} else if (fieldValue instanceof Double) {
node.addTag(tagName, (Double) fieldValue);
} else if (fieldValue instanceof Iterable) {
node.addTag(tagName, (Iterable) fieldValue);
} else if (fieldValue instanceof Price) {
node.addTag(tagName, (Price) fieldValue);
} else if (fieldValue instanceof Boolean) {
node.addTag(tagName, (Boolean) fieldValue);
} else {
String fieldTypeName = field.getTypeName();
throw new EntityConversionException("The type of the field
is not supported. [fieldTypeName"
+ fieldTypeName + "]");
}
}
/**
* Determines whether the specified class type is not base.
*
* @param currentClassType the current class type to be checked.
* @return <code>true</code> if the specified class type is not
base.
*/
protected boolean isNotBaseClass(ClassType currentClassType) {
return !
currentClassType.getDeclaringClass().equals(EntityBaseSendPart.class);
}
}
And:
package com.npq.fm.client.entity;
import com.google.gwt.xml.client.Node;
import com.gwtent.client.reflection.ClassType;
import com.gwtent.client.reflection.Field;
import com.gwtent.client.reflection.Method;
import com.gwtent.client.reflection.Type;
import com.npq.fm.client.model.remote.net.obj.NetworkObjectReceive;
import
com.npq.fm.client.model.remote.net.obj.NetworkObjectReceivePart;
import com.npq.fm.client.util.ConversionException;
import com.npq.fm.client.util.XmlUtils;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* Base class for all entities for request receiving with ability so
serialize automatically.
*
* @author Victor Kovtun
* @version 5 Apr 2010
*/
public class EntityBaseReceivePart extends EntityBaseEx implements
NetworkObjectReceivePart {
/* --- Methods --- */
/**
* {@inheritDoc}
*/
@Override
public void decode(Node xmlNode) throws ConversionException {
Map<String, Tag> fieldNameToTagNameMap = new
LinkedHashMap<String, Tag>();
ClassType currentClassType = getClassType();
/* Going from current class to super all the time until we
reach this class - EntityBaseReceivePart. */
while (isNotBaseClass(currentClassType)) {
addInheritedFieldsToMap(fieldNameToTagNameMap,
currentClassType);
addNativeFieldsToMap(fieldNameToTagNameMap,
currentClassType);
currentClassType = currentClassType.getSuperclass();
}
decodeFields(xmlNode, fieldNameToTagNameMap);
}
/**
* Encodes the fields from the specified map.
*
* @param xmlNode the node to be used for encoding.
* @param fieldNameToTagNameMap the map from field name to tag
name to be used in encoding.
*/
private void decodeFields(Node xmlNode, Map<String, Tag>
fieldNameToTagNameMap) {
for (String fieldName : fieldNameToTagNameMap.keySet()) {
Field field = getClassType().getField(fieldName);
if (field == null) {
throw new EntityConversionException("The specified
field not found. [fieldName=" + fieldName + "]");
}
Tag tag = fieldNameToTagNameMap.get(fieldName);
String tagName = tag.getName();
String fieldTypeName =
field.getType().getQualifiedSourceName();
Object readValue = null;
try {
if (fieldTypeName.equals("java.lang.String")) {
readValue =
XmlUtils.getChildNodeValueAsString(xmlNode, tagName);
} else if (fieldTypeName.equals("java.util.Date")) {
readValue =
XmlUtils.getChildNodeValueAsDate(xmlNode, tagName);
} else if (fieldTypeName.equals("java.lang.Integer"))
{
readValue =
XmlUtils.getChildNodeValueAsInteger(xmlNode, tagName);
} else if (fieldTypeName.equals("java.lang.Double")) {
readValue =
XmlUtils.getChildNodeValueAsDouble(xmlNode, tagName);
} else if (fieldTypeName.equals("java.lang.List")) {
Mappable mappableAnnotation =
field.getAnnotation(Mappable.class);
final Method factoryMethod =
getClassType().getMethod(mappableAnnotation.factoryMethodName(),
null);
readValue =
XmlUtils.getChildNodeValueAsList(xmlNode, tagName,
new
AbstractNetworkObjectReceiveFactory<NetworkObjectReceive>() {
/**
* {@inheritDoc}
*/
@Override
public NetworkObjectReceive create() {
return (NetworkObjectReceive)
factoryMethod.invoke(getCurrentEntity());
}
});
} else if
(fieldTypeName.equals("com.npq.fm.client.util.Price")) {
readValue =
XmlUtils.getChildNodeValueAsPrice(xmlNode, tagName);
} else if (fieldTypeName.equals("java.lang.Boolean"))
{
readValue =
XmlUtils.getChildNodeValueAsBoolean(xmlNode, tagName);
} else {
throw new EntityConversionException("The type of
the field is not supported. [fieldTypeName"
+ fieldTypeName + "]");
}
} catch (ConversionException e) {
throw new EntityConversionException("Can't convert
node. [tagName=" + tagName + "]");
}
/*
* Invoking setter directly instead of using construction
field.setFieldValue(getCurrentEntity(),
* readValue) to be able to set null values.
*/
getClassType().getMethod(getSetterName(fieldName), new
Type[] {field.getType()}).invoke(getCurrentEntity(),
readValue);
}
}
/**
* Returns the name of the setter for the specified field name.
*
* @param fieldName the name of the field.
* @return the name of the setter for the specified field.
*/
private String getSetterName(String fieldName) {
return "set" + fieldName.substring(0, 1).toUpperCase() +
fieldName.substring(1);
}
/**
* Returns the current entity.
* <p/>
* This method is overridden for the case when this class plays a
role of delegate.
*
* @return the instance of current entity.
*/
protected Entity getCurrentEntity() {
return this;
}
/**
* Determines whether the specified class type is not base.
*
* @param currentClassType the current class type to be checked.
* @return <code>true</code> if the specified class type is not
base.
*/
protected boolean isNotBaseClass(ClassType currentClassType) {
return !
currentClassType.getDeclaringClass().equals(EntityBaseReceivePart.class);
}
}
We haven't managed to determine where the problem exactly is, but it
appeared definitely after we attached and started to use GWT Ent
library.
On MSDN help there is an article about this warning in IE:
http://support.microsoft.com/kb/175500 . It happens when some
statement is executed 5,000,000 (by default) times in a row (with no
call to other statement).
Do you have any ideas what can be wrong with it? We'll appreciate any
help.
Regards,
Victor.
--
You received this message because you are subscribed to the Google Groups "GWT-Ent Developer Forum" group.
To post to this group, send email to
gwt...@googlegroups.com.
To unsubscribe from this group, send email to
gwt-ent+u...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/gwt-ent?hl=en.