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

Java Open Source » Content Management System » webman 
webman » com » teamkonzept » webman » TKWMReferenceSelectorReg.java
/*
 * $Header: /cvsroot/webman-cms/source/webman/com/teamkonzept/webman/TKWMReferenceSelectorReg.java,v 1.10 2001/08/06 14:34:34 alex Exp $
 *
 */
package com.teamkonzept.webman;

import java.sql.*;

import com.teamkonzept.db.*;
import de.webman.generator.*;
import com.teamkonzept.webman.db.*;
import com.teamkonzept.webman.db.queries.*;
import com.teamkonzept.lib.*;

public class TKWMReferenceSelectorReg 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 TKWMReferenceSelector getSelector( String selectionType )
  {
    try {
      Object o = get(selectionType);
      //nicht nach System.out schreiben, da der vom Preview benoetigt wird!
      return (TKWMReferenceSelector) o;
    }
    catch( Throwable t ) {
      throw new Error( t.getMessage() );
    }
  }

  public boolean _check( String selectionType )
  {
    return getSelector( selectionType ).checkSelection( );
  }


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

  public TKDBResult _getValues( String selectionType, String selectionData, int siteNodeId )
  {
    TKDBResult v=null;
    try {
      v = getSelector( selectionType ).getSelectionValues( selectionData, siteNodeId );
    } catch (SQLException s) {
      throw new Error( s.getMessage() );
    }
    return v;
  }

  public TKVector _getNodes( String selectionType, String selectionData, int siteNodeId )
  {
    TKVector v=null;
    try {
      v = getSelector( selectionType ).getSelectionNodes( selectionData, siteNodeId );
    } catch (SQLException s) {
      throw new Error( s.getMessage() );
    }
    return v;
  }

  public void _reduceReferences(
    String selectionType,
    String selectionData,
    TKVector allRefUrls,
    TKVector allRefDocs,
    TKVector allRefNodes,
    GenNode currAnchor
  )
  {
    getSelector( selectionType ).reduceReferences(
      selectionData, allRefUrls, allRefDocs, allRefNodes, currAnchor
    );
  }

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

  public static final boolean check( String selectionType )
  {
    if( !initialized ) initialize();
    return registry._check( selectionType );
  }

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

  public static final TKDBResult getValues( String selectionType, String selectionData, int siteNodeId )
  {
    if( !initialized ) initialize();
    return registry._getValues( selectionType, selectionData, siteNodeId );
  }

  public static final TKDBResult getValues( String selectionType, int siteNodeId )
  {
    return getValues( selectionType, null, siteNodeId );
  }

  public static final TKVector getNodes( String selectionType, String selectionData, int siteNodeId )
  {
    if( !initialized ) initialize();
    return registry._getNodes( selectionType, selectionData, siteNodeId );
  }

  public static final TKVector getNodes( String selectionType, int siteNodeId )
  {
    return getNodes( selectionType, null, siteNodeId );
  }

  public static final void reduceReferences(
    String selectionType,
    String selectionData,
    TKVector allRefUrls,
    TKVector allRefDocs,
    TKVector allRefNodes,
    GenNode currAnchor
  )
  {
    if( !initialized ) initialize();
    registry._reduceReferences(
      selectionType,
      selectionData,
      allRefUrls,
      allRefDocs,
      allRefNodes,
      currAnchor
    );
  }

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

    initialized = true;
    registry = new TKWMReferenceSelectorReg();

    try {
      TKQuery q = TKWebmanDBManager.newQuery(TKDBRefSelClassGetAll.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.