コード例 #1
0
        public override INodePointer CreateChild(SifXPathContext context, string name, int i)
        {
            SifVersion   version    = Version;
            IElementDef  subEleDef  = GetChildDef(name);
            SifFormatter formatter  = Adk.Dtd.GetFormatter(version);
            SifElement   sifElement = (SifElement)fElement;

            // Check to see if this child has a render surrogate defined
            IRenderSurrogate rs = subEleDef.GetVersionInfo(version).GetSurrogate();

            if (rs != null)
            {
                return(rs.CreateChild(this, formatter, version, context));
            }

            if (subEleDef.Field)
            {
                SifSimpleType ssf = subEleDef.TypeConverter.GetSifSimpleType(null);
                SimpleField   sf  = formatter.SetField(sifElement, subEleDef, ssf, version);
                return(SimpleFieldPointer.Create(this, sf));
            }
            else
            {
                SifElement newEle = SifElement.Create(sifElement, subEleDef);
                formatter.AddChild(sifElement, newEle, version);
                return(new SifElementPointer(this, newEle, version));
            }
        }
コード例 #2
0
 public virtual INodePointer CreateAttribute(SifXPathContext context, string name)
 {
     throw new InvalidOperationException(
               string.Format(
                   "Cannot create an object for path {0}/{1}. Creating a child is not supported by this type of node: {2}({3})",
                   Name, name, NodeType, GetType().FullName));
 }
コード例 #3
0
        /// <summary>
        /// Creates a new SifXPathContext instance to use for traversing the
        /// specified SIF Data Object
        /// </summary>
        /// <remarks>
        /// NOTE: The SIFDataObject.setSIFVersion(version) is automatically
        /// called and set to the target version.
        /// </remarks>
        /// <param name="sdo">The SIF Data Object or SIFElement to traverse</param>
        /// <returns>an instance of SifXPathContext</returns>
        /// <param name="version">The SIFVersion to use when traversing this object using XPath.</param>
        public static SifXPathContext NewSIFContext(SifElement sdo, SifVersion version)
        {
            sdo.SifVersion = version;
            SifXPathContext context = NewSIFContext(sdo);

            return(context);
        }
コード例 #4
0
        /// <summary>
        /// Creates a new SifXPathContext instance to use for traversing the
        /// specified SIF Data Object
        /// </summary>
        /// <remarks>
        /// Contexts that are created from other contexts automatically inherit all
        /// custom variables and functions that are defined in the other context
        /// </remarks>
        /// <param name="parent">The SifXPathContext to share custom functions and
        /// variables with</param>
        /// <param name="sdo">The SIF Data Object or SIFElement to traverse</param>
        /// <returns>an instance of SifXPathContext</returns>
        public static SifXPathContext NewSIFContext(SifXPathContext parent,
                                                    SifElement sdo)
        {
            SifXPathContext context = new SifXPathContext(parent, sdo);

            return(context);
        }
コード例 #5
0
        /// <summary>
        /// Creates a child element, if supported by this node
        /// </summary>
        /// <param name="parentPointer"></param>
        /// <param name="formatter"></param>
        /// <param name="version"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public INodePointer CreateChild( INodePointer parentPointer, SifFormatter formatter, SifVersion version,
                                         SifXPathContext context )
        {
            // 1) Create an instance of the SimpleField with a null value (It's assigned later)

            //
            // STEP 2
            // Find the actual field to set the value to
            //
            SifElement parent = (SifElement) ((SifElementPointer) parentPointer).Element;
            SifElement targetElement = parent;

            if ( !fElementDef.Field )
            {
                //	This indicates a child SifElement that needs to be created
                targetElement = SifElement.Create( parent, fElementDef );

                formatter.AddChild( parent, targetElement, version );
            }

            IElementDef fieldDef = null;
            if ( fValueXpath.Equals( "." ) )
            {
                fieldDef = fElementDef;
            }
            else
            {
                String fieldName = fValueXpath;
                if ( fValueXpath.StartsWith( "@" ) )
                {
                    fieldName = fValueXpath.Substring( 1 );
                }
                fieldDef = Adk.Dtd.LookupElementDef( fElementDef, fieldName );
            }

            if ( fieldDef == null )
            {
                throw new ArgumentException( "Support for value path {" + fValueXpath +
                                             "} is not supported by XPathSurrogate." );
            }

            SifSimpleType ssf = fieldDef.TypeConverter.GetSifSimpleType( null );
            SimpleField sf = ssf.CreateField( targetElement, fieldDef );
            targetElement.SetField( sf );

            // 2) built out a fake set of node pointers representing the SIF 1.5r1 path and
            //    return the root pointer from that stack
            return BuildLegacyPointers( parentPointer, sf );
        }
コード例 #6
0
        public override INodePointer CreateAttribute(SifXPathContext context, String name)
        {
            IElementDef subEleDef  = GetChildDef(name);
            SifElement  sifElement = (SifElement)fElement;

            if (subEleDef.Field)
            {
                SifSimpleType ssf = subEleDef.TypeConverter.GetSifSimpleType(null);
                SimpleField   sf  = ssf.CreateField(sifElement, subEleDef);
                sifElement.SetField(sf);
                return(SimpleFieldPointer.Create(this, sf));
            }

            throw new ArgumentException(
                      "Factory could not create a child node for path: " + Name
                      + "/" + name);
        }
コード例 #7
0
        /// <summary>
        /// Creates a new SifXPathContext
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="context"></param>
        private SifXPathContext( SifXPathContext parent, SifElement context )
        {
            if ( parent != null )
            {
                fContext = parent.fContext;
            }
            else
            {
                fContext = new SifXsltContext();
                fContext.AddFunctions( "adk", new ClassFunctions( typeof ( AdkFunctions ), null ) );
            }

            SifVersion version = context.SifVersion;
            if( version == null )
            {
                version = SifVersion.LATEST;
            }

            fContextElement = context;
            fContextPointer = new SifElementPointer( null, fContextElement, version );
            fDefaultNavigator = new SifXPathNavigator( fContext, fContextPointer );
        }
コード例 #8
0
        /// <summary>
        /// Creates a new SifXPathContext
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="context"></param>
        private SifXPathContext(SifXPathContext parent, SifElement context)
        {
            if (parent != null)
            {
                fContext = parent.fContext;
            }
            else
            {
                fContext = new SifXsltContext();
                fContext.AddFunctions("adk", new ClassFunctions(typeof(AdkFunctions), null));
            }

            SifVersion version = context.SifVersion;

            if (version == null)
            {
                version = SifVersion.LATEST;
            }

            fContextElement   = context;
            fContextPointer   = new SifElementPointer(null, fContextElement, version);
            fDefaultNavigator = new SifXPathNavigator(fContext, fContextPointer);
        }
コード例 #9
0
 /// <summary>
 /// Creates a child element, if supported by this node
 /// </summary>
 /// <param name="parentPointer"></param>
 /// <param name="formatter"></param>
 /// <param name="version"></param>
 /// <param name="context"></param>
 /// <returns></returns>
 public INodePointer CreateChild( INodePointer parentPointer, SifFormatter formatter, SifVersion version,
                                  SifXPathContext context )
 {
     return null;
 }
コード例 #10
0
 public object GetValue(SifXPathContext context)
 {
     return(context.GetValue(this));
 }
コード例 #11
0
 public INodePointer CreatePath(SifXPathContext context)
 {
     return(context.CreatePath(this));
 }
コード例 #12
0
        public override INodePointer CreateAttribute( SifXPathContext context, String name )
        {
            IElementDef subEleDef = GetChildDef( name );
            SifElement sifElement = (SifElement) fElement;

            if ( subEleDef.Field )
            {
                SifSimpleType ssf = subEleDef.TypeConverter.GetSifSimpleType( null );
                SimpleField sf = ssf.CreateField( sifElement, subEleDef );
                sifElement.SetField( sf );
                return SimpleFieldPointer.Create( this, sf );
            }

            throw new ArgumentException(
                "Factory could not create a child node for path: " + Name
                + "/" + name );
        }
コード例 #13
0
 public override INodePointer CreateAttribute( SifXPathContext context, string name )
 {
     if ( fChild.IsAttribute && fChildName.Equals( name ) )
     {
         return fChild;
     }
     return base.CreateAttribute( context, name );
 }
コード例 #14
0
        private SifXPathContext GetXPathContext(
            SifElement mappedElement, IFieldAdaptor adaptor)
        {
            lock (this)
            {
                if (!mappedElement.ElementDef.Name.Equals(fElementDef.Name))
                {
                    throw new AdkMappingException(
                        "Unable to use object for mapping. MappingsContext expected an object of type '" +
                        fElementDef.Name + "' but was '" + mappedElement.ElementDef.Name + "'.", null);
                }

                if (fRootContext == null)
                {
                    fRootContext = SifXPathContext.NewSIFContext(mappedElement, fSIFVersion);
                    if (adaptor is IXPathVariableLibrary)
                    {
                        fRootContext.AddVariables( "", (IXPathVariableLibrary)adaptor);
                    }
                }
                return SifXPathContext.NewSIFContext(fRootContext, mappedElement);
            }
        }
コード例 #15
0
ファイル: Query.cs プロジェクト: rafidzal/OpenADK-csharp
 /// <summary>
 /// Evaluates the condition groups and returns True if the Operator is OR and at least
 /// one of the groups evaluates to TRUE. If the Operator is AND, all of the condition
 /// groups have to evaluate to TRUE
 /// </summary>
 /// <param name="op"></param>
 /// <param name="grps"></param>
 /// <param name="context"></param>
 /// <param name="culture"></param>
 /// <returns></returns>
 /// <exception cref="OpenADK.Library.AdkSchemaException">If the condition contains references to invalid elements</exception>
 private bool EvaluateConditionGroups(SifXPathContext context,
                                       GroupOperator op,
                                       ConditionGroup[] grps,
                                       CultureInfo culture)
 {
     bool isMatch = true;
     for (int c = 0; c < grps.Length; c++)
     {
         bool singleMatch = EvaluateConditionGroup(context, grps[c], culture);
         if (op == GroupOperator.Or)
         {
             if (singleMatch)
             {
                 // In OR mode, return as soon as we evaluate to True
                 return true;
             }
             isMatch |= singleMatch;
         }
         else
         {
             isMatch &= singleMatch;
         }
         // As soon as the evaluation fails, return
         if (!isMatch)
         {
             return false;
         }
     }
     return isMatch;
 }
コード例 #16
0
 public virtual INodePointer CreateAttribute( SifXPathContext context, string name )
 {
     throw new InvalidOperationException(
         string.Format(
             "Cannot create an object for path {0}/{1}. Creating a child is not supported by this type of node: {2}({3})",
             Name, name, NodeType, GetType().FullName ) );
 }
コード例 #17
0
 /// <summary>
 /// Creates a new SifXPathContext instance to use for traversing the
 /// specified SIF Data Object
 /// </summary>
 /// <remarks>
 /// NOTE: The SIFDataObject.setSIFVersion(version) is automatically
 /// called and set to the target version.
 /// </remarks>
 /// <param name="parent">The SifXPathContext to share custom functions and 
 /// variables with</param>
 /// <param name="sdo">The SIF Data Object or SIFElement to traverse</param>
 /// <returns>an instance of SifXPathContext</returns>
 /// <param name="version">The SIFVersion to use when traversing this object using XPath.</param>
 public static SifXPathContext NewSIFContext( SifXPathContext parent,
                                              SifElement sdo, SifVersion version )
 {
     sdo.SifVersion = version;
     return NewSIFContext( parent, sdo );
 }
コード例 #18
0
        /// <summary>
        /// Creates a new SifXPathContext instance to use for traversing the
        /// specified SIF Data Object
        /// </summary>
        /// <remarks>
        /// Contexts that are created from other contexts automatically inherit all
        /// custom variables and functions that are defined in the other context
        /// </remarks>
        /// <param name="parent">The SifXPathContext to share custom functions and 
        /// variables with</param>
        /// <param name="sdo">The SIF Data Object or SIFElement to traverse</param>
        /// <returns>an instance of SifXPathContext</returns>
        public static SifXPathContext NewSIFContext( SifXPathContext parent,
                                                     SifElement sdo )
        {
            SifXPathContext context = new SifXPathContext( parent, sdo );

            return context;
        }
コード例 #19
0
ファイル: Rule.cs プロジェクト: rafidzal/OpenADK-csharp
 /// <summary>  Evaluates this rule against a SIFDataObject and returns the text value
 /// of the element or attribute that satisfied the query.
 /// 
 /// </summary>
 /// <param name="context">The SifXPathcontext instance to use for object traversal </param>
 /// <param name="version">The SIF version that is in effect</param>
 /// <returns>The SimpleType representing the value of the element or attribute that
 /// satisfied the query, or null if no match found
 /// </returns>
 public abstract SifSimpleType Evaluate(SifXPathContext context, SifVersion version);
コード例 #20
0
 public virtual INodePointer CreateChild(SifXPathContext context, string name, int i)
 {
     throw new InvalidOperationException("Cannot create an object for path " + Name + "/" + name +
                                         ". Creating a child is not supported by this type of node: " +
                                         NodeType);
 }
コード例 #21
0
ファイル: Mappings.cs プロジェクト: rafidzal/OpenADK-csharp
        internal void MapInbound(
            SifXPathContext xpathContext,
            IFieldAdaptor results,
            SifElement inboundObject,
            ICollection<FieldMapping> fields,
            SifVersion version)
        {
            #if PROFILED
            if( BuildOptions.PROFILED ){
            ProfilerUtils.profileStart( String.valueOf( com.OpenADK.sifprofiler.api.OIDs.ADK_INBOUND_TRANSFORMATIONS ), inboundObject.getElementDef(), null );
            }
            #endif

            FieldMapping lastRule = null;
            try
            {
                foreach (FieldMapping rule in fields)
                {
                    lastRule = rule;
                    if (!results.HasField(rule.FieldName))
                    {
                        SifSimpleType val = rule.Evaluate(xpathContext, version, true);
                        if (val != null)
                        {
                            if (rule.ValueSetID != null &&
                                val is SifString)
                            {
                                String currentValue = val.ToString();
                                //	Perform automatic ValueSet translation
                                // TT 199. Perform a more detailed valueset translation.
                                // If there is a default value set, use it if there is
                                // no match found in the value set
                                ValueSet vs = GetValueSet(rule.ValueSetID, true);
                                if (vs != null)
                                {
                                    currentValue = vs.TranslateReverse(currentValue, rule.DefaultValue);
                                }
                                val = new SifString(currentValue);
                            }
                            results.SetSifValue(rule.FieldName, val, rule);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (lastRule != null)
                {
                    throw new AdkMappingException(
                        "Unable to evaluate field rule: " + lastRule.fRule + " : " + e.Message, null, e);
                }
                throw new AdkMappingException(e.ToString(), null, e);
            }
        }
コード例 #22
0
ファイル: Mappings.cs プロジェクト: rafidzal/OpenADK-csharp
        internal void MapOutbound(
            SifXPathContext context,
            IFieldAdaptor adaptor,
            SifElement dataObject,
            ICollection<FieldMapping> fields,
            IValueBuilder valueBuilder,
            SifVersion version)
        {
            #if PROFILED
            if( BuildOptions.PROFILED ){
            ProfilerUtils.profileStart( String.valueOf( com.OpenADK.sifprofiler.api.OIDs.ADK_OUTBOUND_TRANSFORMATIONS ), dataObject.getElementDef(), null );
            }
            #endif

            SifFormatter textFormatter = Adk.TextFormatter;
            FieldMapping lastRule = null;
            try
            {
                foreach (FieldMapping fm in fields)
                {
                    lastRule = fm;
                    String fieldName = fm.Alias;
                    if (fieldName == null)
                    {
                        fieldName = fm.FieldName;
                    }

                    if (fieldName == null || fieldName.Length == 0)
                    {
                        throw new AdkMappingException(
                            "Mapping rule for " + dataObject.ElementDef.Name + "[" + fm.FieldName +
                            "] must specify a field name", null);
                    }

                    if (adaptor.HasField(fieldName) || fm.HasDefaultValue)
                    {
                        //
                        //  For outbound mapping operations, only process
                        //	XPathRules. All other rule types, like OtherIdRule,
                        //  are only intended to be used for inbound mappings.
                        //
                        if (fm.fRule is XPathRule)
                        {
                            XPathRule rule = (XPathRule) fm.fRule;
                            //  Lookup or create the element/attribute referenced by the rule
                            String ruledef = rule.XPath;
                            if (ruledef == null || ruledef.Trim().Length == 0)
                            {
                                throw new AdkMappingException(
                                    "Mapping rule for " + dataObject.ElementDef.Name + "[\"" + fieldName +
                                    "\"] must specify a path to an element or attribute", null);
                            }

                            // TT 199 If the FieldMapping has an "ifnull" value of "suppress",
                            // don't render a result

                            // Determine if this element should be created before attempting to create it
                            // If the value resolves to null and the IFNULL_SUPPRESS flag is set, the element
                            // should not be created. That's why we have to look up the ElementDef first
                            TypeConverter typeConverter = null;
                            IElementDef def = rule.LookupTargetDef(dataObject.ElementDef);
                            if (def != null)
                            {
                                typeConverter = def.TypeConverter;
                            }
                            if (typeConverter == null)
                            {
                                typeConverter = SifTypeConverters.STRING;
                                // TODO: Perhaps the following exception should be thrown when
                                // in STRICT mode
                                //	throw new ADKMappingException( "Element {" + def.name() +
                                //				"} from rule \"" + ruledef + "\" does not have a data type definition.", null );
                            }

                            SifSimpleType mappedValue;
                            mappedValue = adaptor.GetSifValue(fieldName, typeConverter, fm);

                            // Perform a valueset translation, if applicable
                            if (mappedValue != null &&
                                mappedValue is SifString &&
                                fm.ValueSetID != null)
                            {
                                String textValue = mappedValue.ToString();
                                //	Perform automatic ValueSet translation
                                ValueSet vs = GetValueSet(fm.ValueSetID, true);
                                if (vs != null)
                                {
                                    // TT 199. Perform a more detailed valueset translation.
                                    // If there is a default value for this field, use it if there is
                                    // no match found in the value set
                                    textValue = vs.Translate(textValue, fm.DefaultValue);
                                }
                                mappedValue = new SifString(textValue);
                            }

                            bool usedDefault = false;
                            if (mappedValue == null || mappedValue.RawValue == null)
                            {
                                // If the FieldMapping has a Default value, use that, unless
                                // it is explicitly suppressed
                                if (fm.NullBehavior != MappingBehavior.IfNullSuppress && fm.HasDefaultValue)
                                {
                                    mappedValue = fm.GetDefaultValue(typeConverter, textFormatter);
                                    usedDefault = true;
                                }
                                else
                                {
                                    continue;
                                }
                            }

                            if (!usedDefault)
                            {
                                String valueExpression = rule.ValueExpression;
                                if (valueExpression != null)
                                {
                                    // This XPath rule has a value assignment expression at the end of it
                                    String value = valueBuilder.Evaluate(valueExpression);
                                    mappedValue = typeConverter.Parse(textFormatter, value);
                                }
                            }

                            // If we have a null value to assign at this point, move on to the next rule
                            if (mappedValue == null || mappedValue.RawValue == null)
                            {
                                continue;
                            }

                            // At this point, mappedValue should not be null. We are committeed
                            // to building out the path and setting the value.
                            INodePointer pointer = rule.CreatePath(context, version);
                            //  If the element/attribute does not have a value, assign one.
                            //	If it does have a value, it was already assigned by the XPath
                            //	rule in the lookupByXPath method above and should not be
                            //	changed.
                            //
                            if (pointer != null)
                            {
                                Element pointedElement = (Element) pointer.Value;
                                SifSimpleType elementValue = pointedElement.SifValue;
                                if (elementValue == null || elementValue.RawValue == null)
                                {
                                    if (mappedValue is SifString)
                                    {
                                        // Now that we have the actual element, we may need to create convert the
                                        // data if we were unable to resolve the TypeConverter above. This only happens
                                        // in cases involving surrogates where the rule.lookupTargetDef( dataObject.getElementDef() );
                                        // fails to find the target ElementDef
                                        TypeConverter converter = pointedElement.ElementDef.TypeConverter;
                                        if (converter != null && converter.DataType != mappedValue.DataType)
                                        {
                                            mappedValue = converter.Parse(textFormatter, mappedValue.ToString());
                                        }
                                    }

                                    // This check for null should really not be necessary,
                                    // however keepingit in for now
                                    if (mappedValue != null)
                                    {
                                        pointedElement.SifValue = mappedValue;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (lastRule != null)
                {
                    throw new AdkMappingException(
                        "Unable to evaluate field rule: " + lastRule.fRule + " : " + e.Message, null, e);
                }
                throw new AdkMappingException(e.ToString(), null, e);
            }
            #if PROFILED
            finally
            {

            if( BuildOptions.PROFILED )
                ProfilerUtils.profileStop();
            }
            #endif
        }
コード例 #23
0
ファイル: Query.cs プロジェクト: rafidzal/OpenADK-csharp
        /// <summary>
        /// Evaluates a condition group against a SifDataObject to determine if
        /// they are a match or not
        /// </summary>
        /// <param name="grp"></param>
        /// <param name="context"></param>
        /// <param name="culture"></param>
        /// <returns>True if the result of evaluating the condition groups is true</returns>
        /// <exception cref="OpenADK.Library.AdkSchemaException">If the condition contains references to invalid elements</exception>
        private bool EvaluateConditionGroup(SifXPathContext context,
                                             ConditionGroup grp,
                                             CultureInfo culture)
        {
            Condition[] conds = grp.Conditions;
            if (conds.Length > 0)
            {
                bool returnOnFirstMatch = grp.Operator == GroupOperator.Or ? true : false;

                foreach (Condition c in conds)
                {
                    if ((EvaluateCondition(context, c, culture)) == returnOnFirstMatch)
                    {
                        // If this is an OR group, return true on the first match
                        // If this is an AND Group, return false on the first failure
                        return returnOnFirstMatch;
                    }
                }
                // None of the conditions matched the returnOnFirstMathValue. Therefore,
                // return the opposite value
                return !returnOnFirstMatch;
            }
            else
            {
                return EvaluateConditionGroups(context, grp.Operator, grp.Groups, culture);
            }
        }
コード例 #24
0
ファイル: Query.cs プロジェクト: rafidzal/OpenADK-csharp
        /// <summary>
        /// Evaluates a single SIF_Condition against an object and returns whether it matches or not
        /// </summary>
        /// <param name="cond"></param>
        /// <param name="context"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        /// <exception cref="OpenADK.Library.AdkSchemaException">If the condition contains references to invalid elements</exception>
        private bool EvaluateCondition(SifXPathContext context,
                                        Condition cond,
                                        CultureInfo culture)
        {
            // TODO: Add support for comparison using the SIF Data Types
            Element def = context.GetElementOrAttribute(cond.GetXPath());
            String conditionValue = cond.Value;

            String elementValue = null;
            if (def != null)
            {
                SifSimpleType value = def.SifValue;
                if (value != null)
                {
                    // Format the value to string, based on the query version
                    elementValue = value.ToString(EffectiveVersion);
                }
                else
                {
                    // TODO: Not sure if this would ever return a value if the above does not
                    elementValue = def.TextValue;
                }
            }

            if (elementValue == null || conditionValue == null)
            {
                // Don't use standard comparision because it will fail. If
                // one or the other value is null, it cannot be compared, except for
                // if the operator is EQ or NOT
                bool bothAreNull = (elementValue == null && conditionValue == null);
                switch (cond.Operators)
                {
                    case ComparisonOperators.EQ:
                    case ComparisonOperators.GE:
                    case ComparisonOperators.LE:
                        return bothAreNull;
                    case ComparisonOperators.NE:
                        return !bothAreNull;
                    default:
                        // For any other operator, the results are indeterminate with
                        // null values. Return false in this case.
                        return false;
                }
            }

            int compareLevel = String.Compare(elementValue, conditionValue, false, culture);

            switch (cond.Operators)
            {
                case ComparisonOperators.EQ:
                    return compareLevel == 0;
                case ComparisonOperators.NE:
                    return compareLevel != 0;
                case ComparisonOperators.GT:
                    return compareLevel > 0;
                case ComparisonOperators.LT:
                    return compareLevel < 0;
                case ComparisonOperators.GE:
                    return compareLevel >= 0;
                case ComparisonOperators.LE:
                    return compareLevel <= 0;
            }
            return false;
        }
コード例 #25
0
ファイル: XPathRule.cs プロジェクト: rafidzal/OpenADK-csharp
        /// <summary>  Evaluates this rule against a SifDataObject and returns the text value
        /// of the element or attribute that satisfied the query.
        /// 
        /// </summary>
        /// <param name="context">The SIFXPathContext to evaluate this rule against</param>
        /// <param name="version">The SIF version to use when evaluating this rule</param>
        /// <returns> The text value of the element or attribute that satisfied the
        /// query, or null if no match found
        /// </returns>
        public override SifSimpleType Evaluate(SifXPathContext context, SifVersion version)
        {
            // TODO: This could be done in the constructor, but the ADK outbound mapping
            // syntax sometimes cannot be compiled because it uses proprietary syntax
            // Therefore, compile the expression the first time it is used for a mapping
            if (fExpression == null)
            {
                Compile();
            }

            Object value = fExpression.GetValue(context);
            if (value == null)
            {
                return null;
            }
            else if (value is Element)
            {
                return ((Element) value).SifValue;
            }
            else
            {
                return new SifString(value.ToString());
            }
        }
コード例 #26
0
 /// <summary>
 /// Creates a new SifXPathContext instance to use for traversing the
 /// specified SIF Data Object
 /// </summary>
 /// <remarks>
 /// NOTE: The SIFDataObject.setSIFVersion(version) is automatically
 /// called and set to the target version.
 /// </remarks>
 /// <param name="parent">The SifXPathContext to share custom functions and
 /// variables with</param>
 /// <param name="sdo">The SIF Data Object or SIFElement to traverse</param>
 /// <returns>an instance of SifXPathContext</returns>
 /// <param name="version">The SIFVersion to use when traversing this object using XPath.</param>
 public static SifXPathContext NewSIFContext(SifXPathContext parent,
                                             SifElement sdo, SifVersion version)
 {
     sdo.SifVersion = version;
     return(NewSIFContext(parent, sdo));
 }
コード例 #27
0
 public INodePointer CreatePath( SifXPathContext context )
 {
     return context.CreatePath( this );
 }
コード例 #28
0
 /// <summary>
 /// Creates a child element, if supported by this node
 /// </summary>
 /// <param name="parentPointer"></param>
 /// <param name="formatter"></param>
 /// <param name="version"></param>
 /// <param name="context"></param>
 /// <returns></returns>
 public INodePointer CreateChild( INodePointer parentPointer, SifFormatter formatter, SifVersion version,
                                  SifXPathContext context )
 {
     // TODO Auto-generated method stub
     return null;
 }
コード例 #29
0
 public object GetValue( SifXPathContext context )
 {
     return context.GetValue( this );
 }
コード例 #30
0
 public override INodePointer CreateChild( SifXPathContext context, string name, int i )
 {
     // Do nothing. The child has already been created
     return fChild;
 }
コード例 #31
0
        public override INodePointer CreateChild( SifXPathContext context, string name, int i )
        {
            SifVersion version = Version;
            IElementDef subEleDef = GetChildDef( name );
            SifFormatter formatter = Adk.Dtd.GetFormatter( version );
            SifElement sifElement = (SifElement) fElement;

            // Check to see if this child has a render surrogate defined
            IRenderSurrogate rs = subEleDef.GetVersionInfo( version ).GetSurrogate();
            if ( rs != null )
            {
                return rs.CreateChild( this, formatter, version, context );
            }

            if ( subEleDef.Field )
            {
                SifSimpleType ssf = subEleDef.TypeConverter.GetSifSimpleType( null );
                SimpleField sf = formatter.SetField( sifElement, subEleDef, ssf, version );
                return SimpleFieldPointer.Create( this, sf );
            }
            else
            {
                SifElement newEle = SifElement.Create( sifElement, subEleDef );
                formatter.AddChild( sifElement, newEle, version );
                return new SifElementPointer( this, newEle, version );
            }
        }
コード例 #32
0
 public virtual INodePointer CreateChild( SifXPathContext context, string name, int i )
 {
     throw new InvalidOperationException( "Cannot create an object for path " + Name + "/" + name +
                                          ". Creating a child is not supported by this type of node: " +
                                          NodeType );
 }
コード例 #33
0
ファイル: XPathRule.cs プロジェクト: rafidzal/OpenADK-csharp
        public INodePointer CreatePath(SifXPathContext context, SifVersion version)
        {
            if (fExpression == null)
            {
                Compile();
            }

            return fExpression.CreatePath(context);
        }