Package com.sun.msv.util

Examples of com.sun.msv.util.StringPair


     *         <li>it's in the 'base" name class and
     *         <li>it's not one of those excluded names
     */
    public LaxDefaultNameClass( NameClass _base ) {
        this.base = _base;
        names.add( new StringPair(NAMESPACE_WILDCARD,LOCALNAME_WILDCARD) );
    }
View Full Code Here


     */
    protected NameClass equivalentNameClass;
   
    public boolean accepts( String namespaceURI, String localName ) {
        return base.accepts(namespaceURI,localName) &&
                !names.contains( new StringPair(namespaceURI,localName) );
    }
View Full Code Here

   
    /**
     * add a name so that this name will be rejected by the accepts method.
     */
    public void addName( String namespaceURI, String localName ) {
        names.add( new StringPair(namespaceURI,localName) );
        names.add( new StringPair(namespaceURI,LOCALNAME_WILDCARD) );
        names.add( new StringPair(NAMESPACE_WILDCARD,localName) );
    }
View Full Code Here

       
        Set uris = new java.util.HashSet();
       
        Iterator itr = possibleNames.iterator();
        while( itr.hasNext() ) {
            StringPair name = (StringPair)itr.next();
            if( name.localName!=MAGIC ) {
                // a simple name.
                if( nc.accepts(name)==nc.accepts( name.namespaceURI, MAGIC ) ) {
                    itr.remove();
                    continue;
                }
            } else
            if( name.namespaceURI!=MAGIC ) {
                // a ns name
                if( nc.accepts(name)==nc.accepts(MAGIC,MAGIC) ) {
                    itr.remove();
                    continue;
                }
            }
           
            // collect the remainig namespace URIs.
            if( name.namespaceURI!=MAGIC )
                uris.add(name.namespaceURI);
        }
       
        if( !nc.accepts(MAGIC,MAGIC) )
            possibleNames.remove( new StringPair(MAGIC,MAGIC) );
       
        NameClass result = null;
        Iterator jtr = uris.iterator();
        while( jtr.hasNext() ) {
            final String uri = (String)jtr.next();
           
            NameClass local = null;
            itr = possibleNames.iterator();
            while( itr.hasNext() ) {
                final StringPair name = (StringPair)itr.next();
               
                if(!name.namespaceURI.equals(uri))        continue;
                if(name.localName==MAGIC)                continue;
               
                if(local==null)    local = new SimpleNameClass(name);
                else            local = new ChoiceNameClass(local,new SimpleNameClass(name));
            }
            if(possibleNames.contains(new StringPair(uri,MAGIC))) {
                if(local==null)
                    local = new NamespaceNameClass(uri);
                else
                    local = new DifferenceNameClass(new NamespaceNameClass(uri),local);
            }
View Full Code Here

                inSimpleElement = (exp.getNameClass() instanceof SimpleNameClass);
                inOptionalChoice = true;
                inChoice = false;
                inOneOrMore = false;
               
                StringPair en = null;
                if(inSimpleElement) {
                    currentElementName = (SimpleNameClass)exp.getNameClass();
                    en = new StringPair(currentElementName);
                    currentAttributes = new HashMap();
                } else
                    currentElementName = null;
               
                exp.contentModel.visit(this);

                if(en!=null) {
                    DefAttMap m = (DefAttMap)name2value.get(en);
                    if(m==null)
                        name2value.put(en, new DefAttMap(exp,currentAttributes));
                    else {
                        // there was another ElementExp with the same name.
                        // we need to check that their default attribute values
                        // are consistent.
                        if(!m.defaultAttributes.equals(currentAttributes)) {
                            // TODO: provide better message
                            reportCompError(
                                new Locator[]{
                                    reader.getDeclaredLocationOf(m.sampleDecl),
                                reader.getDeclaredLocationOf(exp)},
                                CERR_DEFVALUE_COMPETING_ELEMENTS,
                                new Object[]{
                                    ((SimpleNameClass)m.sampleDecl.getNameClass()).localName
                                });
                            // make this element name fresh
                            // so that the user won't see excessive error messages.
                            name2value.remove(en);
                        }
                    }
                }
               
                inSimpleElement = oldSE;
                inOptionalChoice = oldOC;
                inChoice = oldC;
                inOneOrMore = oldOOM;
                currentElementName = prevElemName;
                currentAttributes = oldCA;
            }
                   
            public void onOneOrMore( OneOrMoreExp exp ) {
                final boolean oldOOM = inOneOrMore;
                inOneOrMore = true;
                exp.exp.visit(this);
                inOneOrMore=oldOOM;
            }
                   
            public void onChoice( ChoiceExp exp ) {
                final boolean oldOC = inOptionalChoice;
                final boolean oldC = inChoice;
                       
                inChoice = true;
                if(!isEpsilon(exp.exp1) && !isEpsilon(exp.exp2))
                    inOptionalChoice = false;
                super.onChoice(exp);
                       
                inOptionalChoice = oldOC;
                inChoice = oldC;
            }
                   
            public void onAttribute( AttributeExp exp ) {
                if( defaultedAttributes.containsKey(exp) ) {
                    // this attribute has a default value.
                    if(!inOptionalChoice || !inChoice) {
                        reportCompError(
                            new Locator[]{reader.getDeclaredLocationOf(exp)},
                            CERR_DEFVALUE_NOT_OPTIONAL);
                        return;    // abort
                    }
                    if(inOneOrMore) {
                        reportCompError(
                            new Locator[]{reader.getDeclaredLocationOf(exp)},
                            CERR_DEFVALUE_REPEATABLE);
                        return; // abort
                    }
                    if(!inSimpleElement) {
                        reportCompError(
                            new Locator[]{reader.getDeclaredLocationOf(exp)},
                            CERR_DEFVALUE_COMPLEX_ELEMENTNAME);
                        return; // abort
                    }
                   
                    String value = (String)defaultedAttributes.get(exp);
                    String v = (String)currentAttributes.put(
                        new StringPair((SimpleNameClass)exp.nameClass), value );
                           
                    if(v!=null) {
                        // make sure that this value and the previous value
                        // are the same
                        if(!v.equals(value))
View Full Code Here

            throws SAXException {
       
        // create Datatype that validates attribute value.
        Datatype dt = createDatatype(attributeType);
       
        StringPair str = new StringPair("",attributeType);
       
        if(enums!=null) {
            Expression exp = Expression.nullSet;
            for( int i=0; i<enums.length; i++ )
                exp = grammar.pool.createChoice( exp,
View Full Code Here

           
            public void onElement( ElementExp exp ) {
                if(!elements.add(exp))
                    return;    // this element has already processed.
               
                StringPair _en = elementName;
                IDAttMap _curAtts = curAtts;
                ElementExp _curElm = curElm;
               
                NameClass nc = exp.getNameClass();
                if(nc instanceof SimpleNameClass) {
                    elementName = new StringPair((SimpleNameClass)nc);
                    curAtts = (IDAttMap)name2value.get(elementName);    // maybe null.
                } else
                    elementName = null;
                curElm = exp;
               
//                System.out.println("tested:" +
//                    com.sun.msv.grammar.util.ExpressionPrinter.printContentModel(
//                    exp.contentModel.visit(remover)));
                // visit the content model, but remove reference exps first.
                exp.contentModel.visit(remover).visit(this);
               
                if( elementName!=null && curAtts!=null )
                    name2value.put(elementName,curAtts);
               
                elementName = _en;
                curAtts = _curAtts;
                curElm = _curElm;
            }
           
            public void onAttribute( AttributeExp exp ) {
               
                if(!(exp.exp instanceof DataOrValueExp)) {
                    // otherwise visit the content model normally
                    // so that we can find any invalid use of ID/IDREF types.
                    exp.exp.visit(this);
                    return;
                }
               
                DataOrValueExp texp = (DataOrValueExp)exp.exp;
                           
                if(texp.getType().getIdType()==Datatype.ID_TYPE_NULL) {
                    // if this type is not ID/IDREF type, then it's OK
                    return;
                }
               
                if(!(exp.nameClass instanceof SimpleNameClass)) {
                    reportCompError(
                        new Locator[]{reader.getDeclaredLocationOf(exp)},
                        CERR_ID_TYPE_WITH_NON_SIMPLE_ATTNAME,
                        new Object[]{
                            texp.getName().localName,
                            getSemanticsStr(texp.getType().getIdType())} );
                    return;
                }
                   
                StringPair attName = new StringPair((SimpleNameClass)exp.nameClass);
               
                if( elementName==null ) {
                    reportCompError(
                        new Locator[]{
                            reader.getDeclaredLocationOf(exp),
                            reader.getDeclaredLocationOf(curElm)},
                        CERR_ID_TYPE_WITH_NON_SIMPLE_ELEMENTNAME,
                        new Object[]{
                            texp.getName().localName,
                            getSemanticsStr(texp.getType().getIdType())} );
                    return;
                }
                   
                // the enclosing attribute name is simple, and
                // the enclosing element name is simple, too.
                // this is the only place we can have ID/IDREF types.
                                   
                // store that this attribute is used for ID/IDREF.
                if(curAtts==null)
                    curAtts = new IDAttMap(curElm);
                curAtts.idatts.put(attName,texp.getName());
                           
            }
           
            public void onData( DataExp exp )    { checkIdType(exp); }
            public void onValue( ValueExp exp ) { checkIdType(exp); }
            private void checkIdType( DataOrValueExp exp ) {
                if(exp.getType().getIdType()!=Datatype.ID_TYPE_NULL) {
                    // ID/IDREF type in all other locations are subject to
                    // a compatibility error.
                    reportCompError(
                        new Locator[]{reader.getDeclaredLocationOf(exp)},
                        CERR_MALPLACED_ID_TYPE,
                        new Object[]{
                            exp.getName().localName,
                            getSemanticsStr(exp.getType().getIdType())});
                }
            }
        });
       
       
        if(!grammar.isIDcompatible)
            // if an compatibility error has been found, abort further check.
            return;
       
        /*
        2nd pass
        ========
       
        make sure that no other attributes are competing with id attributes.
        */
        Iterator itr = elements.iterator();
        final Vector vec = new Vector();    // IDAttMaps of the competing elements
        while( itr.hasNext() ) {
            final ElementExp eexp = (ElementExp)itr.next();
           
            // list up all competing elements.
            vec.clear();
            Iterator jtr = name2value.entrySet().iterator();
            while(jtr.hasNext()) {
                Map.Entry e = (Map.Entry)jtr.next();
                if( eexp.getNameClass().accepts((StringPair)e.getKey()) )
                    vec.add( e.getValue()/*IDAttMap*/ );
            }
           
            if(vec.size()==0)
                continue;    // this element does not comete with anything.
                            // no need to check
           
            // make sure that no attributes are actually competing.
            eexp.contentModel.visit(remover).visit( new ExpressionWalker() {
                public void onElement( ElementExp exp ) {
                    return;    // do not recurse child elements.
                }
                public void onAttribute( AttributeExp exp ) {
                    if(exp.exp instanceof DataOrValueExp) {
                        DataOrValueExp texp = (DataOrValueExp)exp.exp;
                        if(texp.getType().getIdType()!=Datatype.ID_TYPE_NULL) {
                            // if the schema is OK with the 1st pass check
                            // and if this element contains the ID type, then
                            // this element must be simple-named.
                            // so at most one IDAttMap can match it.
                            _assert(vec.size()==1);
                           
                            // by the same assumption, the attribute name must be
                            // simple.
                            SimpleNameClass attName = (SimpleNameClass)exp.nameClass;
                           
                            IDAttMap iam = (IDAttMap)vec.get(0);
                            if(!texp.getName().equals(iam.idatts.get(new StringPair(attName))))
                                reportCompError(
                                    new Locator[]{
                                        reader.getDeclaredLocationOf(exp),
                                        reader.getDeclaredLocationOf(iam.sampleDecl)},
                                    CERR_COMPETING,
View Full Code Here

    public void onAttribute( AttributeExp exp ) {
        if( exp.nameClass instanceof SimpleNameClass ) {
            // this check is only appliable for those who constrains
            // one particular attribute.
            SimpleNameClass nc = (SimpleNameClass)exp.nameClass;
            StringPair p = new StringPair( nc.namespaceURI, nc.localName );
           
            if( atts.containsKey(p) )
                throw new Eureka(p);    // eureka! : find two AttributeExps that share the same name.
            atts.put(p,current);
        }
View Full Code Here

TOP

Related Classes of com.sun.msv.util.StringPair

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.