001: package org.andromda.cartridges.hibernate.metafacades;
002:
003: import java.util.ArrayList;
004: import java.util.Collection;
005:
006: import org.andromda.cartridges.hibernate.HibernateProfile;
007: import org.andromda.cartridges.hibernate.HibernateUtils;
008: import org.andromda.metafacades.uml.ClassifierFacade;
009: import org.andromda.metafacades.uml.EntityAssociationEnd;
010: import org.andromda.metafacades.uml.EntityMetafacadeUtils;
011: import org.andromda.metafacades.uml.NameMasker;
012: import org.andromda.metafacades.uml.TypeMappings;
013: import org.andromda.metafacades.uml.UMLMetafacadeProperties;
014: import org.andromda.metafacades.uml.UMLProfile;
015: import org.apache.commons.lang.ObjectUtils;
016: import org.apache.commons.lang.StringUtils;
017:
018: /**
019: * MetafacadeLogic implementation for
020: * org.andromda.cartridges.hibernate.metafacades.HibernateAssociationEnd.
021: *
022: * @see org.andromda.cartridges.hibernate.metafacades.HibernateAssociationEnd
023: */
024: public class HibernateAssociationEndLogicImpl extends
025: HibernateAssociationEndLogic {
026: public HibernateAssociationEndLogicImpl(Object metaObject,
027: String context) {
028: super (metaObject, context);
029: }
030:
031: /**
032: * Value for set
033: */
034: private static final String COLLECTION_TYPE_SET = "set";
035:
036: /**
037: * Value for map
038: */
039: private static final String COLLECTION_TYPE_MAP = "map";
040:
041: /**
042: * Value for bags
043: */
044: private static final String COLLECTION_TYPE_BAG = "bag";
045:
046: /**
047: * Value for list
048: */
049: private static final String COLLECTION_TYPE_LIST = "list";
050:
051: /**
052: * Value for collections
053: */
054: private static final String COLLECTION_TYPE_COLLECTION = "collection";
055:
056: /**
057: * Stores the valid collection types
058: */
059: private static final Collection collectionTypes = new ArrayList();
060:
061: static {
062: collectionTypes.add(COLLECTION_TYPE_SET);
063: collectionTypes.add(COLLECTION_TYPE_MAP);
064: collectionTypes.add(COLLECTION_TYPE_BAG);
065: collectionTypes.add(COLLECTION_TYPE_LIST);
066: collectionTypes.add(COLLECTION_TYPE_COLLECTION);
067: }
068:
069: /**
070: * Stores the property indicating whether or not composition should define
071: * the eager loading strategy.
072: */
073: private static final String COMPOSITION_DEFINES_EAGER_LOADING = "compositionDefinesEagerLoading";
074:
075: /**
076: * Stores the default outerjoin setting for this association end.
077: */
078: private static final String PROPERTY_ASSOCIATION_END_OUTERJOIN = "hibernateAssociationEndOuterJoin";
079:
080: /**
081: * Stores the default collection index name.
082: */
083: private static final String COLLECTION_INDEX_NAME = "associationEndCollectionIndexName";
084:
085: /**
086: * Stores the default collection index type.
087: */
088: private static final String COLLECTION_INDEX_TYPE = "associationEndCollectionIndexType";
089:
090: /**
091: * Stores the value of the cascade behavior when modeling an aggregation.
092: */
093: private static final String HIBERNATE_AGGREGATION_CASCADE = "hibernateAggregationCascade";
094:
095: /**
096: * Stores the value of the cascade behavior when modeling a composition.
097: */
098: private static final String HIBERNATE_COMPOSITION_CASCADE = "hibernateCompositionCascade";
099:
100: /**
101: * @see org.andromda.cartridges.hibernate.metafacades.HibernateAssociationEnd#isOne2OnePrimary()
102: */
103: protected boolean handleIsOne2OnePrimary() {
104: return (this .isOne2One() && (this .isAggregation() || this
105: .isComposition()));
106: }
107:
108: /**
109: * @see org.andromda.metafacades.uml.AssociationEndFacade#getGetterSetterTypeName()
110: */
111: public String getGetterSetterTypeName() {
112: String getterSetterTypeName = null;
113:
114: if (this .isMany()) {
115: final boolean specificInterfaces = Boolean
116: .valueOf(
117: ObjectUtils
118: .toString(this
119: .getConfiguredProperty(HibernateGlobals.SPECIFIC_COLLECTION_INTERFACES)))
120: .booleanValue();
121:
122: final TypeMappings mappings = this .getLanguageMappings();
123: if (mappings != null) {
124: if (this .isMap()) {
125: getterSetterTypeName = mappings
126: .getTo(UMLProfile.MAP_TYPE_NAME);
127: } else if (specificInterfaces) {
128: if (this .isSet()) {
129: getterSetterTypeName = mappings
130: .getTo(UMLProfile.SET_TYPE_NAME);
131: } else if (this .isList()) {
132: getterSetterTypeName = mappings
133: .getTo(UMLProfile.LIST_TYPE_NAME);
134: }
135: } else {
136: getterSetterTypeName = ObjectUtils
137: .toString(this
138: .getConfiguredProperty(HibernateGlobals.DEFAULT_COLLECTION_INTERFACE));
139: }
140: } else {
141: getterSetterTypeName = ObjectUtils
142: .toString(this
143: .getConfiguredProperty(HibernateGlobals.DEFAULT_COLLECTION_INTERFACE));
144: }
145: } else {
146: final ClassifierFacade type = this .getType();
147:
148: if (type instanceof HibernateEntity) {
149: final String typeName = ((HibernateEntity) type)
150: .getFullyQualifiedEntityName();
151:
152: if (StringUtils.isNotEmpty(typeName)) {
153: getterSetterTypeName = typeName;
154: }
155: }
156: }
157:
158: if (getterSetterTypeName == null) {
159: getterSetterTypeName = super .getGetterSetterTypeName();
160: } else if (this .isMany()) {
161: // set this association end's type as a template parameter if required
162: if (Boolean
163: .valueOf(
164: String
165: .valueOf(this
166: .getConfiguredProperty(UMLMetafacadeProperties.ENABLE_TEMPLATING)))
167: .booleanValue()) {
168: getterSetterTypeName = getterSetterTypeName + "<"
169: + this .getType().getFullyQualifiedName() + ">";
170: }
171: }
172:
173: return getterSetterTypeName;
174: }
175:
176: /**
177: * @see org.andromda.cartridges.hibernate.metafacades.HibernateAssociationEnd#isLazy()
178: */
179: protected boolean handleIsLazy() {
180: String lazyString = (String) findTaggedValue(HibernateProfile.TAGGEDVALUE_HIBERNATE_LAZY);
181: boolean lazy = true;
182:
183: if (lazyString == null) {
184: // check whether or not composition defines eager loading is turned
185: // on
186: boolean compositionDefinesEagerLoading = Boolean
187: .valueOf(
188: String
189: .valueOf(this
190: .getConfiguredProperty(COMPOSITION_DEFINES_EAGER_LOADING)))
191: .booleanValue();
192:
193: if (compositionDefinesEagerLoading) {
194: lazy = !this .getOtherEnd().isComposition();
195: }
196: } else {
197: lazy = Boolean.valueOf(lazyString).booleanValue();
198: }
199:
200: return lazy;
201: }
202:
203: /**
204: * calculates the hibernate cascade attribute of this association end.
205: *
206: * @return null if no relevant cascade attribute to deliver
207: * @see org.andromda.cartridges.hibernate.metafacades.HibernateAssociationEnd#getHibernateCascade()
208: */
209: protected String handleGetHibernateCascade() {
210: String cascade = null;
211: final String individualCascade = (String) findTaggedValue(HibernateProfile.TAGGEDVALUE_HIBERNATE_CASCADE);
212:
213: if ((individualCascade != null)
214: && (individualCascade.length() > 0)) {
215: cascade = individualCascade;
216: } else if (this .isChild()) // other end is a composition
217: {
218: if (StringUtils.isBlank(this
219: .getHibernateCompositionCascade())) {
220: cascade = HibernateGlobals.HIBERNATE_CASCADE_DELETE;
221:
222: final Object type = this .getType();
223:
224: if (type != null && type instanceof HibernateEntity) {
225: HibernateEntity entity = (HibernateEntity) type;
226: final String defaultCascade = entity
227: .getHibernateDefaultCascade();
228:
229: if (defaultCascade
230: .equalsIgnoreCase(HibernateGlobals.HIBERNATE_CASCADE_SAVE_UPDATE)
231: || defaultCascade
232: .equalsIgnoreCase(HibernateGlobals.HIBERNATE_CASCADE_ALL)) {
233: if (this .isMany()) {
234: cascade = HibernateGlobals.HIBERNATE_CASCADE_ALL_DELETE_ORPHAN;
235: } else {
236: cascade = HibernateGlobals.HIBERNATE_CASCADE_ALL;
237: }
238: }
239: }
240: } else {
241: cascade = this .getHibernateCompositionCascade();
242: }
243: } else if (this .isComposition()) {
244: // on the composition side, always enforce "none", overriding a
245: // default-cascade value
246: cascade = HibernateGlobals.HIBERNATE_CASCADE_NONE;
247: } else if (StringUtils.isNotBlank(this
248: .getHibernateAggregationCascade())) {
249: // on the aggregation side, always enforce "none", overriding a
250: // default-cascade value
251: if (this .isAggregation()) {
252: cascade = HibernateGlobals.HIBERNATE_CASCADE_NONE;
253: } else if (this .getOtherEnd() != null
254: && this .getOtherEnd().isAggregation()) {
255: cascade = this .getHibernateAggregationCascade();
256: }
257: }
258: return cascade;
259: }
260:
261: /**
262: * @see org.andromda.cartridges.hibernate.metafacades.HibernateAssociationEnd#isHibernateInverse()
263: */
264: protected boolean handleIsHibernateInverse() {
265: // inverse can only be true if the relation is bidirectional
266: boolean inverse = this .isNavigable()
267: && this .getOtherEnd().isNavigable();
268:
269: if (inverse) {
270: inverse = this .isMany2One();
271:
272: // for many-to-many we just put the flag on the side that
273: // is aggregation or composition and on the lexically longer
274: // fully qualified name for it's type on other types of relations
275: if (this .isMany2Many() && !inverse) {
276: if (this .isAggregation() || this .isComposition()) {
277: inverse = false;
278: } else if (this .getOtherEnd().isAggregation()
279: || this .getOtherEnd().isComposition()) {
280: inverse = true;
281: } else {
282: String endTypeName = StringUtils.trimToEmpty(this
283: .getType().getFullyQualifiedName(true));
284: String otherEndTypeName = StringUtils
285: .trimToEmpty(this .getOtherEnd().getType()
286: .getFullyQualifiedName(true));
287: int compareTo = endTypeName
288: .compareTo(otherEndTypeName);
289:
290: // if for some reason the fully qualified names are equal,
291: // compare the names.
292: if (compareTo == 0) {
293: String endName = StringUtils.trimToEmpty(this
294: .getName());
295: String otherEndName = StringUtils
296: .trimToEmpty(this .getOtherEnd()
297: .getName());
298: compareTo = endName.compareTo(otherEndName);
299: }
300:
301: inverse = compareTo < 0;
302: }
303: if (inverse && this .isBidirectionalOrderedListChild()
304: && this .isVersion3()) { // A special case - when using ver 3 of hibernate for a bi-dir
305: // ordered list, "inverse" should be set to FALSE, rather than
306: // the usual TRUE. See http://www.hibernate.org/193.html
307: inverse = false;
308: }
309: }
310: }
311:
312: return inverse;
313: }
314:
315: /**
316: * Hibernate 2 outer join option
317: */
318: private static final String HIBERNATE_OUTER_JOIN_YES = "yes";
319:
320: /**
321: * Hibernate 2 outer join option
322: */
323: private static final String HIBERNATE_OUTER_JOIN_AUTO = "auto";
324:
325: /**
326: * @see org.andromda.cartridges.hibernate.metafacades.HibernateAssociationEnd#getOuterJoin()
327: */
328: protected String handleGetOuterJoin() {
329: Object value = this
330: .findTaggedValue(HibernateProfile.TAGGEDVALUE_HIBERNATE_OUTER_JOIN);
331:
332: if (value == null) {
333: value = this
334: .getConfiguredProperty(PROPERTY_ASSOCIATION_END_OUTERJOIN);
335: }
336: String outerValue = StringUtils.trimToEmpty(String
337: .valueOf(value));
338: String version = (String) this
339: .getConfiguredProperty(HibernateGlobals.HIBERNATE_VERSION);
340:
341: if (version.equals(HibernateGlobals.HIBERNATE_VERSION_3)) {
342: outerValue = (outerValue.equals(HIBERNATE_OUTER_JOIN_AUTO) || outerValue
343: .equals(HIBERNATE_OUTER_JOIN_YES)) ? "select"
344: : "join";
345: }
346: return outerValue;
347: }
348:
349: /**
350: * Overridden to provide handling of inheritance.
351: *
352: * @see org.andromda.metafacades.uml.AssociationEndFacade#isRequired()
353: */
354: public boolean isRequired() {
355: boolean required = super .isRequired();
356: Object type = this .getOtherEnd().getType();
357:
358: if ((type != null)
359: && HibernateEntity.class.isAssignableFrom(type
360: .getClass())) {
361: HibernateEntity entity = (HibernateEntity) type;
362:
363: if (entity.isHibernateInheritanceClass()
364: && (entity.getGeneralization() != null)) {
365: required = false;
366: }
367: }
368:
369: return required;
370: }
371:
372: /**
373: * @see org.andromda.cartridges.hibernate.metafacades.HibernateAssociationEnd#getCollectionType()
374: */
375: protected String handleGetCollectionType() {
376: String collectionType = this .getSpecificCollectionType();
377:
378: if (!collectionTypes.contains(collectionType)) {
379: if (this .isOrdered()) {
380: collectionType = COLLECTION_TYPE_LIST;
381: } else {
382: collectionType = (String) this
383: .getConfiguredProperty(HibernateGlobals.HIBERNATE_ASSOCIATION_COLLECTION_TYPE);
384: }
385: }
386:
387: return collectionType;
388: }
389:
390: /**
391: * Gets the collection type defined on this association end.
392: *
393: * @return the specific collection type.
394: */
395: private String getSpecificCollectionType() {
396: return ObjectUtils
397: .toString(this
398: .findTaggedValue(HibernateProfile.TAGGEDVALUE_HIBERNATE_ASSOCIATION_COLLECTION_TYPE));
399: }
400:
401: /**
402: * @see org.andromda.cartridges.hibernate.metafacades.HibernateAssociationEnd#getSortType()
403: */
404: protected String handleGetSortType() {
405: return ObjectUtils
406: .toString(this
407: .findTaggedValue(HibernateProfile.TAGGEDVALUE_HIBERNATE_ASSOCIATION_SORT_TYPE));
408: }
409:
410: /**
411: * @see org.andromda.cartridges.hibernate.metafacades.HibernateAssociationEnd#getOrderByColumns()
412: */
413: protected String handleGetOrderByColumns() {
414: String orderColumns = (String) this
415: .findTaggedValue(HibernateProfile.TAGGEDVALUE_HIBERNATE_ASSOCIATION_ORDER_BY_COLUMNS);
416:
417: if (orderColumns == null) {
418: orderColumns = ((EntityAssociationEnd) this .getOtherEnd())
419: .getColumnName();
420: }
421:
422: return orderColumns;
423: }
424:
425: /**
426: * @see org.andromda.cartridges.hibernate.metafacades.HibernateAssociationEnd#getWhereClause()
427: */
428: protected String handleGetWhereClause() {
429: return (String) this
430: .findTaggedValue(HibernateProfile.TAGGEDVALUE_HIBERNATE_ASSOCIATION_WHERE_CLAUSE);
431: }
432:
433: /**
434: * @see org.andromda.cartridges.hibernate.metafacades.HibernateAssociationEnd#isIndexedCollection()
435: */
436: protected boolean handleIsIndexedCollection() {
437: boolean indexed = false;
438:
439: if (this .isOrdered()) {
440: if ((this .getCollectionType().equals(COLLECTION_TYPE_LIST) || this
441: .getCollectionType().equals(COLLECTION_TYPE_MAP))
442: && StringUtils.isNotBlank(this
443: .getCollectionIndexName())) {
444: indexed = true;
445: }
446: }
447:
448: return indexed;
449: }
450:
451: /**
452: * @see org.andromda.cartridges.hibernate.metafacades.HibernateAssociationEnd#getCollectionIndexName()
453: */
454: protected String handleGetCollectionIndexName() {
455: Object value = this
456: .findTaggedValue(HibernateProfile.TAGGEDVALUE_HIBERNATE_ASSOCIATION_INDEX);
457:
458: if ((value == null)
459: && this .isConfiguredProperty(COLLECTION_INDEX_NAME)) {
460: value = this .getConfiguredProperty(COLLECTION_INDEX_NAME);
461:
462: if (StringUtils.isBlank(ObjectUtils.toString(value))) {
463: value = null;
464: }
465: }
466:
467: if (value != null) {
468: return ObjectUtils.toString(value);
469: }
470: final String otherEntityName = ((HibernateEntity) this
471: .getOtherEnd().getType()).getEntityName();
472: final Object separator = this
473: .getConfiguredProperty(UMLMetafacadeProperties.SQL_NAME_SEPARATOR);
474: return EntityMetafacadeUtils.toSqlName(otherEntityName,
475: separator)
476: + separator
477: + EntityMetafacadeUtils.toSqlName(this .getName(),
478: separator) + separator + "IDX";
479: }
480:
481: /**
482: * @see org.andromda.cartridges.hibernate.metafacades.HibernateAssociationEnd#getCollectionIndexType()
483: */
484: protected String handleGetCollectionIndexType() {
485: Object value = this
486: .findTaggedValue(HibernateProfile.TAGGEDVALUE_HIBERNATE_ASSOCIATION_INDEX_TYPE);
487:
488: if (value == null) {
489: value = this .getConfiguredProperty(COLLECTION_INDEX_TYPE);
490:
491: if (StringUtils.isBlank(ObjectUtils.toString(value))) {
492: value = null;
493: }
494: }
495:
496: if (value != null) {
497: if (value instanceof String) {
498: value = this .getRootPackage().findModelElement(
499: (String) value);
500: }
501: if (value instanceof HibernateType) {
502: value = ((HibernateType) value)
503: .getFullyQualifiedHibernateType();
504: }
505: }
506:
507: return (value != null) ? ObjectUtils.toString(value) : null;
508: }
509:
510: /**
511: * @see org.andromda.cartridges.hibernate.metafacades.HibernateAssociationEnd#isMap()
512: */
513: protected boolean handleIsMap() {
514: boolean isMap = this .getCollectionType().equalsIgnoreCase(
515: COLLECTION_TYPE_MAP);
516:
517: if (isMap
518: && StringUtils
519: .isBlank(this .getSpecificCollectionType())) {
520: isMap = !this .isOrdered();
521: }
522:
523: return isMap;
524: }
525:
526: /**
527: * @see org.andromda.cartridges.hibernate.metafacades.HibernateAssociationEnd#isList()
528: */
529: protected boolean handleIsList() {
530: boolean isList = this .getCollectionType().equalsIgnoreCase(
531: COLLECTION_TYPE_LIST);
532:
533: if (!isList
534: && StringUtils
535: .isBlank(this .getSpecificCollectionType())) {
536: isList = this .isOrdered();
537: }
538:
539: return isList;
540: }
541:
542: /**
543: * @see org.andromda.cartridges.hibernate.metafacades.HibernateAssociationEnd#isSet()
544: */
545: protected boolean handleIsSet() {
546: boolean isSet = this .getCollectionType().equalsIgnoreCase(
547: COLLECTION_TYPE_SET);
548:
549: if (isSet
550: && StringUtils
551: .isBlank(this .getSpecificCollectionType())) {
552: isSet = !this .isOrdered();
553: }
554:
555: return isSet;
556: }
557:
558: /**
559: * @see org.andromda.cartridges.hibernate.metafacades.HibernateAssociationEnd#isBag()
560: */
561: protected boolean handleIsBag() {
562: return this .getCollectionType().equalsIgnoreCase(
563: COLLECTION_TYPE_BAG);
564: }
565:
566: /**
567: * @see org.andromda.cartridges.hibernate.metafacades.HibernateAssociationEnd#getCollectionTypeImplementation()
568: */
569: protected String handleGetCollectionTypeImplementation() {
570: StringBuffer implementation = new StringBuffer();
571:
572: if (this .isMany()) {
573: implementation.append("new ");
574:
575: if (this .isSet()) {
576: implementation
577: .append(this
578: .getConfiguredProperty(HibernateGlobals.SET_TYPE_IMPLEMENTATION));
579: } else if (this .isMap()) {
580: implementation
581: .append(this
582: .getConfiguredProperty(HibernateGlobals.MAP_TYPE_IMPLEMENTATION));
583: } else if (this .isBag()) {
584: implementation
585: .append(this
586: .getConfiguredProperty(HibernateGlobals.BAG_TYPE_IMPLEMENTATION));
587: } else if (this .isList()) {
588: implementation
589: .append(this
590: .getConfiguredProperty(HibernateGlobals.LIST_TYPE_IMPLEMENTATION));
591: }
592:
593: // set this association end's type as a template parameter if required
594: if (Boolean
595: .valueOf(
596: String
597: .valueOf(this
598: .getConfiguredProperty(UMLMetafacadeProperties.ENABLE_TEMPLATING)))
599: .booleanValue()) {
600: implementation.append("<");
601: if (this .isMap()) {
602: implementation
603: .append(this .getCollectionIndexType());
604: implementation.append(", ");
605: }
606: implementation.append(this .getType()
607: .getFullyQualifiedName());
608: implementation.append(">");
609: }
610:
611: implementation.append("()");
612: }
613:
614: return implementation.toString();
615: }
616:
617: /**
618: * @see org.andromda.cartridges.hibernate.metafacades.HibernateAssociationEnd#getHibernateAggregationCascade()
619: */
620: protected java.lang.String handleGetHibernateAggregationCascade() {
621: return StringUtils.trimToEmpty(ObjectUtils.toString(this
622: .getConfiguredProperty(HIBERNATE_AGGREGATION_CASCADE)));
623: }
624:
625: /**
626: * @see org.andromda.cartridges.hibernate.metafacades.HibernateAssociationEnd#getHibernateCompositionCascade()
627: */
628: protected java.lang.String handleGetHibernateCompositionCascade() {
629: return StringUtils.trimToEmpty(ObjectUtils.toString(this
630: .getConfiguredProperty(HIBERNATE_COMPOSITION_CASCADE)));
631: }
632:
633: /**
634: * @see org.andromda.cartridges.hibernate.metafacades.HibernateAssociationEnd#isBidirectionalOrderedListParent()
635: */
636: protected boolean handleIsBidirectionalOrderedListParent() {
637: boolean isBidirectionalOrderedListParent = false;
638: boolean biDirectional = this .isNavigable()
639: && this .getOtherEnd().isNavigable();
640:
641: if (biDirectional
642: && this .isOne2Many()
643: && (this .getOtherEnd() instanceof HibernateAssociationEnd)) {
644: HibernateAssociationEnd otherEnd = (HibernateAssociationEnd) this
645: .getOtherEnd();
646:
647: isBidirectionalOrderedListParent = otherEnd
648: .getCollectionType().equals(COLLECTION_TYPE_LIST)
649: && otherEnd.isIndexedCollection();
650: }
651:
652: return isBidirectionalOrderedListParent;
653: }
654:
655: /**
656: * @see org.andromda.cartridges.hibernate.metafacades.HibernateAssociationEnd#isBidirectionalOrderedListChild()
657: */
658: protected boolean handleIsBidirectionalOrderedListChild() {
659: boolean biDirectional = false;
660: if (this .getOtherEnd() instanceof HibernateAssociationEnd) {
661: HibernateAssociationEnd otherEnd = (HibernateAssociationEnd) this
662: .getOtherEnd();
663: biDirectional = otherEnd.isBidirectionalOrderedListParent();
664: }
665: return biDirectional;
666: }
667:
668: /**
669: * @see org.andromda.cartridges.hibernate.metafacades.HibernateAssociationEnd#isUsingHibernate3()
670: */
671: protected boolean handleIsUsingHibernate3() {
672: boolean usingHibernate3 = false;
673: String property = (String) this
674: .getConfiguredProperty(HibernateGlobals.HIBERNATE_VERSION);
675: if (property != null) {
676: usingHibernate3 = property
677: .equals(HibernateGlobals.HIBERNATE_VERSION_3);
678: }
679: return usingHibernate3;
680: }
681:
682: /**
683: * @see org.andromda.cartridges.hibernate.metafacades.HibernateAssociationEnd#getCollectionIndexNameGetter()
684: */
685: protected String handleGetCollectionIndexNameGetter() {
686: return "get"
687: + NameMasker.mask(this .getCollectionIndexName(),
688: NameMasker.UPPERCAMELCASE);
689: }
690:
691: /**
692: * @see org.andromda.cartridges.hibernate.metafacades.HibernateAssociationEnd#getCollectionIndexNameSetter()
693: */
694: protected String handleGetCollectionIndexNameSetter() {
695: return "set"
696: + NameMasker.mask(this .getCollectionIndexName(),
697: NameMasker.UPPERCAMELCASE);
698: }
699:
700: private boolean isVersion3() {
701: return HibernateUtils
702: .isVersion3((String) this
703: .getConfiguredProperty(HibernateGlobals.HIBERNATE_VERSION));
704: }
705:
706: private boolean isXMLPersistenceActive() {
707: return HibernateUtils
708: .isXmlPersistenceActive(
709: (String) this
710: .getConfiguredProperty(HibernateGlobals.HIBERNATE_VERSION),
711: (String) this
712: .getConfiguredProperty(HibernateGlobals.HIBERNATE_XML_PERSISTENCE));
713: }
714:
715: /**
716: * @see org.andromda.cartridges.hibernate.metafacades.HibernateAssociationEnd#getEmbedXML()
717: */
718: protected String handleGetEmbedXML() {
719: String embedVal = null;
720:
721: if (isXMLPersistenceActive()) {
722: embedVal = (String) this
723: .findTaggedValue(HibernateProfile.TAGGEDVALUE_HIBERNATE_XML_EMBED);
724:
725: if (embedVal == null) {
726: boolean isBiDirectional = this .isNavigable()
727: && this .getOtherEnd().isNavigable();
728: if (isBiDirectional && this .isMany()) {
729: embedVal = "false";
730: } else {
731: embedVal = "true";
732: }
733: }
734: }
735: return (StringUtils.isBlank(embedVal)) ? null : embedVal;
736: }
737:
738: /**
739: * @see org.andromda.cartridges.hibernate.metafacades.HibernateAssociationEnd#getXmlTagName()
740: */
741: protected String handleGetXmlTagName() {
742: String tagName = null;
743:
744: if (isXMLPersistenceActive()) {
745: tagName = (String) this
746: .findTaggedValue(HibernateProfile.TAGGEDVALUE_HIBERNATE_XML_TAG_NAME);
747:
748: if (tagName == null) {
749: tagName = this.getName();
750: }
751: }
752: return (StringUtils.isBlank(tagName)) ? null : tagName;
753: }
754: }
|