⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readcontext.java

📁 JAVA 文章管理系统源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	  * otherwise the full element name. Not null
	  */
	public void pushElement(String elementName) throws Exception {

		elementMappingStack.push(elementName);
		// special case to ensure that root class is appropriately marked
		//TODO: is this really necessary?
        ElementDescriptor nextDescriptor = null;
		if (elementMappingStack.size() == 1 && rootClass != null) {
			markClassMap(rootClass);
            XMLBeanInfo rootClassInfo 
                = getXMLIntrospector().introspect(rootClass);
            nextDescriptor = rootClassInfo.getElementDescriptor();
		} else {
            ElementDescriptor currentDescriptor = getCurrentDescriptor();
            if (currentDescriptor != null) {
                nextDescriptor = currentDescriptor.getElementDescriptor(elementName);
            }
        }
        Updater updater = null;
        if (nextDescriptor != null) {
            updater = nextDescriptor.getUpdater();
        }
        updaterStack.push(updater);
        descriptorStack.push(nextDescriptor);
	}

	/**
	  * Marks the element name stack with a class mapping.
	  * Relative paths and last mapped class are calculated using these marks.
	  * 
	  * @param mappedClazz the Class which has been mapped at the current path, not null
	  */
	public void markClassMap(Class mappedClazz) throws IntrospectionException {
        if (mappedClazz.isArray()) {
            mappedClazz = mappedClazz.getComponentType();
        }
		elementMappingStack.push(mappedClazz);
        
        XMLBeanInfo mappedClassInfo = getXMLIntrospector().introspect(mappedClazz);
        ElementDescriptor mappedElementDescriptor = mappedClassInfo.getElementDescriptor();
        descriptorStack.push(mappedElementDescriptor);
        
        Updater updater = mappedElementDescriptor.getUpdater();
        updaterStack.push(updater);
	}

	/**
	 * Pops an action mapping from the stack
	 * @return
	 */
	public MappingAction popMappingAction() {
		return (MappingAction) actionMappingStack.pop();
	}

	/**
	 * Pushs an action mapping onto the stack
	 * @param mappingAction
	 */
	public void pushMappingAction(MappingAction mappingAction) {
		actionMappingStack.push(mappingAction);
	}

	/**
	 * Gets the current mapping action
	 * @return MappingAction 
	 */
	public MappingAction currentMappingAction() {
		if (actionMappingStack.size() == 0)
		{
			return null;	
		}
		return (MappingAction) actionMappingStack.peek();
	}

	public Object getBean() {
		return objectStack.peek();
	}

	public void setBean(Object bean) {
		// TODO: maybe need to deprecate the set bean method
		// and push into subclass
		// for now, do nothing		
	}

    /**
     * Pops the last mapping <code>Object</code> from the 
     * stack containing beans that have been mapped.
     * @return 
     */
	public Object popBean() {
		return objectStack.pop();
	}

    /**
     * Pushs a newly mapped <code>Object</code> onto the mapped bean stack.
     * @param bean
     */
	public void pushBean(Object bean) {
		objectStack.push(bean);
	}

    /**
     * Gets the <code>XMLIntrospector</code> to be used to create
     * the mappings for the xml.
     * @return <code>XMLIntrospector, not null
     */
	public XMLIntrospector getXMLIntrospector() {
        // read context is not intended to be used by multiple threads
        // so no need to worry about lazy creation
        if (xmlIntrospector == null) {
            xmlIntrospector = new XMLIntrospector();
        }
		return xmlIntrospector;
	}

    /**
     * Sets the <code>XMLIntrospector</code> to be used to create
     * the mappings for the xml.
     * @param xmlIntrospector <code>XMLIntrospector</code>, not null
     */
	public void setXMLIntrospector(XMLIntrospector xmlIntrospector) {
		this.xmlIntrospector = xmlIntrospector;
	}

	public Class getRootClass() {
		return rootClass;
	}

	public void setRootClass(Class rootClass) {
		this.rootClass = rootClass;
	}

    /**
     * Gets the <code>ElementDescriptor</code> that describes the
     * mapping for the current element.
     * @return <code>ElementDescriptor</code> or null if there is no
     * current mapping
     * @throws Exception
     */
	public ElementDescriptor getCurrentDescriptor() throws Exception {
		ElementDescriptor result = null;
        if (!descriptorStack.empty()) {
            result = (ElementDescriptor) descriptorStack.peek();
        }
		return result;
	}
    
    /**
     * Populates the object mapped by the <code>AttributeDescriptor</code>s
     * with the values in the given <code>Attributes</code>.
     * @param attributeDescriptors <code>AttributeDescriptor</code>s, not null
     * @param attributes <code>Attributes</code>, not null
     */
	public void populateAttributes(
		AttributeDescriptor[] attributeDescriptors,
		Attributes attributes) {

		Log log = getLog();
		if (attributeDescriptors != null) {
			for (int i = 0, size = attributeDescriptors.length;
				i < size;
				i++) {
				AttributeDescriptor attributeDescriptor =
					attributeDescriptors[i];

				// The following isn't really the right way to find the attribute
				// but it's quite robust.
				// The idea is that you try both namespace and local name first
				// and if this returns null try the qName.
				String value =
					attributes.getValue(
						attributeDescriptor.getURI(),
						attributeDescriptor.getLocalName());

				if (value == null) {
					value =
						attributes.getValue(
							attributeDescriptor.getQualifiedName());
				}

				if (log.isTraceEnabled()) {
					log.trace("Attr URL:" + attributeDescriptor.getURI());
					log.trace(
						"Attr LocalName:" + attributeDescriptor.getLocalName());
					log.trace(value);
				}

				Updater updater = attributeDescriptor.getUpdater();
				log.trace(updater);
				if (updater != null && value != null) {
					updater.update(this, value);
				}
			}
		}
	}

    /**
     * <p>Pushes an <code>Updater</code> onto the stack.</p>
     * <p>
     * <strong>Note</strong>Any action pushing an <code>Updater</code> onto
     * the stack should take responsibility for popping
     * the updater from the stack at an appropriate time.
     * </p>
     * <p>
     * <strong>Usage:</strong> this may be used by actions
     * which require a temporary object to be updated.
     * Pushing an updater onto the stack allow actions
     * downstream to transparently update the temporary proxy.
     * </p>
     * @param updater Updater, possibly null
     */
    public void pushUpdater(Updater updater) {
        updaterStack.push(updater);
    }
    
    /**
     * Pops the top <code>Updater</code> from the stack.
     * <p>
     * <strong>Note</strong>Any action pushing an <code>Updater</code> onto
     * the stack should take responsibility for popping
     * the updater from the stack at an appropriate time.
     * </p>
     * @return <code>Updater</code>, possibly null
     */
    public Updater popUpdater() {
        return (Updater) updaterStack.pop();
    }

    /**
     * Gets the current <code>Updater</code>.
     * This may (or may not) be the updater for the current
     * descriptor.
     * If the current descriptor is a bean child,
     * the the current updater will (most likely) 
     * be the updater for the property.
     * Actions (that, for example, use proxy objects)
     * may push updaters onto the stack.
     * @return Updater, possibly null
     */
    public Updater getCurrentUpdater() {
        // TODO: think about whether this is right
        //       it makes some sense to look back up the 
        //       stack until a non-empty updater is found.
        //       actions who need to put a stock to this 
        //       behaviour can always use an ignoring implementation. 
        Updater result = null;
        if (!updaterStack.empty()) {
            result = (Updater) updaterStack.peek();
            if ( result == null && updaterStack.size() >1 ) {
                result = (Updater) updaterStack.peek(1);
            }
        }
        return result;  
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -