|
From: Chad B. <cwb...@us...> - 2008-03-28 20:30:54
|
User: cwbrandon
Date: 08/03/28 13:31:00
Modified: andromda-jsf2/src/main/resources/templates/jsf2/preferences/portlet
Preferences.java.vsl
andromda-jsf2/src/main/resources/templates/jsf2/controllers
Controller.java.vsl
Log:
finish implementing facade portlet prefs class
Revision Changes Path
1.2 +58 -120 cartridges/andromda-jsf2/src/main/resources/templates/jsf2/preferences/portlet/Preferences.java.vsl
Index: Preferences.java.vsl
===================================================================
RCS file: /cvsroot/andromdaplugins/cartridges/andromda-jsf2/src/main/resources/templates/jsf2/preferences/portlet/Preferences.java.vsl,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -w -r1.1 -r1.2
--- Preferences.java.vsl 28 Mar 2008 18:37:03 -0000 1.1
+++ Preferences.java.vsl 28 Mar 2008 20:30:59 -0000 1.2
@@ -8,164 +8,102 @@
#end
/**
+ * Provides access to portlet preferences for: $class.useCase.name.
$class.getDocumentation(" * ")
*/
-public#if($class.abstract) abstract#end class $class.name
-#if($class.generalization)
- extends $class.generalization.fullyQualifiedName
-#end
-#if ($serializable)
- implements java.io.Serializable
-#end
+public class $class.name
{
-#if ($serializable)
/**
- * The serial version UID of this class. Needed for serialization.
+ * The shared instance of this class.
*/
- private static final long serialVersionUID = ${class.serialVersionUID}L;
+ private static $class.name instance;
-#end
-##
-## default constructor
-##
-#if ($class.requiredConstructorParameters.size() > 0 || $class.allRequiredConstructorParameters.size() > $class.requiredConstructorParameters.size())
- public ${class.name}()
+ /**
+ * Gets the shared instance of this class.
+ */
+ public static $class.name getInstance()
{
-#if($class.generalization)
- super();
-#end
+ if (instance == null)
+ {
+ instance = new ${class.name}();
+ }
+ return instance;
}
-#end
-##
-## constructor taking only required properties
-##
-#if ($class.allProperties.size() > $class.allRequiredConstructorParameters.size() && ($class.allRequiredConstructorParameters.size() != 1 || !$class.allRequiredConstructorParameters.get(0).getterSetterTypeName.equals($class.fullyQualifiedName)))
- public ${class.name}(## no newline
-#set ($comma = "")
-#foreach ($property in $class.allRequiredConstructorParameters)
-${comma}${property.getterSetterTypeName} ${property.name}## no newline
-#set ($comma = ", ")
-#end
-)
+ private ${class.name}()
{
-#if($class.generalization)
- super(## no newline
-#set ($comma = "")
-#foreach ($property in $class.generalization.allRequiredConstructorParameters)
-${comma}${property.name}## no newline
-#set ($comma = ", ")
-#end
-);
-#end
-#foreach ($property in $class.requiredConstructorParameters)
- this.${property.name} = ${property.name};
-#end
}
-#end
-##
-## constructor taking all properties
-##
-#if ($class.allProperties.size() != 1 || !$class.allProperties.get(0).getterSetterTypeName.equals($class.fullyQualifiedName))
- public ${class.name}(## no newline
-#set ($comma = "")
-#foreach ($property in $class.allProperties)
-${comma}${property.getterSetterTypeName} ${property.name}## no newline
-#set ($comma = ", ")
-#end
-)
+ protected javax.portlet.PortletPreferences getPreferences()
{
-#if($class.generalization)
- super(## no newline
-#set ($comma = "")
-#foreach ($property in $class.generalization.allProperties)
-${comma}${property.name}## no newline
-#set ($comma = ", ")
-#end
-);
-#end
-#foreach ($property in $class.properties)
- this.${property.name} = ${property.name};
-#end
+ return ((javax.portlet.PortletRequest)javax.faces.context.FacesContext.getCurrentInstance().getExternalContext().getRequest()).getPreferences();
}
+#foreach ($attribute in $class.attributes)
-#end
/**
- * Copies constructor from other ${class.name}
- *
- * @param otherBean, cannot be <code>null</code>
- * @throws java.lang.NullPointerException if the argument is <code>null</code>
+$attribute.getDocumentation(" * ")
*/
- public ${class.name}(${class.name} otherBean)
+ public $attribute.getterSetterTypeName ${attribute.getterName}()
{
- this(## no newline
-#set ($comma = "")
-#foreach ($property in $class.allProperties)
-${comma}otherBean.${property.getterName}()## no newline
-#set ($comma = ", ")
+ final java.lang.String value = this.getPreferences().getValue("$attribute.name", null);
+#if (!$attribute.type.stringType)
+ final $attribute.type.wrapperName wrappedValue = ${attribute.type.wrapperName}.valueOf(value);
+#* *##if ($attribute.type.primitive)
+ return wrappedValue.${attribute.getterSetterTypeName}Value();
+#* *##else
+ return wrappedValue;
+#* *##end
+#else
+ return value;
#end
-);
}
/**
- * Copies all properties from the argument value object into this value object.
+ * Associates the value of the specified <code>${attribute.name}</code>
+ * with the '${attribute.name}' preference and persists the change if <code>store</code>
+ * is specified as <code>true</code>.
+ *
+ * @param $attribute.name the value to give the $attribute.name preference.
*/
- public void copy(${class.name} otherBean)
+ public void ${attribute.setterName}(final $attribute.getterSetterTypeName $attribute.name, final boolean store)
+ throws Exception
{
- if (otherBean != null)
+#if ($attribute.type.primitive)
+ final java.lang.String value = java.lang.String.valueOf($attribute.name);
+#else
+ java.lang.String value = null;
+ if ($attribute.name != null)
{
-#foreach ($property in $class.allProperties)
- this.${property.setterName}(otherBean.${property.getterName}());
-#end
- }
+ value = java.lang.String.valueOf($attribute.name);
}
-
-#foreach ($attribute in $class.attributes)
- private $attribute.getterSetterTypeName $attribute.name#if ($attribute.defaultValuePresent) = $attribute.defaultValue#end;
-
- /**
-$attribute.getDocumentation(" * ")
- */
- public $attribute.getterSetterTypeName ${attribute.getterName}()
+#end
+ this.getPreferences().setValue("$attribute.name", value);
+ if (store)
{
- return this.${attribute.name};
+ this.store();
}
-
-## - always have as public, having read-only causes too many issues when attempting to
-## use in other cartridges
- public void ${attribute.setterName}($attribute.getterSetterTypeName $attribute.name)
- {
- this.${attribute.name} = $attribute.name;
}
-#end
-## Generate the relation methods.
-#foreach ($associationEnd in $class.associationEnds)
-#set ($target = $associationEnd.otherEnd)
-#if ($target.navigable)
- private $target.getterSetterTypeName $target.name;
-
/**
- * Get the $target.name
-$target.getDocumentation(" * ")
+ * Associates the value of the specified <code>${attribute.name}</code>
+ * with the '${attribute.name}' preference and persists the change.
+ *
+ * @param $attribute.name the value to give the $attribute.name preference.
*/
- public $target.getterSetterTypeName ${target.getterName}()
+ public void ${attribute.setterName}(final $attribute.getterSetterTypeName $attribute.name)
+ throws Exception
{
- return this.${target.name};
+ this.${attribute.setterName}($attribute.name, true);
}
-## - always have as public, having read-only causes too many issues when attempting to
-## use in other cartridges
+#end
/**
- * Sets the $target.name
+ * Commits any pending portlet preference changes.
*/
- public void ${target.setterName}($target.getterSetterTypeName $target.name)
+ public void store() throws Exception
{
- this.${target.name} = ${target.name};
+ this.getPreferences().store();
}
-#end
-#end
- // ${class.fullyQualifiedName} value-object java merge-point
+ // ${class.fullyQualifiedName} portlet-preferences merge-point
}
\ No newline at end of file
1.9 +10 -0 cartridges/andromda-jsf2/src/main/resources/templates/jsf2/controllers/Controller.java.vsl
Index: Controller.java.vsl
===================================================================
RCS file: /cvsroot/andromdaplugins/cartridges/andromda-jsf2/src/main/resources/templates/jsf2/controllers/Controller.java.vsl,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -w -r1.8 -r1.9
--- Controller.java.vsl 21 Mar 2008 16:07:13 -0000 1.8
+++ Controller.java.vsl 28 Mar 2008 20:31:00 -0000 1.9
@@ -531,4 +531,14 @@
this.getRequest().setAttribute(ACTION_EVENT_ATTRIBUTES, event.getComponent().
getAttributes());
}
+#if ($portlet && $controller.useCase.preferences)
+
+ /**
+ * Gets the portlet preferences available to this controller.
+ */
+ protected $controller.useCase.preferences.name getPreferences()
+ {
+ return ${controller.useCase.preferences.name}.getInstance();
+ }
+#end
}
\ No newline at end of file
|