2014년 2월 26일 수요일

P r o x y ( PureMVC )



/*
 PureMVC Java port by Frederic Saunier <frederic.saunier@puremvc.org>

 Adapted from sources of thoses different authors :
  Donald Stinchfield <donald.stinchfield@puremvc.org>, et all
  Ima OpenSource <opensource@ima.eu>
  Anthony Quinault <anthony.quinault@puremvc.org>

 PureMVC - Copyright(c) 2006-10 Futurescale, Inc., Some rights reserved. 
 Your reuse is governed by the Creative Commons Attribution 3.0 License
*/
package org.puremvc.java.interfaces;

/**
 * The interface definition for a PureMVC Proxy.
 * 
 * <P>
 * In PureMVC, <code>IProxy</code> implementors assume these responsibilities:
 * </P>
 * <UL>
 * <LI>Implement a common method which returns the name of the Proxy.</LI>
 * </UL>
 * <P>
 * Additionally, <code>IProxy</code>s typically:
 * </P>
 * <UL>
 * <LI>Maintain references to one or more pieces of model data.</LI>
 * <LI>Provide methods for manipulating that data.</LI>
 * <LI>Generate <code>INotifications</code> when their model data changes.</LI>
 * <LI>Expose their name as a <code>public static const</code> called <code>NAME</code>, if they are not instantiated multiple times.</LI>
 * <LI>Encapsulate interaction with local or remote services used to fetch and
 * persist model data.</LI>
 * </UL>
 */
public interface IProxy extends INotifier
{

/**
 * Get the Proxy name
 * 
 * @return the Proxy instance name
 */
public String getProxyName( );
/**
 * Set the data object
 * 
 * @param data the data object
 */
public void setData( Object data );
/**
 * Get the data object
 * 
 * @return the data as type Object
 */
public Object getData(); 
/**
 * Called by the Model when the Proxy is registered
 */ 
public void onRegister();
/**
 * Called by the Model when the Proxy is removed
 */ 
public void onRemove( );

}







/*
 PureMVC Java port by Frederic Saunier <frederic.saunier@puremvc.org>

 Adapted from sources of thoses different authors :
  Donald Stinchfield <donald.stinchfield@puremvc.org>, et all
  Ima OpenSource <opensource@ima.eu>
  Anthony Quinault <anthony.quinault@puremvc.org>

 PureMVC - Copyright(c) 2006-10 Futurescale, Inc., Some rights reserved. 
 Your reuse is governed by the Creative Commons Attribution 3.0 License
*/
package org.puremvc.java.patterns.proxy;

import org.puremvc.java.interfaces.IProxy;
import org.puremvc.java.patterns.observer.Notifier;

/**
 * A base <code>IProxy</code> implementation.
 * 
 * <P>
 * In PureMVC, <code>Proxy</code> classes are used to manage parts of the
 * application's data model.
 * </P>
 * 
 * <P>
 * A <code>Proxy</code> might simply manage a reference to a local data
 * object, in which case interacting with it might involve setting and getting
 * of its data in synchronous fashion.
 * </P>
 * 
 * <P>
 * <code>Proxy</code> classes are also used to encapsulate the application's
 * interaction with remote services to save or retrieve data, in which case, we
 * adopt an asyncronous idiom; setting data (or calling a method) on the
 * <code>Proxy</code> and listening for a <code>Notification</code> to be
 * sent when the <code>Proxy</code> has retrieved the data from the service.
 * </P>
 * 
 * @see org.puremvc.java.core.Model Model
 */
public class Proxy extends Notifier implements IProxy
{

// the proxy name
private String proxyName = "Proxy";

// the data object
private Object data = null;

/**
 * Constructor
 * @param proxyName 
 * @param data 
 */
public Proxy( String proxyName, Object data )
{
if (proxyName != null) {
this.proxyName = proxyName;
}
if (data != null) {
this.data = data;
}
}
/**
 * Constructor
 * @param proxyName
 * Name of the <code>Proxy</code>
 */
public Proxy( String proxyName )
{
if( proxyName != null)
this.proxyName = proxyName;
}

/**
 * Get the proxy name
 * @return the proxy name
 */
public String getProxyName()
{
return this.proxyName;
}

/**
 * Set the data object
 * @param data 
 */
public void setData( Object data )
{
this.data = data;
}

/**
 * Get the data object
 * @return the data object
 */
public Object getData( )
{
return this.data;
}
/**
 * Called by the Model when the Proxy is registered
 */ 
public void onRegister(){}
/**
 * Called by the Model when the Proxy is removed
 */ 
public void onRemove(){}
}



댓글 없음:

댓글 쓰기