All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sun.msv.reader.trex.AttributeState Maven / Gradle / Ivy

There is a newer version: 2.2.5.1
Show newest version
/*
 * @(#)$Id: AttributeState.java,v 1.9 2003/06/09 20:37:28 kk122374 Exp $
 *
 * Copyright 2001 Sun Microsystems, Inc. All Rights Reserved.
 * 
 * This software is the proprietary information of Sun Microsystems, Inc.  
 * Use is subject to license terms.
 * 
 */
package com.sun.msv.reader.trex;

import com.sun.msv.grammar.AttributeExp;
import com.sun.msv.grammar.Expression;

/**
 * parses <attribute> pattern.
 * 
 * @author Kohsuke KAWAGUCHI
 */
public class AttributeState extends NameClassAndExpressionState
{
    protected boolean firstChild=true;
    
    protected Expression initialExpression() {
        //  defaults to 
        return Expression.anyString;
    }

    protected String getNamespace() {
        final String ns = startTag.getAttribute("ns");
        final boolean global = "true".equals(startTag.getAttribute("global"));
        
        if( ns!=null )    return ns;    // "ns" attribute always has precedence.
        
        // if global="true" is specified, it defaults to propagated ns attribute.
        if( global )    return ((TREXBaseReader)reader).targetNamespace;
        
        // otherwise, it defaults to ""
        return "";
    }
            

    protected Expression castExpression( Expression initialExpression, Expression newChild ) {
        //  is allowed to have only one pattern
        if(!firstChild)
            reader.reportError( TREXBaseReader.ERR_MORE_THAN_ONE_CHILD_EXPRESSION );
            // recover by ignore the error
        firstChild = false;
        return newChild;
    }

    protected Expression annealExpression( Expression contentModel ) {
        Expression e = reader.pool.createAttribute( nameClass, contentModel );
        if(e instanceof AttributeExp)
            reader.setDeclaredLocationOf(e);
        return e;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy