TKWMContentSelectorReg.java :  » Content-Management-System » webman » com » teamkonzept » webman » Java Open Source

Java Open Source » Content Management System » webman 
webman » com » teamkonzept » webman » TKWMContentSelectorReg.java
package com.teamkonzept.webman;

import com.teamkonzept.web.*;
import com.teamkonzept.webman.db.*;
import com.teamkonzept.webman.db.queries.*;
import com.teamkonzept.db.*;
import com.teamkonzept.lib.*;

import java.sql.*;

public class TKWMContentSelectorReg extends TKClassRegistry {

  protected TKHashtable resultTypes = new TKHashtable();

  public void registerClass( String selectionType, String selectionClass, int resultType )
  {
    super.registerClass( selectionType, selectionClass );
    resultTypes.put( selectionType, Integer.toString( resultType ) );
  }

  public final TKWMContentSelector getSelector( String selectionType )
  {
    try {
      return (TKWMContentSelector) get( selectionType );
    }
    catch( Throwable t ) {
      throw new Error( t.getMessage() );
    }
  }

  public void _edit( TKHTMLTemplate t, String selectionType, int contentNodeId, String selectionData )
  {
    String resultType = (String) resultTypes.get( selectionType );
    TKHashtable dummyParams = new TKHashtable(4);
    dummyParams.put( "SEL_TYPE", selectionType );
    dummyParams.put( "RES_TYPE", resultType );
    dummyParams.put( "NODE_ID", Integer.toString( contentNodeId ) );
    if( selectionData != null ) dummyParams.put( "SEL_DATA", selectionData );

    _modify( t, selectionType, TKWMContentSelector.ACTION_INIT, dummyParams );
  }

  public void _modify( TKHTMLTemplate t, String selectionType, String action, TKHashtable params )
  {
    getSelector( selectionType ).modifySelection( t, action, params );
  }

  public String _getData( String selectionType, TKHashtable params )
  {
    return getSelector( selectionType ).getSelectionData( params );
  }

  public TKVector _select( String selectionType, String selectionData, int contentNodeId )
  {
    return getSelector( selectionType ).doSelection( selectionData, contentNodeId );
  }

  //*******************************************************************
  protected static TKWMContentSelectorReg registry = null;
  protected static boolean initialized = false;

  public static final void edit( TKHTMLTemplate t, String selectionType, int contentNodeId, String selectionData )
  {
    if( !initialized ) initialize();
    registry._edit( t, selectionType, contentNodeId, selectionData );
  }

  public static final void edit( TKHTMLTemplate t, String selectionType, int contentNodeId )
  {
    edit( t, selectionType, contentNodeId, null );
  }

  public static final void modify( TKHTMLTemplate t, String selectionType, String action, TKHashtable params )
  {
    if( !initialized ) initialize();
    registry._modify( t, selectionType, action, params );
  }

  public static final String getData( String selectionType, TKHashtable params )
  {
    if( !initialized ) initialize();
    return registry._getData( selectionType, params );
  }

  public static final TKVector select( String selectionType, String selectionData, int contentNodeId )
  {
    if( !initialized ) initialize();
    return registry._select( selectionType, selectionData, contentNodeId );
  }

  public static final synchronized void initialize()
  {
    if( initialized ) return;

    initialized = true;
    registry = new TKWMContentSelectorReg();

    try {
      TKQuery q = TKWebmanDBManager.newQuery(TKDBContSelClassGetAll.class);
      q.execute();
      ResultSet rs = q.fetchResultSet();

      while( rs.next() ) {
        registry.registerClass(
          rs.getString("SELECTION_TYPE"),
          rs.getString("SELECTION_CLASS"),
          rs.getInt("RESULT_TYPE")
        );
      }
    }
    catch( SQLException e ) {
      throw new TKSQLError( e.getMessage(), e );
    }
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.