001    package echopoint;
002    
003    import echopoint.internal.TextFieldPeer;
004    import echopoint.RegexTextField;
005    import nextapp.echo.app.Component;
006    import nextapp.echo.app.util.Context;
007    import nextapp.echo.webcontainer.ServerMessage;
008    import nextapp.echo.webcontainer.Service;
009    import static nextapp.echo.webcontainer.WebContainerServlet.getServiceRegistry;
010    import static nextapp.echo.webcontainer.service.JavaScriptService.forResource;
011    
012    /**
013     * <p>&copy; Copyright 2009 <a href='http://sptci.com/' target='_top'>Sans
014     * Pareil Technologies, Inc.</a></p>
015     *
016     * @author Rakesh Vidyadharan 2009-03-07
017     * @version $Id: RegexTextFieldPeer.java 258 2009-12-07 16:18:24Z sptrakesh $
018     */
019    public class RegexTextFieldPeer extends TextFieldPeer
020    {
021      /** The name of the component for which this class is a peer. */
022      private static final String COMPONENT_NAME = RegexTextField.class.getName();
023    
024      /** The service for the client side peer for this component. */
025      private static final Service COMPONENT_SERVICE = forResource( COMPONENT_NAME,
026          "resource/js/Sync.RegexTextField.js" );
027    
028      /** Register the services */
029      static
030      {
031        getServiceRegistry().add( COMPONENT_SERVICE );
032      }
033    
034      public RegexTextFieldPeer()
035      {
036        super();
037        addOutputProperty(RegexTextField.PROPERTY_REGEX);
038      }
039    
040      /**
041       * {@inheritDoc}
042       * @see nextapp.echo.webcontainer.AbstractComponentSynchronizePeer#init
043       */
044      @Override
045      public void init( final Context context, final Component component )
046      {
047        super.init( context, component );
048        final ServerMessage serverMessage =
049            (ServerMessage) context.get( ServerMessage.class );
050        serverMessage.addLibrary( COMPONENT_NAME );
051      }
052    
053      /**
054       * {@inheritDoc}
055       * @see nextapp.echo.webcontainer.AbstractComponentSynchronizePeer#getComponentClass
056       */
057      @Override
058      public Class getComponentClass()
059      {
060        return RegexTextField.class;
061      }
062    
063      /**
064       * {@inheritDoc}
065       * @see nextapp.echo.webcontainer.AbstractComponentSynchronizePeer#getClientComponentType
066       */
067      public String getClientComponentType( final boolean shortType )
068      {
069        return COMPONENT_NAME;
070      }
071    
072      @Override
073      public Object getOutputProperty(Context context, Component component, String propertyName, int propertyIndex) 
074      {
075        if( propertyName.equals(RegexTextField.PROPERTY_REGEX) ) 
076          return ((RegexTextField)component).getRegex();
077        else 
078          return super.getOutputProperty(context, component, propertyName, propertyIndex);
079      }
080    }