📄 componentdefinition.java
字号:
/*
* $Id: ComponentDefinition.java 471754 2006-11-06 14:55:09Z husted $
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
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.tiles.xmlDefinition.XmlDefinition;
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 = null;
/**
* Component / template path (URL).
*/
protected String path = null;
/**
* Attributes defined for the component.
*/
protected Map attributes = null;
/**
* Role associated to definition.
*/
protected String role = null;
/** Associated Controller URL or classname, if defined */
protected String controller = null;
/**
* Associated Controller typename, if controllerName defined.
* Can be CONTROLLER, ACTION or URL, or null.
*/
protected String controllerType = null;
/**
* 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 = null;
/**
* 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(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 page 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);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -