maparraytyperule.java

来自「一个完整的XACML工程,学习XACML技术的好例子!」· Java 代码 · 共 81 行

JAVA
81
字号
/*
 * MapArrayTypeRule.java
 *
 * Created on 29 May 2003, 12:18
 */

package ke.defaultimpl.utils.xml.parsing;

import java.util.*;

import org.xml.sax.Attributes;

/**
 *
 * @author  Stefan Boddy, James Cunningham
 */

public class MapArrayTypeRule extends org.apache.commons.digester.Rule
{
    /** Creates a new instance of MapArrayTypeRule */
    public MapArrayTypeRule() {}


    /* (non-Javadoc)
     * @see org.apache.commons.digester.Rule#begin(java.lang.String, java.lang.String, org.xml.sax.Attributes)
     */
    
    public void begin(String namespace, 
            		  String name, 
            		  Attributes attributes) {
        for(int i = 0; i < attributes.getLength(); i++) {
             if(attributes.getQName(i).equals("itemType")) this.type = attributes.getValue(i);
        }
    }

    
    public void end(String namespace, 
            		String name) {
        PlaceHolder ph;
        if(digester.peek() instanceof PlaceHolder) {
			ph = (PlaceHolder)digester.peek();
		}
		else {
			System.out.println("WARNING: list element found without parent simpleType element [instanceof failure on " + digester.peek().getClass().getName() + "]. Terminating parsing of this element");
			this.type = null;
			return;
		}
        if(ph.getType().equals("simpleType")) {
			String attName = "";
			if((attName = (String)ph.getAttribute("name"))!=null) {
        		HashMap mapping = (HashMap)digester.peek(digester.getCount()-1);
				if(this.type == null) {
					System.out.println("WARNING: attribute '" + attName + "' without type in schema " + (String)mapping.get("Schema_Name"));
				}
				else {
					if(this.type.startsWith("xsd:")) {
						this.type = this.type.substring(this.type.indexOf("xsd:")+4); // simplify the type name
					}
					this.type = this.type + "[]";
					mapping.put(attName, this.type);
				}
			}
			else {
				System.out.println("WARNING: list element found with parent that has no name attribute. Terminating parsing of this element");
				this.type = null;
				return;
			}
		}
		else {
			System.out.println("WARNING: list element found without parent simpleType element [type check failure]. Terminating parsing of this element");
			this.type = null;
			return;
		}
        this.type = null;
    }

    //------------------------------------

    private String type;
}

⌨️ 快捷键说明

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