<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Japlemmo</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Japlemmo"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Japlemmo"/>
	<updated>2026-09-19T19:28:06Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517/M601_Design_Document&amp;diff=75212</id>
		<title>CSC/ECE 517/M601 Design Document</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517/M601_Design_Document&amp;diff=75212"/>
		<updated>2013-04-27T12:43:20Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: /* Specific Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;h1&amp;gt;Add ability to update css through webapp&amp;lt;/h1&amp;gt;&lt;br /&gt;
== Example Video ==&lt;br /&gt;
A video example of this module can be seen here [http://youtu.be/2dQeFYjcsnU]&lt;br /&gt;
==Team== &lt;br /&gt;
Yuri Kolesnikov &amp;lt;br&amp;gt;&lt;br /&gt;
Jonathan Wills &amp;lt;br&amp;gt;&lt;br /&gt;
Jeffrey Plemmons &amp;lt;br&amp;gt;&lt;br /&gt;
Roshna Agarwal&lt;br /&gt;
&lt;br /&gt;
==Our Work==&lt;br /&gt;
Link to the OpenMRS ticket: https://tickets.openmrs.org/browse/TRUNK-3415&amp;lt;br&amp;gt;&lt;br /&gt;
Link to our code in GitHub: https://github.com/ykolesn/openmrs-module-m601 &amp;lt;br&amp;gt;&lt;br /&gt;
Link to application: http://152.46.17.228:8081/openmrs-standalone&lt;br /&gt;
&lt;br /&gt;
==Purpose==&lt;br /&gt;
	The purpose of this module is to add the functionality of allowing the admin to customize the OpenMRS css file to their own specifications. By having the ability to customize the OpenMRS css file, the admin will be free to change the look and feel in their installation of OpenMRS.&lt;br /&gt;
&lt;br /&gt;
==Problem Definition==&lt;br /&gt;
	Add admin page for customization of the openmrs css file. Admins can 'override' any openmrs css with their own file by specifying that file in the openmrs runtime properties file.&lt;br /&gt;
This would be best as a new module in openmrs or perhaps just adding a new feature in the Custom Logo module? The admin should see a page with a large text box. The text box value should be persisted in the database as a new object/table/column somehow. When the module starts up, the Activator is called. Modify the activator to update the filesystem css file with whatever is defined by the admin.&lt;br /&gt;
&lt;br /&gt;
==Design Requirements==&lt;br /&gt;
&lt;br /&gt;
1. The admin should be able to customize the openmrs css file through an admin page. &amp;lt;br&amp;gt;&lt;br /&gt;
2. The admin should see a page with a large text box. &amp;lt;br&amp;gt;&lt;br /&gt;
3. The text box content should be stored in the database. &amp;lt;br&amp;gt;&lt;br /&gt;
4. The activator needs to be modified so that it updates the filesystem css file with whatever is defined by the admin. &amp;lt;br&amp;gt;&lt;br /&gt;
5. Need to use Eclipse and Maven as development tools for the module. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
'''Week 1'''&lt;br /&gt;
&lt;br /&gt;
*Get OpenMRS Id&lt;br /&gt;
*Get ticket assigned and in progress&lt;br /&gt;
*Get openmrs module name assigned&lt;br /&gt;
*Create openmrs module&lt;br /&gt;
*Commit module to github&lt;br /&gt;
*Check out module on partner machines&lt;br /&gt;
*Get new admin page link&lt;br /&gt;
*Create new spring controller and jsp page&lt;br /&gt;
'''Week 2'''&lt;br /&gt;
&lt;br /&gt;
*Create object for storing css in db&lt;br /&gt;
*Create service layer and dao layer methods to save object&lt;br /&gt;
*Connect controller to db object for saving + retrieving&lt;br /&gt;
*Add unit tests for saving/retrieving&lt;br /&gt;
'''Week 3'''&lt;br /&gt;
&lt;br /&gt;
*Create settings page to allow admin to choose where tomcat is running&lt;br /&gt;
*Add some magic so that module tries to guess where tomcat is running&lt;br /&gt;
*Add ability to put the saved css into the right folder in tomcat so that the css is actually overriding the openmrs style.css file.&lt;br /&gt;
&lt;br /&gt;
==Development Tools==&lt;br /&gt;
1. '''Eclipse'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Integrated_development_environment&amp;lt;/ref&amp;gt;: Eclipse is the Integrated Development Environment used to develop, modify, and compile the code for our module. &amp;lt;br&amp;gt;&lt;br /&gt;
2. '''Maven'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Maven&amp;lt;/ref&amp;gt;: Maven is used through a plug-in in Eclipse to compile, run unit tests, and package all of the Java files in the module.  &amp;lt;br&amp;gt;&lt;br /&gt;
3. '''Tomcat'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Tomcat&amp;lt;/ref&amp;gt;: Tomcat is the web-server used to run the application. &amp;lt;br&amp;gt; &lt;br /&gt;
4. '''Hibernate'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Hibernate_(Java)&amp;lt;/ref&amp;gt;: Hibernate is a built-in utility in the OpenMRS module, that is used to connect the Java classes to the database tables in the application. It configured the database table through an xml file: UpdateCSS.hbm.xml&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE hibernate-mapping PUBLIC&lt;br /&gt;
    &amp;quot;-//Hibernate/Hibernate Mapping DTD 3.0//EN&amp;quot;&lt;br /&gt;
    &amp;quot;http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&amp;quot; &amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hibernate-mapping package=&amp;quot;org.openmrs.module.updatecss&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;class name=&amp;quot;UpdateCSS&amp;quot;&lt;br /&gt;
	table=&amp;quot;css_properties&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;id name=&amp;quot;id&amp;quot; type=&amp;quot;int&amp;quot; column=&amp;quot;id&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;generator class=&amp;quot;native&amp;quot;/&amp;gt;&lt;br /&gt;
        &amp;lt;/id&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;cssData&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;css_location&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;homeDirectory&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;tomcat_home&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/class&amp;gt;&lt;br /&gt;
&amp;lt;/hibernate-mapping&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
''Here in the UpdateCSS.hbm.xml we specify the table name and columns. Hibernate generates the table with the fields specified and handles all the necessary SQL calls and queries.''&amp;lt;br&amp;gt;&lt;br /&gt;
5. '''MySQL''': MySQL&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Mysql&amp;lt;/ref&amp;gt; is the RDBMS that is used to store the CSS data for the application.&lt;br /&gt;
&lt;br /&gt;
==Use Case==&lt;br /&gt;
[[File:Openmrsui.png|800px|alt=OpenMRS UI]]&amp;lt;br&amp;gt;&lt;br /&gt;
''This is the user interface for the UpdateCSS module. The initial start screen provides a default location for the css style sheet and default css code. Here the navigation bar is changed to &amp;quot;orange&amp;quot;. ''&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
1. Log in to the Admin page with user &amp;quot;Admin&amp;quot; and password &amp;quot;Admin123&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
2. Once logged in, click on &amp;quot;Administration&amp;quot; on the right-hand side of the navigation bar. &amp;lt;br&amp;gt;&lt;br /&gt;
3. Under &amp;quot;Update CSS Module&amp;quot;, click on &amp;quot;Manage module&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
4. Here the user can enter their desired CSS preferences for customization. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Application Overview==&lt;br /&gt;
[[File:Overview.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt;Code Changes&amp;lt;/h1&amp;gt;&lt;br /&gt;
==Classes and Files Worked On==&lt;br /&gt;
* UpdateCSSActivator.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSS.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSService.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSServiceImpl.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSDAO.java &amp;lt;br&amp;gt;&lt;br /&gt;
* HibernateUpdateCSSDAO.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSS.hbm.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* liquibase.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* moduleApplicationContext.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSServiceTest.java &amp;lt;br&amp;gt;&lt;br /&gt;
* manage.jsp &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSManageController.java &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Specific Changes==&lt;br /&gt;
'''UpdateCSSActivator.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
The activator class is an OpenMRS standard module class for initializing necessary components&amp;lt;br&amp;gt;&lt;br /&gt;
when the module is in a certain state of activity.  In our case, we needed to have the CSS&amp;lt;br&amp;gt;&lt;br /&gt;
file overridden at module startup so the following function was added.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	/**&lt;br /&gt;
	 * @see ModuleActivator#started()&lt;br /&gt;
	 */&lt;br /&gt;
	public void started() {&lt;br /&gt;
		log.info(&amp;quot;Update CSS Module started&amp;quot;);&lt;br /&gt;
		&lt;br /&gt;
		// When the module loads, copy the css data&lt;br /&gt;
		// to the tomcat directory CSS file&lt;br /&gt;
		UpdateCSSService cssService = Context.getService(UpdateCSSService.class);&lt;br /&gt;
		cssService.copyCssDataToTomcatDirectory();			&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''UpdateCSSServiceImpl.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
Added below methods to UpdateCSSServiceImpl class: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  /**&lt;br /&gt;
+   * Replaces the text of the specified CSS file in the&lt;br /&gt;
+   * specified directory with the specified text&lt;br /&gt;
+   */ +  public void copyCssDataToTomcatDirectory(String directory, String cssText) {&lt;br /&gt;
+    File cssFile = new File(directory);&lt;br /&gt;
+    if (cssFile.exists()) {&lt;br /&gt;
+      writeDataToFile(cssFile, cssText);&lt;br /&gt;
+    }&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Copies the data stored in the DB into the CSS file that is saved in the &lt;br /&gt;
+   * directory column of the css_properties table&lt;br /&gt;
+   */&lt;br /&gt;
+  public void copyCssDataToTomcatDirectory() {&lt;br /&gt;
+    UpdateCSS updateCSS = getData();&lt;br /&gt;
+    String cssDirectory = updateCSS.getHomeDirectory();&lt;br /&gt;
+    String cssText = updateCSS.getCssData();&lt;br /&gt;
+    copyCssDataToTomcatDirectory(cssDirectory, cssText);&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Writes the specified text to the specified CSS file&lt;br /&gt;
+   */&lt;br /&gt;
+  public void writeDataToFile(File cssFile, String cssText) {&lt;br /&gt;
+    try {&lt;br /&gt;
+      if (cssFile.exists()) {&lt;br /&gt;
+        PrintWriter writer = new PrintWriter(cssFile);&lt;br /&gt;
+        writer.print(cssText);&lt;br /&gt;
+        writer.close();&lt;br /&gt;
+      }&lt;br /&gt;
+    } catch (FileNotFoundException ex) {&lt;br /&gt;
+      &lt;br /&gt;
+    }&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Reads the data in the file at the specified path and returns&lt;br /&gt;
+   * a String with the contents. If the file doesn't exist&lt;br /&gt;
+   * then it returns an empty string&lt;br /&gt;
+   */&lt;br /&gt;
+  public String getCssTextFromFile(String filePath) {&lt;br /&gt;
+    String cssText = &amp;quot;&amp;quot;;&lt;br /&gt;
+    try {&lt;br /&gt;
+      File cssFile = new File(filePath);&lt;br /&gt;
+      if (cssFile.exists()) {&lt;br /&gt;
+        cssText = FileUtils.readFileToString(cssFile);&lt;br /&gt;
+      }  &lt;br /&gt;
+    } catch (IOException ex) {&lt;br /&gt;
+    &lt;br /&gt;
+    }&lt;br /&gt;
+    return cssText;&lt;br /&gt;
+  }&lt;br /&gt;
+    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''UpdateCSS.java:''' &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Our model portion of the MVC pattern.  This Java POJO represents the database record we are storing&amp;lt;br&amp;gt;&lt;br /&gt;
to update/get CSS configuration setting.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/**&lt;br /&gt;
 * The contents of this file are subject to the OpenMRS Public License&lt;br /&gt;
 * Version 1.0 (the &amp;quot;License&amp;quot;); you may not use this file except in&lt;br /&gt;
 * compliance with the License. You may obtain a copy of the License at&lt;br /&gt;
 * http://license.openmrs.org&lt;br /&gt;
 *&lt;br /&gt;
 * Software distributed under the License is distributed on an &amp;quot;AS IS&amp;quot;&lt;br /&gt;
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the&lt;br /&gt;
 * License for the specific language governing rights and limitations&lt;br /&gt;
 * under the License.&lt;br /&gt;
 *&lt;br /&gt;
 * Copyright (C) OpenMRS, LLC.  All Rights Reserved.&lt;br /&gt;
 */&lt;br /&gt;
package org.openmrs.module.updatecss;&lt;br /&gt;
&lt;br /&gt;
import java.io.Serializable;&lt;br /&gt;
import org.openmrs.BaseOpenmrsObject;&lt;br /&gt;
import org.openmrs.BaseOpenmrsMetadata;&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * It is a model class. It should extend either {@link BaseOpenmrsObject} or {@link BaseOpenmrsMetadata}.&lt;br /&gt;
 */&lt;br /&gt;
public class UpdateCSS extends BaseOpenmrsObject implements Serializable {&lt;br /&gt;
&lt;br /&gt;
	private static final long serialVersionUID = 1L;&lt;br /&gt;
	&lt;br /&gt;
	private Integer id;&lt;br /&gt;
	private String homeDirectory;&lt;br /&gt;
	private String cssData;&lt;br /&gt;
	&lt;br /&gt;
	@Override&lt;br /&gt;
	public Integer getId() {&lt;br /&gt;
		return id;&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	@Override&lt;br /&gt;
	public void setId(Integer id) {&lt;br /&gt;
		this.id = id;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	public String getHomeDirectory() {&lt;br /&gt;
		return homeDirectory;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	public void setHomeDirectory(String homeDirectory) {&lt;br /&gt;
		this.homeDirectory = homeDirectory;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	public String getCssData() {&lt;br /&gt;
		return cssData;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	public void setCssData(String cssData) {&lt;br /&gt;
		this.cssData = cssData;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''UpdateCSSDAO.java/HibernateUpdateCSSDAO.java'''&lt;br /&gt;
The DAO files carry the primary responsibility of interaction with the DB layer in the MVC architecture.&amp;lt;br&amp;gt;&lt;br /&gt;
The data layer changes involved 3 separate components:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. liquibase.xml file to configure our new table: css_properties&amp;lt;br&amp;gt;&lt;br /&gt;
2. UpdateCSSDAO.java/HibernateUpdateCSSDAO.java - Interface/Implementation for DAO getter/setter.&amp;lt;br&amp;gt;&lt;br /&gt;
3. UpdateCSS.hbm.xml - Hibernate configuration file for mapping DAO to new properties table.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''liquibase.xml''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Liquibase&amp;lt;ref&amp;gt;http://www.liquibase.org/documentation/&amp;lt;/ref&amp;gt; is a method for automatically generating database changes at module startup.  We used this to add&amp;lt;br&amp;gt;&lt;br /&gt;
our new css_properties table.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    &amp;lt;changeSet id=&amp;quot;updatecss-2013-04-22-26:00&amp;quot; author=&amp;quot;yurijeffroshnajon&amp;quot; runOnChange=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
     	&amp;lt;preConditions onFail=&amp;quot;MARK_RAN&amp;quot;&amp;gt;&lt;br /&gt;
             &amp;lt;not&amp;gt;&amp;lt;tableExists tableName=&amp;quot;css_properties&amp;quot;/&amp;gt;&amp;lt;/not&amp;gt;&lt;br /&gt;
        &amp;lt;/preConditions&amp;gt;&lt;br /&gt;
        &amp;lt;comment&amp;gt;&lt;br /&gt;
             Create the css_properties table&lt;br /&gt;
        &amp;lt;/comment&amp;gt;&lt;br /&gt;
        &amp;lt;createTable tableName=&amp;quot;css_properties&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;column name=&amp;quot;id&amp;quot; type=&amp;quot;int&amp;quot; autoIncrement=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;constraints primaryKey=&amp;quot;true&amp;quot; nullable=&amp;quot;false&amp;quot;/&amp;gt;&lt;br /&gt;
            &amp;lt;/column&amp;gt;&lt;br /&gt;
            &amp;lt;column name=&amp;quot;css_location&amp;quot; type=&amp;quot;longtext&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;constraints nullable=&amp;quot;false&amp;quot;/&amp;gt;&lt;br /&gt;
            &amp;lt;/column&amp;gt;&lt;br /&gt;
            &amp;lt;column name=&amp;quot;tomcat_home&amp;quot; type=&amp;quot;varchar(255)&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;constraints nullable=&amp;quot;false&amp;quot;/&amp;gt;&lt;br /&gt;
            &amp;lt;/column&amp;gt;&lt;br /&gt;
        &amp;lt;/createTable&amp;gt;&lt;br /&gt;
    &amp;lt;/changeSet&amp;gt; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
''Hibernate''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Hibernate&amp;lt;ref&amp;gt;http://www.hibernate.org/&amp;lt;/ref&amp;gt; is a POJO-based implementation used for database interaction without the need for SQL queries.&amp;lt;br&amp;gt;  Instead, by using some XML-based configuration files provided by the Hibernate framework, you can manipulate the&amp;lt;br&amp;gt;&lt;br /&gt;
database using only Java objects.  This is the mechanism we used for our database interaction.  Our sample config file:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;hibernate-mapping package=&amp;quot;org.openmrs.module.updatecss&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;class name=&amp;quot;UpdateCSS&amp;quot;&lt;br /&gt;
	table=&amp;quot;css_properties&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;id name=&amp;quot;id&amp;quot; type=&amp;quot;int&amp;quot; column=&amp;quot;id&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;generator class=&amp;quot;native&amp;quot;/&amp;gt;&lt;br /&gt;
        &amp;lt;/id&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;cssData&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;css_location&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;homeDirectory&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;tomcat_home&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/class&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/hibernate-mapping&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''UpdateCSSService.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
The interface for the UpdateCSSServiceImpl file described above.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSManageController.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
Our controller utilized in the MVC pattern.  We modified this file to initialize our main web page and populate it&amp;lt;br&amp;gt;&lt;br /&gt;
with our existing configuration record.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	//this method creates an UpdateCSS object the first time this controller is loaded&lt;br /&gt;
	@ModelAttribute(&amp;quot;updateCSS&amp;quot;)&lt;br /&gt;
	public UpdateCSS getPatientSearchObject(){&lt;br /&gt;
		UpdateCSSService cssService = Context.getService(UpdateCSSService.class);&lt;br /&gt;
		UpdateCSS currCSS = cssService.getData();&lt;br /&gt;
		&lt;br /&gt;
		if (currCSS == null) {&lt;br /&gt;
			UpdateCSS newCSS = new UpdateCSS();&lt;br /&gt;
			newCSS.setHomeDirectory(System.getProperty(&amp;quot;catalina.base&amp;quot;) + &amp;quot;\\webapps\\openmrs-standalone\\style.css&amp;quot;);&lt;br /&gt;
			newCSS.setCssData(cssService.getCssTextFromFile(newCSS.getHomeDirectory()));&lt;br /&gt;
			return newCSS;&lt;br /&gt;
		} else {&lt;br /&gt;
			return currCSS;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517/M601_Design_Document&amp;diff=75211</id>
		<title>CSC/ECE 517/M601 Design Document</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517/M601_Design_Document&amp;diff=75211"/>
		<updated>2013-04-27T12:40:52Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: /* Specific Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;h1&amp;gt;Add ability to update css through webapp&amp;lt;/h1&amp;gt;&lt;br /&gt;
== Example Video ==&lt;br /&gt;
A video example of this module can be seen here [http://youtu.be/2dQeFYjcsnU]&lt;br /&gt;
==Team== &lt;br /&gt;
Yuri Kolesnikov &amp;lt;br&amp;gt;&lt;br /&gt;
Jonathan Wills &amp;lt;br&amp;gt;&lt;br /&gt;
Jeffrey Plemmons &amp;lt;br&amp;gt;&lt;br /&gt;
Roshna Agarwal&lt;br /&gt;
&lt;br /&gt;
==Our Work==&lt;br /&gt;
Link to the OpenMRS ticket: https://tickets.openmrs.org/browse/TRUNK-3415&amp;lt;br&amp;gt;&lt;br /&gt;
Link to our code in GitHub: https://github.com/ykolesn/openmrs-module-m601 &amp;lt;br&amp;gt;&lt;br /&gt;
Link to application: http://152.46.17.228:8081/openmrs-standalone&lt;br /&gt;
&lt;br /&gt;
==Purpose==&lt;br /&gt;
	The purpose of this module is to add the functionality of allowing the admin to customize the OpenMRS css file to their own specifications. By having the ability to customize the OpenMRS css file, the admin will be free to change the look and feel in their installation of OpenMRS.&lt;br /&gt;
&lt;br /&gt;
==Problem Definition==&lt;br /&gt;
	Add admin page for customization of the openmrs css file. Admins can 'override' any openmrs css with their own file by specifying that file in the openmrs runtime properties file.&lt;br /&gt;
This would be best as a new module in openmrs or perhaps just adding a new feature in the Custom Logo module? The admin should see a page with a large text box. The text box value should be persisted in the database as a new object/table/column somehow. When the module starts up, the Activator is called. Modify the activator to update the filesystem css file with whatever is defined by the admin.&lt;br /&gt;
&lt;br /&gt;
==Design Requirements==&lt;br /&gt;
&lt;br /&gt;
1. The admin should be able to customize the openmrs css file through an admin page. &amp;lt;br&amp;gt;&lt;br /&gt;
2. The admin should see a page with a large text box. &amp;lt;br&amp;gt;&lt;br /&gt;
3. The text box content should be stored in the database. &amp;lt;br&amp;gt;&lt;br /&gt;
4. The activator needs to be modified so that it updates the filesystem css file with whatever is defined by the admin. &amp;lt;br&amp;gt;&lt;br /&gt;
5. Need to use Eclipse and Maven as development tools for the module. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
'''Week 1'''&lt;br /&gt;
&lt;br /&gt;
*Get OpenMRS Id&lt;br /&gt;
*Get ticket assigned and in progress&lt;br /&gt;
*Get openmrs module name assigned&lt;br /&gt;
*Create openmrs module&lt;br /&gt;
*Commit module to github&lt;br /&gt;
*Check out module on partner machines&lt;br /&gt;
*Get new admin page link&lt;br /&gt;
*Create new spring controller and jsp page&lt;br /&gt;
'''Week 2'''&lt;br /&gt;
&lt;br /&gt;
*Create object for storing css in db&lt;br /&gt;
*Create service layer and dao layer methods to save object&lt;br /&gt;
*Connect controller to db object for saving + retrieving&lt;br /&gt;
*Add unit tests for saving/retrieving&lt;br /&gt;
'''Week 3'''&lt;br /&gt;
&lt;br /&gt;
*Create settings page to allow admin to choose where tomcat is running&lt;br /&gt;
*Add some magic so that module tries to guess where tomcat is running&lt;br /&gt;
*Add ability to put the saved css into the right folder in tomcat so that the css is actually overriding the openmrs style.css file.&lt;br /&gt;
&lt;br /&gt;
==Development Tools==&lt;br /&gt;
1. '''Eclipse'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Integrated_development_environment&amp;lt;/ref&amp;gt;: Eclipse is the Integrated Development Environment used to develop, modify, and compile the code for our module. &amp;lt;br&amp;gt;&lt;br /&gt;
2. '''Maven'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Maven&amp;lt;/ref&amp;gt;: Maven is used through a plug-in in Eclipse to compile, run unit tests, and package all of the Java files in the module.  &amp;lt;br&amp;gt;&lt;br /&gt;
3. '''Tomcat'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Tomcat&amp;lt;/ref&amp;gt;: Tomcat is the web-server used to run the application. &amp;lt;br&amp;gt; &lt;br /&gt;
4. '''Hibernate'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Hibernate_(Java)&amp;lt;/ref&amp;gt;: Hibernate is a built-in utility in the OpenMRS module, that is used to connect the Java classes to the database tables in the application. It configured the database table through an xml file: UpdateCSS.hbm.xml&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE hibernate-mapping PUBLIC&lt;br /&gt;
    &amp;quot;-//Hibernate/Hibernate Mapping DTD 3.0//EN&amp;quot;&lt;br /&gt;
    &amp;quot;http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&amp;quot; &amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hibernate-mapping package=&amp;quot;org.openmrs.module.updatecss&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;class name=&amp;quot;UpdateCSS&amp;quot;&lt;br /&gt;
	table=&amp;quot;css_properties&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;id name=&amp;quot;id&amp;quot; type=&amp;quot;int&amp;quot; column=&amp;quot;id&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;generator class=&amp;quot;native&amp;quot;/&amp;gt;&lt;br /&gt;
        &amp;lt;/id&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;cssData&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;css_location&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;homeDirectory&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;tomcat_home&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/class&amp;gt;&lt;br /&gt;
&amp;lt;/hibernate-mapping&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
''Here in the UpdateCSS.hbm.xml we specify the table name and columns. Hibernate generates the table with the fields specified and handles all the necessary SQL calls and queries.''&amp;lt;br&amp;gt;&lt;br /&gt;
5. '''MySQL''': MySQL&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Mysql&amp;lt;/ref&amp;gt; is the RDBMS that is used to store the CSS data for the application.&lt;br /&gt;
&lt;br /&gt;
==Use Case==&lt;br /&gt;
[[File:Openmrsui.png|800px|alt=OpenMRS UI]]&amp;lt;br&amp;gt;&lt;br /&gt;
''This is the user interface for the UpdateCSS module. The initial start screen provides a default location for the css style sheet and default css code. Here the navigation bar is changed to &amp;quot;orange&amp;quot;. ''&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
1. Log in to the Admin page with user &amp;quot;Admin&amp;quot; and password &amp;quot;Admin123&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
2. Once logged in, click on &amp;quot;Administration&amp;quot; on the right-hand side of the navigation bar. &amp;lt;br&amp;gt;&lt;br /&gt;
3. Under &amp;quot;Update CSS Module&amp;quot;, click on &amp;quot;Manage module&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
4. Here the user can enter their desired CSS preferences for customization. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Application Overview==&lt;br /&gt;
[[File:Overview.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt;Code Changes&amp;lt;/h1&amp;gt;&lt;br /&gt;
==Classes and Files Worked On==&lt;br /&gt;
* UpdateCSSActivator.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSS.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSService.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSServiceImpl.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSDAO.java &amp;lt;br&amp;gt;&lt;br /&gt;
* HibernateUpdateCSSDAO.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSS.hbm.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* liquibase.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* moduleApplicationContext.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSServiceTest.java &amp;lt;br&amp;gt;&lt;br /&gt;
* manage.jsp &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSManageController.java &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Specific Changes==&lt;br /&gt;
'''UpdateCSSActivator.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSServiceImpl.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
Added below methods to UpdateCSSServiceImpl class: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  /**&lt;br /&gt;
+   * Replaces the text of the specified CSS file in the&lt;br /&gt;
+   * specified directory with the specified text&lt;br /&gt;
+   */ +  public void copyCssDataToTomcatDirectory(String directory, String cssText) {&lt;br /&gt;
+    File cssFile = new File(directory);&lt;br /&gt;
+    if (cssFile.exists()) {&lt;br /&gt;
+      writeDataToFile(cssFile, cssText);&lt;br /&gt;
+    }&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Copies the data stored in the DB into the CSS file that is saved in the &lt;br /&gt;
+   * directory column of the css_properties table&lt;br /&gt;
+   */&lt;br /&gt;
+  public void copyCssDataToTomcatDirectory() {&lt;br /&gt;
+    UpdateCSS updateCSS = getData();&lt;br /&gt;
+    String cssDirectory = updateCSS.getHomeDirectory();&lt;br /&gt;
+    String cssText = updateCSS.getCssData();&lt;br /&gt;
+    copyCssDataToTomcatDirectory(cssDirectory, cssText);&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Writes the specified text to the specified CSS file&lt;br /&gt;
+   */&lt;br /&gt;
+  public void writeDataToFile(File cssFile, String cssText) {&lt;br /&gt;
+    try {&lt;br /&gt;
+      if (cssFile.exists()) {&lt;br /&gt;
+        PrintWriter writer = new PrintWriter(cssFile);&lt;br /&gt;
+        writer.print(cssText);&lt;br /&gt;
+        writer.close();&lt;br /&gt;
+      }&lt;br /&gt;
+    } catch (FileNotFoundException ex) {&lt;br /&gt;
+      &lt;br /&gt;
+    }&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Reads the data in the file at the specified path and returns&lt;br /&gt;
+   * a String with the contents. If the file doesn't exist&lt;br /&gt;
+   * then it returns an empty string&lt;br /&gt;
+   */&lt;br /&gt;
+  public String getCssTextFromFile(String filePath) {&lt;br /&gt;
+    String cssText = &amp;quot;&amp;quot;;&lt;br /&gt;
+    try {&lt;br /&gt;
+      File cssFile = new File(filePath);&lt;br /&gt;
+      if (cssFile.exists()) {&lt;br /&gt;
+        cssText = FileUtils.readFileToString(cssFile);&lt;br /&gt;
+      }  &lt;br /&gt;
+    } catch (IOException ex) {&lt;br /&gt;
+    &lt;br /&gt;
+    }&lt;br /&gt;
+    return cssText;&lt;br /&gt;
+  }&lt;br /&gt;
+    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''UpdateCSS.java:''' &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Our model portion of the MVC pattern.  This Java POJO represents the database record we are storing&amp;lt;br&amp;gt;&lt;br /&gt;
to update/get CSS configuration setting.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/**&lt;br /&gt;
 * The contents of this file are subject to the OpenMRS Public License&lt;br /&gt;
 * Version 1.0 (the &amp;quot;License&amp;quot;); you may not use this file except in&lt;br /&gt;
 * compliance with the License. You may obtain a copy of the License at&lt;br /&gt;
 * http://license.openmrs.org&lt;br /&gt;
 *&lt;br /&gt;
 * Software distributed under the License is distributed on an &amp;quot;AS IS&amp;quot;&lt;br /&gt;
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the&lt;br /&gt;
 * License for the specific language governing rights and limitations&lt;br /&gt;
 * under the License.&lt;br /&gt;
 *&lt;br /&gt;
 * Copyright (C) OpenMRS, LLC.  All Rights Reserved.&lt;br /&gt;
 */&lt;br /&gt;
package org.openmrs.module.updatecss;&lt;br /&gt;
&lt;br /&gt;
import java.io.Serializable;&lt;br /&gt;
import org.openmrs.BaseOpenmrsObject;&lt;br /&gt;
import org.openmrs.BaseOpenmrsMetadata;&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * It is a model class. It should extend either {@link BaseOpenmrsObject} or {@link BaseOpenmrsMetadata}.&lt;br /&gt;
 */&lt;br /&gt;
public class UpdateCSS extends BaseOpenmrsObject implements Serializable {&lt;br /&gt;
&lt;br /&gt;
	private static final long serialVersionUID = 1L;&lt;br /&gt;
	&lt;br /&gt;
	private Integer id;&lt;br /&gt;
	private String homeDirectory;&lt;br /&gt;
	private String cssData;&lt;br /&gt;
	&lt;br /&gt;
	@Override&lt;br /&gt;
	public Integer getId() {&lt;br /&gt;
		return id;&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	@Override&lt;br /&gt;
	public void setId(Integer id) {&lt;br /&gt;
		this.id = id;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	public String getHomeDirectory() {&lt;br /&gt;
		return homeDirectory;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	public void setHomeDirectory(String homeDirectory) {&lt;br /&gt;
		this.homeDirectory = homeDirectory;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	public String getCssData() {&lt;br /&gt;
		return cssData;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	public void setCssData(String cssData) {&lt;br /&gt;
		this.cssData = cssData;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''UpdateCSSDAO.java/HibernateUpdateCSSDAO.java'''&lt;br /&gt;
The DAO files carry the primary responsibility of interaction with the DB layer in the MVC architecture.&amp;lt;br&amp;gt;&lt;br /&gt;
The data layer changes involved 3 separate components:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. liquibase.xml file to configure our new table: css_properties&amp;lt;br&amp;gt;&lt;br /&gt;
2. UpdateCSSDAO.java/HibernateUpdateCSSDAO.java - Interface/Implementation for DAO getter/setter.&amp;lt;br&amp;gt;&lt;br /&gt;
3. UpdateCSS.hbm.xml - Hibernate configuration file for mapping DAO to new properties table.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''liquibase.xml''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Liquibase&amp;lt;ref&amp;gt;http://www.liquibase.org/documentation/&amp;lt;/ref&amp;gt; is a method for automatically generating database changes at module startup.  We used this to add&amp;lt;br&amp;gt;&lt;br /&gt;
our new css_properties table.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    &amp;lt;changeSet id=&amp;quot;updatecss-2013-04-22-26:00&amp;quot; author=&amp;quot;yurijeffroshnajon&amp;quot; runOnChange=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
     	&amp;lt;preConditions onFail=&amp;quot;MARK_RAN&amp;quot;&amp;gt;&lt;br /&gt;
             &amp;lt;not&amp;gt;&amp;lt;tableExists tableName=&amp;quot;css_properties&amp;quot;/&amp;gt;&amp;lt;/not&amp;gt;&lt;br /&gt;
        &amp;lt;/preConditions&amp;gt;&lt;br /&gt;
        &amp;lt;comment&amp;gt;&lt;br /&gt;
             Create the css_properties table&lt;br /&gt;
        &amp;lt;/comment&amp;gt;&lt;br /&gt;
        &amp;lt;createTable tableName=&amp;quot;css_properties&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;column name=&amp;quot;id&amp;quot; type=&amp;quot;int&amp;quot; autoIncrement=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;constraints primaryKey=&amp;quot;true&amp;quot; nullable=&amp;quot;false&amp;quot;/&amp;gt;&lt;br /&gt;
            &amp;lt;/column&amp;gt;&lt;br /&gt;
            &amp;lt;column name=&amp;quot;css_location&amp;quot; type=&amp;quot;longtext&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;constraints nullable=&amp;quot;false&amp;quot;/&amp;gt;&lt;br /&gt;
            &amp;lt;/column&amp;gt;&lt;br /&gt;
            &amp;lt;column name=&amp;quot;tomcat_home&amp;quot; type=&amp;quot;varchar(255)&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;constraints nullable=&amp;quot;false&amp;quot;/&amp;gt;&lt;br /&gt;
            &amp;lt;/column&amp;gt;&lt;br /&gt;
        &amp;lt;/createTable&amp;gt;&lt;br /&gt;
    &amp;lt;/changeSet&amp;gt; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
''Hibernate''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Hibernate&amp;lt;ref&amp;gt;http://www.hibernate.org/&amp;lt;/ref&amp;gt; is a POJO-based implementation used for database interaction without the need for SQL queries.&amp;lt;br&amp;gt;  Instead, by using some XML-based configuration files provided by the Hibernate framework, you can manipulate the&amp;lt;br&amp;gt;&lt;br /&gt;
database using only Java objects.  This is the mechanism we used for our database interaction.  Our sample config file:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;hibernate-mapping package=&amp;quot;org.openmrs.module.updatecss&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;class name=&amp;quot;UpdateCSS&amp;quot;&lt;br /&gt;
	table=&amp;quot;css_properties&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;id name=&amp;quot;id&amp;quot; type=&amp;quot;int&amp;quot; column=&amp;quot;id&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;generator class=&amp;quot;native&amp;quot;/&amp;gt;&lt;br /&gt;
        &amp;lt;/id&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;cssData&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;css_location&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;homeDirectory&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;tomcat_home&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/class&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/hibernate-mapping&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''UpdateCSSService.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
The interface for the UpdateCSSServiceImpl file described above.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSManageController.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
Our controller utilized in the MVC pattern.  We modified this file to initialize our main web page and populate it&amp;lt;br&amp;gt;&lt;br /&gt;
with our existing configuration record.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	//this method creates an UpdateCSS object the first time this controller is loaded&lt;br /&gt;
	@ModelAttribute(&amp;quot;updateCSS&amp;quot;)&lt;br /&gt;
	public UpdateCSS getPatientSearchObject(){&lt;br /&gt;
		UpdateCSSService cssService = Context.getService(UpdateCSSService.class);&lt;br /&gt;
		UpdateCSS currCSS = cssService.getData();&lt;br /&gt;
		&lt;br /&gt;
		if (currCSS == null) {&lt;br /&gt;
			UpdateCSS newCSS = new UpdateCSS();&lt;br /&gt;
			newCSS.setHomeDirectory(System.getProperty(&amp;quot;catalina.base&amp;quot;) + &amp;quot;\\webapps\\openmrs-standalone\\style.css&amp;quot;);&lt;br /&gt;
			newCSS.setCssData(cssService.getCssTextFromFile(newCSS.getHomeDirectory()));&lt;br /&gt;
			return newCSS;&lt;br /&gt;
		} else {&lt;br /&gt;
			return currCSS;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517/M601_Design_Document&amp;diff=75210</id>
		<title>CSC/ECE 517/M601 Design Document</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517/M601_Design_Document&amp;diff=75210"/>
		<updated>2013-04-27T12:38:33Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: /* Specific Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;h1&amp;gt;Add ability to update css through webapp&amp;lt;/h1&amp;gt;&lt;br /&gt;
== Example Video ==&lt;br /&gt;
A video example of this module can be seen here [http://youtu.be/2dQeFYjcsnU]&lt;br /&gt;
==Team== &lt;br /&gt;
Yuri Kolesnikov &amp;lt;br&amp;gt;&lt;br /&gt;
Jonathan Wills &amp;lt;br&amp;gt;&lt;br /&gt;
Jeffrey Plemmons &amp;lt;br&amp;gt;&lt;br /&gt;
Roshna Agarwal&lt;br /&gt;
&lt;br /&gt;
==Our Work==&lt;br /&gt;
Link to the OpenMRS ticket: https://tickets.openmrs.org/browse/TRUNK-3415&amp;lt;br&amp;gt;&lt;br /&gt;
Link to our code in GitHub: https://github.com/ykolesn/openmrs-module-m601 &amp;lt;br&amp;gt;&lt;br /&gt;
Link to application: http://152.46.17.228:8081/openmrs-standalone&lt;br /&gt;
&lt;br /&gt;
==Purpose==&lt;br /&gt;
	The purpose of this module is to add the functionality of allowing the admin to customize the OpenMRS css file to their own specifications. By having the ability to customize the OpenMRS css file, the admin will be free to change the look and feel in their installation of OpenMRS.&lt;br /&gt;
&lt;br /&gt;
==Problem Definition==&lt;br /&gt;
	Add admin page for customization of the openmrs css file. Admins can 'override' any openmrs css with their own file by specifying that file in the openmrs runtime properties file.&lt;br /&gt;
This would be best as a new module in openmrs or perhaps just adding a new feature in the Custom Logo module? The admin should see a page with a large text box. The text box value should be persisted in the database as a new object/table/column somehow. When the module starts up, the Activator is called. Modify the activator to update the filesystem css file with whatever is defined by the admin.&lt;br /&gt;
&lt;br /&gt;
==Design Requirements==&lt;br /&gt;
&lt;br /&gt;
1. The admin should be able to customize the openmrs css file through an admin page. &amp;lt;br&amp;gt;&lt;br /&gt;
2. The admin should see a page with a large text box. &amp;lt;br&amp;gt;&lt;br /&gt;
3. The text box content should be stored in the database. &amp;lt;br&amp;gt;&lt;br /&gt;
4. The activator needs to be modified so that it updates the filesystem css file with whatever is defined by the admin. &amp;lt;br&amp;gt;&lt;br /&gt;
5. Need to use Eclipse and Maven as development tools for the module. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
'''Week 1'''&lt;br /&gt;
&lt;br /&gt;
*Get OpenMRS Id&lt;br /&gt;
*Get ticket assigned and in progress&lt;br /&gt;
*Get openmrs module name assigned&lt;br /&gt;
*Create openmrs module&lt;br /&gt;
*Commit module to github&lt;br /&gt;
*Check out module on partner machines&lt;br /&gt;
*Get new admin page link&lt;br /&gt;
*Create new spring controller and jsp page&lt;br /&gt;
'''Week 2'''&lt;br /&gt;
&lt;br /&gt;
*Create object for storing css in db&lt;br /&gt;
*Create service layer and dao layer methods to save object&lt;br /&gt;
*Connect controller to db object for saving + retrieving&lt;br /&gt;
*Add unit tests for saving/retrieving&lt;br /&gt;
'''Week 3'''&lt;br /&gt;
&lt;br /&gt;
*Create settings page to allow admin to choose where tomcat is running&lt;br /&gt;
*Add some magic so that module tries to guess where tomcat is running&lt;br /&gt;
*Add ability to put the saved css into the right folder in tomcat so that the css is actually overriding the openmrs style.css file.&lt;br /&gt;
&lt;br /&gt;
==Development Tools==&lt;br /&gt;
1. '''Eclipse'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Integrated_development_environment&amp;lt;/ref&amp;gt;: Eclipse is the Integrated Development Environment used to develop, modify, and compile the code for our module. &amp;lt;br&amp;gt;&lt;br /&gt;
2. '''Maven'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Maven&amp;lt;/ref&amp;gt;: Maven is used through a plug-in in Eclipse to compile, run unit tests, and package all of the Java files in the module.  &amp;lt;br&amp;gt;&lt;br /&gt;
3. '''Tomcat'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Tomcat&amp;lt;/ref&amp;gt;: Tomcat is the web-server used to run the application. &amp;lt;br&amp;gt; &lt;br /&gt;
4. '''Hibernate'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Hibernate_(Java)&amp;lt;/ref&amp;gt;: Hibernate is a built-in utility in the OpenMRS module, that is used to connect the Java classes to the database tables in the application. It configured the database table through an xml file: UpdateCSS.hbm.xml&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE hibernate-mapping PUBLIC&lt;br /&gt;
    &amp;quot;-//Hibernate/Hibernate Mapping DTD 3.0//EN&amp;quot;&lt;br /&gt;
    &amp;quot;http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&amp;quot; &amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hibernate-mapping package=&amp;quot;org.openmrs.module.updatecss&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;class name=&amp;quot;UpdateCSS&amp;quot;&lt;br /&gt;
	table=&amp;quot;css_properties&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;id name=&amp;quot;id&amp;quot; type=&amp;quot;int&amp;quot; column=&amp;quot;id&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;generator class=&amp;quot;native&amp;quot;/&amp;gt;&lt;br /&gt;
        &amp;lt;/id&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;cssData&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;css_location&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;homeDirectory&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;tomcat_home&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/class&amp;gt;&lt;br /&gt;
&amp;lt;/hibernate-mapping&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
''Here in the UpdateCSS.hbm.xml we specify the table name and columns. Hibernate generates the table with the fields specified and handles all the necessary SQL calls and queries.''&amp;lt;br&amp;gt;&lt;br /&gt;
5. '''MySQL''': MySQL&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Mysql&amp;lt;/ref&amp;gt; is the RDBMS that is used to store the CSS data for the application.&lt;br /&gt;
&lt;br /&gt;
==Use Case==&lt;br /&gt;
[[File:Openmrsui.png|800px|alt=OpenMRS UI]]&amp;lt;br&amp;gt;&lt;br /&gt;
''This is the user interface for the UpdateCSS module. The initial start screen provides a default location for the css style sheet and default css code. Here the navigation bar is changed to &amp;quot;orange&amp;quot;. ''&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
1. Log in to the Admin page with user &amp;quot;Admin&amp;quot; and password &amp;quot;Admin123&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
2. Once logged in, click on &amp;quot;Administration&amp;quot; on the right-hand side of the navigation bar. &amp;lt;br&amp;gt;&lt;br /&gt;
3. Under &amp;quot;Update CSS Module&amp;quot;, click on &amp;quot;Manage module&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
4. Here the user can enter their desired CSS preferences for customization. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Application Overview==&lt;br /&gt;
[[File:Overview.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt;Code Changes&amp;lt;/h1&amp;gt;&lt;br /&gt;
==Classes and Files Worked On==&lt;br /&gt;
* UpdateCSSActivator.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSS.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSService.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSServiceImpl.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSDAO.java &amp;lt;br&amp;gt;&lt;br /&gt;
* HibernateUpdateCSSDAO.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSS.hbm.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* liquibase.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* moduleApplicationContext.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSServiceTest.java &amp;lt;br&amp;gt;&lt;br /&gt;
* manage.jsp &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSManageController.java &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Specific Changes==&lt;br /&gt;
'''UpdateCSSActivator.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSServiceImpl.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
Added below methods to UpdateCSSServiceImpl class: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  /**&lt;br /&gt;
+   * Replaces the text of the specified CSS file in the&lt;br /&gt;
+   * specified directory with the specified text&lt;br /&gt;
+   */ +  public void copyCssDataToTomcatDirectory(String directory, String cssText) {&lt;br /&gt;
+    File cssFile = new File(directory);&lt;br /&gt;
+    if (cssFile.exists()) {&lt;br /&gt;
+      writeDataToFile(cssFile, cssText);&lt;br /&gt;
+    }&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Copies the data stored in the DB into the CSS file that is saved in the &lt;br /&gt;
+   * directory column of the css_properties table&lt;br /&gt;
+   */&lt;br /&gt;
+  public void copyCssDataToTomcatDirectory() {&lt;br /&gt;
+    UpdateCSS updateCSS = getData();&lt;br /&gt;
+    String cssDirectory = updateCSS.getHomeDirectory();&lt;br /&gt;
+    String cssText = updateCSS.getCssData();&lt;br /&gt;
+    copyCssDataToTomcatDirectory(cssDirectory, cssText);&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Writes the specified text to the specified CSS file&lt;br /&gt;
+   */&lt;br /&gt;
+  public void writeDataToFile(File cssFile, String cssText) {&lt;br /&gt;
+    try {&lt;br /&gt;
+      if (cssFile.exists()) {&lt;br /&gt;
+        PrintWriter writer = new PrintWriter(cssFile);&lt;br /&gt;
+        writer.print(cssText);&lt;br /&gt;
+        writer.close();&lt;br /&gt;
+      }&lt;br /&gt;
+    } catch (FileNotFoundException ex) {&lt;br /&gt;
+      &lt;br /&gt;
+    }&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Reads the data in the file at the specified path and returns&lt;br /&gt;
+   * a String with the contents. If the file doesn't exist&lt;br /&gt;
+   * then it returns an empty string&lt;br /&gt;
+   */&lt;br /&gt;
+  public String getCssTextFromFile(String filePath) {&lt;br /&gt;
+    String cssText = &amp;quot;&amp;quot;;&lt;br /&gt;
+    try {&lt;br /&gt;
+      File cssFile = new File(filePath);&lt;br /&gt;
+      if (cssFile.exists()) {&lt;br /&gt;
+        cssText = FileUtils.readFileToString(cssFile);&lt;br /&gt;
+      }  &lt;br /&gt;
+    } catch (IOException ex) {&lt;br /&gt;
+    &lt;br /&gt;
+    }&lt;br /&gt;
+    return cssText;&lt;br /&gt;
+  }&lt;br /&gt;
+    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''UpdateCSS.java:''' &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSDAO.java/HibernateUpdateCSSDAO.java'''&lt;br /&gt;
The DAO files carry the primary responsibility of interaction with the DB layer in the MVC architecture.&amp;lt;br&amp;gt;&lt;br /&gt;
The data layer changes involved 3 separate components:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. liquibase.xml file to configure our new table: css_properties&amp;lt;br&amp;gt;&lt;br /&gt;
2. UpdateCSSDAO.java/HibernateUpdateCSSDAO.java - Interface/Implementation for DAO getter/setter.&amp;lt;br&amp;gt;&lt;br /&gt;
3. UpdateCSS.hbm.xml - Hibernate configuration file for mapping DAO to new properties table.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''liquibase.xml''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Liquibase&amp;lt;ref&amp;gt;http://www.liquibase.org/documentation/&amp;lt;/ref&amp;gt; is a method for automatically generating database changes at module startup.  We used this to add&amp;lt;br&amp;gt;&lt;br /&gt;
our new css_properties table.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    &amp;lt;changeSet id=&amp;quot;updatecss-2013-04-22-26:00&amp;quot; author=&amp;quot;yurijeffroshnajon&amp;quot; runOnChange=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
     	&amp;lt;preConditions onFail=&amp;quot;MARK_RAN&amp;quot;&amp;gt;&lt;br /&gt;
             &amp;lt;not&amp;gt;&amp;lt;tableExists tableName=&amp;quot;css_properties&amp;quot;/&amp;gt;&amp;lt;/not&amp;gt;&lt;br /&gt;
        &amp;lt;/preConditions&amp;gt;&lt;br /&gt;
        &amp;lt;comment&amp;gt;&lt;br /&gt;
             Create the css_properties table&lt;br /&gt;
        &amp;lt;/comment&amp;gt;&lt;br /&gt;
        &amp;lt;createTable tableName=&amp;quot;css_properties&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;column name=&amp;quot;id&amp;quot; type=&amp;quot;int&amp;quot; autoIncrement=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;constraints primaryKey=&amp;quot;true&amp;quot; nullable=&amp;quot;false&amp;quot;/&amp;gt;&lt;br /&gt;
            &amp;lt;/column&amp;gt;&lt;br /&gt;
            &amp;lt;column name=&amp;quot;css_location&amp;quot; type=&amp;quot;longtext&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;constraints nullable=&amp;quot;false&amp;quot;/&amp;gt;&lt;br /&gt;
            &amp;lt;/column&amp;gt;&lt;br /&gt;
            &amp;lt;column name=&amp;quot;tomcat_home&amp;quot; type=&amp;quot;varchar(255)&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;constraints nullable=&amp;quot;false&amp;quot;/&amp;gt;&lt;br /&gt;
            &amp;lt;/column&amp;gt;&lt;br /&gt;
        &amp;lt;/createTable&amp;gt;&lt;br /&gt;
    &amp;lt;/changeSet&amp;gt; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
''Hibernate''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Hibernate&amp;lt;ref&amp;gt;http://www.hibernate.org/&amp;lt;/ref&amp;gt; is a POJO-based implementation used for database interaction without the need for SQL queries.&amp;lt;br&amp;gt;  Instead, by using some XML-based configuration files provided by the Hibernate framework, you can manipulate the&amp;lt;br&amp;gt;&lt;br /&gt;
database using only Java objects.  This is the mechanism we used for our database interaction.  Our sample config file:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;hibernate-mapping package=&amp;quot;org.openmrs.module.updatecss&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;class name=&amp;quot;UpdateCSS&amp;quot;&lt;br /&gt;
	table=&amp;quot;css_properties&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;id name=&amp;quot;id&amp;quot; type=&amp;quot;int&amp;quot; column=&amp;quot;id&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;generator class=&amp;quot;native&amp;quot;/&amp;gt;&lt;br /&gt;
        &amp;lt;/id&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;cssData&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;css_location&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;homeDirectory&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;tomcat_home&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/class&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/hibernate-mapping&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''UpdateCSSService.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
The interface for the UpdateCSSServiceImpl file described above.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSManageController.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
Our controller utilized in the MVC pattern.  We modified this file to initialize our main web page and populate it&amp;lt;br&amp;gt;&lt;br /&gt;
with our existing configuration record.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	//this method creates an UpdateCSS object the first time this controller is loaded&lt;br /&gt;
	@ModelAttribute(&amp;quot;updateCSS&amp;quot;)&lt;br /&gt;
	public UpdateCSS getPatientSearchObject(){&lt;br /&gt;
		UpdateCSSService cssService = Context.getService(UpdateCSSService.class);&lt;br /&gt;
		UpdateCSS currCSS = cssService.getData();&lt;br /&gt;
		&lt;br /&gt;
		if (currCSS == null) {&lt;br /&gt;
			UpdateCSS newCSS = new UpdateCSS();&lt;br /&gt;
			newCSS.setHomeDirectory(System.getProperty(&amp;quot;catalina.base&amp;quot;) + &amp;quot;\\webapps\\openmrs-standalone\\style.css&amp;quot;);&lt;br /&gt;
			newCSS.setCssData(cssService.getCssTextFromFile(newCSS.getHomeDirectory()));&lt;br /&gt;
			return newCSS;&lt;br /&gt;
		} else {&lt;br /&gt;
			return currCSS;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517/M601_Design_Document&amp;diff=75209</id>
		<title>CSC/ECE 517/M601 Design Document</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517/M601_Design_Document&amp;diff=75209"/>
		<updated>2013-04-27T12:35:28Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: /* Specific Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;h1&amp;gt;Add ability to update css through webapp&amp;lt;/h1&amp;gt;&lt;br /&gt;
== Example Video ==&lt;br /&gt;
A video example of this module can be seen here [http://youtu.be/2dQeFYjcsnU]&lt;br /&gt;
==Team== &lt;br /&gt;
Yuri Kolesnikov &amp;lt;br&amp;gt;&lt;br /&gt;
Jonathan Wills &amp;lt;br&amp;gt;&lt;br /&gt;
Jeffrey Plemmons &amp;lt;br&amp;gt;&lt;br /&gt;
Roshna Agarwal&lt;br /&gt;
&lt;br /&gt;
==Our Work==&lt;br /&gt;
Link to the OpenMRS ticket: https://tickets.openmrs.org/browse/TRUNK-3415&amp;lt;br&amp;gt;&lt;br /&gt;
Link to our code in GitHub: https://github.com/ykolesn/openmrs-module-m601 &amp;lt;br&amp;gt;&lt;br /&gt;
Link to application: http://152.46.17.228:8081/openmrs-standalone&lt;br /&gt;
&lt;br /&gt;
==Purpose==&lt;br /&gt;
	The purpose of this module is to add the functionality of allowing the admin to customize the OpenMRS css file to their own specifications. By having the ability to customize the OpenMRS css file, the admin will be free to change the look and feel in their installation of OpenMRS.&lt;br /&gt;
&lt;br /&gt;
==Problem Definition==&lt;br /&gt;
	Add admin page for customization of the openmrs css file. Admins can 'override' any openmrs css with their own file by specifying that file in the openmrs runtime properties file.&lt;br /&gt;
This would be best as a new module in openmrs or perhaps just adding a new feature in the Custom Logo module? The admin should see a page with a large text box. The text box value should be persisted in the database as a new object/table/column somehow. When the module starts up, the Activator is called. Modify the activator to update the filesystem css file with whatever is defined by the admin.&lt;br /&gt;
&lt;br /&gt;
==Design Requirements==&lt;br /&gt;
&lt;br /&gt;
1. The admin should be able to customize the openmrs css file through an admin page. &amp;lt;br&amp;gt;&lt;br /&gt;
2. The admin should see a page with a large text box. &amp;lt;br&amp;gt;&lt;br /&gt;
3. The text box content should be stored in the database. &amp;lt;br&amp;gt;&lt;br /&gt;
4. The activator needs to be modified so that it updates the filesystem css file with whatever is defined by the admin. &amp;lt;br&amp;gt;&lt;br /&gt;
5. Need to use Eclipse and Maven as development tools for the module. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
'''Week 1'''&lt;br /&gt;
&lt;br /&gt;
*Get OpenMRS Id&lt;br /&gt;
*Get ticket assigned and in progress&lt;br /&gt;
*Get openmrs module name assigned&lt;br /&gt;
*Create openmrs module&lt;br /&gt;
*Commit module to github&lt;br /&gt;
*Check out module on partner machines&lt;br /&gt;
*Get new admin page link&lt;br /&gt;
*Create new spring controller and jsp page&lt;br /&gt;
'''Week 2'''&lt;br /&gt;
&lt;br /&gt;
*Create object for storing css in db&lt;br /&gt;
*Create service layer and dao layer methods to save object&lt;br /&gt;
*Connect controller to db object for saving + retrieving&lt;br /&gt;
*Add unit tests for saving/retrieving&lt;br /&gt;
'''Week 3'''&lt;br /&gt;
&lt;br /&gt;
*Create settings page to allow admin to choose where tomcat is running&lt;br /&gt;
*Add some magic so that module tries to guess where tomcat is running&lt;br /&gt;
*Add ability to put the saved css into the right folder in tomcat so that the css is actually overriding the openmrs style.css file.&lt;br /&gt;
&lt;br /&gt;
==Development Tools==&lt;br /&gt;
1. '''Eclipse'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Integrated_development_environment&amp;lt;/ref&amp;gt;: Eclipse is the Integrated Development Environment used to develop, modify, and compile the code for our module. &amp;lt;br&amp;gt;&lt;br /&gt;
2. '''Maven'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Maven&amp;lt;/ref&amp;gt;: Maven is used through a plug-in in Eclipse to compile, run unit tests, and package all of the Java files in the module.  &amp;lt;br&amp;gt;&lt;br /&gt;
3. '''Tomcat'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Tomcat&amp;lt;/ref&amp;gt;: Tomcat is the web-server used to run the application. &amp;lt;br&amp;gt; &lt;br /&gt;
4. '''Hibernate'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Hibernate_(Java)&amp;lt;/ref&amp;gt;: Hibernate is a built-in utility in the OpenMRS module, that is used to connect the Java classes to the database tables in the application. It configured the database table through an xml file: UpdateCSS.hbm.xml&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE hibernate-mapping PUBLIC&lt;br /&gt;
    &amp;quot;-//Hibernate/Hibernate Mapping DTD 3.0//EN&amp;quot;&lt;br /&gt;
    &amp;quot;http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&amp;quot; &amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hibernate-mapping package=&amp;quot;org.openmrs.module.updatecss&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;class name=&amp;quot;UpdateCSS&amp;quot;&lt;br /&gt;
	table=&amp;quot;css_properties&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;id name=&amp;quot;id&amp;quot; type=&amp;quot;int&amp;quot; column=&amp;quot;id&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;generator class=&amp;quot;native&amp;quot;/&amp;gt;&lt;br /&gt;
        &amp;lt;/id&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;cssData&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;css_location&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;homeDirectory&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;tomcat_home&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/class&amp;gt;&lt;br /&gt;
&amp;lt;/hibernate-mapping&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
''Here in the UpdateCSS.hbm.xml we specify the table name and columns. Hibernate generates the table with the fields specified and handles all the necessary SQL calls and queries.''&amp;lt;br&amp;gt;&lt;br /&gt;
5. '''MySQL''': MySQL&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Mysql&amp;lt;/ref&amp;gt; is the RDBMS that is used to store the CSS data for the application.&lt;br /&gt;
&lt;br /&gt;
==Use Case==&lt;br /&gt;
[[File:Openmrsui.png|800px|alt=OpenMRS UI]]&amp;lt;br&amp;gt;&lt;br /&gt;
''This is the user interface for the UpdateCSS module. The initial start screen provides a default location for the css style sheet and default css code. Here the navigation bar is changed to &amp;quot;orange&amp;quot;. ''&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
1. Log in to the Admin page with user &amp;quot;Admin&amp;quot; and password &amp;quot;Admin123&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
2. Once logged in, click on &amp;quot;Administration&amp;quot; on the right-hand side of the navigation bar. &amp;lt;br&amp;gt;&lt;br /&gt;
3. Under &amp;quot;Update CSS Module&amp;quot;, click on &amp;quot;Manage module&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
4. Here the user can enter their desired CSS preferences for customization. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Application Overview==&lt;br /&gt;
[[File:Overview.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt;Code Changes&amp;lt;/h1&amp;gt;&lt;br /&gt;
==Classes and Files Worked On==&lt;br /&gt;
* UpdateCSSActivator.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSS.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSService.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSServiceImpl.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSDAO.java &amp;lt;br&amp;gt;&lt;br /&gt;
* HibernateUpdateCSSDAO.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSS.hbm.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* liquibase.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* moduleApplicationContext.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSServiceTest.java &amp;lt;br&amp;gt;&lt;br /&gt;
* manage.jsp &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSManageController.java &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Specific Changes==&lt;br /&gt;
'''UpdateCSSActivator.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSServiceImpl.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
Added below methods to UpdateCSSServiceImpl class: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  /**&lt;br /&gt;
+   * Replaces the text of the specified CSS file in the&lt;br /&gt;
+   * specified directory with the specified text&lt;br /&gt;
+   */ +  public void copyCssDataToTomcatDirectory(String directory, String cssText) {&lt;br /&gt;
+    File cssFile = new File(directory);&lt;br /&gt;
+    if (cssFile.exists()) {&lt;br /&gt;
+      writeDataToFile(cssFile, cssText);&lt;br /&gt;
+    }&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Copies the data stored in the DB into the CSS file that is saved in the &lt;br /&gt;
+   * directory column of the css_properties table&lt;br /&gt;
+   */&lt;br /&gt;
+  public void copyCssDataToTomcatDirectory() {&lt;br /&gt;
+    UpdateCSS updateCSS = getData();&lt;br /&gt;
+    String cssDirectory = updateCSS.getHomeDirectory();&lt;br /&gt;
+    String cssText = updateCSS.getCssData();&lt;br /&gt;
+    copyCssDataToTomcatDirectory(cssDirectory, cssText);&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Writes the specified text to the specified CSS file&lt;br /&gt;
+   */&lt;br /&gt;
+  public void writeDataToFile(File cssFile, String cssText) {&lt;br /&gt;
+    try {&lt;br /&gt;
+      if (cssFile.exists()) {&lt;br /&gt;
+        PrintWriter writer = new PrintWriter(cssFile);&lt;br /&gt;
+        writer.print(cssText);&lt;br /&gt;
+        writer.close();&lt;br /&gt;
+      }&lt;br /&gt;
+    } catch (FileNotFoundException ex) {&lt;br /&gt;
+      &lt;br /&gt;
+    }&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Reads the data in the file at the specified path and returns&lt;br /&gt;
+   * a String with the contents. If the file doesn't exist&lt;br /&gt;
+   * then it returns an empty string&lt;br /&gt;
+   */&lt;br /&gt;
+  public String getCssTextFromFile(String filePath) {&lt;br /&gt;
+    String cssText = &amp;quot;&amp;quot;;&lt;br /&gt;
+    try {&lt;br /&gt;
+      File cssFile = new File(filePath);&lt;br /&gt;
+      if (cssFile.exists()) {&lt;br /&gt;
+        cssText = FileUtils.readFileToString(cssFile);&lt;br /&gt;
+      }  &lt;br /&gt;
+    } catch (IOException ex) {&lt;br /&gt;
+    &lt;br /&gt;
+    }&lt;br /&gt;
+    return cssText;&lt;br /&gt;
+  }&lt;br /&gt;
+    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''UpdateCSS.java:''' &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSDAO.java/HibernateUpdateCSSDAO.java'''&lt;br /&gt;
The DAO files carry the primary responsibility of interaction with the DB layer in the MVC architecture.&amp;lt;br&amp;gt;&lt;br /&gt;
The data layer changes involved 3 separate components:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. liquibase.xml file to configure our new table: css_properties&amp;lt;br&amp;gt;&lt;br /&gt;
2. UpdateCSSDAO.java/HibernateUpdateCSSDAO.java - Interface/Implementation for DAO getter/setter.&amp;lt;br&amp;gt;&lt;br /&gt;
3. UpdateCSS.hbm.xml - Hibernate configuration file for mapping DAO to new properties table.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''liquibase.xml''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Liquibase&amp;lt;ref&amp;gt;http://www.liquibase.org/documentation/&amp;lt;/ref&amp;gt; is a method for automatically generating database changes at module startup.  We used this to add&amp;lt;br&amp;gt;&lt;br /&gt;
our new css_properties table.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    &amp;lt;changeSet id=&amp;quot;updatecss-2013-04-22-26:00&amp;quot; author=&amp;quot;yurijeffroshnajon&amp;quot; runOnChange=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
     	&amp;lt;preConditions onFail=&amp;quot;MARK_RAN&amp;quot;&amp;gt;&lt;br /&gt;
             &amp;lt;not&amp;gt;&amp;lt;tableExists tableName=&amp;quot;css_properties&amp;quot;/&amp;gt;&amp;lt;/not&amp;gt;&lt;br /&gt;
        &amp;lt;/preConditions&amp;gt;&lt;br /&gt;
        &amp;lt;comment&amp;gt;&lt;br /&gt;
             Create the css_properties table&lt;br /&gt;
        &amp;lt;/comment&amp;gt;&lt;br /&gt;
        &amp;lt;createTable tableName=&amp;quot;css_properties&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;column name=&amp;quot;id&amp;quot; type=&amp;quot;int&amp;quot; autoIncrement=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;constraints primaryKey=&amp;quot;true&amp;quot; nullable=&amp;quot;false&amp;quot;/&amp;gt;&lt;br /&gt;
            &amp;lt;/column&amp;gt;&lt;br /&gt;
            &amp;lt;column name=&amp;quot;css_location&amp;quot; type=&amp;quot;longtext&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;constraints nullable=&amp;quot;false&amp;quot;/&amp;gt;&lt;br /&gt;
            &amp;lt;/column&amp;gt;&lt;br /&gt;
            &amp;lt;column name=&amp;quot;tomcat_home&amp;quot; type=&amp;quot;varchar(255)&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;constraints nullable=&amp;quot;false&amp;quot;/&amp;gt;&lt;br /&gt;
            &amp;lt;/column&amp;gt;&lt;br /&gt;
        &amp;lt;/createTable&amp;gt;&lt;br /&gt;
    &amp;lt;/changeSet&amp;gt; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
''Hibernate''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Hibernate&amp;lt;ref&amp;gt;http://www.hibernate.org/&amp;lt;/ref&amp;gt; is a POJO-based implementation used for database interaction without the need for SQL queries.&amp;lt;br&amp;gt;  Instead, by using some XML-based configuration files provided by the Hibernate framework, you can manipulate the&amp;lt;br&amp;gt;&lt;br /&gt;
database using only Java objects.  This is the mechanism we used for our database interaction.  Our sample config file:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;hibernate-mapping package=&amp;quot;org.openmrs.module.updatecss&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;class name=&amp;quot;UpdateCSS&amp;quot;&lt;br /&gt;
	table=&amp;quot;css_properties&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;id name=&amp;quot;id&amp;quot; type=&amp;quot;int&amp;quot; column=&amp;quot;id&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;generator class=&amp;quot;native&amp;quot;/&amp;gt;&lt;br /&gt;
        &amp;lt;/id&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;cssData&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;css_location&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;homeDirectory&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;tomcat_home&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/class&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/hibernate-mapping&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''UpdateCSSService.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
The interface for the UpdateCSSServiceImpl file described above.&amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSManageController.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517/M601_Design_Document&amp;diff=75208</id>
		<title>CSC/ECE 517/M601 Design Document</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517/M601_Design_Document&amp;diff=75208"/>
		<updated>2013-04-27T12:33:49Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: /* Specific Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;h1&amp;gt;Add ability to update css through webapp&amp;lt;/h1&amp;gt;&lt;br /&gt;
== Example Video ==&lt;br /&gt;
A video example of this module can be seen here [http://youtu.be/2dQeFYjcsnU]&lt;br /&gt;
==Team== &lt;br /&gt;
Yuri Kolesnikov &amp;lt;br&amp;gt;&lt;br /&gt;
Jonathan Wills &amp;lt;br&amp;gt;&lt;br /&gt;
Jeffrey Plemmons &amp;lt;br&amp;gt;&lt;br /&gt;
Roshna Agarwal&lt;br /&gt;
&lt;br /&gt;
==Our Work==&lt;br /&gt;
Link to the OpenMRS ticket: https://tickets.openmrs.org/browse/TRUNK-3415&amp;lt;br&amp;gt;&lt;br /&gt;
Link to our code in GitHub: https://github.com/ykolesn/openmrs-module-m601 &amp;lt;br&amp;gt;&lt;br /&gt;
Link to application: http://152.46.17.228:8081/openmrs-standalone&lt;br /&gt;
&lt;br /&gt;
==Purpose==&lt;br /&gt;
	The purpose of this module is to add the functionality of allowing the admin to customize the OpenMRS css file to their own specifications. By having the ability to customize the OpenMRS css file, the admin will be free to change the look and feel in their installation of OpenMRS.&lt;br /&gt;
&lt;br /&gt;
==Problem Definition==&lt;br /&gt;
	Add admin page for customization of the openmrs css file. Admins can 'override' any openmrs css with their own file by specifying that file in the openmrs runtime properties file.&lt;br /&gt;
This would be best as a new module in openmrs or perhaps just adding a new feature in the Custom Logo module? The admin should see a page with a large text box. The text box value should be persisted in the database as a new object/table/column somehow. When the module starts up, the Activator is called. Modify the activator to update the filesystem css file with whatever is defined by the admin.&lt;br /&gt;
&lt;br /&gt;
==Design Requirements==&lt;br /&gt;
&lt;br /&gt;
1. The admin should be able to customize the openmrs css file through an admin page. &amp;lt;br&amp;gt;&lt;br /&gt;
2. The admin should see a page with a large text box. &amp;lt;br&amp;gt;&lt;br /&gt;
3. The text box content should be stored in the database. &amp;lt;br&amp;gt;&lt;br /&gt;
4. The activator needs to be modified so that it updates the filesystem css file with whatever is defined by the admin. &amp;lt;br&amp;gt;&lt;br /&gt;
5. Need to use Eclipse and Maven as development tools for the module. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
'''Week 1'''&lt;br /&gt;
&lt;br /&gt;
*Get OpenMRS Id&lt;br /&gt;
*Get ticket assigned and in progress&lt;br /&gt;
*Get openmrs module name assigned&lt;br /&gt;
*Create openmrs module&lt;br /&gt;
*Commit module to github&lt;br /&gt;
*Check out module on partner machines&lt;br /&gt;
*Get new admin page link&lt;br /&gt;
*Create new spring controller and jsp page&lt;br /&gt;
'''Week 2'''&lt;br /&gt;
&lt;br /&gt;
*Create object for storing css in db&lt;br /&gt;
*Create service layer and dao layer methods to save object&lt;br /&gt;
*Connect controller to db object for saving + retrieving&lt;br /&gt;
*Add unit tests for saving/retrieving&lt;br /&gt;
'''Week 3'''&lt;br /&gt;
&lt;br /&gt;
*Create settings page to allow admin to choose where tomcat is running&lt;br /&gt;
*Add some magic so that module tries to guess where tomcat is running&lt;br /&gt;
*Add ability to put the saved css into the right folder in tomcat so that the css is actually overriding the openmrs style.css file.&lt;br /&gt;
&lt;br /&gt;
==Development Tools==&lt;br /&gt;
1. '''Eclipse'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Integrated_development_environment&amp;lt;/ref&amp;gt;: Eclipse is the Integrated Development Environment used to develop, modify, and compile the code for our module. &amp;lt;br&amp;gt;&lt;br /&gt;
2. '''Maven'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Maven&amp;lt;/ref&amp;gt;: Maven is used through a plug-in in Eclipse to compile, run unit tests, and package all of the Java files in the module.  &amp;lt;br&amp;gt;&lt;br /&gt;
3. '''Tomcat'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Tomcat&amp;lt;/ref&amp;gt;: Tomcat is the web-server used to run the application. &amp;lt;br&amp;gt; &lt;br /&gt;
4. '''Hibernate'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Hibernate_(Java)&amp;lt;/ref&amp;gt;: Hibernate is a built-in utility in the OpenMRS module, that is used to connect the Java classes to the database tables in the application. It configured the database table through an xml file: UpdateCSS.hbm.xml&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE hibernate-mapping PUBLIC&lt;br /&gt;
    &amp;quot;-//Hibernate/Hibernate Mapping DTD 3.0//EN&amp;quot;&lt;br /&gt;
    &amp;quot;http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&amp;quot; &amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hibernate-mapping package=&amp;quot;org.openmrs.module.updatecss&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;class name=&amp;quot;UpdateCSS&amp;quot;&lt;br /&gt;
	table=&amp;quot;css_properties&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;id name=&amp;quot;id&amp;quot; type=&amp;quot;int&amp;quot; column=&amp;quot;id&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;generator class=&amp;quot;native&amp;quot;/&amp;gt;&lt;br /&gt;
        &amp;lt;/id&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;cssData&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;css_location&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;homeDirectory&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;tomcat_home&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/class&amp;gt;&lt;br /&gt;
&amp;lt;/hibernate-mapping&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
''Here in the UpdateCSS.hbm.xml we specify the table name and columns. Hibernate generates the table with the fields specified and handles all the necessary SQL calls and queries.''&amp;lt;br&amp;gt;&lt;br /&gt;
5. '''MySQL''': MySQL&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Mysql&amp;lt;/ref&amp;gt; is the RDBMS that is used to store the CSS data for the application.&lt;br /&gt;
&lt;br /&gt;
==Use Case==&lt;br /&gt;
[[File:Openmrsui.png|800px|alt=OpenMRS UI]]&amp;lt;br&amp;gt;&lt;br /&gt;
''This is the user interface for the UpdateCSS module. The initial start screen provides a default location for the css style sheet and default css code. Here the navigation bar is changed to &amp;quot;orange&amp;quot;. ''&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
1. Log in to the Admin page with user &amp;quot;Admin&amp;quot; and password &amp;quot;Admin123&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
2. Once logged in, click on &amp;quot;Administration&amp;quot; on the right-hand side of the navigation bar. &amp;lt;br&amp;gt;&lt;br /&gt;
3. Under &amp;quot;Update CSS Module&amp;quot;, click on &amp;quot;Manage module&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
4. Here the user can enter their desired CSS preferences for customization. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Application Overview==&lt;br /&gt;
[[File:Overview.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt;Code Changes&amp;lt;/h1&amp;gt;&lt;br /&gt;
==Classes and Files Worked On==&lt;br /&gt;
* UpdateCSSActivator.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSS.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSService.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSServiceImpl.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSDAO.java &amp;lt;br&amp;gt;&lt;br /&gt;
* HibernateUpdateCSSDAO.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSS.hbm.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* liquibase.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* moduleApplicationContext.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSServiceTest.java &amp;lt;br&amp;gt;&lt;br /&gt;
* manage.jsp &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSManageController.java &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Specific Changes==&lt;br /&gt;
'''UpdateCSSActivator.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSServiceImpl.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
Added below methods to UpdateCSSServiceImpl class: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  /**&lt;br /&gt;
+   * Replaces the text of the specified CSS file in the&lt;br /&gt;
+   * specified directory with the specified text&lt;br /&gt;
+   */ +  public void copyCssDataToTomcatDirectory(String directory, String cssText) {&lt;br /&gt;
+    File cssFile = new File(directory);&lt;br /&gt;
+    if (cssFile.exists()) {&lt;br /&gt;
+      writeDataToFile(cssFile, cssText);&lt;br /&gt;
+    }&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Copies the data stored in the DB into the CSS file that is saved in the &lt;br /&gt;
+   * directory column of the css_properties table&lt;br /&gt;
+   */&lt;br /&gt;
+  public void copyCssDataToTomcatDirectory() {&lt;br /&gt;
+    UpdateCSS updateCSS = getData();&lt;br /&gt;
+    String cssDirectory = updateCSS.getHomeDirectory();&lt;br /&gt;
+    String cssText = updateCSS.getCssData();&lt;br /&gt;
+    copyCssDataToTomcatDirectory(cssDirectory, cssText);&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Writes the specified text to the specified CSS file&lt;br /&gt;
+   */&lt;br /&gt;
+  public void writeDataToFile(File cssFile, String cssText) {&lt;br /&gt;
+    try {&lt;br /&gt;
+      if (cssFile.exists()) {&lt;br /&gt;
+        PrintWriter writer = new PrintWriter(cssFile);&lt;br /&gt;
+        writer.print(cssText);&lt;br /&gt;
+        writer.close();&lt;br /&gt;
+      }&lt;br /&gt;
+    } catch (FileNotFoundException ex) {&lt;br /&gt;
+      &lt;br /&gt;
+    }&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Reads the data in the file at the specified path and returns&lt;br /&gt;
+   * a String with the contents. If the file doesn't exist&lt;br /&gt;
+   * then it returns an empty string&lt;br /&gt;
+   */&lt;br /&gt;
+  public String getCssTextFromFile(String filePath) {&lt;br /&gt;
+    String cssText = &amp;quot;&amp;quot;;&lt;br /&gt;
+    try {&lt;br /&gt;
+      File cssFile = new File(filePath);&lt;br /&gt;
+      if (cssFile.exists()) {&lt;br /&gt;
+        cssText = FileUtils.readFileToString(cssFile);&lt;br /&gt;
+      }  &lt;br /&gt;
+    } catch (IOException ex) {&lt;br /&gt;
+    &lt;br /&gt;
+    }&lt;br /&gt;
+    return cssText;&lt;br /&gt;
+  }&lt;br /&gt;
+    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''UpdateCSS.java:''' &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSDAO.java/HibernateUpdateCSSDAO.java'''&lt;br /&gt;
The DAO files carry the primary responsibility of interaction with the DB layer in the MVC architecture.&amp;lt;br&amp;gt;&lt;br /&gt;
The data layer changes involved 3 separate components:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. liquibase.xml file to configure our new table: css_properties&amp;lt;br&amp;gt;&lt;br /&gt;
2. UpdateCSSDAO.java/HibernateUpdateCSSDAO.java - Interface/Implementation for DAO getter/setter.&amp;lt;br&amp;gt;&lt;br /&gt;
3. UpdateCSS.hbm.xml - Hibernate configuration file for mapping DAO to new properties table.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''liquibase.xml''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Liquibase&amp;lt;ref&amp;gt;http://www.liquibase.org/documentation/&amp;lt;/ref&amp;gt; is a method for automatically generating database changes at module startup.  We used this to add&amp;lt;br&amp;gt;&lt;br /&gt;
our new css_properties table.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    &amp;lt;changeSet id=&amp;quot;updatecss-2013-04-22-26:00&amp;quot; author=&amp;quot;yurijeffroshnajon&amp;quot; runOnChange=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
     	&amp;lt;preConditions onFail=&amp;quot;MARK_RAN&amp;quot;&amp;gt;&lt;br /&gt;
             &amp;lt;not&amp;gt;&amp;lt;tableExists tableName=&amp;quot;css_properties&amp;quot;/&amp;gt;&amp;lt;/not&amp;gt;&lt;br /&gt;
        &amp;lt;/preConditions&amp;gt;&lt;br /&gt;
        &amp;lt;comment&amp;gt;&lt;br /&gt;
             Create the css_properties table&lt;br /&gt;
        &amp;lt;/comment&amp;gt;&lt;br /&gt;
        &amp;lt;createTable tableName=&amp;quot;css_properties&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;column name=&amp;quot;id&amp;quot; type=&amp;quot;int&amp;quot; autoIncrement=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;constraints primaryKey=&amp;quot;true&amp;quot; nullable=&amp;quot;false&amp;quot;/&amp;gt;&lt;br /&gt;
            &amp;lt;/column&amp;gt;&lt;br /&gt;
            &amp;lt;column name=&amp;quot;css_location&amp;quot; type=&amp;quot;longtext&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;constraints nullable=&amp;quot;false&amp;quot;/&amp;gt;&lt;br /&gt;
            &amp;lt;/column&amp;gt;&lt;br /&gt;
            &amp;lt;column name=&amp;quot;tomcat_home&amp;quot; type=&amp;quot;varchar(255)&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;constraints nullable=&amp;quot;false&amp;quot;/&amp;gt;&lt;br /&gt;
            &amp;lt;/column&amp;gt;&lt;br /&gt;
        &amp;lt;/createTable&amp;gt;&lt;br /&gt;
    &amp;lt;/changeSet&amp;gt; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
''Hibernate''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Hibernate&amp;lt;ref&amp;gt;http://www.hibernate.org/&amp;lt;/ref&amp;gt; is a POJO-based implementation used for database interaction without the need for SQL queries.&amp;lt;br&amp;gt;  Instead, by using some XML-based configuration files provided by the Hibernate framework, you can manipulate the&amp;lt;br&amp;gt;&lt;br /&gt;
database using only Java objects.  This is the mechanism we used for our database interaction.  Our sample config file:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;hibernate-mapping package=&amp;quot;org.openmrs.module.updatecss&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;class name=&amp;quot;UpdateCSS&amp;quot;&lt;br /&gt;
	table=&amp;quot;css_properties&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;id name=&amp;quot;id&amp;quot; type=&amp;quot;int&amp;quot; column=&amp;quot;id&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;generator class=&amp;quot;native&amp;quot;/&amp;gt;&lt;br /&gt;
        &amp;lt;/id&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;cssData&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;css_location&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;homeDirectory&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;tomcat_home&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/class&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/hibernate-mapping&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''UpdateCSSService.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSManageController.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517/M601_Design_Document&amp;diff=75207</id>
		<title>CSC/ECE 517/M601 Design Document</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517/M601_Design_Document&amp;diff=75207"/>
		<updated>2013-04-27T12:29:35Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: /* Specific Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;h1&amp;gt;Add ability to update css through webapp&amp;lt;/h1&amp;gt;&lt;br /&gt;
== Example Video ==&lt;br /&gt;
A video example of this module can be seen here [http://youtu.be/2dQeFYjcsnU]&lt;br /&gt;
==Team== &lt;br /&gt;
Yuri Kolesnikov &amp;lt;br&amp;gt;&lt;br /&gt;
Jonathan Wills &amp;lt;br&amp;gt;&lt;br /&gt;
Jeffrey Plemmons &amp;lt;br&amp;gt;&lt;br /&gt;
Roshna Agarwal&lt;br /&gt;
&lt;br /&gt;
==Our Work==&lt;br /&gt;
Link to the OpenMRS ticket: https://tickets.openmrs.org/browse/TRUNK-3415&amp;lt;br&amp;gt;&lt;br /&gt;
Link to our code in GitHub: https://github.com/ykolesn/openmrs-module-m601 &amp;lt;br&amp;gt;&lt;br /&gt;
Link to application: http://152.46.17.228:8081/openmrs-standalone&lt;br /&gt;
&lt;br /&gt;
==Purpose==&lt;br /&gt;
	The purpose of this module is to add the functionality of allowing the admin to customize the OpenMRS css file to their own specifications. By having the ability to customize the OpenMRS css file, the admin will be free to change the look and feel in their installation of OpenMRS.&lt;br /&gt;
&lt;br /&gt;
==Problem Definition==&lt;br /&gt;
	Add admin page for customization of the openmrs css file. Admins can 'override' any openmrs css with their own file by specifying that file in the openmrs runtime properties file.&lt;br /&gt;
This would be best as a new module in openmrs or perhaps just adding a new feature in the Custom Logo module? The admin should see a page with a large text box. The text box value should be persisted in the database as a new object/table/column somehow. When the module starts up, the Activator is called. Modify the activator to update the filesystem css file with whatever is defined by the admin.&lt;br /&gt;
&lt;br /&gt;
==Design Requirements==&lt;br /&gt;
&lt;br /&gt;
1. The admin should be able to customize the openmrs css file through an admin page. &amp;lt;br&amp;gt;&lt;br /&gt;
2. The admin should see a page with a large text box. &amp;lt;br&amp;gt;&lt;br /&gt;
3. The text box content should be stored in the database. &amp;lt;br&amp;gt;&lt;br /&gt;
4. The activator needs to be modified so that it updates the filesystem css file with whatever is defined by the admin. &amp;lt;br&amp;gt;&lt;br /&gt;
5. Need to use Eclipse and Maven as development tools for the module. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
'''Week 1'''&lt;br /&gt;
&lt;br /&gt;
*Get OpenMRS Id&lt;br /&gt;
*Get ticket assigned and in progress&lt;br /&gt;
*Get openmrs module name assigned&lt;br /&gt;
*Create openmrs module&lt;br /&gt;
*Commit module to github&lt;br /&gt;
*Check out module on partner machines&lt;br /&gt;
*Get new admin page link&lt;br /&gt;
*Create new spring controller and jsp page&lt;br /&gt;
'''Week 2'''&lt;br /&gt;
&lt;br /&gt;
*Create object for storing css in db&lt;br /&gt;
*Create service layer and dao layer methods to save object&lt;br /&gt;
*Connect controller to db object for saving + retrieving&lt;br /&gt;
*Add unit tests for saving/retrieving&lt;br /&gt;
'''Week 3'''&lt;br /&gt;
&lt;br /&gt;
*Create settings page to allow admin to choose where tomcat is running&lt;br /&gt;
*Add some magic so that module tries to guess where tomcat is running&lt;br /&gt;
*Add ability to put the saved css into the right folder in tomcat so that the css is actually overriding the openmrs style.css file.&lt;br /&gt;
&lt;br /&gt;
==Development Tools==&lt;br /&gt;
1. '''Eclipse'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Integrated_development_environment&amp;lt;/ref&amp;gt;: Eclipse is the Integrated Development Environment used to develop, modify, and compile the code for our module. &amp;lt;br&amp;gt;&lt;br /&gt;
2. '''Maven'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Maven&amp;lt;/ref&amp;gt;: Maven is used through a plug-in in Eclipse to compile, run unit tests, and package all of the Java files in the module.  &amp;lt;br&amp;gt;&lt;br /&gt;
3. '''Tomcat'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Tomcat&amp;lt;/ref&amp;gt;: Tomcat is the web-server used to run the application. &amp;lt;br&amp;gt; &lt;br /&gt;
4. '''Hibernate'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Hibernate_(Java)&amp;lt;/ref&amp;gt;: Hibernate is a built-in utility in the OpenMRS module, that is used to connect the Java classes to the database tables in the application. It configured the database table through an xml file: UpdateCSS.hbm.xml&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE hibernate-mapping PUBLIC&lt;br /&gt;
    &amp;quot;-//Hibernate/Hibernate Mapping DTD 3.0//EN&amp;quot;&lt;br /&gt;
    &amp;quot;http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&amp;quot; &amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hibernate-mapping package=&amp;quot;org.openmrs.module.updatecss&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;class name=&amp;quot;UpdateCSS&amp;quot;&lt;br /&gt;
	table=&amp;quot;css_properties&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;id name=&amp;quot;id&amp;quot; type=&amp;quot;int&amp;quot; column=&amp;quot;id&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;generator class=&amp;quot;native&amp;quot;/&amp;gt;&lt;br /&gt;
        &amp;lt;/id&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;cssData&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;css_location&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;homeDirectory&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;tomcat_home&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/class&amp;gt;&lt;br /&gt;
&amp;lt;/hibernate-mapping&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
''Here in the UpdateCSS.hbm.xml we specify the table name and columns. Hibernate generates the table with the fields specified and handles all the necessary SQL calls and queries.''&amp;lt;br&amp;gt;&lt;br /&gt;
5. '''MySQL''': MySQL&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Mysql&amp;lt;/ref&amp;gt; is the RDBMS that is used to store the CSS data for the application.&lt;br /&gt;
&lt;br /&gt;
==Use Case==&lt;br /&gt;
[[File:Openmrsui.png|800px|alt=OpenMRS UI]]&amp;lt;br&amp;gt;&lt;br /&gt;
''This is the user interface for the UpdateCSS module. The initial start screen provides a default location for the css style sheet and default css code. Here the navigation bar is changed to &amp;quot;orange&amp;quot;. ''&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
1. Log in to the Admin page with user &amp;quot;Admin&amp;quot; and password &amp;quot;Admin123&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
2. Once logged in, click on &amp;quot;Administration&amp;quot; on the right-hand side of the navigation bar. &amp;lt;br&amp;gt;&lt;br /&gt;
3. Under &amp;quot;Update CSS Module&amp;quot;, click on &amp;quot;Manage module&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
4. Here the user can enter their desired CSS preferences for customization. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Application Overview==&lt;br /&gt;
[[File:Overview.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt;Code Changes&amp;lt;/h1&amp;gt;&lt;br /&gt;
==Classes and Files Worked On==&lt;br /&gt;
* UpdateCSSActivator.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSS.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSService.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSServiceImpl.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSDAO.java &amp;lt;br&amp;gt;&lt;br /&gt;
* HibernateUpdateCSSDAO.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSS.hbm.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* liquibase.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* moduleApplicationContext.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSServiceTest.java &amp;lt;br&amp;gt;&lt;br /&gt;
* manage.jsp &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSManageController.java &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Specific Changes==&lt;br /&gt;
'''UpdateCSSActivator.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSServiceImpl.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
Added below methods to UpdateCSSServiceImpl class: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  /**&lt;br /&gt;
+   * Replaces the text of the specified CSS file in the&lt;br /&gt;
+   * specified directory with the specified text&lt;br /&gt;
+   */ +  public void copyCssDataToTomcatDirectory(String directory, String cssText) {&lt;br /&gt;
+    File cssFile = new File(directory);&lt;br /&gt;
+    if (cssFile.exists()) {&lt;br /&gt;
+      writeDataToFile(cssFile, cssText);&lt;br /&gt;
+    }&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Copies the data stored in the DB into the CSS file that is saved in the &lt;br /&gt;
+   * directory column of the css_properties table&lt;br /&gt;
+   */&lt;br /&gt;
+  public void copyCssDataToTomcatDirectory() {&lt;br /&gt;
+    UpdateCSS updateCSS = getData();&lt;br /&gt;
+    String cssDirectory = updateCSS.getHomeDirectory();&lt;br /&gt;
+    String cssText = updateCSS.getCssData();&lt;br /&gt;
+    copyCssDataToTomcatDirectory(cssDirectory, cssText);&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Writes the specified text to the specified CSS file&lt;br /&gt;
+   */&lt;br /&gt;
+  public void writeDataToFile(File cssFile, String cssText) {&lt;br /&gt;
+    try {&lt;br /&gt;
+      if (cssFile.exists()) {&lt;br /&gt;
+        PrintWriter writer = new PrintWriter(cssFile);&lt;br /&gt;
+        writer.print(cssText);&lt;br /&gt;
+        writer.close();&lt;br /&gt;
+      }&lt;br /&gt;
+    } catch (FileNotFoundException ex) {&lt;br /&gt;
+      &lt;br /&gt;
+    }&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Reads the data in the file at the specified path and returns&lt;br /&gt;
+   * a String with the contents. If the file doesn't exist&lt;br /&gt;
+   * then it returns an empty string&lt;br /&gt;
+   */&lt;br /&gt;
+  public String getCssTextFromFile(String filePath) {&lt;br /&gt;
+    String cssText = &amp;quot;&amp;quot;;&lt;br /&gt;
+    try {&lt;br /&gt;
+      File cssFile = new File(filePath);&lt;br /&gt;
+      if (cssFile.exists()) {&lt;br /&gt;
+        cssText = FileUtils.readFileToString(cssFile);&lt;br /&gt;
+      }  &lt;br /&gt;
+    } catch (IOException ex) {&lt;br /&gt;
+    &lt;br /&gt;
+    }&lt;br /&gt;
+    return cssText;&lt;br /&gt;
+  }&lt;br /&gt;
+    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''UpdateCSS.java:''' &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSDAO.java/HibernateUpdateCSSDAO.java'''&lt;br /&gt;
The DAO files carry the primary responsibility of interaction with the DB layer in the MVC architecture.&amp;lt;br&amp;gt;&lt;br /&gt;
The data layer changes involved 3 separate components:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. liquibase.xml file to configure our new table: css_properties&amp;lt;br&amp;gt;&lt;br /&gt;
2. UpdateCSSDAO.java/HibernateUpdateCSSDAO.java - Interface/Implementation for DAO getter/setter.&amp;lt;br&amp;gt;&lt;br /&gt;
3. UpdateCSS.hbm.xml - Hibernate configuration file for mapping DAO to new properties table.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''liquibase.xml''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Liquibase&amp;lt;ref&amp;gt;http://www.liquibase.org/documentation/&amp;lt;/ref&amp;gt; is a method for automatically generating database changes at module startup.  We used this to add&amp;lt;br&amp;gt;&lt;br /&gt;
our new css_properties table.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    &amp;lt;changeSet id=&amp;quot;updatecss-2013-04-22-26:00&amp;quot; author=&amp;quot;yurijeffroshnajon&amp;quot; runOnChange=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
     	&amp;lt;preConditions onFail=&amp;quot;MARK_RAN&amp;quot;&amp;gt;&lt;br /&gt;
             &amp;lt;not&amp;gt;&amp;lt;tableExists tableName=&amp;quot;css_properties&amp;quot;/&amp;gt;&amp;lt;/not&amp;gt;&lt;br /&gt;
        &amp;lt;/preConditions&amp;gt;&lt;br /&gt;
        &amp;lt;comment&amp;gt;&lt;br /&gt;
             Create the css_properties table&lt;br /&gt;
        &amp;lt;/comment&amp;gt;&lt;br /&gt;
        &amp;lt;createTable tableName=&amp;quot;css_properties&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;column name=&amp;quot;id&amp;quot; type=&amp;quot;int&amp;quot; autoIncrement=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;constraints primaryKey=&amp;quot;true&amp;quot; nullable=&amp;quot;false&amp;quot;/&amp;gt;&lt;br /&gt;
            &amp;lt;/column&amp;gt;&lt;br /&gt;
            &amp;lt;column name=&amp;quot;css_location&amp;quot; type=&amp;quot;longtext&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;constraints nullable=&amp;quot;false&amp;quot;/&amp;gt;&lt;br /&gt;
            &amp;lt;/column&amp;gt;&lt;br /&gt;
            &amp;lt;column name=&amp;quot;tomcat_home&amp;quot; type=&amp;quot;varchar(255)&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;constraints nullable=&amp;quot;false&amp;quot;/&amp;gt;&lt;br /&gt;
            &amp;lt;/column&amp;gt;&lt;br /&gt;
        &amp;lt;/createTable&amp;gt;&lt;br /&gt;
    &amp;lt;/changeSet&amp;gt; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
''Hibernate''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSService.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSManageController.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517/M601_Design_Document&amp;diff=75206</id>
		<title>CSC/ECE 517/M601 Design Document</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517/M601_Design_Document&amp;diff=75206"/>
		<updated>2013-04-27T12:27:54Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: /* Specific Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;h1&amp;gt;Add ability to update css through webapp&amp;lt;/h1&amp;gt;&lt;br /&gt;
== Example Video ==&lt;br /&gt;
A video example of this module can be seen here [http://youtu.be/2dQeFYjcsnU]&lt;br /&gt;
==Team== &lt;br /&gt;
Yuri Kolesnikov &amp;lt;br&amp;gt;&lt;br /&gt;
Jonathan Wills &amp;lt;br&amp;gt;&lt;br /&gt;
Jeffrey Plemmons &amp;lt;br&amp;gt;&lt;br /&gt;
Roshna Agarwal&lt;br /&gt;
&lt;br /&gt;
==Our Work==&lt;br /&gt;
Link to the OpenMRS ticket: https://tickets.openmrs.org/browse/TRUNK-3415&amp;lt;br&amp;gt;&lt;br /&gt;
Link to our code in GitHub: https://github.com/ykolesn/openmrs-module-m601 &amp;lt;br&amp;gt;&lt;br /&gt;
Link to application: http://152.46.17.228:8081/openmrs-standalone&lt;br /&gt;
&lt;br /&gt;
==Purpose==&lt;br /&gt;
	The purpose of this module is to add the functionality of allowing the admin to customize the OpenMRS css file to their own specifications. By having the ability to customize the OpenMRS css file, the admin will be free to change the look and feel in their installation of OpenMRS.&lt;br /&gt;
&lt;br /&gt;
==Problem Definition==&lt;br /&gt;
	Add admin page for customization of the openmrs css file. Admins can 'override' any openmrs css with their own file by specifying that file in the openmrs runtime properties file.&lt;br /&gt;
This would be best as a new module in openmrs or perhaps just adding a new feature in the Custom Logo module? The admin should see a page with a large text box. The text box value should be persisted in the database as a new object/table/column somehow. When the module starts up, the Activator is called. Modify the activator to update the filesystem css file with whatever is defined by the admin.&lt;br /&gt;
&lt;br /&gt;
==Design Requirements==&lt;br /&gt;
&lt;br /&gt;
1. The admin should be able to customize the openmrs css file through an admin page. &amp;lt;br&amp;gt;&lt;br /&gt;
2. The admin should see a page with a large text box. &amp;lt;br&amp;gt;&lt;br /&gt;
3. The text box content should be stored in the database. &amp;lt;br&amp;gt;&lt;br /&gt;
4. The activator needs to be modified so that it updates the filesystem css file with whatever is defined by the admin. &amp;lt;br&amp;gt;&lt;br /&gt;
5. Need to use Eclipse and Maven as development tools for the module. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
'''Week 1'''&lt;br /&gt;
&lt;br /&gt;
*Get OpenMRS Id&lt;br /&gt;
*Get ticket assigned and in progress&lt;br /&gt;
*Get openmrs module name assigned&lt;br /&gt;
*Create openmrs module&lt;br /&gt;
*Commit module to github&lt;br /&gt;
*Check out module on partner machines&lt;br /&gt;
*Get new admin page link&lt;br /&gt;
*Create new spring controller and jsp page&lt;br /&gt;
'''Week 2'''&lt;br /&gt;
&lt;br /&gt;
*Create object for storing css in db&lt;br /&gt;
*Create service layer and dao layer methods to save object&lt;br /&gt;
*Connect controller to db object for saving + retrieving&lt;br /&gt;
*Add unit tests for saving/retrieving&lt;br /&gt;
'''Week 3'''&lt;br /&gt;
&lt;br /&gt;
*Create settings page to allow admin to choose where tomcat is running&lt;br /&gt;
*Add some magic so that module tries to guess where tomcat is running&lt;br /&gt;
*Add ability to put the saved css into the right folder in tomcat so that the css is actually overriding the openmrs style.css file.&lt;br /&gt;
&lt;br /&gt;
==Development Tools==&lt;br /&gt;
1. '''Eclipse'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Integrated_development_environment&amp;lt;/ref&amp;gt;: Eclipse is the Integrated Development Environment used to develop, modify, and compile the code for our module. &amp;lt;br&amp;gt;&lt;br /&gt;
2. '''Maven'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Maven&amp;lt;/ref&amp;gt;: Maven is used through a plug-in in Eclipse to compile, run unit tests, and package all of the Java files in the module.  &amp;lt;br&amp;gt;&lt;br /&gt;
3. '''Tomcat'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Tomcat&amp;lt;/ref&amp;gt;: Tomcat is the web-server used to run the application. &amp;lt;br&amp;gt; &lt;br /&gt;
4. '''Hibernate'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Hibernate_(Java)&amp;lt;/ref&amp;gt;: Hibernate is a built-in utility in the OpenMRS module, that is used to connect the Java classes to the database tables in the application. It configured the database table through an xml file: UpdateCSS.hbm.xml&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE hibernate-mapping PUBLIC&lt;br /&gt;
    &amp;quot;-//Hibernate/Hibernate Mapping DTD 3.0//EN&amp;quot;&lt;br /&gt;
    &amp;quot;http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&amp;quot; &amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hibernate-mapping package=&amp;quot;org.openmrs.module.updatecss&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;class name=&amp;quot;UpdateCSS&amp;quot;&lt;br /&gt;
	table=&amp;quot;css_properties&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;id name=&amp;quot;id&amp;quot; type=&amp;quot;int&amp;quot; column=&amp;quot;id&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;generator class=&amp;quot;native&amp;quot;/&amp;gt;&lt;br /&gt;
        &amp;lt;/id&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;cssData&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;css_location&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;homeDirectory&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;tomcat_home&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/class&amp;gt;&lt;br /&gt;
&amp;lt;/hibernate-mapping&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
''Here in the UpdateCSS.hbm.xml we specify the table name and columns. Hibernate generates the table with the fields specified and handles all the necessary SQL calls and queries.''&amp;lt;br&amp;gt;&lt;br /&gt;
5. '''MySQL''': MySQL&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Mysql&amp;lt;/ref&amp;gt; is the RDBMS that is used to store the CSS data for the application.&lt;br /&gt;
&lt;br /&gt;
==Use Case==&lt;br /&gt;
[[File:Openmrsui.png|800px|alt=OpenMRS UI]]&amp;lt;br&amp;gt;&lt;br /&gt;
''This is the user interface for the UpdateCSS module. The initial start screen provides a default location for the css style sheet and default css code. Here the navigation bar is changed to &amp;quot;orange&amp;quot;. ''&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
1. Log in to the Admin page with user &amp;quot;Admin&amp;quot; and password &amp;quot;Admin123&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
2. Once logged in, click on &amp;quot;Administration&amp;quot; on the right-hand side of the navigation bar. &amp;lt;br&amp;gt;&lt;br /&gt;
3. Under &amp;quot;Update CSS Module&amp;quot;, click on &amp;quot;Manage module&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
4. Here the user can enter their desired CSS preferences for customization. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Application Overview==&lt;br /&gt;
[[File:Overview.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt;Code Changes&amp;lt;/h1&amp;gt;&lt;br /&gt;
==Classes and Files Worked On==&lt;br /&gt;
* UpdateCSSActivator.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSS.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSService.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSServiceImpl.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSDAO.java &amp;lt;br&amp;gt;&lt;br /&gt;
* HibernateUpdateCSSDAO.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSS.hbm.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* liquibase.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* moduleApplicationContext.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSServiceTest.java &amp;lt;br&amp;gt;&lt;br /&gt;
* manage.jsp &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSManageController.java &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Specific Changes==&lt;br /&gt;
'''UpdateCSSActivator.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSServiceImpl.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
Added below methods to UpdateCSSServiceImpl class: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  /**&lt;br /&gt;
+   * Replaces the text of the specified CSS file in the&lt;br /&gt;
+   * specified directory with the specified text&lt;br /&gt;
+   */ +  public void copyCssDataToTomcatDirectory(String directory, String cssText) {&lt;br /&gt;
+    File cssFile = new File(directory);&lt;br /&gt;
+    if (cssFile.exists()) {&lt;br /&gt;
+      writeDataToFile(cssFile, cssText);&lt;br /&gt;
+    }&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Copies the data stored in the DB into the CSS file that is saved in the &lt;br /&gt;
+   * directory column of the css_properties table&lt;br /&gt;
+   */&lt;br /&gt;
+  public void copyCssDataToTomcatDirectory() {&lt;br /&gt;
+    UpdateCSS updateCSS = getData();&lt;br /&gt;
+    String cssDirectory = updateCSS.getHomeDirectory();&lt;br /&gt;
+    String cssText = updateCSS.getCssData();&lt;br /&gt;
+    copyCssDataToTomcatDirectory(cssDirectory, cssText);&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Writes the specified text to the specified CSS file&lt;br /&gt;
+   */&lt;br /&gt;
+  public void writeDataToFile(File cssFile, String cssText) {&lt;br /&gt;
+    try {&lt;br /&gt;
+      if (cssFile.exists()) {&lt;br /&gt;
+        PrintWriter writer = new PrintWriter(cssFile);&lt;br /&gt;
+        writer.print(cssText);&lt;br /&gt;
+        writer.close();&lt;br /&gt;
+      }&lt;br /&gt;
+    } catch (FileNotFoundException ex) {&lt;br /&gt;
+      &lt;br /&gt;
+    }&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Reads the data in the file at the specified path and returns&lt;br /&gt;
+   * a String with the contents. If the file doesn't exist&lt;br /&gt;
+   * then it returns an empty string&lt;br /&gt;
+   */&lt;br /&gt;
+  public String getCssTextFromFile(String filePath) {&lt;br /&gt;
+    String cssText = &amp;quot;&amp;quot;;&lt;br /&gt;
+    try {&lt;br /&gt;
+      File cssFile = new File(filePath);&lt;br /&gt;
+      if (cssFile.exists()) {&lt;br /&gt;
+        cssText = FileUtils.readFileToString(cssFile);&lt;br /&gt;
+      }  &lt;br /&gt;
+    } catch (IOException ex) {&lt;br /&gt;
+    &lt;br /&gt;
+    }&lt;br /&gt;
+    return cssText;&lt;br /&gt;
+  }&lt;br /&gt;
+    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''UpdateCSS.java:''' &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSDAO.java/HibernateUpdateCSSDAO.java'''&lt;br /&gt;
The DAO files carry the primary responsibility of interaction with the DB layer in the MVC architecture.&amp;lt;br&amp;gt;&lt;br /&gt;
The data layer changes involved 3 separate components:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. liquibase.xml file to configure our new table: css_properties&amp;lt;br&amp;gt;&lt;br /&gt;
2. UpdateCSSDAO.java/HibernateUpdateCSSDAO.java - Interface/Implementation for DAO getter/setter.&amp;lt;br&amp;gt;&lt;br /&gt;
3. UpdateCSS.hbm.xml - Hibernate configuration file for mapping DAO to new properties table.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''liquibase.xml''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Liquibase&amp;lt;ref&amp;gt;http://www.liquibase.org/documentation/&amp;lt;/ref&amp;gt; is a method for automatically generating database changes at module startup.  We used this to add&amp;lt;br&amp;gt;&lt;br /&gt;
our new css_properties table.&lt;br /&gt;
''Hibernate''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSService.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSManageController.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517/M601_Design_Document&amp;diff=75205</id>
		<title>CSC/ECE 517/M601 Design Document</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517/M601_Design_Document&amp;diff=75205"/>
		<updated>2013-04-27T12:26:08Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: /* Specific Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;h1&amp;gt;Add ability to update css through webapp&amp;lt;/h1&amp;gt;&lt;br /&gt;
== Example Video ==&lt;br /&gt;
A video example of this module can be seen here [http://youtu.be/2dQeFYjcsnU]&lt;br /&gt;
==Team== &lt;br /&gt;
Yuri Kolesnikov &amp;lt;br&amp;gt;&lt;br /&gt;
Jonathan Wills &amp;lt;br&amp;gt;&lt;br /&gt;
Jeffrey Plemmons &amp;lt;br&amp;gt;&lt;br /&gt;
Roshna Agarwal&lt;br /&gt;
&lt;br /&gt;
==Our Work==&lt;br /&gt;
Link to the OpenMRS ticket: https://tickets.openmrs.org/browse/TRUNK-3415&amp;lt;br&amp;gt;&lt;br /&gt;
Link to our code in GitHub: https://github.com/ykolesn/openmrs-module-m601 &amp;lt;br&amp;gt;&lt;br /&gt;
Link to application: http://152.46.17.228:8081/openmrs-standalone&lt;br /&gt;
&lt;br /&gt;
==Purpose==&lt;br /&gt;
	The purpose of this module is to add the functionality of allowing the admin to customize the OpenMRS css file to their own specifications. By having the ability to customize the OpenMRS css file, the admin will be free to change the look and feel in their installation of OpenMRS.&lt;br /&gt;
&lt;br /&gt;
==Problem Definition==&lt;br /&gt;
	Add admin page for customization of the openmrs css file. Admins can 'override' any openmrs css with their own file by specifying that file in the openmrs runtime properties file.&lt;br /&gt;
This would be best as a new module in openmrs or perhaps just adding a new feature in the Custom Logo module? The admin should see a page with a large text box. The text box value should be persisted in the database as a new object/table/column somehow. When the module starts up, the Activator is called. Modify the activator to update the filesystem css file with whatever is defined by the admin.&lt;br /&gt;
&lt;br /&gt;
==Design Requirements==&lt;br /&gt;
&lt;br /&gt;
1. The admin should be able to customize the openmrs css file through an admin page. &amp;lt;br&amp;gt;&lt;br /&gt;
2. The admin should see a page with a large text box. &amp;lt;br&amp;gt;&lt;br /&gt;
3. The text box content should be stored in the database. &amp;lt;br&amp;gt;&lt;br /&gt;
4. The activator needs to be modified so that it updates the filesystem css file with whatever is defined by the admin. &amp;lt;br&amp;gt;&lt;br /&gt;
5. Need to use Eclipse and Maven as development tools for the module. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
'''Week 1'''&lt;br /&gt;
&lt;br /&gt;
*Get OpenMRS Id&lt;br /&gt;
*Get ticket assigned and in progress&lt;br /&gt;
*Get openmrs module name assigned&lt;br /&gt;
*Create openmrs module&lt;br /&gt;
*Commit module to github&lt;br /&gt;
*Check out module on partner machines&lt;br /&gt;
*Get new admin page link&lt;br /&gt;
*Create new spring controller and jsp page&lt;br /&gt;
'''Week 2'''&lt;br /&gt;
&lt;br /&gt;
*Create object for storing css in db&lt;br /&gt;
*Create service layer and dao layer methods to save object&lt;br /&gt;
*Connect controller to db object for saving + retrieving&lt;br /&gt;
*Add unit tests for saving/retrieving&lt;br /&gt;
'''Week 3'''&lt;br /&gt;
&lt;br /&gt;
*Create settings page to allow admin to choose where tomcat is running&lt;br /&gt;
*Add some magic so that module tries to guess where tomcat is running&lt;br /&gt;
*Add ability to put the saved css into the right folder in tomcat so that the css is actually overriding the openmrs style.css file.&lt;br /&gt;
&lt;br /&gt;
==Development Tools==&lt;br /&gt;
1. '''Eclipse'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Integrated_development_environment&amp;lt;/ref&amp;gt;: Eclipse is the Integrated Development Environment used to develop, modify, and compile the code for our module. &amp;lt;br&amp;gt;&lt;br /&gt;
2. '''Maven'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Maven&amp;lt;/ref&amp;gt;: Maven is used through a plug-in in Eclipse to compile, run unit tests, and package all of the Java files in the module.  &amp;lt;br&amp;gt;&lt;br /&gt;
3. '''Tomcat'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Tomcat&amp;lt;/ref&amp;gt;: Tomcat is the web-server used to run the application. &amp;lt;br&amp;gt; &lt;br /&gt;
4. '''Hibernate'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Hibernate_(Java)&amp;lt;/ref&amp;gt;: Hibernate is a built-in utility in the OpenMRS module, that is used to connect the Java classes to the database tables in the application. It configured the database table through an xml file: UpdateCSS.hbm.xml&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE hibernate-mapping PUBLIC&lt;br /&gt;
    &amp;quot;-//Hibernate/Hibernate Mapping DTD 3.0//EN&amp;quot;&lt;br /&gt;
    &amp;quot;http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&amp;quot; &amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hibernate-mapping package=&amp;quot;org.openmrs.module.updatecss&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;class name=&amp;quot;UpdateCSS&amp;quot;&lt;br /&gt;
	table=&amp;quot;css_properties&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;id name=&amp;quot;id&amp;quot; type=&amp;quot;int&amp;quot; column=&amp;quot;id&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;generator class=&amp;quot;native&amp;quot;/&amp;gt;&lt;br /&gt;
        &amp;lt;/id&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;cssData&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;css_location&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;homeDirectory&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;tomcat_home&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/class&amp;gt;&lt;br /&gt;
&amp;lt;/hibernate-mapping&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
''Here in the UpdateCSS.hbm.xml we specify the table name and columns. Hibernate generates the table with the fields specified and handles all the necessary SQL calls and queries.''&amp;lt;br&amp;gt;&lt;br /&gt;
5. '''MySQL''': MySQL&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Mysql&amp;lt;/ref&amp;gt; is the RDBMS that is used to store the CSS data for the application.&lt;br /&gt;
&lt;br /&gt;
==Use Case==&lt;br /&gt;
[[File:Openmrsui.png|800px|alt=OpenMRS UI]]&amp;lt;br&amp;gt;&lt;br /&gt;
''This is the user interface for the UpdateCSS module. The initial start screen provides a default location for the css style sheet and default css code. Here the navigation bar is changed to &amp;quot;orange&amp;quot;. ''&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
1. Log in to the Admin page with user &amp;quot;Admin&amp;quot; and password &amp;quot;Admin123&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
2. Once logged in, click on &amp;quot;Administration&amp;quot; on the right-hand side of the navigation bar. &amp;lt;br&amp;gt;&lt;br /&gt;
3. Under &amp;quot;Update CSS Module&amp;quot;, click on &amp;quot;Manage module&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
4. Here the user can enter their desired CSS preferences for customization. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Application Overview==&lt;br /&gt;
[[File:Overview.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt;Code Changes&amp;lt;/h1&amp;gt;&lt;br /&gt;
==Classes and Files Worked On==&lt;br /&gt;
* UpdateCSSActivator.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSS.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSService.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSServiceImpl.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSDAO.java &amp;lt;br&amp;gt;&lt;br /&gt;
* HibernateUpdateCSSDAO.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSS.hbm.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* liquibase.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* moduleApplicationContext.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSServiceTest.java &amp;lt;br&amp;gt;&lt;br /&gt;
* manage.jsp &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSManageController.java &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Specific Changes==&lt;br /&gt;
'''UpdateCSSActivator.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSServiceImpl.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
Added below methods to UpdateCSSServiceImpl class: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  /**&lt;br /&gt;
+   * Replaces the text of the specified CSS file in the&lt;br /&gt;
+   * specified directory with the specified text&lt;br /&gt;
+   */ +  public void copyCssDataToTomcatDirectory(String directory, String cssText) {&lt;br /&gt;
+    File cssFile = new File(directory);&lt;br /&gt;
+    if (cssFile.exists()) {&lt;br /&gt;
+      writeDataToFile(cssFile, cssText);&lt;br /&gt;
+    }&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Copies the data stored in the DB into the CSS file that is saved in the &lt;br /&gt;
+   * directory column of the css_properties table&lt;br /&gt;
+   */&lt;br /&gt;
+  public void copyCssDataToTomcatDirectory() {&lt;br /&gt;
+    UpdateCSS updateCSS = getData();&lt;br /&gt;
+    String cssDirectory = updateCSS.getHomeDirectory();&lt;br /&gt;
+    String cssText = updateCSS.getCssData();&lt;br /&gt;
+    copyCssDataToTomcatDirectory(cssDirectory, cssText);&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Writes the specified text to the specified CSS file&lt;br /&gt;
+   */&lt;br /&gt;
+  public void writeDataToFile(File cssFile, String cssText) {&lt;br /&gt;
+    try {&lt;br /&gt;
+      if (cssFile.exists()) {&lt;br /&gt;
+        PrintWriter writer = new PrintWriter(cssFile);&lt;br /&gt;
+        writer.print(cssText);&lt;br /&gt;
+        writer.close();&lt;br /&gt;
+      }&lt;br /&gt;
+    } catch (FileNotFoundException ex) {&lt;br /&gt;
+      &lt;br /&gt;
+    }&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Reads the data in the file at the specified path and returns&lt;br /&gt;
+   * a String with the contents. If the file doesn't exist&lt;br /&gt;
+   * then it returns an empty string&lt;br /&gt;
+   */&lt;br /&gt;
+  public String getCssTextFromFile(String filePath) {&lt;br /&gt;
+    String cssText = &amp;quot;&amp;quot;;&lt;br /&gt;
+    try {&lt;br /&gt;
+      File cssFile = new File(filePath);&lt;br /&gt;
+      if (cssFile.exists()) {&lt;br /&gt;
+        cssText = FileUtils.readFileToString(cssFile);&lt;br /&gt;
+      }  &lt;br /&gt;
+    } catch (IOException ex) {&lt;br /&gt;
+    &lt;br /&gt;
+    }&lt;br /&gt;
+    return cssText;&lt;br /&gt;
+  }&lt;br /&gt;
+    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''UpdateCSS.java:''' &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSDAO.java/HibernateUpdateCSSDAO.java'''&lt;br /&gt;
The DAO files carry the primary responsibility of interaction with the DB layer in the MVC architecture.&amp;lt;br&amp;gt;&lt;br /&gt;
The data layer changes involved 3 separate components:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. liquibase.xml file to configure our new table: css_properties&amp;lt;br&amp;gt;&lt;br /&gt;
2. UpdateCSSDAO.java/HibernateUpdateCSSDAO.java - Interface/Implementation for DAO getter/setter.&amp;lt;br&amp;gt;&lt;br /&gt;
3. UpdateCSS.hbm.xml - Hibernate configuration file for mapping DAO to new properties table.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''liquibase.xml''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Liquibase is a method for automatically generating database changes at module startup.  We used this to add&amp;lt;br&amp;gt;&lt;br /&gt;
our new css_properties table.&lt;br /&gt;
''Hibernate''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSService.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSManageController.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517/M601_Design_Document&amp;diff=75204</id>
		<title>CSC/ECE 517/M601 Design Document</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517/M601_Design_Document&amp;diff=75204"/>
		<updated>2013-04-27T12:24:33Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: /* Specific Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;h1&amp;gt;Add ability to update css through webapp&amp;lt;/h1&amp;gt;&lt;br /&gt;
== Example Video ==&lt;br /&gt;
A video example of this module can be seen here [http://youtu.be/2dQeFYjcsnU]&lt;br /&gt;
==Team== &lt;br /&gt;
Yuri Kolesnikov &amp;lt;br&amp;gt;&lt;br /&gt;
Jonathan Wills &amp;lt;br&amp;gt;&lt;br /&gt;
Jeffrey Plemmons &amp;lt;br&amp;gt;&lt;br /&gt;
Roshna Agarwal&lt;br /&gt;
&lt;br /&gt;
==Our Work==&lt;br /&gt;
Link to the OpenMRS ticket: https://tickets.openmrs.org/browse/TRUNK-3415&amp;lt;br&amp;gt;&lt;br /&gt;
Link to our code in GitHub: https://github.com/ykolesn/openmrs-module-m601 &amp;lt;br&amp;gt;&lt;br /&gt;
Link to application: http://152.46.17.228:8081/openmrs-standalone&lt;br /&gt;
&lt;br /&gt;
==Purpose==&lt;br /&gt;
	The purpose of this module is to add the functionality of allowing the admin to customize the OpenMRS css file to their own specifications. By having the ability to customize the OpenMRS css file, the admin will be free to change the look and feel in their installation of OpenMRS.&lt;br /&gt;
&lt;br /&gt;
==Problem Definition==&lt;br /&gt;
	Add admin page for customization of the openmrs css file. Admins can 'override' any openmrs css with their own file by specifying that file in the openmrs runtime properties file.&lt;br /&gt;
This would be best as a new module in openmrs or perhaps just adding a new feature in the Custom Logo module? The admin should see a page with a large text box. The text box value should be persisted in the database as a new object/table/column somehow. When the module starts up, the Activator is called. Modify the activator to update the filesystem css file with whatever is defined by the admin.&lt;br /&gt;
&lt;br /&gt;
==Design Requirements==&lt;br /&gt;
&lt;br /&gt;
1. The admin should be able to customize the openmrs css file through an admin page. &amp;lt;br&amp;gt;&lt;br /&gt;
2. The admin should see a page with a large text box. &amp;lt;br&amp;gt;&lt;br /&gt;
3. The text box content should be stored in the database. &amp;lt;br&amp;gt;&lt;br /&gt;
4. The activator needs to be modified so that it updates the filesystem css file with whatever is defined by the admin. &amp;lt;br&amp;gt;&lt;br /&gt;
5. Need to use Eclipse and Maven as development tools for the module. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
'''Week 1'''&lt;br /&gt;
&lt;br /&gt;
*Get OpenMRS Id&lt;br /&gt;
*Get ticket assigned and in progress&lt;br /&gt;
*Get openmrs module name assigned&lt;br /&gt;
*Create openmrs module&lt;br /&gt;
*Commit module to github&lt;br /&gt;
*Check out module on partner machines&lt;br /&gt;
*Get new admin page link&lt;br /&gt;
*Create new spring controller and jsp page&lt;br /&gt;
'''Week 2'''&lt;br /&gt;
&lt;br /&gt;
*Create object for storing css in db&lt;br /&gt;
*Create service layer and dao layer methods to save object&lt;br /&gt;
*Connect controller to db object for saving + retrieving&lt;br /&gt;
*Add unit tests for saving/retrieving&lt;br /&gt;
'''Week 3'''&lt;br /&gt;
&lt;br /&gt;
*Create settings page to allow admin to choose where tomcat is running&lt;br /&gt;
*Add some magic so that module tries to guess where tomcat is running&lt;br /&gt;
*Add ability to put the saved css into the right folder in tomcat so that the css is actually overriding the openmrs style.css file.&lt;br /&gt;
&lt;br /&gt;
==Development Tools==&lt;br /&gt;
1. '''Eclipse'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Integrated_development_environment&amp;lt;/ref&amp;gt;: Eclipse is the Integrated Development Environment used to develop, modify, and compile the code for our module. &amp;lt;br&amp;gt;&lt;br /&gt;
2. '''Maven'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Maven&amp;lt;/ref&amp;gt;: Maven is used through a plug-in in Eclipse to compile, run unit tests, and package all of the Java files in the module.  &amp;lt;br&amp;gt;&lt;br /&gt;
3. '''Tomcat'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Tomcat&amp;lt;/ref&amp;gt;: Tomcat is the web-server used to run the application. &amp;lt;br&amp;gt; &lt;br /&gt;
4. '''Hibernate'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Hibernate_(Java)&amp;lt;/ref&amp;gt;: Hibernate is a built-in utility in the OpenMRS module, that is used to connect the Java classes to the database tables in the application. It configured the database table through an xml file: UpdateCSS.hbm.xml&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE hibernate-mapping PUBLIC&lt;br /&gt;
    &amp;quot;-//Hibernate/Hibernate Mapping DTD 3.0//EN&amp;quot;&lt;br /&gt;
    &amp;quot;http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&amp;quot; &amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hibernate-mapping package=&amp;quot;org.openmrs.module.updatecss&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;class name=&amp;quot;UpdateCSS&amp;quot;&lt;br /&gt;
	table=&amp;quot;css_properties&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;id name=&amp;quot;id&amp;quot; type=&amp;quot;int&amp;quot; column=&amp;quot;id&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;generator class=&amp;quot;native&amp;quot;/&amp;gt;&lt;br /&gt;
        &amp;lt;/id&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;cssData&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;css_location&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;homeDirectory&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;tomcat_home&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/class&amp;gt;&lt;br /&gt;
&amp;lt;/hibernate-mapping&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
''Here in the UpdateCSS.hbm.xml we specify the table name and columns. Hibernate generates the table with the fields specified and handles all the necessary SQL calls and queries.''&amp;lt;br&amp;gt;&lt;br /&gt;
5. '''MySQL''': MySQL&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Mysql&amp;lt;/ref&amp;gt; is the RDBMS that is used to store the CSS data for the application.&lt;br /&gt;
&lt;br /&gt;
==Use Case==&lt;br /&gt;
[[File:Openmrsui.png|800px|alt=OpenMRS UI]]&amp;lt;br&amp;gt;&lt;br /&gt;
''This is the user interface for the UpdateCSS module. The initial start screen provides a default location for the css style sheet and default css code. Here the navigation bar is changed to &amp;quot;orange&amp;quot;. ''&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
1. Log in to the Admin page with user &amp;quot;Admin&amp;quot; and password &amp;quot;Admin123&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
2. Once logged in, click on &amp;quot;Administration&amp;quot; on the right-hand side of the navigation bar. &amp;lt;br&amp;gt;&lt;br /&gt;
3. Under &amp;quot;Update CSS Module&amp;quot;, click on &amp;quot;Manage module&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
4. Here the user can enter their desired CSS preferences for customization. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Application Overview==&lt;br /&gt;
[[File:Overview.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt;Code Changes&amp;lt;/h1&amp;gt;&lt;br /&gt;
==Classes and Files Worked On==&lt;br /&gt;
* UpdateCSSActivator.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSS.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSService.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSServiceImpl.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSDAO.java &amp;lt;br&amp;gt;&lt;br /&gt;
* HibernateUpdateCSSDAO.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSS.hbm.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* liquibase.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* moduleApplicationContext.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSServiceTest.java &amp;lt;br&amp;gt;&lt;br /&gt;
* manage.jsp &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSManageController.java &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Specific Changes==&lt;br /&gt;
'''UpdateCSSActivator.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSServiceImpl.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
Added below methods to UpdateCSSServiceImpl class: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  /**&lt;br /&gt;
+   * Replaces the text of the specified CSS file in the&lt;br /&gt;
+   * specified directory with the specified text&lt;br /&gt;
+   */ +  public void copyCssDataToTomcatDirectory(String directory, String cssText) {&lt;br /&gt;
+    File cssFile = new File(directory);&lt;br /&gt;
+    if (cssFile.exists()) {&lt;br /&gt;
+      writeDataToFile(cssFile, cssText);&lt;br /&gt;
+    }&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Copies the data stored in the DB into the CSS file that is saved in the &lt;br /&gt;
+   * directory column of the css_properties table&lt;br /&gt;
+   */&lt;br /&gt;
+  public void copyCssDataToTomcatDirectory() {&lt;br /&gt;
+    UpdateCSS updateCSS = getData();&lt;br /&gt;
+    String cssDirectory = updateCSS.getHomeDirectory();&lt;br /&gt;
+    String cssText = updateCSS.getCssData();&lt;br /&gt;
+    copyCssDataToTomcatDirectory(cssDirectory, cssText);&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Writes the specified text to the specified CSS file&lt;br /&gt;
+   */&lt;br /&gt;
+  public void writeDataToFile(File cssFile, String cssText) {&lt;br /&gt;
+    try {&lt;br /&gt;
+      if (cssFile.exists()) {&lt;br /&gt;
+        PrintWriter writer = new PrintWriter(cssFile);&lt;br /&gt;
+        writer.print(cssText);&lt;br /&gt;
+        writer.close();&lt;br /&gt;
+      }&lt;br /&gt;
+    } catch (FileNotFoundException ex) {&lt;br /&gt;
+      &lt;br /&gt;
+    }&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Reads the data in the file at the specified path and returns&lt;br /&gt;
+   * a String with the contents. If the file doesn't exist&lt;br /&gt;
+   * then it returns an empty string&lt;br /&gt;
+   */&lt;br /&gt;
+  public String getCssTextFromFile(String filePath) {&lt;br /&gt;
+    String cssText = &amp;quot;&amp;quot;;&lt;br /&gt;
+    try {&lt;br /&gt;
+      File cssFile = new File(filePath);&lt;br /&gt;
+      if (cssFile.exists()) {&lt;br /&gt;
+        cssText = FileUtils.readFileToString(cssFile);&lt;br /&gt;
+      }  &lt;br /&gt;
+    } catch (IOException ex) {&lt;br /&gt;
+    &lt;br /&gt;
+    }&lt;br /&gt;
+    return cssText;&lt;br /&gt;
+  }&lt;br /&gt;
+    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''UpdateCSS.java:''' &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSDAO.java/HibernateUpdateCSSDAO.java'''&lt;br /&gt;
The DAO files carry the primary responsibility of interaction with the DB layer in the MVC architecture.&amp;lt;br&amp;gt;&lt;br /&gt;
The data layer changes involved 3 separate components:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. liquibase.xml file to configure our new table: css_properties&amp;lt;br&amp;gt;&lt;br /&gt;
2. UpdateCSSDAO.java/HibernateUpdateCSSDAO.java - Interface/Implementation for DAO getter/setter.&amp;lt;br&amp;gt;&lt;br /&gt;
3. UpdateCSS.hbm.xml - Hibernate configuration file for mapping DAO to new properties table.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''Hibernate''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSService.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSManageController.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517/M601_Design_Document&amp;diff=75203</id>
		<title>CSC/ECE 517/M601 Design Document</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517/M601_Design_Document&amp;diff=75203"/>
		<updated>2013-04-27T12:24:06Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: /* Hibernate */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;h1&amp;gt;Add ability to update css through webapp&amp;lt;/h1&amp;gt;&lt;br /&gt;
== Example Video ==&lt;br /&gt;
A video example of this module can be seen here [http://youtu.be/2dQeFYjcsnU]&lt;br /&gt;
==Team== &lt;br /&gt;
Yuri Kolesnikov &amp;lt;br&amp;gt;&lt;br /&gt;
Jonathan Wills &amp;lt;br&amp;gt;&lt;br /&gt;
Jeffrey Plemmons &amp;lt;br&amp;gt;&lt;br /&gt;
Roshna Agarwal&lt;br /&gt;
&lt;br /&gt;
==Our Work==&lt;br /&gt;
Link to the OpenMRS ticket: https://tickets.openmrs.org/browse/TRUNK-3415&amp;lt;br&amp;gt;&lt;br /&gt;
Link to our code in GitHub: https://github.com/ykolesn/openmrs-module-m601 &amp;lt;br&amp;gt;&lt;br /&gt;
Link to application: http://152.46.17.228:8081/openmrs-standalone&lt;br /&gt;
&lt;br /&gt;
==Purpose==&lt;br /&gt;
	The purpose of this module is to add the functionality of allowing the admin to customize the OpenMRS css file to their own specifications. By having the ability to customize the OpenMRS css file, the admin will be free to change the look and feel in their installation of OpenMRS.&lt;br /&gt;
&lt;br /&gt;
==Problem Definition==&lt;br /&gt;
	Add admin page for customization of the openmrs css file. Admins can 'override' any openmrs css with their own file by specifying that file in the openmrs runtime properties file.&lt;br /&gt;
This would be best as a new module in openmrs or perhaps just adding a new feature in the Custom Logo module? The admin should see a page with a large text box. The text box value should be persisted in the database as a new object/table/column somehow. When the module starts up, the Activator is called. Modify the activator to update the filesystem css file with whatever is defined by the admin.&lt;br /&gt;
&lt;br /&gt;
==Design Requirements==&lt;br /&gt;
&lt;br /&gt;
1. The admin should be able to customize the openmrs css file through an admin page. &amp;lt;br&amp;gt;&lt;br /&gt;
2. The admin should see a page with a large text box. &amp;lt;br&amp;gt;&lt;br /&gt;
3. The text box content should be stored in the database. &amp;lt;br&amp;gt;&lt;br /&gt;
4. The activator needs to be modified so that it updates the filesystem css file with whatever is defined by the admin. &amp;lt;br&amp;gt;&lt;br /&gt;
5. Need to use Eclipse and Maven as development tools for the module. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
'''Week 1'''&lt;br /&gt;
&lt;br /&gt;
*Get OpenMRS Id&lt;br /&gt;
*Get ticket assigned and in progress&lt;br /&gt;
*Get openmrs module name assigned&lt;br /&gt;
*Create openmrs module&lt;br /&gt;
*Commit module to github&lt;br /&gt;
*Check out module on partner machines&lt;br /&gt;
*Get new admin page link&lt;br /&gt;
*Create new spring controller and jsp page&lt;br /&gt;
'''Week 2'''&lt;br /&gt;
&lt;br /&gt;
*Create object for storing css in db&lt;br /&gt;
*Create service layer and dao layer methods to save object&lt;br /&gt;
*Connect controller to db object for saving + retrieving&lt;br /&gt;
*Add unit tests for saving/retrieving&lt;br /&gt;
'''Week 3'''&lt;br /&gt;
&lt;br /&gt;
*Create settings page to allow admin to choose where tomcat is running&lt;br /&gt;
*Add some magic so that module tries to guess where tomcat is running&lt;br /&gt;
*Add ability to put the saved css into the right folder in tomcat so that the css is actually overriding the openmrs style.css file.&lt;br /&gt;
&lt;br /&gt;
==Development Tools==&lt;br /&gt;
1. '''Eclipse'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Integrated_development_environment&amp;lt;/ref&amp;gt;: Eclipse is the Integrated Development Environment used to develop, modify, and compile the code for our module. &amp;lt;br&amp;gt;&lt;br /&gt;
2. '''Maven'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Maven&amp;lt;/ref&amp;gt;: Maven is used through a plug-in in Eclipse to compile, run unit tests, and package all of the Java files in the module.  &amp;lt;br&amp;gt;&lt;br /&gt;
3. '''Tomcat'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Tomcat&amp;lt;/ref&amp;gt;: Tomcat is the web-server used to run the application. &amp;lt;br&amp;gt; &lt;br /&gt;
4. '''Hibernate'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Hibernate_(Java)&amp;lt;/ref&amp;gt;: Hibernate is a built-in utility in the OpenMRS module, that is used to connect the Java classes to the database tables in the application. It configured the database table through an xml file: UpdateCSS.hbm.xml&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE hibernate-mapping PUBLIC&lt;br /&gt;
    &amp;quot;-//Hibernate/Hibernate Mapping DTD 3.0//EN&amp;quot;&lt;br /&gt;
    &amp;quot;http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&amp;quot; &amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hibernate-mapping package=&amp;quot;org.openmrs.module.updatecss&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;class name=&amp;quot;UpdateCSS&amp;quot;&lt;br /&gt;
	table=&amp;quot;css_properties&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;id name=&amp;quot;id&amp;quot; type=&amp;quot;int&amp;quot; column=&amp;quot;id&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;generator class=&amp;quot;native&amp;quot;/&amp;gt;&lt;br /&gt;
        &amp;lt;/id&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;cssData&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;css_location&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;homeDirectory&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;tomcat_home&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/class&amp;gt;&lt;br /&gt;
&amp;lt;/hibernate-mapping&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
''Here in the UpdateCSS.hbm.xml we specify the table name and columns. Hibernate generates the table with the fields specified and handles all the necessary SQL calls and queries.''&amp;lt;br&amp;gt;&lt;br /&gt;
5. '''MySQL''': MySQL&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Mysql&amp;lt;/ref&amp;gt; is the RDBMS that is used to store the CSS data for the application.&lt;br /&gt;
&lt;br /&gt;
==Use Case==&lt;br /&gt;
[[File:Openmrsui.png|800px|alt=OpenMRS UI]]&amp;lt;br&amp;gt;&lt;br /&gt;
''This is the user interface for the UpdateCSS module. The initial start screen provides a default location for the css style sheet and default css code. Here the navigation bar is changed to &amp;quot;orange&amp;quot;. ''&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
1. Log in to the Admin page with user &amp;quot;Admin&amp;quot; and password &amp;quot;Admin123&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
2. Once logged in, click on &amp;quot;Administration&amp;quot; on the right-hand side of the navigation bar. &amp;lt;br&amp;gt;&lt;br /&gt;
3. Under &amp;quot;Update CSS Module&amp;quot;, click on &amp;quot;Manage module&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
4. Here the user can enter their desired CSS preferences for customization. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Application Overview==&lt;br /&gt;
[[File:Overview.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt;Code Changes&amp;lt;/h1&amp;gt;&lt;br /&gt;
==Classes and Files Worked On==&lt;br /&gt;
* UpdateCSSActivator.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSS.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSService.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSServiceImpl.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSDAO.java &amp;lt;br&amp;gt;&lt;br /&gt;
* HibernateUpdateCSSDAO.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSS.hbm.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* liquibase.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* moduleApplicationContext.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSServiceTest.java &amp;lt;br&amp;gt;&lt;br /&gt;
* manage.jsp &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSManageController.java &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Specific Changes==&lt;br /&gt;
'''UpdateCSSActivator.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSServiceImpl.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
Added below methods to UpdateCSSServiceImpl class: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  /**&lt;br /&gt;
+   * Replaces the text of the specified CSS file in the&lt;br /&gt;
+   * specified directory with the specified text&lt;br /&gt;
+   */ +  public void copyCssDataToTomcatDirectory(String directory, String cssText) {&lt;br /&gt;
+    File cssFile = new File(directory);&lt;br /&gt;
+    if (cssFile.exists()) {&lt;br /&gt;
+      writeDataToFile(cssFile, cssText);&lt;br /&gt;
+    }&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Copies the data stored in the DB into the CSS file that is saved in the &lt;br /&gt;
+   * directory column of the css_properties table&lt;br /&gt;
+   */&lt;br /&gt;
+  public void copyCssDataToTomcatDirectory() {&lt;br /&gt;
+    UpdateCSS updateCSS = getData();&lt;br /&gt;
+    String cssDirectory = updateCSS.getHomeDirectory();&lt;br /&gt;
+    String cssText = updateCSS.getCssData();&lt;br /&gt;
+    copyCssDataToTomcatDirectory(cssDirectory, cssText);&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Writes the specified text to the specified CSS file&lt;br /&gt;
+   */&lt;br /&gt;
+  public void writeDataToFile(File cssFile, String cssText) {&lt;br /&gt;
+    try {&lt;br /&gt;
+      if (cssFile.exists()) {&lt;br /&gt;
+        PrintWriter writer = new PrintWriter(cssFile);&lt;br /&gt;
+        writer.print(cssText);&lt;br /&gt;
+        writer.close();&lt;br /&gt;
+      }&lt;br /&gt;
+    } catch (FileNotFoundException ex) {&lt;br /&gt;
+      &lt;br /&gt;
+    }&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Reads the data in the file at the specified path and returns&lt;br /&gt;
+   * a String with the contents. If the file doesn't exist&lt;br /&gt;
+   * then it returns an empty string&lt;br /&gt;
+   */&lt;br /&gt;
+  public String getCssTextFromFile(String filePath) {&lt;br /&gt;
+    String cssText = &amp;quot;&amp;quot;;&lt;br /&gt;
+    try {&lt;br /&gt;
+      File cssFile = new File(filePath);&lt;br /&gt;
+      if (cssFile.exists()) {&lt;br /&gt;
+        cssText = FileUtils.readFileToString(cssFile);&lt;br /&gt;
+      }  &lt;br /&gt;
+    } catch (IOException ex) {&lt;br /&gt;
+    &lt;br /&gt;
+    }&lt;br /&gt;
+    return cssText;&lt;br /&gt;
+  }&lt;br /&gt;
+    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''UpdateCSS.java:''' &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSDAO.java/HibernateUpdateCSSDAO.java'''&lt;br /&gt;
The DAO files carry the primary responsibility of interaction with the DB layer in the MVC architecture.&amp;lt;br&amp;gt;&lt;br /&gt;
The data layer changes involved 3 separate components:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. liquibase.xml file to configure our new table: css_properties&amp;lt;br&amp;gt;&lt;br /&gt;
2. UpdateCSSDAO.java/HibernateUpdateCSSDAO.java - Interface/Implementation for DAO getter/setter.&amp;lt;br&amp;gt;&lt;br /&gt;
3. UpdateCSS.hbm.xml - Hibernate configuration file for mapping DAO to new properties table.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''Hibernate''&lt;br /&gt;
'''UpdateCSSService.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSManageController.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517/M601_Design_Document&amp;diff=75202</id>
		<title>CSC/ECE 517/M601 Design Document</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517/M601_Design_Document&amp;diff=75202"/>
		<updated>2013-04-27T12:23:44Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: /* UpdateCSSDAO.java/HibernateUpdateCSSDAO.java */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;h1&amp;gt;Add ability to update css through webapp&amp;lt;/h1&amp;gt;&lt;br /&gt;
== Example Video ==&lt;br /&gt;
A video example of this module can be seen here [http://youtu.be/2dQeFYjcsnU]&lt;br /&gt;
==Team== &lt;br /&gt;
Yuri Kolesnikov &amp;lt;br&amp;gt;&lt;br /&gt;
Jonathan Wills &amp;lt;br&amp;gt;&lt;br /&gt;
Jeffrey Plemmons &amp;lt;br&amp;gt;&lt;br /&gt;
Roshna Agarwal&lt;br /&gt;
&lt;br /&gt;
==Our Work==&lt;br /&gt;
Link to the OpenMRS ticket: https://tickets.openmrs.org/browse/TRUNK-3415&amp;lt;br&amp;gt;&lt;br /&gt;
Link to our code in GitHub: https://github.com/ykolesn/openmrs-module-m601 &amp;lt;br&amp;gt;&lt;br /&gt;
Link to application: http://152.46.17.228:8081/openmrs-standalone&lt;br /&gt;
&lt;br /&gt;
==Purpose==&lt;br /&gt;
	The purpose of this module is to add the functionality of allowing the admin to customize the OpenMRS css file to their own specifications. By having the ability to customize the OpenMRS css file, the admin will be free to change the look and feel in their installation of OpenMRS.&lt;br /&gt;
&lt;br /&gt;
==Problem Definition==&lt;br /&gt;
	Add admin page for customization of the openmrs css file. Admins can 'override' any openmrs css with their own file by specifying that file in the openmrs runtime properties file.&lt;br /&gt;
This would be best as a new module in openmrs or perhaps just adding a new feature in the Custom Logo module? The admin should see a page with a large text box. The text box value should be persisted in the database as a new object/table/column somehow. When the module starts up, the Activator is called. Modify the activator to update the filesystem css file with whatever is defined by the admin.&lt;br /&gt;
&lt;br /&gt;
==Design Requirements==&lt;br /&gt;
&lt;br /&gt;
1. The admin should be able to customize the openmrs css file through an admin page. &amp;lt;br&amp;gt;&lt;br /&gt;
2. The admin should see a page with a large text box. &amp;lt;br&amp;gt;&lt;br /&gt;
3. The text box content should be stored in the database. &amp;lt;br&amp;gt;&lt;br /&gt;
4. The activator needs to be modified so that it updates the filesystem css file with whatever is defined by the admin. &amp;lt;br&amp;gt;&lt;br /&gt;
5. Need to use Eclipse and Maven as development tools for the module. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
'''Week 1'''&lt;br /&gt;
&lt;br /&gt;
*Get OpenMRS Id&lt;br /&gt;
*Get ticket assigned and in progress&lt;br /&gt;
*Get openmrs module name assigned&lt;br /&gt;
*Create openmrs module&lt;br /&gt;
*Commit module to github&lt;br /&gt;
*Check out module on partner machines&lt;br /&gt;
*Get new admin page link&lt;br /&gt;
*Create new spring controller and jsp page&lt;br /&gt;
'''Week 2'''&lt;br /&gt;
&lt;br /&gt;
*Create object for storing css in db&lt;br /&gt;
*Create service layer and dao layer methods to save object&lt;br /&gt;
*Connect controller to db object for saving + retrieving&lt;br /&gt;
*Add unit tests for saving/retrieving&lt;br /&gt;
'''Week 3'''&lt;br /&gt;
&lt;br /&gt;
*Create settings page to allow admin to choose where tomcat is running&lt;br /&gt;
*Add some magic so that module tries to guess where tomcat is running&lt;br /&gt;
*Add ability to put the saved css into the right folder in tomcat so that the css is actually overriding the openmrs style.css file.&lt;br /&gt;
&lt;br /&gt;
==Development Tools==&lt;br /&gt;
1. '''Eclipse'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Integrated_development_environment&amp;lt;/ref&amp;gt;: Eclipse is the Integrated Development Environment used to develop, modify, and compile the code for our module. &amp;lt;br&amp;gt;&lt;br /&gt;
2. '''Maven'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Maven&amp;lt;/ref&amp;gt;: Maven is used through a plug-in in Eclipse to compile, run unit tests, and package all of the Java files in the module.  &amp;lt;br&amp;gt;&lt;br /&gt;
3. '''Tomcat'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Tomcat&amp;lt;/ref&amp;gt;: Tomcat is the web-server used to run the application. &amp;lt;br&amp;gt; &lt;br /&gt;
4. '''Hibernate'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Hibernate_(Java)&amp;lt;/ref&amp;gt;: Hibernate is a built-in utility in the OpenMRS module, that is used to connect the Java classes to the database tables in the application. It configured the database table through an xml file: UpdateCSS.hbm.xml&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE hibernate-mapping PUBLIC&lt;br /&gt;
    &amp;quot;-//Hibernate/Hibernate Mapping DTD 3.0//EN&amp;quot;&lt;br /&gt;
    &amp;quot;http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&amp;quot; &amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hibernate-mapping package=&amp;quot;org.openmrs.module.updatecss&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;class name=&amp;quot;UpdateCSS&amp;quot;&lt;br /&gt;
	table=&amp;quot;css_properties&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;id name=&amp;quot;id&amp;quot; type=&amp;quot;int&amp;quot; column=&amp;quot;id&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;generator class=&amp;quot;native&amp;quot;/&amp;gt;&lt;br /&gt;
        &amp;lt;/id&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;cssData&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;css_location&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;homeDirectory&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;tomcat_home&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/class&amp;gt;&lt;br /&gt;
&amp;lt;/hibernate-mapping&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
''Here in the UpdateCSS.hbm.xml we specify the table name and columns. Hibernate generates the table with the fields specified and handles all the necessary SQL calls and queries.''&amp;lt;br&amp;gt;&lt;br /&gt;
5. '''MySQL''': MySQL&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Mysql&amp;lt;/ref&amp;gt; is the RDBMS that is used to store the CSS data for the application.&lt;br /&gt;
&lt;br /&gt;
==Use Case==&lt;br /&gt;
[[File:Openmrsui.png|800px|alt=OpenMRS UI]]&amp;lt;br&amp;gt;&lt;br /&gt;
''This is the user interface for the UpdateCSS module. The initial start screen provides a default location for the css style sheet and default css code. Here the navigation bar is changed to &amp;quot;orange&amp;quot;. ''&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
1. Log in to the Admin page with user &amp;quot;Admin&amp;quot; and password &amp;quot;Admin123&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
2. Once logged in, click on &amp;quot;Administration&amp;quot; on the right-hand side of the navigation bar. &amp;lt;br&amp;gt;&lt;br /&gt;
3. Under &amp;quot;Update CSS Module&amp;quot;, click on &amp;quot;Manage module&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
4. Here the user can enter their desired CSS preferences for customization. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Application Overview==&lt;br /&gt;
[[File:Overview.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt;Code Changes&amp;lt;/h1&amp;gt;&lt;br /&gt;
==Classes and Files Worked On==&lt;br /&gt;
* UpdateCSSActivator.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSS.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSService.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSServiceImpl.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSDAO.java &amp;lt;br&amp;gt;&lt;br /&gt;
* HibernateUpdateCSSDAO.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSS.hbm.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* liquibase.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* moduleApplicationContext.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSServiceTest.java &amp;lt;br&amp;gt;&lt;br /&gt;
* manage.jsp &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSManageController.java &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Specific Changes==&lt;br /&gt;
'''UpdateCSSActivator.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSServiceImpl.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
Added below methods to UpdateCSSServiceImpl class: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  /**&lt;br /&gt;
+   * Replaces the text of the specified CSS file in the&lt;br /&gt;
+   * specified directory with the specified text&lt;br /&gt;
+   */ +  public void copyCssDataToTomcatDirectory(String directory, String cssText) {&lt;br /&gt;
+    File cssFile = new File(directory);&lt;br /&gt;
+    if (cssFile.exists()) {&lt;br /&gt;
+      writeDataToFile(cssFile, cssText);&lt;br /&gt;
+    }&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Copies the data stored in the DB into the CSS file that is saved in the &lt;br /&gt;
+   * directory column of the css_properties table&lt;br /&gt;
+   */&lt;br /&gt;
+  public void copyCssDataToTomcatDirectory() {&lt;br /&gt;
+    UpdateCSS updateCSS = getData();&lt;br /&gt;
+    String cssDirectory = updateCSS.getHomeDirectory();&lt;br /&gt;
+    String cssText = updateCSS.getCssData();&lt;br /&gt;
+    copyCssDataToTomcatDirectory(cssDirectory, cssText);&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Writes the specified text to the specified CSS file&lt;br /&gt;
+   */&lt;br /&gt;
+  public void writeDataToFile(File cssFile, String cssText) {&lt;br /&gt;
+    try {&lt;br /&gt;
+      if (cssFile.exists()) {&lt;br /&gt;
+        PrintWriter writer = new PrintWriter(cssFile);&lt;br /&gt;
+        writer.print(cssText);&lt;br /&gt;
+        writer.close();&lt;br /&gt;
+      }&lt;br /&gt;
+    } catch (FileNotFoundException ex) {&lt;br /&gt;
+      &lt;br /&gt;
+    }&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Reads the data in the file at the specified path and returns&lt;br /&gt;
+   * a String with the contents. If the file doesn't exist&lt;br /&gt;
+   * then it returns an empty string&lt;br /&gt;
+   */&lt;br /&gt;
+  public String getCssTextFromFile(String filePath) {&lt;br /&gt;
+    String cssText = &amp;quot;&amp;quot;;&lt;br /&gt;
+    try {&lt;br /&gt;
+      File cssFile = new File(filePath);&lt;br /&gt;
+      if (cssFile.exists()) {&lt;br /&gt;
+        cssText = FileUtils.readFileToString(cssFile);&lt;br /&gt;
+      }  &lt;br /&gt;
+    } catch (IOException ex) {&lt;br /&gt;
+    &lt;br /&gt;
+    }&lt;br /&gt;
+    return cssText;&lt;br /&gt;
+  }&lt;br /&gt;
+    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''UpdateCSS.java:''' &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSDAO.java/HibernateUpdateCSSDAO.java'''&lt;br /&gt;
The DAO files carry the primary responsibility of interaction with the DB layer in the MVC architecture.&amp;lt;br&amp;gt;&lt;br /&gt;
The data layer changes involved 3 separate components:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. liquibase.xml file to configure our new table: css_properties&amp;lt;br&amp;gt;&lt;br /&gt;
2. UpdateCSSDAO.java/HibernateUpdateCSSDAO.java - Interface/Implementation for DAO getter/setter.&amp;lt;br&amp;gt;&lt;br /&gt;
3. UpdateCSS.hbm.xml - Hibernate configuration file for mapping DAO to new properties table.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Hibernate==&lt;br /&gt;
'''UpdateCSSService.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSManageController.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517/M601_Design_Document&amp;diff=75201</id>
		<title>CSC/ECE 517/M601 Design Document</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517/M601_Design_Document&amp;diff=75201"/>
		<updated>2013-04-27T12:23:20Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: /* liquibase.xml */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;h1&amp;gt;Add ability to update css through webapp&amp;lt;/h1&amp;gt;&lt;br /&gt;
== Example Video ==&lt;br /&gt;
A video example of this module can be seen here [http://youtu.be/2dQeFYjcsnU]&lt;br /&gt;
==Team== &lt;br /&gt;
Yuri Kolesnikov &amp;lt;br&amp;gt;&lt;br /&gt;
Jonathan Wills &amp;lt;br&amp;gt;&lt;br /&gt;
Jeffrey Plemmons &amp;lt;br&amp;gt;&lt;br /&gt;
Roshna Agarwal&lt;br /&gt;
&lt;br /&gt;
==Our Work==&lt;br /&gt;
Link to the OpenMRS ticket: https://tickets.openmrs.org/browse/TRUNK-3415&amp;lt;br&amp;gt;&lt;br /&gt;
Link to our code in GitHub: https://github.com/ykolesn/openmrs-module-m601 &amp;lt;br&amp;gt;&lt;br /&gt;
Link to application: http://152.46.17.228:8081/openmrs-standalone&lt;br /&gt;
&lt;br /&gt;
==Purpose==&lt;br /&gt;
	The purpose of this module is to add the functionality of allowing the admin to customize the OpenMRS css file to their own specifications. By having the ability to customize the OpenMRS css file, the admin will be free to change the look and feel in their installation of OpenMRS.&lt;br /&gt;
&lt;br /&gt;
==Problem Definition==&lt;br /&gt;
	Add admin page for customization of the openmrs css file. Admins can 'override' any openmrs css with their own file by specifying that file in the openmrs runtime properties file.&lt;br /&gt;
This would be best as a new module in openmrs or perhaps just adding a new feature in the Custom Logo module? The admin should see a page with a large text box. The text box value should be persisted in the database as a new object/table/column somehow. When the module starts up, the Activator is called. Modify the activator to update the filesystem css file with whatever is defined by the admin.&lt;br /&gt;
&lt;br /&gt;
==Design Requirements==&lt;br /&gt;
&lt;br /&gt;
1. The admin should be able to customize the openmrs css file through an admin page. &amp;lt;br&amp;gt;&lt;br /&gt;
2. The admin should see a page with a large text box. &amp;lt;br&amp;gt;&lt;br /&gt;
3. The text box content should be stored in the database. &amp;lt;br&amp;gt;&lt;br /&gt;
4. The activator needs to be modified so that it updates the filesystem css file with whatever is defined by the admin. &amp;lt;br&amp;gt;&lt;br /&gt;
5. Need to use Eclipse and Maven as development tools for the module. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
'''Week 1'''&lt;br /&gt;
&lt;br /&gt;
*Get OpenMRS Id&lt;br /&gt;
*Get ticket assigned and in progress&lt;br /&gt;
*Get openmrs module name assigned&lt;br /&gt;
*Create openmrs module&lt;br /&gt;
*Commit module to github&lt;br /&gt;
*Check out module on partner machines&lt;br /&gt;
*Get new admin page link&lt;br /&gt;
*Create new spring controller and jsp page&lt;br /&gt;
'''Week 2'''&lt;br /&gt;
&lt;br /&gt;
*Create object for storing css in db&lt;br /&gt;
*Create service layer and dao layer methods to save object&lt;br /&gt;
*Connect controller to db object for saving + retrieving&lt;br /&gt;
*Add unit tests for saving/retrieving&lt;br /&gt;
'''Week 3'''&lt;br /&gt;
&lt;br /&gt;
*Create settings page to allow admin to choose where tomcat is running&lt;br /&gt;
*Add some magic so that module tries to guess where tomcat is running&lt;br /&gt;
*Add ability to put the saved css into the right folder in tomcat so that the css is actually overriding the openmrs style.css file.&lt;br /&gt;
&lt;br /&gt;
==Development Tools==&lt;br /&gt;
1. '''Eclipse'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Integrated_development_environment&amp;lt;/ref&amp;gt;: Eclipse is the Integrated Development Environment used to develop, modify, and compile the code for our module. &amp;lt;br&amp;gt;&lt;br /&gt;
2. '''Maven'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Maven&amp;lt;/ref&amp;gt;: Maven is used through a plug-in in Eclipse to compile, run unit tests, and package all of the Java files in the module.  &amp;lt;br&amp;gt;&lt;br /&gt;
3. '''Tomcat'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Tomcat&amp;lt;/ref&amp;gt;: Tomcat is the web-server used to run the application. &amp;lt;br&amp;gt; &lt;br /&gt;
4. '''Hibernate'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Hibernate_(Java)&amp;lt;/ref&amp;gt;: Hibernate is a built-in utility in the OpenMRS module, that is used to connect the Java classes to the database tables in the application. It configured the database table through an xml file: UpdateCSS.hbm.xml&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE hibernate-mapping PUBLIC&lt;br /&gt;
    &amp;quot;-//Hibernate/Hibernate Mapping DTD 3.0//EN&amp;quot;&lt;br /&gt;
    &amp;quot;http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&amp;quot; &amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hibernate-mapping package=&amp;quot;org.openmrs.module.updatecss&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;class name=&amp;quot;UpdateCSS&amp;quot;&lt;br /&gt;
	table=&amp;quot;css_properties&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;id name=&amp;quot;id&amp;quot; type=&amp;quot;int&amp;quot; column=&amp;quot;id&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;generator class=&amp;quot;native&amp;quot;/&amp;gt;&lt;br /&gt;
        &amp;lt;/id&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;cssData&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;css_location&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;homeDirectory&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;tomcat_home&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/class&amp;gt;&lt;br /&gt;
&amp;lt;/hibernate-mapping&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
''Here in the UpdateCSS.hbm.xml we specify the table name and columns. Hibernate generates the table with the fields specified and handles all the necessary SQL calls and queries.''&amp;lt;br&amp;gt;&lt;br /&gt;
5. '''MySQL''': MySQL&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Mysql&amp;lt;/ref&amp;gt; is the RDBMS that is used to store the CSS data for the application.&lt;br /&gt;
&lt;br /&gt;
==Use Case==&lt;br /&gt;
[[File:Openmrsui.png|800px|alt=OpenMRS UI]]&amp;lt;br&amp;gt;&lt;br /&gt;
''This is the user interface for the UpdateCSS module. The initial start screen provides a default location for the css style sheet and default css code. Here the navigation bar is changed to &amp;quot;orange&amp;quot;. ''&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
1. Log in to the Admin page with user &amp;quot;Admin&amp;quot; and password &amp;quot;Admin123&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
2. Once logged in, click on &amp;quot;Administration&amp;quot; on the right-hand side of the navigation bar. &amp;lt;br&amp;gt;&lt;br /&gt;
3. Under &amp;quot;Update CSS Module&amp;quot;, click on &amp;quot;Manage module&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
4. Here the user can enter their desired CSS preferences for customization. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Application Overview==&lt;br /&gt;
[[File:Overview.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt;Code Changes&amp;lt;/h1&amp;gt;&lt;br /&gt;
==Classes and Files Worked On==&lt;br /&gt;
* UpdateCSSActivator.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSS.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSService.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSServiceImpl.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSDAO.java &amp;lt;br&amp;gt;&lt;br /&gt;
* HibernateUpdateCSSDAO.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSS.hbm.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* liquibase.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* moduleApplicationContext.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSServiceTest.java &amp;lt;br&amp;gt;&lt;br /&gt;
* manage.jsp &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSManageController.java &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Specific Changes==&lt;br /&gt;
'''UpdateCSSActivator.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSServiceImpl.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
Added below methods to UpdateCSSServiceImpl class: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  /**&lt;br /&gt;
+   * Replaces the text of the specified CSS file in the&lt;br /&gt;
+   * specified directory with the specified text&lt;br /&gt;
+   */ +  public void copyCssDataToTomcatDirectory(String directory, String cssText) {&lt;br /&gt;
+    File cssFile = new File(directory);&lt;br /&gt;
+    if (cssFile.exists()) {&lt;br /&gt;
+      writeDataToFile(cssFile, cssText);&lt;br /&gt;
+    }&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Copies the data stored in the DB into the CSS file that is saved in the &lt;br /&gt;
+   * directory column of the css_properties table&lt;br /&gt;
+   */&lt;br /&gt;
+  public void copyCssDataToTomcatDirectory() {&lt;br /&gt;
+    UpdateCSS updateCSS = getData();&lt;br /&gt;
+    String cssDirectory = updateCSS.getHomeDirectory();&lt;br /&gt;
+    String cssText = updateCSS.getCssData();&lt;br /&gt;
+    copyCssDataToTomcatDirectory(cssDirectory, cssText);&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Writes the specified text to the specified CSS file&lt;br /&gt;
+   */&lt;br /&gt;
+  public void writeDataToFile(File cssFile, String cssText) {&lt;br /&gt;
+    try {&lt;br /&gt;
+      if (cssFile.exists()) {&lt;br /&gt;
+        PrintWriter writer = new PrintWriter(cssFile);&lt;br /&gt;
+        writer.print(cssText);&lt;br /&gt;
+        writer.close();&lt;br /&gt;
+      }&lt;br /&gt;
+    } catch (FileNotFoundException ex) {&lt;br /&gt;
+      &lt;br /&gt;
+    }&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Reads the data in the file at the specified path and returns&lt;br /&gt;
+   * a String with the contents. If the file doesn't exist&lt;br /&gt;
+   * then it returns an empty string&lt;br /&gt;
+   */&lt;br /&gt;
+  public String getCssTextFromFile(String filePath) {&lt;br /&gt;
+    String cssText = &amp;quot;&amp;quot;;&lt;br /&gt;
+    try {&lt;br /&gt;
+      File cssFile = new File(filePath);&lt;br /&gt;
+      if (cssFile.exists()) {&lt;br /&gt;
+        cssText = FileUtils.readFileToString(cssFile);&lt;br /&gt;
+      }  &lt;br /&gt;
+    } catch (IOException ex) {&lt;br /&gt;
+    &lt;br /&gt;
+    }&lt;br /&gt;
+    return cssText;&lt;br /&gt;
+  }&lt;br /&gt;
+    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''UpdateCSS.java:''' &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
==UpdateCSSDAO.java/HibernateUpdateCSSDAO.java==&lt;br /&gt;
The DAO files carry the primary responsibility of interaction with the DB layer in the MVC architecture.&amp;lt;br&amp;gt;&lt;br /&gt;
The data layer changes involved 3 separate components:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. liquibase.xml file to configure our new table: css_properties&amp;lt;br&amp;gt;&lt;br /&gt;
2. UpdateCSSDAO.java/HibernateUpdateCSSDAO.java - Interface/Implementation for DAO getter/setter.&amp;lt;br&amp;gt;&lt;br /&gt;
3. UpdateCSS.hbm.xml - Hibernate configuration file for mapping DAO to new properties table.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Hibernate==&lt;br /&gt;
'''UpdateCSSService.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSManageController.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517/M601_Design_Document&amp;diff=75200</id>
		<title>CSC/ECE 517/M601 Design Document</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517/M601_Design_Document&amp;diff=75200"/>
		<updated>2013-04-27T12:22:28Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: /* Specific Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;h1&amp;gt;Add ability to update css through webapp&amp;lt;/h1&amp;gt;&lt;br /&gt;
== Example Video ==&lt;br /&gt;
A video example of this module can be seen here [http://youtu.be/2dQeFYjcsnU]&lt;br /&gt;
==Team== &lt;br /&gt;
Yuri Kolesnikov &amp;lt;br&amp;gt;&lt;br /&gt;
Jonathan Wills &amp;lt;br&amp;gt;&lt;br /&gt;
Jeffrey Plemmons &amp;lt;br&amp;gt;&lt;br /&gt;
Roshna Agarwal&lt;br /&gt;
&lt;br /&gt;
==Our Work==&lt;br /&gt;
Link to the OpenMRS ticket: https://tickets.openmrs.org/browse/TRUNK-3415&amp;lt;br&amp;gt;&lt;br /&gt;
Link to our code in GitHub: https://github.com/ykolesn/openmrs-module-m601 &amp;lt;br&amp;gt;&lt;br /&gt;
Link to application: http://152.46.17.228:8081/openmrs-standalone&lt;br /&gt;
&lt;br /&gt;
==Purpose==&lt;br /&gt;
	The purpose of this module is to add the functionality of allowing the admin to customize the OpenMRS css file to their own specifications. By having the ability to customize the OpenMRS css file, the admin will be free to change the look and feel in their installation of OpenMRS.&lt;br /&gt;
&lt;br /&gt;
==Problem Definition==&lt;br /&gt;
	Add admin page for customization of the openmrs css file. Admins can 'override' any openmrs css with their own file by specifying that file in the openmrs runtime properties file.&lt;br /&gt;
This would be best as a new module in openmrs or perhaps just adding a new feature in the Custom Logo module? The admin should see a page with a large text box. The text box value should be persisted in the database as a new object/table/column somehow. When the module starts up, the Activator is called. Modify the activator to update the filesystem css file with whatever is defined by the admin.&lt;br /&gt;
&lt;br /&gt;
==Design Requirements==&lt;br /&gt;
&lt;br /&gt;
1. The admin should be able to customize the openmrs css file through an admin page. &amp;lt;br&amp;gt;&lt;br /&gt;
2. The admin should see a page with a large text box. &amp;lt;br&amp;gt;&lt;br /&gt;
3. The text box content should be stored in the database. &amp;lt;br&amp;gt;&lt;br /&gt;
4. The activator needs to be modified so that it updates the filesystem css file with whatever is defined by the admin. &amp;lt;br&amp;gt;&lt;br /&gt;
5. Need to use Eclipse and Maven as development tools for the module. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
'''Week 1'''&lt;br /&gt;
&lt;br /&gt;
*Get OpenMRS Id&lt;br /&gt;
*Get ticket assigned and in progress&lt;br /&gt;
*Get openmrs module name assigned&lt;br /&gt;
*Create openmrs module&lt;br /&gt;
*Commit module to github&lt;br /&gt;
*Check out module on partner machines&lt;br /&gt;
*Get new admin page link&lt;br /&gt;
*Create new spring controller and jsp page&lt;br /&gt;
'''Week 2'''&lt;br /&gt;
&lt;br /&gt;
*Create object for storing css in db&lt;br /&gt;
*Create service layer and dao layer methods to save object&lt;br /&gt;
*Connect controller to db object for saving + retrieving&lt;br /&gt;
*Add unit tests for saving/retrieving&lt;br /&gt;
'''Week 3'''&lt;br /&gt;
&lt;br /&gt;
*Create settings page to allow admin to choose where tomcat is running&lt;br /&gt;
*Add some magic so that module tries to guess where tomcat is running&lt;br /&gt;
*Add ability to put the saved css into the right folder in tomcat so that the css is actually overriding the openmrs style.css file.&lt;br /&gt;
&lt;br /&gt;
==Development Tools==&lt;br /&gt;
1. '''Eclipse'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Integrated_development_environment&amp;lt;/ref&amp;gt;: Eclipse is the Integrated Development Environment used to develop, modify, and compile the code for our module. &amp;lt;br&amp;gt;&lt;br /&gt;
2. '''Maven'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Maven&amp;lt;/ref&amp;gt;: Maven is used through a plug-in in Eclipse to compile, run unit tests, and package all of the Java files in the module.  &amp;lt;br&amp;gt;&lt;br /&gt;
3. '''Tomcat'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Tomcat&amp;lt;/ref&amp;gt;: Tomcat is the web-server used to run the application. &amp;lt;br&amp;gt; &lt;br /&gt;
4. '''Hibernate'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Hibernate_(Java)&amp;lt;/ref&amp;gt;: Hibernate is a built-in utility in the OpenMRS module, that is used to connect the Java classes to the database tables in the application. It configured the database table through an xml file: UpdateCSS.hbm.xml&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE hibernate-mapping PUBLIC&lt;br /&gt;
    &amp;quot;-//Hibernate/Hibernate Mapping DTD 3.0//EN&amp;quot;&lt;br /&gt;
    &amp;quot;http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&amp;quot; &amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hibernate-mapping package=&amp;quot;org.openmrs.module.updatecss&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;class name=&amp;quot;UpdateCSS&amp;quot;&lt;br /&gt;
	table=&amp;quot;css_properties&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;id name=&amp;quot;id&amp;quot; type=&amp;quot;int&amp;quot; column=&amp;quot;id&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;generator class=&amp;quot;native&amp;quot;/&amp;gt;&lt;br /&gt;
        &amp;lt;/id&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;cssData&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;css_location&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;homeDirectory&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;tomcat_home&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/class&amp;gt;&lt;br /&gt;
&amp;lt;/hibernate-mapping&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
''Here in the UpdateCSS.hbm.xml we specify the table name and columns. Hibernate generates the table with the fields specified and handles all the necessary SQL calls and queries.''&amp;lt;br&amp;gt;&lt;br /&gt;
5. '''MySQL''': MySQL&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Mysql&amp;lt;/ref&amp;gt; is the RDBMS that is used to store the CSS data for the application.&lt;br /&gt;
&lt;br /&gt;
==Use Case==&lt;br /&gt;
[[File:Openmrsui.png|800px|alt=OpenMRS UI]]&amp;lt;br&amp;gt;&lt;br /&gt;
''This is the user interface for the UpdateCSS module. The initial start screen provides a default location for the css style sheet and default css code. Here the navigation bar is changed to &amp;quot;orange&amp;quot;. ''&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
1. Log in to the Admin page with user &amp;quot;Admin&amp;quot; and password &amp;quot;Admin123&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
2. Once logged in, click on &amp;quot;Administration&amp;quot; on the right-hand side of the navigation bar. &amp;lt;br&amp;gt;&lt;br /&gt;
3. Under &amp;quot;Update CSS Module&amp;quot;, click on &amp;quot;Manage module&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
4. Here the user can enter their desired CSS preferences for customization. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Application Overview==&lt;br /&gt;
[[File:Overview.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt;Code Changes&amp;lt;/h1&amp;gt;&lt;br /&gt;
==Classes and Files Worked On==&lt;br /&gt;
* UpdateCSSActivator.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSS.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSService.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSServiceImpl.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSDAO.java &amp;lt;br&amp;gt;&lt;br /&gt;
* HibernateUpdateCSSDAO.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSS.hbm.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* liquibase.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* moduleApplicationContext.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSServiceTest.java &amp;lt;br&amp;gt;&lt;br /&gt;
* manage.jsp &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSManageController.java &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Specific Changes==&lt;br /&gt;
'''UpdateCSSActivator.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSServiceImpl.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
Added below methods to UpdateCSSServiceImpl class: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  /**&lt;br /&gt;
+   * Replaces the text of the specified CSS file in the&lt;br /&gt;
+   * specified directory with the specified text&lt;br /&gt;
+   */ +  public void copyCssDataToTomcatDirectory(String directory, String cssText) {&lt;br /&gt;
+    File cssFile = new File(directory);&lt;br /&gt;
+    if (cssFile.exists()) {&lt;br /&gt;
+      writeDataToFile(cssFile, cssText);&lt;br /&gt;
+    }&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Copies the data stored in the DB into the CSS file that is saved in the &lt;br /&gt;
+   * directory column of the css_properties table&lt;br /&gt;
+   */&lt;br /&gt;
+  public void copyCssDataToTomcatDirectory() {&lt;br /&gt;
+    UpdateCSS updateCSS = getData();&lt;br /&gt;
+    String cssDirectory = updateCSS.getHomeDirectory();&lt;br /&gt;
+    String cssText = updateCSS.getCssData();&lt;br /&gt;
+    copyCssDataToTomcatDirectory(cssDirectory, cssText);&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Writes the specified text to the specified CSS file&lt;br /&gt;
+   */&lt;br /&gt;
+  public void writeDataToFile(File cssFile, String cssText) {&lt;br /&gt;
+    try {&lt;br /&gt;
+      if (cssFile.exists()) {&lt;br /&gt;
+        PrintWriter writer = new PrintWriter(cssFile);&lt;br /&gt;
+        writer.print(cssText);&lt;br /&gt;
+        writer.close();&lt;br /&gt;
+      }&lt;br /&gt;
+    } catch (FileNotFoundException ex) {&lt;br /&gt;
+      &lt;br /&gt;
+    }&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Reads the data in the file at the specified path and returns&lt;br /&gt;
+   * a String with the contents. If the file doesn't exist&lt;br /&gt;
+   * then it returns an empty string&lt;br /&gt;
+   */&lt;br /&gt;
+  public String getCssTextFromFile(String filePath) {&lt;br /&gt;
+    String cssText = &amp;quot;&amp;quot;;&lt;br /&gt;
+    try {&lt;br /&gt;
+      File cssFile = new File(filePath);&lt;br /&gt;
+      if (cssFile.exists()) {&lt;br /&gt;
+        cssText = FileUtils.readFileToString(cssFile);&lt;br /&gt;
+      }  &lt;br /&gt;
+    } catch (IOException ex) {&lt;br /&gt;
+    &lt;br /&gt;
+    }&lt;br /&gt;
+    return cssText;&lt;br /&gt;
+  }&lt;br /&gt;
+    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''UpdateCSS.java:''' &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
==UpdateCSSDAO.java/HibernateUpdateCSSDAO.java==&lt;br /&gt;
The DAO files carry the primary responsibility of interaction with the DB layer in the MVC architecture.&amp;lt;br&amp;gt;&lt;br /&gt;
The data layer changes involved 3 separate components:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. liquibase.xml file to configure our new table: css_properties&amp;lt;br&amp;gt;&lt;br /&gt;
2. UpdateCSSDAO.java/HibernateUpdateCSSDAO.java - Interface/Implementation for DAO getter/setter.&amp;lt;br&amp;gt;&lt;br /&gt;
3. UpdateCSS.hbm.xml - Hibernate configuration file for mapping DAO to new properties table.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==liquibase.xml==&lt;br /&gt;
==Hibernate==&lt;br /&gt;
'''UpdateCSSService.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSManageController.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517/M601_Design_Document&amp;diff=75199</id>
		<title>CSC/ECE 517/M601 Design Document</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517/M601_Design_Document&amp;diff=75199"/>
		<updated>2013-04-27T12:21:31Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: /* Specific Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;h1&amp;gt;Add ability to update css through webapp&amp;lt;/h1&amp;gt;&lt;br /&gt;
== Example Video ==&lt;br /&gt;
A video example of this module can be seen here [http://youtu.be/2dQeFYjcsnU]&lt;br /&gt;
==Team== &lt;br /&gt;
Yuri Kolesnikov &amp;lt;br&amp;gt;&lt;br /&gt;
Jonathan Wills &amp;lt;br&amp;gt;&lt;br /&gt;
Jeffrey Plemmons &amp;lt;br&amp;gt;&lt;br /&gt;
Roshna Agarwal&lt;br /&gt;
&lt;br /&gt;
==Our Work==&lt;br /&gt;
Link to the OpenMRS ticket: https://tickets.openmrs.org/browse/TRUNK-3415&amp;lt;br&amp;gt;&lt;br /&gt;
Link to our code in GitHub: https://github.com/ykolesn/openmrs-module-m601 &amp;lt;br&amp;gt;&lt;br /&gt;
Link to application: http://152.46.17.228:8081/openmrs-standalone&lt;br /&gt;
&lt;br /&gt;
==Purpose==&lt;br /&gt;
	The purpose of this module is to add the functionality of allowing the admin to customize the OpenMRS css file to their own specifications. By having the ability to customize the OpenMRS css file, the admin will be free to change the look and feel in their installation of OpenMRS.&lt;br /&gt;
&lt;br /&gt;
==Problem Definition==&lt;br /&gt;
	Add admin page for customization of the openmrs css file. Admins can 'override' any openmrs css with their own file by specifying that file in the openmrs runtime properties file.&lt;br /&gt;
This would be best as a new module in openmrs or perhaps just adding a new feature in the Custom Logo module? The admin should see a page with a large text box. The text box value should be persisted in the database as a new object/table/column somehow. When the module starts up, the Activator is called. Modify the activator to update the filesystem css file with whatever is defined by the admin.&lt;br /&gt;
&lt;br /&gt;
==Design Requirements==&lt;br /&gt;
&lt;br /&gt;
1. The admin should be able to customize the openmrs css file through an admin page. &amp;lt;br&amp;gt;&lt;br /&gt;
2. The admin should see a page with a large text box. &amp;lt;br&amp;gt;&lt;br /&gt;
3. The text box content should be stored in the database. &amp;lt;br&amp;gt;&lt;br /&gt;
4. The activator needs to be modified so that it updates the filesystem css file with whatever is defined by the admin. &amp;lt;br&amp;gt;&lt;br /&gt;
5. Need to use Eclipse and Maven as development tools for the module. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
'''Week 1'''&lt;br /&gt;
&lt;br /&gt;
*Get OpenMRS Id&lt;br /&gt;
*Get ticket assigned and in progress&lt;br /&gt;
*Get openmrs module name assigned&lt;br /&gt;
*Create openmrs module&lt;br /&gt;
*Commit module to github&lt;br /&gt;
*Check out module on partner machines&lt;br /&gt;
*Get new admin page link&lt;br /&gt;
*Create new spring controller and jsp page&lt;br /&gt;
'''Week 2'''&lt;br /&gt;
&lt;br /&gt;
*Create object for storing css in db&lt;br /&gt;
*Create service layer and dao layer methods to save object&lt;br /&gt;
*Connect controller to db object for saving + retrieving&lt;br /&gt;
*Add unit tests for saving/retrieving&lt;br /&gt;
'''Week 3'''&lt;br /&gt;
&lt;br /&gt;
*Create settings page to allow admin to choose where tomcat is running&lt;br /&gt;
*Add some magic so that module tries to guess where tomcat is running&lt;br /&gt;
*Add ability to put the saved css into the right folder in tomcat so that the css is actually overriding the openmrs style.css file.&lt;br /&gt;
&lt;br /&gt;
==Development Tools==&lt;br /&gt;
1. '''Eclipse'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Integrated_development_environment&amp;lt;/ref&amp;gt;: Eclipse is the Integrated Development Environment used to develop, modify, and compile the code for our module. &amp;lt;br&amp;gt;&lt;br /&gt;
2. '''Maven'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Maven&amp;lt;/ref&amp;gt;: Maven is used through a plug-in in Eclipse to compile, run unit tests, and package all of the Java files in the module.  &amp;lt;br&amp;gt;&lt;br /&gt;
3. '''Tomcat'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Tomcat&amp;lt;/ref&amp;gt;: Tomcat is the web-server used to run the application. &amp;lt;br&amp;gt; &lt;br /&gt;
4. '''Hibernate'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Hibernate_(Java)&amp;lt;/ref&amp;gt;: Hibernate is a built-in utility in the OpenMRS module, that is used to connect the Java classes to the database tables in the application. It configured the database table through an xml file: UpdateCSS.hbm.xml&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE hibernate-mapping PUBLIC&lt;br /&gt;
    &amp;quot;-//Hibernate/Hibernate Mapping DTD 3.0//EN&amp;quot;&lt;br /&gt;
    &amp;quot;http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&amp;quot; &amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hibernate-mapping package=&amp;quot;org.openmrs.module.updatecss&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;class name=&amp;quot;UpdateCSS&amp;quot;&lt;br /&gt;
	table=&amp;quot;css_properties&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;id name=&amp;quot;id&amp;quot; type=&amp;quot;int&amp;quot; column=&amp;quot;id&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;generator class=&amp;quot;native&amp;quot;/&amp;gt;&lt;br /&gt;
        &amp;lt;/id&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;cssData&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;css_location&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;homeDirectory&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;tomcat_home&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/class&amp;gt;&lt;br /&gt;
&amp;lt;/hibernate-mapping&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
''Here in the UpdateCSS.hbm.xml we specify the table name and columns. Hibernate generates the table with the fields specified and handles all the necessary SQL calls and queries.''&amp;lt;br&amp;gt;&lt;br /&gt;
5. '''MySQL''': MySQL&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Mysql&amp;lt;/ref&amp;gt; is the RDBMS that is used to store the CSS data for the application.&lt;br /&gt;
&lt;br /&gt;
==Use Case==&lt;br /&gt;
[[File:Openmrsui.png|800px|alt=OpenMRS UI]]&amp;lt;br&amp;gt;&lt;br /&gt;
''This is the user interface for the UpdateCSS module. The initial start screen provides a default location for the css style sheet and default css code. Here the navigation bar is changed to &amp;quot;orange&amp;quot;. ''&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
1. Log in to the Admin page with user &amp;quot;Admin&amp;quot; and password &amp;quot;Admin123&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
2. Once logged in, click on &amp;quot;Administration&amp;quot; on the right-hand side of the navigation bar. &amp;lt;br&amp;gt;&lt;br /&gt;
3. Under &amp;quot;Update CSS Module&amp;quot;, click on &amp;quot;Manage module&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
4. Here the user can enter their desired CSS preferences for customization. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Application Overview==&lt;br /&gt;
[[File:Overview.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt;Code Changes&amp;lt;/h1&amp;gt;&lt;br /&gt;
==Classes and Files Worked On==&lt;br /&gt;
* UpdateCSSActivator.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSS.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSService.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSServiceImpl.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSDAO.java &amp;lt;br&amp;gt;&lt;br /&gt;
* HibernateUpdateCSSDAO.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSS.hbm.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* liquibase.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* moduleApplicationContext.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSServiceTest.java &amp;lt;br&amp;gt;&lt;br /&gt;
* manage.jsp &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSManageController.java &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Specific Changes==&lt;br /&gt;
'''UpdateCSSActivator.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSServiceImpl.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
Added below methods to UpdateCSSServiceImpl class: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  /**&lt;br /&gt;
+   * Replaces the text of the specified CSS file in the&lt;br /&gt;
+   * specified directory with the specified text&lt;br /&gt;
+   */ +  public void copyCssDataToTomcatDirectory(String directory, String cssText) {&lt;br /&gt;
+    File cssFile = new File(directory);&lt;br /&gt;
+    if (cssFile.exists()) {&lt;br /&gt;
+      writeDataToFile(cssFile, cssText);&lt;br /&gt;
+    }&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Copies the data stored in the DB into the CSS file that is saved in the &lt;br /&gt;
+   * directory column of the css_properties table&lt;br /&gt;
+   */&lt;br /&gt;
+  public void copyCssDataToTomcatDirectory() {&lt;br /&gt;
+    UpdateCSS updateCSS = getData();&lt;br /&gt;
+    String cssDirectory = updateCSS.getHomeDirectory();&lt;br /&gt;
+    String cssText = updateCSS.getCssData();&lt;br /&gt;
+    copyCssDataToTomcatDirectory(cssDirectory, cssText);&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Writes the specified text to the specified CSS file&lt;br /&gt;
+   */&lt;br /&gt;
+  public void writeDataToFile(File cssFile, String cssText) {&lt;br /&gt;
+    try {&lt;br /&gt;
+      if (cssFile.exists()) {&lt;br /&gt;
+        PrintWriter writer = new PrintWriter(cssFile);&lt;br /&gt;
+        writer.print(cssText);&lt;br /&gt;
+        writer.close();&lt;br /&gt;
+      }&lt;br /&gt;
+    } catch (FileNotFoundException ex) {&lt;br /&gt;
+      &lt;br /&gt;
+    }&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Reads the data in the file at the specified path and returns&lt;br /&gt;
+   * a String with the contents. If the file doesn't exist&lt;br /&gt;
+   * then it returns an empty string&lt;br /&gt;
+   */&lt;br /&gt;
+  public String getCssTextFromFile(String filePath) {&lt;br /&gt;
+    String cssText = &amp;quot;&amp;quot;;&lt;br /&gt;
+    try {&lt;br /&gt;
+      File cssFile = new File(filePath);&lt;br /&gt;
+      if (cssFile.exists()) {&lt;br /&gt;
+        cssText = FileUtils.readFileToString(cssFile);&lt;br /&gt;
+      }  &lt;br /&gt;
+    } catch (IOException ex) {&lt;br /&gt;
+    &lt;br /&gt;
+    }&lt;br /&gt;
+    return cssText;&lt;br /&gt;
+  }&lt;br /&gt;
+    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''UpdateCSS.java:''' &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSDAO.java/HibernateUpdateCSSDAO.java'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The DAO files carry the primary responsibility of interaction with the DB layer in the MVC architecture.&amp;lt;br&amp;gt;&lt;br /&gt;
The data layer changes involved 3 separate components:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. liquibase.xml file to configure our new table: css_properties&amp;lt;br&amp;gt;&lt;br /&gt;
2. UpdateCSSDAO.java/HibernateUpdateCSSDAO.java - Interface/Implementation for DAO getter/setter.&amp;lt;br&amp;gt;&lt;br /&gt;
3. UpdateCSS.hbm.xml - Hibernate configuration file for mapping DAO to new properties table.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
==liquibase.xml==&lt;br /&gt;
==Hibernate==&lt;br /&gt;
'''UpdateCSSService.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSManageController.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517/M601_Design_Document&amp;diff=75198</id>
		<title>CSC/ECE 517/M601 Design Document</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517/M601_Design_Document&amp;diff=75198"/>
		<updated>2013-04-27T12:19:45Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: /* Specific Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;h1&amp;gt;Add ability to update css through webapp&amp;lt;/h1&amp;gt;&lt;br /&gt;
== Example Video ==&lt;br /&gt;
A video example of this module can be seen here [http://youtu.be/2dQeFYjcsnU]&lt;br /&gt;
==Team== &lt;br /&gt;
Yuri Kolesnikov &amp;lt;br&amp;gt;&lt;br /&gt;
Jonathan Wills &amp;lt;br&amp;gt;&lt;br /&gt;
Jeffrey Plemmons &amp;lt;br&amp;gt;&lt;br /&gt;
Roshna Agarwal&lt;br /&gt;
&lt;br /&gt;
==Our Work==&lt;br /&gt;
Link to the OpenMRS ticket: https://tickets.openmrs.org/browse/TRUNK-3415&amp;lt;br&amp;gt;&lt;br /&gt;
Link to our code in GitHub: https://github.com/ykolesn/openmrs-module-m601 &amp;lt;br&amp;gt;&lt;br /&gt;
Link to application: http://152.46.17.228:8081/openmrs-standalone&lt;br /&gt;
&lt;br /&gt;
==Purpose==&lt;br /&gt;
	The purpose of this module is to add the functionality of allowing the admin to customize the OpenMRS css file to their own specifications. By having the ability to customize the OpenMRS css file, the admin will be free to change the look and feel in their installation of OpenMRS.&lt;br /&gt;
&lt;br /&gt;
==Problem Definition==&lt;br /&gt;
	Add admin page for customization of the openmrs css file. Admins can 'override' any openmrs css with their own file by specifying that file in the openmrs runtime properties file.&lt;br /&gt;
This would be best as a new module in openmrs or perhaps just adding a new feature in the Custom Logo module? The admin should see a page with a large text box. The text box value should be persisted in the database as a new object/table/column somehow. When the module starts up, the Activator is called. Modify the activator to update the filesystem css file with whatever is defined by the admin.&lt;br /&gt;
&lt;br /&gt;
==Design Requirements==&lt;br /&gt;
&lt;br /&gt;
1. The admin should be able to customize the openmrs css file through an admin page. &amp;lt;br&amp;gt;&lt;br /&gt;
2. The admin should see a page with a large text box. &amp;lt;br&amp;gt;&lt;br /&gt;
3. The text box content should be stored in the database. &amp;lt;br&amp;gt;&lt;br /&gt;
4. The activator needs to be modified so that it updates the filesystem css file with whatever is defined by the admin. &amp;lt;br&amp;gt;&lt;br /&gt;
5. Need to use Eclipse and Maven as development tools for the module. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
'''Week 1'''&lt;br /&gt;
&lt;br /&gt;
*Get OpenMRS Id&lt;br /&gt;
*Get ticket assigned and in progress&lt;br /&gt;
*Get openmrs module name assigned&lt;br /&gt;
*Create openmrs module&lt;br /&gt;
*Commit module to github&lt;br /&gt;
*Check out module on partner machines&lt;br /&gt;
*Get new admin page link&lt;br /&gt;
*Create new spring controller and jsp page&lt;br /&gt;
'''Week 2'''&lt;br /&gt;
&lt;br /&gt;
*Create object for storing css in db&lt;br /&gt;
*Create service layer and dao layer methods to save object&lt;br /&gt;
*Connect controller to db object for saving + retrieving&lt;br /&gt;
*Add unit tests for saving/retrieving&lt;br /&gt;
'''Week 3'''&lt;br /&gt;
&lt;br /&gt;
*Create settings page to allow admin to choose where tomcat is running&lt;br /&gt;
*Add some magic so that module tries to guess where tomcat is running&lt;br /&gt;
*Add ability to put the saved css into the right folder in tomcat so that the css is actually overriding the openmrs style.css file.&lt;br /&gt;
&lt;br /&gt;
==Development Tools==&lt;br /&gt;
1. '''Eclipse'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Integrated_development_environment&amp;lt;/ref&amp;gt;: Eclipse is the Integrated Development Environment used to develop, modify, and compile the code for our module. &amp;lt;br&amp;gt;&lt;br /&gt;
2. '''Maven'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Maven&amp;lt;/ref&amp;gt;: Maven is used through a plug-in in Eclipse to compile, run unit tests, and package all of the Java files in the module.  &amp;lt;br&amp;gt;&lt;br /&gt;
3. '''Tomcat'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Tomcat&amp;lt;/ref&amp;gt;: Tomcat is the web-server used to run the application. &amp;lt;br&amp;gt; &lt;br /&gt;
4. '''Hibernate'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Hibernate_(Java)&amp;lt;/ref&amp;gt;: Hibernate is a built-in utility in the OpenMRS module, that is used to connect the Java classes to the database tables in the application. It configured the database table through an xml file: UpdateCSS.hbm.xml&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE hibernate-mapping PUBLIC&lt;br /&gt;
    &amp;quot;-//Hibernate/Hibernate Mapping DTD 3.0//EN&amp;quot;&lt;br /&gt;
    &amp;quot;http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&amp;quot; &amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hibernate-mapping package=&amp;quot;org.openmrs.module.updatecss&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;class name=&amp;quot;UpdateCSS&amp;quot;&lt;br /&gt;
	table=&amp;quot;css_properties&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;id name=&amp;quot;id&amp;quot; type=&amp;quot;int&amp;quot; column=&amp;quot;id&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;generator class=&amp;quot;native&amp;quot;/&amp;gt;&lt;br /&gt;
        &amp;lt;/id&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;cssData&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;css_location&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;homeDirectory&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;tomcat_home&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/class&amp;gt;&lt;br /&gt;
&amp;lt;/hibernate-mapping&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
''Here in the UpdateCSS.hbm.xml we specify the table name and columns. Hibernate generates the table with the fields specified and handles all the necessary SQL calls and queries.''&amp;lt;br&amp;gt;&lt;br /&gt;
5. '''MySQL''': MySQL&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Mysql&amp;lt;/ref&amp;gt; is the RDBMS that is used to store the CSS data for the application.&lt;br /&gt;
&lt;br /&gt;
==Use Case==&lt;br /&gt;
[[File:Openmrsui.png|800px|alt=OpenMRS UI]]&amp;lt;br&amp;gt;&lt;br /&gt;
''This is the user interface for the UpdateCSS module. The initial start screen provides a default location for the css style sheet and default css code. Here the navigation bar is changed to &amp;quot;orange&amp;quot;. ''&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
1. Log in to the Admin page with user &amp;quot;Admin&amp;quot; and password &amp;quot;Admin123&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
2. Once logged in, click on &amp;quot;Administration&amp;quot; on the right-hand side of the navigation bar. &amp;lt;br&amp;gt;&lt;br /&gt;
3. Under &amp;quot;Update CSS Module&amp;quot;, click on &amp;quot;Manage module&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
4. Here the user can enter their desired CSS preferences for customization. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Application Overview==&lt;br /&gt;
[[File:Overview.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt;Code Changes&amp;lt;/h1&amp;gt;&lt;br /&gt;
==Classes and Files Worked On==&lt;br /&gt;
* UpdateCSSActivator.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSS.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSService.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSServiceImpl.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSDAO.java &amp;lt;br&amp;gt;&lt;br /&gt;
* HibernateUpdateCSSDAO.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSS.hbm.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* liquibase.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* moduleApplicationContext.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSServiceTest.java &amp;lt;br&amp;gt;&lt;br /&gt;
* manage.jsp &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSManageController.java &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Specific Changes==&lt;br /&gt;
'''UpdateCSSActivator.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSServiceImpl.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
Added below methods to UpdateCSSServiceImpl class: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  /**&lt;br /&gt;
+   * Replaces the text of the specified CSS file in the&lt;br /&gt;
+   * specified directory with the specified text&lt;br /&gt;
+   */ +  public void copyCssDataToTomcatDirectory(String directory, String cssText) {&lt;br /&gt;
+    File cssFile = new File(directory);&lt;br /&gt;
+    if (cssFile.exists()) {&lt;br /&gt;
+      writeDataToFile(cssFile, cssText);&lt;br /&gt;
+    }&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Copies the data stored in the DB into the CSS file that is saved in the &lt;br /&gt;
+   * directory column of the css_properties table&lt;br /&gt;
+   */&lt;br /&gt;
+  public void copyCssDataToTomcatDirectory() {&lt;br /&gt;
+    UpdateCSS updateCSS = getData();&lt;br /&gt;
+    String cssDirectory = updateCSS.getHomeDirectory();&lt;br /&gt;
+    String cssText = updateCSS.getCssData();&lt;br /&gt;
+    copyCssDataToTomcatDirectory(cssDirectory, cssText);&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Writes the specified text to the specified CSS file&lt;br /&gt;
+   */&lt;br /&gt;
+  public void writeDataToFile(File cssFile, String cssText) {&lt;br /&gt;
+    try {&lt;br /&gt;
+      if (cssFile.exists()) {&lt;br /&gt;
+        PrintWriter writer = new PrintWriter(cssFile);&lt;br /&gt;
+        writer.print(cssText);&lt;br /&gt;
+        writer.close();&lt;br /&gt;
+      }&lt;br /&gt;
+    } catch (FileNotFoundException ex) {&lt;br /&gt;
+      &lt;br /&gt;
+    }&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Reads the data in the file at the specified path and returns&lt;br /&gt;
+   * a String with the contents. If the file doesn't exist&lt;br /&gt;
+   * then it returns an empty string&lt;br /&gt;
+   */&lt;br /&gt;
+  public String getCssTextFromFile(String filePath) {&lt;br /&gt;
+    String cssText = &amp;quot;&amp;quot;;&lt;br /&gt;
+    try {&lt;br /&gt;
+      File cssFile = new File(filePath);&lt;br /&gt;
+      if (cssFile.exists()) {&lt;br /&gt;
+        cssText = FileUtils.readFileToString(cssFile);&lt;br /&gt;
+      }  &lt;br /&gt;
+    } catch (IOException ex) {&lt;br /&gt;
+    &lt;br /&gt;
+    }&lt;br /&gt;
+    return cssText;&lt;br /&gt;
+  }&lt;br /&gt;
+    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''UpdateCSS.java:''' &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSDAO.java/HibernateUpdateCSSDAO.java'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The DAO files carry the primary responsibility of interaction with the DB layer in the MVC architecture.&amp;lt;br&amp;gt;&lt;br /&gt;
The data layer changes involved 3 separate components:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. liquibase.xml file to configure our new table: css_properties&amp;lt;br&amp;gt;&lt;br /&gt;
2. UpdateCSSDAO.java/HibernateUpdateCSSDAO.java - Interface/Implementation for DAO getter/setter.&amp;lt;br&amp;gt;&lt;br /&gt;
3. UpdateCSS.hbm.xml - Hibernate configuration file for mapping DAO to new properties table.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
==liquibase.xml==&amp;lt;br&amp;gt;&lt;br /&gt;
==Hibernate==&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSService.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSManageController.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517/M601_Design_Document&amp;diff=75197</id>
		<title>CSC/ECE 517/M601 Design Document</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517/M601_Design_Document&amp;diff=75197"/>
		<updated>2013-04-27T02:29:15Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: /* Specific Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;h1&amp;gt;Add ability to update css through webapp&amp;lt;/h1&amp;gt;&lt;br /&gt;
== Example Video ==&lt;br /&gt;
A video example of this module can be seen here [http://youtu.be/2dQeFYjcsnU]&lt;br /&gt;
==Team== &lt;br /&gt;
Yuri Kolesnikov &amp;lt;br&amp;gt;&lt;br /&gt;
Jonathan Wills &amp;lt;br&amp;gt;&lt;br /&gt;
Jeffrey Plemmons &amp;lt;br&amp;gt;&lt;br /&gt;
Roshna Agarwal&lt;br /&gt;
&lt;br /&gt;
==Our Work==&lt;br /&gt;
Link to the OpenMRS ticket: https://tickets.openmrs.org/browse/TRUNK-3415&amp;lt;br&amp;gt;&lt;br /&gt;
Link to our code in GitHub: https://github.com/ykolesn/openmrs-module-m601 &amp;lt;br&amp;gt;&lt;br /&gt;
Link to application: http://152.46.17.228:8081/openmrs-standalone&lt;br /&gt;
&lt;br /&gt;
==Purpose==&lt;br /&gt;
	The purpose of this module is to add the functionality of allowing the admin to customize the OpenMRS css file to their own specifications. By having the ability to customize the OpenMRS css file, the admin will be free to change the look and feel in their installation of OpenMRS.&lt;br /&gt;
&lt;br /&gt;
==Problem Definition==&lt;br /&gt;
	Add admin page for customization of the openmrs css file. Admins can 'override' any openmrs css with their own file by specifying that file in the openmrs runtime properties file.&lt;br /&gt;
This would be best as a new module in openmrs or perhaps just adding a new feature in the Custom Logo module? The admin should see a page with a large text box. The text box value should be persisted in the database as a new object/table/column somehow. When the module starts up, the Activator is called. Modify the activator to update the filesystem css file with whatever is defined by the admin.&lt;br /&gt;
&lt;br /&gt;
==Design Requirements==&lt;br /&gt;
&lt;br /&gt;
1. The admin should be able to customize the openmrs css file through an admin page. &amp;lt;br&amp;gt;&lt;br /&gt;
2. The admin should see a page with a large text box. &amp;lt;br&amp;gt;&lt;br /&gt;
3. The text box content should be stored in the database. &amp;lt;br&amp;gt;&lt;br /&gt;
4. The activator needs to be modified so that it updates the filesystem css file with whatever is defined by the admin. &amp;lt;br&amp;gt;&lt;br /&gt;
5. Need to use Eclipse and Maven as development tools for the module. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
'''Week 1'''&lt;br /&gt;
&lt;br /&gt;
*Get OpenMRS Id&lt;br /&gt;
*Get ticket assigned and in progress&lt;br /&gt;
*Get openmrs module name assigned&lt;br /&gt;
*Create openmrs module&lt;br /&gt;
*Commit module to github&lt;br /&gt;
*Check out module on partner machines&lt;br /&gt;
*Get new admin page link&lt;br /&gt;
*Create new spring controller and jsp page&lt;br /&gt;
'''Week 2'''&lt;br /&gt;
&lt;br /&gt;
*Create object for storing css in db&lt;br /&gt;
*Create service layer and dao layer methods to save object&lt;br /&gt;
*Connect controller to db object for saving + retrieving&lt;br /&gt;
*Add unit tests for saving/retrieving&lt;br /&gt;
'''Week 3'''&lt;br /&gt;
&lt;br /&gt;
*Create settings page to allow admin to choose where tomcat is running&lt;br /&gt;
*Add some magic so that module tries to guess where tomcat is running&lt;br /&gt;
*Add ability to put the saved css into the right folder in tomcat so that the css is actually overriding the openmrs style.css file.&lt;br /&gt;
&lt;br /&gt;
==Development Tools==&lt;br /&gt;
1. '''Eclipse'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Integrated_development_environment&amp;lt;/ref&amp;gt;: Eclipse is the Integrated Development Environment used to develop, modify, and compile the code for our module. &amp;lt;br&amp;gt;&lt;br /&gt;
2. '''Maven'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Maven&amp;lt;/ref&amp;gt;: Maven is used through a plug-in in Eclipse to compile, run unit tests, and package all of the Java files in the module.  &amp;lt;br&amp;gt;&lt;br /&gt;
3. '''Tomcat'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Tomcat&amp;lt;/ref&amp;gt;: Tomcat is the web-server used to run the application. &amp;lt;br&amp;gt; &lt;br /&gt;
4. '''Hibernate'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Hibernate_(Java)&amp;lt;/ref&amp;gt;: Hibernate is a built-in utility in the OpenMRS module, that is used to connect the Java classes to the database tables in the application. It configured the database table through an xml file: UpdateCSS.hbm.xml&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE hibernate-mapping PUBLIC&lt;br /&gt;
    &amp;quot;-//Hibernate/Hibernate Mapping DTD 3.0//EN&amp;quot;&lt;br /&gt;
    &amp;quot;http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&amp;quot; &amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hibernate-mapping package=&amp;quot;org.openmrs.module.updatecss&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;class name=&amp;quot;UpdateCSS&amp;quot;&lt;br /&gt;
	table=&amp;quot;css_properties&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;id name=&amp;quot;id&amp;quot; type=&amp;quot;int&amp;quot; column=&amp;quot;id&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;generator class=&amp;quot;native&amp;quot;/&amp;gt;&lt;br /&gt;
        &amp;lt;/id&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;cssData&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;css_location&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;homeDirectory&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;tomcat_home&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/class&amp;gt;&lt;br /&gt;
&amp;lt;/hibernate-mapping&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
''Here in the UpdateCSS.hbm.xml we specify the table name and columns. Hibernate generates the table with the fields specified and handles all the necessary SQL calls and queries.''&amp;lt;br&amp;gt;&lt;br /&gt;
5. '''MySQL''': MySQL&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Mysql&amp;lt;/ref&amp;gt; is the RDBMS that is used to store the CSS data for the application.&lt;br /&gt;
&lt;br /&gt;
==Use Case==&lt;br /&gt;
[[File:Openmrsui.png|800px|alt=OpenMRS UI]]&amp;lt;br&amp;gt;&lt;br /&gt;
''This is the user interface for the UpdateCSS module. The initial start screen provides a default location for the css style sheet and default css code. Here the navigation bar is changed to &amp;quot;orange&amp;quot;. ''&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
1. Log in to the Admin page with user &amp;quot;Admin&amp;quot; and password &amp;quot;Admin123&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
2. Once logged in, click on &amp;quot;Administration&amp;quot; on the right-hand side of the navigation bar. &amp;lt;br&amp;gt;&lt;br /&gt;
3. Under &amp;quot;Update CSS Module&amp;quot;, click on &amp;quot;Manage module&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
4. Here the user can enter their desired CSS preferences for customization. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Application Overview==&lt;br /&gt;
[[File:Overview.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt;Code Changes&amp;lt;/h1&amp;gt;&lt;br /&gt;
==Classes and Files Worked On==&lt;br /&gt;
* UpdateCSSActivator.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSS.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSService.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSServiceImpl.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSDAO.java &amp;lt;br&amp;gt;&lt;br /&gt;
* HibernateUpdateCSSDAO.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSS.hbm.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* liquibase.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* moduleApplicationContext.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSServiceTest.java &amp;lt;br&amp;gt;&lt;br /&gt;
* manage.jsp &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSManageController.java &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Specific Changes==&lt;br /&gt;
'''UpdateCSSActivator.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSServiceImpl.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
Added below methods to UpdateCSSServiceImpl class: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  /**&lt;br /&gt;
+   * Replaces the text of the specified CSS file in the&lt;br /&gt;
+   * specified directory with the specified text&lt;br /&gt;
+   */ +  public void copyCssDataToTomcatDirectory(String directory, String cssText) {&lt;br /&gt;
+    File cssFile = new File(directory);&lt;br /&gt;
+    if (cssFile.exists()) {&lt;br /&gt;
+      writeDataToFile(cssFile, cssText);&lt;br /&gt;
+    }&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Copies the data stored in the DB into the CSS file that is saved in the &lt;br /&gt;
+   * directory column of the css_properties table&lt;br /&gt;
+   */&lt;br /&gt;
+  public void copyCssDataToTomcatDirectory() {&lt;br /&gt;
+    UpdateCSS updateCSS = getData();&lt;br /&gt;
+    String cssDirectory = updateCSS.getHomeDirectory();&lt;br /&gt;
+    String cssText = updateCSS.getCssData();&lt;br /&gt;
+    copyCssDataToTomcatDirectory(cssDirectory, cssText);&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Writes the specified text to the specified CSS file&lt;br /&gt;
+   */&lt;br /&gt;
+  public void writeDataToFile(File cssFile, String cssText) {&lt;br /&gt;
+    try {&lt;br /&gt;
+      if (cssFile.exists()) {&lt;br /&gt;
+        PrintWriter writer = new PrintWriter(cssFile);&lt;br /&gt;
+        writer.print(cssText);&lt;br /&gt;
+        writer.close();&lt;br /&gt;
+      }&lt;br /&gt;
+    } catch (FileNotFoundException ex) {&lt;br /&gt;
+      &lt;br /&gt;
+    }&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Reads the data in the file at the specified path and returns&lt;br /&gt;
+   * a String with the contents. If the file doesn't exist&lt;br /&gt;
+   * then it returns an empty string&lt;br /&gt;
+   */&lt;br /&gt;
+  public String getCssTextFromFile(String filePath) {&lt;br /&gt;
+    String cssText = &amp;quot;&amp;quot;;&lt;br /&gt;
+    try {&lt;br /&gt;
+      File cssFile = new File(filePath);&lt;br /&gt;
+      if (cssFile.exists()) {&lt;br /&gt;
+        cssText = FileUtils.readFileToString(cssFile);&lt;br /&gt;
+      }  &lt;br /&gt;
+    } catch (IOException ex) {&lt;br /&gt;
+    &lt;br /&gt;
+    }&lt;br /&gt;
+    return cssText;&lt;br /&gt;
+  }&lt;br /&gt;
+    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''UpdateCSS.java:''' &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSDAO.java/HibernateUpdateCSSDAO.java'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The DAO files carry the primary responsibility of interaction with the DB layer in the MVC architecture.&amp;lt;br&amp;gt;&lt;br /&gt;
The data layer changes involved 3 separate components:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. liquibase.xml file to configure our new table: css_properties&amp;lt;br&amp;gt;&lt;br /&gt;
2. UpdateCSSDAO.java/HibernateUpdateCSSDAO.java - Interface/Implementation for DAO getter/setter.&amp;lt;br&amp;gt;&lt;br /&gt;
3. UpdateCSS.hbm.xml - Hibernate configuration file for mapping DAO to new properties table.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
''liquibase.xml''&amp;lt;br&amp;gt;&lt;br /&gt;
''Hibernate''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSService.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSManageController.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517/M601_Design_Document&amp;diff=75196</id>
		<title>CSC/ECE 517/M601 Design Document</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517/M601_Design_Document&amp;diff=75196"/>
		<updated>2013-04-27T02:27:05Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: /* Specific Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;h1&amp;gt;Add ability to update css through webapp&amp;lt;/h1&amp;gt;&lt;br /&gt;
== Example Video ==&lt;br /&gt;
A video example of this module can be seen here [http://youtu.be/2dQeFYjcsnU]&lt;br /&gt;
==Team== &lt;br /&gt;
Yuri Kolesnikov &amp;lt;br&amp;gt;&lt;br /&gt;
Jonathan Wills &amp;lt;br&amp;gt;&lt;br /&gt;
Jeffrey Plemmons &amp;lt;br&amp;gt;&lt;br /&gt;
Roshna Agarwal&lt;br /&gt;
&lt;br /&gt;
==Our Work==&lt;br /&gt;
Link to the OpenMRS ticket: https://tickets.openmrs.org/browse/TRUNK-3415&amp;lt;br&amp;gt;&lt;br /&gt;
Link to our code in GitHub: https://github.com/ykolesn/openmrs-module-m601 &amp;lt;br&amp;gt;&lt;br /&gt;
Link to application: http://152.46.17.228:8081/openmrs-standalone&lt;br /&gt;
&lt;br /&gt;
==Purpose==&lt;br /&gt;
	The purpose of this module is to add the functionality of allowing the admin to customize the OpenMRS css file to their own specifications. By having the ability to customize the OpenMRS css file, the admin will be free to change the look and feel in their installation of OpenMRS.&lt;br /&gt;
&lt;br /&gt;
==Problem Definition==&lt;br /&gt;
	Add admin page for customization of the openmrs css file. Admins can 'override' any openmrs css with their own file by specifying that file in the openmrs runtime properties file.&lt;br /&gt;
This would be best as a new module in openmrs or perhaps just adding a new feature in the Custom Logo module? The admin should see a page with a large text box. The text box value should be persisted in the database as a new object/table/column somehow. When the module starts up, the Activator is called. Modify the activator to update the filesystem css file with whatever is defined by the admin.&lt;br /&gt;
&lt;br /&gt;
==Design Requirements==&lt;br /&gt;
&lt;br /&gt;
1. The admin should be able to customize the openmrs css file through an admin page. &amp;lt;br&amp;gt;&lt;br /&gt;
2. The admin should see a page with a large text box. &amp;lt;br&amp;gt;&lt;br /&gt;
3. The text box content should be stored in the database. &amp;lt;br&amp;gt;&lt;br /&gt;
4. The activator needs to be modified so that it updates the filesystem css file with whatever is defined by the admin. &amp;lt;br&amp;gt;&lt;br /&gt;
5. Need to use Eclipse and Maven as development tools for the module. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
'''Week 1'''&lt;br /&gt;
&lt;br /&gt;
*Get OpenMRS Id&lt;br /&gt;
*Get ticket assigned and in progress&lt;br /&gt;
*Get openmrs module name assigned&lt;br /&gt;
*Create openmrs module&lt;br /&gt;
*Commit module to github&lt;br /&gt;
*Check out module on partner machines&lt;br /&gt;
*Get new admin page link&lt;br /&gt;
*Create new spring controller and jsp page&lt;br /&gt;
'''Week 2'''&lt;br /&gt;
&lt;br /&gt;
*Create object for storing css in db&lt;br /&gt;
*Create service layer and dao layer methods to save object&lt;br /&gt;
*Connect controller to db object for saving + retrieving&lt;br /&gt;
*Add unit tests for saving/retrieving&lt;br /&gt;
'''Week 3'''&lt;br /&gt;
&lt;br /&gt;
*Create settings page to allow admin to choose where tomcat is running&lt;br /&gt;
*Add some magic so that module tries to guess where tomcat is running&lt;br /&gt;
*Add ability to put the saved css into the right folder in tomcat so that the css is actually overriding the openmrs style.css file.&lt;br /&gt;
&lt;br /&gt;
==Development Tools==&lt;br /&gt;
1. '''Eclipse'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Integrated_development_environment&amp;lt;/ref&amp;gt;: Eclipse is the Integrated Development Environment used to develop, modify, and compile the code for our module. &amp;lt;br&amp;gt;&lt;br /&gt;
2. '''Maven'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Maven&amp;lt;/ref&amp;gt;: Maven is used through a plug-in in Eclipse to compile, run unit tests, and package all of the Java files in the module.  &amp;lt;br&amp;gt;&lt;br /&gt;
3. '''Tomcat'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Tomcat&amp;lt;/ref&amp;gt;: Tomcat is the web-server used to run the application. &amp;lt;br&amp;gt; &lt;br /&gt;
4. '''Hibernate'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Hibernate_(Java)&amp;lt;/ref&amp;gt;: Hibernate is a built-in utility in the OpenMRS module, that is used to connect the Java classes to the database tables in the application. It configured the database table through an xml file: UpdateCSS.hbm.xml&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE hibernate-mapping PUBLIC&lt;br /&gt;
    &amp;quot;-//Hibernate/Hibernate Mapping DTD 3.0//EN&amp;quot;&lt;br /&gt;
    &amp;quot;http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&amp;quot; &amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hibernate-mapping package=&amp;quot;org.openmrs.module.updatecss&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;class name=&amp;quot;UpdateCSS&amp;quot;&lt;br /&gt;
	table=&amp;quot;css_properties&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;id name=&amp;quot;id&amp;quot; type=&amp;quot;int&amp;quot; column=&amp;quot;id&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;generator class=&amp;quot;native&amp;quot;/&amp;gt;&lt;br /&gt;
        &amp;lt;/id&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;cssData&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;css_location&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;homeDirectory&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;tomcat_home&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/class&amp;gt;&lt;br /&gt;
&amp;lt;/hibernate-mapping&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
''Here in the UpdateCSS.hbm.xml we specify the table name and columns. Hibernate generates the table with the fields specified and handles all the necessary SQL calls and queries.''&amp;lt;br&amp;gt;&lt;br /&gt;
5. '''MySQL''': MySQL&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Mysql&amp;lt;/ref&amp;gt; is the RDBMS that is used to store the CSS data for the application.&lt;br /&gt;
&lt;br /&gt;
==Use Case==&lt;br /&gt;
[[File:Openmrsui.png|800px|alt=OpenMRS UI]]&amp;lt;br&amp;gt;&lt;br /&gt;
''This is the user interface for the UpdateCSS module. The initial start screen provides a default location for the css style sheet and default css code. Here the navigation bar is changed to &amp;quot;orange&amp;quot;. ''&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
1. Log in to the Admin page with user &amp;quot;Admin&amp;quot; and password &amp;quot;Admin123&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
2. Once logged in, click on &amp;quot;Administration&amp;quot; on the right-hand side of the navigation bar. &amp;lt;br&amp;gt;&lt;br /&gt;
3. Under &amp;quot;Update CSS Module&amp;quot;, click on &amp;quot;Manage module&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
4. Here the user can enter their desired CSS preferences for customization. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Application Overview==&lt;br /&gt;
[[File:Overview.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt;Code Changes&amp;lt;/h1&amp;gt;&lt;br /&gt;
==Classes and Files Worked On==&lt;br /&gt;
* UpdateCSSActivator.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSS.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSService.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSServiceImpl.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSDAO.java &amp;lt;br&amp;gt;&lt;br /&gt;
* HibernateUpdateCSSDAO.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSS.hbm.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* liquibase.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* moduleApplicationContext.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSServiceTest.java &amp;lt;br&amp;gt;&lt;br /&gt;
* manage.jsp &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSManageController.java &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Specific Changes==&lt;br /&gt;
'''UpdateCSSActivator.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSServiceImpl.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
Added below methods to UpdateCSSServiceImpl class: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  /**&lt;br /&gt;
+   * Replaces the text of the specified CSS file in the&lt;br /&gt;
+   * specified directory with the specified text&lt;br /&gt;
+   */ +  public void copyCssDataToTomcatDirectory(String directory, String cssText) {&lt;br /&gt;
+    File cssFile = new File(directory);&lt;br /&gt;
+    if (cssFile.exists()) {&lt;br /&gt;
+      writeDataToFile(cssFile, cssText);&lt;br /&gt;
+    }&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Copies the data stored in the DB into the CSS file that is saved in the &lt;br /&gt;
+   * directory column of the css_properties table&lt;br /&gt;
+   */&lt;br /&gt;
+  public void copyCssDataToTomcatDirectory() {&lt;br /&gt;
+    UpdateCSS updateCSS = getData();&lt;br /&gt;
+    String cssDirectory = updateCSS.getHomeDirectory();&lt;br /&gt;
+    String cssText = updateCSS.getCssData();&lt;br /&gt;
+    copyCssDataToTomcatDirectory(cssDirectory, cssText);&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Writes the specified text to the specified CSS file&lt;br /&gt;
+   */&lt;br /&gt;
+  public void writeDataToFile(File cssFile, String cssText) {&lt;br /&gt;
+    try {&lt;br /&gt;
+      if (cssFile.exists()) {&lt;br /&gt;
+        PrintWriter writer = new PrintWriter(cssFile);&lt;br /&gt;
+        writer.print(cssText);&lt;br /&gt;
+        writer.close();&lt;br /&gt;
+      }&lt;br /&gt;
+    } catch (FileNotFoundException ex) {&lt;br /&gt;
+      &lt;br /&gt;
+    }&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Reads the data in the file at the specified path and returns&lt;br /&gt;
+   * a String with the contents. If the file doesn't exist&lt;br /&gt;
+   * then it returns an empty string&lt;br /&gt;
+   */&lt;br /&gt;
+  public String getCssTextFromFile(String filePath) {&lt;br /&gt;
+    String cssText = &amp;quot;&amp;quot;;&lt;br /&gt;
+    try {&lt;br /&gt;
+      File cssFile = new File(filePath);&lt;br /&gt;
+      if (cssFile.exists()) {&lt;br /&gt;
+        cssText = FileUtils.readFileToString(cssFile);&lt;br /&gt;
+      }  &lt;br /&gt;
+    } catch (IOException ex) {&lt;br /&gt;
+    &lt;br /&gt;
+    }&lt;br /&gt;
+    return cssText;&lt;br /&gt;
+  }&lt;br /&gt;
+    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''UpdateCSS.java:''' &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSDAO.java/HibernateUpdateCSSDAO.java'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The DAO files carry the primary responsibility of interaction with the DB layer in the MVC architecture.&amp;lt;br&amp;gt;&lt;br /&gt;
The data layer changes involved 3 separate components:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. liquibase.xml file to configure our new table: css_properties&amp;lt;br&amp;gt;&lt;br /&gt;
2. UpdateCSSDAO.java/HibernateUpdateCSSDAO.java - Interface/Implementation for DAO getter/setter.&amp;lt;br&amp;gt;&lt;br /&gt;
3. UpdateCSS.hbm.xml - Hibernate configuration file for mapping DAO to new properties table.&amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSService.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSManageController.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517/M601_Design_Document&amp;diff=75195</id>
		<title>CSC/ECE 517/M601 Design Document</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517/M601_Design_Document&amp;diff=75195"/>
		<updated>2013-04-27T02:26:38Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: /* Specific Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;h1&amp;gt;Add ability to update css through webapp&amp;lt;/h1&amp;gt;&lt;br /&gt;
== Example Video ==&lt;br /&gt;
A video example of this module can be seen here [http://youtu.be/2dQeFYjcsnU]&lt;br /&gt;
==Team== &lt;br /&gt;
Yuri Kolesnikov &amp;lt;br&amp;gt;&lt;br /&gt;
Jonathan Wills &amp;lt;br&amp;gt;&lt;br /&gt;
Jeffrey Plemmons &amp;lt;br&amp;gt;&lt;br /&gt;
Roshna Agarwal&lt;br /&gt;
&lt;br /&gt;
==Our Work==&lt;br /&gt;
Link to the OpenMRS ticket: https://tickets.openmrs.org/browse/TRUNK-3415&amp;lt;br&amp;gt;&lt;br /&gt;
Link to our code in GitHub: https://github.com/ykolesn/openmrs-module-m601 &amp;lt;br&amp;gt;&lt;br /&gt;
Link to application: http://152.46.17.228:8081/openmrs-standalone&lt;br /&gt;
&lt;br /&gt;
==Purpose==&lt;br /&gt;
	The purpose of this module is to add the functionality of allowing the admin to customize the OpenMRS css file to their own specifications. By having the ability to customize the OpenMRS css file, the admin will be free to change the look and feel in their installation of OpenMRS.&lt;br /&gt;
&lt;br /&gt;
==Problem Definition==&lt;br /&gt;
	Add admin page for customization of the openmrs css file. Admins can 'override' any openmrs css with their own file by specifying that file in the openmrs runtime properties file.&lt;br /&gt;
This would be best as a new module in openmrs or perhaps just adding a new feature in the Custom Logo module? The admin should see a page with a large text box. The text box value should be persisted in the database as a new object/table/column somehow. When the module starts up, the Activator is called. Modify the activator to update the filesystem css file with whatever is defined by the admin.&lt;br /&gt;
&lt;br /&gt;
==Design Requirements==&lt;br /&gt;
&lt;br /&gt;
1. The admin should be able to customize the openmrs css file through an admin page. &amp;lt;br&amp;gt;&lt;br /&gt;
2. The admin should see a page with a large text box. &amp;lt;br&amp;gt;&lt;br /&gt;
3. The text box content should be stored in the database. &amp;lt;br&amp;gt;&lt;br /&gt;
4. The activator needs to be modified so that it updates the filesystem css file with whatever is defined by the admin. &amp;lt;br&amp;gt;&lt;br /&gt;
5. Need to use Eclipse and Maven as development tools for the module. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
'''Week 1'''&lt;br /&gt;
&lt;br /&gt;
*Get OpenMRS Id&lt;br /&gt;
*Get ticket assigned and in progress&lt;br /&gt;
*Get openmrs module name assigned&lt;br /&gt;
*Create openmrs module&lt;br /&gt;
*Commit module to github&lt;br /&gt;
*Check out module on partner machines&lt;br /&gt;
*Get new admin page link&lt;br /&gt;
*Create new spring controller and jsp page&lt;br /&gt;
'''Week 2'''&lt;br /&gt;
&lt;br /&gt;
*Create object for storing css in db&lt;br /&gt;
*Create service layer and dao layer methods to save object&lt;br /&gt;
*Connect controller to db object for saving + retrieving&lt;br /&gt;
*Add unit tests for saving/retrieving&lt;br /&gt;
'''Week 3'''&lt;br /&gt;
&lt;br /&gt;
*Create settings page to allow admin to choose where tomcat is running&lt;br /&gt;
*Add some magic so that module tries to guess where tomcat is running&lt;br /&gt;
*Add ability to put the saved css into the right folder in tomcat so that the css is actually overriding the openmrs style.css file.&lt;br /&gt;
&lt;br /&gt;
==Development Tools==&lt;br /&gt;
1. '''Eclipse'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Integrated_development_environment&amp;lt;/ref&amp;gt;: Eclipse is the Integrated Development Environment used to develop, modify, and compile the code for our module. &amp;lt;br&amp;gt;&lt;br /&gt;
2. '''Maven'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Maven&amp;lt;/ref&amp;gt;: Maven is used through a plug-in in Eclipse to compile, run unit tests, and package all of the Java files in the module.  &amp;lt;br&amp;gt;&lt;br /&gt;
3. '''Tomcat'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Tomcat&amp;lt;/ref&amp;gt;: Tomcat is the web-server used to run the application. &amp;lt;br&amp;gt; &lt;br /&gt;
4. '''Hibernate'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Hibernate_(Java)&amp;lt;/ref&amp;gt;: Hibernate is a built-in utility in the OpenMRS module, that is used to connect the Java classes to the database tables in the application. It configured the database table through an xml file: UpdateCSS.hbm.xml&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE hibernate-mapping PUBLIC&lt;br /&gt;
    &amp;quot;-//Hibernate/Hibernate Mapping DTD 3.0//EN&amp;quot;&lt;br /&gt;
    &amp;quot;http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&amp;quot; &amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hibernate-mapping package=&amp;quot;org.openmrs.module.updatecss&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;class name=&amp;quot;UpdateCSS&amp;quot;&lt;br /&gt;
	table=&amp;quot;css_properties&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;id name=&amp;quot;id&amp;quot; type=&amp;quot;int&amp;quot; column=&amp;quot;id&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;generator class=&amp;quot;native&amp;quot;/&amp;gt;&lt;br /&gt;
        &amp;lt;/id&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;cssData&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;css_location&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;homeDirectory&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;tomcat_home&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/class&amp;gt;&lt;br /&gt;
&amp;lt;/hibernate-mapping&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
''Here in the UpdateCSS.hbm.xml we specify the table name and columns. Hibernate generates the table with the fields specified and handles all the necessary SQL calls and queries.''&amp;lt;br&amp;gt;&lt;br /&gt;
5. '''MySQL''': MySQL&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Mysql&amp;lt;/ref&amp;gt; is the RDBMS that is used to store the CSS data for the application.&lt;br /&gt;
&lt;br /&gt;
==Use Case==&lt;br /&gt;
[[File:Openmrsui.png|800px|alt=OpenMRS UI]]&amp;lt;br&amp;gt;&lt;br /&gt;
''This is the user interface for the UpdateCSS module. The initial start screen provides a default location for the css style sheet and default css code. Here the navigation bar is changed to &amp;quot;orange&amp;quot;. ''&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
1. Log in to the Admin page with user &amp;quot;Admin&amp;quot; and password &amp;quot;Admin123&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
2. Once logged in, click on &amp;quot;Administration&amp;quot; on the right-hand side of the navigation bar. &amp;lt;br&amp;gt;&lt;br /&gt;
3. Under &amp;quot;Update CSS Module&amp;quot;, click on &amp;quot;Manage module&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
4. Here the user can enter their desired CSS preferences for customization. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Application Overview==&lt;br /&gt;
[[File:Overview.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt;Code Changes&amp;lt;/h1&amp;gt;&lt;br /&gt;
==Classes and Files Worked On==&lt;br /&gt;
* UpdateCSSActivator.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSS.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSService.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSServiceImpl.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSDAO.java &amp;lt;br&amp;gt;&lt;br /&gt;
* HibernateUpdateCSSDAO.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSS.hbm.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* liquibase.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* moduleApplicationContext.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSServiceTest.java &amp;lt;br&amp;gt;&lt;br /&gt;
* manage.jsp &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSManageController.java &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Specific Changes==&lt;br /&gt;
'''UpdateCSSActivator.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSServiceImpl.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
Added below methods to UpdateCSSServiceImpl class: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  /**&lt;br /&gt;
+   * Replaces the text of the specified CSS file in the&lt;br /&gt;
+   * specified directory with the specified text&lt;br /&gt;
+   */ +  public void copyCssDataToTomcatDirectory(String directory, String cssText) {&lt;br /&gt;
+    File cssFile = new File(directory);&lt;br /&gt;
+    if (cssFile.exists()) {&lt;br /&gt;
+      writeDataToFile(cssFile, cssText);&lt;br /&gt;
+    }&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Copies the data stored in the DB into the CSS file that is saved in the &lt;br /&gt;
+   * directory column of the css_properties table&lt;br /&gt;
+   */&lt;br /&gt;
+  public void copyCssDataToTomcatDirectory() {&lt;br /&gt;
+    UpdateCSS updateCSS = getData();&lt;br /&gt;
+    String cssDirectory = updateCSS.getHomeDirectory();&lt;br /&gt;
+    String cssText = updateCSS.getCssData();&lt;br /&gt;
+    copyCssDataToTomcatDirectory(cssDirectory, cssText);&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Writes the specified text to the specified CSS file&lt;br /&gt;
+   */&lt;br /&gt;
+  public void writeDataToFile(File cssFile, String cssText) {&lt;br /&gt;
+    try {&lt;br /&gt;
+      if (cssFile.exists()) {&lt;br /&gt;
+        PrintWriter writer = new PrintWriter(cssFile);&lt;br /&gt;
+        writer.print(cssText);&lt;br /&gt;
+        writer.close();&lt;br /&gt;
+      }&lt;br /&gt;
+    } catch (FileNotFoundException ex) {&lt;br /&gt;
+      &lt;br /&gt;
+    }&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Reads the data in the file at the specified path and returns&lt;br /&gt;
+   * a String with the contents. If the file doesn't exist&lt;br /&gt;
+   * then it returns an empty string&lt;br /&gt;
+   */&lt;br /&gt;
+  public String getCssTextFromFile(String filePath) {&lt;br /&gt;
+    String cssText = &amp;quot;&amp;quot;;&lt;br /&gt;
+    try {&lt;br /&gt;
+      File cssFile = new File(filePath);&lt;br /&gt;
+      if (cssFile.exists()) {&lt;br /&gt;
+        cssText = FileUtils.readFileToString(cssFile);&lt;br /&gt;
+      }  &lt;br /&gt;
+    } catch (IOException ex) {&lt;br /&gt;
+    &lt;br /&gt;
+    }&lt;br /&gt;
+    return cssText;&lt;br /&gt;
+  }&lt;br /&gt;
+    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''UpdateCSS.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSDAO.java/HibernateUpdateCSSDAO.java'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The DAO files carry the primary responsibility of interaction with the DB layer in the MVC architecture.&amp;lt;br&amp;gt;&lt;br /&gt;
The data layer changes involved 3 separate components:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. liquibase.xml file to configure our new table: css_properties&amp;lt;br&amp;gt;&lt;br /&gt;
2. UpdateCSSDAO.java/HibernateUpdateCSSDAO.java - Interface/Implementation for DAO getter/setter.&amp;lt;br&amp;gt;&lt;br /&gt;
3. UpdateCSS.hbm.xml - Hibernate configuration file for mapping DAO to new properties table.&amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSService.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSManageController.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517/M601_Design_Document&amp;diff=75194</id>
		<title>CSC/ECE 517/M601 Design Document</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517/M601_Design_Document&amp;diff=75194"/>
		<updated>2013-04-27T02:25:42Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: /* Specific Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;h1&amp;gt;Add ability to update css through webapp&amp;lt;/h1&amp;gt;&lt;br /&gt;
== Example Video ==&lt;br /&gt;
A video example of this module can be seen here [http://youtu.be/2dQeFYjcsnU]&lt;br /&gt;
==Team== &lt;br /&gt;
Yuri Kolesnikov &amp;lt;br&amp;gt;&lt;br /&gt;
Jonathan Wills &amp;lt;br&amp;gt;&lt;br /&gt;
Jeffrey Plemmons &amp;lt;br&amp;gt;&lt;br /&gt;
Roshna Agarwal&lt;br /&gt;
&lt;br /&gt;
==Our Work==&lt;br /&gt;
Link to the OpenMRS ticket: https://tickets.openmrs.org/browse/TRUNK-3415&amp;lt;br&amp;gt;&lt;br /&gt;
Link to our code in GitHub: https://github.com/ykolesn/openmrs-module-m601 &amp;lt;br&amp;gt;&lt;br /&gt;
Link to application: http://152.46.17.228:8081/openmrs-standalone&lt;br /&gt;
&lt;br /&gt;
==Purpose==&lt;br /&gt;
	The purpose of this module is to add the functionality of allowing the admin to customize the OpenMRS css file to their own specifications. By having the ability to customize the OpenMRS css file, the admin will be free to change the look and feel in their installation of OpenMRS.&lt;br /&gt;
&lt;br /&gt;
==Problem Definition==&lt;br /&gt;
	Add admin page for customization of the openmrs css file. Admins can 'override' any openmrs css with their own file by specifying that file in the openmrs runtime properties file.&lt;br /&gt;
This would be best as a new module in openmrs or perhaps just adding a new feature in the Custom Logo module? The admin should see a page with a large text box. The text box value should be persisted in the database as a new object/table/column somehow. When the module starts up, the Activator is called. Modify the activator to update the filesystem css file with whatever is defined by the admin.&lt;br /&gt;
&lt;br /&gt;
==Design Requirements==&lt;br /&gt;
&lt;br /&gt;
1. The admin should be able to customize the openmrs css file through an admin page. &amp;lt;br&amp;gt;&lt;br /&gt;
2. The admin should see a page with a large text box. &amp;lt;br&amp;gt;&lt;br /&gt;
3. The text box content should be stored in the database. &amp;lt;br&amp;gt;&lt;br /&gt;
4. The activator needs to be modified so that it updates the filesystem css file with whatever is defined by the admin. &amp;lt;br&amp;gt;&lt;br /&gt;
5. Need to use Eclipse and Maven as development tools for the module. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
'''Week 1'''&lt;br /&gt;
&lt;br /&gt;
*Get OpenMRS Id&lt;br /&gt;
*Get ticket assigned and in progress&lt;br /&gt;
*Get openmrs module name assigned&lt;br /&gt;
*Create openmrs module&lt;br /&gt;
*Commit module to github&lt;br /&gt;
*Check out module on partner machines&lt;br /&gt;
*Get new admin page link&lt;br /&gt;
*Create new spring controller and jsp page&lt;br /&gt;
'''Week 2'''&lt;br /&gt;
&lt;br /&gt;
*Create object for storing css in db&lt;br /&gt;
*Create service layer and dao layer methods to save object&lt;br /&gt;
*Connect controller to db object for saving + retrieving&lt;br /&gt;
*Add unit tests for saving/retrieving&lt;br /&gt;
'''Week 3'''&lt;br /&gt;
&lt;br /&gt;
*Create settings page to allow admin to choose where tomcat is running&lt;br /&gt;
*Add some magic so that module tries to guess where tomcat is running&lt;br /&gt;
*Add ability to put the saved css into the right folder in tomcat so that the css is actually overriding the openmrs style.css file.&lt;br /&gt;
&lt;br /&gt;
==Development Tools==&lt;br /&gt;
1. '''Eclipse'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Integrated_development_environment&amp;lt;/ref&amp;gt;: Eclipse is the Integrated Development Environment used to develop, modify, and compile the code for our module. &amp;lt;br&amp;gt;&lt;br /&gt;
2. '''Maven'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Maven&amp;lt;/ref&amp;gt;: Maven is used through a plug-in in Eclipse to compile, run unit tests, and package all of the Java files in the module.  &amp;lt;br&amp;gt;&lt;br /&gt;
3. '''Tomcat'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Tomcat&amp;lt;/ref&amp;gt;: Tomcat is the web-server used to run the application. &amp;lt;br&amp;gt; &lt;br /&gt;
4. '''Hibernate'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Hibernate_(Java)&amp;lt;/ref&amp;gt;: Hibernate is a built-in utility in the OpenMRS module, that is used to connect the Java classes to the database tables in the application. It configured the database table through an xml file: UpdateCSS.hbm.xml&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE hibernate-mapping PUBLIC&lt;br /&gt;
    &amp;quot;-//Hibernate/Hibernate Mapping DTD 3.0//EN&amp;quot;&lt;br /&gt;
    &amp;quot;http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&amp;quot; &amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hibernate-mapping package=&amp;quot;org.openmrs.module.updatecss&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;class name=&amp;quot;UpdateCSS&amp;quot;&lt;br /&gt;
	table=&amp;quot;css_properties&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;id name=&amp;quot;id&amp;quot; type=&amp;quot;int&amp;quot; column=&amp;quot;id&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;generator class=&amp;quot;native&amp;quot;/&amp;gt;&lt;br /&gt;
        &amp;lt;/id&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;cssData&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;css_location&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;homeDirectory&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;tomcat_home&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/class&amp;gt;&lt;br /&gt;
&amp;lt;/hibernate-mapping&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
''Here in the UpdateCSS.hbm.xml we specify the table name and columns. Hibernate generates the table with the fields specified and handles all the necessary SQL calls and queries.''&amp;lt;br&amp;gt;&lt;br /&gt;
5. '''MySQL''': MySQL&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Mysql&amp;lt;/ref&amp;gt; is the RDBMS that is used to store the CSS data for the application.&lt;br /&gt;
&lt;br /&gt;
==Use Case==&lt;br /&gt;
[[File:Openmrsui.png|800px|alt=OpenMRS UI]]&amp;lt;br&amp;gt;&lt;br /&gt;
''This is the user interface for the UpdateCSS module. The initial start screen provides a default location for the css style sheet and default css code. Here the navigation bar is changed to &amp;quot;orange&amp;quot;. ''&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
1. Log in to the Admin page with user &amp;quot;Admin&amp;quot; and password &amp;quot;Admin123&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
2. Once logged in, click on &amp;quot;Administration&amp;quot; on the right-hand side of the navigation bar. &amp;lt;br&amp;gt;&lt;br /&gt;
3. Under &amp;quot;Update CSS Module&amp;quot;, click on &amp;quot;Manage module&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
4. Here the user can enter their desired CSS preferences for customization. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Application Overview==&lt;br /&gt;
[[File:Overview.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt;Code Changes&amp;lt;/h1&amp;gt;&lt;br /&gt;
==Classes and Files Worked On==&lt;br /&gt;
* UpdateCSSActivator.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSS.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSService.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSServiceImpl.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSDAO.java &amp;lt;br&amp;gt;&lt;br /&gt;
* HibernateUpdateCSSDAO.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSS.hbm.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* liquibase.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* moduleApplicationContext.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSServiceTest.java &amp;lt;br&amp;gt;&lt;br /&gt;
* manage.jsp &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSManageController.java &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Specific Changes==&lt;br /&gt;
'''UpdateCSSActivator.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSServiceImpl.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
Added below methods to UpdateCSSServiceImpl class: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  /**&lt;br /&gt;
+   * Replaces the text of the specified CSS file in the&lt;br /&gt;
+   * specified directory with the specified text&lt;br /&gt;
+   */ +  public void copyCssDataToTomcatDirectory(String directory, String cssText) {&lt;br /&gt;
+    File cssFile = new File(directory);&lt;br /&gt;
+    if (cssFile.exists()) {&lt;br /&gt;
+      writeDataToFile(cssFile, cssText);&lt;br /&gt;
+    }&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Copies the data stored in the DB into the CSS file that is saved in the &lt;br /&gt;
+   * directory column of the css_properties table&lt;br /&gt;
+   */&lt;br /&gt;
+  public void copyCssDataToTomcatDirectory() {&lt;br /&gt;
+    UpdateCSS updateCSS = getData();&lt;br /&gt;
+    String cssDirectory = updateCSS.getHomeDirectory();&lt;br /&gt;
+    String cssText = updateCSS.getCssData();&lt;br /&gt;
+    copyCssDataToTomcatDirectory(cssDirectory, cssText);&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Writes the specified text to the specified CSS file&lt;br /&gt;
+   */&lt;br /&gt;
+  public void writeDataToFile(File cssFile, String cssText) {&lt;br /&gt;
+    try {&lt;br /&gt;
+      if (cssFile.exists()) {&lt;br /&gt;
+        PrintWriter writer = new PrintWriter(cssFile);&lt;br /&gt;
+        writer.print(cssText);&lt;br /&gt;
+        writer.close();&lt;br /&gt;
+      }&lt;br /&gt;
+    } catch (FileNotFoundException ex) {&lt;br /&gt;
+      &lt;br /&gt;
+    }&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Reads the data in the file at the specified path and returns&lt;br /&gt;
+   * a String with the contents. If the file doesn't exist&lt;br /&gt;
+   * then it returns an empty string&lt;br /&gt;
+   */&lt;br /&gt;
+  public String getCssTextFromFile(String filePath) {&lt;br /&gt;
+    String cssText = &amp;quot;&amp;quot;;&lt;br /&gt;
+    try {&lt;br /&gt;
+      File cssFile = new File(filePath);&lt;br /&gt;
+      if (cssFile.exists()) {&lt;br /&gt;
+        cssText = FileUtils.readFileToString(cssFile);&lt;br /&gt;
+      }  &lt;br /&gt;
+    } catch (IOException ex) {&lt;br /&gt;
+    &lt;br /&gt;
+    }&lt;br /&gt;
+    return cssText;&lt;br /&gt;
+  }&lt;br /&gt;
+    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''UpdateCSS.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSDAO.java/HibernateUpdateCSSDAO.java'''&amp;lt;br&amp;gt;&lt;br /&gt;
The DAO files carry the primary responsibility of interaction with the DB layer in the MVC architecture.&amp;lt;br&amp;gt;&lt;br /&gt;
The data layer changes involved 3 separate components:&amp;lt;br&amp;gt;&lt;br /&gt;
1. liquibase.xml file to configure our new table: css_properties&amp;lt;br&amp;gt;&lt;br /&gt;
2. UpdateCSSDAO.java/HibernateUpdateCSSDAO.java - Interface/Implementation for DAO getter/setter.&amp;lt;br&amp;gt;&lt;br /&gt;
3. UpdateCSS.hbm.xml - Hibernate configuration file for mapping DAO to new properties table.&amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSService.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSManageController.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517/M601_Design_Document&amp;diff=75193</id>
		<title>CSC/ECE 517/M601 Design Document</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517/M601_Design_Document&amp;diff=75193"/>
		<updated>2013-04-27T02:24:57Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;h1&amp;gt;Add ability to update css through webapp&amp;lt;/h1&amp;gt;&lt;br /&gt;
== Example Video ==&lt;br /&gt;
A video example of this module can be seen here [http://youtu.be/2dQeFYjcsnU]&lt;br /&gt;
==Team== &lt;br /&gt;
Yuri Kolesnikov &amp;lt;br&amp;gt;&lt;br /&gt;
Jonathan Wills &amp;lt;br&amp;gt;&lt;br /&gt;
Jeffrey Plemmons &amp;lt;br&amp;gt;&lt;br /&gt;
Roshna Agarwal&lt;br /&gt;
&lt;br /&gt;
==Our Work==&lt;br /&gt;
Link to the OpenMRS ticket: https://tickets.openmrs.org/browse/TRUNK-3415&amp;lt;br&amp;gt;&lt;br /&gt;
Link to our code in GitHub: https://github.com/ykolesn/openmrs-module-m601 &amp;lt;br&amp;gt;&lt;br /&gt;
Link to application: http://152.46.17.228:8081/openmrs-standalone&lt;br /&gt;
&lt;br /&gt;
==Purpose==&lt;br /&gt;
	The purpose of this module is to add the functionality of allowing the admin to customize the OpenMRS css file to their own specifications. By having the ability to customize the OpenMRS css file, the admin will be free to change the look and feel in their installation of OpenMRS.&lt;br /&gt;
&lt;br /&gt;
==Problem Definition==&lt;br /&gt;
	Add admin page for customization of the openmrs css file. Admins can 'override' any openmrs css with their own file by specifying that file in the openmrs runtime properties file.&lt;br /&gt;
This would be best as a new module in openmrs or perhaps just adding a new feature in the Custom Logo module? The admin should see a page with a large text box. The text box value should be persisted in the database as a new object/table/column somehow. When the module starts up, the Activator is called. Modify the activator to update the filesystem css file with whatever is defined by the admin.&lt;br /&gt;
&lt;br /&gt;
==Design Requirements==&lt;br /&gt;
&lt;br /&gt;
1. The admin should be able to customize the openmrs css file through an admin page. &amp;lt;br&amp;gt;&lt;br /&gt;
2. The admin should see a page with a large text box. &amp;lt;br&amp;gt;&lt;br /&gt;
3. The text box content should be stored in the database. &amp;lt;br&amp;gt;&lt;br /&gt;
4. The activator needs to be modified so that it updates the filesystem css file with whatever is defined by the admin. &amp;lt;br&amp;gt;&lt;br /&gt;
5. Need to use Eclipse and Maven as development tools for the module. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
'''Week 1'''&lt;br /&gt;
&lt;br /&gt;
*Get OpenMRS Id&lt;br /&gt;
*Get ticket assigned and in progress&lt;br /&gt;
*Get openmrs module name assigned&lt;br /&gt;
*Create openmrs module&lt;br /&gt;
*Commit module to github&lt;br /&gt;
*Check out module on partner machines&lt;br /&gt;
*Get new admin page link&lt;br /&gt;
*Create new spring controller and jsp page&lt;br /&gt;
'''Week 2'''&lt;br /&gt;
&lt;br /&gt;
*Create object for storing css in db&lt;br /&gt;
*Create service layer and dao layer methods to save object&lt;br /&gt;
*Connect controller to db object for saving + retrieving&lt;br /&gt;
*Add unit tests for saving/retrieving&lt;br /&gt;
'''Week 3'''&lt;br /&gt;
&lt;br /&gt;
*Create settings page to allow admin to choose where tomcat is running&lt;br /&gt;
*Add some magic so that module tries to guess where tomcat is running&lt;br /&gt;
*Add ability to put the saved css into the right folder in tomcat so that the css is actually overriding the openmrs style.css file.&lt;br /&gt;
&lt;br /&gt;
==Development Tools==&lt;br /&gt;
1. '''Eclipse'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Integrated_development_environment&amp;lt;/ref&amp;gt;: Eclipse is the Integrated Development Environment used to develop, modify, and compile the code for our module. &amp;lt;br&amp;gt;&lt;br /&gt;
2. '''Maven'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Maven&amp;lt;/ref&amp;gt;: Maven is used through a plug-in in Eclipse to compile, run unit tests, and package all of the Java files in the module.  &amp;lt;br&amp;gt;&lt;br /&gt;
3. '''Tomcat'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Tomcat&amp;lt;/ref&amp;gt;: Tomcat is the web-server used to run the application. &amp;lt;br&amp;gt; &lt;br /&gt;
4. '''Hibernate'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Hibernate_(Java)&amp;lt;/ref&amp;gt;: Hibernate is a built-in utility in the OpenMRS module, that is used to connect the Java classes to the database tables in the application. It configured the database table through an xml file: UpdateCSS.hbm.xml&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE hibernate-mapping PUBLIC&lt;br /&gt;
    &amp;quot;-//Hibernate/Hibernate Mapping DTD 3.0//EN&amp;quot;&lt;br /&gt;
    &amp;quot;http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&amp;quot; &amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hibernate-mapping package=&amp;quot;org.openmrs.module.updatecss&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;class name=&amp;quot;UpdateCSS&amp;quot;&lt;br /&gt;
	table=&amp;quot;css_properties&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;id name=&amp;quot;id&amp;quot; type=&amp;quot;int&amp;quot; column=&amp;quot;id&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;generator class=&amp;quot;native&amp;quot;/&amp;gt;&lt;br /&gt;
        &amp;lt;/id&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;cssData&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;css_location&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;homeDirectory&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;tomcat_home&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/class&amp;gt;&lt;br /&gt;
&amp;lt;/hibernate-mapping&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
''Here in the UpdateCSS.hbm.xml we specify the table name and columns. Hibernate generates the table with the fields specified and handles all the necessary SQL calls and queries.''&amp;lt;br&amp;gt;&lt;br /&gt;
5. '''MySQL''': MySQL&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Mysql&amp;lt;/ref&amp;gt; is the RDBMS that is used to store the CSS data for the application.&lt;br /&gt;
&lt;br /&gt;
==Use Case==&lt;br /&gt;
[[File:Openmrsui.png|800px|alt=OpenMRS UI]]&amp;lt;br&amp;gt;&lt;br /&gt;
''This is the user interface for the UpdateCSS module. The initial start screen provides a default location for the css style sheet and default css code. Here the navigation bar is changed to &amp;quot;orange&amp;quot;. ''&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
1. Log in to the Admin page with user &amp;quot;Admin&amp;quot; and password &amp;quot;Admin123&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
2. Once logged in, click on &amp;quot;Administration&amp;quot; on the right-hand side of the navigation bar. &amp;lt;br&amp;gt;&lt;br /&gt;
3. Under &amp;quot;Update CSS Module&amp;quot;, click on &amp;quot;Manage module&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
4. Here the user can enter their desired CSS preferences for customization. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Application Overview==&lt;br /&gt;
[[File:Overview.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt;Code Changes&amp;lt;/h1&amp;gt;&lt;br /&gt;
==Classes and Files Worked On==&lt;br /&gt;
* UpdateCSSActivator.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSS.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSService.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSServiceImpl.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSDAO.java &amp;lt;br&amp;gt;&lt;br /&gt;
* HibernateUpdateCSSDAO.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSS.hbm.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* liquibase.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* moduleApplicationContext.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSServiceTest.java &amp;lt;br&amp;gt;&lt;br /&gt;
* manage.jsp &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSManageController.java &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Specific Changes==&lt;br /&gt;
'''UpdateCSSActivator.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSServiceImpl.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
Added below methods to UpdateCSSServiceImpl class: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  /**&lt;br /&gt;
+   * Replaces the text of the specified CSS file in the&lt;br /&gt;
+   * specified directory with the specified text&lt;br /&gt;
+   */ +  public void copyCssDataToTomcatDirectory(String directory, String cssText) {&lt;br /&gt;
+    File cssFile = new File(directory);&lt;br /&gt;
+    if (cssFile.exists()) {&lt;br /&gt;
+      writeDataToFile(cssFile, cssText);&lt;br /&gt;
+    }&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Copies the data stored in the DB into the CSS file that is saved in the &lt;br /&gt;
+   * directory column of the css_properties table&lt;br /&gt;
+   */&lt;br /&gt;
+  public void copyCssDataToTomcatDirectory() {&lt;br /&gt;
+    UpdateCSS updateCSS = getData();&lt;br /&gt;
+    String cssDirectory = updateCSS.getHomeDirectory();&lt;br /&gt;
+    String cssText = updateCSS.getCssData();&lt;br /&gt;
+    copyCssDataToTomcatDirectory(cssDirectory, cssText);&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Writes the specified text to the specified CSS file&lt;br /&gt;
+   */&lt;br /&gt;
+  public void writeDataToFile(File cssFile, String cssText) {&lt;br /&gt;
+    try {&lt;br /&gt;
+      if (cssFile.exists()) {&lt;br /&gt;
+        PrintWriter writer = new PrintWriter(cssFile);&lt;br /&gt;
+        writer.print(cssText);&lt;br /&gt;
+        writer.close();&lt;br /&gt;
+      }&lt;br /&gt;
+    } catch (FileNotFoundException ex) {&lt;br /&gt;
+      &lt;br /&gt;
+    }&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Reads the data in the file at the specified path and returns&lt;br /&gt;
+   * a String with the contents. If the file doesn't exist&lt;br /&gt;
+   * then it returns an empty string&lt;br /&gt;
+   */&lt;br /&gt;
+  public String getCssTextFromFile(String filePath) {&lt;br /&gt;
+    String cssText = &amp;quot;&amp;quot;;&lt;br /&gt;
+    try {&lt;br /&gt;
+      File cssFile = new File(filePath);&lt;br /&gt;
+      if (cssFile.exists()) {&lt;br /&gt;
+        cssText = FileUtils.readFileToString(cssFile);&lt;br /&gt;
+      }  &lt;br /&gt;
+    } catch (IOException ex) {&lt;br /&gt;
+    &lt;br /&gt;
+    }&lt;br /&gt;
+    return cssText;&lt;br /&gt;
+  }&lt;br /&gt;
+    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''UpdateCSS.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSDAO.java/HibernateUpdateCSSDAO.java'''&amp;lt;br&amp;gt;&lt;br /&gt;
The DAO files carry the primary responsibility of interaction with the DB layer in the MVC architecture.&amp;lt;br&amp;gt;&lt;br /&gt;
The data layer changes involved 3 separate components:&lt;br /&gt;
1. liquibase.xml file to configure our new table: css_properties&lt;br /&gt;
2. UpdateCSSDAO.java/HibernateUpdateCSSDAO.java - Interface/Implementation for DAO getter/setter.&lt;br /&gt;
3. UpdateCSS.hbm.xml - Hibernate configuration file for mapping DAO to new properties table.&lt;br /&gt;
'''UpdateCSSService.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSManageController.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517/M601_Design_Document&amp;diff=75191</id>
		<title>CSC/ECE 517/M601 Design Document</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517/M601_Design_Document&amp;diff=75191"/>
		<updated>2013-04-27T02:01:22Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: /* Specific Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;h1&amp;gt;Add ability to update css through webapp&amp;lt;/h1&amp;gt;&lt;br /&gt;
== Example Video ==&lt;br /&gt;
A video example of this module can be seen here [http://youtu.be/2dQeFYjcsnU]&lt;br /&gt;
==Team== &lt;br /&gt;
Yuri Kolesnikov &amp;lt;br&amp;gt;&lt;br /&gt;
Jonathan Wills &amp;lt;br&amp;gt;&lt;br /&gt;
Jeffrey Plemmons &amp;lt;br&amp;gt;&lt;br /&gt;
Roshna Agarwal&lt;br /&gt;
&lt;br /&gt;
==Our Work==&lt;br /&gt;
Link to the OpenMRS ticket: https://tickets.openmrs.org/browse/TRUNK-3415&amp;lt;br&amp;gt;&lt;br /&gt;
Link to our code in GitHub: https://github.com/ykolesn/openmrs-module-m601 &amp;lt;br&amp;gt;&lt;br /&gt;
Link to application: http://152.46.17.228:8081/openmrs-standalone&lt;br /&gt;
&lt;br /&gt;
==Purpose==&lt;br /&gt;
	The purpose of this module is to add the functionality of allowing the admin to customize the OpenMRS css file to their own specifications. By having the ability to customize the OpenMRS css file, the admin will be free to change the look and feel in their installation of OpenMRS.&lt;br /&gt;
&lt;br /&gt;
==Problem Definition==&lt;br /&gt;
	Add admin page for customization of the openmrs css file. Admins can 'override' any openmrs css with their own file by specifying that file in the openmrs runtime properties file.&lt;br /&gt;
This would be best as a new module in openmrs or perhaps just adding a new feature in the Custom Logo module? The admin should see a page with a large text box. The text box value should be persisted in the database as a new object/table/column somehow. When the module starts up, the Activator is called. Modify the activator to update the filesystem css file with whatever is defined by the admin.&lt;br /&gt;
&lt;br /&gt;
==Design Requirements==&lt;br /&gt;
&lt;br /&gt;
1. The admin should be able to customize the openmrs css file through an admin page. &amp;lt;br&amp;gt;&lt;br /&gt;
2. The admin should see a page with a large text box. &amp;lt;br&amp;gt;&lt;br /&gt;
3. The text box content should be stored in the database. &amp;lt;br&amp;gt;&lt;br /&gt;
4. The activator needs to be modified so that it updates the filesystem css file with whatever is defined by the admin. &amp;lt;br&amp;gt;&lt;br /&gt;
5. Need to use Eclipse and Maven as development tools for the module. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
'''Week 1'''&lt;br /&gt;
&lt;br /&gt;
*Get OpenMRS Id&lt;br /&gt;
*Get ticket assigned and in progress&lt;br /&gt;
*Get openmrs module name assigned&lt;br /&gt;
*Create openmrs module&lt;br /&gt;
*Commit module to github&lt;br /&gt;
*Check out module on partner machines&lt;br /&gt;
*Get new admin page link&lt;br /&gt;
*Create new spring controller and jsp page&lt;br /&gt;
'''Week 2'''&lt;br /&gt;
&lt;br /&gt;
*Create object for storing css in db&lt;br /&gt;
*Create service layer and dao layer methods to save object&lt;br /&gt;
*Connect controller to db object for saving + retrieving&lt;br /&gt;
*Add unit tests for saving/retrieving&lt;br /&gt;
'''Week 3'''&lt;br /&gt;
&lt;br /&gt;
*Create settings page to allow admin to choose where tomcat is running&lt;br /&gt;
*Add some magic so that module tries to guess where tomcat is running&lt;br /&gt;
*Add ability to put the saved css into the right folder in tomcat so that the css is actually overriding the openmrs style.css file.&lt;br /&gt;
&lt;br /&gt;
==Development Tools==&lt;br /&gt;
1. '''Eclipse'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Integrated_development_environment&amp;lt;/ref&amp;gt;: Eclipse is the Integrated Development Environment used to develop, modify, and compile the code for our module. &amp;lt;br&amp;gt;&lt;br /&gt;
2. '''Maven'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Maven&amp;lt;/ref&amp;gt;: Maven is used through a plug-in in Eclipse to compile, run unit tests, and package all of the Java files in the module.  &amp;lt;br&amp;gt;&lt;br /&gt;
3. '''Tomcat'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Tomcat&amp;lt;/ref&amp;gt;: Tomcat is the web-server used to run the application. &amp;lt;br&amp;gt; &lt;br /&gt;
4. '''Hibernate'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Hibernate_(Java)&amp;lt;/ref&amp;gt;: Hibernate is a built-in utility in the OpenMRS module, that is used to connect the Java classes to the database tables in the application. It configured the database table through an xml file: UpdateCSS.hbm.xml&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE hibernate-mapping PUBLIC&lt;br /&gt;
    &amp;quot;-//Hibernate/Hibernate Mapping DTD 3.0//EN&amp;quot;&lt;br /&gt;
    &amp;quot;http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&amp;quot; &amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hibernate-mapping package=&amp;quot;org.openmrs.module.updatecss&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;class name=&amp;quot;UpdateCSS&amp;quot;&lt;br /&gt;
	table=&amp;quot;css_properties&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;id name=&amp;quot;id&amp;quot; type=&amp;quot;int&amp;quot; column=&amp;quot;id&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;generator class=&amp;quot;native&amp;quot;/&amp;gt;&lt;br /&gt;
        &amp;lt;/id&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;cssData&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;css_location&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;homeDirectory&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;tomcat_home&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/class&amp;gt;&lt;br /&gt;
&amp;lt;/hibernate-mapping&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
''Here in the UpdateCSS.hbm.xml we specify the table name and columns. Hibernate generates the table with the fields specified and handles all the necessary SQL calls and queries.''&amp;lt;br&amp;gt;&lt;br /&gt;
5. '''MySQL''': MySQL&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Mysql&amp;lt;/ref&amp;gt; is the RDBMS that is used to store the CSS data for the application.&lt;br /&gt;
&lt;br /&gt;
==Use Case==&lt;br /&gt;
[[File:Openmrsui.png|800px|alt=OpenMRS UI]]&amp;lt;br&amp;gt;&lt;br /&gt;
''This is the user interface for the UpdateCSS module. The initial start screen provides a default location for the css style sheet and default css code. Here the navigation bar is changed to &amp;quot;orange&amp;quot;. ''&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
1. Log in to the Admin page with user &amp;quot;Admin&amp;quot; and password &amp;quot;Admin123&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
2. Once logged in, click on &amp;quot;Administration&amp;quot; on the right-hand side of the navigation bar. &amp;lt;br&amp;gt;&lt;br /&gt;
3. Under &amp;quot;Update CSS Module&amp;quot;, click on &amp;quot;Manage module&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
4. Here the user can enter their desired CSS preferences for customization. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Application Overview==&lt;br /&gt;
[[File:Overview.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt;Code Changes&amp;lt;/h1&amp;gt;&lt;br /&gt;
==Classes and Files Worked On==&lt;br /&gt;
* UpdateCSSActivator.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSS.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSService.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSServiceImpl.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSDAO.java &amp;lt;br&amp;gt;&lt;br /&gt;
* HibernateUpdateCSSDAO.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSS.hbm.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* liquibase.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* moduleApplicationContext.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSServiceTest.java &amp;lt;br&amp;gt;&lt;br /&gt;
* manage.jsp &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSManageController.java &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Specific Changes==&lt;br /&gt;
'''UpdateCSSActivator.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSServiceImpl.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
Added below code: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  /**&lt;br /&gt;
+   * Replaces the text of the specified CSS file in the&lt;br /&gt;
+   * specified directory with the specified text&lt;br /&gt;
+   */ +  public void copyCssDataToTomcatDirectory(String directory, String cssText) {&lt;br /&gt;
+    File cssFile = new File(directory);&lt;br /&gt;
+    if (cssFile.exists()) {&lt;br /&gt;
+      writeDataToFile(cssFile, cssText);&lt;br /&gt;
+    }&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Copies the data stored in the DB into the CSS file that is saved in the &lt;br /&gt;
+   * directory column of the css_properties table&lt;br /&gt;
+   */&lt;br /&gt;
+  public void copyCssDataToTomcatDirectory() {&lt;br /&gt;
+    UpdateCSS updateCSS = getData();&lt;br /&gt;
+    String cssDirectory = updateCSS.getHomeDirectory();&lt;br /&gt;
+    String cssText = updateCSS.getCssData();&lt;br /&gt;
+    copyCssDataToTomcatDirectory(cssDirectory, cssText);&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Writes the specified text to the specified CSS file&lt;br /&gt;
+   */&lt;br /&gt;
+  public void writeDataToFile(File cssFile, String cssText) {&lt;br /&gt;
+    try {&lt;br /&gt;
+      if (cssFile.exists()) {&lt;br /&gt;
+        PrintWriter writer = new PrintWriter(cssFile);&lt;br /&gt;
+        writer.print(cssText);&lt;br /&gt;
+        writer.close();&lt;br /&gt;
+      }&lt;br /&gt;
+    } catch (FileNotFoundException ex) {&lt;br /&gt;
+      &lt;br /&gt;
+    }&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Reads the data in the file at the specified path and returns&lt;br /&gt;
+   * a String with the contents. If the file doesn't exist&lt;br /&gt;
+   * then it returns an empty string&lt;br /&gt;
+   */&lt;br /&gt;
+  public String getCssTextFromFile(String filePath) {&lt;br /&gt;
+    String cssText = &amp;quot;&amp;quot;;&lt;br /&gt;
+    try {&lt;br /&gt;
+      File cssFile = new File(filePath);&lt;br /&gt;
+      if (cssFile.exists()) {&lt;br /&gt;
+        cssText = FileUtils.readFileToString(cssFile);&lt;br /&gt;
+      }  &lt;br /&gt;
+    } catch (IOException ex) {&lt;br /&gt;
+    &lt;br /&gt;
+    }&lt;br /&gt;
+    return cssText;&lt;br /&gt;
+  }&lt;br /&gt;
+    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''UpdateCSS.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSDAO.java/HibernateUpdateCSSDAO.java'''&amp;lt;br&amp;gt;&lt;br /&gt;
The DAO files carry the primary responsibility of interaction with the DB layer in the MVC architecture.&amp;lt;br&amp;gt;&lt;br /&gt;
The data layer changes involved &lt;br /&gt;
'''UpdateCSSService.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSManageController.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517/M601_Design_Document&amp;diff=75190</id>
		<title>CSC/ECE 517/M601 Design Document</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517/M601_Design_Document&amp;diff=75190"/>
		<updated>2013-04-27T01:48:40Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: /* Specific Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;h1&amp;gt;Add ability to update css through webapp&amp;lt;/h1&amp;gt;&lt;br /&gt;
== Example Video ==&lt;br /&gt;
A video example of this module can be seen here [http://youtu.be/2dQeFYjcsnU]&lt;br /&gt;
==Team== &lt;br /&gt;
Yuri Kolesnikov &amp;lt;br&amp;gt;&lt;br /&gt;
Jonathan Wills &amp;lt;br&amp;gt;&lt;br /&gt;
Jeffrey Plemmons &amp;lt;br&amp;gt;&lt;br /&gt;
Roshna Agarwal&lt;br /&gt;
&lt;br /&gt;
==Our Work==&lt;br /&gt;
Link to the OpenMRS ticket: https://tickets.openmrs.org/browse/TRUNK-3415&amp;lt;br&amp;gt;&lt;br /&gt;
Link to our code in GitHub: https://github.com/ykolesn/openmrs-module-m601 &amp;lt;br&amp;gt;&lt;br /&gt;
Link to application: http://152.46.17.228:8081/openmrs-standalone&lt;br /&gt;
&lt;br /&gt;
==Purpose==&lt;br /&gt;
	The purpose of this module is to add the functionality of allowing the admin to customize the OpenMRS css file to their own specifications. By having the ability to customize the OpenMRS css file, the admin will be free to change the look and feel in their installation of OpenMRS.&lt;br /&gt;
&lt;br /&gt;
==Problem Definition==&lt;br /&gt;
	Add admin page for customization of the openmrs css file. Admins can 'override' any openmrs css with their own file by specifying that file in the openmrs runtime properties file.&lt;br /&gt;
This would be best as a new module in openmrs or perhaps just adding a new feature in the Custom Logo module? The admin should see a page with a large text box. The text box value should be persisted in the database as a new object/table/column somehow. When the module starts up, the Activator is called. Modify the activator to update the filesystem css file with whatever is defined by the admin.&lt;br /&gt;
&lt;br /&gt;
==Design Requirements==&lt;br /&gt;
&lt;br /&gt;
1. The admin should be able to customize the openmrs css file through an admin page. &amp;lt;br&amp;gt;&lt;br /&gt;
2. The admin should see a page with a large text box. &amp;lt;br&amp;gt;&lt;br /&gt;
3. The text box content should be stored in the database. &amp;lt;br&amp;gt;&lt;br /&gt;
4. The activator needs to be modified so that it updates the filesystem css file with whatever is defined by the admin. &amp;lt;br&amp;gt;&lt;br /&gt;
5. Need to use Eclipse and Maven as development tools for the module. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
'''Week 1'''&lt;br /&gt;
&lt;br /&gt;
*Get OpenMRS Id&lt;br /&gt;
*Get ticket assigned and in progress&lt;br /&gt;
*Get openmrs module name assigned&lt;br /&gt;
*Create openmrs module&lt;br /&gt;
*Commit module to github&lt;br /&gt;
*Check out module on partner machines&lt;br /&gt;
*Get new admin page link&lt;br /&gt;
*Create new spring controller and jsp page&lt;br /&gt;
'''Week 2'''&lt;br /&gt;
&lt;br /&gt;
*Create object for storing css in db&lt;br /&gt;
*Create service layer and dao layer methods to save object&lt;br /&gt;
*Connect controller to db object for saving + retrieving&lt;br /&gt;
*Add unit tests for saving/retrieving&lt;br /&gt;
'''Week 3'''&lt;br /&gt;
&lt;br /&gt;
*Create settings page to allow admin to choose where tomcat is running&lt;br /&gt;
*Add some magic so that module tries to guess where tomcat is running&lt;br /&gt;
*Add ability to put the saved css into the right folder in tomcat so that the css is actually overriding the openmrs style.css file.&lt;br /&gt;
&lt;br /&gt;
==Development Tools==&lt;br /&gt;
1. '''Eclipse'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Integrated_development_environment&amp;lt;/ref&amp;gt;: Eclipse is the Integrated Development Environment used to develop, modify, and compile the code for our module. &amp;lt;br&amp;gt;&lt;br /&gt;
2. '''Maven'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Maven&amp;lt;/ref&amp;gt;: Maven is used through a plug-in in Eclipse to compile, run unit tests, and package all of the Java files in the module.  &amp;lt;br&amp;gt;&lt;br /&gt;
3. '''Tomcat'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Tomcat&amp;lt;/ref&amp;gt;: Tomcat is the web-server used to run the application. &amp;lt;br&amp;gt; &lt;br /&gt;
4. '''Hibernate'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Hibernate_(Java)&amp;lt;/ref&amp;gt;: Hibernate is a built-in utility in the OpenMRS module, that is used to connect the Java classes to the database tables in the application. It configured the database table through an xml file: UpdateCSS.hbm.xml&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE hibernate-mapping PUBLIC&lt;br /&gt;
    &amp;quot;-//Hibernate/Hibernate Mapping DTD 3.0//EN&amp;quot;&lt;br /&gt;
    &amp;quot;http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&amp;quot; &amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hibernate-mapping package=&amp;quot;org.openmrs.module.updatecss&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;class name=&amp;quot;UpdateCSS&amp;quot;&lt;br /&gt;
	table=&amp;quot;css_properties&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;id name=&amp;quot;id&amp;quot; type=&amp;quot;int&amp;quot; column=&amp;quot;id&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;generator class=&amp;quot;native&amp;quot;/&amp;gt;&lt;br /&gt;
        &amp;lt;/id&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;cssData&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;css_location&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;homeDirectory&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;tomcat_home&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/class&amp;gt;&lt;br /&gt;
&amp;lt;/hibernate-mapping&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
''Here in the UpdateCSS.hbm.xml we specify the table name and columns. Hibernate generates the table with the fields specified and handles all the necessary SQL calls and queries.''&amp;lt;br&amp;gt;&lt;br /&gt;
5. '''MySQL''': MySQL&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Mysql&amp;lt;/ref&amp;gt; is the RDBMS that is used to store the CSS data for the application.&lt;br /&gt;
&lt;br /&gt;
==Use Case==&lt;br /&gt;
[[File:Openmrsui.png|800px|alt=OpenMRS UI]]&amp;lt;br&amp;gt;&lt;br /&gt;
''This is the user interface for the UpdateCSS module. The initial start screen provides a default location for the css style sheet and default css code. Here the navigation bar is changed to &amp;quot;orange&amp;quot;. ''&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
1. Log in to the Admin page with user &amp;quot;Admin&amp;quot; and password &amp;quot;Admin123&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
2. Once logged in, click on &amp;quot;Administration&amp;quot; on the right-hand side of the navigation bar. &amp;lt;br&amp;gt;&lt;br /&gt;
3. Under &amp;quot;Update CSS Module&amp;quot;, click on &amp;quot;Manage module&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
4. Here the user can enter their desired CSS preferences for customization. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Application Overview==&lt;br /&gt;
[[File:Overview.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt;Code Changes&amp;lt;/h1&amp;gt;&lt;br /&gt;
==Classes and Files Worked On==&lt;br /&gt;
* UpdateCSSActivator.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSS.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSService.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSServiceImpl.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSDAO.java &amp;lt;br&amp;gt;&lt;br /&gt;
* HibernateUpdateCSSDAO.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSS.hbm.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* liquibase.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* moduleApplicationContext.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSServiceTest.java &amp;lt;br&amp;gt;&lt;br /&gt;
* manage.jsp &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSManageController.java &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Specific Changes==&lt;br /&gt;
'''UpdateCSSActivator.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSServiceImpl.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
Added below code: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  /**&lt;br /&gt;
+   * Replaces the text of the specified CSS file in the&lt;br /&gt;
+   * specified directory with the specified text&lt;br /&gt;
+   */ +  public void copyCssDataToTomcatDirectory(String directory, String cssText) {&lt;br /&gt;
+    File cssFile = new File(directory);&lt;br /&gt;
+    if (cssFile.exists()) {&lt;br /&gt;
+      writeDataToFile(cssFile, cssText);&lt;br /&gt;
+    }&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Copies the data stored in the DB into the CSS file that is saved in the &lt;br /&gt;
+   * directory column of the css_properties table&lt;br /&gt;
+   */&lt;br /&gt;
+  public void copyCssDataToTomcatDirectory() {&lt;br /&gt;
+    UpdateCSS updateCSS = getData();&lt;br /&gt;
+    String cssDirectory = updateCSS.getHomeDirectory();&lt;br /&gt;
+    String cssText = updateCSS.getCssData();&lt;br /&gt;
+    copyCssDataToTomcatDirectory(cssDirectory, cssText);&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Writes the specified text to the specified CSS file&lt;br /&gt;
+   */&lt;br /&gt;
+  public void writeDataToFile(File cssFile, String cssText) {&lt;br /&gt;
+    try {&lt;br /&gt;
+      if (cssFile.exists()) {&lt;br /&gt;
+        PrintWriter writer = new PrintWriter(cssFile);&lt;br /&gt;
+        writer.print(cssText);&lt;br /&gt;
+        writer.close();&lt;br /&gt;
+      }&lt;br /&gt;
+    } catch (FileNotFoundException ex) {&lt;br /&gt;
+      &lt;br /&gt;
+    }&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Reads the data in the file at the specified path and returns&lt;br /&gt;
+   * a String with the contents. If the file doesn't exist&lt;br /&gt;
+   * then it returns an empty string&lt;br /&gt;
+   */&lt;br /&gt;
+  public String getCssTextFromFile(String filePath) {&lt;br /&gt;
+    String cssText = &amp;quot;&amp;quot;;&lt;br /&gt;
+    try {&lt;br /&gt;
+      File cssFile = new File(filePath);&lt;br /&gt;
+      if (cssFile.exists()) {&lt;br /&gt;
+        cssText = FileUtils.readFileToString(cssFile);&lt;br /&gt;
+      }  &lt;br /&gt;
+    } catch (IOException ex) {&lt;br /&gt;
+    &lt;br /&gt;
+    }&lt;br /&gt;
+    return cssText;&lt;br /&gt;
+  }&lt;br /&gt;
+    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''UpdateCSS.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSDAO.java/HibernateUpdateCSSDAO.java'''&amp;lt;br&amp;gt;&lt;br /&gt;
The DAO files carry the primary responsibility of interaction with the DB layer in the MVC architecture.&lt;br /&gt;
'''UpdateCSSService.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSManageController.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517/M601_Design_Document&amp;diff=75189</id>
		<title>CSC/ECE 517/M601 Design Document</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517/M601_Design_Document&amp;diff=75189"/>
		<updated>2013-04-27T01:47:55Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;h1&amp;gt;Add ability to update css through webapp&amp;lt;/h1&amp;gt;&lt;br /&gt;
== Example Video ==&lt;br /&gt;
A video example of this module can be seen here [http://youtu.be/2dQeFYjcsnU]&lt;br /&gt;
==Team== &lt;br /&gt;
Yuri Kolesnikov &amp;lt;br&amp;gt;&lt;br /&gt;
Jonathan Wills &amp;lt;br&amp;gt;&lt;br /&gt;
Jeffrey Plemmons &amp;lt;br&amp;gt;&lt;br /&gt;
Roshna Agarwal&lt;br /&gt;
&lt;br /&gt;
==Our Work==&lt;br /&gt;
Link to the OpenMRS ticket: https://tickets.openmrs.org/browse/TRUNK-3415&amp;lt;br&amp;gt;&lt;br /&gt;
Link to our code in GitHub: https://github.com/ykolesn/openmrs-module-m601 &amp;lt;br&amp;gt;&lt;br /&gt;
Link to application: http://152.46.17.228:8081/openmrs-standalone&lt;br /&gt;
&lt;br /&gt;
==Purpose==&lt;br /&gt;
	The purpose of this module is to add the functionality of allowing the admin to customize the OpenMRS css file to their own specifications. By having the ability to customize the OpenMRS css file, the admin will be free to change the look and feel in their installation of OpenMRS.&lt;br /&gt;
&lt;br /&gt;
==Problem Definition==&lt;br /&gt;
	Add admin page for customization of the openmrs css file. Admins can 'override' any openmrs css with their own file by specifying that file in the openmrs runtime properties file.&lt;br /&gt;
This would be best as a new module in openmrs or perhaps just adding a new feature in the Custom Logo module? The admin should see a page with a large text box. The text box value should be persisted in the database as a new object/table/column somehow. When the module starts up, the Activator is called. Modify the activator to update the filesystem css file with whatever is defined by the admin.&lt;br /&gt;
&lt;br /&gt;
==Design Requirements==&lt;br /&gt;
&lt;br /&gt;
1. The admin should be able to customize the openmrs css file through an admin page. &amp;lt;br&amp;gt;&lt;br /&gt;
2. The admin should see a page with a large text box. &amp;lt;br&amp;gt;&lt;br /&gt;
3. The text box content should be stored in the database. &amp;lt;br&amp;gt;&lt;br /&gt;
4. The activator needs to be modified so that it updates the filesystem css file with whatever is defined by the admin. &amp;lt;br&amp;gt;&lt;br /&gt;
5. Need to use Eclipse and Maven as development tools for the module. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
'''Week 1'''&lt;br /&gt;
&lt;br /&gt;
*Get OpenMRS Id&lt;br /&gt;
*Get ticket assigned and in progress&lt;br /&gt;
*Get openmrs module name assigned&lt;br /&gt;
*Create openmrs module&lt;br /&gt;
*Commit module to github&lt;br /&gt;
*Check out module on partner machines&lt;br /&gt;
*Get new admin page link&lt;br /&gt;
*Create new spring controller and jsp page&lt;br /&gt;
'''Week 2'''&lt;br /&gt;
&lt;br /&gt;
*Create object for storing css in db&lt;br /&gt;
*Create service layer and dao layer methods to save object&lt;br /&gt;
*Connect controller to db object for saving + retrieving&lt;br /&gt;
*Add unit tests for saving/retrieving&lt;br /&gt;
'''Week 3'''&lt;br /&gt;
&lt;br /&gt;
*Create settings page to allow admin to choose where tomcat is running&lt;br /&gt;
*Add some magic so that module tries to guess where tomcat is running&lt;br /&gt;
*Add ability to put the saved css into the right folder in tomcat so that the css is actually overriding the openmrs style.css file.&lt;br /&gt;
&lt;br /&gt;
==Development Tools==&lt;br /&gt;
1. '''Eclipse'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Integrated_development_environment&amp;lt;/ref&amp;gt;: Eclipse is the Integrated Development Environment used to develop, modify, and compile the code for our module. &amp;lt;br&amp;gt;&lt;br /&gt;
2. '''Maven'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Maven&amp;lt;/ref&amp;gt;: Maven is used through a plug-in in Eclipse to compile, run unit tests, and package all of the Java files in the module.  &amp;lt;br&amp;gt;&lt;br /&gt;
3. '''Tomcat'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Tomcat&amp;lt;/ref&amp;gt;: Tomcat is the web-server used to run the application. &amp;lt;br&amp;gt; &lt;br /&gt;
4. '''Hibernate'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Hibernate_(Java)&amp;lt;/ref&amp;gt;: Hibernate is a built-in utility in the OpenMRS module, that is used to connect the Java classes to the database tables in the application. It configured the database table through an xml file: UpdateCSS.hbm.xml&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE hibernate-mapping PUBLIC&lt;br /&gt;
    &amp;quot;-//Hibernate/Hibernate Mapping DTD 3.0//EN&amp;quot;&lt;br /&gt;
    &amp;quot;http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&amp;quot; &amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hibernate-mapping package=&amp;quot;org.openmrs.module.updatecss&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;class name=&amp;quot;UpdateCSS&amp;quot;&lt;br /&gt;
	table=&amp;quot;css_properties&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;id name=&amp;quot;id&amp;quot; type=&amp;quot;int&amp;quot; column=&amp;quot;id&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;generator class=&amp;quot;native&amp;quot;/&amp;gt;&lt;br /&gt;
        &amp;lt;/id&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;cssData&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;css_location&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;property name=&amp;quot;homeDirectory&amp;quot; type=&amp;quot;java.lang.String&amp;quot; column=&amp;quot;tomcat_home&amp;quot;&lt;br /&gt;
			length=&amp;quot;255&amp;quot; not-null=&amp;quot;true&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/class&amp;gt;&lt;br /&gt;
&amp;lt;/hibernate-mapping&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
''Here in the UpdateCSS.hbm.xml we specify the table name and columns. Hibernate generates the table with the fields specified and handles all the necessary SQL calls and queries.''&amp;lt;br&amp;gt;&lt;br /&gt;
5. '''MySQL''': MySQL&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Mysql&amp;lt;/ref&amp;gt; is the RDBMS that is used to store the CSS data for the application.&lt;br /&gt;
&lt;br /&gt;
==Use Case==&lt;br /&gt;
[[File:Openmrsui.png|800px|alt=OpenMRS UI]]&amp;lt;br&amp;gt;&lt;br /&gt;
''This is the user interface for the UpdateCSS module. The initial start screen provides a default location for the css style sheet and default css code. Here the navigation bar is changed to &amp;quot;orange&amp;quot;. ''&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
1. Log in to the Admin page with user &amp;quot;Admin&amp;quot; and password &amp;quot;Admin123&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
2. Once logged in, click on &amp;quot;Administration&amp;quot; on the right-hand side of the navigation bar. &amp;lt;br&amp;gt;&lt;br /&gt;
3. Under &amp;quot;Update CSS Module&amp;quot;, click on &amp;quot;Manage module&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
4. Here the user can enter their desired CSS preferences for customization. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Application Overview==&lt;br /&gt;
[[File:Overview.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt;Code Changes&amp;lt;/h1&amp;gt;&lt;br /&gt;
==Classes and Files Worked On==&lt;br /&gt;
* UpdateCSSActivator.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSS.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSService.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSServiceImpl.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSDAO.java &amp;lt;br&amp;gt;&lt;br /&gt;
* HibernateUpdateCSSDAO.java &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSS.hbm.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* liquibase.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* moduleApplicationContext.xml &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSServiceTest.java &amp;lt;br&amp;gt;&lt;br /&gt;
* manage.jsp &amp;lt;br&amp;gt;&lt;br /&gt;
* UpdateCSSManageController.java &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Specific Changes==&lt;br /&gt;
'''UpdateCSSActivator.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSServiceImpl.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
Added below code: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  /**&lt;br /&gt;
+   * Replaces the text of the specified CSS file in the&lt;br /&gt;
+   * specified directory with the specified text&lt;br /&gt;
+   */ +  public void copyCssDataToTomcatDirectory(String directory, String cssText) {&lt;br /&gt;
+    File cssFile = new File(directory);&lt;br /&gt;
+    if (cssFile.exists()) {&lt;br /&gt;
+      writeDataToFile(cssFile, cssText);&lt;br /&gt;
+    }&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Copies the data stored in the DB into the CSS file that is saved in the &lt;br /&gt;
+   * directory column of the css_properties table&lt;br /&gt;
+   */&lt;br /&gt;
+  public void copyCssDataToTomcatDirectory() {&lt;br /&gt;
+    UpdateCSS updateCSS = getData();&lt;br /&gt;
+    String cssDirectory = updateCSS.getHomeDirectory();&lt;br /&gt;
+    String cssText = updateCSS.getCssData();&lt;br /&gt;
+    copyCssDataToTomcatDirectory(cssDirectory, cssText);&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Writes the specified text to the specified CSS file&lt;br /&gt;
+   */&lt;br /&gt;
+  public void writeDataToFile(File cssFile, String cssText) {&lt;br /&gt;
+    try {&lt;br /&gt;
+      if (cssFile.exists()) {&lt;br /&gt;
+        PrintWriter writer = new PrintWriter(cssFile);&lt;br /&gt;
+        writer.print(cssText);&lt;br /&gt;
+        writer.close();&lt;br /&gt;
+      }&lt;br /&gt;
+    } catch (FileNotFoundException ex) {&lt;br /&gt;
+      &lt;br /&gt;
+    }&lt;br /&gt;
+  }&lt;br /&gt;
+  &lt;br /&gt;
+  /**&lt;br /&gt;
+   * Reads the data in the file at the specified path and returns&lt;br /&gt;
+   * a String with the contents. If the file doesn't exist&lt;br /&gt;
+   * then it returns an empty string&lt;br /&gt;
+   */&lt;br /&gt;
+  public String getCssTextFromFile(String filePath) {&lt;br /&gt;
+    String cssText = &amp;quot;&amp;quot;;&lt;br /&gt;
+    try {&lt;br /&gt;
+      File cssFile = new File(filePath);&lt;br /&gt;
+      if (cssFile.exists()) {&lt;br /&gt;
+        cssText = FileUtils.readFileToString(cssFile);&lt;br /&gt;
+      }  &lt;br /&gt;
+    } catch (IOException ex) {&lt;br /&gt;
+    &lt;br /&gt;
+    }&lt;br /&gt;
+    return cssText;&lt;br /&gt;
+  }&lt;br /&gt;
+    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''UpdateCSS.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSDAO.java/HibernateUpdateCSSDAO.java'''&lt;br /&gt;
The DAO files carry the primary responsibility of interaction with the DB layer in the MVC architecture.&lt;br /&gt;
'''UpdateCSSService.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
'''UpdateCSSManageController.java:''' &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73468</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1n jp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73468"/>
		<updated>2013-02-21T01:34:36Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: /* Perl: AUTOLOAD */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby's method_missing(): Advantages/Disadvantages and Alternatives =&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
One of the distinguishing features of the Ruby programming language is it's ability to easily extend classes in a dynamic fashion to perform a variety of different methods depending upon the needs of the current application.  For example, should the developer want to extend a core language class, take String for example, they could easily re-open that class and add new methods dynamically to this existing class, rather than creating an entirely new class.&lt;br /&gt;
&lt;br /&gt;
Even more powerful, Ruby allows for a construct called method_missing().  By overriding this method in your class, method_missing() will attempt to handle any method calls not currently defined by the given class (or class hierarchy).  Typically, some sort of regular expression is used to determine if the method call can be redirected to an existing method based on it's naming convention (for example, a method call in a non-existent singular form could be redirected to an existing pluralized form).  If the method_missing() definition cannot determine where to redirect the method call, the default is simply to call the parent class via super().&lt;br /&gt;
&lt;br /&gt;
By having the ability to allow a class to dynamically extend itself even if a method definition never truly existed, Ruby allows for a far greater degree of flexibility than does a statically typed language such as Java, where much greater effort is involved in handing method calls that do not currently exist.  With method_missing() defined, almost any sort of method call can be handled in the desired manner.&lt;br /&gt;
&lt;br /&gt;
This article will explore the method_missing() construct in greater detail, giving both advantages and disadvantages of having this feature in the Ruby language.  We will also examine how other programming languages attempt to handle the same problem.&lt;br /&gt;
&lt;br /&gt;
==Advantages of method_missing()==&lt;br /&gt;
1. Allows for dynamically invoked methods.&lt;br /&gt;
 &lt;br /&gt;
==Disadvantages of method_missing()==&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==Alternatives to method_missing() in other programming languages==&lt;br /&gt;
&lt;br /&gt;
===Smalltalk: doesNotUnderstand===&lt;br /&gt;
&lt;br /&gt;
In many ways the inspiration for Ruby, Smalltalk is often considered one of the original truly Object-Oriented languages.  Smalltalk, much like Ruby with method_missing(), sends a message called #doesNotUnderstand&amp;lt;ref&amp;gt;http://c2.com/cgi/wiki?DoesNotUnderstand&amp;lt;/ref&amp;gt; to handle methods that are unknown.&lt;br /&gt;
&lt;br /&gt;
Essentially, when an object receives a method that it doesn't recognize, the Smalltalk runtime engine is then responsible for turning this message into an object with all necessary parameters and returning it to the sender as an exception. The sender is, at that point, responsible for handling the message and somehow dealing with the exception.  Even though Smalltalk does consider this an exception, this construct is used quite frequently to form proxy objects and can handle a wide variety of different methods and arguments.&lt;br /&gt;
&lt;br /&gt;
Consider the following code: &amp;lt;ref&amp;gt;http://www.iam.unibe.ch/~akuhn/blog/category/smalltalk/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    OrderedCollection subclass: #Group.&lt;br /&gt;
    Group &amp;gt;&amp;gt; eachRespondsTo: aSelector&lt;br /&gt;
        self allSatisfy: [ :each | each respondsTo: aSelector ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; doesNotUnderstand: aMessage&lt;br /&gt;
        (self eachRespondsTo: aMessage selector)&lt;br /&gt;
          ifTrue: [ self collect: [ :each | aMessage sendTo: each ] ]&lt;br /&gt;
          ifFalse: [ super doesNotUnderstand: aMessage ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; respondsTo: aSelector&lt;br /&gt;
      ^ (super respondsTo: aSelector) or: [ self eachRespondsTo: aSelector ]&lt;br /&gt;
&lt;br /&gt;
In this code snippet, an OrderedCollection object is created.  Should this collection class not understand any of the methods being sent to it, the doesUnderstand code will attempt to handle the message itself.  Without overriding this method, the default is for Smalltalk to open a debugger to step through the exception (defining it overrides this behavior).&lt;br /&gt;
&lt;br /&gt;
===Java: DynamicProxy===&lt;br /&gt;
&lt;br /&gt;
In Java, the ability to handle undefined methods is a bit more cumbersome, but it can still be done successfully through the use of dynamic proxy classes.  By creating this dynamic proxy, all calls will essentially be intercepted prior to invocation.  An attempt will be made to invoke the object in question and, if unable to do so, an interface will need to be defined to handle the missing method scenarios.  To give an example&amp;lt;ref&amp;gt;http://www.jroller.com/ie/entry/methodmissing_in_java&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
  public class Dynamic implements java.lang.reflect.InvocationHandler  {&lt;br /&gt;
        Object delegate;&lt;br /&gt;
        public Dynamic(Object delegate){&lt;br /&gt;
                this.delegate=delegate;&lt;br /&gt;
        }        &lt;br /&gt;
        public Object invoke(Object proxy, Method method, Object[] args) &lt;br /&gt;
                           throws Throwable {&lt;br /&gt;
                Object result = null;&lt;br /&gt;
                try {                  &lt;br /&gt;
                    result = method.invoke(delegate, args);&lt;br /&gt;
                } catch (InvocationTargetException e) {&lt;br /&gt;
                        result = &lt;br /&gt;
                  ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } catch (Exception e) {&lt;br /&gt;
                    result = &lt;br /&gt;
             ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } finally {&lt;br /&gt;
                    &lt;br /&gt;
                }&lt;br /&gt;
                if(result==delegate)&lt;br /&gt;
                        result = proxy;&lt;br /&gt;
                &lt;br /&gt;
                return result;&lt;br /&gt;
        }&lt;br /&gt;
        public static T newInstance(Object o,Class... interfaces) {&lt;br /&gt;
                return (T)java.lang.reflect.Proxy.newProxyInstance(&lt;br /&gt;
                    interfaces[0].getClassLoader(),&lt;br /&gt;
                    interfaces,&lt;br /&gt;
                    new Dynamic(o));&lt;br /&gt;
        }        &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Here, we define our Proxy class.  Note, both an Object and Method are passed in as parameters.  When attempting to invoke the method of the given Object, an exception is caught and delegated to a MethodMissing interface, which will also need to be defined.&lt;br /&gt;
&lt;br /&gt;
  public interface MethodMissing {&lt;br /&gt;
        public T methodMissing(Method method,E... args);        &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Now, we define an interface whose methods will need to be implemented in order to handle the missing objects.&lt;br /&gt;
&lt;br /&gt;
  public class Ruby implements MethodMissing{&lt;br /&gt;
        public Object methodMissing(Method method, Object... args) {&lt;br /&gt;
                System.out.println(method.getName());&lt;br /&gt;
                return this;&lt;br /&gt;
        }&lt;br /&gt;
        public static void main(String[] args){&lt;br /&gt;
                IDynamic dynamic = &lt;br /&gt;
                   Dynamic.newInstance(new Ruby(), IDynamic.class);               &lt;br /&gt;
                dynamic.meow().woof();&lt;br /&gt;
                dynamic.woof();&lt;br /&gt;
                &lt;br /&gt;
        }               &lt;br /&gt;
  }&lt;br /&gt;
  public interface IDynamic extends MethodMissing{&lt;br /&gt;
        public IDynamic woof();&lt;br /&gt;
        public IDynamic meow();&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Lastly, we create a class that attempts to utilize the MethodMissing construct.  As you can see, the Ruby class creates an implementation of the methodMissing() method, choosing to simply reflect the name of the method itself.  When the IDynamic class is created, it attempts to run several methods which are never actually defined.  Nevertheless, all of these method calls are actually intercepted by our proxy class and called as if there were no issue.&lt;br /&gt;
&lt;br /&gt;
The output of running this class would be:&lt;br /&gt;
&lt;br /&gt;
  meow&lt;br /&gt;
  woof&lt;br /&gt;
  woof&lt;br /&gt;
&lt;br /&gt;
Compared to Ruby, of course, or even Smalltalk, this is a very difficult way to handle missing methods.  Instead of having something built into the class itself, additional interfaces and wrappers are required to handle these scenarios, creating far more bulky and complex code.  Unfortunately, this is probably the price for having a statically typed language.&lt;br /&gt;
&lt;br /&gt;
===Python: __getattr__===&lt;br /&gt;
&lt;br /&gt;
In Python, much like Ruby, there is also a built-in class mechanism for handling non-existent methods.  Built into a class is __getattr__, which can be used to provide a default for all Python attributes that have not otherwise been defined.  In the following example: &amp;lt;ref&amp;gt;http://farmdev.com/src/secrets/magicmethod/index.html#introducing-getattr&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  class Test(object):&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        self.a = 'a'&lt;br /&gt;
        self.b = 'b'&lt;br /&gt;
    def __getattr__(self, name):&lt;br /&gt;
        return 123456&lt;br /&gt;
  t = Test()&lt;br /&gt;
  print 'object variables: %r' % t.__dict__.keys()&lt;br /&gt;
  print t.a&lt;br /&gt;
  print t.b&lt;br /&gt;
  print t.c&lt;br /&gt;
  print getattr(t, 'd')&lt;br /&gt;
  print hasattr(t, 'x')&lt;br /&gt;
&lt;br /&gt;
Expected output:&lt;br /&gt;
&lt;br /&gt;
  object variables: ['a', 'b']&lt;br /&gt;
  a&lt;br /&gt;
  b&lt;br /&gt;
  123456&lt;br /&gt;
  123456&lt;br /&gt;
  True&lt;br /&gt;
&lt;br /&gt;
In the above code, the Test class has variable definitions for 'a' and 'b', but no others.  When the print method tries to send in a 'c' or 'd' method call, __getattr__ catches this call and prints the generic '123456' value.  Even the hasattr method recognizes non-existent attributes as being valid without there even being an actual method call.&lt;br /&gt;
&lt;br /&gt;
If an attribute is found through a normal mechanism, this function is never actually called.  In fact, one difference with Ruby is that Python executes this method in a static fashion, only checking on one run if attributes have been defined somewhere for a relevant class.  This code may in fact not perform properly if classes are modified dynamically at runtime.&lt;br /&gt;
&lt;br /&gt;
===Perl: AUTOLOAD===&lt;br /&gt;
&lt;br /&gt;
Lastly, the Perl programming language provides the AUTOLOAD feature for handling this situation. Basically, if a class or any parent classes define an AUTOLOAD method, this method is called in the case where a direct method isn't found. &amp;lt;ref&amp;gt;http://perldoc.perl.org/perlobj.html#AUTOLOAD&amp;lt;/ref&amp;gt;  Anything that the AUTOLOAD method returns will be the last value returned to the caller (the caller never even needs to know the AUTOLOAD code exists).&lt;br /&gt;
&lt;br /&gt;
The following is a code snippet that can be used to auto-create methods on the fly in Perl using AUTOLOAD: &amp;lt;ref&amp;gt;http://www.perlmonks.org/?node_id=8227&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #!/usr/bin/perl -w&lt;br /&gt;
  package myClass;&lt;br /&gt;
  use strict;&lt;br /&gt;
  use vars qw{$AUTOLOAD $Debug};&lt;br /&gt;
  $Debug = 1;&lt;br /&gt;
  sub new {&lt;br /&gt;
    return bless {&lt;br /&gt;
      thing	=&amp;gt; 1,&lt;br /&gt;
      thang	=&amp;gt; 2,&lt;br /&gt;
      thong	=&amp;gt; 3,&lt;br /&gt;
    }, shift;&lt;br /&gt;
  }&lt;br /&gt;
  sub AUTOLOAD {&lt;br /&gt;
    my $self = shift or return undef;&lt;br /&gt;
      # Get the called method name and trim off the fully-qualified part&lt;br /&gt;
      ( my $method = $AUTOLOAD ) =~ s{.*::}{};&lt;br /&gt;
        # If the data member being accessed exists, build an accessor for it&lt;br /&gt;
        if ( exists $self-&amp;gt;{$method} ) {&lt;br /&gt;
          ### Create a closure that will become the new accessor method&lt;br /&gt;
            my $accessor = sub {&lt;br /&gt;
            my $closureSelf = shift;&lt;br /&gt;
            if ( @_ ) {&lt;br /&gt;
              return $closureSelf-&amp;gt;{$method} = shift;&lt;br /&gt;
            }&lt;br /&gt;
              return $closureSelf-&amp;gt;{$method}&lt;br /&gt;
            }&lt;br /&gt;
            # Assign the closure to the symbol table at the place where the real&lt;br /&gt;
            # method should be. We need to turn off strict refs, as we'll be mucking&lt;br /&gt;
            # with the symbol table.&lt;br /&gt;
            SYMBOL_TABLE_HACQUERY: {&lt;br /&gt;
              no strict qw{refs};&lt;br /&gt;
              *$AUTOLOAD = $accessor;&lt;br /&gt;
            }&lt;br /&gt;
            # Turn the call back into a method call by sticking the self-reference&lt;br /&gt;
            # back onto the arglist&lt;br /&gt;
            unshift @_, $self;&lt;br /&gt;
            # Jump to the newly-created method with magic goto&lt;br /&gt;
            goto &amp;amp;$AUTOLOAD;&lt;br /&gt;
        }&lt;br /&gt;
        ### Handle other autoloaded methods or errors&lt;br /&gt;
  }&lt;br /&gt;
  DESTROY {}&lt;br /&gt;
  ### Test program&lt;br /&gt;
  package main;&lt;br /&gt;
  my $a = new myClass;&lt;br /&gt;
  print $a-&amp;gt;thing, $a-&amp;gt;thang, $a-&amp;gt;thong, &amp;quot;\n&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
In the above example, new accessor methods are being created dynamically where closures are being added to the symbol table and then the relevant method is loaded for the caller.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73466</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1n jp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73466"/>
		<updated>2013-02-21T01:31:26Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: /* Perl: AUTOLOAD */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby's method_missing(): Advantages/Disadvantages and Alternatives =&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
One of the distinguishing features of the Ruby programming language is it's ability to easily extend classes in a dynamic fashion to perform a variety of different methods depending upon the needs of the current application.  For example, should the developer want to extend a core language class, take String for example, they could easily re-open that class and add new methods dynamically to this existing class, rather than creating an entirely new class.&lt;br /&gt;
&lt;br /&gt;
Even more powerful, Ruby allows for a construct called method_missing().  By overriding this method in your class, method_missing() will attempt to handle any method calls not currently defined by the given class (or class hierarchy).  Typically, some sort of regular expression is used to determine if the method call can be redirected to an existing method based on it's naming convention (for example, a method call in a non-existent singular form could be redirected to an existing pluralized form).  If the method_missing() definition cannot determine where to redirect the method call, the default is simply to call the parent class via super().&lt;br /&gt;
&lt;br /&gt;
By having the ability to allow a class to dynamically extend itself even if a method definition never truly existed, Ruby allows for a far greater degree of flexibility than does a statically typed language such as Java, where much greater effort is involved in handing method calls that do not currently exist.  With method_missing() defined, almost any sort of method call can be handled in the desired manner.&lt;br /&gt;
&lt;br /&gt;
This article will explore the method_missing() construct in greater detail, giving both advantages and disadvantages of having this feature in the Ruby language.  We will also examine how other programming languages attempt to handle the same problem.&lt;br /&gt;
&lt;br /&gt;
==Advantages of method_missing()==&lt;br /&gt;
1. Allows for dynamically invoked methods.&lt;br /&gt;
 &lt;br /&gt;
==Disadvantages of method_missing()==&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==Alternatives to method_missing() in other programming languages==&lt;br /&gt;
&lt;br /&gt;
===Smalltalk: doesNotUnderstand===&lt;br /&gt;
&lt;br /&gt;
In many ways the inspiration for Ruby, Smalltalk is often considered one of the original truly Object-Oriented languages.  Smalltalk, much like Ruby with method_missing(), sends a message called #doesNotUnderstand&amp;lt;ref&amp;gt;http://c2.com/cgi/wiki?DoesNotUnderstand&amp;lt;/ref&amp;gt; to handle methods that are unknown.&lt;br /&gt;
&lt;br /&gt;
Essentially, when an object receives a method that it doesn't recognize, the Smalltalk runtime engine is then responsible for turning this message into an object with all necessary parameters and returning it to the sender as an exception. The sender is, at that point, responsible for handling the message and somehow dealing with the exception.  Even though Smalltalk does consider this an exception, this construct is used quite frequently to form proxy objects and can handle a wide variety of different methods and arguments.&lt;br /&gt;
&lt;br /&gt;
Consider the following code: &amp;lt;ref&amp;gt;http://www.iam.unibe.ch/~akuhn/blog/category/smalltalk/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    OrderedCollection subclass: #Group.&lt;br /&gt;
    Group &amp;gt;&amp;gt; eachRespondsTo: aSelector&lt;br /&gt;
        self allSatisfy: [ :each | each respondsTo: aSelector ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; doesNotUnderstand: aMessage&lt;br /&gt;
        (self eachRespondsTo: aMessage selector)&lt;br /&gt;
          ifTrue: [ self collect: [ :each | aMessage sendTo: each ] ]&lt;br /&gt;
          ifFalse: [ super doesNotUnderstand: aMessage ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; respondsTo: aSelector&lt;br /&gt;
      ^ (super respondsTo: aSelector) or: [ self eachRespondsTo: aSelector ]&lt;br /&gt;
&lt;br /&gt;
In this code snippet, an OrderedCollection object is created.  Should this collection class not understand any of the methods being sent to it, the doesUnderstand code will attempt to handle the message itself.  Without overriding this method, the default is for Smalltalk to open a debugger to step through the exception (defining it overrides this behavior).&lt;br /&gt;
&lt;br /&gt;
===Java: DynamicProxy===&lt;br /&gt;
&lt;br /&gt;
In Java, the ability to handle undefined methods is a bit more cumbersome, but it can still be done successfully through the use of dynamic proxy classes.  By creating this dynamic proxy, all calls will essentially be intercepted prior to invocation.  An attempt will be made to invoke the object in question and, if unable to do so, an interface will need to be defined to handle the missing method scenarios.  To give an example&amp;lt;ref&amp;gt;http://www.jroller.com/ie/entry/methodmissing_in_java&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
  public class Dynamic implements java.lang.reflect.InvocationHandler  {&lt;br /&gt;
        Object delegate;&lt;br /&gt;
        public Dynamic(Object delegate){&lt;br /&gt;
                this.delegate=delegate;&lt;br /&gt;
        }        &lt;br /&gt;
        public Object invoke(Object proxy, Method method, Object[] args) &lt;br /&gt;
                           throws Throwable {&lt;br /&gt;
                Object result = null;&lt;br /&gt;
                try {                  &lt;br /&gt;
                    result = method.invoke(delegate, args);&lt;br /&gt;
                } catch (InvocationTargetException e) {&lt;br /&gt;
                        result = &lt;br /&gt;
                  ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } catch (Exception e) {&lt;br /&gt;
                    result = &lt;br /&gt;
             ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } finally {&lt;br /&gt;
                    &lt;br /&gt;
                }&lt;br /&gt;
                if(result==delegate)&lt;br /&gt;
                        result = proxy;&lt;br /&gt;
                &lt;br /&gt;
                return result;&lt;br /&gt;
        }&lt;br /&gt;
        public static T newInstance(Object o,Class... interfaces) {&lt;br /&gt;
                return (T)java.lang.reflect.Proxy.newProxyInstance(&lt;br /&gt;
                    interfaces[0].getClassLoader(),&lt;br /&gt;
                    interfaces,&lt;br /&gt;
                    new Dynamic(o));&lt;br /&gt;
        }        &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Here, we define our Proxy class.  Note, both an Object and Method are passed in as parameters.  When attempting to invoke the method of the given Object, an exception is caught and delegated to a MethodMissing interface, which will also need to be defined.&lt;br /&gt;
&lt;br /&gt;
  public interface MethodMissing {&lt;br /&gt;
        public T methodMissing(Method method,E... args);        &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Now, we define an interface whose methods will need to be implemented in order to handle the missing objects.&lt;br /&gt;
&lt;br /&gt;
  public class Ruby implements MethodMissing{&lt;br /&gt;
        public Object methodMissing(Method method, Object... args) {&lt;br /&gt;
                System.out.println(method.getName());&lt;br /&gt;
                return this;&lt;br /&gt;
        }&lt;br /&gt;
        public static void main(String[] args){&lt;br /&gt;
                IDynamic dynamic = &lt;br /&gt;
                   Dynamic.newInstance(new Ruby(), IDynamic.class);               &lt;br /&gt;
                dynamic.meow().woof();&lt;br /&gt;
                dynamic.woof();&lt;br /&gt;
                &lt;br /&gt;
        }               &lt;br /&gt;
  }&lt;br /&gt;
  public interface IDynamic extends MethodMissing{&lt;br /&gt;
        public IDynamic woof();&lt;br /&gt;
        public IDynamic meow();&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Lastly, we create a class that attempts to utilize the MethodMissing construct.  As you can see, the Ruby class creates an implementation of the methodMissing() method, choosing to simply reflect the name of the method itself.  When the IDynamic class is created, it attempts to run several methods which are never actually defined.  Nevertheless, all of these method calls are actually intercepted by our proxy class and called as if there were no issue.&lt;br /&gt;
&lt;br /&gt;
The output of running this class would be:&lt;br /&gt;
&lt;br /&gt;
  meow&lt;br /&gt;
  woof&lt;br /&gt;
  woof&lt;br /&gt;
&lt;br /&gt;
Compared to Ruby, of course, or even Smalltalk, this is a very difficult way to handle missing methods.  Instead of having something built into the class itself, additional interfaces and wrappers are required to handle these scenarios, creating far more bulky and complex code.  Unfortunately, this is probably the price for having a statically typed language.&lt;br /&gt;
&lt;br /&gt;
===Python: __getattr__===&lt;br /&gt;
&lt;br /&gt;
In Python, much like Ruby, there is also a built-in class mechanism for handling non-existent methods.  Built into a class is __getattr__, which can be used to provide a default for all Python attributes that have not otherwise been defined.  In the following example: &amp;lt;ref&amp;gt;http://farmdev.com/src/secrets/magicmethod/index.html#introducing-getattr&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  class Test(object):&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        self.a = 'a'&lt;br /&gt;
        self.b = 'b'&lt;br /&gt;
    def __getattr__(self, name):&lt;br /&gt;
        return 123456&lt;br /&gt;
  t = Test()&lt;br /&gt;
  print 'object variables: %r' % t.__dict__.keys()&lt;br /&gt;
  print t.a&lt;br /&gt;
  print t.b&lt;br /&gt;
  print t.c&lt;br /&gt;
  print getattr(t, 'd')&lt;br /&gt;
  print hasattr(t, 'x')&lt;br /&gt;
&lt;br /&gt;
Expected output:&lt;br /&gt;
&lt;br /&gt;
  object variables: ['a', 'b']&lt;br /&gt;
  a&lt;br /&gt;
  b&lt;br /&gt;
  123456&lt;br /&gt;
  123456&lt;br /&gt;
  True&lt;br /&gt;
&lt;br /&gt;
In the above code, the Test class has variable definitions for 'a' and 'b', but no others.  When the print method tries to send in a 'c' or 'd' method call, __getattr__ catches this call and prints the generic '123456' value.  Even the hasattr method recognizes non-existent attributes as being valid without there even being an actual method call.&lt;br /&gt;
&lt;br /&gt;
If an attribute is found through a normal mechanism, this function is never actually called.  In fact, one difference with Ruby is that Python executes this method in a static fashion, only checking on one run if attributes have been defined somewhere for a relevant class.  This code may in fact not perform properly if classes are modified dynamically at runtime.&lt;br /&gt;
&lt;br /&gt;
===Perl: AUTOLOAD===&lt;br /&gt;
&lt;br /&gt;
Lastly, the Perl programming language provides the AUTOLOAD feature for handling this situation. Basically, if a class or any parent classes define an AUTOLOAD method, this method is called in the case where a direct method isn't found. &amp;lt;ref&amp;gt;http://perldoc.perl.org/perlobj.html#AUTOLOAD&amp;lt;/ref&amp;gt;  Anything that the AUTOLOAD method returns will be the last value returned to the caller (the caller never even needs to know the AUTOLOAD code exists).&lt;br /&gt;
&lt;br /&gt;
The following is a code snippet that can be used to auto-create methods on the fly in Perl using AUTOLOAD: &amp;lt;ref&amp;gt;http://www.perlmonks.org/?node_id=8227&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #!/usr/bin/perl -w&lt;br /&gt;
  package myClass;&lt;br /&gt;
  use strict;&lt;br /&gt;
  use vars qw{$AUTOLOAD $Debug};&lt;br /&gt;
  $Debug = 1;&lt;br /&gt;
  sub new {&lt;br /&gt;
    return bless {&lt;br /&gt;
      thing	=&amp;gt; 1,&lt;br /&gt;
      thang	=&amp;gt; 2,&lt;br /&gt;
      thong	=&amp;gt; 3,&lt;br /&gt;
    }, shift;&lt;br /&gt;
  }&lt;br /&gt;
  sub AUTOLOAD {&lt;br /&gt;
    my $self = shift or return undef;&lt;br /&gt;
      # Get the called method name and trim off the fully-qualified part&lt;br /&gt;
      ( my $method = $AUTOLOAD ) =~ s{.*::}{};&lt;br /&gt;
        # If the data member being accessed exists, build an accessor for it&lt;br /&gt;
        if ( exists $self-&amp;gt;{$method} ) {&lt;br /&gt;
          ### Create a closure that will become the new accessor method&lt;br /&gt;
            my $accessor = sub {&lt;br /&gt;
            my $closureSelf = shift;&lt;br /&gt;
            if ( @_ ) {&lt;br /&gt;
              return $closureSelf-&amp;gt;{$method} = shift;&lt;br /&gt;
            }&lt;br /&gt;
              return $closureSelf-&amp;gt;{$method}&lt;br /&gt;
            }&lt;br /&gt;
            # Assign the closure to the symbol table at the place where the real&lt;br /&gt;
            # method should be. We need to turn off strict refs, as we'll be mucking&lt;br /&gt;
            # with the symbol table.&lt;br /&gt;
            SYMBOL_TABLE_HACQUERY: {&lt;br /&gt;
              no strict qw{refs};&lt;br /&gt;
              *$AUTOLOAD = $accessor;&lt;br /&gt;
            }&lt;br /&gt;
            # Turn the call back into a method call by sticking the self-reference&lt;br /&gt;
            # back onto the arglist&lt;br /&gt;
            unshift @_, $self;&lt;br /&gt;
            # Jump to the newly-created method with magic goto&lt;br /&gt;
            goto &amp;amp;$AUTOLOAD;&lt;br /&gt;
        }&lt;br /&gt;
        ### Handle other autoloaded methods or errors&lt;br /&gt;
  }&lt;br /&gt;
  DESTROY {}&lt;br /&gt;
  ### Test program&lt;br /&gt;
  package main;&lt;br /&gt;
  my $a = new myClass;&lt;br /&gt;
  print $a-&amp;gt;thing, $a-&amp;gt;thang, $a-&amp;gt;thong, &amp;quot;\n&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73463</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1n jp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73463"/>
		<updated>2013-02-21T01:28:41Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: /* Perl: AUTOLOAD */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby's method_missing(): Advantages/Disadvantages and Alternatives =&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
One of the distinguishing features of the Ruby programming language is it's ability to easily extend classes in a dynamic fashion to perform a variety of different methods depending upon the needs of the current application.  For example, should the developer want to extend a core language class, take String for example, they could easily re-open that class and add new methods dynamically to this existing class, rather than creating an entirely new class.&lt;br /&gt;
&lt;br /&gt;
Even more powerful, Ruby allows for a construct called method_missing().  By overriding this method in your class, method_missing() will attempt to handle any method calls not currently defined by the given class (or class hierarchy).  Typically, some sort of regular expression is used to determine if the method call can be redirected to an existing method based on it's naming convention (for example, a method call in a non-existent singular form could be redirected to an existing pluralized form).  If the method_missing() definition cannot determine where to redirect the method call, the default is simply to call the parent class via super().&lt;br /&gt;
&lt;br /&gt;
By having the ability to allow a class to dynamically extend itself even if a method definition never truly existed, Ruby allows for a far greater degree of flexibility than does a statically typed language such as Java, where much greater effort is involved in handing method calls that do not currently exist.  With method_missing() defined, almost any sort of method call can be handled in the desired manner.&lt;br /&gt;
&lt;br /&gt;
This article will explore the method_missing() construct in greater detail, giving both advantages and disadvantages of having this feature in the Ruby language.  We will also examine how other programming languages attempt to handle the same problem.&lt;br /&gt;
&lt;br /&gt;
==Advantages of method_missing()==&lt;br /&gt;
1. Allows for dynamically invoked methods.&lt;br /&gt;
 &lt;br /&gt;
==Disadvantages of method_missing()==&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==Alternatives to method_missing() in other programming languages==&lt;br /&gt;
&lt;br /&gt;
===Smalltalk: doesNotUnderstand===&lt;br /&gt;
&lt;br /&gt;
In many ways the inspiration for Ruby, Smalltalk is often considered one of the original truly Object-Oriented languages.  Smalltalk, much like Ruby with method_missing(), sends a message called #doesNotUnderstand&amp;lt;ref&amp;gt;http://c2.com/cgi/wiki?DoesNotUnderstand&amp;lt;/ref&amp;gt; to handle methods that are unknown.&lt;br /&gt;
&lt;br /&gt;
Essentially, when an object receives a method that it doesn't recognize, the Smalltalk runtime engine is then responsible for turning this message into an object with all necessary parameters and returning it to the sender as an exception. The sender is, at that point, responsible for handling the message and somehow dealing with the exception.  Even though Smalltalk does consider this an exception, this construct is used quite frequently to form proxy objects and can handle a wide variety of different methods and arguments.&lt;br /&gt;
&lt;br /&gt;
Consider the following code: &amp;lt;ref&amp;gt;http://www.iam.unibe.ch/~akuhn/blog/category/smalltalk/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    OrderedCollection subclass: #Group.&lt;br /&gt;
    Group &amp;gt;&amp;gt; eachRespondsTo: aSelector&lt;br /&gt;
        self allSatisfy: [ :each | each respondsTo: aSelector ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; doesNotUnderstand: aMessage&lt;br /&gt;
        (self eachRespondsTo: aMessage selector)&lt;br /&gt;
          ifTrue: [ self collect: [ :each | aMessage sendTo: each ] ]&lt;br /&gt;
          ifFalse: [ super doesNotUnderstand: aMessage ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; respondsTo: aSelector&lt;br /&gt;
      ^ (super respondsTo: aSelector) or: [ self eachRespondsTo: aSelector ]&lt;br /&gt;
&lt;br /&gt;
In this code snippet, an OrderedCollection object is created.  Should this collection class not understand any of the methods being sent to it, the doesUnderstand code will attempt to handle the message itself.  Without overriding this method, the default is for Smalltalk to open a debugger to step through the exception (defining it overrides this behavior).&lt;br /&gt;
&lt;br /&gt;
===Java: DynamicProxy===&lt;br /&gt;
&lt;br /&gt;
In Java, the ability to handle undefined methods is a bit more cumbersome, but it can still be done successfully through the use of dynamic proxy classes.  By creating this dynamic proxy, all calls will essentially be intercepted prior to invocation.  An attempt will be made to invoke the object in question and, if unable to do so, an interface will need to be defined to handle the missing method scenarios.  To give an example&amp;lt;ref&amp;gt;http://www.jroller.com/ie/entry/methodmissing_in_java&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
  public class Dynamic implements java.lang.reflect.InvocationHandler  {&lt;br /&gt;
        Object delegate;&lt;br /&gt;
        public Dynamic(Object delegate){&lt;br /&gt;
                this.delegate=delegate;&lt;br /&gt;
        }        &lt;br /&gt;
        public Object invoke(Object proxy, Method method, Object[] args) &lt;br /&gt;
                           throws Throwable {&lt;br /&gt;
                Object result = null;&lt;br /&gt;
                try {                  &lt;br /&gt;
                    result = method.invoke(delegate, args);&lt;br /&gt;
                } catch (InvocationTargetException e) {&lt;br /&gt;
                        result = &lt;br /&gt;
                  ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } catch (Exception e) {&lt;br /&gt;
                    result = &lt;br /&gt;
             ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } finally {&lt;br /&gt;
                    &lt;br /&gt;
                }&lt;br /&gt;
                if(result==delegate)&lt;br /&gt;
                        result = proxy;&lt;br /&gt;
                &lt;br /&gt;
                return result;&lt;br /&gt;
        }&lt;br /&gt;
        public static T newInstance(Object o,Class... interfaces) {&lt;br /&gt;
                return (T)java.lang.reflect.Proxy.newProxyInstance(&lt;br /&gt;
                    interfaces[0].getClassLoader(),&lt;br /&gt;
                    interfaces,&lt;br /&gt;
                    new Dynamic(o));&lt;br /&gt;
        }        &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Here, we define our Proxy class.  Note, both an Object and Method are passed in as parameters.  When attempting to invoke the method of the given Object, an exception is caught and delegated to a MethodMissing interface, which will also need to be defined.&lt;br /&gt;
&lt;br /&gt;
  public interface MethodMissing {&lt;br /&gt;
        public T methodMissing(Method method,E... args);        &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Now, we define an interface whose methods will need to be implemented in order to handle the missing objects.&lt;br /&gt;
&lt;br /&gt;
  public class Ruby implements MethodMissing{&lt;br /&gt;
        public Object methodMissing(Method method, Object... args) {&lt;br /&gt;
                System.out.println(method.getName());&lt;br /&gt;
                return this;&lt;br /&gt;
        }&lt;br /&gt;
        public static void main(String[] args){&lt;br /&gt;
                IDynamic dynamic = &lt;br /&gt;
                   Dynamic.newInstance(new Ruby(), IDynamic.class);               &lt;br /&gt;
                dynamic.meow().woof();&lt;br /&gt;
                dynamic.woof();&lt;br /&gt;
                &lt;br /&gt;
        }               &lt;br /&gt;
  }&lt;br /&gt;
  public interface IDynamic extends MethodMissing{&lt;br /&gt;
        public IDynamic woof();&lt;br /&gt;
        public IDynamic meow();&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Lastly, we create a class that attempts to utilize the MethodMissing construct.  As you can see, the Ruby class creates an implementation of the methodMissing() method, choosing to simply reflect the name of the method itself.  When the IDynamic class is created, it attempts to run several methods which are never actually defined.  Nevertheless, all of these method calls are actually intercepted by our proxy class and called as if there were no issue.&lt;br /&gt;
&lt;br /&gt;
The output of running this class would be:&lt;br /&gt;
&lt;br /&gt;
  meow&lt;br /&gt;
  woof&lt;br /&gt;
  woof&lt;br /&gt;
&lt;br /&gt;
Compared to Ruby, of course, or even Smalltalk, this is a very difficult way to handle missing methods.  Instead of having something built into the class itself, additional interfaces and wrappers are required to handle these scenarios, creating far more bulky and complex code.  Unfortunately, this is probably the price for having a statically typed language.&lt;br /&gt;
&lt;br /&gt;
===Python: __getattr__===&lt;br /&gt;
&lt;br /&gt;
In Python, much like Ruby, there is also a built-in class mechanism for handling non-existent methods.  Built into a class is __getattr__, which can be used to provide a default for all Python attributes that have not otherwise been defined.  In the following example: &amp;lt;ref&amp;gt;http://farmdev.com/src/secrets/magicmethod/index.html#introducing-getattr&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  class Test(object):&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        self.a = 'a'&lt;br /&gt;
        self.b = 'b'&lt;br /&gt;
    def __getattr__(self, name):&lt;br /&gt;
        return 123456&lt;br /&gt;
  t = Test()&lt;br /&gt;
  print 'object variables: %r' % t.__dict__.keys()&lt;br /&gt;
  print t.a&lt;br /&gt;
  print t.b&lt;br /&gt;
  print t.c&lt;br /&gt;
  print getattr(t, 'd')&lt;br /&gt;
  print hasattr(t, 'x')&lt;br /&gt;
&lt;br /&gt;
Expected output:&lt;br /&gt;
&lt;br /&gt;
  object variables: ['a', 'b']&lt;br /&gt;
  a&lt;br /&gt;
  b&lt;br /&gt;
  123456&lt;br /&gt;
  123456&lt;br /&gt;
  True&lt;br /&gt;
&lt;br /&gt;
In the above code, the Test class has variable definitions for 'a' and 'b', but no others.  When the print method tries to send in a 'c' or 'd' method call, __getattr__ catches this call and prints the generic '123456' value.  Even the hasattr method recognizes non-existent attributes as being valid without there even being an actual method call.&lt;br /&gt;
&lt;br /&gt;
If an attribute is found through a normal mechanism, this function is never actually called.  In fact, one difference with Ruby is that Python executes this method in a static fashion, only checking on one run if attributes have been defined somewhere for a relevant class.  This code may in fact not perform properly if classes are modified dynamically at runtime.&lt;br /&gt;
&lt;br /&gt;
===Perl: AUTOLOAD===&lt;br /&gt;
&lt;br /&gt;
Lastly, the Perl programming language provides the AUTOLOAD feature for handling this situation. Basically, if a class or any parent classes define an AUTOLOAD method, this method is called in the case where a direct method isn't found. &amp;lt;ref&amp;gt;http://perldoc.perl.org/perlobj.html#AUTOLOAD&amp;lt;/ref&amp;gt;  Anything that the AUTOLOAD method returns will be the last value returned to the caller (the caller never even needs to know the AUTOLOAD code exists).&lt;br /&gt;
&lt;br /&gt;
The following is a code snippet that can be used to auto-create methods on the fly in Perl using AUTOLOAD: &amp;lt;ref&amp;gt;http://www.perlmonks.org/?node_id=8227&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #!/usr/bin/perl -w&lt;br /&gt;
  package myClass;&lt;br /&gt;
  use strict;&lt;br /&gt;
  use vars qw{$AUTOLOAD $Debug};&lt;br /&gt;
  $Debug = 1;&lt;br /&gt;
  sub new {&lt;br /&gt;
    return bless {&lt;br /&gt;
      thing	=&amp;gt; 1,&lt;br /&gt;
      thang	=&amp;gt; 2,&lt;br /&gt;
      thong	=&amp;gt; 3,&lt;br /&gt;
    }, shift;&lt;br /&gt;
  }&lt;br /&gt;
  sub AUTOLOAD {&lt;br /&gt;
    my $self = shift or return undef;&lt;br /&gt;
      # Get the called method name and trim off the fully-qualified part&lt;br /&gt;
      ( my $method = $AUTOLOAD ) =~ s{.*::}{};&lt;br /&gt;
        # If the data member being accessed exists, build an accessor for it&lt;br /&gt;
	if ( exists $self-&amp;gt;{$method} ) {&lt;br /&gt;
		### Create a closure that will become the new accessor method&lt;br /&gt;
		my $accessor = sub {&lt;br /&gt;
			my $closureSelf = shift;&lt;br /&gt;
			if ( @_ ) {&lt;br /&gt;
				return $closureSelf-&amp;gt;{$method} = shift;&lt;br /&gt;
			}&lt;br /&gt;
			return $closureSelf-&amp;gt;{$method};&lt;br /&gt;
		};&lt;br /&gt;
		# Assign the closure to the symbol table at the place where the real&lt;br /&gt;
		# method should be. We need to turn off strict refs, as we'll be mucking&lt;br /&gt;
	        # with the symbol table.&lt;br /&gt;
	  SYMBOL_TABLE_HACQUERY: {&lt;br /&gt;
			no strict qw{refs};&lt;br /&gt;
			*$AUTOLOAD = $accessor;&lt;br /&gt;
		}&lt;br /&gt;
		# Turn the call back into a method call by sticking the self-reference&lt;br /&gt;
		# back onto the arglist&lt;br /&gt;
		unshift @_, $self;&lt;br /&gt;
		# Jump to the newly-created method with magic goto&lt;br /&gt;
		goto &amp;amp;$AUTOLOAD;&lt;br /&gt;
	}&lt;br /&gt;
	### Handle other autoloaded methods or errors&lt;br /&gt;
  }&lt;br /&gt;
  DESTROY {}&lt;br /&gt;
  ### Test program&lt;br /&gt;
  package main;&lt;br /&gt;
  my $a = new myClass;&lt;br /&gt;
  print $a-&amp;gt;thing, $a-&amp;gt;thang, $a-&amp;gt;thong, &amp;quot;\n&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73462</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1n jp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73462"/>
		<updated>2013-02-21T01:27:13Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: /* Perl: AUTOLOAD */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby's method_missing(): Advantages/Disadvantages and Alternatives =&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
One of the distinguishing features of the Ruby programming language is it's ability to easily extend classes in a dynamic fashion to perform a variety of different methods depending upon the needs of the current application.  For example, should the developer want to extend a core language class, take String for example, they could easily re-open that class and add new methods dynamically to this existing class, rather than creating an entirely new class.&lt;br /&gt;
&lt;br /&gt;
Even more powerful, Ruby allows for a construct called method_missing().  By overriding this method in your class, method_missing() will attempt to handle any method calls not currently defined by the given class (or class hierarchy).  Typically, some sort of regular expression is used to determine if the method call can be redirected to an existing method based on it's naming convention (for example, a method call in a non-existent singular form could be redirected to an existing pluralized form).  If the method_missing() definition cannot determine where to redirect the method call, the default is simply to call the parent class via super().&lt;br /&gt;
&lt;br /&gt;
By having the ability to allow a class to dynamically extend itself even if a method definition never truly existed, Ruby allows for a far greater degree of flexibility than does a statically typed language such as Java, where much greater effort is involved in handing method calls that do not currently exist.  With method_missing() defined, almost any sort of method call can be handled in the desired manner.&lt;br /&gt;
&lt;br /&gt;
This article will explore the method_missing() construct in greater detail, giving both advantages and disadvantages of having this feature in the Ruby language.  We will also examine how other programming languages attempt to handle the same problem.&lt;br /&gt;
&lt;br /&gt;
==Advantages of method_missing()==&lt;br /&gt;
1. Allows for dynamically invoked methods.&lt;br /&gt;
 &lt;br /&gt;
==Disadvantages of method_missing()==&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==Alternatives to method_missing() in other programming languages==&lt;br /&gt;
&lt;br /&gt;
===Smalltalk: doesNotUnderstand===&lt;br /&gt;
&lt;br /&gt;
In many ways the inspiration for Ruby, Smalltalk is often considered one of the original truly Object-Oriented languages.  Smalltalk, much like Ruby with method_missing(), sends a message called #doesNotUnderstand&amp;lt;ref&amp;gt;http://c2.com/cgi/wiki?DoesNotUnderstand&amp;lt;/ref&amp;gt; to handle methods that are unknown.&lt;br /&gt;
&lt;br /&gt;
Essentially, when an object receives a method that it doesn't recognize, the Smalltalk runtime engine is then responsible for turning this message into an object with all necessary parameters and returning it to the sender as an exception. The sender is, at that point, responsible for handling the message and somehow dealing with the exception.  Even though Smalltalk does consider this an exception, this construct is used quite frequently to form proxy objects and can handle a wide variety of different methods and arguments.&lt;br /&gt;
&lt;br /&gt;
Consider the following code: &amp;lt;ref&amp;gt;http://www.iam.unibe.ch/~akuhn/blog/category/smalltalk/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    OrderedCollection subclass: #Group.&lt;br /&gt;
    Group &amp;gt;&amp;gt; eachRespondsTo: aSelector&lt;br /&gt;
        self allSatisfy: [ :each | each respondsTo: aSelector ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; doesNotUnderstand: aMessage&lt;br /&gt;
        (self eachRespondsTo: aMessage selector)&lt;br /&gt;
          ifTrue: [ self collect: [ :each | aMessage sendTo: each ] ]&lt;br /&gt;
          ifFalse: [ super doesNotUnderstand: aMessage ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; respondsTo: aSelector&lt;br /&gt;
      ^ (super respondsTo: aSelector) or: [ self eachRespondsTo: aSelector ]&lt;br /&gt;
&lt;br /&gt;
In this code snippet, an OrderedCollection object is created.  Should this collection class not understand any of the methods being sent to it, the doesUnderstand code will attempt to handle the message itself.  Without overriding this method, the default is for Smalltalk to open a debugger to step through the exception (defining it overrides this behavior).&lt;br /&gt;
&lt;br /&gt;
===Java: DynamicProxy===&lt;br /&gt;
&lt;br /&gt;
In Java, the ability to handle undefined methods is a bit more cumbersome, but it can still be done successfully through the use of dynamic proxy classes.  By creating this dynamic proxy, all calls will essentially be intercepted prior to invocation.  An attempt will be made to invoke the object in question and, if unable to do so, an interface will need to be defined to handle the missing method scenarios.  To give an example&amp;lt;ref&amp;gt;http://www.jroller.com/ie/entry/methodmissing_in_java&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
  public class Dynamic implements java.lang.reflect.InvocationHandler  {&lt;br /&gt;
        Object delegate;&lt;br /&gt;
        public Dynamic(Object delegate){&lt;br /&gt;
                this.delegate=delegate;&lt;br /&gt;
        }        &lt;br /&gt;
        public Object invoke(Object proxy, Method method, Object[] args) &lt;br /&gt;
                           throws Throwable {&lt;br /&gt;
                Object result = null;&lt;br /&gt;
                try {                  &lt;br /&gt;
                    result = method.invoke(delegate, args);&lt;br /&gt;
                } catch (InvocationTargetException e) {&lt;br /&gt;
                        result = &lt;br /&gt;
                  ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } catch (Exception e) {&lt;br /&gt;
                    result = &lt;br /&gt;
             ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } finally {&lt;br /&gt;
                    &lt;br /&gt;
                }&lt;br /&gt;
                if(result==delegate)&lt;br /&gt;
                        result = proxy;&lt;br /&gt;
                &lt;br /&gt;
                return result;&lt;br /&gt;
        }&lt;br /&gt;
        public static T newInstance(Object o,Class... interfaces) {&lt;br /&gt;
                return (T)java.lang.reflect.Proxy.newProxyInstance(&lt;br /&gt;
                    interfaces[0].getClassLoader(),&lt;br /&gt;
                    interfaces,&lt;br /&gt;
                    new Dynamic(o));&lt;br /&gt;
        }        &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Here, we define our Proxy class.  Note, both an Object and Method are passed in as parameters.  When attempting to invoke the method of the given Object, an exception is caught and delegated to a MethodMissing interface, which will also need to be defined.&lt;br /&gt;
&lt;br /&gt;
  public interface MethodMissing {&lt;br /&gt;
        public T methodMissing(Method method,E... args);        &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Now, we define an interface whose methods will need to be implemented in order to handle the missing objects.&lt;br /&gt;
&lt;br /&gt;
  public class Ruby implements MethodMissing{&lt;br /&gt;
        public Object methodMissing(Method method, Object... args) {&lt;br /&gt;
                System.out.println(method.getName());&lt;br /&gt;
                return this;&lt;br /&gt;
        }&lt;br /&gt;
        public static void main(String[] args){&lt;br /&gt;
                IDynamic dynamic = &lt;br /&gt;
                   Dynamic.newInstance(new Ruby(), IDynamic.class);               &lt;br /&gt;
                dynamic.meow().woof();&lt;br /&gt;
                dynamic.woof();&lt;br /&gt;
                &lt;br /&gt;
        }               &lt;br /&gt;
  }&lt;br /&gt;
  public interface IDynamic extends MethodMissing{&lt;br /&gt;
        public IDynamic woof();&lt;br /&gt;
        public IDynamic meow();&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Lastly, we create a class that attempts to utilize the MethodMissing construct.  As you can see, the Ruby class creates an implementation of the methodMissing() method, choosing to simply reflect the name of the method itself.  When the IDynamic class is created, it attempts to run several methods which are never actually defined.  Nevertheless, all of these method calls are actually intercepted by our proxy class and called as if there were no issue.&lt;br /&gt;
&lt;br /&gt;
The output of running this class would be:&lt;br /&gt;
&lt;br /&gt;
  meow&lt;br /&gt;
  woof&lt;br /&gt;
  woof&lt;br /&gt;
&lt;br /&gt;
Compared to Ruby, of course, or even Smalltalk, this is a very difficult way to handle missing methods.  Instead of having something built into the class itself, additional interfaces and wrappers are required to handle these scenarios, creating far more bulky and complex code.  Unfortunately, this is probably the price for having a statically typed language.&lt;br /&gt;
&lt;br /&gt;
===Python: __getattr__===&lt;br /&gt;
&lt;br /&gt;
In Python, much like Ruby, there is also a built-in class mechanism for handling non-existent methods.  Built into a class is __getattr__, which can be used to provide a default for all Python attributes that have not otherwise been defined.  In the following example: &amp;lt;ref&amp;gt;http://farmdev.com/src/secrets/magicmethod/index.html#introducing-getattr&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  class Test(object):&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        self.a = 'a'&lt;br /&gt;
        self.b = 'b'&lt;br /&gt;
    def __getattr__(self, name):&lt;br /&gt;
        return 123456&lt;br /&gt;
  t = Test()&lt;br /&gt;
  print 'object variables: %r' % t.__dict__.keys()&lt;br /&gt;
  print t.a&lt;br /&gt;
  print t.b&lt;br /&gt;
  print t.c&lt;br /&gt;
  print getattr(t, 'd')&lt;br /&gt;
  print hasattr(t, 'x')&lt;br /&gt;
&lt;br /&gt;
Expected output:&lt;br /&gt;
&lt;br /&gt;
  object variables: ['a', 'b']&lt;br /&gt;
  a&lt;br /&gt;
  b&lt;br /&gt;
  123456&lt;br /&gt;
  123456&lt;br /&gt;
  True&lt;br /&gt;
&lt;br /&gt;
In the above code, the Test class has variable definitions for 'a' and 'b', but no others.  When the print method tries to send in a 'c' or 'd' method call, __getattr__ catches this call and prints the generic '123456' value.  Even the hasattr method recognizes non-existent attributes as being valid without there even being an actual method call.&lt;br /&gt;
&lt;br /&gt;
If an attribute is found through a normal mechanism, this function is never actually called.  In fact, one difference with Ruby is that Python executes this method in a static fashion, only checking on one run if attributes have been defined somewhere for a relevant class.  This code may in fact not perform properly if classes are modified dynamically at runtime.&lt;br /&gt;
&lt;br /&gt;
===Perl: AUTOLOAD===&lt;br /&gt;
&lt;br /&gt;
Lastly, the Perl programming language provides the AUTOLOAD feature for handling this situation. Basically, if a class or any parent classes define an AUTOLOAD method, this method is called in the case where a direct method isn't found. &amp;lt;ref&amp;gt;http://perldoc.perl.org/perlobj.html#AUTOLOAD&amp;lt;/ref&amp;gt;  Anything that the AUTOLOAD method returns will be the last value returned to the caller (the caller never even needs to know the AUTOLOAD code exists).&lt;br /&gt;
&lt;br /&gt;
The following is a code snippet that can be used to auto-create methods on the fly in Perl using AUTOLOAD: &amp;lt;ref&amp;gt;http://www.perlmonks.org/?node_id=8227&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #!/usr/bin/perl -w&lt;br /&gt;
  package myClass;&lt;br /&gt;
  use strict;&lt;br /&gt;
  use vars qw{$AUTOLOAD $Debug};&lt;br /&gt;
  $Debug = 1;&lt;br /&gt;
  sub new {&lt;br /&gt;
	return bless {&lt;br /&gt;
                thing	=&amp;gt; 1,&lt;br /&gt;
		thang	=&amp;gt; 2,&lt;br /&gt;
		thong	=&amp;gt; 3,&lt;br /&gt;
	}, shift;&lt;br /&gt;
  }&lt;br /&gt;
  sub AUTOLOAD {&lt;br /&gt;
	my $self = shift or return undef;&lt;br /&gt;
	# Get the called method name and trim off the fully-qualified part&lt;br /&gt;
	( my $method = $AUTOLOAD ) =~ s{.*::}{};&lt;br /&gt;
	# If the data member being accessed exists, build an accessor for it&lt;br /&gt;
	if ( exists $self-&amp;gt;{$method} ) {&lt;br /&gt;
		### Create a closure that will become the new accessor method&lt;br /&gt;
		my $accessor = sub {&lt;br /&gt;
			my $closureSelf = shift;&lt;br /&gt;
			if ( @_ ) {&lt;br /&gt;
				return $closureSelf-&amp;gt;{$method} = shift;&lt;br /&gt;
			}&lt;br /&gt;
			return $closureSelf-&amp;gt;{$method};&lt;br /&gt;
		};&lt;br /&gt;
		# Assign the closure to the symbol table at the place where the real&lt;br /&gt;
		# method should be. We need to turn off strict refs, as we'll be mucking&lt;br /&gt;
	        # with the symbol table.&lt;br /&gt;
	  SYMBOL_TABLE_HACQUERY: {&lt;br /&gt;
			no strict qw{refs};&lt;br /&gt;
			*$AUTOLOAD = $accessor;&lt;br /&gt;
		}&lt;br /&gt;
		# Turn the call back into a method call by sticking the self-reference&lt;br /&gt;
		# back onto the arglist&lt;br /&gt;
		unshift @_, $self;&lt;br /&gt;
		# Jump to the newly-created method with magic goto&lt;br /&gt;
		goto &amp;amp;$AUTOLOAD;&lt;br /&gt;
	}&lt;br /&gt;
	### Handle other autoloaded methods or errors&lt;br /&gt;
  }&lt;br /&gt;
  DESTROY {}&lt;br /&gt;
  ### Test program&lt;br /&gt;
  package main;&lt;br /&gt;
  my $a = new myClass;&lt;br /&gt;
  print $a-&amp;gt;thing, $a-&amp;gt;thang, $a-&amp;gt;thong, &amp;quot;\n&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73460</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1n jp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73460"/>
		<updated>2013-02-21T01:26:32Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: /* Perl: AUTOLOAD */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby's method_missing(): Advantages/Disadvantages and Alternatives =&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
One of the distinguishing features of the Ruby programming language is it's ability to easily extend classes in a dynamic fashion to perform a variety of different methods depending upon the needs of the current application.  For example, should the developer want to extend a core language class, take String for example, they could easily re-open that class and add new methods dynamically to this existing class, rather than creating an entirely new class.&lt;br /&gt;
&lt;br /&gt;
Even more powerful, Ruby allows for a construct called method_missing().  By overriding this method in your class, method_missing() will attempt to handle any method calls not currently defined by the given class (or class hierarchy).  Typically, some sort of regular expression is used to determine if the method call can be redirected to an existing method based on it's naming convention (for example, a method call in a non-existent singular form could be redirected to an existing pluralized form).  If the method_missing() definition cannot determine where to redirect the method call, the default is simply to call the parent class via super().&lt;br /&gt;
&lt;br /&gt;
By having the ability to allow a class to dynamically extend itself even if a method definition never truly existed, Ruby allows for a far greater degree of flexibility than does a statically typed language such as Java, where much greater effort is involved in handing method calls that do not currently exist.  With method_missing() defined, almost any sort of method call can be handled in the desired manner.&lt;br /&gt;
&lt;br /&gt;
This article will explore the method_missing() construct in greater detail, giving both advantages and disadvantages of having this feature in the Ruby language.  We will also examine how other programming languages attempt to handle the same problem.&lt;br /&gt;
&lt;br /&gt;
==Advantages of method_missing()==&lt;br /&gt;
1. Allows for dynamically invoked methods.&lt;br /&gt;
 &lt;br /&gt;
==Disadvantages of method_missing()==&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==Alternatives to method_missing() in other programming languages==&lt;br /&gt;
&lt;br /&gt;
===Smalltalk: doesNotUnderstand===&lt;br /&gt;
&lt;br /&gt;
In many ways the inspiration for Ruby, Smalltalk is often considered one of the original truly Object-Oriented languages.  Smalltalk, much like Ruby with method_missing(), sends a message called #doesNotUnderstand&amp;lt;ref&amp;gt;http://c2.com/cgi/wiki?DoesNotUnderstand&amp;lt;/ref&amp;gt; to handle methods that are unknown.&lt;br /&gt;
&lt;br /&gt;
Essentially, when an object receives a method that it doesn't recognize, the Smalltalk runtime engine is then responsible for turning this message into an object with all necessary parameters and returning it to the sender as an exception. The sender is, at that point, responsible for handling the message and somehow dealing with the exception.  Even though Smalltalk does consider this an exception, this construct is used quite frequently to form proxy objects and can handle a wide variety of different methods and arguments.&lt;br /&gt;
&lt;br /&gt;
Consider the following code: &amp;lt;ref&amp;gt;http://www.iam.unibe.ch/~akuhn/blog/category/smalltalk/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    OrderedCollection subclass: #Group.&lt;br /&gt;
    Group &amp;gt;&amp;gt; eachRespondsTo: aSelector&lt;br /&gt;
        self allSatisfy: [ :each | each respondsTo: aSelector ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; doesNotUnderstand: aMessage&lt;br /&gt;
        (self eachRespondsTo: aMessage selector)&lt;br /&gt;
          ifTrue: [ self collect: [ :each | aMessage sendTo: each ] ]&lt;br /&gt;
          ifFalse: [ super doesNotUnderstand: aMessage ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; respondsTo: aSelector&lt;br /&gt;
      ^ (super respondsTo: aSelector) or: [ self eachRespondsTo: aSelector ]&lt;br /&gt;
&lt;br /&gt;
In this code snippet, an OrderedCollection object is created.  Should this collection class not understand any of the methods being sent to it, the doesUnderstand code will attempt to handle the message itself.  Without overriding this method, the default is for Smalltalk to open a debugger to step through the exception (defining it overrides this behavior).&lt;br /&gt;
&lt;br /&gt;
===Java: DynamicProxy===&lt;br /&gt;
&lt;br /&gt;
In Java, the ability to handle undefined methods is a bit more cumbersome, but it can still be done successfully through the use of dynamic proxy classes.  By creating this dynamic proxy, all calls will essentially be intercepted prior to invocation.  An attempt will be made to invoke the object in question and, if unable to do so, an interface will need to be defined to handle the missing method scenarios.  To give an example&amp;lt;ref&amp;gt;http://www.jroller.com/ie/entry/methodmissing_in_java&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
  public class Dynamic implements java.lang.reflect.InvocationHandler  {&lt;br /&gt;
        Object delegate;&lt;br /&gt;
        public Dynamic(Object delegate){&lt;br /&gt;
                this.delegate=delegate;&lt;br /&gt;
        }        &lt;br /&gt;
        public Object invoke(Object proxy, Method method, Object[] args) &lt;br /&gt;
                           throws Throwable {&lt;br /&gt;
                Object result = null;&lt;br /&gt;
                try {                  &lt;br /&gt;
                    result = method.invoke(delegate, args);&lt;br /&gt;
                } catch (InvocationTargetException e) {&lt;br /&gt;
                        result = &lt;br /&gt;
                  ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } catch (Exception e) {&lt;br /&gt;
                    result = &lt;br /&gt;
             ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } finally {&lt;br /&gt;
                    &lt;br /&gt;
                }&lt;br /&gt;
                if(result==delegate)&lt;br /&gt;
                        result = proxy;&lt;br /&gt;
                &lt;br /&gt;
                return result;&lt;br /&gt;
        }&lt;br /&gt;
        public static T newInstance(Object o,Class... interfaces) {&lt;br /&gt;
                return (T)java.lang.reflect.Proxy.newProxyInstance(&lt;br /&gt;
                    interfaces[0].getClassLoader(),&lt;br /&gt;
                    interfaces,&lt;br /&gt;
                    new Dynamic(o));&lt;br /&gt;
        }        &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Here, we define our Proxy class.  Note, both an Object and Method are passed in as parameters.  When attempting to invoke the method of the given Object, an exception is caught and delegated to a MethodMissing interface, which will also need to be defined.&lt;br /&gt;
&lt;br /&gt;
  public interface MethodMissing {&lt;br /&gt;
        public T methodMissing(Method method,E... args);        &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Now, we define an interface whose methods will need to be implemented in order to handle the missing objects.&lt;br /&gt;
&lt;br /&gt;
  public class Ruby implements MethodMissing{&lt;br /&gt;
        public Object methodMissing(Method method, Object... args) {&lt;br /&gt;
                System.out.println(method.getName());&lt;br /&gt;
                return this;&lt;br /&gt;
        }&lt;br /&gt;
        public static void main(String[] args){&lt;br /&gt;
                IDynamic dynamic = &lt;br /&gt;
                   Dynamic.newInstance(new Ruby(), IDynamic.class);               &lt;br /&gt;
                dynamic.meow().woof();&lt;br /&gt;
                dynamic.woof();&lt;br /&gt;
                &lt;br /&gt;
        }               &lt;br /&gt;
  }&lt;br /&gt;
  public interface IDynamic extends MethodMissing{&lt;br /&gt;
        public IDynamic woof();&lt;br /&gt;
        public IDynamic meow();&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Lastly, we create a class that attempts to utilize the MethodMissing construct.  As you can see, the Ruby class creates an implementation of the methodMissing() method, choosing to simply reflect the name of the method itself.  When the IDynamic class is created, it attempts to run several methods which are never actually defined.  Nevertheless, all of these method calls are actually intercepted by our proxy class and called as if there were no issue.&lt;br /&gt;
&lt;br /&gt;
The output of running this class would be:&lt;br /&gt;
&lt;br /&gt;
  meow&lt;br /&gt;
  woof&lt;br /&gt;
  woof&lt;br /&gt;
&lt;br /&gt;
Compared to Ruby, of course, or even Smalltalk, this is a very difficult way to handle missing methods.  Instead of having something built into the class itself, additional interfaces and wrappers are required to handle these scenarios, creating far more bulky and complex code.  Unfortunately, this is probably the price for having a statically typed language.&lt;br /&gt;
&lt;br /&gt;
===Python: __getattr__===&lt;br /&gt;
&lt;br /&gt;
In Python, much like Ruby, there is also a built-in class mechanism for handling non-existent methods.  Built into a class is __getattr__, which can be used to provide a default for all Python attributes that have not otherwise been defined.  In the following example: &amp;lt;ref&amp;gt;http://farmdev.com/src/secrets/magicmethod/index.html#introducing-getattr&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  class Test(object):&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        self.a = 'a'&lt;br /&gt;
        self.b = 'b'&lt;br /&gt;
    def __getattr__(self, name):&lt;br /&gt;
        return 123456&lt;br /&gt;
  t = Test()&lt;br /&gt;
  print 'object variables: %r' % t.__dict__.keys()&lt;br /&gt;
  print t.a&lt;br /&gt;
  print t.b&lt;br /&gt;
  print t.c&lt;br /&gt;
  print getattr(t, 'd')&lt;br /&gt;
  print hasattr(t, 'x')&lt;br /&gt;
&lt;br /&gt;
Expected output:&lt;br /&gt;
&lt;br /&gt;
  object variables: ['a', 'b']&lt;br /&gt;
  a&lt;br /&gt;
  b&lt;br /&gt;
  123456&lt;br /&gt;
  123456&lt;br /&gt;
  True&lt;br /&gt;
&lt;br /&gt;
In the above code, the Test class has variable definitions for 'a' and 'b', but no others.  When the print method tries to send in a 'c' or 'd' method call, __getattr__ catches this call and prints the generic '123456' value.  Even the hasattr method recognizes non-existent attributes as being valid without there even being an actual method call.&lt;br /&gt;
&lt;br /&gt;
If an attribute is found through a normal mechanism, this function is never actually called.  In fact, one difference with Ruby is that Python executes this method in a static fashion, only checking on one run if attributes have been defined somewhere for a relevant class.  This code may in fact not perform properly if classes are modified dynamically at runtime.&lt;br /&gt;
&lt;br /&gt;
===Perl: AUTOLOAD===&lt;br /&gt;
&lt;br /&gt;
Lastly, the Perl programming language provides the AUTOLOAD feature for handling this situation. Basically, if a class or any parent classes define an AUTOLOAD method, this method is called in the case where a direct method isn't found. &amp;lt;ref&amp;gt;http://perldoc.perl.org/perlobj.html#AUTOLOAD&amp;lt;/ref&amp;gt;  Anything that the AUTOLOAD method returns will be the last value returned to the caller (the caller never even needs to know the AUTOLOAD code exists).&lt;br /&gt;
&lt;br /&gt;
The following is a code snippet that can be used to auto-create methods on the fly in Perl using AUTOLOAD: &amp;lt;ref&amp;gt;http://www.perlmonks.org/?node_id=8227&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #!/usr/bin/perl -w&lt;br /&gt;
  package myClass;&lt;br /&gt;
  use strict;&lt;br /&gt;
  use vars qw{$AUTOLOAD $Debug};&lt;br /&gt;
  $Debug = 1;&lt;br /&gt;
  sub new {&lt;br /&gt;
	return bless {&lt;br /&gt;
		thing	=&amp;gt; 1,&lt;br /&gt;
		thang	=&amp;gt; 2,&lt;br /&gt;
		thong	=&amp;gt; 3,&lt;br /&gt;
	}, shift;&lt;br /&gt;
  }&lt;br /&gt;
  sub AUTOLOAD {&lt;br /&gt;
	my $self = shift or return undef;&lt;br /&gt;
	# Get the called method name and trim off the fully-qualified part&lt;br /&gt;
	( my $method = $AUTOLOAD ) =~ s{.*::}{};&lt;br /&gt;
	# If the data member being accessed exists, build an accessor for it&lt;br /&gt;
	if ( exists $self-&amp;gt;{$method} ) {&lt;br /&gt;
		### Create a closure that will become the new accessor method&lt;br /&gt;
		my $accessor = sub {&lt;br /&gt;
			my $closureSelf = shift;&lt;br /&gt;
			if ( @_ ) {&lt;br /&gt;
				return $closureSelf-&amp;gt;{$method} = shift;&lt;br /&gt;
			}&lt;br /&gt;
			return $closureSelf-&amp;gt;{$method};&lt;br /&gt;
		};&lt;br /&gt;
		# Assign the closure to the symbol table at the place where the real&lt;br /&gt;
		# method should be. We need to turn off strict refs, as we'll be mucking&lt;br /&gt;
	        # with the symbol table.&lt;br /&gt;
	  SYMBOL_TABLE_HACQUERY: {&lt;br /&gt;
			no strict qw{refs};&lt;br /&gt;
			*$AUTOLOAD = $accessor;&lt;br /&gt;
		}&lt;br /&gt;
		# Turn the call back into a method call by sticking the self-reference&lt;br /&gt;
		# back onto the arglist&lt;br /&gt;
		unshift @_, $self;&lt;br /&gt;
		# Jump to the newly-created method with magic goto&lt;br /&gt;
		goto &amp;amp;$AUTOLOAD;&lt;br /&gt;
	}&lt;br /&gt;
	### Handle other autoloaded methods or errors&lt;br /&gt;
  }&lt;br /&gt;
  DESTROY {}&lt;br /&gt;
  ### Test program&lt;br /&gt;
  package main;&lt;br /&gt;
  my $a = new myClass;&lt;br /&gt;
  print $a-&amp;gt;thing, $a-&amp;gt;thang, $a-&amp;gt;thong, &amp;quot;\n&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73458</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1n jp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73458"/>
		<updated>2013-02-21T01:25:27Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: /* Perl: AUTOLOAD */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby's method_missing(): Advantages/Disadvantages and Alternatives =&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
One of the distinguishing features of the Ruby programming language is it's ability to easily extend classes in a dynamic fashion to perform a variety of different methods depending upon the needs of the current application.  For example, should the developer want to extend a core language class, take String for example, they could easily re-open that class and add new methods dynamically to this existing class, rather than creating an entirely new class.&lt;br /&gt;
&lt;br /&gt;
Even more powerful, Ruby allows for a construct called method_missing().  By overriding this method in your class, method_missing() will attempt to handle any method calls not currently defined by the given class (or class hierarchy).  Typically, some sort of regular expression is used to determine if the method call can be redirected to an existing method based on it's naming convention (for example, a method call in a non-existent singular form could be redirected to an existing pluralized form).  If the method_missing() definition cannot determine where to redirect the method call, the default is simply to call the parent class via super().&lt;br /&gt;
&lt;br /&gt;
By having the ability to allow a class to dynamically extend itself even if a method definition never truly existed, Ruby allows for a far greater degree of flexibility than does a statically typed language such as Java, where much greater effort is involved in handing method calls that do not currently exist.  With method_missing() defined, almost any sort of method call can be handled in the desired manner.&lt;br /&gt;
&lt;br /&gt;
This article will explore the method_missing() construct in greater detail, giving both advantages and disadvantages of having this feature in the Ruby language.  We will also examine how other programming languages attempt to handle the same problem.&lt;br /&gt;
&lt;br /&gt;
==Advantages of method_missing()==&lt;br /&gt;
1. Allows for dynamically invoked methods.&lt;br /&gt;
 &lt;br /&gt;
==Disadvantages of method_missing()==&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==Alternatives to method_missing() in other programming languages==&lt;br /&gt;
&lt;br /&gt;
===Smalltalk: doesNotUnderstand===&lt;br /&gt;
&lt;br /&gt;
In many ways the inspiration for Ruby, Smalltalk is often considered one of the original truly Object-Oriented languages.  Smalltalk, much like Ruby with method_missing(), sends a message called #doesNotUnderstand&amp;lt;ref&amp;gt;http://c2.com/cgi/wiki?DoesNotUnderstand&amp;lt;/ref&amp;gt; to handle methods that are unknown.&lt;br /&gt;
&lt;br /&gt;
Essentially, when an object receives a method that it doesn't recognize, the Smalltalk runtime engine is then responsible for turning this message into an object with all necessary parameters and returning it to the sender as an exception. The sender is, at that point, responsible for handling the message and somehow dealing with the exception.  Even though Smalltalk does consider this an exception, this construct is used quite frequently to form proxy objects and can handle a wide variety of different methods and arguments.&lt;br /&gt;
&lt;br /&gt;
Consider the following code: &amp;lt;ref&amp;gt;http://www.iam.unibe.ch/~akuhn/blog/category/smalltalk/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    OrderedCollection subclass: #Group.&lt;br /&gt;
    Group &amp;gt;&amp;gt; eachRespondsTo: aSelector&lt;br /&gt;
        self allSatisfy: [ :each | each respondsTo: aSelector ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; doesNotUnderstand: aMessage&lt;br /&gt;
        (self eachRespondsTo: aMessage selector)&lt;br /&gt;
          ifTrue: [ self collect: [ :each | aMessage sendTo: each ] ]&lt;br /&gt;
          ifFalse: [ super doesNotUnderstand: aMessage ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; respondsTo: aSelector&lt;br /&gt;
      ^ (super respondsTo: aSelector) or: [ self eachRespondsTo: aSelector ]&lt;br /&gt;
&lt;br /&gt;
In this code snippet, an OrderedCollection object is created.  Should this collection class not understand any of the methods being sent to it, the doesUnderstand code will attempt to handle the message itself.  Without overriding this method, the default is for Smalltalk to open a debugger to step through the exception (defining it overrides this behavior).&lt;br /&gt;
&lt;br /&gt;
===Java: DynamicProxy===&lt;br /&gt;
&lt;br /&gt;
In Java, the ability to handle undefined methods is a bit more cumbersome, but it can still be done successfully through the use of dynamic proxy classes.  By creating this dynamic proxy, all calls will essentially be intercepted prior to invocation.  An attempt will be made to invoke the object in question and, if unable to do so, an interface will need to be defined to handle the missing method scenarios.  To give an example&amp;lt;ref&amp;gt;http://www.jroller.com/ie/entry/methodmissing_in_java&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
  public class Dynamic implements java.lang.reflect.InvocationHandler  {&lt;br /&gt;
        Object delegate;&lt;br /&gt;
        public Dynamic(Object delegate){&lt;br /&gt;
                this.delegate=delegate;&lt;br /&gt;
        }        &lt;br /&gt;
        public Object invoke(Object proxy, Method method, Object[] args) &lt;br /&gt;
                           throws Throwable {&lt;br /&gt;
                Object result = null;&lt;br /&gt;
                try {                  &lt;br /&gt;
                    result = method.invoke(delegate, args);&lt;br /&gt;
                } catch (InvocationTargetException e) {&lt;br /&gt;
                        result = &lt;br /&gt;
                  ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } catch (Exception e) {&lt;br /&gt;
                    result = &lt;br /&gt;
             ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } finally {&lt;br /&gt;
                    &lt;br /&gt;
                }&lt;br /&gt;
                if(result==delegate)&lt;br /&gt;
                        result = proxy;&lt;br /&gt;
                &lt;br /&gt;
                return result;&lt;br /&gt;
        }&lt;br /&gt;
        public static T newInstance(Object o,Class... interfaces) {&lt;br /&gt;
                return (T)java.lang.reflect.Proxy.newProxyInstance(&lt;br /&gt;
                    interfaces[0].getClassLoader(),&lt;br /&gt;
                    interfaces,&lt;br /&gt;
                    new Dynamic(o));&lt;br /&gt;
        }        &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Here, we define our Proxy class.  Note, both an Object and Method are passed in as parameters.  When attempting to invoke the method of the given Object, an exception is caught and delegated to a MethodMissing interface, which will also need to be defined.&lt;br /&gt;
&lt;br /&gt;
  public interface MethodMissing {&lt;br /&gt;
        public T methodMissing(Method method,E... args);        &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Now, we define an interface whose methods will need to be implemented in order to handle the missing objects.&lt;br /&gt;
&lt;br /&gt;
  public class Ruby implements MethodMissing{&lt;br /&gt;
        public Object methodMissing(Method method, Object... args) {&lt;br /&gt;
                System.out.println(method.getName());&lt;br /&gt;
                return this;&lt;br /&gt;
        }&lt;br /&gt;
        public static void main(String[] args){&lt;br /&gt;
                IDynamic dynamic = &lt;br /&gt;
                   Dynamic.newInstance(new Ruby(), IDynamic.class);               &lt;br /&gt;
                dynamic.meow().woof();&lt;br /&gt;
                dynamic.woof();&lt;br /&gt;
                &lt;br /&gt;
        }               &lt;br /&gt;
  }&lt;br /&gt;
  public interface IDynamic extends MethodMissing{&lt;br /&gt;
        public IDynamic woof();&lt;br /&gt;
        public IDynamic meow();&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Lastly, we create a class that attempts to utilize the MethodMissing construct.  As you can see, the Ruby class creates an implementation of the methodMissing() method, choosing to simply reflect the name of the method itself.  When the IDynamic class is created, it attempts to run several methods which are never actually defined.  Nevertheless, all of these method calls are actually intercepted by our proxy class and called as if there were no issue.&lt;br /&gt;
&lt;br /&gt;
The output of running this class would be:&lt;br /&gt;
&lt;br /&gt;
  meow&lt;br /&gt;
  woof&lt;br /&gt;
  woof&lt;br /&gt;
&lt;br /&gt;
Compared to Ruby, of course, or even Smalltalk, this is a very difficult way to handle missing methods.  Instead of having something built into the class itself, additional interfaces and wrappers are required to handle these scenarios, creating far more bulky and complex code.  Unfortunately, this is probably the price for having a statically typed language.&lt;br /&gt;
&lt;br /&gt;
===Python: __getattr__===&lt;br /&gt;
&lt;br /&gt;
In Python, much like Ruby, there is also a built-in class mechanism for handling non-existent methods.  Built into a class is __getattr__, which can be used to provide a default for all Python attributes that have not otherwise been defined.  In the following example: &amp;lt;ref&amp;gt;http://farmdev.com/src/secrets/magicmethod/index.html#introducing-getattr&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  class Test(object):&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        self.a = 'a'&lt;br /&gt;
        self.b = 'b'&lt;br /&gt;
    def __getattr__(self, name):&lt;br /&gt;
        return 123456&lt;br /&gt;
  t = Test()&lt;br /&gt;
  print 'object variables: %r' % t.__dict__.keys()&lt;br /&gt;
  print t.a&lt;br /&gt;
  print t.b&lt;br /&gt;
  print t.c&lt;br /&gt;
  print getattr(t, 'd')&lt;br /&gt;
  print hasattr(t, 'x')&lt;br /&gt;
&lt;br /&gt;
Expected output:&lt;br /&gt;
&lt;br /&gt;
  object variables: ['a', 'b']&lt;br /&gt;
  a&lt;br /&gt;
  b&lt;br /&gt;
  123456&lt;br /&gt;
  123456&lt;br /&gt;
  True&lt;br /&gt;
&lt;br /&gt;
In the above code, the Test class has variable definitions for 'a' and 'b', but no others.  When the print method tries to send in a 'c' or 'd' method call, __getattr__ catches this call and prints the generic '123456' value.  Even the hasattr method recognizes non-existent attributes as being valid without there even being an actual method call.&lt;br /&gt;
&lt;br /&gt;
If an attribute is found through a normal mechanism, this function is never actually called.  In fact, one difference with Ruby is that Python executes this method in a static fashion, only checking on one run if attributes have been defined somewhere for a relevant class.  This code may in fact not perform properly if classes are modified dynamically at runtime.&lt;br /&gt;
&lt;br /&gt;
===Perl: AUTOLOAD===&lt;br /&gt;
&lt;br /&gt;
Lastly, the Perl programming language provides the AUTOLOAD feature for handling this situation. Basically, if a class or any parent classes define an AUTOLOAD method, this method is called in the case where a direct method isn't found. &amp;lt;ref&amp;gt;http://perldoc.perl.org/perlobj.html#AUTOLOAD&amp;lt;/ref&amp;gt;  Anything that the AUTOLOAD method returns will be the last value returned to the caller (the caller never even needs to know the AUTOLOAD code exists).&lt;br /&gt;
&lt;br /&gt;
The following is a code snippet that can be used to auto-create methods on the fly in Perl using AUTOLOAD: &amp;lt;ref&amp;gt;http://www.perlmonks.org/?node_id=8227&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #!/usr/bin/perl -w&lt;br /&gt;
  package myClass;&lt;br /&gt;
  use strict;&lt;br /&gt;
  use vars qw{$AUTOLOAD $Debug};&lt;br /&gt;
&lt;br /&gt;
  $Debug = 1;&lt;br /&gt;
&lt;br /&gt;
  sub new {&lt;br /&gt;
	return bless {&lt;br /&gt;
		thing	=&amp;gt; 1,&lt;br /&gt;
		thang	=&amp;gt; 2,&lt;br /&gt;
		thong	=&amp;gt; 3,&lt;br /&gt;
	}, shift;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  sub AUTOLOAD {&lt;br /&gt;
	my $self = shift or return undef;&lt;br /&gt;
&lt;br /&gt;
	# Get the called method name and trim off the fully-qualified part&lt;br /&gt;
	( my $method = $AUTOLOAD ) =~ s{.*::}{};&lt;br /&gt;
&lt;br /&gt;
	# If the data member being accessed exists, build an accessor for it&lt;br /&gt;
	if ( exists $self-&amp;gt;{$method} ) {&lt;br /&gt;
&lt;br /&gt;
		### Create a closure that will become the new accessor method&lt;br /&gt;
		my $accessor = sub {&lt;br /&gt;
			my $closureSelf = shift;&lt;br /&gt;
&lt;br /&gt;
			if ( @_ ) {&lt;br /&gt;
				return $closureSelf-&amp;gt;{$method} = shift;&lt;br /&gt;
			}&lt;br /&gt;
&lt;br /&gt;
			return $closureSelf-&amp;gt;{$method};&lt;br /&gt;
		};&lt;br /&gt;
&lt;br /&gt;
		# Assign the closure to the symbol table at the place where the real&lt;br /&gt;
		# method should be. We need to turn off strict refs, as we'll be mucking&lt;br /&gt;
	        # with the symbol table.&lt;br /&gt;
	  SYMBOL_TABLE_HACQUERY: {&lt;br /&gt;
			no strict qw{refs};&lt;br /&gt;
			*$AUTOLOAD = $accessor;&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		# Turn the call back into a method call by sticking the self-reference&lt;br /&gt;
		# back onto the arglist&lt;br /&gt;
		unshift @_, $self;&lt;br /&gt;
&lt;br /&gt;
		# Jump to the newly-created method with magic goto&lt;br /&gt;
		goto &amp;amp;$AUTOLOAD;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	### Handle other autoloaded methods or errors&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  DESTROY {}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  ### Test program&lt;br /&gt;
  package main;&lt;br /&gt;
&lt;br /&gt;
  my $a = new myClass;&lt;br /&gt;
&lt;br /&gt;
  print $a-&amp;gt;thing, $a-&amp;gt;thang, $a-&amp;gt;thong, &amp;quot;\n&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73442</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1n jp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73442"/>
		<updated>2013-02-21T00:58:50Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: /* Perl: AUTOLOAD */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby's method_missing(): Advantages/Disadvantages and Alternatives =&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
One of the distinguishing features of the Ruby programming language is it's ability to easily extend classes in a dynamic fashion to perform a variety of different methods depending upon the needs of the current application.  For example, should the developer want to extend a core language class, take String for example, they could easily re-open that class and add new methods dynamically to this existing class, rather than creating an entirely new class.&lt;br /&gt;
&lt;br /&gt;
Even more powerful, Ruby allows for a construct called method_missing().  By overriding this method in your class, method_missing() will attempt to handle any method calls not currently defined by the given class (or class hierarchy).  Typically, some sort of regular expression is used to determine if the method call can be redirected to an existing method based on it's naming convention (for example, a method call in a non-existent singular form could be redirected to an existing pluralized form).  If the method_missing() definition cannot determine where to redirect the method call, the default is simply to call the parent class via super().&lt;br /&gt;
&lt;br /&gt;
By having the ability to allow a class to dynamically extend itself even if a method definition never truly existed, Ruby allows for a far greater degree of flexibility than does a statically typed language such as Java, where much greater effort is involved in handing method calls that do not currently exist.  With method_missing() defined, almost any sort of method call can be handled in the desired manner.&lt;br /&gt;
&lt;br /&gt;
This article will explore the method_missing() construct in greater detail, giving both advantages and disadvantages of having this feature in the Ruby language.  We will also examine how other programming languages attempt to handle the same problem.&lt;br /&gt;
&lt;br /&gt;
==Advantages of method_missing()==&lt;br /&gt;
1. Allows for dynamically invoked methods.&lt;br /&gt;
 &lt;br /&gt;
==Disadvantages of method_missing()==&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==Alternatives to method_missing() in other programming languages==&lt;br /&gt;
&lt;br /&gt;
===Smalltalk: doesNotUnderstand===&lt;br /&gt;
&lt;br /&gt;
In many ways the inspiration for Ruby, Smalltalk is often considered one of the original truly Object-Oriented languages.  Smalltalk, much like Ruby with method_missing(), sends a message called #doesNotUnderstand&amp;lt;ref&amp;gt;http://c2.com/cgi/wiki?DoesNotUnderstand&amp;lt;/ref&amp;gt; to handle methods that are unknown.&lt;br /&gt;
&lt;br /&gt;
Essentially, when an object receives a method that it doesn't recognize, the Smalltalk runtime engine is then responsible for turning this message into an object with all necessary parameters and returning it to the sender as an exception. The sender is, at that point, responsible for handling the message and somehow dealing with the exception.  Even though Smalltalk does consider this an exception, this construct is used quite frequently to form proxy objects and can handle a wide variety of different methods and arguments.&lt;br /&gt;
&lt;br /&gt;
Consider the following code: &amp;lt;ref&amp;gt;http://www.iam.unibe.ch/~akuhn/blog/category/smalltalk/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    OrderedCollection subclass: #Group.&lt;br /&gt;
    Group &amp;gt;&amp;gt; eachRespondsTo: aSelector&lt;br /&gt;
        self allSatisfy: [ :each | each respondsTo: aSelector ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; doesNotUnderstand: aMessage&lt;br /&gt;
        (self eachRespondsTo: aMessage selector)&lt;br /&gt;
          ifTrue: [ self collect: [ :each | aMessage sendTo: each ] ]&lt;br /&gt;
          ifFalse: [ super doesNotUnderstand: aMessage ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; respondsTo: aSelector&lt;br /&gt;
      ^ (super respondsTo: aSelector) or: [ self eachRespondsTo: aSelector ]&lt;br /&gt;
&lt;br /&gt;
In this code snippet, an OrderedCollection object is created.  Should this collection class not understand any of the methods being sent to it, the doesUnderstand code will attempt to handle the message itself.  Without overriding this method, the default is for Smalltalk to open a debugger to step through the exception (defining it overrides this behavior).&lt;br /&gt;
&lt;br /&gt;
===Java: DynamicProxy===&lt;br /&gt;
&lt;br /&gt;
In Java, the ability to handle undefined methods is a bit more cumbersome, but it can still be done successfully through the use of dynamic proxy classes.  By creating this dynamic proxy, all calls will essentially be intercepted prior to invocation.  An attempt will be made to invoke the object in question and, if unable to do so, an interface will need to be defined to handle the missing method scenarios.  To give an example&amp;lt;ref&amp;gt;http://www.jroller.com/ie/entry/methodmissing_in_java&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
  public class Dynamic implements java.lang.reflect.InvocationHandler  {&lt;br /&gt;
        Object delegate;&lt;br /&gt;
        public Dynamic(Object delegate){&lt;br /&gt;
                this.delegate=delegate;&lt;br /&gt;
        }        &lt;br /&gt;
        public Object invoke(Object proxy, Method method, Object[] args) &lt;br /&gt;
                           throws Throwable {&lt;br /&gt;
                Object result = null;&lt;br /&gt;
                try {                  &lt;br /&gt;
                    result = method.invoke(delegate, args);&lt;br /&gt;
                } catch (InvocationTargetException e) {&lt;br /&gt;
                        result = &lt;br /&gt;
                  ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } catch (Exception e) {&lt;br /&gt;
                    result = &lt;br /&gt;
             ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } finally {&lt;br /&gt;
                    &lt;br /&gt;
                }&lt;br /&gt;
                if(result==delegate)&lt;br /&gt;
                        result = proxy;&lt;br /&gt;
                &lt;br /&gt;
                return result;&lt;br /&gt;
        }&lt;br /&gt;
        public static T newInstance(Object o,Class... interfaces) {&lt;br /&gt;
                return (T)java.lang.reflect.Proxy.newProxyInstance(&lt;br /&gt;
                    interfaces[0].getClassLoader(),&lt;br /&gt;
                    interfaces,&lt;br /&gt;
                    new Dynamic(o));&lt;br /&gt;
        }        &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Here, we define our Proxy class.  Note, both an Object and Method are passed in as parameters.  When attempting to invoke the method of the given Object, an exception is caught and delegated to a MethodMissing interface, which will also need to be defined.&lt;br /&gt;
&lt;br /&gt;
  public interface MethodMissing {&lt;br /&gt;
        public T methodMissing(Method method,E... args);        &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Now, we define an interface whose methods will need to be implemented in order to handle the missing objects.&lt;br /&gt;
&lt;br /&gt;
  public class Ruby implements MethodMissing{&lt;br /&gt;
        public Object methodMissing(Method method, Object... args) {&lt;br /&gt;
                System.out.println(method.getName());&lt;br /&gt;
                return this;&lt;br /&gt;
        }&lt;br /&gt;
        public static void main(String[] args){&lt;br /&gt;
                IDynamic dynamic = &lt;br /&gt;
                   Dynamic.newInstance(new Ruby(), IDynamic.class);               &lt;br /&gt;
                dynamic.meow().woof();&lt;br /&gt;
                dynamic.woof();&lt;br /&gt;
                &lt;br /&gt;
        }               &lt;br /&gt;
  }&lt;br /&gt;
  public interface IDynamic extends MethodMissing{&lt;br /&gt;
        public IDynamic woof();&lt;br /&gt;
        public IDynamic meow();&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Lastly, we create a class that attempts to utilize the MethodMissing construct.  As you can see, the Ruby class creates an implementation of the methodMissing() method, choosing to simply reflect the name of the method itself.  When the IDynamic class is created, it attempts to run several methods which are never actually defined.  Nevertheless, all of these method calls are actually intercepted by our proxy class and called as if there were no issue.&lt;br /&gt;
&lt;br /&gt;
The output of running this class would be:&lt;br /&gt;
&lt;br /&gt;
  meow&lt;br /&gt;
  woof&lt;br /&gt;
  woof&lt;br /&gt;
&lt;br /&gt;
Compared to Ruby, of course, or even Smalltalk, this is a very difficult way to handle missing methods.  Instead of having something built into the class itself, additional interfaces and wrappers are required to handle these scenarios, creating far more bulky and complex code.  Unfortunately, this is probably the price for having a statically typed language.&lt;br /&gt;
&lt;br /&gt;
===Python: __getattr__===&lt;br /&gt;
&lt;br /&gt;
In Python, much like Ruby, there is also a built-in class mechanism for handling non-existent methods.  Built into a class is __getattr__, which can be used to provide a default for all Python attributes that have not otherwise been defined.  In the following example: &amp;lt;ref&amp;gt;http://farmdev.com/src/secrets/magicmethod/index.html#introducing-getattr&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  class Test(object):&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        self.a = 'a'&lt;br /&gt;
        self.b = 'b'&lt;br /&gt;
    def __getattr__(self, name):&lt;br /&gt;
        return 123456&lt;br /&gt;
  t = Test()&lt;br /&gt;
  print 'object variables: %r' % t.__dict__.keys()&lt;br /&gt;
  print t.a&lt;br /&gt;
  print t.b&lt;br /&gt;
  print t.c&lt;br /&gt;
  print getattr(t, 'd')&lt;br /&gt;
  print hasattr(t, 'x')&lt;br /&gt;
&lt;br /&gt;
Expected output:&lt;br /&gt;
&lt;br /&gt;
  object variables: ['a', 'b']&lt;br /&gt;
  a&lt;br /&gt;
  b&lt;br /&gt;
  123456&lt;br /&gt;
  123456&lt;br /&gt;
  True&lt;br /&gt;
&lt;br /&gt;
In the above code, the Test class has variable definitions for 'a' and 'b', but no others.  When the print method tries to send in a 'c' or 'd' method call, __getattr__ catches this call and prints the generic '123456' value.  Even the hasattr method recognizes non-existent attributes as being valid without there even being an actual method call.&lt;br /&gt;
&lt;br /&gt;
If an attribute is found through a normal mechanism, this function is never actually called.  In fact, one difference with Ruby is that Python executes this method in a static fashion, only checking on one run if attributes have been defined somewhere for a relevant class.  This code may in fact not perform properly if classes are modified dynamically at runtime.&lt;br /&gt;
&lt;br /&gt;
===Perl: AUTOLOAD===&lt;br /&gt;
&lt;br /&gt;
Lastly, the Perl programming language provides the AUTOLOAD feature for handling this situation. Basically, if a class or any parent classes define an AUTOLOAD method, this method is called in the case where a direct method isn't found. &amp;lt;ref&amp;gt;http://perldoc.perl.org/perlobj.html#AUTOLOAD&amp;lt;/ref&amp;gt;  Anything that the AUTOLOAD method returns will be the last value returned to the caller (the caller never even needs to know the AUTOLOAD code exists).&lt;br /&gt;
&lt;br /&gt;
The following is a code snippet that can be used to auto-create methods on the fly in Perl using AUTOLOAD: &amp;lt;ref&amp;gt;http://www.perlmonks.org/?node_id=8227&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  sub AUTOLOAD{&lt;br /&gt;
    my ($self,$value)= @_ ;&lt;br /&gt;
    return if $AUTOLOAD =~ /::DESTROY$/ ;&lt;br /&gt;
    my $attname = $AUTOLOAD;&lt;br /&gt;
    $attname =~ s/.*::// ;&lt;br /&gt;
    if(! exists $self-&amp;gt;{$attname}){&lt;br /&gt;
      Carp::confess(&amp;quot;Attribute $attname does not exists in $self&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    my $pkg = ref($self ) ;&lt;br /&gt;
    my $code = qq{&lt;br /&gt;
               package $pkg ;&lt;br /&gt;
               sub $attname {&lt;br /&gt;
                       my \$self = shift ;&lt;br /&gt;
                       \@_ ? \$self-&amp;gt;{$attname} = shift :&lt;br /&gt;
                       \$self-&amp;gt;{$attname} ;&lt;br /&gt;
               }&lt;br /&gt;
       };&lt;br /&gt;
    eval $code ;&lt;br /&gt;
    if( $@ ){&lt;br /&gt;
      Carp::confess(&amp;quot;Failed to create method $AUTOLOAD : $@&amp;quot;);&lt;br /&gt;
     }&lt;br /&gt;
    goto &amp;amp;$AUTOLOAD ;         &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73440</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1n jp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73440"/>
		<updated>2013-02-21T00:58:06Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: /* Perl: AUTOLOAD */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby's method_missing(): Advantages/Disadvantages and Alternatives =&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
One of the distinguishing features of the Ruby programming language is it's ability to easily extend classes in a dynamic fashion to perform a variety of different methods depending upon the needs of the current application.  For example, should the developer want to extend a core language class, take String for example, they could easily re-open that class and add new methods dynamically to this existing class, rather than creating an entirely new class.&lt;br /&gt;
&lt;br /&gt;
Even more powerful, Ruby allows for a construct called method_missing().  By overriding this method in your class, method_missing() will attempt to handle any method calls not currently defined by the given class (or class hierarchy).  Typically, some sort of regular expression is used to determine if the method call can be redirected to an existing method based on it's naming convention (for example, a method call in a non-existent singular form could be redirected to an existing pluralized form).  If the method_missing() definition cannot determine where to redirect the method call, the default is simply to call the parent class via super().&lt;br /&gt;
&lt;br /&gt;
By having the ability to allow a class to dynamically extend itself even if a method definition never truly existed, Ruby allows for a far greater degree of flexibility than does a statically typed language such as Java, where much greater effort is involved in handing method calls that do not currently exist.  With method_missing() defined, almost any sort of method call can be handled in the desired manner.&lt;br /&gt;
&lt;br /&gt;
This article will explore the method_missing() construct in greater detail, giving both advantages and disadvantages of having this feature in the Ruby language.  We will also examine how other programming languages attempt to handle the same problem.&lt;br /&gt;
&lt;br /&gt;
==Advantages of method_missing()==&lt;br /&gt;
1. Allows for dynamically invoked methods.&lt;br /&gt;
 &lt;br /&gt;
==Disadvantages of method_missing()==&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==Alternatives to method_missing() in other programming languages==&lt;br /&gt;
&lt;br /&gt;
===Smalltalk: doesNotUnderstand===&lt;br /&gt;
&lt;br /&gt;
In many ways the inspiration for Ruby, Smalltalk is often considered one of the original truly Object-Oriented languages.  Smalltalk, much like Ruby with method_missing(), sends a message called #doesNotUnderstand&amp;lt;ref&amp;gt;http://c2.com/cgi/wiki?DoesNotUnderstand&amp;lt;/ref&amp;gt; to handle methods that are unknown.&lt;br /&gt;
&lt;br /&gt;
Essentially, when an object receives a method that it doesn't recognize, the Smalltalk runtime engine is then responsible for turning this message into an object with all necessary parameters and returning it to the sender as an exception. The sender is, at that point, responsible for handling the message and somehow dealing with the exception.  Even though Smalltalk does consider this an exception, this construct is used quite frequently to form proxy objects and can handle a wide variety of different methods and arguments.&lt;br /&gt;
&lt;br /&gt;
Consider the following code: &amp;lt;ref&amp;gt;http://www.iam.unibe.ch/~akuhn/blog/category/smalltalk/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    OrderedCollection subclass: #Group.&lt;br /&gt;
    Group &amp;gt;&amp;gt; eachRespondsTo: aSelector&lt;br /&gt;
        self allSatisfy: [ :each | each respondsTo: aSelector ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; doesNotUnderstand: aMessage&lt;br /&gt;
        (self eachRespondsTo: aMessage selector)&lt;br /&gt;
          ifTrue: [ self collect: [ :each | aMessage sendTo: each ] ]&lt;br /&gt;
          ifFalse: [ super doesNotUnderstand: aMessage ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; respondsTo: aSelector&lt;br /&gt;
      ^ (super respondsTo: aSelector) or: [ self eachRespondsTo: aSelector ]&lt;br /&gt;
&lt;br /&gt;
In this code snippet, an OrderedCollection object is created.  Should this collection class not understand any of the methods being sent to it, the doesUnderstand code will attempt to handle the message itself.  Without overriding this method, the default is for Smalltalk to open a debugger to step through the exception (defining it overrides this behavior).&lt;br /&gt;
&lt;br /&gt;
===Java: DynamicProxy===&lt;br /&gt;
&lt;br /&gt;
In Java, the ability to handle undefined methods is a bit more cumbersome, but it can still be done successfully through the use of dynamic proxy classes.  By creating this dynamic proxy, all calls will essentially be intercepted prior to invocation.  An attempt will be made to invoke the object in question and, if unable to do so, an interface will need to be defined to handle the missing method scenarios.  To give an example&amp;lt;ref&amp;gt;http://www.jroller.com/ie/entry/methodmissing_in_java&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
  public class Dynamic implements java.lang.reflect.InvocationHandler  {&lt;br /&gt;
        Object delegate;&lt;br /&gt;
        public Dynamic(Object delegate){&lt;br /&gt;
                this.delegate=delegate;&lt;br /&gt;
        }        &lt;br /&gt;
        public Object invoke(Object proxy, Method method, Object[] args) &lt;br /&gt;
                           throws Throwable {&lt;br /&gt;
                Object result = null;&lt;br /&gt;
                try {                  &lt;br /&gt;
                    result = method.invoke(delegate, args);&lt;br /&gt;
                } catch (InvocationTargetException e) {&lt;br /&gt;
                        result = &lt;br /&gt;
                  ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } catch (Exception e) {&lt;br /&gt;
                    result = &lt;br /&gt;
             ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } finally {&lt;br /&gt;
                    &lt;br /&gt;
                }&lt;br /&gt;
                if(result==delegate)&lt;br /&gt;
                        result = proxy;&lt;br /&gt;
                &lt;br /&gt;
                return result;&lt;br /&gt;
        }&lt;br /&gt;
        public static T newInstance(Object o,Class... interfaces) {&lt;br /&gt;
                return (T)java.lang.reflect.Proxy.newProxyInstance(&lt;br /&gt;
                    interfaces[0].getClassLoader(),&lt;br /&gt;
                    interfaces,&lt;br /&gt;
                    new Dynamic(o));&lt;br /&gt;
        }        &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Here, we define our Proxy class.  Note, both an Object and Method are passed in as parameters.  When attempting to invoke the method of the given Object, an exception is caught and delegated to a MethodMissing interface, which will also need to be defined.&lt;br /&gt;
&lt;br /&gt;
  public interface MethodMissing {&lt;br /&gt;
        public T methodMissing(Method method,E... args);        &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Now, we define an interface whose methods will need to be implemented in order to handle the missing objects.&lt;br /&gt;
&lt;br /&gt;
  public class Ruby implements MethodMissing{&lt;br /&gt;
        public Object methodMissing(Method method, Object... args) {&lt;br /&gt;
                System.out.println(method.getName());&lt;br /&gt;
                return this;&lt;br /&gt;
        }&lt;br /&gt;
        public static void main(String[] args){&lt;br /&gt;
                IDynamic dynamic = &lt;br /&gt;
                   Dynamic.newInstance(new Ruby(), IDynamic.class);               &lt;br /&gt;
                dynamic.meow().woof();&lt;br /&gt;
                dynamic.woof();&lt;br /&gt;
                &lt;br /&gt;
        }               &lt;br /&gt;
  }&lt;br /&gt;
  public interface IDynamic extends MethodMissing{&lt;br /&gt;
        public IDynamic woof();&lt;br /&gt;
        public IDynamic meow();&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Lastly, we create a class that attempts to utilize the MethodMissing construct.  As you can see, the Ruby class creates an implementation of the methodMissing() method, choosing to simply reflect the name of the method itself.  When the IDynamic class is created, it attempts to run several methods which are never actually defined.  Nevertheless, all of these method calls are actually intercepted by our proxy class and called as if there were no issue.&lt;br /&gt;
&lt;br /&gt;
The output of running this class would be:&lt;br /&gt;
&lt;br /&gt;
  meow&lt;br /&gt;
  woof&lt;br /&gt;
  woof&lt;br /&gt;
&lt;br /&gt;
Compared to Ruby, of course, or even Smalltalk, this is a very difficult way to handle missing methods.  Instead of having something built into the class itself, additional interfaces and wrappers are required to handle these scenarios, creating far more bulky and complex code.  Unfortunately, this is probably the price for having a statically typed language.&lt;br /&gt;
&lt;br /&gt;
===Python: __getattr__===&lt;br /&gt;
&lt;br /&gt;
In Python, much like Ruby, there is also a built-in class mechanism for handling non-existent methods.  Built into a class is __getattr__, which can be used to provide a default for all Python attributes that have not otherwise been defined.  In the following example: &amp;lt;ref&amp;gt;http://farmdev.com/src/secrets/magicmethod/index.html#introducing-getattr&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  class Test(object):&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        self.a = 'a'&lt;br /&gt;
        self.b = 'b'&lt;br /&gt;
    def __getattr__(self, name):&lt;br /&gt;
        return 123456&lt;br /&gt;
  t = Test()&lt;br /&gt;
  print 'object variables: %r' % t.__dict__.keys()&lt;br /&gt;
  print t.a&lt;br /&gt;
  print t.b&lt;br /&gt;
  print t.c&lt;br /&gt;
  print getattr(t, 'd')&lt;br /&gt;
  print hasattr(t, 'x')&lt;br /&gt;
&lt;br /&gt;
Expected output:&lt;br /&gt;
&lt;br /&gt;
  object variables: ['a', 'b']&lt;br /&gt;
  a&lt;br /&gt;
  b&lt;br /&gt;
  123456&lt;br /&gt;
  123456&lt;br /&gt;
  True&lt;br /&gt;
&lt;br /&gt;
In the above code, the Test class has variable definitions for 'a' and 'b', but no others.  When the print method tries to send in a 'c' or 'd' method call, __getattr__ catches this call and prints the generic '123456' value.  Even the hasattr method recognizes non-existent attributes as being valid without there even being an actual method call.&lt;br /&gt;
&lt;br /&gt;
If an attribute is found through a normal mechanism, this function is never actually called.  In fact, one difference with Ruby is that Python executes this method in a static fashion, only checking on one run if attributes have been defined somewhere for a relevant class.  This code may in fact not perform properly if classes are modified dynamically at runtime.&lt;br /&gt;
&lt;br /&gt;
===Perl: AUTOLOAD===&lt;br /&gt;
&lt;br /&gt;
Lastly, the Perl programming language provides the AUTOLOAD feature for handling this situation. Basically, if a class or any parent classes define an AUTOLOAD method, this method is called in the case where a direct method isn't found. &amp;lt;ref&amp;gt;http://perldoc.perl.org/perlobj.html#AUTOLOAD&amp;lt;/ref&amp;gt;  Anything that the AUTOLOAD method returns will be the last value returned to the caller (the caller never even needs to know the AUTOLOAD code exists).&lt;br /&gt;
&lt;br /&gt;
The following is a code snippet that can be used to auto-create methods on the fly in Perl using AUTOLOAD:&lt;br /&gt;
&lt;br /&gt;
  sub AUTOLOAD{&lt;br /&gt;
    my ($self,$value)= @_ ;&lt;br /&gt;
    return if $AUTOLOAD =~ /::DESTROY$/ ;&lt;br /&gt;
    my $attname = $AUTOLOAD;&lt;br /&gt;
    $attname =~ s/.*::// ;&lt;br /&gt;
    if(! exists $self-&amp;gt;{$attname}){&lt;br /&gt;
      Carp::confess(&amp;quot;Attribute $attname does not exists in $self&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    my $pkg = ref($self ) ;&lt;br /&gt;
    my $code = qq{&lt;br /&gt;
               package $pkg ;&lt;br /&gt;
               sub $attname {&lt;br /&gt;
                       my \$self = shift ;&lt;br /&gt;
                       \@_ ? \$self-&amp;gt;{$attname} = shift :&lt;br /&gt;
                       \$self-&amp;gt;{$attname} ;&lt;br /&gt;
               }&lt;br /&gt;
       };&lt;br /&gt;
    eval $code ;&lt;br /&gt;
    if( $@ ){&lt;br /&gt;
      Carp::confess(&amp;quot;Failed to create method $AUTOLOAD : $@&amp;quot;);&lt;br /&gt;
     }&lt;br /&gt;
    goto &amp;amp;$AUTOLOAD ;         &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73439</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1n jp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73439"/>
		<updated>2013-02-21T00:57:22Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: /* Perl: AUTOLOAD */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby's method_missing(): Advantages/Disadvantages and Alternatives =&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
One of the distinguishing features of the Ruby programming language is it's ability to easily extend classes in a dynamic fashion to perform a variety of different methods depending upon the needs of the current application.  For example, should the developer want to extend a core language class, take String for example, they could easily re-open that class and add new methods dynamically to this existing class, rather than creating an entirely new class.&lt;br /&gt;
&lt;br /&gt;
Even more powerful, Ruby allows for a construct called method_missing().  By overriding this method in your class, method_missing() will attempt to handle any method calls not currently defined by the given class (or class hierarchy).  Typically, some sort of regular expression is used to determine if the method call can be redirected to an existing method based on it's naming convention (for example, a method call in a non-existent singular form could be redirected to an existing pluralized form).  If the method_missing() definition cannot determine where to redirect the method call, the default is simply to call the parent class via super().&lt;br /&gt;
&lt;br /&gt;
By having the ability to allow a class to dynamically extend itself even if a method definition never truly existed, Ruby allows for a far greater degree of flexibility than does a statically typed language such as Java, where much greater effort is involved in handing method calls that do not currently exist.  With method_missing() defined, almost any sort of method call can be handled in the desired manner.&lt;br /&gt;
&lt;br /&gt;
This article will explore the method_missing() construct in greater detail, giving both advantages and disadvantages of having this feature in the Ruby language.  We will also examine how other programming languages attempt to handle the same problem.&lt;br /&gt;
&lt;br /&gt;
==Advantages of method_missing()==&lt;br /&gt;
1. Allows for dynamically invoked methods.&lt;br /&gt;
 &lt;br /&gt;
==Disadvantages of method_missing()==&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==Alternatives to method_missing() in other programming languages==&lt;br /&gt;
&lt;br /&gt;
===Smalltalk: doesNotUnderstand===&lt;br /&gt;
&lt;br /&gt;
In many ways the inspiration for Ruby, Smalltalk is often considered one of the original truly Object-Oriented languages.  Smalltalk, much like Ruby with method_missing(), sends a message called #doesNotUnderstand&amp;lt;ref&amp;gt;http://c2.com/cgi/wiki?DoesNotUnderstand&amp;lt;/ref&amp;gt; to handle methods that are unknown.&lt;br /&gt;
&lt;br /&gt;
Essentially, when an object receives a method that it doesn't recognize, the Smalltalk runtime engine is then responsible for turning this message into an object with all necessary parameters and returning it to the sender as an exception. The sender is, at that point, responsible for handling the message and somehow dealing with the exception.  Even though Smalltalk does consider this an exception, this construct is used quite frequently to form proxy objects and can handle a wide variety of different methods and arguments.&lt;br /&gt;
&lt;br /&gt;
Consider the following code: &amp;lt;ref&amp;gt;http://www.iam.unibe.ch/~akuhn/blog/category/smalltalk/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    OrderedCollection subclass: #Group.&lt;br /&gt;
    Group &amp;gt;&amp;gt; eachRespondsTo: aSelector&lt;br /&gt;
        self allSatisfy: [ :each | each respondsTo: aSelector ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; doesNotUnderstand: aMessage&lt;br /&gt;
        (self eachRespondsTo: aMessage selector)&lt;br /&gt;
          ifTrue: [ self collect: [ :each | aMessage sendTo: each ] ]&lt;br /&gt;
          ifFalse: [ super doesNotUnderstand: aMessage ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; respondsTo: aSelector&lt;br /&gt;
      ^ (super respondsTo: aSelector) or: [ self eachRespondsTo: aSelector ]&lt;br /&gt;
&lt;br /&gt;
In this code snippet, an OrderedCollection object is created.  Should this collection class not understand any of the methods being sent to it, the doesUnderstand code will attempt to handle the message itself.  Without overriding this method, the default is for Smalltalk to open a debugger to step through the exception (defining it overrides this behavior).&lt;br /&gt;
&lt;br /&gt;
===Java: DynamicProxy===&lt;br /&gt;
&lt;br /&gt;
In Java, the ability to handle undefined methods is a bit more cumbersome, but it can still be done successfully through the use of dynamic proxy classes.  By creating this dynamic proxy, all calls will essentially be intercepted prior to invocation.  An attempt will be made to invoke the object in question and, if unable to do so, an interface will need to be defined to handle the missing method scenarios.  To give an example&amp;lt;ref&amp;gt;http://www.jroller.com/ie/entry/methodmissing_in_java&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
  public class Dynamic implements java.lang.reflect.InvocationHandler  {&lt;br /&gt;
        Object delegate;&lt;br /&gt;
        public Dynamic(Object delegate){&lt;br /&gt;
                this.delegate=delegate;&lt;br /&gt;
        }        &lt;br /&gt;
        public Object invoke(Object proxy, Method method, Object[] args) &lt;br /&gt;
                           throws Throwable {&lt;br /&gt;
                Object result = null;&lt;br /&gt;
                try {                  &lt;br /&gt;
                    result = method.invoke(delegate, args);&lt;br /&gt;
                } catch (InvocationTargetException e) {&lt;br /&gt;
                        result = &lt;br /&gt;
                  ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } catch (Exception e) {&lt;br /&gt;
                    result = &lt;br /&gt;
             ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } finally {&lt;br /&gt;
                    &lt;br /&gt;
                }&lt;br /&gt;
                if(result==delegate)&lt;br /&gt;
                        result = proxy;&lt;br /&gt;
                &lt;br /&gt;
                return result;&lt;br /&gt;
        }&lt;br /&gt;
        public static T newInstance(Object o,Class... interfaces) {&lt;br /&gt;
                return (T)java.lang.reflect.Proxy.newProxyInstance(&lt;br /&gt;
                    interfaces[0].getClassLoader(),&lt;br /&gt;
                    interfaces,&lt;br /&gt;
                    new Dynamic(o));&lt;br /&gt;
        }        &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Here, we define our Proxy class.  Note, both an Object and Method are passed in as parameters.  When attempting to invoke the method of the given Object, an exception is caught and delegated to a MethodMissing interface, which will also need to be defined.&lt;br /&gt;
&lt;br /&gt;
  public interface MethodMissing {&lt;br /&gt;
        public T methodMissing(Method method,E... args);        &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Now, we define an interface whose methods will need to be implemented in order to handle the missing objects.&lt;br /&gt;
&lt;br /&gt;
  public class Ruby implements MethodMissing{&lt;br /&gt;
        public Object methodMissing(Method method, Object... args) {&lt;br /&gt;
                System.out.println(method.getName());&lt;br /&gt;
                return this;&lt;br /&gt;
        }&lt;br /&gt;
        public static void main(String[] args){&lt;br /&gt;
                IDynamic dynamic = &lt;br /&gt;
                   Dynamic.newInstance(new Ruby(), IDynamic.class);               &lt;br /&gt;
                dynamic.meow().woof();&lt;br /&gt;
                dynamic.woof();&lt;br /&gt;
                &lt;br /&gt;
        }               &lt;br /&gt;
  }&lt;br /&gt;
  public interface IDynamic extends MethodMissing{&lt;br /&gt;
        public IDynamic woof();&lt;br /&gt;
        public IDynamic meow();&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Lastly, we create a class that attempts to utilize the MethodMissing construct.  As you can see, the Ruby class creates an implementation of the methodMissing() method, choosing to simply reflect the name of the method itself.  When the IDynamic class is created, it attempts to run several methods which are never actually defined.  Nevertheless, all of these method calls are actually intercepted by our proxy class and called as if there were no issue.&lt;br /&gt;
&lt;br /&gt;
The output of running this class would be:&lt;br /&gt;
&lt;br /&gt;
  meow&lt;br /&gt;
  woof&lt;br /&gt;
  woof&lt;br /&gt;
&lt;br /&gt;
Compared to Ruby, of course, or even Smalltalk, this is a very difficult way to handle missing methods.  Instead of having something built into the class itself, additional interfaces and wrappers are required to handle these scenarios, creating far more bulky and complex code.  Unfortunately, this is probably the price for having a statically typed language.&lt;br /&gt;
&lt;br /&gt;
===Python: __getattr__===&lt;br /&gt;
&lt;br /&gt;
In Python, much like Ruby, there is also a built-in class mechanism for handling non-existent methods.  Built into a class is __getattr__, which can be used to provide a default for all Python attributes that have not otherwise been defined.  In the following example: &amp;lt;ref&amp;gt;http://farmdev.com/src/secrets/magicmethod/index.html#introducing-getattr&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  class Test(object):&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        self.a = 'a'&lt;br /&gt;
        self.b = 'b'&lt;br /&gt;
    def __getattr__(self, name):&lt;br /&gt;
        return 123456&lt;br /&gt;
  t = Test()&lt;br /&gt;
  print 'object variables: %r' % t.__dict__.keys()&lt;br /&gt;
  print t.a&lt;br /&gt;
  print t.b&lt;br /&gt;
  print t.c&lt;br /&gt;
  print getattr(t, 'd')&lt;br /&gt;
  print hasattr(t, 'x')&lt;br /&gt;
&lt;br /&gt;
Expected output:&lt;br /&gt;
&lt;br /&gt;
  object variables: ['a', 'b']&lt;br /&gt;
  a&lt;br /&gt;
  b&lt;br /&gt;
  123456&lt;br /&gt;
  123456&lt;br /&gt;
  True&lt;br /&gt;
&lt;br /&gt;
In the above code, the Test class has variable definitions for 'a' and 'b', but no others.  When the print method tries to send in a 'c' or 'd' method call, __getattr__ catches this call and prints the generic '123456' value.  Even the hasattr method recognizes non-existent attributes as being valid without there even being an actual method call.&lt;br /&gt;
&lt;br /&gt;
If an attribute is found through a normal mechanism, this function is never actually called.  In fact, one difference with Ruby is that Python executes this method in a static fashion, only checking on one run if attributes have been defined somewhere for a relevant class.  This code may in fact not perform properly if classes are modified dynamically at runtime.&lt;br /&gt;
&lt;br /&gt;
===Perl: AUTOLOAD===&lt;br /&gt;
&lt;br /&gt;
Lastly, the Perl programming language provides the AUTOLOAD feature for handling this situation. Basically, if a class or any parent classes define an AUTOLOAD method, this method is called in the case where a direct method isn't found. &amp;lt;ref&amp;gt;http://perldoc.perl.org/perlobj.html#AUTOLOAD&amp;lt;/ref&amp;gt;  Anything that the AUTOLOAD method returns will be the last value returned to the caller (the caller never even needs to know the AUTOLOAD code exists).&lt;br /&gt;
&lt;br /&gt;
The following is a code snippet that can be used to auto-create methods on the fly in Perl using AUTOLOAD:&lt;br /&gt;
&lt;br /&gt;
  sub AUTOLOAD{&lt;br /&gt;
    my ($self,$value)= @_ ;&lt;br /&gt;
&lt;br /&gt;
    return if $AUTOLOAD =~ /::DESTROY$/ ;&lt;br /&gt;
&lt;br /&gt;
    my $attname = $AUTOLOAD;&lt;br /&gt;
&lt;br /&gt;
    $attname =~ s/.*::// ;&lt;br /&gt;
&lt;br /&gt;
    if(! exists $self-&amp;gt;{$attname}){&lt;br /&gt;
      Carp::confess(&amp;quot;Attribute $attname does not exists in $self&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    my $pkg = ref($self ) ;&lt;br /&gt;
&lt;br /&gt;
    my $code = qq{&lt;br /&gt;
               package $pkg ;&lt;br /&gt;
               sub $attname {&lt;br /&gt;
                       my \$self = shift ;&lt;br /&gt;
                       \@_ ? \$self-&amp;gt;{$attname} = shift :&lt;br /&gt;
                       \$self-&amp;gt;{$attname} ;&lt;br /&gt;
               }&lt;br /&gt;
       &lt;br /&gt;
       };&lt;br /&gt;
&lt;br /&gt;
    eval $code ;&lt;br /&gt;
    if( $@ ){&lt;br /&gt;
      Carp::confess(&amp;quot;Failed to create method $AUTOLOAD : $@&amp;quot;);&lt;br /&gt;
     }&lt;br /&gt;
       &lt;br /&gt;
    goto &amp;amp;$AUTOLOAD ;&lt;br /&gt;
               &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73433</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1n jp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73433"/>
		<updated>2013-02-21T00:51:17Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: /* Perl: AUTOLOAD */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby's method_missing(): Advantages/Disadvantages and Alternatives =&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
One of the distinguishing features of the Ruby programming language is it's ability to easily extend classes in a dynamic fashion to perform a variety of different methods depending upon the needs of the current application.  For example, should the developer want to extend a core language class, take String for example, they could easily re-open that class and add new methods dynamically to this existing class, rather than creating an entirely new class.&lt;br /&gt;
&lt;br /&gt;
Even more powerful, Ruby allows for a construct called method_missing().  By overriding this method in your class, method_missing() will attempt to handle any method calls not currently defined by the given class (or class hierarchy).  Typically, some sort of regular expression is used to determine if the method call can be redirected to an existing method based on it's naming convention (for example, a method call in a non-existent singular form could be redirected to an existing pluralized form).  If the method_missing() definition cannot determine where to redirect the method call, the default is simply to call the parent class via super().&lt;br /&gt;
&lt;br /&gt;
By having the ability to allow a class to dynamically extend itself even if a method definition never truly existed, Ruby allows for a far greater degree of flexibility than does a statically typed language such as Java, where much greater effort is involved in handing method calls that do not currently exist.  With method_missing() defined, almost any sort of method call can be handled in the desired manner.&lt;br /&gt;
&lt;br /&gt;
This article will explore the method_missing() construct in greater detail, giving both advantages and disadvantages of having this feature in the Ruby language.  We will also examine how other programming languages attempt to handle the same problem.&lt;br /&gt;
&lt;br /&gt;
==Advantages of method_missing()==&lt;br /&gt;
1. Allows for dynamically invoked methods.&lt;br /&gt;
 &lt;br /&gt;
==Disadvantages of method_missing()==&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==Alternatives to method_missing() in other programming languages==&lt;br /&gt;
&lt;br /&gt;
===Smalltalk: doesNotUnderstand===&lt;br /&gt;
&lt;br /&gt;
In many ways the inspiration for Ruby, Smalltalk is often considered one of the original truly Object-Oriented languages.  Smalltalk, much like Ruby with method_missing(), sends a message called #doesNotUnderstand&amp;lt;ref&amp;gt;http://c2.com/cgi/wiki?DoesNotUnderstand&amp;lt;/ref&amp;gt; to handle methods that are unknown.&lt;br /&gt;
&lt;br /&gt;
Essentially, when an object receives a method that it doesn't recognize, the Smalltalk runtime engine is then responsible for turning this message into an object with all necessary parameters and returning it to the sender as an exception. The sender is, at that point, responsible for handling the message and somehow dealing with the exception.  Even though Smalltalk does consider this an exception, this construct is used quite frequently to form proxy objects and can handle a wide variety of different methods and arguments.&lt;br /&gt;
&lt;br /&gt;
Consider the following code: &amp;lt;ref&amp;gt;http://www.iam.unibe.ch/~akuhn/blog/category/smalltalk/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    OrderedCollection subclass: #Group.&lt;br /&gt;
    Group &amp;gt;&amp;gt; eachRespondsTo: aSelector&lt;br /&gt;
        self allSatisfy: [ :each | each respondsTo: aSelector ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; doesNotUnderstand: aMessage&lt;br /&gt;
        (self eachRespondsTo: aMessage selector)&lt;br /&gt;
          ifTrue: [ self collect: [ :each | aMessage sendTo: each ] ]&lt;br /&gt;
          ifFalse: [ super doesNotUnderstand: aMessage ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; respondsTo: aSelector&lt;br /&gt;
      ^ (super respondsTo: aSelector) or: [ self eachRespondsTo: aSelector ]&lt;br /&gt;
&lt;br /&gt;
In this code snippet, an OrderedCollection object is created.  Should this collection class not understand any of the methods being sent to it, the doesUnderstand code will attempt to handle the message itself.  Without overriding this method, the default is for Smalltalk to open a debugger to step through the exception (defining it overrides this behavior).&lt;br /&gt;
&lt;br /&gt;
===Java: DynamicProxy===&lt;br /&gt;
&lt;br /&gt;
In Java, the ability to handle undefined methods is a bit more cumbersome, but it can still be done successfully through the use of dynamic proxy classes.  By creating this dynamic proxy, all calls will essentially be intercepted prior to invocation.  An attempt will be made to invoke the object in question and, if unable to do so, an interface will need to be defined to handle the missing method scenarios.  To give an example&amp;lt;ref&amp;gt;http://www.jroller.com/ie/entry/methodmissing_in_java&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
  public class Dynamic implements java.lang.reflect.InvocationHandler  {&lt;br /&gt;
        Object delegate;&lt;br /&gt;
        public Dynamic(Object delegate){&lt;br /&gt;
                this.delegate=delegate;&lt;br /&gt;
        }        &lt;br /&gt;
        public Object invoke(Object proxy, Method method, Object[] args) &lt;br /&gt;
                           throws Throwable {&lt;br /&gt;
                Object result = null;&lt;br /&gt;
                try {                  &lt;br /&gt;
                    result = method.invoke(delegate, args);&lt;br /&gt;
                } catch (InvocationTargetException e) {&lt;br /&gt;
                        result = &lt;br /&gt;
                  ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } catch (Exception e) {&lt;br /&gt;
                    result = &lt;br /&gt;
             ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } finally {&lt;br /&gt;
                    &lt;br /&gt;
                }&lt;br /&gt;
                if(result==delegate)&lt;br /&gt;
                        result = proxy;&lt;br /&gt;
                &lt;br /&gt;
                return result;&lt;br /&gt;
        }&lt;br /&gt;
        public static T newInstance(Object o,Class... interfaces) {&lt;br /&gt;
                return (T)java.lang.reflect.Proxy.newProxyInstance(&lt;br /&gt;
                    interfaces[0].getClassLoader(),&lt;br /&gt;
                    interfaces,&lt;br /&gt;
                    new Dynamic(o));&lt;br /&gt;
        }        &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Here, we define our Proxy class.  Note, both an Object and Method are passed in as parameters.  When attempting to invoke the method of the given Object, an exception is caught and delegated to a MethodMissing interface, which will also need to be defined.&lt;br /&gt;
&lt;br /&gt;
  public interface MethodMissing {&lt;br /&gt;
        public T methodMissing(Method method,E... args);        &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Now, we define an interface whose methods will need to be implemented in order to handle the missing objects.&lt;br /&gt;
&lt;br /&gt;
  public class Ruby implements MethodMissing{&lt;br /&gt;
        public Object methodMissing(Method method, Object... args) {&lt;br /&gt;
                System.out.println(method.getName());&lt;br /&gt;
                return this;&lt;br /&gt;
        }&lt;br /&gt;
        public static void main(String[] args){&lt;br /&gt;
                IDynamic dynamic = &lt;br /&gt;
                   Dynamic.newInstance(new Ruby(), IDynamic.class);               &lt;br /&gt;
                dynamic.meow().woof();&lt;br /&gt;
                dynamic.woof();&lt;br /&gt;
                &lt;br /&gt;
        }               &lt;br /&gt;
  }&lt;br /&gt;
  public interface IDynamic extends MethodMissing{&lt;br /&gt;
        public IDynamic woof();&lt;br /&gt;
        public IDynamic meow();&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Lastly, we create a class that attempts to utilize the MethodMissing construct.  As you can see, the Ruby class creates an implementation of the methodMissing() method, choosing to simply reflect the name of the method itself.  When the IDynamic class is created, it attempts to run several methods which are never actually defined.  Nevertheless, all of these method calls are actually intercepted by our proxy class and called as if there were no issue.&lt;br /&gt;
&lt;br /&gt;
The output of running this class would be:&lt;br /&gt;
&lt;br /&gt;
  meow&lt;br /&gt;
  woof&lt;br /&gt;
  woof&lt;br /&gt;
&lt;br /&gt;
Compared to Ruby, of course, or even Smalltalk, this is a very difficult way to handle missing methods.  Instead of having something built into the class itself, additional interfaces and wrappers are required to handle these scenarios, creating far more bulky and complex code.  Unfortunately, this is probably the price for having a statically typed language.&lt;br /&gt;
&lt;br /&gt;
===Python: __getattr__===&lt;br /&gt;
&lt;br /&gt;
In Python, much like Ruby, there is also a built-in class mechanism for handling non-existent methods.  Built into a class is __getattr__, which can be used to provide a default for all Python attributes that have not otherwise been defined.  In the following example: &amp;lt;ref&amp;gt;http://farmdev.com/src/secrets/magicmethod/index.html#introducing-getattr&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  class Test(object):&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        self.a = 'a'&lt;br /&gt;
        self.b = 'b'&lt;br /&gt;
    def __getattr__(self, name):&lt;br /&gt;
        return 123456&lt;br /&gt;
  t = Test()&lt;br /&gt;
  print 'object variables: %r' % t.__dict__.keys()&lt;br /&gt;
  print t.a&lt;br /&gt;
  print t.b&lt;br /&gt;
  print t.c&lt;br /&gt;
  print getattr(t, 'd')&lt;br /&gt;
  print hasattr(t, 'x')&lt;br /&gt;
&lt;br /&gt;
Expected output:&lt;br /&gt;
&lt;br /&gt;
  object variables: ['a', 'b']&lt;br /&gt;
  a&lt;br /&gt;
  b&lt;br /&gt;
  123456&lt;br /&gt;
  123456&lt;br /&gt;
  True&lt;br /&gt;
&lt;br /&gt;
In the above code, the Test class has variable definitions for 'a' and 'b', but no others.  When the print method tries to send in a 'c' or 'd' method call, __getattr__ catches this call and prints the generic '123456' value.  Even the hasattr method recognizes non-existent attributes as being valid without there even being an actual method call.&lt;br /&gt;
&lt;br /&gt;
If an attribute is found through a normal mechanism, this function is never actually called.  In fact, one difference with Ruby is that Python executes this method in a static fashion, only checking on one run if attributes have been defined somewhere for a relevant class.  This code may in fact not perform properly if classes are modified dynamically at runtime.&lt;br /&gt;
&lt;br /&gt;
===Perl: AUTOLOAD===&lt;br /&gt;
&lt;br /&gt;
Lastly, the Perl programming language provides the AUTOLOAD feature for handling this situation. Basically, if a class or any parent classes define an AUTOLOAD method, this method is called in the case where a direct method isn't found. &amp;lt;ref&amp;gt;http://perldoc.perl.org/perlobj.html#AUTOLOAD&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73359</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1n jp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73359"/>
		<updated>2013-02-20T21:11:43Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: /* Python: __getattr__ */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby's method_missing(): Advantages/Disadvantages and Alternatives =&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
One of the distinguishing features of the Ruby programming language is it's ability to easily extend classes in a dynamic fashion to perform a variety of different methods depending upon the needs of the current application.  For example, should the developer want to extend a core language class, take String for example, they could easily re-open that class and add new methods dynamically to this existing class, rather than creating an entirely new class.&lt;br /&gt;
&lt;br /&gt;
Even more powerful, Ruby allows for a construct called method_missing().  By overriding this method in your class, method_missing() will attempt to handle any method calls not currently defined by the given class (or class hierarchy).  Typically, some sort of regular expression is used to determine if the method call can be redirected to an existing method based on it's naming convention (for example, a method call in a non-existent singular form could be redirected to an existing pluralized form).  If the method_missing() definition cannot determine where to redirect the method call, the default is simply to call the parent class via super().&lt;br /&gt;
&lt;br /&gt;
By having the ability to allow a class to dynamically extend itself even if a method definition never truly existed, Ruby allows for a far greater degree of flexibility than does a statically typed language such as Java, where much greater effort is involved in handing method calls that do not currently exist.  With method_missing() defined, almost any sort of method call can be handled in the desired manner.&lt;br /&gt;
&lt;br /&gt;
This article will explore the method_missing() construct in greater detail, giving both advantages and disadvantages of having this feature in the Ruby language.  We will also examine how other programming languages attempt to handle the same problem.&lt;br /&gt;
&lt;br /&gt;
==Advantages of method_missing()==&lt;br /&gt;
1. Allows for dynamically invoked methods.&lt;br /&gt;
 &lt;br /&gt;
==Disadvantages of method_missing()==&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==Alternatives to method_missing() in other programming languages==&lt;br /&gt;
&lt;br /&gt;
===Smalltalk: doesNotUnderstand===&lt;br /&gt;
&lt;br /&gt;
In many ways the inspiration for Ruby, Smalltalk is often considered one of the original truly Object-Oriented languages.  Smalltalk, much like Ruby with method_missing(), sends a message called #doesNotUnderstand&amp;lt;ref&amp;gt;http://c2.com/cgi/wiki?DoesNotUnderstand&amp;lt;/ref&amp;gt; to handle methods that are unknown.&lt;br /&gt;
&lt;br /&gt;
Essentially, when an object receives a method that it doesn't recognize, the Smalltalk runtime engine is then responsible for turning this message into an object with all necessary parameters and returning it to the sender as an exception. The sender is, at that point, responsible for handling the message and somehow dealing with the exception.  Even though Smalltalk does consider this an exception, this construct is used quite frequently to form proxy objects and can handle a wide variety of different methods and arguments.&lt;br /&gt;
&lt;br /&gt;
Consider the following code: &amp;lt;ref&amp;gt;http://www.iam.unibe.ch/~akuhn/blog/category/smalltalk/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    OrderedCollection subclass: #Group.&lt;br /&gt;
    Group &amp;gt;&amp;gt; eachRespondsTo: aSelector&lt;br /&gt;
        self allSatisfy: [ :each | each respondsTo: aSelector ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; doesNotUnderstand: aMessage&lt;br /&gt;
        (self eachRespondsTo: aMessage selector)&lt;br /&gt;
          ifTrue: [ self collect: [ :each | aMessage sendTo: each ] ]&lt;br /&gt;
          ifFalse: [ super doesNotUnderstand: aMessage ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; respondsTo: aSelector&lt;br /&gt;
      ^ (super respondsTo: aSelector) or: [ self eachRespondsTo: aSelector ]&lt;br /&gt;
&lt;br /&gt;
In this code snippet, an OrderedCollection object is created.  Should this collection class not understand any of the methods being sent to it, the doesUnderstand code will attempt to handle the message itself.  Without overriding this method, the default is for Smalltalk to open a debugger to step through the exception (defining it overrides this behavior).&lt;br /&gt;
&lt;br /&gt;
===Java: DynamicProxy===&lt;br /&gt;
&lt;br /&gt;
In Java, the ability to handle undefined methods is a bit more cumbersome, but it can still be done successfully through the use of dynamic proxy classes.  By creating this dynamic proxy, all calls will essentially be intercepted prior to invocation.  An attempt will be made to invoke the object in question and, if unable to do so, an interface will need to be defined to handle the missing method scenarios.  To give an example&amp;lt;ref&amp;gt;http://www.jroller.com/ie/entry/methodmissing_in_java&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
  public class Dynamic implements java.lang.reflect.InvocationHandler  {&lt;br /&gt;
        Object delegate;&lt;br /&gt;
        public Dynamic(Object delegate){&lt;br /&gt;
                this.delegate=delegate;&lt;br /&gt;
        }        &lt;br /&gt;
        public Object invoke(Object proxy, Method method, Object[] args) &lt;br /&gt;
                           throws Throwable {&lt;br /&gt;
                Object result = null;&lt;br /&gt;
                try {                  &lt;br /&gt;
                    result = method.invoke(delegate, args);&lt;br /&gt;
                } catch (InvocationTargetException e) {&lt;br /&gt;
                        result = &lt;br /&gt;
                  ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } catch (Exception e) {&lt;br /&gt;
                    result = &lt;br /&gt;
             ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } finally {&lt;br /&gt;
                    &lt;br /&gt;
                }&lt;br /&gt;
                if(result==delegate)&lt;br /&gt;
                        result = proxy;&lt;br /&gt;
                &lt;br /&gt;
                return result;&lt;br /&gt;
        }&lt;br /&gt;
        public static T newInstance(Object o,Class... interfaces) {&lt;br /&gt;
                return (T)java.lang.reflect.Proxy.newProxyInstance(&lt;br /&gt;
                    interfaces[0].getClassLoader(),&lt;br /&gt;
                    interfaces,&lt;br /&gt;
                    new Dynamic(o));&lt;br /&gt;
        }        &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Here, we define our Proxy class.  Note, both an Object and Method are passed in as parameters.  When attempting to invoke the method of the given Object, an exception is caught and delegated to a MethodMissing interface, which will also need to be defined.&lt;br /&gt;
&lt;br /&gt;
  public interface MethodMissing {&lt;br /&gt;
        public T methodMissing(Method method,E... args);        &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Now, we define an interface whose methods will need to be implemented in order to handle the missing objects.&lt;br /&gt;
&lt;br /&gt;
  public class Ruby implements MethodMissing{&lt;br /&gt;
        public Object methodMissing(Method method, Object... args) {&lt;br /&gt;
                System.out.println(method.getName());&lt;br /&gt;
                return this;&lt;br /&gt;
        }&lt;br /&gt;
        public static void main(String[] args){&lt;br /&gt;
                IDynamic dynamic = &lt;br /&gt;
                   Dynamic.newInstance(new Ruby(), IDynamic.class);               &lt;br /&gt;
                dynamic.meow().woof();&lt;br /&gt;
                dynamic.woof();&lt;br /&gt;
                &lt;br /&gt;
        }               &lt;br /&gt;
  }&lt;br /&gt;
  public interface IDynamic extends MethodMissing{&lt;br /&gt;
        public IDynamic woof();&lt;br /&gt;
        public IDynamic meow();&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Lastly, we create a class that attempts to utilize the MethodMissing construct.  As you can see, the Ruby class creates an implementation of the methodMissing() method, choosing to simply reflect the name of the method itself.  When the IDynamic class is created, it attempts to run several methods which are never actually defined.  Nevertheless, all of these method calls are actually intercepted by our proxy class and called as if there were no issue.&lt;br /&gt;
&lt;br /&gt;
The output of running this class would be:&lt;br /&gt;
&lt;br /&gt;
  meow&lt;br /&gt;
  woof&lt;br /&gt;
  woof&lt;br /&gt;
&lt;br /&gt;
Compared to Ruby, of course, or even Smalltalk, this is a very difficult way to handle missing methods.  Instead of having something built into the class itself, additional interfaces and wrappers are required to handle these scenarios, creating far more bulky and complex code.  Unfortunately, this is probably the price for having a statically typed language.&lt;br /&gt;
&lt;br /&gt;
===Python: __getattr__===&lt;br /&gt;
&lt;br /&gt;
In Python, much like Ruby, there is also a built-in class mechanism for handling non-existent methods.  Built into a class is __getattr__, which can be used to provide a default for all Python attributes that have not otherwise been defined.  In the following example: &amp;lt;ref&amp;gt;http://farmdev.com/src/secrets/magicmethod/index.html#introducing-getattr&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  class Test(object):&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        self.a = 'a'&lt;br /&gt;
        self.b = 'b'&lt;br /&gt;
    def __getattr__(self, name):&lt;br /&gt;
        return 123456&lt;br /&gt;
  t = Test()&lt;br /&gt;
  print 'object variables: %r' % t.__dict__.keys()&lt;br /&gt;
  print t.a&lt;br /&gt;
  print t.b&lt;br /&gt;
  print t.c&lt;br /&gt;
  print getattr(t, 'd')&lt;br /&gt;
  print hasattr(t, 'x')&lt;br /&gt;
&lt;br /&gt;
Expected output:&lt;br /&gt;
&lt;br /&gt;
  object variables: ['a', 'b']&lt;br /&gt;
  a&lt;br /&gt;
  b&lt;br /&gt;
  123456&lt;br /&gt;
  123456&lt;br /&gt;
  True&lt;br /&gt;
&lt;br /&gt;
In the above code, the Test class has variable definitions for 'a' and 'b', but no others.  When the print method tries to send in a 'c' or 'd' method call, __getattr__ catches this call and prints the generic '123456' value.  Even the hasattr method recognizes non-existent attributes as being valid without there even being an actual method call.&lt;br /&gt;
&lt;br /&gt;
If an attribute is found through a normal mechanism, this function is never actually called.  In fact, one difference with Ruby is that Python executes this method in a static fashion, only checking on one run if attributes have been defined somewhere for a relevant class.  This code may in fact not perform properly if classes are modified dynamically at runtime.&lt;br /&gt;
&lt;br /&gt;
===Perl: AUTOLOAD===&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73358</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1n jp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73358"/>
		<updated>2013-02-20T20:57:29Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: /* Python: __getattr__ */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby's method_missing(): Advantages/Disadvantages and Alternatives =&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
One of the distinguishing features of the Ruby programming language is it's ability to easily extend classes in a dynamic fashion to perform a variety of different methods depending upon the needs of the current application.  For example, should the developer want to extend a core language class, take String for example, they could easily re-open that class and add new methods dynamically to this existing class, rather than creating an entirely new class.&lt;br /&gt;
&lt;br /&gt;
Even more powerful, Ruby allows for a construct called method_missing().  By overriding this method in your class, method_missing() will attempt to handle any method calls not currently defined by the given class (or class hierarchy).  Typically, some sort of regular expression is used to determine if the method call can be redirected to an existing method based on it's naming convention (for example, a method call in a non-existent singular form could be redirected to an existing pluralized form).  If the method_missing() definition cannot determine where to redirect the method call, the default is simply to call the parent class via super().&lt;br /&gt;
&lt;br /&gt;
By having the ability to allow a class to dynamically extend itself even if a method definition never truly existed, Ruby allows for a far greater degree of flexibility than does a statically typed language such as Java, where much greater effort is involved in handing method calls that do not currently exist.  With method_missing() defined, almost any sort of method call can be handled in the desired manner.&lt;br /&gt;
&lt;br /&gt;
This article will explore the method_missing() construct in greater detail, giving both advantages and disadvantages of having this feature in the Ruby language.  We will also examine how other programming languages attempt to handle the same problem.&lt;br /&gt;
&lt;br /&gt;
==Advantages of method_missing()==&lt;br /&gt;
1. Allows for dynamically invoked methods.&lt;br /&gt;
 &lt;br /&gt;
==Disadvantages of method_missing()==&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==Alternatives to method_missing() in other programming languages==&lt;br /&gt;
&lt;br /&gt;
===Smalltalk: doesNotUnderstand===&lt;br /&gt;
&lt;br /&gt;
In many ways the inspiration for Ruby, Smalltalk is often considered one of the original truly Object-Oriented languages.  Smalltalk, much like Ruby with method_missing(), sends a message called #doesNotUnderstand&amp;lt;ref&amp;gt;http://c2.com/cgi/wiki?DoesNotUnderstand&amp;lt;/ref&amp;gt; to handle methods that are unknown.&lt;br /&gt;
&lt;br /&gt;
Essentially, when an object receives a method that it doesn't recognize, the Smalltalk runtime engine is then responsible for turning this message into an object with all necessary parameters and returning it to the sender as an exception. The sender is, at that point, responsible for handling the message and somehow dealing with the exception.  Even though Smalltalk does consider this an exception, this construct is used quite frequently to form proxy objects and can handle a wide variety of different methods and arguments.&lt;br /&gt;
&lt;br /&gt;
Consider the following code: &amp;lt;ref&amp;gt;http://www.iam.unibe.ch/~akuhn/blog/category/smalltalk/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    OrderedCollection subclass: #Group.&lt;br /&gt;
    Group &amp;gt;&amp;gt; eachRespondsTo: aSelector&lt;br /&gt;
        self allSatisfy: [ :each | each respondsTo: aSelector ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; doesNotUnderstand: aMessage&lt;br /&gt;
        (self eachRespondsTo: aMessage selector)&lt;br /&gt;
          ifTrue: [ self collect: [ :each | aMessage sendTo: each ] ]&lt;br /&gt;
          ifFalse: [ super doesNotUnderstand: aMessage ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; respondsTo: aSelector&lt;br /&gt;
      ^ (super respondsTo: aSelector) or: [ self eachRespondsTo: aSelector ]&lt;br /&gt;
&lt;br /&gt;
In this code snippet, an OrderedCollection object is created.  Should this collection class not understand any of the methods being sent to it, the doesUnderstand code will attempt to handle the message itself.  Without overriding this method, the default is for Smalltalk to open a debugger to step through the exception (defining it overrides this behavior).&lt;br /&gt;
&lt;br /&gt;
===Java: DynamicProxy===&lt;br /&gt;
&lt;br /&gt;
In Java, the ability to handle undefined methods is a bit more cumbersome, but it can still be done successfully through the use of dynamic proxy classes.  By creating this dynamic proxy, all calls will essentially be intercepted prior to invocation.  An attempt will be made to invoke the object in question and, if unable to do so, an interface will need to be defined to handle the missing method scenarios.  To give an example&amp;lt;ref&amp;gt;http://www.jroller.com/ie/entry/methodmissing_in_java&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
  public class Dynamic implements java.lang.reflect.InvocationHandler  {&lt;br /&gt;
        Object delegate;&lt;br /&gt;
        public Dynamic(Object delegate){&lt;br /&gt;
                this.delegate=delegate;&lt;br /&gt;
        }        &lt;br /&gt;
        public Object invoke(Object proxy, Method method, Object[] args) &lt;br /&gt;
                           throws Throwable {&lt;br /&gt;
                Object result = null;&lt;br /&gt;
                try {                  &lt;br /&gt;
                    result = method.invoke(delegate, args);&lt;br /&gt;
                } catch (InvocationTargetException e) {&lt;br /&gt;
                        result = &lt;br /&gt;
                  ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } catch (Exception e) {&lt;br /&gt;
                    result = &lt;br /&gt;
             ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } finally {&lt;br /&gt;
                    &lt;br /&gt;
                }&lt;br /&gt;
                if(result==delegate)&lt;br /&gt;
                        result = proxy;&lt;br /&gt;
                &lt;br /&gt;
                return result;&lt;br /&gt;
        }&lt;br /&gt;
        public static T newInstance(Object o,Class... interfaces) {&lt;br /&gt;
                return (T)java.lang.reflect.Proxy.newProxyInstance(&lt;br /&gt;
                    interfaces[0].getClassLoader(),&lt;br /&gt;
                    interfaces,&lt;br /&gt;
                    new Dynamic(o));&lt;br /&gt;
        }        &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Here, we define our Proxy class.  Note, both an Object and Method are passed in as parameters.  When attempting to invoke the method of the given Object, an exception is caught and delegated to a MethodMissing interface, which will also need to be defined.&lt;br /&gt;
&lt;br /&gt;
  public interface MethodMissing {&lt;br /&gt;
        public T methodMissing(Method method,E... args);        &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Now, we define an interface whose methods will need to be implemented in order to handle the missing objects.&lt;br /&gt;
&lt;br /&gt;
  public class Ruby implements MethodMissing{&lt;br /&gt;
        public Object methodMissing(Method method, Object... args) {&lt;br /&gt;
                System.out.println(method.getName());&lt;br /&gt;
                return this;&lt;br /&gt;
        }&lt;br /&gt;
        public static void main(String[] args){&lt;br /&gt;
                IDynamic dynamic = &lt;br /&gt;
                   Dynamic.newInstance(new Ruby(), IDynamic.class);               &lt;br /&gt;
                dynamic.meow().woof();&lt;br /&gt;
                dynamic.woof();&lt;br /&gt;
                &lt;br /&gt;
        }               &lt;br /&gt;
  }&lt;br /&gt;
  public interface IDynamic extends MethodMissing{&lt;br /&gt;
        public IDynamic woof();&lt;br /&gt;
        public IDynamic meow();&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Lastly, we create a class that attempts to utilize the MethodMissing construct.  As you can see, the Ruby class creates an implementation of the methodMissing() method, choosing to simply reflect the name of the method itself.  When the IDynamic class is created, it attempts to run several methods which are never actually defined.  Nevertheless, all of these method calls are actually intercepted by our proxy class and called as if there were no issue.&lt;br /&gt;
&lt;br /&gt;
The output of running this class would be:&lt;br /&gt;
&lt;br /&gt;
  meow&lt;br /&gt;
  woof&lt;br /&gt;
  woof&lt;br /&gt;
&lt;br /&gt;
Compared to Ruby, of course, or even Smalltalk, this is a very difficult way to handle missing methods.  Instead of having something built into the class itself, additional interfaces and wrappers are required to handle these scenarios, creating far more bulky and complex code.  Unfortunately, this is probably the price for having a statically typed language.&lt;br /&gt;
&lt;br /&gt;
===Python: __getattr__===&lt;br /&gt;
&lt;br /&gt;
In Python, much like Ruby, there is also a built-in class mechanism for handling non-existent methods.  Built into a class is __getattr__, which can be used to provide a default for all Python attributes that have not otherwise been defined.  In the following example: &amp;lt;ref&amp;gt;http://farmdev.com/src/secrets/magicmethod/index.html#introducing-getattr&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  class Test(object):&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        self.a = 'a'&lt;br /&gt;
        self.b = 'b'&lt;br /&gt;
    def __getattr__(self, name):&lt;br /&gt;
        return 123456&lt;br /&gt;
  t = Test()&lt;br /&gt;
  print 'object variables: %r' % t.__dict__.keys()&lt;br /&gt;
  print t.a&lt;br /&gt;
  print t.b&lt;br /&gt;
  print t.c&lt;br /&gt;
  print getattr(t, 'd')&lt;br /&gt;
  print hasattr(t, 'x')&lt;br /&gt;
&lt;br /&gt;
Expected output:&lt;br /&gt;
&lt;br /&gt;
  object variables: ['a', 'b']&lt;br /&gt;
  a&lt;br /&gt;
  b&lt;br /&gt;
  123456&lt;br /&gt;
  123456&lt;br /&gt;
  True&lt;br /&gt;
&lt;br /&gt;
===Perl: AUTOLOAD===&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73357</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1n jp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73357"/>
		<updated>2013-02-20T20:56:54Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: /* Python: __getattr__ */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby's method_missing(): Advantages/Disadvantages and Alternatives =&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
One of the distinguishing features of the Ruby programming language is it's ability to easily extend classes in a dynamic fashion to perform a variety of different methods depending upon the needs of the current application.  For example, should the developer want to extend a core language class, take String for example, they could easily re-open that class and add new methods dynamically to this existing class, rather than creating an entirely new class.&lt;br /&gt;
&lt;br /&gt;
Even more powerful, Ruby allows for a construct called method_missing().  By overriding this method in your class, method_missing() will attempt to handle any method calls not currently defined by the given class (or class hierarchy).  Typically, some sort of regular expression is used to determine if the method call can be redirected to an existing method based on it's naming convention (for example, a method call in a non-existent singular form could be redirected to an existing pluralized form).  If the method_missing() definition cannot determine where to redirect the method call, the default is simply to call the parent class via super().&lt;br /&gt;
&lt;br /&gt;
By having the ability to allow a class to dynamically extend itself even if a method definition never truly existed, Ruby allows for a far greater degree of flexibility than does a statically typed language such as Java, where much greater effort is involved in handing method calls that do not currently exist.  With method_missing() defined, almost any sort of method call can be handled in the desired manner.&lt;br /&gt;
&lt;br /&gt;
This article will explore the method_missing() construct in greater detail, giving both advantages and disadvantages of having this feature in the Ruby language.  We will also examine how other programming languages attempt to handle the same problem.&lt;br /&gt;
&lt;br /&gt;
==Advantages of method_missing()==&lt;br /&gt;
1. Allows for dynamically invoked methods.&lt;br /&gt;
 &lt;br /&gt;
==Disadvantages of method_missing()==&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==Alternatives to method_missing() in other programming languages==&lt;br /&gt;
&lt;br /&gt;
===Smalltalk: doesNotUnderstand===&lt;br /&gt;
&lt;br /&gt;
In many ways the inspiration for Ruby, Smalltalk is often considered one of the original truly Object-Oriented languages.  Smalltalk, much like Ruby with method_missing(), sends a message called #doesNotUnderstand&amp;lt;ref&amp;gt;http://c2.com/cgi/wiki?DoesNotUnderstand&amp;lt;/ref&amp;gt; to handle methods that are unknown.&lt;br /&gt;
&lt;br /&gt;
Essentially, when an object receives a method that it doesn't recognize, the Smalltalk runtime engine is then responsible for turning this message into an object with all necessary parameters and returning it to the sender as an exception. The sender is, at that point, responsible for handling the message and somehow dealing with the exception.  Even though Smalltalk does consider this an exception, this construct is used quite frequently to form proxy objects and can handle a wide variety of different methods and arguments.&lt;br /&gt;
&lt;br /&gt;
Consider the following code: &amp;lt;ref&amp;gt;http://www.iam.unibe.ch/~akuhn/blog/category/smalltalk/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    OrderedCollection subclass: #Group.&lt;br /&gt;
    Group &amp;gt;&amp;gt; eachRespondsTo: aSelector&lt;br /&gt;
        self allSatisfy: [ :each | each respondsTo: aSelector ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; doesNotUnderstand: aMessage&lt;br /&gt;
        (self eachRespondsTo: aMessage selector)&lt;br /&gt;
          ifTrue: [ self collect: [ :each | aMessage sendTo: each ] ]&lt;br /&gt;
          ifFalse: [ super doesNotUnderstand: aMessage ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; respondsTo: aSelector&lt;br /&gt;
      ^ (super respondsTo: aSelector) or: [ self eachRespondsTo: aSelector ]&lt;br /&gt;
&lt;br /&gt;
In this code snippet, an OrderedCollection object is created.  Should this collection class not understand any of the methods being sent to it, the doesUnderstand code will attempt to handle the message itself.  Without overriding this method, the default is for Smalltalk to open a debugger to step through the exception (defining it overrides this behavior).&lt;br /&gt;
&lt;br /&gt;
===Java: DynamicProxy===&lt;br /&gt;
&lt;br /&gt;
In Java, the ability to handle undefined methods is a bit more cumbersome, but it can still be done successfully through the use of dynamic proxy classes.  By creating this dynamic proxy, all calls will essentially be intercepted prior to invocation.  An attempt will be made to invoke the object in question and, if unable to do so, an interface will need to be defined to handle the missing method scenarios.  To give an example&amp;lt;ref&amp;gt;http://www.jroller.com/ie/entry/methodmissing_in_java&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
  public class Dynamic implements java.lang.reflect.InvocationHandler  {&lt;br /&gt;
        Object delegate;&lt;br /&gt;
        public Dynamic(Object delegate){&lt;br /&gt;
                this.delegate=delegate;&lt;br /&gt;
        }        &lt;br /&gt;
        public Object invoke(Object proxy, Method method, Object[] args) &lt;br /&gt;
                           throws Throwable {&lt;br /&gt;
                Object result = null;&lt;br /&gt;
                try {                  &lt;br /&gt;
                    result = method.invoke(delegate, args);&lt;br /&gt;
                } catch (InvocationTargetException e) {&lt;br /&gt;
                        result = &lt;br /&gt;
                  ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } catch (Exception e) {&lt;br /&gt;
                    result = &lt;br /&gt;
             ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } finally {&lt;br /&gt;
                    &lt;br /&gt;
                }&lt;br /&gt;
                if(result==delegate)&lt;br /&gt;
                        result = proxy;&lt;br /&gt;
                &lt;br /&gt;
                return result;&lt;br /&gt;
        }&lt;br /&gt;
        public static T newInstance(Object o,Class... interfaces) {&lt;br /&gt;
                return (T)java.lang.reflect.Proxy.newProxyInstance(&lt;br /&gt;
                    interfaces[0].getClassLoader(),&lt;br /&gt;
                    interfaces,&lt;br /&gt;
                    new Dynamic(o));&lt;br /&gt;
        }        &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Here, we define our Proxy class.  Note, both an Object and Method are passed in as parameters.  When attempting to invoke the method of the given Object, an exception is caught and delegated to a MethodMissing interface, which will also need to be defined.&lt;br /&gt;
&lt;br /&gt;
  public interface MethodMissing {&lt;br /&gt;
        public T methodMissing(Method method,E... args);        &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Now, we define an interface whose methods will need to be implemented in order to handle the missing objects.&lt;br /&gt;
&lt;br /&gt;
  public class Ruby implements MethodMissing{&lt;br /&gt;
        public Object methodMissing(Method method, Object... args) {&lt;br /&gt;
                System.out.println(method.getName());&lt;br /&gt;
                return this;&lt;br /&gt;
        }&lt;br /&gt;
        public static void main(String[] args){&lt;br /&gt;
                IDynamic dynamic = &lt;br /&gt;
                   Dynamic.newInstance(new Ruby(), IDynamic.class);               &lt;br /&gt;
                dynamic.meow().woof();&lt;br /&gt;
                dynamic.woof();&lt;br /&gt;
                &lt;br /&gt;
        }               &lt;br /&gt;
  }&lt;br /&gt;
  public interface IDynamic extends MethodMissing{&lt;br /&gt;
        public IDynamic woof();&lt;br /&gt;
        public IDynamic meow();&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Lastly, we create a class that attempts to utilize the MethodMissing construct.  As you can see, the Ruby class creates an implementation of the methodMissing() method, choosing to simply reflect the name of the method itself.  When the IDynamic class is created, it attempts to run several methods which are never actually defined.  Nevertheless, all of these method calls are actually intercepted by our proxy class and called as if there were no issue.&lt;br /&gt;
&lt;br /&gt;
The output of running this class would be:&lt;br /&gt;
&lt;br /&gt;
  meow&lt;br /&gt;
  woof&lt;br /&gt;
  woof&lt;br /&gt;
&lt;br /&gt;
Compared to Ruby, of course, or even Smalltalk, this is a very difficult way to handle missing methods.  Instead of having something built into the class itself, additional interfaces and wrappers are required to handle these scenarios, creating far more bulky and complex code.  Unfortunately, this is probably the price for having a statically typed language.&lt;br /&gt;
&lt;br /&gt;
===Python: __getattr__===&lt;br /&gt;
&lt;br /&gt;
In Python, much like Ruby, there is also a built-in class mechanism for handling non-existent methods.  Built into a class is __getattr__, which can be used to provide a default for all Python attributes that have not otherwise been defined.  In the following example: &amp;lt;ref&amp;gt;http://farmdev.com/src/secrets/magicmethod/index.html#introducing-getattr&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  class Test(object):&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        self.a = 'a'&lt;br /&gt;
        self.b = 'b'&lt;br /&gt;
&lt;br /&gt;
    def __getattr__(self, name):&lt;br /&gt;
        return 123456&lt;br /&gt;
&lt;br /&gt;
  t = Test()&lt;br /&gt;
  print 'object variables: %r' % t.__dict__.keys()&lt;br /&gt;
  print t.a&lt;br /&gt;
  print t.b&lt;br /&gt;
  print t.c&lt;br /&gt;
  print getattr(t, 'd')&lt;br /&gt;
  print hasattr(t, 'x')&lt;br /&gt;
&lt;br /&gt;
Expected output:&lt;br /&gt;
&lt;br /&gt;
  object variables: ['a', 'b']&lt;br /&gt;
  a&lt;br /&gt;
  b&lt;br /&gt;
  123456&lt;br /&gt;
  123456&lt;br /&gt;
  True&lt;br /&gt;
&lt;br /&gt;
===Perl: AUTOLOAD===&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73356</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1n jp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73356"/>
		<updated>2013-02-20T20:54:04Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: /* Python: __getattr__ */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby's method_missing(): Advantages/Disadvantages and Alternatives =&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
One of the distinguishing features of the Ruby programming language is it's ability to easily extend classes in a dynamic fashion to perform a variety of different methods depending upon the needs of the current application.  For example, should the developer want to extend a core language class, take String for example, they could easily re-open that class and add new methods dynamically to this existing class, rather than creating an entirely new class.&lt;br /&gt;
&lt;br /&gt;
Even more powerful, Ruby allows for a construct called method_missing().  By overriding this method in your class, method_missing() will attempt to handle any method calls not currently defined by the given class (or class hierarchy).  Typically, some sort of regular expression is used to determine if the method call can be redirected to an existing method based on it's naming convention (for example, a method call in a non-existent singular form could be redirected to an existing pluralized form).  If the method_missing() definition cannot determine where to redirect the method call, the default is simply to call the parent class via super().&lt;br /&gt;
&lt;br /&gt;
By having the ability to allow a class to dynamically extend itself even if a method definition never truly existed, Ruby allows for a far greater degree of flexibility than does a statically typed language such as Java, where much greater effort is involved in handing method calls that do not currently exist.  With method_missing() defined, almost any sort of method call can be handled in the desired manner.&lt;br /&gt;
&lt;br /&gt;
This article will explore the method_missing() construct in greater detail, giving both advantages and disadvantages of having this feature in the Ruby language.  We will also examine how other programming languages attempt to handle the same problem.&lt;br /&gt;
&lt;br /&gt;
==Advantages of method_missing()==&lt;br /&gt;
1. Allows for dynamically invoked methods.&lt;br /&gt;
 &lt;br /&gt;
==Disadvantages of method_missing()==&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==Alternatives to method_missing() in other programming languages==&lt;br /&gt;
&lt;br /&gt;
===Smalltalk: doesNotUnderstand===&lt;br /&gt;
&lt;br /&gt;
In many ways the inspiration for Ruby, Smalltalk is often considered one of the original truly Object-Oriented languages.  Smalltalk, much like Ruby with method_missing(), sends a message called #doesNotUnderstand&amp;lt;ref&amp;gt;http://c2.com/cgi/wiki?DoesNotUnderstand&amp;lt;/ref&amp;gt; to handle methods that are unknown.&lt;br /&gt;
&lt;br /&gt;
Essentially, when an object receives a method that it doesn't recognize, the Smalltalk runtime engine is then responsible for turning this message into an object with all necessary parameters and returning it to the sender as an exception. The sender is, at that point, responsible for handling the message and somehow dealing with the exception.  Even though Smalltalk does consider this an exception, this construct is used quite frequently to form proxy objects and can handle a wide variety of different methods and arguments.&lt;br /&gt;
&lt;br /&gt;
Consider the following code: &amp;lt;ref&amp;gt;http://www.iam.unibe.ch/~akuhn/blog/category/smalltalk/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    OrderedCollection subclass: #Group.&lt;br /&gt;
    Group &amp;gt;&amp;gt; eachRespondsTo: aSelector&lt;br /&gt;
        self allSatisfy: [ :each | each respondsTo: aSelector ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; doesNotUnderstand: aMessage&lt;br /&gt;
        (self eachRespondsTo: aMessage selector)&lt;br /&gt;
          ifTrue: [ self collect: [ :each | aMessage sendTo: each ] ]&lt;br /&gt;
          ifFalse: [ super doesNotUnderstand: aMessage ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; respondsTo: aSelector&lt;br /&gt;
      ^ (super respondsTo: aSelector) or: [ self eachRespondsTo: aSelector ]&lt;br /&gt;
&lt;br /&gt;
In this code snippet, an OrderedCollection object is created.  Should this collection class not understand any of the methods being sent to it, the doesUnderstand code will attempt to handle the message itself.  Without overriding this method, the default is for Smalltalk to open a debugger to step through the exception (defining it overrides this behavior).&lt;br /&gt;
&lt;br /&gt;
===Java: DynamicProxy===&lt;br /&gt;
&lt;br /&gt;
In Java, the ability to handle undefined methods is a bit more cumbersome, but it can still be done successfully through the use of dynamic proxy classes.  By creating this dynamic proxy, all calls will essentially be intercepted prior to invocation.  An attempt will be made to invoke the object in question and, if unable to do so, an interface will need to be defined to handle the missing method scenarios.  To give an example&amp;lt;ref&amp;gt;http://www.jroller.com/ie/entry/methodmissing_in_java&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
  public class Dynamic implements java.lang.reflect.InvocationHandler  {&lt;br /&gt;
        Object delegate;&lt;br /&gt;
        public Dynamic(Object delegate){&lt;br /&gt;
                this.delegate=delegate;&lt;br /&gt;
        }        &lt;br /&gt;
        public Object invoke(Object proxy, Method method, Object[] args) &lt;br /&gt;
                           throws Throwable {&lt;br /&gt;
                Object result = null;&lt;br /&gt;
                try {                  &lt;br /&gt;
                    result = method.invoke(delegate, args);&lt;br /&gt;
                } catch (InvocationTargetException e) {&lt;br /&gt;
                        result = &lt;br /&gt;
                  ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } catch (Exception e) {&lt;br /&gt;
                    result = &lt;br /&gt;
             ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } finally {&lt;br /&gt;
                    &lt;br /&gt;
                }&lt;br /&gt;
                if(result==delegate)&lt;br /&gt;
                        result = proxy;&lt;br /&gt;
                &lt;br /&gt;
                return result;&lt;br /&gt;
        }&lt;br /&gt;
        public static T newInstance(Object o,Class... interfaces) {&lt;br /&gt;
                return (T)java.lang.reflect.Proxy.newProxyInstance(&lt;br /&gt;
                    interfaces[0].getClassLoader(),&lt;br /&gt;
                    interfaces,&lt;br /&gt;
                    new Dynamic(o));&lt;br /&gt;
        }        &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Here, we define our Proxy class.  Note, both an Object and Method are passed in as parameters.  When attempting to invoke the method of the given Object, an exception is caught and delegated to a MethodMissing interface, which will also need to be defined.&lt;br /&gt;
&lt;br /&gt;
  public interface MethodMissing {&lt;br /&gt;
        public T methodMissing(Method method,E... args);        &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Now, we define an interface whose methods will need to be implemented in order to handle the missing objects.&lt;br /&gt;
&lt;br /&gt;
  public class Ruby implements MethodMissing{&lt;br /&gt;
        public Object methodMissing(Method method, Object... args) {&lt;br /&gt;
                System.out.println(method.getName());&lt;br /&gt;
                return this;&lt;br /&gt;
        }&lt;br /&gt;
        public static void main(String[] args){&lt;br /&gt;
                IDynamic dynamic = &lt;br /&gt;
                   Dynamic.newInstance(new Ruby(), IDynamic.class);               &lt;br /&gt;
                dynamic.meow().woof();&lt;br /&gt;
                dynamic.woof();&lt;br /&gt;
                &lt;br /&gt;
        }               &lt;br /&gt;
  }&lt;br /&gt;
  public interface IDynamic extends MethodMissing{&lt;br /&gt;
        public IDynamic woof();&lt;br /&gt;
        public IDynamic meow();&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Lastly, we create a class that attempts to utilize the MethodMissing construct.  As you can see, the Ruby class creates an implementation of the methodMissing() method, choosing to simply reflect the name of the method itself.  When the IDynamic class is created, it attempts to run several methods which are never actually defined.  Nevertheless, all of these method calls are actually intercepted by our proxy class and called as if there were no issue.&lt;br /&gt;
&lt;br /&gt;
The output of running this class would be:&lt;br /&gt;
&lt;br /&gt;
  meow&lt;br /&gt;
  woof&lt;br /&gt;
  woof&lt;br /&gt;
&lt;br /&gt;
Compared to Ruby, of course, or even Smalltalk, this is a very difficult way to handle missing methods.  Instead of having something built into the class itself, additional interfaces and wrappers are required to handle these scenarios, creating far more bulky and complex code.  Unfortunately, this is probably the price for having a statically typed language.&lt;br /&gt;
&lt;br /&gt;
===Python: __getattr__===&lt;br /&gt;
&lt;br /&gt;
In Python, much like Ruby, there is also a built-in class mechanism for handling non-existent methods.  Built into a class is __getattr__, which can be used to provide a default for all Python attributes that have not otherwise been defined.  In the following example: &amp;lt;ref&amp;gt;http://farmdev.com/src/secrets/magicmethod/index.html#introducing-getattr&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Perl: AUTOLOAD===&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73355</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1n jp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73355"/>
		<updated>2013-02-20T20:35:31Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: /* Java: DynamicProxy */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby's method_missing(): Advantages/Disadvantages and Alternatives =&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
One of the distinguishing features of the Ruby programming language is it's ability to easily extend classes in a dynamic fashion to perform a variety of different methods depending upon the needs of the current application.  For example, should the developer want to extend a core language class, take String for example, they could easily re-open that class and add new methods dynamically to this existing class, rather than creating an entirely new class.&lt;br /&gt;
&lt;br /&gt;
Even more powerful, Ruby allows for a construct called method_missing().  By overriding this method in your class, method_missing() will attempt to handle any method calls not currently defined by the given class (or class hierarchy).  Typically, some sort of regular expression is used to determine if the method call can be redirected to an existing method based on it's naming convention (for example, a method call in a non-existent singular form could be redirected to an existing pluralized form).  If the method_missing() definition cannot determine where to redirect the method call, the default is simply to call the parent class via super().&lt;br /&gt;
&lt;br /&gt;
By having the ability to allow a class to dynamically extend itself even if a method definition never truly existed, Ruby allows for a far greater degree of flexibility than does a statically typed language such as Java, where much greater effort is involved in handing method calls that do not currently exist.  With method_missing() defined, almost any sort of method call can be handled in the desired manner.&lt;br /&gt;
&lt;br /&gt;
This article will explore the method_missing() construct in greater detail, giving both advantages and disadvantages of having this feature in the Ruby language.  We will also examine how other programming languages attempt to handle the same problem.&lt;br /&gt;
&lt;br /&gt;
==Advantages of method_missing()==&lt;br /&gt;
1. Allows for dynamically invoked methods.&lt;br /&gt;
 &lt;br /&gt;
==Disadvantages of method_missing()==&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==Alternatives to method_missing() in other programming languages==&lt;br /&gt;
&lt;br /&gt;
===Smalltalk: doesNotUnderstand===&lt;br /&gt;
&lt;br /&gt;
In many ways the inspiration for Ruby, Smalltalk is often considered one of the original truly Object-Oriented languages.  Smalltalk, much like Ruby with method_missing(), sends a message called #doesNotUnderstand&amp;lt;ref&amp;gt;http://c2.com/cgi/wiki?DoesNotUnderstand&amp;lt;/ref&amp;gt; to handle methods that are unknown.&lt;br /&gt;
&lt;br /&gt;
Essentially, when an object receives a method that it doesn't recognize, the Smalltalk runtime engine is then responsible for turning this message into an object with all necessary parameters and returning it to the sender as an exception. The sender is, at that point, responsible for handling the message and somehow dealing with the exception.  Even though Smalltalk does consider this an exception, this construct is used quite frequently to form proxy objects and can handle a wide variety of different methods and arguments.&lt;br /&gt;
&lt;br /&gt;
Consider the following code: &amp;lt;ref&amp;gt;http://www.iam.unibe.ch/~akuhn/blog/category/smalltalk/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    OrderedCollection subclass: #Group.&lt;br /&gt;
    Group &amp;gt;&amp;gt; eachRespondsTo: aSelector&lt;br /&gt;
        self allSatisfy: [ :each | each respondsTo: aSelector ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; doesNotUnderstand: aMessage&lt;br /&gt;
        (self eachRespondsTo: aMessage selector)&lt;br /&gt;
          ifTrue: [ self collect: [ :each | aMessage sendTo: each ] ]&lt;br /&gt;
          ifFalse: [ super doesNotUnderstand: aMessage ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; respondsTo: aSelector&lt;br /&gt;
      ^ (super respondsTo: aSelector) or: [ self eachRespondsTo: aSelector ]&lt;br /&gt;
&lt;br /&gt;
In this code snippet, an OrderedCollection object is created.  Should this collection class not understand any of the methods being sent to it, the doesUnderstand code will attempt to handle the message itself.  Without overriding this method, the default is for Smalltalk to open a debugger to step through the exception (defining it overrides this behavior).&lt;br /&gt;
&lt;br /&gt;
===Java: DynamicProxy===&lt;br /&gt;
&lt;br /&gt;
In Java, the ability to handle undefined methods is a bit more cumbersome, but it can still be done successfully through the use of dynamic proxy classes.  By creating this dynamic proxy, all calls will essentially be intercepted prior to invocation.  An attempt will be made to invoke the object in question and, if unable to do so, an interface will need to be defined to handle the missing method scenarios.  To give an example&amp;lt;ref&amp;gt;http://www.jroller.com/ie/entry/methodmissing_in_java&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
  public class Dynamic implements java.lang.reflect.InvocationHandler  {&lt;br /&gt;
        Object delegate;&lt;br /&gt;
        public Dynamic(Object delegate){&lt;br /&gt;
                this.delegate=delegate;&lt;br /&gt;
        }        &lt;br /&gt;
        public Object invoke(Object proxy, Method method, Object[] args) &lt;br /&gt;
                           throws Throwable {&lt;br /&gt;
                Object result = null;&lt;br /&gt;
                try {                  &lt;br /&gt;
                    result = method.invoke(delegate, args);&lt;br /&gt;
                } catch (InvocationTargetException e) {&lt;br /&gt;
                        result = &lt;br /&gt;
                  ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } catch (Exception e) {&lt;br /&gt;
                    result = &lt;br /&gt;
             ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } finally {&lt;br /&gt;
                    &lt;br /&gt;
                }&lt;br /&gt;
                if(result==delegate)&lt;br /&gt;
                        result = proxy;&lt;br /&gt;
                &lt;br /&gt;
                return result;&lt;br /&gt;
        }&lt;br /&gt;
        public static T newInstance(Object o,Class... interfaces) {&lt;br /&gt;
                return (T)java.lang.reflect.Proxy.newProxyInstance(&lt;br /&gt;
                    interfaces[0].getClassLoader(),&lt;br /&gt;
                    interfaces,&lt;br /&gt;
                    new Dynamic(o));&lt;br /&gt;
        }        &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Here, we define our Proxy class.  Note, both an Object and Method are passed in as parameters.  When attempting to invoke the method of the given Object, an exception is caught and delegated to a MethodMissing interface, which will also need to be defined.&lt;br /&gt;
&lt;br /&gt;
  public interface MethodMissing {&lt;br /&gt;
        public T methodMissing(Method method,E... args);        &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Now, we define an interface whose methods will need to be implemented in order to handle the missing objects.&lt;br /&gt;
&lt;br /&gt;
  public class Ruby implements MethodMissing{&lt;br /&gt;
        public Object methodMissing(Method method, Object... args) {&lt;br /&gt;
                System.out.println(method.getName());&lt;br /&gt;
                return this;&lt;br /&gt;
        }&lt;br /&gt;
        public static void main(String[] args){&lt;br /&gt;
                IDynamic dynamic = &lt;br /&gt;
                   Dynamic.newInstance(new Ruby(), IDynamic.class);               &lt;br /&gt;
                dynamic.meow().woof();&lt;br /&gt;
                dynamic.woof();&lt;br /&gt;
                &lt;br /&gt;
        }               &lt;br /&gt;
  }&lt;br /&gt;
  public interface IDynamic extends MethodMissing{&lt;br /&gt;
        public IDynamic woof();&lt;br /&gt;
        public IDynamic meow();&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Lastly, we create a class that attempts to utilize the MethodMissing construct.  As you can see, the Ruby class creates an implementation of the methodMissing() method, choosing to simply reflect the name of the method itself.  When the IDynamic class is created, it attempts to run several methods which are never actually defined.  Nevertheless, all of these method calls are actually intercepted by our proxy class and called as if there were no issue.&lt;br /&gt;
&lt;br /&gt;
The output of running this class would be:&lt;br /&gt;
&lt;br /&gt;
  meow&lt;br /&gt;
  woof&lt;br /&gt;
  woof&lt;br /&gt;
&lt;br /&gt;
Compared to Ruby, of course, or even Smalltalk, this is a very difficult way to handle missing methods.  Instead of having something built into the class itself, additional interfaces and wrappers are required to handle these scenarios, creating far more bulky and complex code.  Unfortunately, this is probably the price for having a statically typed language.&lt;br /&gt;
&lt;br /&gt;
===Python: __getattr__===&lt;br /&gt;
===Perl: AUTOLOAD===&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73354</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1n jp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73354"/>
		<updated>2013-02-20T20:33:32Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: /* Java: DynamicProxy */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby's method_missing(): Advantages/Disadvantages and Alternatives =&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
One of the distinguishing features of the Ruby programming language is it's ability to easily extend classes in a dynamic fashion to perform a variety of different methods depending upon the needs of the current application.  For example, should the developer want to extend a core language class, take String for example, they could easily re-open that class and add new methods dynamically to this existing class, rather than creating an entirely new class.&lt;br /&gt;
&lt;br /&gt;
Even more powerful, Ruby allows for a construct called method_missing().  By overriding this method in your class, method_missing() will attempt to handle any method calls not currently defined by the given class (or class hierarchy).  Typically, some sort of regular expression is used to determine if the method call can be redirected to an existing method based on it's naming convention (for example, a method call in a non-existent singular form could be redirected to an existing pluralized form).  If the method_missing() definition cannot determine where to redirect the method call, the default is simply to call the parent class via super().&lt;br /&gt;
&lt;br /&gt;
By having the ability to allow a class to dynamically extend itself even if a method definition never truly existed, Ruby allows for a far greater degree of flexibility than does a statically typed language such as Java, where much greater effort is involved in handing method calls that do not currently exist.  With method_missing() defined, almost any sort of method call can be handled in the desired manner.&lt;br /&gt;
&lt;br /&gt;
This article will explore the method_missing() construct in greater detail, giving both advantages and disadvantages of having this feature in the Ruby language.  We will also examine how other programming languages attempt to handle the same problem.&lt;br /&gt;
&lt;br /&gt;
==Advantages of method_missing()==&lt;br /&gt;
1. Allows for dynamically invoked methods.&lt;br /&gt;
 &lt;br /&gt;
==Disadvantages of method_missing()==&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==Alternatives to method_missing() in other programming languages==&lt;br /&gt;
&lt;br /&gt;
===Smalltalk: doesNotUnderstand===&lt;br /&gt;
&lt;br /&gt;
In many ways the inspiration for Ruby, Smalltalk is often considered one of the original truly Object-Oriented languages.  Smalltalk, much like Ruby with method_missing(), sends a message called #doesNotUnderstand&amp;lt;ref&amp;gt;http://c2.com/cgi/wiki?DoesNotUnderstand&amp;lt;/ref&amp;gt; to handle methods that are unknown.&lt;br /&gt;
&lt;br /&gt;
Essentially, when an object receives a method that it doesn't recognize, the Smalltalk runtime engine is then responsible for turning this message into an object with all necessary parameters and returning it to the sender as an exception. The sender is, at that point, responsible for handling the message and somehow dealing with the exception.  Even though Smalltalk does consider this an exception, this construct is used quite frequently to form proxy objects and can handle a wide variety of different methods and arguments.&lt;br /&gt;
&lt;br /&gt;
Consider the following code: &amp;lt;ref&amp;gt;http://www.iam.unibe.ch/~akuhn/blog/category/smalltalk/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    OrderedCollection subclass: #Group.&lt;br /&gt;
    Group &amp;gt;&amp;gt; eachRespondsTo: aSelector&lt;br /&gt;
        self allSatisfy: [ :each | each respondsTo: aSelector ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; doesNotUnderstand: aMessage&lt;br /&gt;
        (self eachRespondsTo: aMessage selector)&lt;br /&gt;
          ifTrue: [ self collect: [ :each | aMessage sendTo: each ] ]&lt;br /&gt;
          ifFalse: [ super doesNotUnderstand: aMessage ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; respondsTo: aSelector&lt;br /&gt;
      ^ (super respondsTo: aSelector) or: [ self eachRespondsTo: aSelector ]&lt;br /&gt;
&lt;br /&gt;
In this code snippet, an OrderedCollection object is created.  Should this collection class not understand any of the methods being sent to it, the doesUnderstand code will attempt to handle the message itself.  Without overriding this method, the default is for Smalltalk to open a debugger to step through the exception (defining it overrides this behavior).&lt;br /&gt;
&lt;br /&gt;
===Java: DynamicProxy===&lt;br /&gt;
&lt;br /&gt;
In Java, the ability to handle undefined methods is a bit more cumbersome, but it can still be done successfully through the use of dynamic proxy classes.  By creating this dynamic proxy, all calls will essentially be intercepted prior to invocation.  An attempt will be made to invoke the object in question and, if unable to do so, an interface will need to be defined to handle the missing method scenarios.  To give an example&amp;lt;ref&amp;gt;http://www.jroller.com/ie/entry/methodmissing_in_java&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
  public class Dynamic implements java.lang.reflect.InvocationHandler  {&lt;br /&gt;
        Object delegate;&lt;br /&gt;
        public Dynamic(Object delegate){&lt;br /&gt;
                this.delegate=delegate;&lt;br /&gt;
        }        &lt;br /&gt;
        public Object invoke(Object proxy, Method method, Object[] args) &lt;br /&gt;
                           throws Throwable {&lt;br /&gt;
                Object result = null;&lt;br /&gt;
                try {                  &lt;br /&gt;
                    result = method.invoke(delegate, args);&lt;br /&gt;
                } catch (InvocationTargetException e) {&lt;br /&gt;
                        result = &lt;br /&gt;
                  ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } catch (Exception e) {&lt;br /&gt;
                    result = &lt;br /&gt;
             ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } finally {&lt;br /&gt;
                    &lt;br /&gt;
                }&lt;br /&gt;
                if(result==delegate)&lt;br /&gt;
                        result = proxy;&lt;br /&gt;
                &lt;br /&gt;
                return result;&lt;br /&gt;
        }&lt;br /&gt;
        public static T newInstance(Object o,Class... interfaces) {&lt;br /&gt;
                return (T)java.lang.reflect.Proxy.newProxyInstance(&lt;br /&gt;
                    interfaces[0].getClassLoader(),&lt;br /&gt;
                    interfaces,&lt;br /&gt;
                    new Dynamic(o));&lt;br /&gt;
        }        &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Here, we define our Proxy class.  Note, both an Object and Method are passed in as parameters.  When attempting to invoke the method of the given Object, an exception is caught and delegated to a MethodMissing interface, which will also need to be defined.&lt;br /&gt;
&lt;br /&gt;
  public interface MethodMissing {&lt;br /&gt;
        public T methodMissing(Method method,E... args);        &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Now, we define an interface whose methods will need to be implemented in order to handle the missing objects.&lt;br /&gt;
&lt;br /&gt;
  public class Ruby implements MethodMissing{&lt;br /&gt;
        public Object methodMissing(Method method, Object... args) {&lt;br /&gt;
                System.out.println(method.getName());&lt;br /&gt;
                return this;&lt;br /&gt;
        }&lt;br /&gt;
        public static void main(String[] args){&lt;br /&gt;
                IDynamic dynamic = &lt;br /&gt;
                   Dynamic.newInstance(new Ruby(), IDynamic.class);               &lt;br /&gt;
                dynamic.meow().woof();&lt;br /&gt;
                dynamic.woof();&lt;br /&gt;
                &lt;br /&gt;
        }               &lt;br /&gt;
  }&lt;br /&gt;
  public interface IDynamic extends MethodMissing{&lt;br /&gt;
        public IDynamic woof();&lt;br /&gt;
        public IDynamic meow();&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Lastly, we create a class that attempts to utilize the MethodMissing construct.  As you can see, the Ruby class creates an implementation of the methodMissing() method, choosing to simply reflect the name of the method itself.  When the IDynamic class is created, it attempts to run several methods which are never actually defined.  Nevertheless, all of these method calls are actually intercepted by our proxy class and called as if there were no issue.&lt;br /&gt;
&lt;br /&gt;
The output of running this class would be:&lt;br /&gt;
&lt;br /&gt;
  meow&lt;br /&gt;
  woof&lt;br /&gt;
  woof&lt;br /&gt;
&lt;br /&gt;
===Python: __getattr__===&lt;br /&gt;
===Perl: AUTOLOAD===&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73353</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1n jp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73353"/>
		<updated>2013-02-20T20:28:37Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: /* Java: DynamicProxy */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby's method_missing(): Advantages/Disadvantages and Alternatives =&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
One of the distinguishing features of the Ruby programming language is it's ability to easily extend classes in a dynamic fashion to perform a variety of different methods depending upon the needs of the current application.  For example, should the developer want to extend a core language class, take String for example, they could easily re-open that class and add new methods dynamically to this existing class, rather than creating an entirely new class.&lt;br /&gt;
&lt;br /&gt;
Even more powerful, Ruby allows for a construct called method_missing().  By overriding this method in your class, method_missing() will attempt to handle any method calls not currently defined by the given class (or class hierarchy).  Typically, some sort of regular expression is used to determine if the method call can be redirected to an existing method based on it's naming convention (for example, a method call in a non-existent singular form could be redirected to an existing pluralized form).  If the method_missing() definition cannot determine where to redirect the method call, the default is simply to call the parent class via super().&lt;br /&gt;
&lt;br /&gt;
By having the ability to allow a class to dynamically extend itself even if a method definition never truly existed, Ruby allows for a far greater degree of flexibility than does a statically typed language such as Java, where much greater effort is involved in handing method calls that do not currently exist.  With method_missing() defined, almost any sort of method call can be handled in the desired manner.&lt;br /&gt;
&lt;br /&gt;
This article will explore the method_missing() construct in greater detail, giving both advantages and disadvantages of having this feature in the Ruby language.  We will also examine how other programming languages attempt to handle the same problem.&lt;br /&gt;
&lt;br /&gt;
==Advantages of method_missing()==&lt;br /&gt;
1. Allows for dynamically invoked methods.&lt;br /&gt;
 &lt;br /&gt;
==Disadvantages of method_missing()==&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==Alternatives to method_missing() in other programming languages==&lt;br /&gt;
&lt;br /&gt;
===Smalltalk: doesNotUnderstand===&lt;br /&gt;
&lt;br /&gt;
In many ways the inspiration for Ruby, Smalltalk is often considered one of the original truly Object-Oriented languages.  Smalltalk, much like Ruby with method_missing(), sends a message called #doesNotUnderstand&amp;lt;ref&amp;gt;http://c2.com/cgi/wiki?DoesNotUnderstand&amp;lt;/ref&amp;gt; to handle methods that are unknown.&lt;br /&gt;
&lt;br /&gt;
Essentially, when an object receives a method that it doesn't recognize, the Smalltalk runtime engine is then responsible for turning this message into an object with all necessary parameters and returning it to the sender as an exception. The sender is, at that point, responsible for handling the message and somehow dealing with the exception.  Even though Smalltalk does consider this an exception, this construct is used quite frequently to form proxy objects and can handle a wide variety of different methods and arguments.&lt;br /&gt;
&lt;br /&gt;
Consider the following code: &amp;lt;ref&amp;gt;http://www.iam.unibe.ch/~akuhn/blog/category/smalltalk/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    OrderedCollection subclass: #Group.&lt;br /&gt;
    Group &amp;gt;&amp;gt; eachRespondsTo: aSelector&lt;br /&gt;
        self allSatisfy: [ :each | each respondsTo: aSelector ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; doesNotUnderstand: aMessage&lt;br /&gt;
        (self eachRespondsTo: aMessage selector)&lt;br /&gt;
          ifTrue: [ self collect: [ :each | aMessage sendTo: each ] ]&lt;br /&gt;
          ifFalse: [ super doesNotUnderstand: aMessage ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; respondsTo: aSelector&lt;br /&gt;
      ^ (super respondsTo: aSelector) or: [ self eachRespondsTo: aSelector ]&lt;br /&gt;
&lt;br /&gt;
In this code snippet, an OrderedCollection object is created.  Should this collection class not understand any of the methods being sent to it, the doesUnderstand code will attempt to handle the message itself.  Without overriding this method, the default is for Smalltalk to open a debugger to step through the exception (defining it overrides this behavior).&lt;br /&gt;
&lt;br /&gt;
===Java: DynamicProxy===&lt;br /&gt;
&lt;br /&gt;
In Java, the ability to handle undefined methods is a bit more cumbersome, but it can still be done successfully through the use of dynamic proxy classes.  By creating this dynamic proxy, all calls will essentially be intercepted prior to invocation.  An attempt will be made to invoke the object in question and, if unable to do so, an interface will need to be defined to handle the missing method scenarios.  To give an example&amp;lt;ref&amp;gt;http://www.jroller.com/ie/entry/methodmissing_in_java&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
  public class Dynamic implements java.lang.reflect.InvocationHandler  {&lt;br /&gt;
        Object delegate;&lt;br /&gt;
        public Dynamic(Object delegate){&lt;br /&gt;
                this.delegate=delegate;&lt;br /&gt;
        }        &lt;br /&gt;
        public Object invoke(Object proxy, Method method, Object[] args) &lt;br /&gt;
                           throws Throwable {&lt;br /&gt;
                Object result = null;&lt;br /&gt;
                try {                  &lt;br /&gt;
                    result = method.invoke(delegate, args);&lt;br /&gt;
                } catch (InvocationTargetException e) {&lt;br /&gt;
                        result = &lt;br /&gt;
                  ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } catch (Exception e) {&lt;br /&gt;
                    result = &lt;br /&gt;
             ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } finally {&lt;br /&gt;
                    &lt;br /&gt;
                }&lt;br /&gt;
                if(result==delegate)&lt;br /&gt;
                        result = proxy;&lt;br /&gt;
                &lt;br /&gt;
                return result;&lt;br /&gt;
        }&lt;br /&gt;
        public static T newInstance(Object o,Class... interfaces) {&lt;br /&gt;
                return (T)java.lang.reflect.Proxy.newProxyInstance(&lt;br /&gt;
                    interfaces[0].getClassLoader(),&lt;br /&gt;
                    interfaces,&lt;br /&gt;
                    new Dynamic(o));&lt;br /&gt;
        }        &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Here, we define our Proxy class.  Note, both an Object and Method are passed in as parameters.  When attempting to invoke the method of the given Object, an exception is caught and delegated to a MethodMissing interface, which will also need to be defined.&lt;br /&gt;
&lt;br /&gt;
  public interface MethodMissing {&lt;br /&gt;
        public T methodMissing(Method method,E... args);        &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  public class Ruby implements MethodMissing{&lt;br /&gt;
        public Object methodMissing(Method method, Object... args) {&lt;br /&gt;
                System.out.println(method.getName());&lt;br /&gt;
                return this;&lt;br /&gt;
        }&lt;br /&gt;
        public static void main(String[] args){&lt;br /&gt;
                IDynamic dynamic = &lt;br /&gt;
                   Dynamic.newInstance(new Ruby(), IDynamic.class);               &lt;br /&gt;
                dynamic.meow().woof();&lt;br /&gt;
                dynamic.woof();&lt;br /&gt;
                &lt;br /&gt;
        }               &lt;br /&gt;
  }&lt;br /&gt;
  public interface IDynamic extends MethodMissing{&lt;br /&gt;
        public IDynamic woof();&lt;br /&gt;
        public IDynamic meow();&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
===Python: __getattr__===&lt;br /&gt;
===Perl: AUTOLOAD===&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73352</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1n jp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73352"/>
		<updated>2013-02-20T20:25:58Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: /* Java: DynamicProxy */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby's method_missing(): Advantages/Disadvantages and Alternatives =&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
One of the distinguishing features of the Ruby programming language is it's ability to easily extend classes in a dynamic fashion to perform a variety of different methods depending upon the needs of the current application.  For example, should the developer want to extend a core language class, take String for example, they could easily re-open that class and add new methods dynamically to this existing class, rather than creating an entirely new class.&lt;br /&gt;
&lt;br /&gt;
Even more powerful, Ruby allows for a construct called method_missing().  By overriding this method in your class, method_missing() will attempt to handle any method calls not currently defined by the given class (or class hierarchy).  Typically, some sort of regular expression is used to determine if the method call can be redirected to an existing method based on it's naming convention (for example, a method call in a non-existent singular form could be redirected to an existing pluralized form).  If the method_missing() definition cannot determine where to redirect the method call, the default is simply to call the parent class via super().&lt;br /&gt;
&lt;br /&gt;
By having the ability to allow a class to dynamically extend itself even if a method definition never truly existed, Ruby allows for a far greater degree of flexibility than does a statically typed language such as Java, where much greater effort is involved in handing method calls that do not currently exist.  With method_missing() defined, almost any sort of method call can be handled in the desired manner.&lt;br /&gt;
&lt;br /&gt;
This article will explore the method_missing() construct in greater detail, giving both advantages and disadvantages of having this feature in the Ruby language.  We will also examine how other programming languages attempt to handle the same problem.&lt;br /&gt;
&lt;br /&gt;
==Advantages of method_missing()==&lt;br /&gt;
1. Allows for dynamically invoked methods.&lt;br /&gt;
 &lt;br /&gt;
==Disadvantages of method_missing()==&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==Alternatives to method_missing() in other programming languages==&lt;br /&gt;
&lt;br /&gt;
===Smalltalk: doesNotUnderstand===&lt;br /&gt;
&lt;br /&gt;
In many ways the inspiration for Ruby, Smalltalk is often considered one of the original truly Object-Oriented languages.  Smalltalk, much like Ruby with method_missing(), sends a message called #doesNotUnderstand&amp;lt;ref&amp;gt;http://c2.com/cgi/wiki?DoesNotUnderstand&amp;lt;/ref&amp;gt; to handle methods that are unknown.&lt;br /&gt;
&lt;br /&gt;
Essentially, when an object receives a method that it doesn't recognize, the Smalltalk runtime engine is then responsible for turning this message into an object with all necessary parameters and returning it to the sender as an exception. The sender is, at that point, responsible for handling the message and somehow dealing with the exception.  Even though Smalltalk does consider this an exception, this construct is used quite frequently to form proxy objects and can handle a wide variety of different methods and arguments.&lt;br /&gt;
&lt;br /&gt;
Consider the following code: &amp;lt;ref&amp;gt;http://www.iam.unibe.ch/~akuhn/blog/category/smalltalk/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    OrderedCollection subclass: #Group.&lt;br /&gt;
    Group &amp;gt;&amp;gt; eachRespondsTo: aSelector&lt;br /&gt;
        self allSatisfy: [ :each | each respondsTo: aSelector ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; doesNotUnderstand: aMessage&lt;br /&gt;
        (self eachRespondsTo: aMessage selector)&lt;br /&gt;
          ifTrue: [ self collect: [ :each | aMessage sendTo: each ] ]&lt;br /&gt;
          ifFalse: [ super doesNotUnderstand: aMessage ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; respondsTo: aSelector&lt;br /&gt;
      ^ (super respondsTo: aSelector) or: [ self eachRespondsTo: aSelector ]&lt;br /&gt;
&lt;br /&gt;
In this code snippet, an OrderedCollection object is created.  Should this collection class not understand any of the methods being sent to it, the doesUnderstand code will attempt to handle the message itself.  Without overriding this method, the default is for Smalltalk to open a debugger to step through the exception (defining it overrides this behavior).&lt;br /&gt;
&lt;br /&gt;
===Java: DynamicProxy===&lt;br /&gt;
&lt;br /&gt;
In Java, the ability to handle undefined methods is a bit more cumbersome, but it can still be done successfully through the use of dynamic proxy classes.&amp;lt;ref&amp;gt;http://www.jroller.com/ie/entry/methodmissing_in_java&amp;lt;/ref&amp;gt;  By creating this dynamic proxy, all calls will essentially be intercepted prior to invocation.  An attempt will be made to invoke the object in question and, if unable to do so, an interface will need to be defined to handle the missing method scenarios.  To give an example:&lt;br /&gt;
&lt;br /&gt;
  public class Dynamic implements java.lang.reflect.InvocationHandler  {&lt;br /&gt;
        Object delegate;&lt;br /&gt;
        public Dynamic(Object delegate){&lt;br /&gt;
                this.delegate=delegate;&lt;br /&gt;
        }        &lt;br /&gt;
        public Object invoke(Object proxy, Method method, Object[] args) &lt;br /&gt;
                           throws Throwable {&lt;br /&gt;
                Object result = null;&lt;br /&gt;
                try {                  &lt;br /&gt;
                    result = method.invoke(delegate, args);&lt;br /&gt;
                } catch (InvocationTargetException e) {&lt;br /&gt;
                        result = &lt;br /&gt;
                  ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } catch (Exception e) {&lt;br /&gt;
                    result = &lt;br /&gt;
             ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } finally {&lt;br /&gt;
                    &lt;br /&gt;
                }&lt;br /&gt;
                if(result==delegate)&lt;br /&gt;
                        result = proxy;&lt;br /&gt;
                &lt;br /&gt;
                return result;&lt;br /&gt;
        }&lt;br /&gt;
        public static T newInstance(Object o,Class... interfaces) {&lt;br /&gt;
                return (T)java.lang.reflect.Proxy.newProxyInstance(&lt;br /&gt;
                    interfaces[0].getClassLoader(),&lt;br /&gt;
                    interfaces,&lt;br /&gt;
                    new Dynamic(o));&lt;br /&gt;
        }        &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Here, we define our Proxy class.  Note, both an Object and Method are passed in as parameters.  When attempting to invoke the method of the given Object, an exception is caught and delegated to a MethodMissing interface, which will also need to be defined.&lt;br /&gt;
&lt;br /&gt;
  public interface MethodMissing {&lt;br /&gt;
        public T methodMissing(Method method,E... args);        &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  public class Ruby implements MethodMissing{&lt;br /&gt;
        public Object methodMissing(Method method, Object... args) {&lt;br /&gt;
                System.out.println(method.getName());&lt;br /&gt;
                return this;&lt;br /&gt;
        }&lt;br /&gt;
        public static void main(String[] args){&lt;br /&gt;
                IDynamic dynamic = &lt;br /&gt;
                   Dynamic.newInstance(new Ruby(), IDynamic.class);               &lt;br /&gt;
                dynamic.meow().woof();&lt;br /&gt;
                dynamic.woof();&lt;br /&gt;
                &lt;br /&gt;
        }               &lt;br /&gt;
  }&lt;br /&gt;
  public interface IDynamic extends MethodMissing{&lt;br /&gt;
        public IDynamic woof();&lt;br /&gt;
        public IDynamic meow();&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
===Python: __getattr__===&lt;br /&gt;
===Perl: AUTOLOAD===&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73351</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1n jp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73351"/>
		<updated>2013-02-20T20:25:39Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: /* Java: DynamicProxy */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby's method_missing(): Advantages/Disadvantages and Alternatives =&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
One of the distinguishing features of the Ruby programming language is it's ability to easily extend classes in a dynamic fashion to perform a variety of different methods depending upon the needs of the current application.  For example, should the developer want to extend a core language class, take String for example, they could easily re-open that class and add new methods dynamically to this existing class, rather than creating an entirely new class.&lt;br /&gt;
&lt;br /&gt;
Even more powerful, Ruby allows for a construct called method_missing().  By overriding this method in your class, method_missing() will attempt to handle any method calls not currently defined by the given class (or class hierarchy).  Typically, some sort of regular expression is used to determine if the method call can be redirected to an existing method based on it's naming convention (for example, a method call in a non-existent singular form could be redirected to an existing pluralized form).  If the method_missing() definition cannot determine where to redirect the method call, the default is simply to call the parent class via super().&lt;br /&gt;
&lt;br /&gt;
By having the ability to allow a class to dynamically extend itself even if a method definition never truly existed, Ruby allows for a far greater degree of flexibility than does a statically typed language such as Java, where much greater effort is involved in handing method calls that do not currently exist.  With method_missing() defined, almost any sort of method call can be handled in the desired manner.&lt;br /&gt;
&lt;br /&gt;
This article will explore the method_missing() construct in greater detail, giving both advantages and disadvantages of having this feature in the Ruby language.  We will also examine how other programming languages attempt to handle the same problem.&lt;br /&gt;
&lt;br /&gt;
==Advantages of method_missing()==&lt;br /&gt;
1. Allows for dynamically invoked methods.&lt;br /&gt;
 &lt;br /&gt;
==Disadvantages of method_missing()==&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==Alternatives to method_missing() in other programming languages==&lt;br /&gt;
&lt;br /&gt;
===Smalltalk: doesNotUnderstand===&lt;br /&gt;
&lt;br /&gt;
In many ways the inspiration for Ruby, Smalltalk is often considered one of the original truly Object-Oriented languages.  Smalltalk, much like Ruby with method_missing(), sends a message called #doesNotUnderstand&amp;lt;ref&amp;gt;http://c2.com/cgi/wiki?DoesNotUnderstand&amp;lt;/ref&amp;gt; to handle methods that are unknown.&lt;br /&gt;
&lt;br /&gt;
Essentially, when an object receives a method that it doesn't recognize, the Smalltalk runtime engine is then responsible for turning this message into an object with all necessary parameters and returning it to the sender as an exception. The sender is, at that point, responsible for handling the message and somehow dealing with the exception.  Even though Smalltalk does consider this an exception, this construct is used quite frequently to form proxy objects and can handle a wide variety of different methods and arguments.&lt;br /&gt;
&lt;br /&gt;
Consider the following code: &amp;lt;ref&amp;gt;http://www.iam.unibe.ch/~akuhn/blog/category/smalltalk/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    OrderedCollection subclass: #Group.&lt;br /&gt;
    Group &amp;gt;&amp;gt; eachRespondsTo: aSelector&lt;br /&gt;
        self allSatisfy: [ :each | each respondsTo: aSelector ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; doesNotUnderstand: aMessage&lt;br /&gt;
        (self eachRespondsTo: aMessage selector)&lt;br /&gt;
          ifTrue: [ self collect: [ :each | aMessage sendTo: each ] ]&lt;br /&gt;
          ifFalse: [ super doesNotUnderstand: aMessage ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; respondsTo: aSelector&lt;br /&gt;
      ^ (super respondsTo: aSelector) or: [ self eachRespondsTo: aSelector ]&lt;br /&gt;
&lt;br /&gt;
In this code snippet, an OrderedCollection object is created.  Should this collection class not understand any of the methods being sent to it, the doesUnderstand code will attempt to handle the message itself.  Without overriding this method, the default is for Smalltalk to open a debugger to step through the exception (defining it overrides this behavior).&lt;br /&gt;
&lt;br /&gt;
===Java: DynamicProxy===&lt;br /&gt;
&lt;br /&gt;
In Java, the ability to handle undefined methods is a bit more cumbersome, but it can still be done successfully through the use of dynamic proxy classes.&amp;lt;ref&amp;gt;http://www.jroller.com/ie/entry/methodmissing_in_java&amp;lt;/ref&amp;gt;  By creating this dynamic proxy, all calls will essentially be intercepted prior to invocation.  An attempt will be made to invoke the object in question and, if unable to do so, an interface will need to be defined to handle the missing method scenarios.  To give an example:&lt;br /&gt;
&lt;br /&gt;
  public class Dynamic implements java.lang.reflect.InvocationHandler  {&lt;br /&gt;
        Object delegate;&lt;br /&gt;
        public Dynamic(Object delegate){&lt;br /&gt;
                this.delegate=delegate;&lt;br /&gt;
        }        &lt;br /&gt;
        public Object invoke(Object proxy, Method method, Object[] args) &lt;br /&gt;
                           throws Throwable {&lt;br /&gt;
                Object result = null;&lt;br /&gt;
                try {                  &lt;br /&gt;
                    result = method.invoke(delegate, args);&lt;br /&gt;
                } catch (InvocationTargetException e) {&lt;br /&gt;
                        result = &lt;br /&gt;
                  ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } catch (Exception e) {&lt;br /&gt;
                    result = &lt;br /&gt;
             ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } finally {&lt;br /&gt;
                    &lt;br /&gt;
                }&lt;br /&gt;
                if(result==delegate)&lt;br /&gt;
                        result = proxy;&lt;br /&gt;
                &lt;br /&gt;
                return result;&lt;br /&gt;
        }&lt;br /&gt;
        public static T newInstance(Object o,Class... interfaces) {&lt;br /&gt;
                return (T)java.lang.reflect.Proxy.newProxyInstance(&lt;br /&gt;
                    interfaces[0].getClassLoader(),&lt;br /&gt;
                    interfaces,&lt;br /&gt;
                    new Dynamic(o));&lt;br /&gt;
        }        &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Here, we define our Proxy class.  Note, both an Object and Method are passed in as parameters.  When attempting to invoke the method of the given Object, an exception is caught and delegated to a MethodMissing interface, which will also need to be defined&amp;lt;ref&amp;gt;http://www.jroller.com/ie/entry/methodmissing_in_java&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
  public interface MethodMissing {&lt;br /&gt;
        public T methodMissing(Method method,E... args);        &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  public class Ruby implements MethodMissing{&lt;br /&gt;
        public Object methodMissing(Method method, Object... args) {&lt;br /&gt;
                System.out.println(method.getName());&lt;br /&gt;
                return this;&lt;br /&gt;
        }&lt;br /&gt;
        public static void main(String[] args){&lt;br /&gt;
                IDynamic dynamic = &lt;br /&gt;
                   Dynamic.newInstance(new Ruby(), IDynamic.class);               &lt;br /&gt;
                dynamic.meow().woof();&lt;br /&gt;
                dynamic.woof();&lt;br /&gt;
                &lt;br /&gt;
        }               &lt;br /&gt;
  }&lt;br /&gt;
  public interface IDynamic extends MethodMissing{&lt;br /&gt;
        public IDynamic woof();&lt;br /&gt;
        public IDynamic meow();&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
===Python: __getattr__===&lt;br /&gt;
===Perl: AUTOLOAD===&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73350</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1n jp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73350"/>
		<updated>2013-02-20T20:24:31Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: /* Java: DynamicProxy */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby's method_missing(): Advantages/Disadvantages and Alternatives =&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
One of the distinguishing features of the Ruby programming language is it's ability to easily extend classes in a dynamic fashion to perform a variety of different methods depending upon the needs of the current application.  For example, should the developer want to extend a core language class, take String for example, they could easily re-open that class and add new methods dynamically to this existing class, rather than creating an entirely new class.&lt;br /&gt;
&lt;br /&gt;
Even more powerful, Ruby allows for a construct called method_missing().  By overriding this method in your class, method_missing() will attempt to handle any method calls not currently defined by the given class (or class hierarchy).  Typically, some sort of regular expression is used to determine if the method call can be redirected to an existing method based on it's naming convention (for example, a method call in a non-existent singular form could be redirected to an existing pluralized form).  If the method_missing() definition cannot determine where to redirect the method call, the default is simply to call the parent class via super().&lt;br /&gt;
&lt;br /&gt;
By having the ability to allow a class to dynamically extend itself even if a method definition never truly existed, Ruby allows for a far greater degree of flexibility than does a statically typed language such as Java, where much greater effort is involved in handing method calls that do not currently exist.  With method_missing() defined, almost any sort of method call can be handled in the desired manner.&lt;br /&gt;
&lt;br /&gt;
This article will explore the method_missing() construct in greater detail, giving both advantages and disadvantages of having this feature in the Ruby language.  We will also examine how other programming languages attempt to handle the same problem.&lt;br /&gt;
&lt;br /&gt;
==Advantages of method_missing()==&lt;br /&gt;
1. Allows for dynamically invoked methods.&lt;br /&gt;
 &lt;br /&gt;
==Disadvantages of method_missing()==&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==Alternatives to method_missing() in other programming languages==&lt;br /&gt;
&lt;br /&gt;
===Smalltalk: doesNotUnderstand===&lt;br /&gt;
&lt;br /&gt;
In many ways the inspiration for Ruby, Smalltalk is often considered one of the original truly Object-Oriented languages.  Smalltalk, much like Ruby with method_missing(), sends a message called #doesNotUnderstand&amp;lt;ref&amp;gt;http://c2.com/cgi/wiki?DoesNotUnderstand&amp;lt;/ref&amp;gt; to handle methods that are unknown.&lt;br /&gt;
&lt;br /&gt;
Essentially, when an object receives a method that it doesn't recognize, the Smalltalk runtime engine is then responsible for turning this message into an object with all necessary parameters and returning it to the sender as an exception. The sender is, at that point, responsible for handling the message and somehow dealing with the exception.  Even though Smalltalk does consider this an exception, this construct is used quite frequently to form proxy objects and can handle a wide variety of different methods and arguments.&lt;br /&gt;
&lt;br /&gt;
Consider the following code: &amp;lt;ref&amp;gt;http://www.iam.unibe.ch/~akuhn/blog/category/smalltalk/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    OrderedCollection subclass: #Group.&lt;br /&gt;
    Group &amp;gt;&amp;gt; eachRespondsTo: aSelector&lt;br /&gt;
        self allSatisfy: [ :each | each respondsTo: aSelector ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; doesNotUnderstand: aMessage&lt;br /&gt;
        (self eachRespondsTo: aMessage selector)&lt;br /&gt;
          ifTrue: [ self collect: [ :each | aMessage sendTo: each ] ]&lt;br /&gt;
          ifFalse: [ super doesNotUnderstand: aMessage ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; respondsTo: aSelector&lt;br /&gt;
      ^ (super respondsTo: aSelector) or: [ self eachRespondsTo: aSelector ]&lt;br /&gt;
&lt;br /&gt;
In this code snippet, an OrderedCollection object is created.  Should this collection class not understand any of the methods being sent to it, the doesUnderstand code will attempt to handle the message itself.  Without overriding this method, the default is for Smalltalk to open a debugger to step through the exception (defining it overrides this behavior).&lt;br /&gt;
&lt;br /&gt;
===Java: DynamicProxy===&lt;br /&gt;
&lt;br /&gt;
In Java, the ability to handle undefined methods is a bit more cumbersome, but it can still be done successfully through the use of dynamic proxy classes.&amp;lt;ref&amp;gt;http://www.jroller.com/ie/entry/methodmissing_in_java&amp;lt;/ref&amp;gt;  By creating this dynamic proxy, all calls will essentially be intercepted prior to invocation.  An attempt will be made to invoke the object in question and, if unable to do so, an interface will need to be defined to handle the missing method scenarios.  To give an example:&lt;br /&gt;
&lt;br /&gt;
  public class Dynamic implements java.lang.reflect.InvocationHandler  {&lt;br /&gt;
        Object delegate;&lt;br /&gt;
        public Dynamic(Object delegate){&lt;br /&gt;
                this.delegate=delegate;&lt;br /&gt;
        }        &lt;br /&gt;
        public Object invoke(Object proxy, Method method, Object[] args) &lt;br /&gt;
                           throws Throwable {&lt;br /&gt;
                Object result = null;&lt;br /&gt;
                try {                  &lt;br /&gt;
                    result = method.invoke(delegate, args);&lt;br /&gt;
                } catch (InvocationTargetException e) {&lt;br /&gt;
                        result = &lt;br /&gt;
                  ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } catch (Exception e) {&lt;br /&gt;
                    result = &lt;br /&gt;
             ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } finally {&lt;br /&gt;
                    &lt;br /&gt;
                }&lt;br /&gt;
                if(result==delegate)&lt;br /&gt;
                        result = proxy;&lt;br /&gt;
                &lt;br /&gt;
                return result;&lt;br /&gt;
        }&lt;br /&gt;
        public static T newInstance(Object o,Class... interfaces) {&lt;br /&gt;
                return (T)java.lang.reflect.Proxy.newProxyInstance(&lt;br /&gt;
                    interfaces[0].getClassLoader(),&lt;br /&gt;
                    interfaces,&lt;br /&gt;
                    new Dynamic(o));&lt;br /&gt;
        }        &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Here, we define our Proxy class.  Note, both an Object and Method are passed in as parameters.  When attempting to invoke the method of the given Object, an exception is caught and delegated to a MethodMissing interface, which will also need to be defined.&lt;br /&gt;
&lt;br /&gt;
  public interface MethodMissing {&lt;br /&gt;
        public T methodMissing(Method method,E... args);        &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  public class Ruby implements MethodMissing{&lt;br /&gt;
        public Object methodMissing(Method method, Object... args) {&lt;br /&gt;
                System.out.println(method.getName());&lt;br /&gt;
                return this;&lt;br /&gt;
        }&lt;br /&gt;
        public static void main(String[] args){&lt;br /&gt;
                IDynamic dynamic = &lt;br /&gt;
                   Dynamic.newInstance(new Ruby(), IDynamic.class);               &lt;br /&gt;
                dynamic.meow().woof();&lt;br /&gt;
                dynamic.woof();&lt;br /&gt;
                &lt;br /&gt;
        }               &lt;br /&gt;
  }&lt;br /&gt;
  public interface IDynamic extends MethodMissing{&lt;br /&gt;
        public IDynamic woof();&lt;br /&gt;
        public IDynamic meow();&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
===Python: __getattr__===&lt;br /&gt;
===Perl: AUTOLOAD===&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73349</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1n jp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73349"/>
		<updated>2013-02-20T20:18:02Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: /* Java: DynamicProxy */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby's method_missing(): Advantages/Disadvantages and Alternatives =&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
One of the distinguishing features of the Ruby programming language is it's ability to easily extend classes in a dynamic fashion to perform a variety of different methods depending upon the needs of the current application.  For example, should the developer want to extend a core language class, take String for example, they could easily re-open that class and add new methods dynamically to this existing class, rather than creating an entirely new class.&lt;br /&gt;
&lt;br /&gt;
Even more powerful, Ruby allows for a construct called method_missing().  By overriding this method in your class, method_missing() will attempt to handle any method calls not currently defined by the given class (or class hierarchy).  Typically, some sort of regular expression is used to determine if the method call can be redirected to an existing method based on it's naming convention (for example, a method call in a non-existent singular form could be redirected to an existing pluralized form).  If the method_missing() definition cannot determine where to redirect the method call, the default is simply to call the parent class via super().&lt;br /&gt;
&lt;br /&gt;
By having the ability to allow a class to dynamically extend itself even if a method definition never truly existed, Ruby allows for a far greater degree of flexibility than does a statically typed language such as Java, where much greater effort is involved in handing method calls that do not currently exist.  With method_missing() defined, almost any sort of method call can be handled in the desired manner.&lt;br /&gt;
&lt;br /&gt;
This article will explore the method_missing() construct in greater detail, giving both advantages and disadvantages of having this feature in the Ruby language.  We will also examine how other programming languages attempt to handle the same problem.&lt;br /&gt;
&lt;br /&gt;
==Advantages of method_missing()==&lt;br /&gt;
1. Allows for dynamically invoked methods.&lt;br /&gt;
 &lt;br /&gt;
==Disadvantages of method_missing()==&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==Alternatives to method_missing() in other programming languages==&lt;br /&gt;
&lt;br /&gt;
===Smalltalk: doesNotUnderstand===&lt;br /&gt;
&lt;br /&gt;
In many ways the inspiration for Ruby, Smalltalk is often considered one of the original truly Object-Oriented languages.  Smalltalk, much like Ruby with method_missing(), sends a message called #doesNotUnderstand&amp;lt;ref&amp;gt;http://c2.com/cgi/wiki?DoesNotUnderstand&amp;lt;/ref&amp;gt; to handle methods that are unknown.&lt;br /&gt;
&lt;br /&gt;
Essentially, when an object receives a method that it doesn't recognize, the Smalltalk runtime engine is then responsible for turning this message into an object with all necessary parameters and returning it to the sender as an exception. The sender is, at that point, responsible for handling the message and somehow dealing with the exception.  Even though Smalltalk does consider this an exception, this construct is used quite frequently to form proxy objects and can handle a wide variety of different methods and arguments.&lt;br /&gt;
&lt;br /&gt;
Consider the following code: &amp;lt;ref&amp;gt;http://www.iam.unibe.ch/~akuhn/blog/category/smalltalk/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    OrderedCollection subclass: #Group.&lt;br /&gt;
    Group &amp;gt;&amp;gt; eachRespondsTo: aSelector&lt;br /&gt;
        self allSatisfy: [ :each | each respondsTo: aSelector ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; doesNotUnderstand: aMessage&lt;br /&gt;
        (self eachRespondsTo: aMessage selector)&lt;br /&gt;
          ifTrue: [ self collect: [ :each | aMessage sendTo: each ] ]&lt;br /&gt;
          ifFalse: [ super doesNotUnderstand: aMessage ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; respondsTo: aSelector&lt;br /&gt;
      ^ (super respondsTo: aSelector) or: [ self eachRespondsTo: aSelector ]&lt;br /&gt;
&lt;br /&gt;
In this code snippet, an OrderedCollection object is created.  Should this collection class not understand any of the methods being sent to it, the doesUnderstand code will attempt to handle the message itself.  Without overriding this method, the default is for Smalltalk to open a debugger to step through the exception (defining it overrides this behavior).&lt;br /&gt;
&lt;br /&gt;
===Java: DynamicProxy===&lt;br /&gt;
&lt;br /&gt;
In Java, the ability to handle undefined methods is a bit more cumbersome, but it can still be done successfully through the use of dynamic proxy classes.&amp;lt;ref&amp;gt;http://www.jroller.com/ie/entry/methodmissing_in_java&amp;lt;/ref&amp;gt;  By creating this dynamic proxy, all calls will essentially be intercepted prior to invocation.  An attempt will be made to invoke the object in question and, if unable to do so, an interface will need to be defined to handle the missing method scenarios.  To give an example:&lt;br /&gt;
&lt;br /&gt;
  public class Dynamic implements java.lang.reflect.InvocationHandler  {&lt;br /&gt;
        Object delegate;&lt;br /&gt;
        public Dynamic(Object delegate){&lt;br /&gt;
                this.delegate=delegate;&lt;br /&gt;
        }        &lt;br /&gt;
        public Object invoke(Object proxy, Method method, Object[] args) &lt;br /&gt;
                           throws Throwable {&lt;br /&gt;
                Object result = null;&lt;br /&gt;
                try {                  &lt;br /&gt;
                    result = method.invoke(delegate, args);&lt;br /&gt;
                } catch (InvocationTargetException e) {&lt;br /&gt;
                        result = &lt;br /&gt;
                  ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } catch (Exception e) {&lt;br /&gt;
                    result = &lt;br /&gt;
             ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } finally {&lt;br /&gt;
                    &lt;br /&gt;
                }&lt;br /&gt;
                if(result==delegate)&lt;br /&gt;
                        result = proxy;&lt;br /&gt;
                &lt;br /&gt;
                return result;&lt;br /&gt;
        }&lt;br /&gt;
        public static T newInstance(Object o,Class... interfaces) {&lt;br /&gt;
                return (T)java.lang.reflect.Proxy.newProxyInstance(&lt;br /&gt;
                    interfaces[0].getClassLoader(),&lt;br /&gt;
                    interfaces,&lt;br /&gt;
                    new Dynamic(o));&lt;br /&gt;
        }        &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Here, we define our Proxy class.  Note, both an Object and Method are passed in as parameters.  When attempting to invoke the method of the given Object, an exception is caught and delegated to a MethodMissing interface, which will also need to be defined.&lt;br /&gt;
&lt;br /&gt;
  public interface MethodMissing {&lt;br /&gt;
        public T methodMissing(Method method,E... args);        &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
===Python: __getattr__===&lt;br /&gt;
===Perl: AUTOLOAD===&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73348</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1n jp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73348"/>
		<updated>2013-02-20T20:17:44Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: /* Java: DynamicProxy */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby's method_missing(): Advantages/Disadvantages and Alternatives =&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
One of the distinguishing features of the Ruby programming language is it's ability to easily extend classes in a dynamic fashion to perform a variety of different methods depending upon the needs of the current application.  For example, should the developer want to extend a core language class, take String for example, they could easily re-open that class and add new methods dynamically to this existing class, rather than creating an entirely new class.&lt;br /&gt;
&lt;br /&gt;
Even more powerful, Ruby allows for a construct called method_missing().  By overriding this method in your class, method_missing() will attempt to handle any method calls not currently defined by the given class (or class hierarchy).  Typically, some sort of regular expression is used to determine if the method call can be redirected to an existing method based on it's naming convention (for example, a method call in a non-existent singular form could be redirected to an existing pluralized form).  If the method_missing() definition cannot determine where to redirect the method call, the default is simply to call the parent class via super().&lt;br /&gt;
&lt;br /&gt;
By having the ability to allow a class to dynamically extend itself even if a method definition never truly existed, Ruby allows for a far greater degree of flexibility than does a statically typed language such as Java, where much greater effort is involved in handing method calls that do not currently exist.  With method_missing() defined, almost any sort of method call can be handled in the desired manner.&lt;br /&gt;
&lt;br /&gt;
This article will explore the method_missing() construct in greater detail, giving both advantages and disadvantages of having this feature in the Ruby language.  We will also examine how other programming languages attempt to handle the same problem.&lt;br /&gt;
&lt;br /&gt;
==Advantages of method_missing()==&lt;br /&gt;
1. Allows for dynamically invoked methods.&lt;br /&gt;
 &lt;br /&gt;
==Disadvantages of method_missing()==&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==Alternatives to method_missing() in other programming languages==&lt;br /&gt;
&lt;br /&gt;
===Smalltalk: doesNotUnderstand===&lt;br /&gt;
&lt;br /&gt;
In many ways the inspiration for Ruby, Smalltalk is often considered one of the original truly Object-Oriented languages.  Smalltalk, much like Ruby with method_missing(), sends a message called #doesNotUnderstand&amp;lt;ref&amp;gt;http://c2.com/cgi/wiki?DoesNotUnderstand&amp;lt;/ref&amp;gt; to handle methods that are unknown.&lt;br /&gt;
&lt;br /&gt;
Essentially, when an object receives a method that it doesn't recognize, the Smalltalk runtime engine is then responsible for turning this message into an object with all necessary parameters and returning it to the sender as an exception. The sender is, at that point, responsible for handling the message and somehow dealing with the exception.  Even though Smalltalk does consider this an exception, this construct is used quite frequently to form proxy objects and can handle a wide variety of different methods and arguments.&lt;br /&gt;
&lt;br /&gt;
Consider the following code: &amp;lt;ref&amp;gt;http://www.iam.unibe.ch/~akuhn/blog/category/smalltalk/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    OrderedCollection subclass: #Group.&lt;br /&gt;
    Group &amp;gt;&amp;gt; eachRespondsTo: aSelector&lt;br /&gt;
        self allSatisfy: [ :each | each respondsTo: aSelector ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; doesNotUnderstand: aMessage&lt;br /&gt;
        (self eachRespondsTo: aMessage selector)&lt;br /&gt;
          ifTrue: [ self collect: [ :each | aMessage sendTo: each ] ]&lt;br /&gt;
          ifFalse: [ super doesNotUnderstand: aMessage ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; respondsTo: aSelector&lt;br /&gt;
      ^ (super respondsTo: aSelector) or: [ self eachRespondsTo: aSelector ]&lt;br /&gt;
&lt;br /&gt;
In this code snippet, an OrderedCollection object is created.  Should this collection class not understand any of the methods being sent to it, the doesUnderstand code will attempt to handle the message itself.  Without overriding this method, the default is for Smalltalk to open a debugger to step through the exception (defining it overrides this behavior).&lt;br /&gt;
&lt;br /&gt;
===Java: DynamicProxy===&lt;br /&gt;
&lt;br /&gt;
In Java, the ability to handle undefined methods is a bit more cumbersome, but it can still be done successfully through the use of dynamic proxy classes.&amp;lt;ref&amp;gt;http://www.jroller.com/ie/entry/methodmissing_in_java&amp;lt;/ref&amp;gt;  By creating this dynamic proxy, all calls will essentially be intercepted prior to invocation.  An attempt will be made to invoke the object in question and, if unable to do so, an interface will need to be defined to handle the missing method scenarios.  To give an example:&lt;br /&gt;
&lt;br /&gt;
  public class Dynamic implements java.lang.reflect.InvocationHandler  {&lt;br /&gt;
        Object delegate;&lt;br /&gt;
        public Dynamic(Object delegate){&lt;br /&gt;
                this.delegate=delegate;&lt;br /&gt;
        }        &lt;br /&gt;
        public Object invoke(Object proxy, Method method, Object[] args) &lt;br /&gt;
                           throws Throwable {&lt;br /&gt;
                Object result = null;&lt;br /&gt;
                try {                  &lt;br /&gt;
                    result = method.invoke(delegate, args);&lt;br /&gt;
                } catch (InvocationTargetException e) {&lt;br /&gt;
                        result = &lt;br /&gt;
                  ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } catch (Exception e) {&lt;br /&gt;
                    result = &lt;br /&gt;
             ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } finally {&lt;br /&gt;
                    &lt;br /&gt;
                }&lt;br /&gt;
                if(result==delegate)&lt;br /&gt;
                        result = proxy;&lt;br /&gt;
                &lt;br /&gt;
                return result;&lt;br /&gt;
        }&lt;br /&gt;
        public static T newInstance(Object o,Class... interfaces) {&lt;br /&gt;
                return (T)java.lang.reflect.Proxy.newProxyInstance(&lt;br /&gt;
                    interfaces[0].getClassLoader(),&lt;br /&gt;
                    interfaces,&lt;br /&gt;
                    new Dynamic(o));&lt;br /&gt;
        }        &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Here, we define our Proxy class.  Note, both an Object and Method are passed in as parameters.  When attempting to invoke the method of the given Object, an exception is caught and delegated to a MethodMissing interface, which will also need to be defined.&lt;br /&gt;
&lt;br /&gt;
  public interface MethodMissing {&lt;br /&gt;
&lt;br /&gt;
        public T methodMissing(Method method,E... args);&lt;br /&gt;
        &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
===Python: __getattr__===&lt;br /&gt;
===Perl: AUTOLOAD===&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73347</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1n jp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73347"/>
		<updated>2013-02-20T20:14:49Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: /* Java: DynamicProxy */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby's method_missing(): Advantages/Disadvantages and Alternatives =&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
One of the distinguishing features of the Ruby programming language is it's ability to easily extend classes in a dynamic fashion to perform a variety of different methods depending upon the needs of the current application.  For example, should the developer want to extend a core language class, take String for example, they could easily re-open that class and add new methods dynamically to this existing class, rather than creating an entirely new class.&lt;br /&gt;
&lt;br /&gt;
Even more powerful, Ruby allows for a construct called method_missing().  By overriding this method in your class, method_missing() will attempt to handle any method calls not currently defined by the given class (or class hierarchy).  Typically, some sort of regular expression is used to determine if the method call can be redirected to an existing method based on it's naming convention (for example, a method call in a non-existent singular form could be redirected to an existing pluralized form).  If the method_missing() definition cannot determine where to redirect the method call, the default is simply to call the parent class via super().&lt;br /&gt;
&lt;br /&gt;
By having the ability to allow a class to dynamically extend itself even if a method definition never truly existed, Ruby allows for a far greater degree of flexibility than does a statically typed language such as Java, where much greater effort is involved in handing method calls that do not currently exist.  With method_missing() defined, almost any sort of method call can be handled in the desired manner.&lt;br /&gt;
&lt;br /&gt;
This article will explore the method_missing() construct in greater detail, giving both advantages and disadvantages of having this feature in the Ruby language.  We will also examine how other programming languages attempt to handle the same problem.&lt;br /&gt;
&lt;br /&gt;
==Advantages of method_missing()==&lt;br /&gt;
1. Allows for dynamically invoked methods.&lt;br /&gt;
 &lt;br /&gt;
==Disadvantages of method_missing()==&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==Alternatives to method_missing() in other programming languages==&lt;br /&gt;
&lt;br /&gt;
===Smalltalk: doesNotUnderstand===&lt;br /&gt;
&lt;br /&gt;
In many ways the inspiration for Ruby, Smalltalk is often considered one of the original truly Object-Oriented languages.  Smalltalk, much like Ruby with method_missing(), sends a message called #doesNotUnderstand&amp;lt;ref&amp;gt;http://c2.com/cgi/wiki?DoesNotUnderstand&amp;lt;/ref&amp;gt; to handle methods that are unknown.&lt;br /&gt;
&lt;br /&gt;
Essentially, when an object receives a method that it doesn't recognize, the Smalltalk runtime engine is then responsible for turning this message into an object with all necessary parameters and returning it to the sender as an exception. The sender is, at that point, responsible for handling the message and somehow dealing with the exception.  Even though Smalltalk does consider this an exception, this construct is used quite frequently to form proxy objects and can handle a wide variety of different methods and arguments.&lt;br /&gt;
&lt;br /&gt;
Consider the following code: &amp;lt;ref&amp;gt;http://www.iam.unibe.ch/~akuhn/blog/category/smalltalk/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    OrderedCollection subclass: #Group.&lt;br /&gt;
    Group &amp;gt;&amp;gt; eachRespondsTo: aSelector&lt;br /&gt;
        self allSatisfy: [ :each | each respondsTo: aSelector ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; doesNotUnderstand: aMessage&lt;br /&gt;
        (self eachRespondsTo: aMessage selector)&lt;br /&gt;
          ifTrue: [ self collect: [ :each | aMessage sendTo: each ] ]&lt;br /&gt;
          ifFalse: [ super doesNotUnderstand: aMessage ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; respondsTo: aSelector&lt;br /&gt;
      ^ (super respondsTo: aSelector) or: [ self eachRespondsTo: aSelector ]&lt;br /&gt;
&lt;br /&gt;
In this code snippet, an OrderedCollection object is created.  Should this collection class not understand any of the methods being sent to it, the doesUnderstand code will attempt to handle the message itself.  Without overriding this method, the default is for Smalltalk to open a debugger to step through the exception (defining it overrides this behavior).&lt;br /&gt;
&lt;br /&gt;
===Java: DynamicProxy===&lt;br /&gt;
&lt;br /&gt;
In Java, the ability to handle undefined methods is a bit more cumbersome, but it can still be done successfully through the use of dynamic proxy classes.&amp;lt;ref&amp;gt;http://www.jroller.com/ie/entry/methodmissing_in_java&amp;lt;/ref&amp;gt;  By creating this dynamic proxy, all calls will essentially be intercepted prior to invocation.  An attempt will be made to invoke the object in question and, if unable to do so, an interface will need to be defined to handle the missing method scenarios.  To give an example:&lt;br /&gt;
&lt;br /&gt;
  public class Dynamic implements java.lang.reflect.InvocationHandler  {&lt;br /&gt;
        Object delegate;&lt;br /&gt;
        public Dynamic(Object delegate){&lt;br /&gt;
                this.delegate=delegate;&lt;br /&gt;
        }        &lt;br /&gt;
        public Object invoke(Object proxy, Method method, Object[] args) &lt;br /&gt;
                           throws Throwable {&lt;br /&gt;
                Object result = null;&lt;br /&gt;
                try {                  &lt;br /&gt;
                    result = method.invoke(delegate, args);&lt;br /&gt;
                } catch (InvocationTargetException e) {&lt;br /&gt;
                        result = &lt;br /&gt;
                  ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } catch (Exception e) {&lt;br /&gt;
                    result = &lt;br /&gt;
             ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } finally {&lt;br /&gt;
                    &lt;br /&gt;
                }&lt;br /&gt;
                if(result==delegate)&lt;br /&gt;
                        result = proxy;&lt;br /&gt;
                &lt;br /&gt;
                return result;&lt;br /&gt;
        }&lt;br /&gt;
        public static T newInstance(Object o,Class... interfaces) {&lt;br /&gt;
                return (T)java.lang.reflect.Proxy.newProxyInstance(&lt;br /&gt;
                    interfaces[0].getClassLoader(),&lt;br /&gt;
                    interfaces,&lt;br /&gt;
                    new Dynamic(o));&lt;br /&gt;
        }        &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
===Python: __getattr__===&lt;br /&gt;
===Perl: AUTOLOAD===&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73346</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1n jp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73346"/>
		<updated>2013-02-20T20:14:37Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: /* Java: DynamicProxy */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby's method_missing(): Advantages/Disadvantages and Alternatives =&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
One of the distinguishing features of the Ruby programming language is it's ability to easily extend classes in a dynamic fashion to perform a variety of different methods depending upon the needs of the current application.  For example, should the developer want to extend a core language class, take String for example, they could easily re-open that class and add new methods dynamically to this existing class, rather than creating an entirely new class.&lt;br /&gt;
&lt;br /&gt;
Even more powerful, Ruby allows for a construct called method_missing().  By overriding this method in your class, method_missing() will attempt to handle any method calls not currently defined by the given class (or class hierarchy).  Typically, some sort of regular expression is used to determine if the method call can be redirected to an existing method based on it's naming convention (for example, a method call in a non-existent singular form could be redirected to an existing pluralized form).  If the method_missing() definition cannot determine where to redirect the method call, the default is simply to call the parent class via super().&lt;br /&gt;
&lt;br /&gt;
By having the ability to allow a class to dynamically extend itself even if a method definition never truly existed, Ruby allows for a far greater degree of flexibility than does a statically typed language such as Java, where much greater effort is involved in handing method calls that do not currently exist.  With method_missing() defined, almost any sort of method call can be handled in the desired manner.&lt;br /&gt;
&lt;br /&gt;
This article will explore the method_missing() construct in greater detail, giving both advantages and disadvantages of having this feature in the Ruby language.  We will also examine how other programming languages attempt to handle the same problem.&lt;br /&gt;
&lt;br /&gt;
==Advantages of method_missing()==&lt;br /&gt;
1. Allows for dynamically invoked methods.&lt;br /&gt;
 &lt;br /&gt;
==Disadvantages of method_missing()==&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==Alternatives to method_missing() in other programming languages==&lt;br /&gt;
&lt;br /&gt;
===Smalltalk: doesNotUnderstand===&lt;br /&gt;
&lt;br /&gt;
In many ways the inspiration for Ruby, Smalltalk is often considered one of the original truly Object-Oriented languages.  Smalltalk, much like Ruby with method_missing(), sends a message called #doesNotUnderstand&amp;lt;ref&amp;gt;http://c2.com/cgi/wiki?DoesNotUnderstand&amp;lt;/ref&amp;gt; to handle methods that are unknown.&lt;br /&gt;
&lt;br /&gt;
Essentially, when an object receives a method that it doesn't recognize, the Smalltalk runtime engine is then responsible for turning this message into an object with all necessary parameters and returning it to the sender as an exception. The sender is, at that point, responsible for handling the message and somehow dealing with the exception.  Even though Smalltalk does consider this an exception, this construct is used quite frequently to form proxy objects and can handle a wide variety of different methods and arguments.&lt;br /&gt;
&lt;br /&gt;
Consider the following code: &amp;lt;ref&amp;gt;http://www.iam.unibe.ch/~akuhn/blog/category/smalltalk/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    OrderedCollection subclass: #Group.&lt;br /&gt;
    Group &amp;gt;&amp;gt; eachRespondsTo: aSelector&lt;br /&gt;
        self allSatisfy: [ :each | each respondsTo: aSelector ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; doesNotUnderstand: aMessage&lt;br /&gt;
        (self eachRespondsTo: aMessage selector)&lt;br /&gt;
          ifTrue: [ self collect: [ :each | aMessage sendTo: each ] ]&lt;br /&gt;
          ifFalse: [ super doesNotUnderstand: aMessage ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; respondsTo: aSelector&lt;br /&gt;
      ^ (super respondsTo: aSelector) or: [ self eachRespondsTo: aSelector ]&lt;br /&gt;
&lt;br /&gt;
In this code snippet, an OrderedCollection object is created.  Should this collection class not understand any of the methods being sent to it, the doesUnderstand code will attempt to handle the message itself.  Without overriding this method, the default is for Smalltalk to open a debugger to step through the exception (defining it overrides this behavior).&lt;br /&gt;
&lt;br /&gt;
===Java: DynamicProxy===&lt;br /&gt;
&lt;br /&gt;
In Java, the ability to handle undefined methods is a bit more cumbersome, but it can still be done successfully through the use of dynamic proxy classes.&amp;lt;ref&amp;gt;http://www.jroller.com/ie/entry/methodmissing_in_java&amp;lt;/ref&amp;gt;  By creating this dynamic proxy, all calls will essentially be intercepted prior to invocation.  An attempt will be made to invoke the object in question and, if unable to do so, an interface will need to be defined to handle the missing method scenarios.  To give an example:&lt;br /&gt;
&lt;br /&gt;
  public class Dynamic implements java.lang.reflect.InvocationHandler  {&lt;br /&gt;
        Object delegate;&lt;br /&gt;
        public Dynamic(Object delegate){&lt;br /&gt;
                this.delegate=delegate;&lt;br /&gt;
        }        &lt;br /&gt;
        public Object invoke(Object proxy, Method method, Object[] args) &lt;br /&gt;
                           throws Throwable {&lt;br /&gt;
                Object result = null;&lt;br /&gt;
                try {                  &lt;br /&gt;
                    result = method.invoke(delegate, args);&lt;br /&gt;
                } catch (InvocationTargetException e) {&lt;br /&gt;
                        result = &lt;br /&gt;
                  ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } catch (Exception e) {&lt;br /&gt;
                    result = &lt;br /&gt;
             ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
&lt;br /&gt;
                } finally {&lt;br /&gt;
                    &lt;br /&gt;
                }&lt;br /&gt;
                if(result==delegate)&lt;br /&gt;
                        result = proxy;&lt;br /&gt;
                &lt;br /&gt;
                return result;&lt;br /&gt;
        }&lt;br /&gt;
        public static T newInstance(Object o,Class... interfaces) {&lt;br /&gt;
                return (T)java.lang.reflect.Proxy.newProxyInstance(&lt;br /&gt;
                    interfaces[0].getClassLoader(),&lt;br /&gt;
                    interfaces,&lt;br /&gt;
                    new Dynamic(o));&lt;br /&gt;
        }        &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
===Python: __getattr__===&lt;br /&gt;
===Perl: AUTOLOAD===&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73345</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1n jp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73345"/>
		<updated>2013-02-20T20:14:24Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: /* Java: DynamicProxy */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby's method_missing(): Advantages/Disadvantages and Alternatives =&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
One of the distinguishing features of the Ruby programming language is it's ability to easily extend classes in a dynamic fashion to perform a variety of different methods depending upon the needs of the current application.  For example, should the developer want to extend a core language class, take String for example, they could easily re-open that class and add new methods dynamically to this existing class, rather than creating an entirely new class.&lt;br /&gt;
&lt;br /&gt;
Even more powerful, Ruby allows for a construct called method_missing().  By overriding this method in your class, method_missing() will attempt to handle any method calls not currently defined by the given class (or class hierarchy).  Typically, some sort of regular expression is used to determine if the method call can be redirected to an existing method based on it's naming convention (for example, a method call in a non-existent singular form could be redirected to an existing pluralized form).  If the method_missing() definition cannot determine where to redirect the method call, the default is simply to call the parent class via super().&lt;br /&gt;
&lt;br /&gt;
By having the ability to allow a class to dynamically extend itself even if a method definition never truly existed, Ruby allows for a far greater degree of flexibility than does a statically typed language such as Java, where much greater effort is involved in handing method calls that do not currently exist.  With method_missing() defined, almost any sort of method call can be handled in the desired manner.&lt;br /&gt;
&lt;br /&gt;
This article will explore the method_missing() construct in greater detail, giving both advantages and disadvantages of having this feature in the Ruby language.  We will also examine how other programming languages attempt to handle the same problem.&lt;br /&gt;
&lt;br /&gt;
==Advantages of method_missing()==&lt;br /&gt;
1. Allows for dynamically invoked methods.&lt;br /&gt;
 &lt;br /&gt;
==Disadvantages of method_missing()==&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==Alternatives to method_missing() in other programming languages==&lt;br /&gt;
&lt;br /&gt;
===Smalltalk: doesNotUnderstand===&lt;br /&gt;
&lt;br /&gt;
In many ways the inspiration for Ruby, Smalltalk is often considered one of the original truly Object-Oriented languages.  Smalltalk, much like Ruby with method_missing(), sends a message called #doesNotUnderstand&amp;lt;ref&amp;gt;http://c2.com/cgi/wiki?DoesNotUnderstand&amp;lt;/ref&amp;gt; to handle methods that are unknown.&lt;br /&gt;
&lt;br /&gt;
Essentially, when an object receives a method that it doesn't recognize, the Smalltalk runtime engine is then responsible for turning this message into an object with all necessary parameters and returning it to the sender as an exception. The sender is, at that point, responsible for handling the message and somehow dealing with the exception.  Even though Smalltalk does consider this an exception, this construct is used quite frequently to form proxy objects and can handle a wide variety of different methods and arguments.&lt;br /&gt;
&lt;br /&gt;
Consider the following code: &amp;lt;ref&amp;gt;http://www.iam.unibe.ch/~akuhn/blog/category/smalltalk/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    OrderedCollection subclass: #Group.&lt;br /&gt;
    Group &amp;gt;&amp;gt; eachRespondsTo: aSelector&lt;br /&gt;
        self allSatisfy: [ :each | each respondsTo: aSelector ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; doesNotUnderstand: aMessage&lt;br /&gt;
        (self eachRespondsTo: aMessage selector)&lt;br /&gt;
          ifTrue: [ self collect: [ :each | aMessage sendTo: each ] ]&lt;br /&gt;
          ifFalse: [ super doesNotUnderstand: aMessage ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; respondsTo: aSelector&lt;br /&gt;
      ^ (super respondsTo: aSelector) or: [ self eachRespondsTo: aSelector ]&lt;br /&gt;
&lt;br /&gt;
In this code snippet, an OrderedCollection object is created.  Should this collection class not understand any of the methods being sent to it, the doesUnderstand code will attempt to handle the message itself.  Without overriding this method, the default is for Smalltalk to open a debugger to step through the exception (defining it overrides this behavior).&lt;br /&gt;
&lt;br /&gt;
===Java: DynamicProxy===&lt;br /&gt;
&lt;br /&gt;
In Java, the ability to handle undefined methods is a bit more cumbersome, but it can still be done successfully through the use of dynamic proxy classes.&amp;lt;ref&amp;gt;http://www.jroller.com/ie/entry/methodmissing_in_java&amp;lt;/ref&amp;gt;  By creating this dynamic proxy, all calls will essentially be intercepted prior to invocation.  An attempt will be made to invoke the object in question and, if unable to do so, an interface will need to be defined to handle the missing method scenarios.  To give an example:&lt;br /&gt;
&lt;br /&gt;
  public class Dynamic implements java.lang.reflect.InvocationHandler  {&lt;br /&gt;
        Object delegate;&lt;br /&gt;
        public Dynamic(Object delegate){&lt;br /&gt;
                this.delegate=delegate;&lt;br /&gt;
        }        &lt;br /&gt;
        public Object invoke(Object proxy, Method method, Object[] args) &lt;br /&gt;
                           throws Throwable {&lt;br /&gt;
                Object result = null;&lt;br /&gt;
                try {&lt;br /&gt;
                   &lt;br /&gt;
                    result = method.invoke(delegate, args);&lt;br /&gt;
                } catch (InvocationTargetException e) {&lt;br /&gt;
                        result = &lt;br /&gt;
                  ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } catch (Exception e) {&lt;br /&gt;
                    result = &lt;br /&gt;
             ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
&lt;br /&gt;
                } finally {&lt;br /&gt;
                    &lt;br /&gt;
                }&lt;br /&gt;
                if(result==delegate)&lt;br /&gt;
                        result = proxy;&lt;br /&gt;
                &lt;br /&gt;
                return result;&lt;br /&gt;
        }&lt;br /&gt;
        public static T newInstance(Object o,Class... interfaces) {&lt;br /&gt;
                return (T)java.lang.reflect.Proxy.newProxyInstance(&lt;br /&gt;
                    interfaces[0].getClassLoader(),&lt;br /&gt;
                    interfaces,&lt;br /&gt;
                    new Dynamic(o));&lt;br /&gt;
        }        &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
===Python: __getattr__===&lt;br /&gt;
===Perl: AUTOLOAD===&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73344</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1n jp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73344"/>
		<updated>2013-02-20T20:13:43Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: /* Java: DynamicProxy */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby's method_missing(): Advantages/Disadvantages and Alternatives =&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
One of the distinguishing features of the Ruby programming language is it's ability to easily extend classes in a dynamic fashion to perform a variety of different methods depending upon the needs of the current application.  For example, should the developer want to extend a core language class, take String for example, they could easily re-open that class and add new methods dynamically to this existing class, rather than creating an entirely new class.&lt;br /&gt;
&lt;br /&gt;
Even more powerful, Ruby allows for a construct called method_missing().  By overriding this method in your class, method_missing() will attempt to handle any method calls not currently defined by the given class (or class hierarchy).  Typically, some sort of regular expression is used to determine if the method call can be redirected to an existing method based on it's naming convention (for example, a method call in a non-existent singular form could be redirected to an existing pluralized form).  If the method_missing() definition cannot determine where to redirect the method call, the default is simply to call the parent class via super().&lt;br /&gt;
&lt;br /&gt;
By having the ability to allow a class to dynamically extend itself even if a method definition never truly existed, Ruby allows for a far greater degree of flexibility than does a statically typed language such as Java, where much greater effort is involved in handing method calls that do not currently exist.  With method_missing() defined, almost any sort of method call can be handled in the desired manner.&lt;br /&gt;
&lt;br /&gt;
This article will explore the method_missing() construct in greater detail, giving both advantages and disadvantages of having this feature in the Ruby language.  We will also examine how other programming languages attempt to handle the same problem.&lt;br /&gt;
&lt;br /&gt;
==Advantages of method_missing()==&lt;br /&gt;
1. Allows for dynamically invoked methods.&lt;br /&gt;
 &lt;br /&gt;
==Disadvantages of method_missing()==&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==Alternatives to method_missing() in other programming languages==&lt;br /&gt;
&lt;br /&gt;
===Smalltalk: doesNotUnderstand===&lt;br /&gt;
&lt;br /&gt;
In many ways the inspiration for Ruby, Smalltalk is often considered one of the original truly Object-Oriented languages.  Smalltalk, much like Ruby with method_missing(), sends a message called #doesNotUnderstand&amp;lt;ref&amp;gt;http://c2.com/cgi/wiki?DoesNotUnderstand&amp;lt;/ref&amp;gt; to handle methods that are unknown.&lt;br /&gt;
&lt;br /&gt;
Essentially, when an object receives a method that it doesn't recognize, the Smalltalk runtime engine is then responsible for turning this message into an object with all necessary parameters and returning it to the sender as an exception. The sender is, at that point, responsible for handling the message and somehow dealing with the exception.  Even though Smalltalk does consider this an exception, this construct is used quite frequently to form proxy objects and can handle a wide variety of different methods and arguments.&lt;br /&gt;
&lt;br /&gt;
Consider the following code: &amp;lt;ref&amp;gt;http://www.iam.unibe.ch/~akuhn/blog/category/smalltalk/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    OrderedCollection subclass: #Group.&lt;br /&gt;
    Group &amp;gt;&amp;gt; eachRespondsTo: aSelector&lt;br /&gt;
        self allSatisfy: [ :each | each respondsTo: aSelector ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; doesNotUnderstand: aMessage&lt;br /&gt;
        (self eachRespondsTo: aMessage selector)&lt;br /&gt;
          ifTrue: [ self collect: [ :each | aMessage sendTo: each ] ]&lt;br /&gt;
          ifFalse: [ super doesNotUnderstand: aMessage ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; respondsTo: aSelector&lt;br /&gt;
      ^ (super respondsTo: aSelector) or: [ self eachRespondsTo: aSelector ]&lt;br /&gt;
&lt;br /&gt;
In this code snippet, an OrderedCollection object is created.  Should this collection class not understand any of the methods being sent to it, the doesUnderstand code will attempt to handle the message itself.  Without overriding this method, the default is for Smalltalk to open a debugger to step through the exception (defining it overrides this behavior).&lt;br /&gt;
&lt;br /&gt;
===Java: DynamicProxy===&lt;br /&gt;
&lt;br /&gt;
In Java, the ability to handle undefined methods is a bit more cumbersome, but it can still be done successfully through the use of dynamic proxy classes.&amp;lt;ref&amp;gt;http://www.jroller.com/ie/entry/methodmissing_in_java&amp;lt;/ref&amp;gt;  By creating this dynamic proxy, all calls will essentially be intercepted prior to invocation.  An attempt will be made to invoke the object in question and, if unable to do so, an interface will need to be defined to handle the missing method scenarios.  To give an example:&lt;br /&gt;
&lt;br /&gt;
  public class Dynamic implements java.lang.reflect.InvocationHandler  {&lt;br /&gt;
&lt;br /&gt;
        Object delegate;&lt;br /&gt;
        public Dynamic(Object delegate){&lt;br /&gt;
                this.delegate=delegate;&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        &lt;br /&gt;
        public Object invoke(Object proxy, Method method, Object[] args) &lt;br /&gt;
                           throws Throwable {&lt;br /&gt;
                Object result = null;&lt;br /&gt;
                try {&lt;br /&gt;
                   &lt;br /&gt;
                    result = method.invoke(delegate, args);&lt;br /&gt;
                } catch (InvocationTargetException e) {&lt;br /&gt;
                        result = &lt;br /&gt;
                  ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
                } catch (Exception e) {&lt;br /&gt;
                    result = &lt;br /&gt;
             ((MethodMissing)delegate).methodMissing(method,args);&lt;br /&gt;
&lt;br /&gt;
                } finally {&lt;br /&gt;
                    &lt;br /&gt;
                }&lt;br /&gt;
                if(result==delegate)&lt;br /&gt;
                        result = proxy;&lt;br /&gt;
                &lt;br /&gt;
                return result;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        public static T newInstance(Object o,Class... interfaces) {&lt;br /&gt;
                return (T)java.lang.reflect.Proxy.newProxyInstance(&lt;br /&gt;
                    interfaces[0].getClassLoader(),&lt;br /&gt;
                    interfaces,&lt;br /&gt;
                    new Dynamic(o));&lt;br /&gt;
            }&lt;br /&gt;
        &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
===Python: __getattr__===&lt;br /&gt;
===Perl: AUTOLOAD===&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73343</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1n jp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1n_jp&amp;diff=73343"/>
		<updated>2013-02-20T20:08:55Z</updated>

		<summary type="html">&lt;p&gt;Japlemmo: /* Java: DynamicProxy */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby's method_missing(): Advantages/Disadvantages and Alternatives =&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
One of the distinguishing features of the Ruby programming language is it's ability to easily extend classes in a dynamic fashion to perform a variety of different methods depending upon the needs of the current application.  For example, should the developer want to extend a core language class, take String for example, they could easily re-open that class and add new methods dynamically to this existing class, rather than creating an entirely new class.&lt;br /&gt;
&lt;br /&gt;
Even more powerful, Ruby allows for a construct called method_missing().  By overriding this method in your class, method_missing() will attempt to handle any method calls not currently defined by the given class (or class hierarchy).  Typically, some sort of regular expression is used to determine if the method call can be redirected to an existing method based on it's naming convention (for example, a method call in a non-existent singular form could be redirected to an existing pluralized form).  If the method_missing() definition cannot determine where to redirect the method call, the default is simply to call the parent class via super().&lt;br /&gt;
&lt;br /&gt;
By having the ability to allow a class to dynamically extend itself even if a method definition never truly existed, Ruby allows for a far greater degree of flexibility than does a statically typed language such as Java, where much greater effort is involved in handing method calls that do not currently exist.  With method_missing() defined, almost any sort of method call can be handled in the desired manner.&lt;br /&gt;
&lt;br /&gt;
This article will explore the method_missing() construct in greater detail, giving both advantages and disadvantages of having this feature in the Ruby language.  We will also examine how other programming languages attempt to handle the same problem.&lt;br /&gt;
&lt;br /&gt;
==Advantages of method_missing()==&lt;br /&gt;
1. Allows for dynamically invoked methods.&lt;br /&gt;
 &lt;br /&gt;
==Disadvantages of method_missing()==&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==Alternatives to method_missing() in other programming languages==&lt;br /&gt;
&lt;br /&gt;
===Smalltalk: doesNotUnderstand===&lt;br /&gt;
&lt;br /&gt;
In many ways the inspiration for Ruby, Smalltalk is often considered one of the original truly Object-Oriented languages.  Smalltalk, much like Ruby with method_missing(), sends a message called #doesNotUnderstand&amp;lt;ref&amp;gt;http://c2.com/cgi/wiki?DoesNotUnderstand&amp;lt;/ref&amp;gt; to handle methods that are unknown.&lt;br /&gt;
&lt;br /&gt;
Essentially, when an object receives a method that it doesn't recognize, the Smalltalk runtime engine is then responsible for turning this message into an object with all necessary parameters and returning it to the sender as an exception. The sender is, at that point, responsible for handling the message and somehow dealing with the exception.  Even though Smalltalk does consider this an exception, this construct is used quite frequently to form proxy objects and can handle a wide variety of different methods and arguments.&lt;br /&gt;
&lt;br /&gt;
Consider the following code: &amp;lt;ref&amp;gt;http://www.iam.unibe.ch/~akuhn/blog/category/smalltalk/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    OrderedCollection subclass: #Group.&lt;br /&gt;
    Group &amp;gt;&amp;gt; eachRespondsTo: aSelector&lt;br /&gt;
        self allSatisfy: [ :each | each respondsTo: aSelector ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; doesNotUnderstand: aMessage&lt;br /&gt;
        (self eachRespondsTo: aMessage selector)&lt;br /&gt;
          ifTrue: [ self collect: [ :each | aMessage sendTo: each ] ]&lt;br /&gt;
          ifFalse: [ super doesNotUnderstand: aMessage ]&lt;br /&gt;
    Group &amp;gt;&amp;gt; respondsTo: aSelector&lt;br /&gt;
      ^ (super respondsTo: aSelector) or: [ self eachRespondsTo: aSelector ]&lt;br /&gt;
&lt;br /&gt;
In this code snippet, an OrderedCollection object is created.  Should this collection class not understand any of the methods being sent to it, the doesUnderstand code will attempt to handle the message itself.  Without overriding this method, the default is for Smalltalk to open a debugger to step through the exception (defining it overrides this behavior).&lt;br /&gt;
&lt;br /&gt;
===Java: DynamicProxy===&lt;br /&gt;
&lt;br /&gt;
In Java, the ability to handle undefined methods is a bit more cumbersome, but it can still be done successfully through the use of dynamic proxy classes.&amp;lt;ref&amp;gt;http://www.jroller.com/ie/entry/methodmissing_in_java&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Python: __getattr__===&lt;br /&gt;
===Perl: AUTOLOAD===&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Japlemmo</name></author>
	</entry>
</feed>