01: package org.andromda.cartridges.ejb.metafacades;
02:
03: import java.text.MessageFormat;
04:
05: import java.util.StringTokenizer;
06:
07: import org.andromda.cartridges.ejb.EJBProfile;
08: import org.andromda.metafacades.uml.GeneralizableElementFacade;
09: import org.apache.commons.lang.StringUtils;
10:
11: /**
12: * MetafacadeLogic implementation for org.andromda.cartridges.ejb.metafacades.ValueObjectFacade.
13: *
14: * @see org.andromda.cartridges.ejb.metafacades.ValueObjectFacade
15: */
16: public class ValueObjectFacadeLogicImpl extends ValueObjectFacadeLogic {
17: // ---------------- constructor -------------------------------
18: public ValueObjectFacadeLogicImpl(Object metaObject, String context) {
19: super (metaObject, context);
20: }
21:
22: /**
23: * Using <code>/</code> in the configuredProperty <code>valueObjectPackage</code> can remove the previous package
24: * name.
25: *
26: * @see org.andromda.cartridges.ejb.metafacades.ValueObjectFacade#getPackageName()
27: */
28: public String getPackageName() {
29: final String packageName = MessageFormat.format(
30: this .getConfiguredProperty("valueObjectPackage")
31: .toString(), new String[] { StringUtils
32: .trimToEmpty(super .getPackageName()) });
33: StringBuffer buffer = new StringBuffer();
34: for (final StringTokenizer tokenizer = new StringTokenizer(
35: packageName, "."); tokenizer.hasMoreTokens();) {
36: String token = tokenizer.nextToken();
37: if (token.indexOf("/") < 0) {
38: buffer.append(token).append(".");
39: }
40: }
41: final String name = buffer.toString();
42: return name.endsWith(".") ? name
43: .substring(0, name.length() - 1) : name;
44: }
45:
46: /**
47: * @see org.andromda.cartridges.ejb.metafacades.ValueObjectFacade#getName()
48: */
49: public String getName() {
50: return MessageFormat
51: .format(this .getConfiguredProperty("valueObjectName")
52: .toString(), new Object[] { StringUtils
53: .trimToEmpty(super .getName()) });
54: }
55:
56: /**
57: * @see org.andromda.metafacades.uml.ModelElementFacade#getFullyQualifiedName()
58: */
59: public String getFullyQualifiedName() {
60: final String name = this .getPackageName();
61: return name == null || name.equalsIgnoreCase("") ? getName()
62: : name + "." + getName();
63: }
64:
65: /**
66: * If we're using inheritance to build up a value object with all model elements of an entity, we're returning no
67: * superclass.
68: */
69: public GeneralizableElementFacade getGeneralization() {
70: GeneralizableElementFacade generalization = super
71: .getGeneralization();
72: return generalization == null
73: || generalization
74: .hasStereotype(EJBProfile.STEREOTYPE_ENTITY) ? null
75: : generalization;
76: }
77: }
|