org.appcelerator.kroll
Class KrollProxy

java.lang.Object
  extended by org.appcelerator.kroll.KrollProxy
All Implemented Interfaces:
Handler.Callback, org.appcelerator.kroll.KrollProxySupport
Direct Known Subclasses:
BufferProxy, KrollModule, TiBlob, TiViewProxy

@Kroll.proxy(name="KrollProxy",
             propertyAccessors="_hasJavaListener")
public class KrollProxy
extends Object
implements Handler.Callback, org.appcelerator.kroll.KrollProxySupport

This is the parent class of all proxies. A proxy is a dynamic object that can be created or queried by the user through a module or another proxy's API. When you create a native view with Titanium.UI.createView , the view object is a proxy itself.


Constructor Summary
KrollProxy()
          The default KrollProxy constructor.
KrollProxy(String baseCreationUrl)
          Constructs a KrollProxy, using the passed in creation URL.
 
Method Summary
 boolean fireEvent(String event, Object data)
          Fires an event asynchronously via KrollRuntime thread, which can be intercepted on JS side.
 boolean fireSyncEvent(String event, Object data)
          Fires an event synchronously via KrollRuntime thread, which can be intercepted on JS side.
 Activity getActivity()
           
 org.appcelerator.titanium.util.TiUrl getCreationUrl()
           
 org.appcelerator.kroll.KrollObject getKrollObject()
           
protected  KrollDict getLangConversionTable()
           
 KrollDict getProperties()
          Returns a KrollDict object that contains all current properties associated with this proxy.
 Object getProperty(String name)
          Returns the property value given its key.
 void handleCreationArgs(KrollModule createdInModule, Object[] args)
          Handles the arguments passed into the "create" method for this proxy.
 void handleCreationDict(KrollDict dict)
          Handles the creation KrollDict passed into the create method for this proxy.
protected  void handleDefaultValues()
          Handles initialization of the proxy's default property values.
 boolean hasListeners(String event)
           
 boolean hasProperty(String name)
           
 void release()
          Releases the KrollObject, freeing memory.
 String resolveUrl(String scheme, String path)
          Resolves the passed in scheme / path, and uses the Proxy's creationUrl if the path is relative.
 void setModelListener(KrollProxyListener modelListener)
          Associates this proxy with the passed in KrollProxyListener.
 void setProperty(String name, Object value)
          This sets the named property as well as updating the actual JS object.
 void setPropertyAndFire(String name, Object value)
          Same behavior as setProperty(String, Object), but also invokes KrollProxyListener.propertyChanged(String, Object, Object, KrollProxy).
 

Constructor Detail

KrollProxy

public KrollProxy()
The default KrollProxy constructor. Equivalent to KrollProxy("")


KrollProxy

public KrollProxy(String baseCreationUrl)
Constructs a KrollProxy, using the passed in creation URL.

Parameters:
baseCreationUrl - the creation URL for this proxy, which can be used to resolve relative paths
Method Detail

getActivity

public Activity getActivity()
Returns:
the activity associated with this proxy. It can be null.

handleCreationArgs

public void handleCreationArgs(KrollModule createdInModule,
                               Object[] args)
Handles the arguments passed into the "create" method for this proxy. If your proxy simply needs to handle a KrollDict, see handleCreationDict(KrollDict)

Parameters:
args -

handleDefaultValues

protected void handleDefaultValues()
Handles initialization of the proxy's default property values.


getLangConversionTable

protected KrollDict getLangConversionTable()
Returns:
the language conversion table used to load localized values for certain properties from the locale files. For each localizable property, such as "title," the proxy should define a second property, such as "titleid", used to specify a localization key for that property. If the user specifies a localization key in "titleid", the corresponding localized text from the locale file is used for "title." Subclasses should override this method to return a table mapping localizable properties to the corresponding localization key properties. For example, if the proxy has two properties, "title" and "text", and the corresponding localization key properties are "titleid" and "textid", this might look like:
protected KrollDict getLangConversionTable()
{
        KrollDict table = new KrollDict();
        table.put("title", "titleid");
        table.put("text", "textid");
        return table;
} 

handleCreationDict

public void handleCreationDict(KrollDict dict)
Handles the creation KrollDict passed into the create method for this proxy. This is usually the first (and sometimes only) argument to the proxy's create method. To set default property values, add them to the map

Parameters:
dict -

getKrollObject

public org.appcelerator.kroll.KrollObject getKrollObject()
Returns:
the KrollObject associated with this proxy if it exists. Otherwise create it in the KrollRuntime thread.

getCreationUrl

public org.appcelerator.titanium.util.TiUrl getCreationUrl()
Returns:
the absolute URL of the location in code where the proxy was created in Javascript.

hasProperty

public boolean hasProperty(String name)
Parameters:
name - the lookup key.
Returns:
true if the proxy contains this property, false otherwise.

getProperty

public Object getProperty(String name)
Returns the property value given its key. Properties are cached on the Proxy and updated from JS for relevant annotated APIs

Parameters:
name - the lookup key.
Returns:
the property object or null if a property for the given key does not exist.

setProperty

public void setProperty(String name,
                        Object value)
This sets the named property as well as updating the actual JS object.


fireEvent

public boolean fireEvent(String event,
                         Object data)
Fires an event asynchronously via KrollRuntime thread, which can be intercepted on JS side.

Parameters:
event - the event to be fired.
data - the data to be sent.
Returns:
whether this proxy has an eventListener for this event.

fireSyncEvent

public boolean fireSyncEvent(String event,
                             Object data)
Fires an event synchronously via KrollRuntime thread, which can be intercepted on JS side.

Parameters:
event - the event to be fired.
data - the data to be sent.
Returns:
whether this proxy has an eventListener for this event.

hasListeners

public boolean hasListeners(String event)
Parameters:
event - the event to check
Returns:
whether the associated KrollObject has an event listener for the passed in event.

setPropertyAndFire

public void setPropertyAndFire(String name,
                               Object value)
Same behavior as setProperty(String, Object), but also invokes KrollProxyListener.propertyChanged(String, Object, Object, KrollProxy).

Parameters:
name - the property name.
value - the property value.

getProperties

public KrollDict getProperties()
Returns a KrollDict object that contains all current properties associated with this proxy.

Returns:
KrollDict properties object.

setModelListener

public void setModelListener(KrollProxyListener modelListener)
Associates this proxy with the passed in KrollProxyListener.

Parameters:
modelListener - the passed in KrollProxyListener.

resolveUrl

public String resolveUrl(String scheme,
                         String path)
Resolves the passed in scheme / path, and uses the Proxy's creationUrl if the path is relative.

Parameters:
scheme - the scheme of Url.
path - the path of Url.
Returns:
a string representation of URL given its components.

release

public void release()
Releases the KrollObject, freeing memory.



Copyright © 2010-2012 Appcelerator, Inc. Licensed under the Apache License 2.0