Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/java/org/trails/hibernate/HibernateDescriptorDecorator.java =================================================================== --- C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/java/org/trails/hibernate/HibernateDescriptorDecorator.java (revision 490) +++ C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/java/org/trails/hibernate/HibernateDescriptorDecorator.java (working copy) @@ -51,62 +51,57 @@ import org.trails.descriptor.IPropertyDescriptor; import org.trails.descriptor.IdentifierDescriptor; import org.trails.descriptor.ObjectReferenceDescriptor; +import org.trails.descriptor.OwningObjectReferenceDescriptor; import org.trails.descriptor.TrailsPropertyDescriptor; - /** - * This decorator will add metadata information. It will replace simple reflection based - * TrailsPropertyIPropertyDescriptors with appropriate Hibernate descriptors - * + * This decorator will add metadata information. It will replace simple + * reflection based TrailsPropertyIPropertyDescriptors with appropriate + * Hibernate descriptors + * * @see TrailsPropertyDescriptor * @see ObjectReferenceDescriptor + * @see OwningObjectReferenceDescriptor * @see CollectionDescriptor * @see EmbeddedDescriptor */ -public class HibernateDescriptorDecorator implements DescriptorDecorator -{ - protected static final Log LOG = LogFactory.getLog(HibernateDescriptorDecorator.class); - +public class HibernateDescriptorDecorator implements DescriptorDecorator { + protected static final Log LOG = LogFactory + .getLog(HibernateDescriptorDecorator.class); + private LocalSessionFactoryBean localSessionFactoryBean; private List types; - private DescriptorFactory descriptorFactory; - private HashMap descriptors = new HashMap(); - private int largeColumnLength = 100; - public IClassDescriptor decorate(IClassDescriptor descriptor) - { + public IClassDescriptor decorate(IClassDescriptor descriptor) { ArrayList decoratedPropertyDescriptors = new ArrayList(); - for (IPropertyDescriptor propertyDescriptor : descriptor.getPropertyDescriptors()) - { + for (IPropertyDescriptor propertyDescriptor : descriptor + .getPropertyDescriptors()) { Class type = descriptor.getType(); IPropertyDescriptor result; - try - { + try { ClassMetadata classMetaData = findMetadata(type); - if (propertyDescriptor.getName().equals(getIdentifierProperty(type))) - { + if (propertyDescriptor.getName().equals( + getIdentifierProperty(type))) { result = buildIdentifierDescriptor(type, propertyDescriptor); - } - else if (notAHibernateProperty(classMetaData, propertyDescriptor)) - { - // If this is not a hibernate property (i.e. marked Transient), it's certainly not searchable + } else if (notAHibernateProperty(classMetaData, + propertyDescriptor)) { + // If this is not a hibernate property (i.e. marked + // Transient), it's certainly not searchable // Are the any other properties like this? propertyDescriptor.setSearchable(false); result = propertyDescriptor; + } else { + Property mappingProperty = getMapping(type).getProperty( + propertyDescriptor.getName()); + result = decoratePropertyDescriptor(type, mappingProperty, + propertyDescriptor, descriptor); } - else - { - Property mappingProperty = getMapping(type).getProperty(propertyDescriptor.getName()); - result = decoratePropertyDescriptor(type, mappingProperty, propertyDescriptor, descriptor); - } - } - catch (HibernateException e) - { + } catch (HibernateException e) { throw new TrailsRuntimeException(e); } decoratedPropertyDescriptors.add(result); @@ -115,68 +110,113 @@ return descriptor; } - protected IPropertyDescriptor decoratePropertyDescriptor(Class type, Property mappingProperty, IPropertyDescriptor descriptor, IClassDescriptor parentClassDescriptor) - { - if (isFormula(mappingProperty)) - { + protected IPropertyDescriptor decoratePropertyDescriptor(Class type, + Property mappingProperty, IPropertyDescriptor descriptor, + IClassDescriptor parentClassDescriptor) { + if (isFormula(mappingProperty)) { descriptor.setReadOnly(true); return descriptor; } descriptor.setLength(findColumnLength(mappingProperty)); descriptor.setLarge(isLarge(mappingProperty)); - if (!mappingProperty.isOptional()) - { + if (!mappingProperty.isOptional()) { descriptor.setRequired(true); } - if (!mappingProperty.isInsertable() && !mappingProperty.isUpdateable()) - { + if (!mappingProperty.isInsertable() && !mappingProperty.isUpdateable()) { descriptor.setReadOnly(true); } IPropertyDescriptor result = descriptor; Type hibernateType = mappingProperty.getType(); - if (mappingProperty.getType() instanceof ComponentType) - { - EmbeddedDescriptor embeddedDescriptor = buildEmbeddedDescriptor(type, mappingProperty, descriptor, parentClassDescriptor); + if (mappingProperty.getType() instanceof ComponentType) { + EmbeddedDescriptor embeddedDescriptor = buildEmbeddedDescriptor( + type, mappingProperty, descriptor, parentClassDescriptor); result = embeddedDescriptor; + } else if (Collection.class.isAssignableFrom(descriptor + .getPropertyType())) { + result = buildCollectionDescriptor(type, descriptor, + parentClassDescriptor); + } else if (hibernateType.isAssociationType()) { + type = parentClassDescriptor.getType(); + try { + Field propertyField = type.getDeclaredField(descriptor + .getName()); + PropertyDescriptor beanPropDescriptor = (PropertyDescriptor) Ognl + .getValue("propertyDescriptors.{? name == '" + + descriptor.getName() + "'}[0]", Introspector + .getBeanInfo(type)); + Method readMethod = beanPropDescriptor.getReadMethod(); + String mappedBy = ""; + if (readMethod + .isAnnotationPresent(javax.persistence.OneToOne.class)) { + mappedBy = readMethod.getAnnotation( + javax.persistence.OneToOne.class).mappedBy(); + if ("".equals(mappedBy)) { + result = buildOwningObjectReferenceDescriptor(type, + descriptor, (AssociationType) hibernateType); + } else { + result = buildObjectReferenceDescriptor(type, + descriptor, (AssociationType) hibernateType); + ((ObjectReferenceDescriptor)result).setInverseProperty(mappedBy); + } + } else if (propertyField + .isAnnotationPresent(javax.persistence.OneToOne.class)) { + mappedBy = propertyField.getAnnotation( + javax.persistence.OneToOne.class).mappedBy(); + if ("".equals(mappedBy)) { + result = buildOwningObjectReferenceDescriptor(type, + descriptor, (AssociationType) hibernateType); + } else { + result = buildObjectReferenceDescriptor(type, + descriptor, (AssociationType) hibernateType); + ((ObjectReferenceDescriptor)result).setInverseProperty(mappedBy); + } + } else { + result = buildObjectReferenceDescriptor(type, + descriptor, (AssociationType) hibernateType); + } + } catch (SecurityException e) { + LOG.error(e.getMessage()); + } catch (NoSuchFieldException e) { + LOG.error(e.getMessage()); + } catch (OgnlException e) { + LOG.error(e.getMessage()); + } catch (IntrospectionException e) { + LOG.error(e.getMessage()); + } + } else if (hibernateType.getReturnedClass().isEnum()) { + descriptor.addExtension(EnumReferenceDescriptor.class.getName(), + new EnumReferenceDescriptor(hibernateType + .getReturnedClass())); } - else if (Collection.class.isAssignableFrom(descriptor.getPropertyType())) - { - result = buildCollectionDescriptor(type, descriptor, parentClassDescriptor); - } - else if (hibernateType.isAssociationType()) - { - result = buildReferenceDescriptor(type, descriptor, (AssociationType) hibernateType); - } - else if (hibernateType.getReturnedClass().isEnum()) - { - descriptor.addExtension(EnumReferenceDescriptor.class.getName(), new EnumReferenceDescriptor(hibernateType.getReturnedClass())); - } return result; } - private EmbeddedDescriptor buildEmbeddedDescriptor(Class type, Property mappingProperty, IPropertyDescriptor descriptor, IClassDescriptor parentClassDescriptor) - { + private EmbeddedDescriptor buildEmbeddedDescriptor(Class type, + Property mappingProperty, IPropertyDescriptor descriptor, + IClassDescriptor parentClassDescriptor) { Component componentMapping = (Component) mappingProperty.getValue(); - IClassDescriptor baseDescriptor = getDescriptorFactory().buildClassDescriptor(descriptor.getPropertyType()); + IClassDescriptor baseDescriptor = getDescriptorFactory() + .buildClassDescriptor(descriptor.getPropertyType()); // build from base descriptor - EmbeddedDescriptor embeddedDescriptor = new EmbeddedDescriptor(type, baseDescriptor); + EmbeddedDescriptor embeddedDescriptor = new EmbeddedDescriptor(type, + baseDescriptor); // and copy from property descriptor embeddedDescriptor.copyFrom(descriptor); ArrayList decoratedProperties = new ArrayList(); // go thru each property and decorate it with Hibernate info - for (IPropertyDescriptor propertyDescriptor : embeddedDescriptor.getPropertyDescriptors()) - { - if (notAHibernateProperty(componentMapping, propertyDescriptor)) - { + for (IPropertyDescriptor propertyDescriptor : embeddedDescriptor + .getPropertyDescriptors()) { + if (notAHibernateProperty(componentMapping, propertyDescriptor)) { decoratedProperties.add(propertyDescriptor); - } - else - { - Property property = componentMapping.getProperty(propertyDescriptor.getName()); - IPropertyDescriptor iPropertyDescriptor = decoratePropertyDescriptor(embeddedDescriptor.getBeanType(), property, propertyDescriptor, parentClassDescriptor); + } else { + Property property = componentMapping + .getProperty(propertyDescriptor.getName()); + IPropertyDescriptor iPropertyDescriptor = decoratePropertyDescriptor( + embeddedDescriptor.getBeanType(), property, + propertyDescriptor, parentClassDescriptor); decoratedProperties.add(iPropertyDescriptor); } } @@ -185,63 +225,57 @@ } /** - * The default way to order our property descriptors is by the order they appear in the hibernate config, with id - * first. Any non-mapped properties are tacked on at the end, til I think of a better way. + * The default way to order our property descriptors is by the order they + * appear in the hibernate config, with id first. Any non-mapped properties + * are tacked on at the end, til I think of a better way. * * @param propertyDescriptors * @return */ - protected List sortPropertyDescriptors(Class type, List propertyDescriptors) - { + protected List sortPropertyDescriptors(Class type, List propertyDescriptors) { ArrayList sortedPropertyDescriptors = new ArrayList(); - try - { - sortedPropertyDescriptors.add(Ognl.getValue("#this.{? identifier == true}[0]", propertyDescriptors)); + try { + sortedPropertyDescriptors.add(Ognl.getValue( + "#this.{? identifier == true}[0]", propertyDescriptors)); for (Iterator iter = getMapping(type).getPropertyIterator(); iter - .hasNext();) - { + .hasNext();) { Property mapping = (Property) iter.next(); - sortedPropertyDescriptors.addAll((List) Ognl.getValue("#this.{ ? name == \"" + mapping.getName() + "\"}", propertyDescriptors)); + sortedPropertyDescriptors.addAll((List) Ognl.getValue( + "#this.{ ? name == \"" + mapping.getName() + "\"}", + propertyDescriptors)); } - } - catch (Exception ex) - { + } catch (Exception ex) { throw new TrailsRuntimeException(ex); } return sortedPropertyDescriptors; } /** - * Find the Hibernate metadata for this type, traversing up the hierarchy to supertypes if necessary + * Find the Hibernate metadata for this type, traversing up the hierarchy to + * supertypes if necessary * * @param type * @return */ - protected ClassMetadata findMetadata(Class type) throws MetadataNotFoundException - { + protected ClassMetadata findMetadata(Class type) + throws MetadataNotFoundException { ClassMetadata metaData = getSessionFactory().getClassMetadata(type); - if (metaData != null) - { + if (metaData != null) { return metaData; } - if (!type.equals(Object.class)) - { + if (!type.equals(Object.class)) { return findMetadata(type.getSuperclass()); - } - else - { + } else { throw new MetadataNotFoundException("Failed to find metadata."); } } - private boolean isFormula(Property mappingProperty) - { - for (Iterator iter = mappingProperty.getColumnIterator(); iter.hasNext();) - { + private boolean isFormula(Property mappingProperty) { + for (Iterator iter = mappingProperty.getColumnIterator(); iter + .hasNext();) { Selectable selectable = (Selectable) iter.next(); - if (selectable.isFormula()) - { + if (selectable.isFormula()) { return true; } } @@ -255,31 +289,29 @@ * @param propertyDescriptor * @return true if the propertyDescriptor property is in componentMapping */ - protected boolean notAHibernateProperty(Component componentMapping, IPropertyDescriptor propertyDescriptor) - { - for (Iterator iter = componentMapping.getPropertyIterator(); iter.hasNext();) - { + protected boolean notAHibernateProperty(Component componentMapping, + IPropertyDescriptor propertyDescriptor) { + for (Iterator iter = componentMapping.getPropertyIterator(); iter + .hasNext();) { Property property = (Property) iter.next(); - if (property.getName().equals(propertyDescriptor.getName())) - { + if (property.getName().equals(propertyDescriptor.getName())) { return false; } } return true; } - private boolean isLarge(Property mappingProperty) - { + private boolean isLarge(Property mappingProperty) { // Hack to avoid setting large property if length // is exactly equal to Hibernate default column length - return findColumnLength(mappingProperty) != Column.DEFAULT_LENGTH && findColumnLength(mappingProperty) > getLargeColumnLength(); + return findColumnLength(mappingProperty) != Column.DEFAULT_LENGTH + && findColumnLength(mappingProperty) > getLargeColumnLength(); } - private int findColumnLength(Property mappingProperty) - { + private int findColumnLength(Property mappingProperty) { int length = 0; - for (Iterator iter = mappingProperty.getColumnIterator(); iter.hasNext();) - { + for (Iterator iter = mappingProperty.getColumnIterator(); iter + .hasNext();) { Column column = (Column) iter.next(); length += column.getLength(); } @@ -291,14 +323,12 @@ * @param type * @return */ - protected boolean notAHibernateProperty(ClassMetadata classMetaData, IPropertyDescriptor descriptor) - { - try - { - return (Boolean) Ognl.getValue("propertyNames.{ ? #this == \"" + descriptor.getName() + "\"}.size() == 0", classMetaData); - } - catch (OgnlException oe) - { + protected boolean notAHibernateProperty(ClassMetadata classMetaData, + IPropertyDescriptor descriptor) { + try { + return (Boolean) Ognl.getValue("propertyNames.{ ? #this == \"" + + descriptor.getName() + "\"}.size() == 0", classMetaData); + } catch (OgnlException oe) { throw new TrailsRuntimeException(oe); } } @@ -309,24 +339,42 @@ * @param parentClassDescriptor * @return */ - private IPropertyDescriptor buildReferenceDescriptor(Class beanType, IPropertyDescriptor descriptor, AssociationType type) - { - return new ObjectReferenceDescriptor(beanType, descriptor, type.getReturnedClass()); + private IPropertyDescriptor buildObjectReferenceDescriptor(Class beanType, + IPropertyDescriptor descriptor, AssociationType type) { + ObjectReferenceDescriptor newInstance = new ObjectReferenceDescriptor(beanType, descriptor, type + .getReturnedClass()); + newInstance.setOneToOne(true); + return newInstance; } /** + * @param descriptor * @param type + * @param parentClassDescriptor + * @return + */ + private IPropertyDescriptor buildOwningObjectReferenceDescriptor( + Class beanType, IPropertyDescriptor descriptor, AssociationType type) { + OwningObjectReferenceDescriptor newInstance = new OwningObjectReferenceDescriptor(beanType, descriptor, type + .getReturnedClass()); + newInstance.setOneToOne(true); + return newInstance; + } + + /** + * @param type * @param descriptor * @param parentClassDescriptor * @return */ - private IdentifierDescriptor buildIdentifierDescriptor(Class type, IPropertyDescriptor descriptor) - { - IdentifierDescriptor identifierDescriptor = new IdentifierDescriptor(type, descriptor); + private IdentifierDescriptor buildIdentifierDescriptor(Class type, + IPropertyDescriptor descriptor) { + IdentifierDescriptor identifierDescriptor = new IdentifierDescriptor( + type, descriptor); PersistentClass mapping = getMapping(type); - if (((SimpleValue) mapping.getIdentifier()).getIdentifierGeneratorStrategy().equals("assigned")) - { + if (((SimpleValue) mapping.getIdentifier()) + .getIdentifierGeneratorStrategy().equals("assigned")) { identifierDescriptor.setGenerated(false); } @@ -337,8 +385,7 @@ * @param type * @return */ - protected PersistentClass getMapping(Class type) - { + protected PersistentClass getMapping(Class type) { Configuration cfg = getLocalSessionFactoryBean().getConfiguration(); return cfg.getClassMapping(type.getName()); @@ -348,99 +395,108 @@ * @param type * @param newDescriptor */ - private CollectionDescriptor buildCollectionDescriptor(Class type, IPropertyDescriptor descriptor, IClassDescriptor parentClassDescriptor) - { - try - { - CollectionDescriptor collectionDescriptor = new CollectionDescriptor(type, descriptor); - org.hibernate.mapping.Collection collectionMapping = findCollectionMapping(type, descriptor.getName()); - // It is a child relationship if it has delete-orphan specified in the mapping - collectionDescriptor.setChildRelationship(collectionMapping.hasOrphanDelete()); + private CollectionDescriptor buildCollectionDescriptor(Class type, + IPropertyDescriptor descriptor, + IClassDescriptor parentClassDescriptor) { + try { + CollectionDescriptor collectionDescriptor = new CollectionDescriptor( + type, descriptor); + org.hibernate.mapping.Collection collectionMapping = findCollectionMapping( + type, descriptor.getName()); + // It is a child relationship if it has delete-orphan specified in + // the mapping + collectionDescriptor.setChildRelationship(collectionMapping + .hasOrphanDelete()); CollectionMetadata collectionMetaData = getSessionFactory() .getCollectionMetadata(collectionMapping.getRole()); - collectionDescriptor.setElementType(collectionMetaData.getElementType() - .getReturnedClass()); + collectionDescriptor.setElementType(collectionMetaData + .getElementType().getReturnedClass()); collectionDescriptor.setOneToMany(collectionMapping.isOneToMany()); - - decorateOneToManyCollection(parentClassDescriptor, collectionDescriptor, collectionMapping); - + + decorateOneToManyCollection(parentClassDescriptor, + collectionDescriptor, collectionMapping); + return collectionDescriptor; - } - catch (HibernateException e) - { + } catch (HibernateException e) { throw new TrailsRuntimeException(e); } } /** - * I couldn't find a way to get the "mappedBy" value from the collection metadata, so I'm getting it from the OneToMany annotation. + * I couldn't find a way to get the "mappedBy" value from the collection + * metadata, so I'm getting it from the OneToMany annotation. */ - private void decorateOneToManyCollection(IClassDescriptor parentClassDescriptor , CollectionDescriptor collectionDescriptor, org.hibernate.mapping.Collection collectionMapping) { - Class type = parentClassDescriptor.getType(); - if (collectionDescriptor.isOneToMany() && collectionMapping.isInverse()) { - try { + private void decorateOneToManyCollection( + IClassDescriptor parentClassDescriptor, + CollectionDescriptor collectionDescriptor, + org.hibernate.mapping.Collection collectionMapping) { + Class type = parentClassDescriptor.getType(); + if (collectionDescriptor.isOneToMany() && collectionMapping.isInverse()) { + try { - Field propertyField = type.getDeclaredField(collectionDescriptor.getName()); - PropertyDescriptor beanPropDescriptor = (PropertyDescriptor)Ognl.getValue("propertyDescriptors.{? name == '" + collectionDescriptor.getName() + "'}[0]", Introspector.getBeanInfo(type)); - Method readMethod = beanPropDescriptor.getReadMethod(); - String mappedBy = ""; - if (readMethod.isAnnotationPresent(javax.persistence.OneToMany.class)) { - mappedBy = readMethod.getAnnotation(javax.persistence.OneToMany.class).mappedBy(); - } else if (propertyField.isAnnotationPresent(javax.persistence.OneToMany.class)) { - mappedBy = propertyField.getAnnotation(javax.persistence.OneToMany.class).mappedBy(); - } - - if (!"".equals(mappedBy)) { - collectionDescriptor.setInverseProperty(mappedBy); - } - - parentClassDescriptor.setHasCyclicRelationships(true); - - } catch (SecurityException e) { - LOG.error(e.getMessage()); - } catch (NoSuchFieldException e) { - LOG.error(e.getMessage()); - } catch (OgnlException e) { - LOG.error(e.getMessage()); - } catch (IntrospectionException e) { - LOG.error(e.getMessage()); - } - } - } + Field propertyField = type + .getDeclaredField(collectionDescriptor.getName()); + PropertyDescriptor beanPropDescriptor = (PropertyDescriptor) Ognl + .getValue("propertyDescriptors.{? name == '" + + collectionDescriptor.getName() + "'}[0]", + Introspector.getBeanInfo(type)); + Method readMethod = beanPropDescriptor.getReadMethod(); + String mappedBy = ""; + if (readMethod + .isAnnotationPresent(javax.persistence.OneToMany.class)) { + mappedBy = readMethod.getAnnotation( + javax.persistence.OneToMany.class).mappedBy(); + } else if (propertyField + .isAnnotationPresent(javax.persistence.OneToMany.class)) { + mappedBy = propertyField.getAnnotation( + javax.persistence.OneToMany.class).mappedBy(); + } - protected org.hibernate.mapping.Collection findCollectionMapping(Class type, String name) - { + if (!"".equals(mappedBy)) { + collectionDescriptor.setInverseProperty(mappedBy); + } + + parentClassDescriptor.setHasCyclicRelationships(true); + + } catch (SecurityException e) { + LOG.error(e.getMessage()); + } catch (NoSuchFieldException e) { + LOG.error(e.getMessage()); + } catch (OgnlException e) { + LOG.error(e.getMessage()); + } catch (IntrospectionException e) { + LOG.error(e.getMessage()); + } + } + } + + protected org.hibernate.mapping.Collection findCollectionMapping( + Class type, String name) { String roleName = type.getName() + "." + name; - org.hibernate.mapping.Collection collectionMapping = getLocalSessionFactoryBean().getConfiguration().getCollectionMapping(roleName); - if (collectionMapping != null) - { + org.hibernate.mapping.Collection collectionMapping = getLocalSessionFactoryBean() + .getConfiguration().getCollectionMapping(roleName); + if (collectionMapping != null) { return collectionMapping; - } - else if (!type.equals(Object.class)) - { + } else if (!type.equals(Object.class)) { return findCollectionMapping(type.getSuperclass(), name); - } - else - { + } else { throw new MetadataNotFoundException("Metadata not found."); } } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.trails.descriptor.PropertyDescriptorService#getIdentifierProperty(java.lang.Class) */ - public String getIdentifierProperty(Class type) - { - try - { + public String getIdentifierProperty(Class type) { + try { return getSessionFactory().getClassMetadata(type) .getIdentifierPropertyName(); - } - catch (HibernateException e) - { + } catch (HibernateException e) { throw new TrailsRuntimeException(e); } } @@ -448,54 +504,48 @@ /** * @return Returns the sessionFactory. */ - public SessionFactory getSessionFactory() - { + public SessionFactory getSessionFactory() { return (SessionFactory) getLocalSessionFactoryBean().getObject(); } - public IClassDescriptor getClassDescriptor(Class type) - { + public IClassDescriptor getClassDescriptor(Class type) { return descriptors.get(type); } /** * @return Returns the localSessionFactoryBean. */ - public LocalSessionFactoryBean getLocalSessionFactoryBean() - { + public LocalSessionFactoryBean getLocalSessionFactoryBean() { return localSessionFactoryBean; } /** - * @param localSessionFactoryBean The localSessionFactoryBean to set. + * @param localSessionFactoryBean + * The localSessionFactoryBean to set. */ - public void setLocalSessionFactoryBean(LocalSessionFactoryBean localSessionFactoryBean) - { + public void setLocalSessionFactoryBean( + LocalSessionFactoryBean localSessionFactoryBean) { this.localSessionFactoryBean = localSessionFactoryBean; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.trails.descriptor.TrailsDescriptorService#getAllDescriptors() */ - public List getAllDescriptors() - { + public List getAllDescriptors() { return new ArrayList(descriptors.values()); } - - public List getTypes() - { + public List getTypes() { return types; } - - public void setTypes(List types) - { + public void setTypes(List types) { this.types = types; } - public int getLargeColumnLength() - { + public int getLargeColumnLength() { return largeColumnLength; } @@ -504,18 +554,15 @@ * * @param largeColumnLength */ - public void setLargeColumnLength(int largeColumnLength) - { + public void setLargeColumnLength(int largeColumnLength) { this.largeColumnLength = largeColumnLength; } - public DescriptorFactory getDescriptorFactory() - { + public DescriptorFactory getDescriptorFactory() { return descriptorFactory; } - public void setDescriptorFactory(DescriptorFactory descriptorFactory) - { + public void setDescriptorFactory(DescriptorFactory descriptorFactory) { this.descriptorFactory = descriptorFactory; } Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/java/org/trails/hibernate/HibernatePersistenceService.java =================================================================== --- C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/java/org/trails/hibernate/HibernatePersistenceService.java (revision 490) +++ C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/java/org/trails/hibernate/HibernatePersistenceService.java (working copy) @@ -57,12 +57,12 @@ public class HibernatePersistenceService extends HibernateDaoSupport implements PersistenceService, ApplicationContextAware { - ApplicationContext appContext = null; - private DescriptorService _descriptorService = null; - - /** - * We need this because cylcic reference between HibernatePersistenceService and TrailsDescriptorService - */ + ApplicationContext appContext = null; + private DescriptorService _descriptorService = null; + + /** + * We need this because cylcic reference between HibernatePersistenceService and TrailsDescriptorService + */ public DescriptorService getDescriptorService() { if (_descriptorService == null) @@ -89,10 +89,10 @@ } }); } - + /* * (non-Javadoc) - * + * * @see org.blah.service.IPersistenceService#getAllInstances(java.lang.Class) */ @Transactional @@ -108,7 +108,7 @@ /* * (non-Javadoc) - * + * * @see org.blah.service.IPersistenceService#save(java.lang.Object) */ @Transactional @@ -116,7 +116,7 @@ { try { - if (!getDescriptorService().getClassDescriptor(instance.getClass()).getHasCyclicRelationships()) + if (! getDescriptorService().getClassDescriptor(instance.getClass()).getHasCyclicRelationships()) { getHibernateTemplate().saveOrUpdate(instance); } else @@ -140,7 +140,7 @@ /* * (non-Javadoc) - * + * * @see org.trails.persistence.PersistenceService#getInstances(org.trails.persistence.Query) */ @Transactional @@ -166,18 +166,18 @@ } - + /* * (non-Javadoc) - * + * * @see org.trails.persistence.PersistenceService#getInstance(final Class type) */ @Transactional public T getInstance( final Class type) { - return getInstance(DetachedCriteria.forClass(type) ); + return getInstance(DetachedCriteria.forClass(type) ); } - + @Transactional public T getInstance(final DetachedCriteria criteria) { @@ -189,7 +189,7 @@ }); return (T) result; } - + @Transactional public List getInstances( final Object example ) { @@ -235,6 +235,15 @@ searchCriteria.createCriteria( propertyName ) .add( Restrictions.idEq( identifierValue ) ); } + else if( propertyDescriptor.isOwningObjectReference() ) + { + //'one'-end of one-to-one -> just match the identifier + Object identifierValue = Ognl.getValue( descriptorService + .getClassDescriptor( value.getClass() ).getIdentifierDescriptor().getName(), + value ); + searchCriteria.createCriteria( propertyName ) + .add( Restrictions.idEq( identifierValue ) ); + } else if( propertyClass.isPrimitive() ) { //primitive types: ignore zeroes in case of numeric types, ignore booleans anyway (TODO come up with something...) Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/java/org/trails/hibernate/EmbeddedDescriptor.java =================================================================== --- C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/java/org/trails/hibernate/EmbeddedDescriptor.java (revision 490) +++ C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/java/org/trails/hibernate/EmbeddedDescriptor.java (working copy) @@ -7,13 +7,13 @@ public class EmbeddedDescriptor extends TrailsClassDescriptor implements IPropertyDescriptor { - - private int index; - - private boolean readOnly; - - private String name; + private int index; + + private boolean readOnly; + + private String name; + ///////////////////////////////////////////////////////////////////////////////////////////////////////// // constructors ///////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -37,101 +37,107 @@ ///////////////////////////////////////////////////////////////////////////////////////////////////////// // bean setters/getters - ///////////////////////////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////////////////////////// public boolean isNumeric() - { - // TODO Auto-generated method stub - return false; - } + { + // TODO Auto-generated method stub + return false; + } - public boolean isBoolean() - { - // TODO Auto-generated method stub - return false; - } + public boolean isBoolean() + { + // TODO Auto-generated method stub + return false; + } - public boolean isDate() - { - // TODO Auto-generated method stub - return false; - } + public boolean isDate() + { + // TODO Auto-generated method stub + return false; + } - public boolean isString() - { - // TODO Auto-generated method stub - return false; - } + public boolean isString() + { + // TODO Auto-generated method stub + return false; + } - public boolean isObjectReference() - { - // TODO Auto-generated method stub - return false; - } + public boolean isObjectReference() + { + // TODO Auto-generated method stub + return false; + } - private boolean required; - - private int length; - - private boolean large; - - private String format; - - private boolean searchable; - - private boolean summary; + public boolean isOwningObjectReference() + { + // TODO Auto-generated method stub + return false; + } - private boolean richText; - - private Class beanType; + private boolean required; - public boolean isEmbedded() - { - return true; - } + private int length; - public Class getPropertyType() - { - return getType(); - } + private boolean large; - public void setPropertyType(Class propertyType) - { - setType(propertyType); - } + private String format; - public int getIndex() - { - return index; - } + private boolean searchable; - public boolean isReadOnly() - { - return readOnly; - } + private boolean summary; - public void setReadOnly(boolean readOnly) - { - this.readOnly = readOnly; - } + private boolean richText; - public void setIndex(int index) - { - this.index = index; - } + private Class beanType; - public String getName() - { - return name; - } + public boolean isEmbedded() + { + return true; + } - public void setName(String name) - { - this.name = name; - } + public Class getPropertyType() + { + return getType(); + } - public boolean isCollection() { return false; } + public void setPropertyType(Class propertyType) + { + setType(propertyType); + } + public int getIndex() + { + return index; + } + public boolean isReadOnly() + { + return readOnly; + } + + public void setReadOnly(boolean readOnly) + { + this.readOnly = readOnly; + } + + public void setIndex(int index) + { + this.index = index; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public boolean isCollection() { return false; } + + public IClassDescriptor getParentClassDescriptor() { return null;//To change body of implemented methods use File | Settings | File Templates. @@ -143,103 +149,103 @@ } @Override - public Object clone() - { - return new EmbeddedDescriptor(getBeanType(), this); - } + public Object clone() + { + return new EmbeddedDescriptor(getBeanType(), this); + } - public String getFormat() - { - return format; - } + public String getFormat() + { + return format; + } - public void setFormat(String format) - { - this.format = format; - } + public void setFormat(String format) + { + this.format = format; + } - public boolean isLarge() - { - return large; - } + public boolean isLarge() + { + return large; + } - public void setLarge(boolean large) - { - this.large = large; - } + public void setLarge(boolean large) + { + this.large = large; + } - public int getLength() - { - return length; - } + public int getLength() + { + return length; + } - public void setLength(int length) - { - this.length = length; - } + public void setLength(int length) + { + this.length = length; + } - public boolean isSearchable() - { - return searchable; - } + public boolean isSearchable() + { + return searchable; + } - public void setSearchable(boolean searchable) - { - this.searchable = searchable; - } + public void setSearchable(boolean searchable) + { + this.searchable = searchable; + } - public boolean isSummary() - { - return summary; - } + public boolean isSummary() + { + return summary; + } - public void setSummary(boolean summary) - { - this.summary = summary; - } + public void setSummary(boolean summary) + { + this.summary = summary; + } - public Class getBeanType() - { - return beanType; - } + public Class getBeanType() + { + return beanType; + } - public void setBeanType(Class beanType) - { - this.beanType = beanType; - } + public void setBeanType(Class beanType) + { + this.beanType = beanType; + } public boolean isRichText() - { - return richText; - } + { + return richText; + } - public void setRichText(boolean richText) - { - this.richText = richText; - } + public void setRichText(boolean richText) + { + this.richText = richText; + } - public boolean isRequired() - { - return required; - } + public boolean isRequired() + { + return required; + } - public void setRequired(boolean required) - { - this.required = required; - } + public void setRequired(boolean required) + { + this.required = required; + } - @Override - public void copyFrom(IDescriptor descriptor) - { + @Override + public void copyFrom(IDescriptor descriptor) + { - super.copyFrom(descriptor); - } + super.copyFrom(descriptor); + } - public boolean isIdentifier() - { - return false; - } - - - + public boolean isIdentifier() + { + return false; + } + + + } Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/java/org/trails/component/AssociationSelect.java =================================================================== --- C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/java/org/trails/component/AssociationSelect.java (revision 490) +++ C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/java/org/trails/component/AssociationSelect.java (working copy) @@ -1,88 +1,154 @@ package org.trails.component; +import ognl.Ognl; +import ognl.OgnlException; + import org.apache.tapestry.BaseComponent; import org.apache.tapestry.IRequestCycle; import org.apache.tapestry.annotations.InjectObject; +import org.apache.tapestry.annotations.Parameter; +import org.apache.tapestry.annotations.Persist; import org.apache.tapestry.form.IPropertySelectionModel; import org.hibernate.criterion.DetachedCriteria; +import org.hibernate.criterion.Restrictions; import org.trails.descriptor.DescriptorService; import org.trails.descriptor.IClassDescriptor; import org.trails.descriptor.IPropertyDescriptor; +import org.trails.page.EditPage; +import org.trails.page.PageResolver; import org.trails.persistence.PersistenceService; /** - * * @author Chris Nelson - * - * This guy interacts with persistence service to produce a Select - * containing all the elements of the PropertyDescriptor's type. If - * a criteria is specified, it will filter the list by it. * + * This guy interacts with persistence service to produce a Select containing + * all the elements of the PropertyDescriptor's type. If a criteria is + * specified, it will filter the list by it. + * + * Additionally, a detached criteria is available to automatically filter out + * associations without owners, or get all owners by default. + * */ -public abstract class AssociationSelect extends BaseComponent -{ +public abstract class AssociationSelect extends BaseComponent { @InjectObject("spring:persistenceService") public abstract PersistenceService getPersistenceService(); - + @InjectObject("spring:descriptorService") public abstract DescriptorService getDescriptorService(); - + + @InjectObject("spring:pageResolver") + public abstract PageResolver getPageResolver(); + public abstract IPropertySelectionModel getPropertySelectionModel(); + public abstract void setPropertySelectionModel( + IPropertySelectionModel PropertySelectionModel); - public abstract void setPropertySelectionModel(IPropertySelectionModel PropertySelectionModel); - public abstract DetachedCriteria getCriteria(); + public abstract void setCriteria(DetachedCriteria Criteria); - public abstract void setCriteria(DetachedCriteria Criteria); - + @Parameter(required = true, cache = true) + public abstract Object getModel(); + public abstract void setModel(Object bytes); + + @Persist + public abstract Object getValue(); + public abstract void setValue(Object value); + + @Parameter(required = true, cache = true) public abstract IPropertyDescriptor getPropertyDescriptor(); + public abstract void setPropertyDescriptor(IPropertyDescriptor propertyDescriptor); - public abstract void setPropertyDescriptor(IPropertyDescriptor PropertyDescriptor); - + @Parameter(required = true, cache = true) + public abstract Object getOwner(); + public abstract void setOwner(Object owner); + + @Parameter(required = true, cache = true) + public abstract Object getAssociation(); + public abstract void setAssociation(Object association); + public abstract boolean isAllowNone(); + public abstract void setAllowNone(boolean allowNone); - public abstract void setAllowNone(boolean AllowNone); - - public abstract String getNoneLabel(); + public abstract String getNoneLabel(); + public abstract void setNoneLabel(String noneLabel); - public abstract void setNoneLabel(String NoneLabel); - - public AssociationSelect() - { + public String getOwnerTypeName() { + return getOwner().getClass().getName(); + } + + public Class getOwnerType() { + return getOwner().getClass(); + } + + public String getAssociationTypeName() { + return getPropertyDescriptor().getPropertyType().getCanonicalName(); + } + + public Class getAssociationType() { + return getPropertyDescriptor().getPropertyType().getClass(); + } + + public AssociationSelect() { super(); - // TODO Auto-generated constructor stub } - public IClassDescriptor getClassDescriptor() - { - return getDescriptorService().getClassDescriptor(getPropertyDescriptor().getPropertyType()); + public IClassDescriptor getClassDescriptor() { + return getDescriptorService().getClassDescriptor( + getPropertyDescriptor().getPropertyType()); } @Override - protected void prepareForRender(IRequestCycle arg0) - { - // Leaving this in causes the select to always use the same - // property selectio model. Not sure why yet :( -// if (getPropertySelectionModel() == null) -// { - buildSelectionModel(); -// } - super.prepareForRender(arg0); + protected void prepareForRender(IRequestCycle cycle) { + buildSelectionModel(); + + super.prepareForRender(cycle); } - public void buildSelectionModel() - { - DetachedCriteria criteria = getCriteria() != null ? - getCriteria() : - DetachedCriteria.forClass(getClassDescriptor().getType()); + protected void cleanupAfterRender(IRequestCycle cycle) { + super.cleanupAfterRender(cycle); + //ownerEditPage = (EditPage) cycle.getPage(); + } + + public void buildSelectionModel() { + DetachedCriteria criteria = getCriteria() != null ? getCriteria() + : getAllAssociations(); IdentifierSelectionModel selectionModel = new IdentifierSelectionModel( - getPersistenceService().getInstances(criteria), - getClassDescriptor().getIdentifierDescriptor().getName(), - isAllowNone()); + getPersistenceService().getInstances(criteria), + getClassDescriptor().getIdentifierDescriptor().getName(), + isAllowNone()); selectionModel.setNoneLabel(getNoneLabel()); setPropertySelectionModel(selectionModel); } - - + public DetachedCriteria getAssociationsWithoutOwners() { + DetachedCriteria criteria = DetachedCriteria.forClass(getClassDescriptor().getType()); + try { + //EditPage page = (EditPage) Ognl.getValue("page", getContainer().getPage()); + EditPage page = (EditPage) getPage().getRequestCycle().getPage(); + String ownerOgnlIdentifier = page.getClassDescriptor().getIdentifierDescriptor().getName(); + String associationOgnlIdentifier = getClassDescriptor().getIdentifierDescriptor().getName(); + String inverseOgnlProperty = getPropertyDescriptor().getName(); // league + + if (getOwner() != null) { + + criteria.add(Restrictions.disjunction().add( + Restrictions.isNull(inverseOgnlProperty)).add( + Restrictions.eq(inverseOgnlProperty + "." + + associationOgnlIdentifier, Ognl.getValue( + ownerOgnlIdentifier, getOwner())))); + + } else { + criteria.add(Restrictions.isNull(inverseOgnlProperty)); + } + } catch (OgnlException e) { + e.printStackTrace(); + } + return criteria; + } + + public DetachedCriteria getAllAssociations() { + DetachedCriteria criteria = DetachedCriteria + .forClass(getClassDescriptor().getType()); + return criteria; + } } Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/java/org/trails/component/AssociationMgt.java =================================================================== --- C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/java/org/trails/component/AssociationMgt.java (revision 0) +++ C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/java/org/trails/component/AssociationMgt.java (revision 0) @@ -0,0 +1,315 @@ +package org.trails.component; + +import java.util.Iterator; + +import ognl.Ognl; +import ognl.OgnlException; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.tapestry.IPage; +import org.apache.tapestry.IRequestCycle; +import org.apache.tapestry.annotations.Bean; +import org.apache.tapestry.annotations.ComponentClass; +import org.apache.tapestry.annotations.InjectObject; +import org.apache.tapestry.annotations.InjectState; +import org.apache.tapestry.annotations.Lifecycle; +import org.apache.tapestry.annotations.Parameter; +import org.apache.tapestry.callback.ICallback; +import org.apache.tapestry.components.Insert; +import org.hibernate.NonUniqueObjectException; +import org.trails.TrailsRuntimeException; +import org.trails.callback.AssociationCallback; +import org.trails.callback.CallbackStack; +import org.trails.callback.CollectionCallback; +import org.trails.callback.EditCallback; +import org.trails.callback.EditCollectionMemberCallback; +import org.trails.descriptor.BlockFinder; +import org.trails.descriptor.CollectionDescriptor; +import org.trails.descriptor.DescriptorService; +import org.trails.descriptor.IClassDescriptor; +import org.trails.descriptor.IDescriptor; +import org.trails.descriptor.IPropertyDescriptor; +import org.trails.descriptor.ObjectReferenceDescriptor; +import org.trails.descriptor.OwningObjectReferenceDescriptor; +import org.trails.page.EditPage; +import org.trails.page.PageResolver; +import org.trails.page.TrailsPage.PageType; +import org.trails.persistence.PersistenceException; +import org.trails.persistence.PersistenceService; +import org.trails.validation.TrailsValidationDelegate; + +/** + * @OneToOne use case. + * + * This guy manages the owning side user interface of a OneToOne association. + * + * Owner-<>-----Association + * + * @author kenneth.colassi nhhockeyplayer@hotmail.com + */ +@ComponentClass(allowBody = true, allowInformalParameters = true) +public abstract class AssociationMgt extends TrailsComponent { + protected static final Log LOG = LogFactory.getLog(AssociationMgt.class); + + @Bean(lifecycle = Lifecycle.REQUEST) + public abstract TrailsValidationDelegate getDelegate(); + + public abstract String getCreateExpression(); + public abstract void setCreateExpression(String CreateExpression); + + @Parameter(required = true, cache = true) + public abstract IPropertyDescriptor getDescriptor(); + public abstract void setDescriptor(IPropertyDescriptor descriptor); + + @Parameter(required = true, cache = true) + public abstract Object getOwner(); + public abstract void setOwner(Object owner); + + @Parameter(required = true, cache = true) + public abstract Object getAssociation(); + public abstract void setAssociation(Object association); + + @Parameter(required = true, cache = true) + public abstract Object getValue(); + public abstract void setValue(Object value); + + @Parameter(required = true, cache = true) + public abstract Object getModel(); + public abstract void setModel(Object bytes); + + @InjectState("callbackStack") + public abstract CallbackStack getCallbackStack(); + + @InjectObject("spring:pageResolver") + public abstract PageResolver getPageResolver(); + + @InjectObject("spring:persistenceService") + public abstract PersistenceService getPersistenceService(); + + @InjectObject("spring:editorService") + public abstract BlockFinder getBlockFinder(); + + @InjectObject("spring:descriptorService") + public abstract DescriptorService getDescriptorService(); + + public IClassDescriptor getClassDescriptor() { + return getDescriptorService().getClassDescriptor( + getDescriptor().getPropertyType()); + } + + public AssociationMgt() { + super(); + + // if (getValue() != null) + // this.setAssociation(getValue()); + } + + public String getOwnerTypeName() { + return getOwner().getClass().getName(); + } + + public Class getOwnerType() { + return getOwner().getClass(); + } + + public String getAssociationTypeName() { + return getDescriptor().getPropertyType().getCanonicalName(); + } + + public Class getAssociationType() { + return getDescriptor().getPropertyType().getClass(); + } + + /* + public IPage edit(Object member) + { + EditCallback callback = new EditCallback( + getPage().getRequestCycle().getPage().getPageName(), + getModel()); + getCallbackStack().push(callback); + EditPage editPage = (EditPage)getPageResolver().resolvePage( + getPage().getRequestCycle(), + Utils.checkForCGLIB(member.getClass()).getName(), + PageType.EDIT); + try + { + getPersistenceService().reattach(member); + } catch (NonUniqueObjectException e) + { + member = getPersistenceService().reload(member); + } + editPage.setModel(member); + return editPage; + } + */ + + AssociationCallback buildCallback() + { + AssociationCallback callback = new AssociationCallback( + getPage().getRequestCycle().getPage().getPageName(), getModel(), getObjectReferenceDescriptor()); + return callback; + } + + public void addNew(IRequestCycle cycle) { + getCallbackStack().push(buildCallback()); + + String currentEditPageName = getPage().getRequestCycle().getPage() + .getPageName(); + EditPage ownerEditPage = (EditPage) getPageResolver().resolvePage( + cycle, getDescriptor().getClass().getName(), PageType.EDIT); + + try { + boolean isNewModel = true; + + // Object newModel = createModel(); + Object newModel = buildNewMemberInstance(); + //AssociationCallback nextPage = new AssociationCallback( + // ownerEditPage.getPageName(), newModel, isNewModel, + // ownerEditPage); + EditCallback nextPage = new EditCallback( + ownerEditPage.getPageName(), newModel); + + /** + * This guy gets invoked implicitly on SUBMIT button method after + * this call ...EditPage.onFormSubmit(...) ... who tracks all + * submissions... and subsequently triggers + * EditCallback.performCallback(...) + * getNextPage().performCallback(cycle); + * + * sends us to association editor page + */ + //ownerEditPage.getCallbackStack().push(nextPage); + + ((EditPage) cycle.getPage(currentEditPageName)) + .setNextPage(nextPage); + } catch (Exception ex) { + throw new TrailsRuntimeException(ex); + } + } + + protected Object createModel() throws InstantiationException, + IllegalAccessException { + return getDescriptor().getPropertyType().newInstance(); + } + + protected Object buildNewMemberInstance() throws InstantiationException, + IllegalAccessException { + Object associationModel; + if (getCreateExpression() == null) { + associationModel = getDescriptor().getPropertyType().newInstance(); + } else { + try { + associationModel = Ognl.getValue(getCreateExpression(), + getOwner()); + } catch (OgnlException oe) { + oe.printStackTrace(); + return null; + } + } + + if (getObjectReferenceDescriptor().getInverseProperty() != null + && getObjectReferenceDescriptor().isOneToOne()) { + try { + Ognl.setValue(getObjectReferenceDescriptor() + .getInverseProperty(), associationModel, getOwner()); + } catch (OgnlException e) { + LOG.error(e.getMessage()); + } + } + + return associationModel; + } + + EditCallback buildOwnerCallback(IRequestCycle cycle) { + EditPage editPage = (EditPage) getPageResolver().resolvePage(cycle, + getDescriptor().getClass().getName(), PageType.EDIT); + + EditCallback callback = new EditCallback(getPage().getRequestCycle() + .getPage().getPageName(), editPage.getModel()); + return callback; + } + + EditCallback buildAssociationCallback(IRequestCycle cycle) { + EditPage editPage = (EditPage) getPageResolver().resolvePage(cycle, + getDescriptor().getClass().getName(), PageType.EDIT); + + EditCallback callback = new EditCallback(getPage().getRequestCycle() + .getPage().getPageName(), editPage.getModel()); + return callback; + } + + /* + * AssociationCallback buildOwnerCallback(IRequestCycle cycle) { boolean + * isNewModel = false; EditPage ownerEditPage = (EditPage) + * getPageResolver().resolvePage( cycle, + * getDescriptor().getClass().getName(), PageType.EDIT); AssociationCallback + * callback = new AssociationCallback(ownerEditPage .getPageName(), + * getOwner(), isNewModel, ownerEditPage); return callback; } + * + * AssociationCallback buildAssociationCallback(IRequestCycle cycle) { + * boolean newModel = true; String currentEditPageName = + * getPage().getRequestCycle().getPage() .getPageName(); AssociationCallback + * callback = new AssociationCallback( ((EditPage) + * cycle.getPage(currentEditPageName)).getPageName(), getAssociation(), + * newModel); return callback; } + */ + + public void remove(IRequestCycle cycle) { + EditPage editPage = (EditPage) getPageResolver().resolvePage(cycle, + getDescriptor().getClass().getName(), PageType.EDIT); + try { + getPersistenceService().remove(getAssociation()); + editPage.setModel(getPersistenceService().reload( + editPage.getModel())); + cycle.activate(editPage); + } catch (PersistenceException pe) { + getDelegate().record(pe); + return; + } + + ICallback callback = editPage.getCallbackStack().popPreviousCallback(); + callback.performCallback(cycle); + } + + public abstract EditLink getEditLink(); + + public abstract Insert getLinkInsert(); + + + public ObjectReferenceDescriptor getObjectReferenceDescriptor() { + for (Iterator iter = getDescriptorService().getClassDescriptor( + getDescriptor().getPropertyType()).getPropertyDescriptors() + .iterator(); iter.hasNext();) { + IDescriptor descriptor = (IDescriptor) iter.next(); + + if (descriptor instanceof ObjectReferenceDescriptor) { + ObjectReferenceDescriptor ord = (ObjectReferenceDescriptor) descriptor; + + OwningObjectReferenceDescriptor owd = (OwningObjectReferenceDescriptor) ord.getParentClassDescriptor().getPropertyDescriptors().get(getDescriptor().getIndex()); + + //TrailsClassDescriptor parentClassDescriptor = (TrailsClassDescriptor) ord + // .getParentClassDescriptor(); + owd.getParentClassDescriptor().getPropertyDescriptors().get(getDescriptor().getIndex()); + + // Iterate all descriptors in the object reference + // If the inverse property one matches the inverse property of an ord + // then you have a match + + // What is the likelihood that multiple properties of the association + // would match multiple properties within the owner? Is one possible? + if ( ord.getInverseProperty().equals(owd.getName())) { + return ord; + } + } + } + + return null; + } + /* + public ObjectReferenceDescriptor getObjectReferenceDescriptor() + { + return (ObjectReferenceDescriptor) getDescriptor(); + } + */ +} Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/java/org/trails/callback/AssociationCallback.java =================================================================== --- C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/java/org/trails/callback/AssociationCallback.java (revision 0) +++ C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/java/org/trails/callback/AssociationCallback.java (revision 0) @@ -0,0 +1,69 @@ +package org.trails.callback; + +import java.util.HashMap; + +import ognl.Ognl; +import ognl.OgnlException; + +import org.trails.TrailsRuntimeException; +import org.trails.descriptor.ObjectReferenceDescriptor; +import org.trails.persistence.PersistenceService; + +/** + * This guy is responsible for returning from an add or remove on a association. + */ +public class AssociationCallback extends EditCallback { + private ObjectReferenceDescriptor ord; + private boolean oneToOne; + + /** + * @param pageName + * @param model + */ + public AssociationCallback(String pageName, Object model, + ObjectReferenceDescriptor ord) { + super(pageName, model); + this.ord = ord; + this.setOneToOne(ord.isOneToOne()); + } + + public void save(PersistenceService persistenceService, Object newObject) { + executeOgnlExpression(ord.findAddExpression(), newObject); + persistenceService.save(getModel()); + } + + public void remove(PersistenceService persistenceService, Object object) { + executeOgnlExpression(ord.findRemoveExpression(), object); + persistenceService.save(getModel()); + } + + /** + * @param previousModel + */ + private void executeOgnlExpression(String ognlExpression, Object newObject) { + HashMap context = new HashMap(); + context.put("member", newObject); + + try { + Ognl.getValue(ognlExpression + "(#member)", context, model); + } catch (OgnlException e) { + throw new TrailsRuntimeException(e); + } + } + + public boolean isOneToOne() { + return oneToOne; + } + + public void setOneToOne(boolean oneToOne) { + this.oneToOne = oneToOne; + } + + public ObjectReferenceDescriptor getOrd() { + return ord; + } + + public void setOrd(ObjectReferenceDescriptor ord) { + this.ord = ord; + } +} Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/java/org/trails/page/ListPage.java =================================================================== --- C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/java/org/trails/page/ListPage.java (revision 490) +++ C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/java/org/trails/page/ListPage.java (working copy) @@ -26,25 +26,25 @@ /** * List all the instances of a type - * + * * @author Chris Nelson - * + * */ public abstract class ListPage extends TrailsPage implements IExternalPage, PageBeginRenderListener { - + @Override - public void pageBeginRender(PageEvent event) - { - super.pageBeginRender(event); -// if (!getRequestCycle().isRewinding()) -// { -// setInstances(getPersistenceService().getInstances(getCriteria())); -// } - } + public void pageBeginRender(PageEvent event) + { + super.pageBeginRender(event); +// if (!getRequestCycle().isRewinding()) +// { +// setInstances(getPersistenceService().getInstances(getCriteria())); +// } + } - /* (non-Javadoc) + /* (non-Javadoc) * @see org.apache.tapestry.IExternalPage#activateExternalPage(java.lang.Object[], org.apache.tapestry.IRequestCycle) */ public void activateExternalPage(Object[] args, IRequestCycle cycle) @@ -56,13 +56,13 @@ public abstract List getInstances(); - public abstract void setInstances(List Instances); - - @Persist + public abstract void setInstances(List Instances); + + @Persist public abstract DetachedCriteria getCriteria(); - public abstract void setCriteria(DetachedCriteria Criteria); - + public abstract void setCriteria(DetachedCriteria Criteria); + public abstract String getTypeName(); public abstract void setTypeName(String typeName); @@ -79,12 +79,10 @@ } } - /** - * - */ + @Override public void pushCallback() { - + getCallbackStack().push(new ListCallback(getPageName(), getTypeName(), getCriteria())); } } Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/java/org/trails/page/EditorBlockPage.java =================================================================== --- C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/java/org/trails/page/EditorBlockPage.java (revision 490) +++ C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/java/org/trails/page/EditorBlockPage.java (working copy) @@ -6,8 +6,8 @@ import org.trails.validation.ValidatorTranslatorService; /** - * - * This page contains all the default editor Blocks. This allows + * + * This page contains all the default editor Blocks. This allows * Trails to dynamically pick at runtime which editor to use for a * specific property. * @author Chris Nelson @@ -15,18 +15,17 @@ */ public abstract class EditorBlockPage extends ModelPage { - - + @Override public void pushCallback() { EditCallback callback = new EditCallback(getEditPageName(), getModel()); getCallbackStack().push(callback); } - + public abstract IPropertyDescriptor getDescriptor(); public abstract void setDescriptor(IPropertyDescriptor Descriptor); - + public abstract String getEditPageName(); public abstract void setEditPageName(String EditPageName); Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/java/org/trails/descriptor/TrailsPropertyDescriptor.java =================================================================== --- C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/java/org/trails/descriptor/TrailsPropertyDescriptor.java (revision 490) +++ C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/java/org/trails/descriptor/TrailsPropertyDescriptor.java (working copy) @@ -24,29 +24,29 @@ public class TrailsPropertyDescriptor extends TrailsDescriptor implements IPropertyDescriptor { private boolean searchable = true; - + private boolean required; - + private boolean readOnly; - + private String name; - + private int index = UNDEFINED_INDEX; - + private int length = DEFAULT_LENGTH; - + private boolean large; - + private String format; private boolean summary = true; - + private boolean richText; - + private Class beanType; private IClassDescriptor parentClassDescriptor; - + ///////////////////////////////////////////////////////////////////////////////////////////////////////// // constructors ///////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -63,7 +63,7 @@ public TrailsPropertyDescriptor(Class beanType, Class type) { super(type); - this.beanType = beanType; + this.beanType = beanType; } public TrailsPropertyDescriptor(Class beanType, String name, Class type) @@ -103,7 +103,7 @@ public boolean isBoolean() { return getPropertyType().getName().endsWith("boolean") || - getPropertyType().getName().endsWith("Boolean"); + getPropertyType().getName().endsWith("Boolean"); } /** * @return @@ -162,15 +162,23 @@ { return false; } - + /** + * @return + */ + public boolean isOwningObjectReference() + { + return false; + } + + /** * @return Returns the required. */ public boolean isRequired() { return required; } - + /** * @param required The required to set. */ @@ -186,7 +194,7 @@ { return readOnly; } - + /** * @param readOnly The readOnly to set. */ @@ -194,7 +202,7 @@ { this.readOnly = readOnly; } - + /** * @return */ @@ -295,17 +303,17 @@ this.richText = richText; } - public Class getBeanType() { - return beanType; - } + public Class getBeanType() { + return beanType; + } - public void setBeanType(Class beanType) { - this.beanType = beanType; - } + public void setBeanType(Class beanType) { + this.beanType = beanType; + } - public boolean isEmbedded() - { - return false; - } + public boolean isEmbedded() + { + return false; + } } Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/java/org/trails/descriptor/OwningObjectReferenceDescriptor.java =================================================================== --- C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/java/org/trails/descriptor/OwningObjectReferenceDescriptor.java (revision 0) +++ C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/java/org/trails/descriptor/OwningObjectReferenceDescriptor.java (revision 0) @@ -0,0 +1,139 @@ +package org.trails.descriptor; + +import org.apache.commons.beanutils.BeanUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.trails.component.AssociationMgt; +import org.trails.component.AssociationSelect; +import org.trails.hibernate.HibernateDescriptorDecorator; + +/** + * This class represents a one-to-one association and is created by + * HibernateDescriptorDecorator at bootstrap time + * + * @OneToOne use case. + * + * EXAMPLE: one-to-one association + * + * Organization-<>-----Director + * + * Organization is the owner. Director is the reference. Each requires a + * specialized trails property editor. Both of these objects are manipulated by + * dedicated descriptors respectively OwningObjectReferenceDescriptor and + * ObjectReferenceDescriptor which have a sole duty of governing which editor + * launches. + * + * In short this guy operates the owning side of the association for the + * framework and gets detected as owner iff OneToOne does NOT have the mappedBy + * attribute set + * + * @author kenneth.colassi nhhockeyplayer@hotmail.com + * + * @see HibernateDescriptorDecorator + * @see ObjectReferenceDescriptor + * @see AssociationSelect + * @see AssociationMgt + */ +public class OwningObjectReferenceDescriptor extends TrailsPropertyDescriptor + implements IPropertyDescriptor { + private static final Log log = LogFactory.getLog(OwningObjectReferenceDescriptor.class); + private Class actualType; + + private String inverseProperty = null; + + private boolean oneToOne = false; + + /** + * + * @param beanType + * @param descriptor + * @param actualType + */ + public OwningObjectReferenceDescriptor(Class beanType, + IPropertyDescriptor descriptor, Class actualType) { + this(beanType, descriptor.getPropertyType(), actualType); + copyFrom(descriptor); + } + + /** + * + * @param beanType + * @param declaredType + * @param actualType + */ + public OwningObjectReferenceDescriptor(Class beanType, Class declaredType, + Class actualType) { + super(beanType, declaredType); + this.actualType = actualType; + } + + /** + * + * @param beanType + * @param name + * @param type + */ + public OwningObjectReferenceDescriptor(Class beanType, String name, + Class type) { + super(beanType, name, type); + this.actualType = type; + } + + /** + * + * @param dto + */ + public OwningObjectReferenceDescriptor(OwningObjectReferenceDescriptor dto) { + super(dto.getBeanType(), dto.getName(), dto.getType()); + + try { + BeanUtils.copyProperties(this, dto); + } catch (Exception e) { + log.error(e.toString()); + e.printStackTrace(); + } + } + + /** + * @see org.trails.descriptor.PropertyDescriptor#getPropertyType() + */ + public Class getPropertyType() { + return actualType; + } + + /** + * @see org.trails.descriptor.PropertyDescriptor#isOwningObjectReference() + */ + @Override + public boolean isOwningObjectReference() { + return true; + } + + public Class getActualType() { + return actualType; + } + + public void setActualType(Class actualType) { + this.actualType = actualType; + } + + public String getInverseProperty() { + return inverseProperty; + } + + public void setInverseProperty(String inverseProperty) { + this.inverseProperty = inverseProperty; + } + + public boolean isOneToOne() { + return oneToOne; + } + + public void setOneToOne(boolean oneToOne) { + this.oneToOne = oneToOne; + } + + public Object clone() { + return new OwningObjectReferenceDescriptor(this); + } +} Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/java/org/trails/descriptor/ReflectionDescriptorFactory.java =================================================================== --- C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/java/org/trails/descriptor/ReflectionDescriptorFactory.java (revision 490) +++ C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/java/org/trails/descriptor/ReflectionDescriptorFactory.java (working copy) @@ -3,37 +3,38 @@ import java.beans.BeanInfo; import java.beans.Introspector; import java.beans.PropertyDescriptor; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; import org.apache.commons.beanutils.BeanUtils; /** - * Generate descriptors using reflection on the underlying class. ReflectionDescriptorFactory.buildClassDescriptor() - * is the only public method here. + * Generate descriptors using reflection on the underlying class. + * ReflectionDescriptorFactory.buildClassDescriptor() is the only public method + * here. */ -public class ReflectionDescriptorFactory implements DescriptorFactory -{ - private List propertyExcludes = new ArrayList(); - - private List methodExcludes = new ArrayList(); +public class ReflectionDescriptorFactory implements DescriptorFactory { + private List propertyExcludes = new ArrayList(); + private List methodExcludes = new ArrayList(); + /** * Given a type, build a property descriptor - * @param type The type to build for + * + * @param type + * The type to build for * @return a completed property descriptor */ - public IClassDescriptor buildClassDescriptor(Class type) - { - try - { + public IClassDescriptor buildClassDescriptor(Class type) { + try { IClassDescriptor descriptor = new TrailsClassDescriptor(type); BeanInfo beanInfo = Introspector.getBeanInfo(type); BeanUtils.copyProperties(descriptor, beanInfo.getBeanDescriptor()); - descriptor.setPropertyDescriptors(buildPropertyDescriptors(type, beanInfo, descriptor)); + descriptor.setPropertyDescriptors(buildPropertyDescriptors(type, + beanInfo, descriptor)); return descriptor; - } catch (Exception ex) - { + } catch (Exception ex) { ex.printStackTrace(); } return null; @@ -41,29 +42,57 @@ /** * Build the set of property descriptors for this type - * @param type the aggregating class - * @param beanInfo the BeanInfo, already gathered - * @param parentClassDescriptor reference to the aggregating class, used for recovery with graph traversal - * @return ObjectReferenceDescriptor if this property is an association, otherwise a TrailsPropertyDescriptor + * + * @param type + * the aggregating class + * @param beanInfo + * the BeanInfo, already gathered + * @param parentClassDescriptor + * reference to the aggregating class, used for recovery with + * graph traversal + * @return ObjectReferenceDescriptor if this property is an association, + * otherwise a TrailsPropertyDescriptor * @throws Exception */ - protected ArrayList buildPropertyDescriptors(Class type, BeanInfo beanInfo, IClassDescriptor parentClassDescriptor) throws Exception - { + protected ArrayList buildPropertyDescriptors( + Class type, BeanInfo beanInfo, + IClassDescriptor parentClassDescriptor) throws Exception { ArrayList result = new ArrayList(); - for (PropertyDescriptor beanPropDescriptor : beanInfo.getPropertyDescriptors()) - { - if (!isExcluded(beanPropDescriptor.getName(), getPropertyExcludes())) - { + for (PropertyDescriptor beanPropDescriptor : beanInfo + .getPropertyDescriptors()) { + if (!isExcluded(beanPropDescriptor.getName(), getPropertyExcludes())) { TrailsPropertyDescriptor propDescriptor; Class propertyType = beanPropDescriptor.getPropertyType(); - if (propertyType.isEnum() || propertyType.isPrimitive() || propertyType.isArray() || propertyType.getPackage().getName().startsWith("java")) - { - propDescriptor = new TrailsPropertyDescriptor(type, beanPropDescriptor.getPropertyType()); - } - else - { - propDescriptor = new ObjectReferenceDescriptor(type, beanPropDescriptor.getPropertyType(), beanPropDescriptor.getPropertyType()); + if (propertyType.isEnum() + || propertyType.isPrimitive() + || propertyType.isArray() + || propertyType.getPackage().getName().startsWith( + "java")) { + propDescriptor = new TrailsPropertyDescriptor(type, + beanPropDescriptor.getPropertyType()); + } else { + String mappedBy = ""; + type = parentClassDescriptor.getType(); + Method readMethod = beanPropDescriptor.getReadMethod(); + if (readMethod + .isAnnotationPresent(javax.persistence.OneToOne.class)) { + mappedBy = readMethod.getAnnotation( + javax.persistence.OneToOne.class).mappedBy(); + if ("".equals(mappedBy)) { + propDescriptor = new OwningObjectReferenceDescriptor( + type, beanPropDescriptor.getPropertyType(), + beanPropDescriptor.getPropertyType()); + } else { + propDescriptor = new ObjectReferenceDescriptor( + type, beanPropDescriptor.getPropertyType(), + beanPropDescriptor.getPropertyType()); + } + } else { + propDescriptor = new ObjectReferenceDescriptor(type, + beanPropDescriptor.getPropertyType(), + beanPropDescriptor.getPropertyType()); + } } BeanUtils.copyProperties(propDescriptor, beanPropDescriptor); TrailsPropertyDescriptor newPropertyDescriptor = propDescriptor; @@ -73,14 +102,11 @@ return result; } - protected boolean isExcluded(String name, List excludes) - { - for (Object exclude1 : excludes) - { + protected boolean isExcluded(String name, List excludes) { + for (Object exclude1 : excludes) { String exclude = (String) exclude1; - if (name.matches(exclude)) - { + if (name.matches(exclude)) { return true; } } @@ -88,23 +114,19 @@ return false; } - public List getMethodExcludes() - { - return methodExcludes; - } + public List getMethodExcludes() { + return methodExcludes; + } - public void setMethodExcludes(List methodExcludes) - { - this.methodExcludes = methodExcludes; - } + public void setMethodExcludes(List methodExcludes) { + this.methodExcludes = methodExcludes; + } - public List getPropertyExcludes() - { - return propertyExcludes; - } + public List getPropertyExcludes() { + return propertyExcludes; + } - public void setPropertyExcludes(List propertyExcludes) - { - this.propertyExcludes = propertyExcludes; - } + public void setPropertyExcludes(List propertyExcludes) { + this.propertyExcludes = propertyExcludes; + } } Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/java/org/trails/descriptor/ObjectReferenceDescriptor.java =================================================================== --- C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/java/org/trails/descriptor/ObjectReferenceDescriptor.java (revision 490) +++ C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/java/org/trails/descriptor/ObjectReferenceDescriptor.java (working copy) @@ -11,55 +11,145 @@ */ package org.trails.descriptor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import org.apache.commons.beanutils.BeanUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.trails.TrailsRuntimeException; +import org.trails.component.Utils; import org.trails.hibernate.HibernateDescriptorDecorator; - /** * @author Chris Nelson * - * This class represents a to-one association and is created by HibernateDescriptorDecorator - * + * This class represents a to-one association and is created by + * HibernateDescriptorDecorator + * * @see HibernateDescriptorDecorator */ -public class ObjectReferenceDescriptor extends TrailsPropertyDescriptor -{ +public class ObjectReferenceDescriptor extends TrailsPropertyDescriptor { + protected static final Log LOG = LogFactory.getLog(ObjectReferenceDescriptor.class); + private Class actualType; + private String inverseProperty = null; + private boolean oneToOne = false; - public ObjectReferenceDescriptor(Class beanType, IPropertyDescriptor descriptor, - Class actualType) - { + public ObjectReferenceDescriptor(Class beanType, + IPropertyDescriptor descriptor, Class actualType) { this(beanType, descriptor.getPropertyType(), actualType); copyFrom(descriptor); } - + /** * @param realDescriptor */ - public ObjectReferenceDescriptor( - Class beanType, Class declaredType, Class actualType) - { + public ObjectReferenceDescriptor(Class beanType, Class declaredType, + Class actualType) { super(beanType, declaredType); this.actualType = actualType; } - /* (non-Javadoc) + /** + * + * @param beanType + * @param name + * @param type + */ + public ObjectReferenceDescriptor(Class beanType, String name, Class type) { + super(beanType, name, type); + this.actualType = type; + } + + /* + * (non-Javadoc) + * * @see org.trails.descriptor.PropertyDescriptor#getPropertyType() */ - public Class getPropertyType() - { + public Class getPropertyType() { return actualType; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.trails.descriptor.PropertyDescriptor#isObjectReference() */ - public boolean isObjectReference() - { + public boolean isObjectReference() { return true; } - public Object clone() - { - return new ObjectReferenceDescriptor(getBeanType(), this, getPropertyType()); + public Class getActualType() { + return actualType; } + + public void setActualType(Class actualType) { + this.actualType = actualType; + } + + public String getInverseProperty() { + return inverseProperty; + } + + public void setInverseProperty(String inverseProperty) { + this.inverseProperty = inverseProperty; + } + + public boolean isOneToOne() { + return oneToOne; + } + + public void setOneToOne(boolean oneToOne) { + this.oneToOne = oneToOne; + } + + public Object clone() { + return new ObjectReferenceDescriptor(getBeanType(), this, + getPropertyType()); + } + + public String findAddExpression() { + return findExpression("add"); + } + + public String findRemoveExpression() { + return findExpression("remove"); + } + + /** + * @param method + * the method to look for, usually add or remove + * @return the ogln expression to use to add or remove a member to the + * association. Will look for a addName method where Name is the + * unqualified element class name, if there isn't one it will use + * the association's add method. + */ + String findExpression(String method) { + Method addMethod = null; + + try { + addMethod = getBeanType().getMethod( + method + Utils.unqualify(getPropertyType().getName()), + new Class[] { getPropertyType() }); + } catch (NoSuchMethodException ex) { + // if we don't have one... + return getName() + "." + method; + } catch (Exception e) { + throw new TrailsRuntimeException(e); + } + + return addMethod.getName(); + } + + private void copyFrom(ObjectReferenceDescriptor ord) { + LOG.debug("Clonning ObjectReferenceDescriptor"); + try { + BeanUtils.copyProperties(this, ord); + } catch (IllegalAccessException e) { + LOG.error(e.getMessage()); + } catch (InvocationTargetException e) { + LOG.error(e.getMessage()); + } + } } Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/java/org/trails/descriptor/IPropertyDescriptor.java =================================================================== --- C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/java/org/trails/descriptor/IPropertyDescriptor.java (revision 490) +++ C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/java/org/trails/descriptor/IPropertyDescriptor.java (working copy) @@ -2,13 +2,13 @@ * Created on Mar 18, 2005 * * Copyright 2004 Chris Nelson - * - * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and limitations under the License. */ package org.trails.descriptor; @@ -23,13 +23,13 @@ public interface IPropertyDescriptor extends IDescriptor { public static final int UNDEFINED_INDEX = -1; - + public static final int DEFAULT_LENGTH = 255; - + public void setIndex(int index); - + public int getIndex(); - + /** * @return */ @@ -58,6 +58,12 @@ public boolean isObjectReference(); /** + * @return + */ + public boolean isOwningObjectReference(); + + + /** * @return Returns the required. */ public boolean isRequired(); @@ -81,48 +87,48 @@ * @return */ public String getName(); - + public void setName(String name); /** * @return */ public String getShortDescription(); - + public void setShortDescription(String shortDescription); - + public int getLength(); - + public void setLength(int length); - + public abstract boolean isLarge(); public abstract void setLarge(boolean Large); - + public String getFormat(); - + public void setFormat(String format); public boolean isSearchable(); - + public void setSearchable(boolean searchable); public boolean isSummary(); - + public boolean isCollection(); public void setSummary(boolean summary); - + public boolean isEmbedded(); public boolean isRichText(); - + public boolean isIdentifier(); public void setRichText(boolean richText); - + public Class getBeanType(); - + public void setBeanType(Class beanType); /** Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/resources/org/trails/component/AssociationSelect.html =================================================================== --- C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/resources/org/trails/component/AssociationSelect.html (revision 490) +++ C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/resources/org/trails/component/AssociationSelect.html (working copy) @@ -1,6 +1,6 @@ - - - - + \ No newline at end of file Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/resources/org/trails/component/AssociationMgt.html =================================================================== --- C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/resources/org/trails/component/AssociationMgt.html (revision 0) +++ C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/resources/org/trails/component/AssociationMgt.html (revision 0) @@ -0,0 +1,24 @@ + + + + + + + + + + + +
+
+ +
+
+ +
+ + +
+ Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/resources/org/trails/component/AssociationSelect.jwc =================================================================== --- C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/resources/org/trails/component/AssociationSelect.jwc (revision 490) +++ C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/resources/org/trails/component/AssociationSelect.jwc (working copy) @@ -1,17 +1,20 @@ - produces a select list for an association property + produces a select list for an association property - - - + - + + + + + + - propertySelectionModel - value + + - + Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/resources/org/trails/component/trails.library =================================================================== --- C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/resources/org/trails/component/trails.library (revision 490) +++ C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/resources/org/trails/component/trails.library (working copy) @@ -24,13 +24,16 @@ - - --> + + + + Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/resources/org/trails/component/AssociationMgt.jwc =================================================================== --- C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/resources/org/trails/component/AssociationMgt.jwc (revision 0) +++ C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/resources/org/trails/component/AssociationMgt.jwc (revision 0) @@ -0,0 +1,35 @@ + + + + + + + + + "int" + + + + listener:addNew + true + page.isModelNew() + + + listener:remove + false + page.isModelNew() + + + + value + + + value + + + + Ognl expression to invoke on the model to create a new association instance + + Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/resources/org/trails/page/Editors.page =================================================================== --- C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/resources/org/trails/page/Editors.page (revision 490) +++ C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/resources/org/trails/page/Editors.page (working copy) @@ -1,73 +1,83 @@ - - - - - - - model[descriptor.name] - ognl:validatorTranslatorService.getTranslator(descriptor) - - - descriptor.displayName - ognl:validatorTranslatorService.getValidator(descriptor) - model[descriptor.name] - descriptor.length - - - descriptor.displayName - ognl:validatorTranslatorService.getValidator(descriptor) - model[descriptor.name] - descriptor.length - true - - - descriptor.displayName - model[descriptor.name] - - - descriptor.displayName - ognl:validatorTranslatorService.getTranslator(descriptor) - ognl:validatorTranslatorService.getValidator(descriptor) - model[descriptor.name] - - - model[descriptor.name] - - - model[descriptor.name] - descriptor - - - descriptor - - - - model[descriptor.name] - descriptor - - - - model[descriptor.name] - - - model[descriptor.name] - - - - model[descriptor.name] - descriptor - - - - model[descriptor.name] - descriptor - - - - - + + + + + + + model[descriptor.name] + ognl:validatorTranslatorService.getTranslator(descriptor) + + + descriptor.displayName + ognl:validatorTranslatorService.getValidator(descriptor) + model[descriptor.name] + descriptor.length + + + descriptor.displayName + ognl:validatorTranslatorService.getValidator(descriptor) + model[descriptor.name] + descriptor.length + true + + + descriptor.displayName + model[descriptor.name] + + + descriptor.displayName + ognl:validatorTranslatorService.getTranslator(descriptor) + ognl:validatorTranslatorService.getValidator(descriptor) + model[descriptor.name] + + + model[descriptor.name] + + + model[descriptor.name] + descriptor + + + descriptor + + + + model[descriptor.name] + + + model[descriptor.name] + + + + model[descriptor.name] + descriptor + + + + model[descriptor.name] + descriptor + + + + model + descriptor + + + + model + model[descriptor.name] + model + model[descriptor.name] + descriptor + + + + model + model[descriptor.name] + model + model[descriptor.name] + descriptor + + + + Index: C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/resources/org/trails/page/Editors.html =================================================================== --- C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/resources/org/trails/page/Editors.html (revision 490) +++ C:/Prototype/Mavenized/Product/trails/trunk/trails/trails-core/src/main/resources/org/trails/page/Editors.html (working copy) @@ -55,7 +55,8 @@
- + + @@ -89,7 +90,7 @@
- + + + + + +
+ +