  | Mailing List | | Home | | Forum Home | | JBoss - Java Application Server | | Tomcat - JSP/Servlet container | | Struts - A MVC web framework | | iText - An open source PDF Java Library | | JDOM - JDOM XML Parser | | J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition | | JSP - A mailing list about Java Server Pages specification and reference | | J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog | | Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology | |
Struts & Hibernate
|
|
|
  | | | - 2.0.0BETA1 jboss-seam-ui.jar doesn 't match source | - 2.0.0BETA1 jboss-seam-ui.jar doesn 't match source 2007-08-10 - By wiberto
Back I was debugging some code and the debugger couldn't match the line, when I checked the source for EntityConverter I saw that the source and what's in the jar is not the same. This is from the jar which I decompiled:
| public class EntityConverter | implements Converter, Serializable | { | | private org.jboss.seam.core.Expressions.ValueExpression entityManager; | private EntityConverterStore entityIdentifierStore; | | public EntityConverter() | { | } | | public void create() | { | entityIdentifierStore = EntityConverterStore.instance(); | } | | private void init() | { | if(getEntityManager() != null) | { | entityIdentifierStore.setEntityManager(getEntityManager()); | } | } | | public String getAsString(FacesContext facesContext, UIComponent cmp, Object value) | throws ConverterException | { | init(); | if(value == null) | { | return null; | } | if(value instanceof String) | { | return (String)value; | } else | { | return entityIdentifierStore.put(value).toString(); | } | } | | public Object getAsObject(FacesContext facesContext, UIComponent cmp, String value) | throws ConverterException | { | init(); | if(value == null) | { | return null; | } else | { | return entityIdentifierStore.get(new Integer(value)); | } | } | | public void setEntityManager(org.jboss.seam.core.Expressions .ValueExpression entityManager) | { | this.entityManager = entityManager; | } | | private EntityManager getEntityManager() | { | return entityManager != null ? (EntityManager)entityManager .getValue() : null; | } | } |
And from the src folder of 2.0.0:
| package org.jboss.seam.ui.converter; | | import static org.jboss.seam.ScopeType.CONVERSATION; | import static org.jboss.seam.annotations.Install.BUILT_IN; | | import java.io.Serializable; | | import javax.faces.component.UIComponent; | import javax.faces.context.FacesContext; | import javax.faces.convert.ConverterException; | import javax.persistence.EntityManager; | | import org.jboss.seam.annotations.Create; | import org.jboss.seam.annotations.Install; | import org.jboss.seam.annotations.Name; | import org.jboss.seam.annotations.Role; | import org.jboss.seam.annotations.Scope; | import org.jboss.seam.annotations.Transactional; | import org.jboss.seam.annotations.intercept.BypassInterceptors; | import org.jboss.seam.annotations.faces.Converter; | import org.jboss.seam.core.Expressions.ValueExpression; | | /** | * Allows conversion of an entity to/from a key which can be written to a page. | * | * Any annotated Entity will work, or any entity if a PersistenceProvider for your ORM exists | */ | @(protected)("org.jboss.seam.ui.entityConverter") | @(protected)(name="org.jboss.seam.ui.EntityConverter") | @(protected)(CONVERSATION) | @(protected)(precedence = BUILT_IN) | @(protected) | @(protected) | public class EntityConverter implements | javax.faces.convert.Converter, Serializable | { | | private ValueExpression<EntityManager> entityManager; | private EntityConverterStore entityIdentifierStore; | | @(protected) | public void create() | { | entityIdentifierStore = EntityConverterStore.instance(); | | } | | private void init() | { | if (getEntityManager() != null) | { | entityIdentifierStore.setEntityManager(getEntityManager()); | } | } | | @(protected)("unchecked") | @(protected) | public String getAsString(FacesContext facesContext, UIComponent cmp, Object value) throws ConverterException | { | init(); | if (value == null) | { | return null; | } | if (value instanceof String) | { | return (String) value; | } | return entityIdentifierStore.put(value).toString(); | } | | | @(protected) | public Object getAsObject(FacesContext facesContext, UIComponent cmp, String value) throws ConverterException | { | init(); | if (value == null) | { | return null; | } | return entityIdentifierStore.get(new Integer(value)); | } | | public void setEntityManager(ValueExpression<EntityManager> entityManager) | { | this.entityManager = entityManager; | } | | private EntityManager getEntityManager() | { | return entityManager == null ? | null : entityManager.getValue(); | } | } |
I checked the 1.2.1GA source and it's not the same, so it's not an old class :)
| package org.jboss.seam.ui; | | import static javax.faces.application.FacesMessage.SEVERITY_ERROR; | import static org.jboss.seam.annotations.Install.BUILT_IN; | import static org.jboss.seam.InterceptionType.NEVER; | | import java.io.Serializable; | import java.lang.reflect.Field; | import java.lang.reflect.Method; | import java.util.List; | | import javax.faces.component.UIComponent; | import javax.faces.context.FacesContext; | import javax.faces.convert.ConverterException; | import javax.persistence.Entity; | import javax.persistence.EntityManager; | import javax.persistence.Id; | | import org.jboss.seam.Component; | import org.jboss.seam.ScopeType; | import org.jboss.seam.annotations.Install; | import org.jboss.seam.annotations.Intercept; | import org.jboss.seam.annotations.Name; | import org.jboss.seam.annotations.Scope; | import org.jboss.seam.annotations.Transactional; | import org.jboss.seam.annotations.jsf.Converter; | import org.jboss.seam.core.FacesMessages; | import org.jboss.seam.core.Expressions.ValueBinding; | import org.jboss.seam.log.Log; | import org.jboss.seam.log.Logging; | import org.jboss.seam.util.Reflections; | | /** | * This implementation of the EntityConverter is suitable for any Entity which | * uses annotations | * | * | */ | @(protected)("org.jboss.seam.ui.entityConverter") | @(protected)(ScopeType.CONVERSATION) | @(protected)(precedence = BUILT_IN) | @(protected) | @(protected)(NEVER) | public class EntityConverter implements | javax.faces.convert.Converter, Serializable | { | | private ValueBinding<EntityManager> entityManager; | | private Log log = Logging.getLog(EntityConverter.class); | | private String errorMessage = "Error selecting object"; | | public void setEntityManager(ValueBinding<EntityManager> entityManager) | { | this.entityManager = entityManager; | } | | private EntityManager getEntityManager() { | if (entityManager==null) | { | return (EntityManager) Component.getInstance( "entityManager" ); | } | else | { | return entityManager.getValue(); | } | } | | protected void errorGettingIdMessage(UIComponent cmp, FacesContext facesContext, Object entity) | { | log.error("@(protected) annotation not on #0", entity.getClass()); | throw new ConverterException(FacesMessages.createFacesMessage (SEVERITY_ERROR, getErrorMessageKey(), getErrorMessage())); | } | | protected String getErrorMessage() | { | return errorMessage; | } | | protected String getErrorMessageKey() | { | return getEntityConverterKeyPrefix() + "idNotFound"; | } | | protected void invalidSelectionMessage(Class clazz, Object id) | { | log.error("Cannot load entity (#0 with id #1) from persistence context", clazz.getName(), id); | throw new ConverterException(FacesMessages.createFacesMessage (SEVERITY_ERROR, getErrorMessageKey(), getErrorMessage())); | } | | protected void entityManagerNotFoundMessage() | { | log.error("Entity Manager not found"); | throw new ConverterException(FacesMessages.createFacesMessage (SEVERITY_ERROR, getErrorMessageKey(), getErrorMessage())); | } | | protected String getEntityConverterKeyPrefix() | { | return "org.jboss.seam.ui.entityConverter."; | } | | /** | * @(protected) entity | * The entity to use | * @(protected) cmp | * The UIComponent this converter is attached to | * @(protected) facesContext | * The current facesContext | * @(protected) The ID of the entity as a string or null if unable to determine it | */ | protected Object getIdFromEntity(UIComponent cmp, FacesContext facesContext, | Object entity, Class entityClass) | { | Object id = null; | List<Field> fields = Reflections.getFields(entityClass, Id.class); | if (fields.size() == 1) | { | Field field = fields.get(0); | boolean accessible = field.isAccessible(); | field.setAccessible(true); | | try { | id = Reflections.get(field, entity); | } | catch (Exception e) | { | errorGettingIdMessage(cmp, facesContext, entity); | } | finally | { | field.setAccessible(accessible); | } | } | else | { | List<Method> methods = Reflections.getGetterMethods(entityClass, Id.class); | if (methods.size() == 1) | { | try | { | id = Reflections.invoke(methods.get(0), entity, new Object[0 ]); | } | catch (Exception e) | { | errorGettingIdMessage(cmp, facesContext, entity); | } | } | } | if (id == null) | { | return NoSelectionConverter.NO_SELECTION_VALUE; | } | else | { | return id; | } | } | | @(protected)("unchecked") | @(protected) | public String getAsString(FacesContext facesContext, UIComponent cmp, Object value) throws ConverterException | { | | if (value == null) | { | return null; | } | if (value instanceof String) | { | return (String) value; | } | Class entityClass = deproxy(value.getClass()); | return EntityConverterStore.instance().put(entityClass, getIdFromEntity(cmp, facesContext, value, entityClass)).toString(); | } | | // Hibernate Lazy proxies don't copy annotations to proxied methods - why? | private Class deproxy(Class clazz) | { | if (Object.class.equals(clazz) || clazz.isAnnotationPresent(Entity .class)) | { | return clazz; | } | else | { | return deproxy(clazz.getSuperclass()); | } | } | | @(protected) | public Object getAsObject(FacesContext facesContext, UIComponent cmp, String value) throws ConverterException | { | if (value == null) | { | return null; | } | Integer key = new Integer(value); | Class clazz = EntityConverterStore.instance().getClass(key); | Object id = EntityConverterStore.instance().getId(key); | return loadEntityFromPersistenceContext(clazz, id); | } | | /** | * Retrieve the Entity from the PersistenceContext | * | * @(protected) clazz | * The class of the entity to load | * @(protected) id | * The id of the entity to load | * @(protected) The entity, null if not found | */ | @(protected)("unchecked") | protected Object loadEntityFromPersistenceContext(Class clazz, Object id) | { | if (id == null || clazz == null) | { | return null; | } | Object entity = null; | if (getEntityManager() == null) | { | entityManagerNotFoundMessage(); | } | entity = getEntityManager().find(clazz, id); | if (entity == null) | { | invalidSelectionMessage(clazz, id); | return null; | } | else | { | return entity; | } | } | } |
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic &p=4072830#4072830
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode =reply&p=4072830 __ ____ ____ ____ ____ ____ ____ ____ ____ ____ jboss-user mailing list jboss-user@(protected) https://lists.jboss.org/mailman/listinfo/jboss-user
|
|
 |