📄 componentdefinition.java
字号:
/*
* $Header: /sfroot/cvs/esimple/src/core/org/apache/struts/tiles/ComponentDefinition.java,v 1.1.1.1 2004/09/08 06:38:36 lava Exp $
* $Revision: 1.1.1.1 $
* $Date: 2004/09/08 06:38:36 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2003 The Apache Software Foundation. All rights
* reserved.
*
* 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 acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Struts", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* 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 THE APACHE SOFTWARE FOUNDATION OR
* ITS 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 software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.struts.tiles;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.util.RequestUtils;
/**
* Definition of a template / component attributes.
* Attributes of a component can be defined with the help of this class.
* An instance of this class can be used as a bean, and passed to 'insert' tag.
*/
public class ComponentDefinition implements Serializable
{
/** Commons Logging instance. */
protected static Log log = LogFactory.getLog(ComponentDefinition.class);
/**
* Definition name
*/
protected String name;
/**
* Component / template path (URL).
*/
protected String path;
/**
* Attributes defined for the component.
*/
protected Map attributes;
/** role associated to definition */
protected String role;
/** Associated Controller URL or classname, if defined */
protected String controller;
/** Associated Controller typename, if controllerName defined.
* Can be CONTROLLER, ACTION or URL, or null */
protected String controllerType;
/** Controller name type */
public static final String URL = "url";
/** Controller name type */
public static final String CONTROLLER = "controller";
/** Controller name type */
public static final String ACTION = "action";
/**
* Controller associated to Definition.
* Lazy creation : only on first request
*/
private Controller controllerInstance;
/**
* Constructor.
*/
public ComponentDefinition()
{
attributes = new HashMap();
}
/**
* Copy Constructor.
* Create a new definition initialized with parent definition.
* Do a shallow copy : attributes are shared between copies, but not the Map
* containing attributes.
*/
public ComponentDefinition( ComponentDefinition definition )
{
attributes = new HashMap( definition.getAttributes() );
this.name = definition.getName();
this.path = definition.getPath();
this.role = definition.getRole();
this.controllerInstance = definition.getControllerInstance();
this.controller = definition.getController();
this.controllerType = definition.getControllerType();
}
/**
* Constructor.
* Create a new definition initialized from a RawDefinition.
* Raw definitions are used to read definition from a data source (xml file, db, ...).
* A RawDefinition mainly contains properties of type String, while Definition
* contains more complex type (ex : Controller).
* Do a shallow copy : attributes are shared between objects, but not the Map
* containing attributes.
* OO Design issues : Actually RawDefinition (XmlDefinition) extends ComponentDefinition.
* This must not be the case. I have do it because I am lazy.
* @throws InstantiationException if an error occur while instanciating Controller :
* (classname can't be instanciated, Illegal access with instanciated class,
* Error while instanciating class, classname can't be instanciated.
*/
public ComponentDefinition( org.apache.struts.tiles.xmlDefinition.XmlDefinition definition )
{
this((ComponentDefinition)definition);
}
/**
* Constructor.
*/
public ComponentDefinition( String name, String path, Map attributes )
{
this.name = name;
this.path = path;
this.attributes = attributes;
}
/**
* Access method for the name property.
*
* @return the current value of the name property
*/
public String getName() {
return name;}
/**
* Sets the value of the name property.
*
* @param aName the new value of the name property
*/
public void setName(String aName) {
name = aName;}
/**
* Access method for the path property.
*
* @return the current value of the path property
*/
public String getPage()
{
return path;
}
/**
* Sets the value of the path property.
*
* @param aPath the new value of the path property
*/
public void setPage(String page)
{
path = page;
}
/**
* Access method for the path property.
*
* @return the current value of the path property
*/
public String getPath()
{
return path;
}
/**
* Sets the value of the path property.
*
* @param aPath the new value of the path property
*/
public void setPath(String aPath)
{
path = aPath;
}
/**
* Access method for the template property.
* Same as getPath()
* @return the current value of the template property
*/
public String getTemplate()
{
return path;
}
/**
* Sets the value of the template property.
* Same as setPath()
*
* @param template the new value of the path property
*/
public void setTemplate(String template)
{
path = template;
}
/**
* Access method for the role property.
* @return the current value of the role property
*/
public String getRole()
{
return role;
}
/**
* Sets the value of the role property.
*
* @param role the new value of the path property
*/
public void setRole(String role)
{
this.role = role;
}
/**
* Access method for the attributes property.
* If there is no attributes, return an empty map.
* @return the current value of the attributes property
*/
public Map getAttributes()
{
return attributes;
}
/**
* Returns the value of the named attribute as an Object, or null if no
* attribute of the given name exists.
*
* @return requested attribute or null if not found
*/
public Object getAttribute(String key)
{
return attributes.get( key);
}
/**
* Put a new attribute in this component
*
* @param key String key for attribute
* @param value Attibute value.
*/
public void putAttribute(String key, Object value)
{
attributes.put( key, value );
}
/**
* Put an attribute in component / template definition.
* Attribute can be used as content for tag get.
* @param name Attribute name
* @param content Attribute value
*/
public void put(String name, Object content)
{
put(name, content, false, null );
}
/**
* Put an attribute in template definition.
* Attribute can be used as content for tag get.
* @param name Attribute name
* @param content Attribute value
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -