Package anvil.core.system

Source Code of anvil.core.system.AnyEnvelope

/*
* $Id: AnyEnvelope.java,v 1.16 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.system;

import anvil.core.Any;
import anvil.core.AnyAbstractClass;
import anvil.core.runtime.AnyScope;
import anvil.core.time.AnyCalendar;
import anvil.script.compiler.CompiledModule;
import anvil.script.Context;
import anvil.script.Module;
import anvil.script.ModuleEnvelope;
import anvil.server.Address;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

/// @class Envelope
/// Envelope represents compiled script in server's cache.

/**
* class AnyEnvelope
*
* @author: Jani Lehtim�ki
*/
public class AnyEnvelope extends AnyAbstractClass
{



  public static anvil.core.RuntimePermission CAN_READ  = new anvil.core.RuntimePermission("anvil.system.Envelope", false);
  public static anvil.core.RuntimePermission CAN_WRITE = new anvil.core.RuntimePermission("anvil.system.Envelope", true);

 
  private ModuleEnvelope _envelope;

 
  public AnyEnvelope(ModuleEnvelope envelope)
  {
    _envelope = envelope;
  }
 

  public final anvil.script.ClassType classOf()
  {
    return __class__;
  }

 
  public String toString()
  {
    return "Envelope(" + _envelope.getAddress() + ")";
  }
 
 
  public Object toObject()
  {
    return _envelope;
  }
 

  /// @method getPathinfo
  /// Returns the pathinfo for this envelope.
  /// @synopsis string getPathinfo()
  public Any m_getPathinfo(Context context)
  {
    return Any.create(_envelope.getAddress().getPathinfo());
  }

  /// @method getHostname
  /// Returns the name of domain for this envelope.
  /// @synopsis string getHostname()
  public Any m_getHostname(Context context)
  {
    return Any.create(_envelope.getAddress().getHostname());
  }



  /// @method getLastModified
  /// Returns the time of last modification for this envelope.
  /// @synopsis Calendar getLastModified()
  public Any m_getLastModified(Context context)
  {
    TimeZone tz = context.getTimeZone();
    Locale lc = context.getLocale();
    Calendar cal = Calendar.getInstance(tz, lc);
    cal.setTime(new Date(_envelope.getLastModified()));
    return new anvil.core.time.AnyCalendar(cal);
  }

 
  /// @method getModule
  /// Returns the compiled script for this envelope.
  /// @synopsis Scope getModule()
  /// @throws AccessDenied if security policy denies this operation
  public Any m_getModule(Context context)
  {
    Module script = _envelope.getModule();
    context.checkImport(script.getPathinfo());
    return new anvil.core.runtime.AnyScope(script);
  }

 
 
  /// @method purge
  /// Removes this envelope from cache.
  /// @synopsis void purge()
  /// @throws AccessDenied if security policy denies this operation
  public Any m_purge(Context context)
  {
    context.checkAccess(CAN_WRITE);
    Address addr = _envelope.getAddress();
    addr.getServer().getCache().purge(addr);
    return this;
  }


  public static final anvil.script.compiler.NativeClass __class__ =
    new anvil.script.compiler.NativeClass("Envelope", AnyEnvelope.class,
    //DOC{{
    ""+
      " @class Envelope\n" +
      " Envelope represents compiled script in server's cache.\n" +
      " @method getPathinfo\n" +
      " Returns the pathinfo for this envelope.\n" +
      " @synopsis string getPathinfo()\n" +
      " @method getHostname\n" +
      " Returns the name of domain for this envelope.\n" +
      " @synopsis string getHostname()\n" +
      " @method getLastModified\n" +
      " Returns the time of last modification for this envelope.\n" +
      " @synopsis Calendar getLastModified()\n" +
      " @method getModule\n" +
      " Returns the compiled script for this envelope.\n" +
      " @synopsis Scope getModule()\n" +
      " @throws AccessDenied if security policy denies this operation\n" +
      " @method purge\n" +
      " Removes this envelope from cache.\n" +
      " @synopsis void purge()\n" +
      " @throws AccessDenied if security policy denies this operation\n"
    //}}DOC
    );
  static {
    SystemModule.class.getName();
  }
 
}
TOP

Related Classes of anvil.core.system.AnyEnvelope

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.