Package com.sun.msv.grammar

Examples of com.sun.msv.grammar.Expression$AnyStringExpression


        else
            if( ot.attributePrunedExpression!=null )
                return ot.attributePrunedExpression;
       
        // cache miss. compute it.
        Expression r = exp.visit(this);
       
        ot.attributePrunedExpression = r;    // cache this result
        return r;
    }
View Full Code Here


    }

    /** ListExp can consume this token if its pattern accepts this string */
    public boolean match(ListExp exp) {
        StringTokenizer tokens = new StringTokenizer(literal);
        Expression residual = exp.exp;

        // if the application needs type information,
        // collect them from children.
        DatatypeRef dtRef = null;
        Datatype[] childTypes = null;
        int cnt = 0;

        if (this.refType != null) {
            dtRef = new DatatypeRef();
            childTypes = new Datatype[tokens.countTokens()];
        }

        while (tokens.hasMoreTokens()) {
            StringToken child = createChildStringToken(tokens.nextToken(), dtRef);
            residual = resCalc.calcResidual(residual, child);

            if (residual == Expression.nullSet)
                // the expression is failed to accept this item.
                return false;

            if (dtRef != null) {
                if (dtRef.types == null) {
                    // failed to assign type. bail out.
                    saturated = true;
                    refType.types = null;
                    dtRef = null;
                } else {
                    // type is successfully assigned for this child.
                    if (dtRef.types.length != 1)
                        // the current RELAX NG prohibits to nest <list> patterns.
                        // Thus it's not possible for this child to return more than one type.
                        throw new Error();

                    childTypes[cnt++] = dtRef.types[0];
                }
            }
        }

        if (!residual.isEpsilonReducible())
            // some expressions are still left. failed to accept this string.
            return false;

        // this <list> accepts this string.

View Full Code Here

        public Expression onElement(ElementExp exp) {
            return exp;
        }

        public Expression onAttribute(AttributeExp exp) {
            Expression content = exp.exp.visit(this);
            if (content == Expression.nullSet)
                return Expression.nullSet; // this attribute is not allowed
            else
                return pool.createAttribute(exp.nameClass, content);
        }
View Full Code Here

    }

   
    public final Expression feed( Expression exp, AttributeToken token, boolean ignoreUndeclaredAttribute ) {
        this.token = token;
        Expression r = exp.visit(this);
       
        if(r!=Expression.nullSet || !ignoreUndeclaredAttribute)    return r;
       
        // if ignoreUndeclaredAttribute==true and expression is nullSet,
        // we have to check which of the following is the case.
View Full Code Here

      usage();
      return -1;
    }
   
   
    Expression topLevel  = grammar.getTopLevel();
   
    // polish up this AGM for instance generation.
    if( grammar instanceof RELAXGrammar
    ||  grammar instanceof RELAXModule )
      topLevel = topLevel.visit( new NoneTypeRemover(grammar.getPool()) );
   
    if( grammar instanceof XMLSchemaGrammar )
      topLevel = topLevel.visit( new SchemaLocationRemover(grammar.getPool()) );
   
 
    topLevel = topLevel.visit( new RefExpRemover(grammar.getPool(),true) );
       
        if(rootName!=null) {
            topLevel = findElement(topLevel,rootName);
            if(topLevel==null) {
                out.println("unable to find the specified root element: "+rootName);
View Full Code Here

  public static String dumpMSVExpressionTree(Expression rootExpression) throws Exception {
    MSVExpressionIterator iterator = new MSVExpressionIterator(rootExpression);
    StringBuilder builder = new StringBuilder();
    while (iterator.hasNext()) {
      Expression expr = iterator.next();
      builder.append(dumpMSVExpression(expr, iterator.getDepth())).append("\n");
    }
    return builder.toString();
  }
View Full Code Here

  /** Iterating the Tree like the following  
  If there are (unvisited) children -> go down
  If there are no (unvisited) children, but unvistsiblings -> go up and right
   */
  private Expression getNextExpression() {
    Expression nextExpression = null;
    // the current expression might be null if the desired type of expression was never found in the tree
    if (mCurrentExpression != null) {
      // if all tree is desired, or root, or if it is not element expression
      if (!mOnlyChildren || mAncestorsAndCurrent.size() == 1 || !(mAncestorsAndCurrent.peek().mExp instanceof ElementExp)) {
        List<Expression> children = (List<Expression>) mCurrentExpression.visit(mVisitor);
        // see if we can go DOWN the tree
        if (children.size() > 0) {
          Expression nextExpCandidate = children.get(0);
          // DO NOT expand elements which occur more than one time in the ancestors hierarchy (i.e.
          // since we compute the last element: Do not expand it, if it also occurs before)
          if (isNoKnownElement(nextExpCandidate)) {
            // GO DOWN - Proceed with first child
            nextExpression = nextExpCandidate;
            mAncestorsAndCurrent.push(new UniqueAncestor(nextExpression, 0));
          }
        }
      }

      // if you could not get depper, but you can go up
      // if there was no first child for the next expression and still some parent not being the root
      while (nextExpression == null && mAncestorsAndCurrent.size() > 1) {
        // go one up the stack
        UniqueAncestor uniqueAncestor = mAncestorsAndCurrent.pop();
        // get the new parent
        Expression parent = mAncestorsAndCurrent.peek().mExp;
        // to get the siblings
        List<Expression> siblings = (List<Expression>) parent.visit(mVisitor);
        // get the unvisted sibling index
        final int nextSiblingIndex = uniqueAncestor.mSiblingIndex + 1;
        if (nextSiblingIndex < siblings.size()) {
          Expression nextExpCandidate = siblings.get(nextSiblingIndex);
          // DO NOT expand elements which occur more than one time in the ancestors hierarchy (i.e.
          // since we compute the last element: Do not expand it, if it also occurs before)
          if (isNoKnownElement(nextExpCandidate)) {
            // GO RIGHT - Add next sibling to the stack
            nextExpression = nextExpCandidate;
View Full Code Here

  public Expression next() {
    if (mCurrentExpression == null) {
      return null;
    }
    Expression retVal = mCurrentExpression;
    mCurrentDepth = mAncestorsAndCurrent.size() - 1;
    mCurrentExpression = getNextExpression();
   
    // as there is always a desired expression, make sure the next one is adequate
    while (!mDesiredExpression.isInstance(mCurrentExpression) && mCurrentExpression != null) {
View Full Code Here

   * extract PuzzlePieces out of a XML schema</p>
   */
  @Test
  public void testMSVExpressionTree() {
    try {
      Expression odf10Root = OdfHelper.loadSchemaODF10();
      String odf10Dump = MSVExpressionIterator.dumpMSVExpressionTree(odf10Root);
      LOG.info("Writing MSV RelaxNG tree into file: " + OUTPUT_DUMP_ODF10);
      PrintWriter out0 = new PrintWriter(new FileWriter(OUTPUT_DUMP_ODF10));
      out0.print(odf10Dump);
      out0.close();

      Expression odf11Root = OdfHelper.loadSchemaODF11();
      String odf11Dump = MSVExpressionIterator.dumpMSVExpressionTree(odf11Root);
      LOG.info("Writing MSV RelaxNG tree into file: " + OUTPUT_DUMP_ODF11);
      PrintWriter out1 = new PrintWriter(new FileWriter(OUTPUT_DUMP_ODF11));
      out1.print(odf11Dump);
      out1.close();

      Expression odf12Root = OdfHelper.loadSchemaODF12();
      String odf12Dump = MSVExpressionIterator.dumpMSVExpressionTree(odf12Root);
      LOG.info("Writing MSV RelaxNG tree into file: " + OUTPUT_DUMP_ODF12);
      PrintWriter out2 = new PrintWriter(new FileWriter(OUTPUT_DUMP_ODF12));
      out2.print(odf12Dump);
      out2.close();
View Full Code Here

  private static <T extends Expression> void extractTypedPuzzlePieces(Expression root, PuzzlePieceSet setToBeFilled, Class<T> superclass) {
    MSVExpressionIterator iter = new MSVExpressionIterator(root, superclass);
    HashMap<String, List<PuzzlePiece>> multipleMap = new HashMap<String, List<PuzzlePiece>>();

    while (iter.hasNext()) {
      Expression exp = iter.next();

      // If there is more than one name for this expression, create more than one PuzzlePiece
      List<String> names = (List<String>) ((NameClassAndExpression) exp).getNameClass().visit(NAME_VISITOR);

      for (String name : names) {
View Full Code Here

TOP

Related Classes of com.sun.msv.grammar.Expression$AnyStringExpression

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.