package org.jucas;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/*
* License
*
*
* Copyright (c) 2003 Essl Christian. All rights
* reserved.
*
* This Licence is based on the Apache Software Licence Version 1.1.
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by Christian Essl
* and others for project Jucas (http://www.jucas.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Jucas" and "Christian Essl" must not be used to endorse or
* promote products derived from this software without prior written
* permission. For written permission, please contact essl_christian@jucas.
* org.
*
* 5. Products derived from this software may not be called "Jucas"
* or "Christian Essl", nor may "Jucas" or "Christian Essl"
* appear in their name, without prior written permission
* of Christian Essl (essl_christian@jucas.org).
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CHRISTIAN ESSL OR
* OTHER CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
*
*/
/**
* This class provides various servics to IJucasBeans. An instance of this
* class is given to each IJucasBean when it is setup.
* The services provided are:<br>
* 1.) encapsulated storing in session and request
* 2.) access to HttpServletRequest, Response and Context and to the BeanManager
* 3.) the possiblility to manage own child IJucasBeans.
* 4.) provide access to plugged in services
* Through the storage methods it is possible
* to enable some sort of data encapsulation in
* HttpServletRequest and HttpSession. The majority of methods in this
* class are storage methodes. Most important are the {@link #get(String, int)}
* {@link #getStatic(String, int)} {@link #put(String, int, Object)} {@link #putStatic(String, int, Object)}
* and the methods from which you can get a StorageValue:
* {@link #getStorageValue(String, int)} and {@link #getStaticStorageValue(String, int)}.
* The other storage methods are customizations for the primitiv Objects and String.
*
* <br><br>
* To store a value the BeanName is used to construct a key which than holds
* the value in Session or Request scope. A second type of key is produced for the static
* values. This static key is
* the same for the JucasType of the Instance (@link org.jucas.IJucasBean#getStaticType()} (normally
* the same for the same class). So all JucasBeans of the same type share the same variable set.
* According this class has two sets of identical methods where one ends with
* static. For all storage get methods BeanLinks are resolved before the value is
* returned<br><br>
*
* <b>Access to HttpServletRequest, Response, Context and the BeanManager</b><br>
* This access is provided through the correspondingt get methods.
* <br><br>
*
* <b>Services to manage own children:</b><br>
* Container (that are JucasBeans which have their own child JucasBeans) need to
* do certain operations on their child JucasBeans. Methods in here are needed if an IJucasBean
* wants to instantiate it's own IJucasBeans without using the BeanManager
* lookup. An IJucasBean (a Container) which does this has to use this Helper
* to fullfill the Framework contract on the instantiated IJucasBean which is
* normaly done by the BeanManager.<br><br>
*
* There are two contracts to full fill one with the bean that it is correctly
* setUp (the beanName and the helpers) and the second with the outside that the
* bean is reachable through the beanName.
* <br><br>
* The frist contract must be fullfilled. The second contract doesn't have to be fullfilled if the
* child IJucasBean never leaves (is never reachable) directly or indirectly the creating
* IJucasBean (Container).
* <br><br>
*
* The first contract is fullfilled if you call {@link #setUpNewBean(IJucasBean,String)}
* This may only and must be called on a new or freshly gotten from
* pool IJucasBean. The name given must be unique (no other before setup bean
* may have the same name) and it must be a valid property-path part (generally a java name and no '.').
* This name is appended with a trailing '.' to
* PropertyUtils part of the beanName of the container (the URI fragement). This
* way each IJucasBean gets a unique name, which is crucial for the working of
* the framework. As name all org.apache. commons.beanutils.PropertyUtil
* fragements are allowed (simple, indexed, mapped but not compound).
* <br><br>
* Belonging to the first contract is the method
* {@link #createChildJucasBean(String, URI)}. This method is used if you want to
* let the BeanManager through it's IPageBeanFactories create a IJucasBean. This
* is for IJucasBeans which are not fully defined by classes but rather by XML-
* Files like the JaulBeans. For the name the same thing holds. The second
* argument the uri names the Resource which defines the Bean. <br><br>
*
* The second contract means that the bean must also be reached by evaluating
* it's name through PropertyUtils therefore you must (if the Bean ever leaves this
* IJucasBean directly or indirectly) create Properties (getter Methods or
* implement Map or DynaProperties) in the container for each named IJucasBean
* setup.
* <br><br>
*
* For the second contract (and for the first) it is not necessery that the
* IJucasBeans are instantiated at initialization but. If a bean is asked and it
* has been instantiated with a name the same instance must be returned and if
* the IContainer is newly created an a Bean is asked the same Class must be
* returned and the instance must be as far equal so that tracings have the same
* effect.
*
* By calling the method {@link #getContainerStorageHelper()}. You will get an instance of
* ContainerStorageHelper. This instance will also keep the created child IJucasBeans in an Map and
* will ensure that the contract is fullfilled concerining the unique child beanNames.
*
* <br><br>
* <b>Access to pluged-in service:</b><br>
* If in the jucas-config.xml an plugged in Service is specified. An instance of the Service which
* is suitable for this the holding IJucasBean can be retrieved through the
* {@link #getService(Class)} or {@link #getService(String)} methods.
*
*
*
* @author chris
*/
public class JucasServices implements Serializable
{
transient private BeanManager beanManagerO = null;
private IJucasBean parent;
private URI beanName;
private IJucasBean myBean;
private String staticType;
private ContainerStorageHelper containerStorageHelper = null;
transient private Map services = null;
/**
* Constructor for BaseHelper.
*/
JucasServices(BeanManager beanManager,IJucasBean parent,URI beanName,IJucasBean myBean,String staticType)
{
super();
this.beanManagerO = beanManager;
this.parent = parent;
this.beanName = beanName;
this.myBean = myBean;
this.staticType = staticType;
}
/**
* this method returns the BeanManager
* @return BeanManager
*/
public final BeanManager getBeanManager(){
if(this.beanManagerO == null)
this.beanManagerO = BeanManager.getBeanManager();
return beanManagerO;
}
/**
* returns the name of the IJucasBean
* must be mapped out by the IJucasBean this JucasService belongs to.
* @return URI
*/
public URI getBeanName(){
return this.beanName;
}
/**
* returns the parent of the IJucasBean or null if it is a page bean.
* must be mapped out by the IJucasBean
* @return IContainer
*/
public IJucasBean getJucasParent(){
return this.parent;
}
///////////////////////////////////////
//Enviroment Helper
/**
* the current HttpServletRequest
*/
final public HttpServletRequest getHttpServletRequest(){
return getBeanManager().getHttpServletRequest();
}
/**
* the current HttpServletResponse
* @return HttpServletResponse
*/
final public HttpServletResponse getHttpServletResponse(){
return getBeanManager().getHttpServletResponse();
}
/**
* the current ServletContext
* @return ServletContext
*/
final public ServletContext getServletContext(){
return getBeanManager().getServletContext();
}
/////////////////////////////////////////////////
//Container Helper
/**
* returns the Bean this JucasService belongs to
*/
public IJucasBean getBelongingBean(){
return myBean;
}
/**
* constructs the child BeanName
* @param name
* @return URI
*/
URI getChildBeanName(String name)
{
URI childName = Conventions.getChildName(this.getBeanName(), name);
return childName;
}
/** see the calss description
*
* @param bean
* @param name
* @throws a JucasRuntimeException if setup went wrong
* @throws NullPointerException if an argumetn is missing
*/
public void setUpNewBean(IJucasBean bean,String name){
if(name == null)
throw new NullPointerException("Name is null");
if(bean == null)
throw new NullPointerException("Bean is null");
if(!(BeanManager.isJucasBeanSetup(bean))){
URI cName = this.getChildBeanName(name);
this.getBeanManager().setUpBean(bean, cName,this.getBelongingBean());
}else{
throw new IllegalArgumentException("The JaulBean is already set up");
}
}
/**
* see the class description
* @param name
* @param definingPageURI the pageBeanName which defines the Bean
* @return IJucasBean
* @throws JucasRuntimeException if setup went of child went wrong
* @throws IllegalArgumentException if the definingPageURI is no PageBean name
*/
public IJucasBean createChildJucasBean(String name,URI definingPageURI)
{
//make the new name
URI bN = this.getChildBeanName(name);
//make the bean using the beanManager
IJucasBean impl = ((BeanManager)this.getBeanManager()).createPageBean(bN, definingPageURI,this.myBean);
return impl;
}
/**
* If a bean you created is released by the Container (the container doesn't hold any reference to it
* anymore or the container implemnts itself IDestroyble and is destroyed) this method should be called
* to release the IJucasBaen. This is used for pooling of the bean etc.<br><br>
* It is recommended that you call in such cases this method however it is not demanded by the contract of
* IDestroyable.
* @param bean
* @throws IllegalArgumentException if the bean to destroy is no child bean
*/
public void destroyBean(IJucasBean bean){
//check if we are parent
if(bean.getJucasParent() != this.getBelongingBean())
throw new IllegalArgumentException("May only be called on childs");
if(bean instanceof IDestroyable)
BeanManager.destroyBean((IDestroyable)bean);
}
/**
* This method will if not yet present create a ContainerStorageHelper and return it.
* A ContainerStorageHelper is used for like the container methods in here to but also keeps
* them in a map.
* @return ContainerStorageHelper
*/
public ContainerStorageHelper getContainerStorageHelper(){
if(this.containerStorageHelper == null)
this.containerStorageHelper = new ContainerStorageHelper(this);
return this.containerStorageHelper;
}
//////////////////////////////////////////
//Storage things
/**
* returns the type used for static storage
* @return String
*/
public String getStaticType(){
return staticType;
}
/**
* this will always create a new
* {@link StorageValue} which points to in the value in here with the given
* name and sope in static values.
* @param name
* @param scope
* @return StorageValue
*/
public StorageValue getStaticStorageValue(String name,int scope){
return new StorageValue(this,this.makeStaticKey(name),name,scope);
}
/**
* this will always create a new
* {@link StorageValue} which point to the value in here with the given name
* and socpe and in the normal values (not static)
* @param name
* @param scope
* @return StorageValue
*/
public StorageValue getStorageValue(String name,int scope){
return new StorageValue(this,this.makeInstanceKey(name),name,scope);
}
//for storageValue
Object getHelper(String key,int scope){
Object ret = getBeanManager().getVar(key, scope);
ret = this.resolveBeanLink(ret);
return ret;
}
Object putHelper(String key,Object value,int scope){
value = this.checkJucasBean(value);
return getBeanManager().setVar(key, scope, value);
}
BeanLink importBeanHelper(String key, int scope, URI beanName,int requestedScope){
BeanLink link = new BeanLink(getBeanManager(),beanName,requestedScope);
this.putHelper(key, link, scope);
return link;
}
/**
* Gets the value with the given name from the given scope. BeanLink is
* resolved.
* @param name anay String even null
* @param scope Scopes.REQUEST, Scopes.SESSION
* @return Object
*/
public Object get(String name, int scope)
{
Object ret = getBeanManager().getVar(this.makeInstanceKey(name), scope);
ret = this.resolveBeanLink(ret);
return ret;
}
/**
* Seraches the value first in Request and than in Session. BeanLink is
* resolved.
* @param name
* @return Object
*/
public Object get(String name){
Object ret = getBeanManager().getVar(this.makeInstanceKey(name));
ret = this.resolveBeanLink(ret);
return ret;
}
/**
* Stores the value in the given scope under the given name.
* JucasBeans which are not in the same PageBean are automaticly converted
* to a BeanLink (see {@link #checkJucasBean(Object)}
* @param name any String
* @param scope Scopes.REQUEST, Scopes.RESPONSE
* @param ob the value to store
* @return Object the old value stored under the name
*/
public Object put(String name, int scope, Object ob)
{
ob = this.checkJucasBean(ob);
return getBeanManager().setVar(this.makeInstanceKey(name), scope, ob);
}
/**
* used to initialze the value. The value is set only if it is currently null.
* @param name
* @param scope
* @param value
*/
public void init(String name,int scope,Object value){
if(this.get(name, scope) == null)
this.put(name, scope, value);
}
/**
* imports a Bean (creates a BeanLink) and stores the BeanLink in the socpe
* @param name the var name
* @param scope Scopes.REQUEST Scopes.SESSION
* @param beanName the name of the Object to import
* @param requestedScope the scope into which the PageBean should be
* imported
* @return BeanLink returns teh BeanLink
*/
public BeanLink importBean(String name,int scope,URI beanName,int requestedScope){
BeanLink link = new BeanLink(getBeanManager(),beanName,requestedScope);
this.put(name, scope, link);
return link;
}
/**
* like get(String,scope). But gets with the type key, so that is accessible
* by all IJucasBeans with the same type
* @param name
* @param scope
* @return Object
*/
public Object getStatic(String name, int scope)
{
Object ret = getBeanManager().getVar(this.makeStaticKey(name), scope);
ret = this.resolveBeanLink(ret);
return ret;
}
/**
* like get(String) But gets with the type key, so that is accessible by all
* IJucasBeans with the same type
* @param name
* @return Object
*/
public Object getStatic(String name){
Object ret = getBeanManager().getVar(this.makeStaticKey(name));
ret = this.resolveBeanLink(ret);
return ret;
}
/**
* like put(name,int,ob) But store with the type key, so that is accessible
* by all IJucasBeans with the same type.<br><br> JucasBeans which are not
* in the same PageBean are automaticly converted to a BeanLink
* (see {@link #checkJucasBean(Object)})
* @param name
* @param scope
* @param ob
* @return Object
*/
public Object putStatic(String name, int scope, Object ob)
{
ob = this.checkJucasBean(ob);
return getBeanManager().setVar(this.makeStaticKey(name), scope, ob);
}
/**
* used to initalize. the value gets only set if it is currently null
* @param name
* @param scope
* @param ob
*/
public void initStatic(String name, int scope, Object ob){
if(this.getStatic(name, scope) == null)
this.putStatic(name, scope, ob);
}
/**
* Like importBean But store with the type key, so that is accessible by all
* IJucasBeans with the same type
* @param name
* @param scope
* @param beanName
* @param requestedScope
* @return BeanLink
*/
public BeanLink importBeanStatic(String name,int scope,URI beanName,int requestedScope){
BeanLink link = new BeanLink(getBeanManager(),beanName,requestedScope);
this.putStatic(name, scope, link);
return link;
}
private String makeInstanceKey(String name)
{
String key = Conventions.getStorageInstanceKey(this.beanName)+"|value|" + name;
return key;
}
private String makeStaticKey(String name)
{
String key = Conventions.getStorageStaticKey(this.staticType)+"|value|" + name;
return key;
}
/**
* Helper to check if an Object is a BeanLink and if so resolve it
* @param ret
* @return Object
*/
public Object resolveBeanLink(Object ret){
if(ret == null)
return ret;
if(ret instanceof BeanLink)
ret = ((BeanLink)ret).getBean();
return ret;
}
/**
* helper to chekc if the toPut is an IJucasBean. If so the Bean is checked
* wheter it is setup (in this case an illegal argument exception is
* thrown). If it is set up it is check wheter the bean belongs to the same
* PageBean (see {@link Conventions#isSameContainingPageBean(URI, URI)} if
* not a BeanLink is created and returned in all other cases the toPut
* parameter is returned.
*
* This method is used in all setting methods in this class to do the
* described check. It is public so that other users can use it too. Has no
* sideffects on this object.
* @param toPut
* @return Object
*/
public Object checkJucasBean(Object toPut){
if(toPut == null)
return null;
if(toPut instanceof IJucasBean){
if(!BeanManager.isJucasBeanSetup((IJucasBean)toPut))
throw new IllegalArgumentException("The JaulBean is not setup yet");
if(Conventions.isSameContainingPageBean(beanName, ((IJucasBean)toPut).getBeanName()))
return new BeanLink(getBeanManager(),(IJucasBean)toPut);
}
return toPut;
}
/////////////////////////
//Integer things
/**
* uses {@link #get(String, int)} to get an Integer
* @param defaultValue the value to return if get return null or not an
* Integer
*/
public int getInt(String name,int scope,int defaultValue){
Object gotten = this.get(name, scope);
if(gotten == null || !(gotten instanceof Integer))
return defaultValue;
return ((Integer)gotten).intValue();
}
/**
* uses {@link #get(String)} to get an Integer
* @param name
* @param defaultValue the value to return if the get retuns null or not an
* Iteger
* @return int
*/
public int getInt(String name,int defaultValue){
Object gotten = this.get(name);
if(gotten == null || !(gotten instanceof Integer))
return defaultValue;
return ((Integer)gotten).intValue();
}
/**
* uses {@link #put(String, int, Object)} to set an Integer
* @param name
* @param scope
* @param value
* @return Object
*/
public Object putInt(String name,int scope,int value){
return this.put(name, scope, new Integer(value));
}
/**
* uses {@link #getStatic(String, int)} to get an Integer
* @param name
* @param scope
* @param defaultValue the value returned if null or not an Integer is set
* @return int
*/
public int getStaticInt(String name,int scope,int defaultValue){
Object gotten = this.getStatic(name, scope);
if(gotten == null || !(gotten instanceof Integer))
return defaultValue;
return ((Integer)gotten).intValue();
}
/**
* uses {@link #getStatic(String)} to get an Integer
* @param name
* @param defaultValue the value returned if null or not an Integer is set
* @return int
*/
public int getStaticInt(String name,int defaultValue){
Object gotten = this.getStatic(name);
if(gotten == null || !(gotten instanceof Integer))
return defaultValue;
return ((Integer)gotten).intValue();
}
/**
* uses {@link #putStatic(String, int, Object)} to set an Integer
* @param name
* @param scope
* @param value
* @return Object
*/
public Object putStaticInt(String name,int scope,int value){
return this.put(name, scope, new Integer(value));
}
/////////////////////////
//Char things
/**
* uses {@link #get(String, char)} to get an Character
* @param defaultValue the value to return if get return null or not an
* Character
*/
public char getChar(String name,int scope,char defaultValue){
Object gotten = this.get(name, scope);
if(gotten == null || !(gotten instanceof Character))
return defaultValue;
return ((Character)gotten).charValue();
}
/**
* uses {@link #get(String)} to get an Character
* @param name
* @param defaultValue the value to return if the get retuns null or not an
* Iteger
* @return char
*/
public char getChar(String name,char defaultValue){
Object gotten = this.get(name);
if(gotten == null || !(gotten instanceof Character))
return defaultValue;
return ((Character)gotten).charValue();
}
/**
* uses {@link #put(String, char, Object)} to set an Character
* @param name
* @param scope
* @param value
* @return Object
*/
public Object putChar(String name,int scope,char value){
return this.put(name, scope, new Character(value));
}
/**
* uses {@link #getStatic(String, char)} to get an Character
* @param name
* @param scope
* @param defaultValue the value returned if null or not an Character is set
* @return char
*/
public char getStaticChar(String name,int scope,char defaultValue){
Object gotten = this.getStatic(name, scope);
if(gotten == null || !(gotten instanceof Character))
return defaultValue;
return ((Character)gotten).charValue();
}
/**
* uses {@link #getStatic(String)} to get an Character
* @param name
* @param defaultValue the value returned if null or not an Character is set
* @return char
*/
public char getStaticChar(String name,char defaultValue){
Object gotten = this.getStatic(name);
if(gotten == null || !(gotten instanceof Character))
return defaultValue;
return ((Character)gotten).charValue();
}
/**
* uses {@link #putStatic(String, char, Object)} to set an Character
* @param name
* @param scope
* @param value
* @return Object
*/
public Object putStaticChar(String name,int scope,char value){
return this.put(name, scope, new Character(value));
}
/////////////////////////
//Short things
/**
* uses {@link #get(String, short)} to get an Short
* @param defaultValue the value to return if get return null or not an
* Short
*/
public short getShort(String name,int scope,short defaultValue){
Object gotten = this.get(name, scope);
if(gotten == null || !(gotten instanceof Short))
return defaultValue;
return ((Short)gotten).shortValue();
}
/**
* uses {@link #get(String)} to get an Short
* @param name
* @param defaultValue the value to return if the get retuns null or not an
* Iteger
* @return short
*/
public short getShort(String name,short defaultValue){
Object gotten = this.get(name);
if(gotten == null || !(gotten instanceof Short))
return defaultValue;
return ((Short)gotten).shortValue();
}
/**
* uses {@link #put(String, short, Object)} to set an Short
* @param name
* @param scope
* @param value
* @return Object
*/
public Object putShort(String name,int scope,short value){
return this.put(name, scope, new Short(value));
}
/**
* uses {@link #getStatic(String, short)} to get an Short
* @param name
* @param scope
* @param defaultValue the value returned if null or not an Short is set
* @return short
*/
public short getStaticShort(String name,int scope,short defaultValue){
Object gotten = this.getStatic(name, scope);
if(gotten == null || !(gotten instanceof Short))
return defaultValue;
return ((Short)gotten).shortValue();
}
/**
* uses {@link #getStatic(String)} to get an Short
* @param name
* @param defaultValue the value returned if null or not an Short is set
* @return short
*/
public short getStaticShort(String name,short defaultValue){
Object gotten = this.getStatic(name);
if(gotten == null || !(gotten instanceof Short))
return defaultValue;
return ((Short)gotten).shortValue();
}
/**
* uses {@link #putStatic(String, short, Object)} to set an Short
* @param name
* @param scope
* @param value
* @return Object
*/
public Object putStaticShort(String name,int scope,short value){
return this.put(name, scope, new Short(value));
}
////////////////////////////////////////
//Long
/**
* uses {@link #get(String, int)} to get an Long
* @param defaultValue the value to return if get return null or not an
* Long
*/
public long getLong(String name,int scope,long defaultValue){
Object gotten = this.get(name, scope);
if(gotten == null || !(gotten instanceof Long))
return defaultValue;
return ((Long)gotten).longValue();
}
/**
* uses {@link #get(String)} to get an Long
* @param name
* @param defaultValue the value to return if the get retuns null or not an
* Iteger
* @return long
*/
public long getLong(String name,long defaultValue){
Object gotten = this.get(name);
if(gotten == null || !(gotten instanceof Long))
return defaultValue;
return ((Long)gotten).longValue();
}
/**
* uses {@link #put(String, int, Object)} to set an Long
* @param name
* @param scope
* @param value
* @return Object
*/
public Object putLong(String name,int scope,long value){
return this.put(name, scope, new Long(value));
}
/**
* uses {@link #getStatic(String, int)} to get an Long
* @param name
* @param scope
* @param defaultValue the value returned if null or not an Long is set
* @return long
*/
public long getStaticLong(String name,int scope,long defaultValue){
Object gotten = this.getStatic(name, scope);
if(gotten == null || !(gotten instanceof Long))
return defaultValue;
return ((Long)gotten).longValue();
}
/**
* uses {@link #getStatic(String)} to get an Long
* @param name
* @param defaultValue the value returned if null or not an Long is set
* @return long
*/
public long getStaticLong(String name,long defaultValue){
Object gotten = this.getStatic(name);
if(gotten == null || !(gotten instanceof Long))
return defaultValue;
return ((Long)gotten).longValue();
}
/**
* uses {@link #putStatic(String, int, Object)} to set an Long
* @param name
* @param scope
* @param value
* @return Object
*/
public Object putStaticInt(String name,int scope,long value){
return this.put(name, scope, new Long(value));
}
////////////////////////////////////////
//Float
/**
* uses {@link #get(String, int)} to get an Float
* @param defaultValue the value to return if get return null or not an
* Float
*/
public float getFloat(String name,int scope,float defaultValue){
Object gotten = this.get(name, scope);
if(gotten == null || !(gotten instanceof Float))
return defaultValue;
return ((Float)gotten).floatValue();
}
/**
* uses {@link #get(String)} to get an Float
* @param name
* @param defaultValue the value to return if the get retuns null or not an
* Iteger
* @return float
*/
public float getFloat(String name,float defaultValue){
Object gotten = this.get(name);
if(gotten == null || !(gotten instanceof Float))
return defaultValue;
return ((Float)gotten).floatValue();
}
/**
* uses {@link #put(String, int, Object)} to set an Float
* @param name
* @param scope
* @param value
* @return Object
*/
public Object putFloat(String name,int scope,float value){
return this.put(name, scope, new Float(value));
}
/**
* uses {@link #getStatic(String, int)} to get an Float
* @param name
* @param scope
* @param defaultValue the value returned if null or not an Float is set
* @return float
*/
public float getStaticFloat(String name,int scope,float defaultValue){
Object gotten = this.getStatic(name, scope);
if(gotten == null || !(gotten instanceof Float))
return defaultValue;
return ((Float)gotten).floatValue();
}
/**
* uses {@link #getStatic(String)} to get an Float
* @param name
* @param defaultValue the value returned if null or not an Float is set
* @return float
*/
public float getStaticFloat(String name,float defaultValue){
Object gotten = this.getStatic(name);
if(gotten == null || !(gotten instanceof Float))
return defaultValue;
return ((Float)gotten).floatValue();
}
/**
* uses {@link #putStatic(String, int, Object)} to set an Float
* @param name
* @param scope
* @param value
* @return Object
*/
public Object putStaticFloat(String name,int scope,float value){
return this.put(name, scope, new Float(value));
}
////////////////////////////////////////
//Double
/**
* uses {@link #get(String, int)} to get an Double
* @param defaultValue the value to return if get return null or not an
* Double
*/
public double getDouble(String name,int scope,double defaultValue){
Object gotten = this.get(name, scope);
if(gotten == null || !(gotten instanceof Double))
return defaultValue;
return ((Double)gotten).doubleValue();
}
/**
* uses {@link #get(String)} to get an Double
* @param name
* @param defaultValue the value to return if the get retuns null or not an
* Iteger
* @return double
*/
public double getDouble(String name,double defaultValue){
Object gotten = this.get(name);
if(gotten == null || !(gotten instanceof Double))
return defaultValue;
return ((Double)gotten).doubleValue();
}
/**
* uses {@link #put(String, int, Object)} to set an Double
* @param name
* @param scope
* @param value
* @return Object
*/
public Object putDouble(String name,int scope,double value){
return this.put(name, scope, new Double(value));
}
/**
* uses {@link #getStatic(String, int)} to get an Double
* @param name
* @param scope
* @param defaultValue the value returned if null or not an Double is set
* @return double
*/
public double getStaticDouble(String name,int scope,double defaultValue){
Object gotten = this.getStatic(name, scope);
if(gotten == null || !(gotten instanceof Double))
return defaultValue;
return ((Double)gotten).doubleValue();
}
/**
* uses {@link #getStatic(String)} to get an Double
* @param name
* @param defaultValue the value returned if null or not an Double is set
* @return double
*/
public double getStaticDouble(String name,double defaultValue){
Object gotten = this.getStatic(name);
if(gotten == null || !(gotten instanceof Double))
return defaultValue;
return ((Double)gotten).doubleValue();
}
/**
* uses {@link #putStatic(String, int, Object)} to set an Double
* @param name
* @param scope
* @param value
* @return Object
*/
public Object putStaticDouble(String name,int scope,double value){
return this.put(name, scope, new Double(value));
}
////////////////////////////////////////
//Boolean
/**
* uses {@link #get(String, int)} to get an Boolean
* @param defaultValue the value to return if get return null or not an
* Boolean
*/
public boolean getBoolean(String name,int scope,boolean defaultValue){
Object gotten = this.get(name, scope);
if(gotten == null || !(gotten instanceof Boolean))
return defaultValue;
return ((Boolean)gotten).booleanValue();
}
/**
* uses {@link #get(String)} to get an Boolean
* @param name
* @param defaultValue the value to return if the get retuns null or not an
* Iteger
* @return boolean
*/
public boolean getBoolean(String name,boolean defaultValue){
Object gotten = this.get(name);
if(gotten == null || !(gotten instanceof Boolean))
return defaultValue;
return ((Boolean)gotten).booleanValue();
}
/**
* uses {@link #put(String, int, Object)} to set an Boolean
* @param name
* @param scope
* @param value
* @return Object
*/
public Object putBoolean(String name,int scope,boolean value){
return this.put(name, scope, Boolean.valueOf(value));
}
/**
* uses {@link #getStatic(String, int)} to get an Boolean
* @param name
* @param scope
* @param defaultValue the value returned if null or not an Boolean is set
* @return boolean
*/
public boolean getStaticBoolean(String name,int scope,boolean defaultValue){
Object gotten = this.getStatic(name, scope);
if(gotten == null || !(gotten instanceof Boolean))
return defaultValue;
return ((Boolean)gotten).booleanValue();
}
/**
* uses {@link #getStatic(String)} to get an Boolean
* @param name
* @param defaultValue the value returned if null or not an Boolean is set
* @return boolean
*/
public boolean getStaticBoolean(String name,boolean defaultValue){
Object gotten = this.getStatic(name);
if(gotten == null || !(gotten instanceof Boolean))
return defaultValue;
return ((Boolean)gotten).booleanValue();
}
/**
* uses {@link #putStatic(String, int, Object)} to set an Boolean
* @param name
* @param scope
* @param value
* @return Object
*/
public Object putStaticBoolean(String name,int scope,boolean value){
return this.put(name, scope, Boolean.valueOf(value));
}
////////////////////////////////////////
//String
/**
* uses {@link #get(String, int)} to get an String
* @param defaultValue the value to return if get return null or not an
* String
*/
public String getString(String name,int scope,String defaultValue){
Object gotten = this.get(name, scope);
if(gotten == null || !(gotten instanceof String))
return defaultValue;
return ((String)gotten);
}
/**
* uses {@link #get(String)} to get an String
* @param name
* @param defaultValue the value to return if the get retuns null or not an
* Iteger
* @return String
*/
public String getString(String name,String defaultValue){
Object gotten = this.get(name);
if(gotten == null || !(gotten instanceof String))
return defaultValue;
return ((String)gotten);
}
/**
* uses {@link #put(String, int, Object)} to set an String
* @param name
* @param scope
* @param value
* @return Object
*/
public Object putString(String name,int scope,String value){
return this.put(name, scope, value);
}
/**
* uses {@link #getStatic(String, int)} to get an String
* @param name
* @param scope
* @param defaultValue the value returned if null or not an String is set
* @return String
*/
public String getStaticString(String name,int scope,String defaultValue){
Object gotten = this.getStatic(name, scope);
if(gotten == null || !(gotten instanceof String))
return defaultValue;
return ((String)gotten);
}
/**
* uses {@link #getStatic(String)} to get an String
* @param name
* @param defaultValue the value returned if null or not an String is set
* @return String
*/
public String getStaticString(String name,String defaultValue){
Object gotten = this.getStatic(name);
if(gotten == null || !(gotten instanceof String))
return defaultValue;
return ((String)gotten);
}
/**
* uses {@link #putStatic(String, int, Object)} to set an String
* @param name
* @param scope
* @param value
* @return Object
*/
public Object putStaticString(String name,int scope,String value){
return this.put(name, scope, value);
}
//////////////////////////////////////////
//Plugin services
/**
* This method will get the plugin Service which is produced for this
* IJucasBean.
* @param serviceFactory the class of the IServiceFactory from which the service should be gotten
* @return Object the service (depends) on the service factory or null if the ServiceFactory does not exist
* @throws JucasRuntimeException if the ServiceFactory throws some Exception
* @see IServiceFactory
*/
public Object getService(Class serviceFactory){
return this.getService(serviceFactory.getName());
}
/**
* Same as {@link #getService(Class)} only that instead of the class the className is given
* @param serviceFactoryClassName
* @return Object
* @throws NullPointerException if the argumetn is not provided
*/
public Object getService(String serviceFactoryClassName){
if(serviceFactoryClassName == null)
throw new NullPointerException("Must provide a service name");
//first get the services map
if(this.services == null){
this.services = new HashMap();
}
Object serv = this.services.get(serviceFactoryClassName);
if(serv != null)
return serv;
//try to construct the service
IServiceFactory fact = RequestManagerFilter.getServiceFactory(serviceFactoryClassName);
if(fact == null)
return null;
serv = fact.createServiceFor(this);
if(serv == null)
return serv;
//keep the service
this.services.put(serviceFactoryClassName, serv);
return serv;
}
}
|