/*
* $Id: AnySearchResult.java,v 1.7 2002/09/16 08:05:03 jkl Exp $
*
* Copyright (c) 2002 Njet Communications Ltd. All Rights Reserved.
*
* Use is subject to license terms, as defined in
* Anvil Sofware License, Version 1.1. See LICENSE
* file, or http://njet.org/license-1.1.txt
*/
package anvil.core.naming;
import javax.naming.NamingException;
import javax.naming.NameClassPair;
import javax.naming.Binding;
import javax.naming.directory.SearchResult;
import javax.naming.directory.Attributes;
import anvil.core.Any;
import anvil.core.AnyAbstractClass;
import anvil.core.IndexedEnumeration;
import anvil.java.util.BindingEnumeration;
import anvil.script.Context;
/// @class SearchResult
/**
* class AnySearchResult
*
* @author: Simo Tuokko
* @author: Jani Lehtim�ki
*/
public class AnySearchResult extends AnyAbstractClass
{
public static final anvil.script.compiler.NativeClass __class__ =
new anvil.script.compiler.NativeClass("SearchResult", AnySearchResult.class,
//DOC{{
""+
" @class SearchResult\n" +
" @method getClassName\n" +
" @synopsis string getClassName()\n" +
" @method setClassName\n" +
" @synopsis Attribute setClassName(string className)\n" +
" @method setName\n" +
" @synopsis Attribute setName(string name)\n" +
" @method getName\n" +
" @synopsis string getName()\n" +
" @method getValue\n" +
" @synopsis object getValue()\n" +
" @method setValue\n" +
" @synopsis Attribute setValue(object value)\n" +
" @method isRelative\n" +
" @synopsis boolean isRelative()\n" +
" @method setRelative\n" +
" @synopsis SearchResult setRelative(boolean isRelative)\n" +
" @method getAttributes\n" +
" @synopsis Attributes getAttributes()\n" +
" @method setAttributes\n" +
" @synopsis Attribute setAttributes(Attributes attributes)\n"
//}}DOC
);
static {
NamingModule.class.getName();
}
private NameClassPair _result;
public AnySearchResult(NameClassPair nameclass)
{
_result = nameclass;
}
public AnySearchResult(Binding binding)
{
_result = binding;
}
public AnySearchResult(SearchResult searchresult)
{
_result = searchresult;
}
public anvil.script.ClassType classOf()
{
return __class__;
}
public Object toObject()
{
return _result;
}
public Any getAttribute(Context context, String attribute)
{
if (attribute.equalsIgnoreCase("name")) {
return Any.create(_result.getName());
}
if (attribute.equalsIgnoreCase("value")) {
if (_result instanceof Binding) {
return Any.create(((Binding)_result).getObject());
} else {
return Any.create(_result.getClassName());
}
}
return UNDEFINED;
}
public Any getReference(Context context, Any index)
{
switch(index.toInt()) {
case 0:
return Any.create(_result.getName());
case 1:
if (_result instanceof Binding) {
return Any.create(((Binding)_result).getObject());
} else {
return Any.create(_result.getClassName());
}
default:
return UNDEFINED;
}
}
/// @method getClassName
/// @synopsis string getClassName()
public Any m_getClassName(anvil.script.Context context, Any[] parameters)
{
return Any.create(_result.getClassName());
}
/// @method setClassName
/// @synopsis Attribute setClassName(string className)
public Any m_setClassName(anvil.script.Context context, Any[] parameters)
{
if (parameters.length < 1) {
throw parametersMissing(context, "setClassName");
}
_result.setClassName(parameters[0].toString());
return NULL;
}
/// @method setName
/// @synopsis Attribute setName(string name)
public Any m_setName(anvil.script.Context context, Any[] parameters)
{
if (parameters.length < 1) {
throw parametersMissing(context, "setName");
}
_result.setName(parameters[0].toString());
return this;
}
/// @method getName
/// @synopsis string getName()
public Any m_getName(anvil.script.Context context, Any[] parameters)
{
return Any.create(_result.getName());
}
/// @method getValue
/// @synopsis object getValue()
public Any m_getValue(anvil.script.Context context, Any[] parameters)
{
if (_result instanceof Binding) {
return Any.create(((Binding)_result).getObject());
} else {
return Any.create(_result.getClassName());
}
}
/// @method setValue
/// @synopsis Attribute setValue(object value)
public Any m_setValue(anvil.script.Context context, Any[] parameters)
{
if (parameters.length < 1) {
throw parametersMissing(context, "setValue");
}
if (_result instanceof Binding) {
((Binding)_result).setObject(parameters[0].toObject());
}
return this;
}
/// @method isRelative
/// @synopsis boolean isRelative()
public Any m_isRelative(anvil.script.Context context, Any[] parameters)
{
return Any.create(_result.isRelative());
}
/// @method setRelative
/// @synopsis SearchResult setRelative(boolean isRelative)
public Any m_setRelative(anvil.script.Context context, Any[] parameters)
{
if (parameters.length < 1) {
throw parametersMissing(context, "setRelative");
}
_result.setRelative(parameters[0].toBoolean());
return this;
}
/// @method getAttributes
/// @synopsis Attributes getAttributes()
public Any m_getAttributes(anvil.script.Context context, Any[] parameters)
{
if (_result instanceof SearchResult) {
return new AnyAttributes(((SearchResult)_result).getAttributes());
}
return UNDEFINED;
}
/// @method setAttributes
/// @synopsis Attribute setAttributes(Attributes attributes)
public Any m_setAttributes(anvil.script.Context context, Any[] parameters)
{
if (parameters.length < 1) {
throw parametersMissing(context, "setAttributes");
}
if (_result instanceof SearchResult) {
Any param = parameters[0];
if (!(param instanceof AnyAttributes)) {
((SearchResult)_result).setAttributes((Attributes)param.toObject());
} else {
throw context.BadParameter("Attributes expected");
}
}
return this;
}
}