diff --git a/wst/trunk/ws_helper/command_line_parser.pas b/wst/trunk/ws_helper/command_line_parser.pas index 13f9496df..561552487 100644 --- a/wst/trunk/ws_helper/command_line_parser.pas +++ b/wst/trunk/ws_helper/command_line_parser.pas @@ -25,7 +25,7 @@ Type cloOutPutDirRelative, cloOutPutDirAbsolute, cloHandleWrappedParameters, cloGenerateDocAsComments, cloGenerateObjectCollection, cloFileRenaming, cloPrefixEnum, cloParserCaseSensitive, - cloStringMaping + cloStringMaping, cloCreateChoiceFields ); TComandLineOptions = set of TComandLineOption; @@ -85,6 +85,9 @@ begin end else if ( Pos('S',OptArg) = 1 ) then begin Include(AAppOptions,cloStringMaping); OptionsArgsMAP[cloStringMaping] := OptArg; + end else if ( Pos('F',OptArg) = 1 ) then begin + Include(AAppOptions,cloCreateChoiceFields); + OptionsArgsMAP[cloCreateChoiceFields] := OptArg; end; end; 'f' : diff --git a/wst/trunk/ws_helper/generator.pas b/wst/trunk/ws_helper/generator.pas index 07c15678b..679cdaea0 100644 --- a/wst/trunk/ws_helper/generator.pas +++ b/wst/trunk/ws_helper/generator.pas @@ -29,7 +29,8 @@ type TGeneratorOption = ( goDocumentWrappedParameter { .Net style wrapped parameters }, goGenerateDocAsComments { Documentation include in the XSD/WSDL schema will be generated as comments }, - goGenerateObjectCollection { Generate object "collection" instead of "array" } + goGenerateObjectCollection { Generate object "collection" instead of "array" }, + goCreateChoiceFieldsInConstructor ); TGeneratorOptions = set of TGeneratorOption; @@ -2545,12 +2546,14 @@ var p : TPasProperty; pte : TPasElement; pt : TPasType; + okCreation, okChoiceFields : Boolean; begin if ( locClassPropNbr > 0 ) then begin NewLine(); WriteLn('{ %s }',[ASymbol.Name]); if ( locClassPropNbr > 0 ) or ( locClassPropNbr > 0 ) then begin + okChoiceFields := (goCreateChoiceFieldsInConstructor in Self.Options); NewLine(); WriteLn('constructor %s.Create();',[ASymbol.Name]); WriteLn('begin'); @@ -2559,9 +2562,15 @@ var for k := 0 to Pred(locPropCount) do begin p := TPasProperty(locPropList[k]); pt := FindActualType(p.VarType,SymbolTable); - if SymbolTable.IsOfType(pt,TPasClassType) or - SymbolTable.IsOfType(pt,TPasArrayType) - then begin + okCreation := SymbolTable.IsOfType(pt,TPasArrayType); + if not okCreation then begin + okCreation := SymbolTable.IsOfType(pt,TPasClassType) and + (GetUltimeType(pt,SymbolTable) <> ASymbol) and + ( not(SymbolTable.IsChoiceProperty(p)) or + okChoiceFields + ); + end; + if okCreation then begin Indent(); WriteLn('F%s := %s.Create();',[p.Name,GetTypeText(p,pt)]); end; end; diff --git a/wst/trunk/ws_helper/pascal_parser_intf.pas b/wst/trunk/ws_helper/pascal_parser_intf.pas index ecdeb10d6..acc6a9cfb 100644 --- a/wst/trunk/ws_helper/pascal_parser_intf.pas +++ b/wst/trunk/ws_helper/pascal_parser_intf.pas @@ -30,6 +30,7 @@ const sARRAY_STYLE_SCOPED = 'ARRAY_STYLE_SCOPED'; sARRAY_STYLE_EMBEDDED = 'ARRAY_STYLE_EMBEDDED'; sARRAY_IS_COLLECTION = 'ARRAY_COLLECTION'; + sCHOICE = 'CHOICE'; sWST_PROP_STORE_PREFIX = 'wstHas_'; sFILE_NAME = 'FileName'; sNS_COUNT = 'NS_Count'; @@ -187,6 +188,8 @@ type function GetNameSpace(AType : TPasType) : string ; function IsAttributeProperty(AObject : TPasVariable) : Boolean; procedure SetPropertyAsAttribute(AObject : TPasVariable; const AValue : Boolean); + function IsChoiceProperty(AObject : TPasProperty) : Boolean; + procedure SetPropertyAsChoice(AObject : TPasProperty; const AValue : Boolean); function IsInitNeed(AType: TPasType): Boolean; function IsOfType(AType: TPasType; AClass: TClass): Boolean; @@ -1176,6 +1179,27 @@ begin Properties.SetValue(AObject,sATTRIBUTE,s); end; +function TwstPasTreeContainer.IsChoiceProperty( + AObject : TPasProperty +) : Boolean; +begin + Result := AnsiSameText(Properties.GetValue(AObject,sCHOICE),'True'); +end; + +procedure TwstPasTreeContainer.SetPropertyAsChoice( + AObject : TPasProperty; + const AValue : Boolean +); +var + s : string; +begin + if AValue then + s := 'True' + else + s := 'False'; + Properties.SetValue(AObject,sCHOICE,s); +end; + function TwstPasTreeContainer.FindElementNS(const AName, ANameSpace: string): TPasElement; var mdl : TPasModule; diff --git a/wst/trunk/ws_helper/ws_helper_prog.inc b/wst/trunk/ws_helper/ws_helper_prog.inc index 065b1ba48..2df5d7689 100644 --- a/wst/trunk/ws_helper/ws_helper_prog.inc +++ b/wst/trunk/ws_helper/ws_helper_prog.inc @@ -19,6 +19,8 @@ resourcestring ' C : object arrays are generated as "collection" derived from TObjectCollectionRemotable' + sNEW_LINE + ' EP : enum type''s items are prefixed with the enum name' + sNEW_LINE + ' EN : enum type''s items are not prefixed with the enum name, the default' + sNEW_LINE + + ' FN : do not create fields for "choice"''s items in constructor' + sNEW_LINE + + ' FO : create fields for "choice"''s items in constructor, the default' + sNEW_LINE + ' SS : XSD''string type is mapped to Object Pascal'' String' + sNEW_LINE + ' SU : XSD''string type is mapped to Object Pascal'' UnicodeString' + sNEW_LINE + ' -p Generate service proxy' + sNEW_LINE + @@ -101,6 +103,12 @@ var end else begin Include(AppOptions,cloParserCaseSensitive); end; + if not(cloCreateChoiceFields in AppOptions) then begin + Include(AppOptions,cloCreateChoiceFields); + end else begin + if AnsiSameText('FN',Trim(GetOptionArg(cloCreateChoiceFields))) then + Exclude(AppOptions,cloCreateChoiceFields); + end; end; function GenerateSymbolTable() : Boolean ; @@ -287,7 +295,9 @@ var if wrappedParams then g.Options := g.Options + [goDocumentWrappedParameter]; if ( cloGenerateObjectCollection in AppOptions ) then - g.Options := g.Options + [goGenerateObjectCollection]; + g.Options := g.Options + [goGenerateObjectCollection]; + if ( cloCreateChoiceFields in AppOptions ) then + g.Options := g.Options + [goCreateChoiceFieldsInConstructor]; g.Execute(); FreeAndNil(g); end; diff --git a/wst/trunk/ws_helper/ws_parser_imp.pas b/wst/trunk/ws_helper/ws_parser_imp.pas index 2d79120b3..484907dbe 100644 --- a/wst/trunk/ws_helper/ws_parser_imp.pas +++ b/wst/trunk/ws_helper/ws_parser_imp.pas @@ -779,6 +779,8 @@ begin end; if locIsAttribute then FSymbols.SetPropertyAsAttribute(dest,True); + if FSymbols.IsChoiceProperty(src) then + FSymbols.SetPropertyAsChoice(dest,True); {$IFDEF HAS_EXP_TREE} if (src.DefaultExpr <> nil) and src.DefaultExpr.InheritsFrom(TPrimitiveExpr) @@ -1067,7 +1069,11 @@ var AMaxUnboundded := locMaxOccurUnbounded; end; - procedure ParseElement(AElement : TDOMNode; const ABoundInfos : TOccurrenceRec); + procedure ParseElement( + AElement : TDOMNode; + const ABoundInfos : TOccurrenceRec; + const AIsChoiceParent : Boolean + ); var locAttCursor, locPartCursor : IObjectCursor; locName, locTypeName, locTypeInternalName : string; @@ -1273,6 +1279,8 @@ var {$ELSE HAS_EXP_TREE} locProp.DefaultValue := (locPartCursor.GetCurrent() as TDOMNodeRttiExposer).NodeValue; {$ENDIF HAS_EXP_TREE} + if AIsChoiceParent then + FSymbols.SetPropertyAsChoice(locProp,AIsChoiceParent); ExtractExtendedMetadata(locProp,AElement); end; @@ -1284,9 +1292,10 @@ var end; procedure ParseElementsAndAttributes( - AEltCrs, - AEltAttCrs : IObjectCursor; - ABoundInfos : TOccurrenceRec + AEltCrs, + AEltAttCrs : IObjectCursor; + ABoundInfos : TOccurrenceRec; + const AIsChoiceParent : Boolean ); function ExtractElement(ANode : TDOMNode) : IObjectCursor; @@ -1324,17 +1333,20 @@ var ExtractOccurences(s_choice,locEltAttCrs,locBoundInfos.MinOccurs,locBoundInfos.MaxOccurs,locBoundInfos.Unboundded); locBoundInfos.MinOccurs := 0; locBoundInfos.Valid := True; - ParseElementsAndAttributes(locEltCrs,locEltAttCrs,locBoundInfos); + ParseElementsAndAttributes(locEltCrs,locEltAttCrs,locBoundInfos,AIsChoiceParent); end; end else begin - ParseElement(locNode,ABoundInfos); + ParseElement(locNode,ABoundInfos,AIsChoiceParent); end; end; end; if Assigned(AEltAttCrs) then begin AEltAttCrs.Reset(); while AEltAttCrs.MoveNext() do begin - ParseElement((AEltAttCrs.GetCurrent() as TDOMNodeRttiExposer).InnerObject,ABoundInfos); + ParseElement( + (AEltAttCrs.GetCurrent() as TDOMNodeRttiExposer).InnerObject, + ABoundInfos,AIsChoiceParent + ); end; end; end; @@ -1397,6 +1409,7 @@ var locDefaultAncestorUsed : Boolean; locBoundInfos : TOccurrenceRec; locTempNode : TDOMNode; + locIsChoiceParent : Boolean; begin ExtractBaseType(); eltCrs := ExtractElementCursor(nil,eltAttCrs,grpCrs,attGrpCrs,locAnyNode,locAnyAttNode); @@ -1443,6 +1456,7 @@ begin classDef.AncestorType.AddRef(); if Assigned(eltCrs) or Assigned(eltAttCrs) then begin isArrayDef := False; + locIsChoiceParent := False; FillChar(locBoundInfos,SizeOf(locBoundInfos),#0); if (eltCrs <> nil) then begin eltCrs.Reset(); @@ -1457,10 +1471,11 @@ begin ); locBoundInfos.MinOccurs := 0; locBoundInfos.Valid := True; + locIsChoiceParent := True; end; end; end; - ParseElementsAndAttributes(eltCrs,eltAttCrs,locBoundInfos); + ParseElementsAndAttributes(eltCrs,eltAttCrs,locBoundInfos,locIsChoiceParent); ParseGroups(classDef,grpCrs); ParseGroups(classDef,attGrpCrs); if ( arrayItems.GetCount() > 0 ) then begin