system/src/sc/lang/pattern/Pattern.java
public String evalPatternWithInst(Map<String,Object> otherProps, Object inst) {
      StringBuilder sb = new StringBuilder();
      for (Object elem:elements) {
         if (PString.isString(elem))
            sb.append(elem);
         else if (elem instanceof OptionalPattern) {
            OptionalPattern pat = (OptionalPattern) elem;
            String optStr = pat.evalPatternWithInst(otherProps, inst);
            if (optStr != null)
               sb.append(optStr);
         }
         else if (elem instanceof PatternVariable) {
            PatternVariable patVar = (PatternVariable) elem;
            String propName = patVar.propertyName;
            try {
               // The pattern is not defined because some property is not defined or we do not have an instance
               Object propVal = otherProps == null ? null : otherProps.get(propName);
               propVal = propVal == null && inst != null ? DynUtil.getProperty(inst, propName) : propVal;
               if (propVal == null)
                  return null;
               // TODO: are there any cases where we need to do something other than toString here?
               //sb.append(propName);
               //sb.append('=');
               sb.append(propVal.toString());
            }
            catch (IllegalArgumentException exc) {
               System.err.println("*** Failed to get property: " + inst + "." + propName + " for pattern: " + this);
               return null;
            }
         }
      }
      return sb.toString();
   }
/**
    * Returns a string for this pattern.  If inst is not null, it's used as a source for
    * any PatternVariables which map onto properties of the instance. If otherProps is not
    * null, that map is consulted before the instance is checked (so you can create a new URL
    * from the existing instance but replace one or more properties in the new URL)
    *
    * If a required PatternVariable does not have a value, null is returned - which means
    * this URL is not valid in this context.
    *
    * TODO: needs to be updated to handle repeat and negated patterns
    */
Returns a string for this pattern.  If inst is not null, it's used as a source for
any PatternVariables which map onto properties of the instance. If otherProps is not
null, that map is consulted before the instance is checked (so you can create a new URL
from the existing instance but replace one or more properties in the new URL)

If a required PatternVariable does not have a value, null is returned - which means
this URL is not valid in this context.

needs to be updated to handle repeat and negated patterns
Returns a string for this pattern . If inst is not null it ' s used as a source for any PatternVariables which map onto properties of the instance . If otherProps is not null that map is consulted before the instance is checked ( so you can create a new URL from the existing instance but replace one or more properties in the new URL ) If a required PatternVariable does not have a value null is returned - which means this URL is not valid in this context . needs to be updated to handle repeat and negated patterns
public String evalPatternWithInst(Map<String,Object> otherProps, Object inst) {
      StringBuilder sb = new StringBuilder();
      for (Object elem:elements) {
         if (PString.isString(elem))
            sb.append(elem);
         else if (elem instanceof OptionalPattern) {
            OptionalPattern pat = (OptionalPattern) elem;
            String optStr = pat.evalPatternWithInst(otherProps, inst);
            if (optStr != null)
               sb.append(optStr);
         }
         else if (elem instanceof PatternVariable) {
            PatternVariable patVar = (PatternVariable) elem;
            String propName = patVar.propertyName;
            try {
               Object propVal = otherProps == null ? null : otherProps.get(propName);
               propVal = propVal == null && inst != null ? DynUtil.getProperty(inst, propName) : propVal;
               if (propVal == null)
                  return null;
               sb.append(propVal.toString());
            }
            catch (IllegalArgumentException exc) {
               System.err.println("*** Failed to get property: " + inst + "." + propName + " for pattern: " + this);
               return null;
            }
         }
      }
      return sb.toString();
   }
public String evalPatternWithInst ( Map < String , Object > otherProps , Object inst ) { StringBuilder sb = new StringBuilder ( ) ; for ( Object elem : elements ) { if ( PString . isString ( elem ) ) sb . append ( elem ) ; else if ( elem instanceof OptionalPattern ) { OptionalPattern pat = ( OptionalPattern ) elem ; String optStr = pat . evalPatternWithInst ( otherProps , inst ) ; if ( optStr != null ) sb . append ( optStr ) ; } else if ( elem instanceof PatternVariable ) { PatternVariable patVar = ( PatternVariable ) elem ; String propName = patVar . propertyName ; try { Object propVal = otherProps == null ? null : otherProps . get ( propName ) ; propVal = propVal == null && inst != null ? DynUtil . getProperty ( inst , propName ) : propVal ; if ( propVal == null ) return null ; sb . append ( propVal . toString ( ) ) ; } catch ( IllegalArgumentException exc ) { System . err . println ( "*** Failed to get property: " + inst + "." + propName + " for pattern: " + this ) ; return null ; } } } return sb . toString ( ) ; }
Returns a string for this pattern.
Returns a string for this pattern .
// The pattern is not defined because some property is not defined or we do not have an instance // TODO: are there any cases where we need to do something other than toString here? //sb.append(propName); //sb.append('=');