From: Chad B. <cwb...@us...> - 2008-04-26 17:36:10
|
User: cwbrandon Date: 08/04/26 10:36:15 Modified: andromda-jsf2/src/main/java/org/andromda/cartridges/jsf2/metafacades JSFUseCaseLogicImpl.java JSFParameterLogicImpl.java Log: improve message resolution for attributes/association ends Revision Changes Path 1.9 +66 -35 cartridges/andromda-jsf2/src/main/java/org/andromda/cartridges/jsf2/metafacades/JSFUseCaseLogicImpl.java Index: JSFUseCaseLogicImpl.java =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-jsf2/src/main/java/org/andromda/cartridges/jsf2/metafacades/JSFUseCaseLogicImpl.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -w -r1.8 -r1.9 --- JSFUseCaseLogicImpl.java 7 Apr 2008 15:38:34 -0000 1.8 +++ JSFUseCaseLogicImpl.java 26 Apr 2008 17:36:15 -0000 1.9 @@ -162,41 +162,9 @@ { final JSFParameter parameter = (JSFParameter)object; - final Collection attributes = parameter.getAttributes(); - if (!attributes.isEmpty()) - { - for (final Iterator iterator = attributes.iterator(); iterator.hasNext();) - { - final JSFAttribute attribute = (JSFAttribute)iterator.next(); - messages.put( - attribute.getMessageKey(), - attribute.getMessageValue()); - } - } - final Collection associationEnds = parameter.getNavigableAssociationEnds(); - if (!associationEnds.isEmpty()) - { - for (final Iterator iterator = associationEnds.iterator(); iterator.hasNext();) - { - final AssociationEndFacade end = (AssociationEndFacade)iterator.next(); - final ClassifierFacade type = end.getType(); - if (type != null) - { - final Collection typeAttributes = type.getAttributes(); - if (!attributes.isEmpty()) - { - for (final Iterator attributeIterator = typeAttributes.iterator(); - attributeIterator.hasNext();) - { - final JSFAttribute attribute = (JSFAttribute)attributeIterator.next(); - messages.put( - attribute.getMessageKey(), - attribute.getMessageValue()); - } - } - } - } - } + final Collection<ClassifierFacade> resolvingTypes = new ArrayList<ClassifierFacade>(); + this.collectAttributeMessages(messages, parameter.getAttributes(), resolvingTypes); + this.collectAssociationEndMessages(messages, parameter.getNavigableAssociationEnds(), resolvingTypes); messages.put( parameter.getMessageKey(), parameter.getMessageValue()); @@ -440,6 +408,69 @@ } /** + * Collects all attribute messages into the given Map. + * + * @param messages the Map in which messags are collected. + * @param attributes the attributes to collect the messages from. + * @param resolvingTypes used to prevent endless recursion. + */ + private void collectAttributeMessages(Map<String,String> messages, Collection attributes, + final Collection<ClassifierFacade> resolvingTypes) + { + if (attributes != null && !attributes.isEmpty()) + { + for (final Iterator iterator = attributes.iterator(); iterator.hasNext();) + { + final JSFAttribute attribute = (JSFAttribute)iterator.next(); + messages.put( + attribute.getMessageKey(), + attribute.getMessageValue()); + // - lets go another level for nested attributes + this.collectTypeMessages(messages, attribute.getType(), resolvingTypes); + } + } + } + + /** + * Collects all association end messages into the given Map. + * + * @param messages the Map in which messags are collected. + * @param associationEnds the association ends to collect the messages from. + * @param resolvingTypes used to prevent endless recursion. + */ + private void collectAssociationEndMessages(Map<String,String> messages, Collection associationEnds, + final Collection<ClassifierFacade> resolvingTypes) + { + if (associationEnds != null && !associationEnds.isEmpty()) + { + for (final Iterator iterator = associationEnds.iterator(); iterator.hasNext();) + { + final AssociationEndFacade end = (AssociationEndFacade)iterator.next(); + this.collectTypeMessages(messages, end.getType(), resolvingTypes); + } + } + } + + private void collectTypeMessages(Map<String,String> messages, ClassifierFacade type, + final Collection<ClassifierFacade> resolvingTypes) + { + if (type != null) + { + if (!resolvingTypes.contains(type)) + { + resolvingTypes.add(type); + if (type.isArrayType()) + { + type = type.getNonArray(); + } + this.collectAttributeMessages(messages, type.getAttributes(), resolvingTypes); + this.collectAssociationEndMessages(messages, type.getNavigableConnectingEnds(), resolvingTypes); + } + resolvingTypes.remove(type); + } + } + + /** * @see org.andromda.cartridges.jsf2.metafacades.JSFUseCase#getActionForwards() */ protected List handleGetActionForwards() 1.4 +18 -4 cartridges/andromda-jsf2/src/main/java/org/andromda/cartridges/jsf2/metafacades/JSFParameterLogicImpl.java Index: JSFParameterLogicImpl.java =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-jsf2/src/main/java/org/andromda/cartridges/jsf2/metafacades/JSFParameterLogicImpl.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -w -r1.3 -r1.4 --- JSFParameterLogicImpl.java 27 Mar 2008 18:34:52 -0000 1.3 +++ JSFParameterLogicImpl.java 26 Apr 2008 17:36:15 -0000 1.4 @@ -896,11 +896,18 @@ protected Collection handleGetAttributes() { Collection attributes = null; - final ClassifierFacade type = this.getType(); + ClassifierFacade type = this.getType(); + if (type != null) + { + if (type.isArrayType()) + { + type = type.getNonArray(); + } if (type != null) { attributes = type.getAttributes(true); } + } return attributes == null ? Collections.EMPTY_LIST : attributes; } @@ -910,11 +917,18 @@ protected Collection handleGetNavigableAssociationEnds() { Collection associationEnds = null; - final ClassifierFacade type = this.getType(); + ClassifierFacade type = this.getType(); + if (type != null) + { + if (type.isArrayType()) + { + type = type.getNonArray(); + } if (type != null) { associationEnds = type.getNavigableConnectingEnds(); } + } return associationEnds == null ? Collections.EMPTY_LIST : associationEnds; } |