Provide an option not to create fields from XSD's "choice" construct.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4629 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
parent
870591f5a1
commit
fb72045f86
@ -25,7 +25,7 @@ Type
|
|||||||
cloOutPutDirRelative, cloOutPutDirAbsolute, cloHandleWrappedParameters,
|
cloOutPutDirRelative, cloOutPutDirAbsolute, cloHandleWrappedParameters,
|
||||||
cloGenerateDocAsComments, cloGenerateObjectCollection,
|
cloGenerateDocAsComments, cloGenerateObjectCollection,
|
||||||
cloFileRenaming, cloPrefixEnum, cloParserCaseSensitive,
|
cloFileRenaming, cloPrefixEnum, cloParserCaseSensitive,
|
||||||
cloStringMaping
|
cloStringMaping, cloCreateChoiceFields
|
||||||
);
|
);
|
||||||
TComandLineOptions = set of TComandLineOption;
|
TComandLineOptions = set of TComandLineOption;
|
||||||
|
|
||||||
@ -85,6 +85,9 @@ begin
|
|||||||
end else if ( Pos('S',OptArg) = 1 ) then begin
|
end else if ( Pos('S',OptArg) = 1 ) then begin
|
||||||
Include(AAppOptions,cloStringMaping);
|
Include(AAppOptions,cloStringMaping);
|
||||||
OptionsArgsMAP[cloStringMaping] := OptArg;
|
OptionsArgsMAP[cloStringMaping] := OptArg;
|
||||||
|
end else if ( Pos('F',OptArg) = 1 ) then begin
|
||||||
|
Include(AAppOptions,cloCreateChoiceFields);
|
||||||
|
OptionsArgsMAP[cloCreateChoiceFields] := OptArg;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
'f' :
|
'f' :
|
||||||
|
@ -29,7 +29,8 @@ type
|
|||||||
TGeneratorOption = (
|
TGeneratorOption = (
|
||||||
goDocumentWrappedParameter { .Net style wrapped parameters },
|
goDocumentWrappedParameter { .Net style wrapped parameters },
|
||||||
goGenerateDocAsComments { Documentation include in the XSD/WSDL schema will be generated as comments },
|
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;
|
TGeneratorOptions = set of TGeneratorOption;
|
||||||
|
|
||||||
@ -2545,12 +2546,14 @@ var
|
|||||||
p : TPasProperty;
|
p : TPasProperty;
|
||||||
pte : TPasElement;
|
pte : TPasElement;
|
||||||
pt : TPasType;
|
pt : TPasType;
|
||||||
|
okCreation, okChoiceFields : Boolean;
|
||||||
begin
|
begin
|
||||||
if ( locClassPropNbr > 0 ) then begin
|
if ( locClassPropNbr > 0 ) then begin
|
||||||
NewLine();
|
NewLine();
|
||||||
WriteLn('{ %s }',[ASymbol.Name]);
|
WriteLn('{ %s }',[ASymbol.Name]);
|
||||||
|
|
||||||
if ( locClassPropNbr > 0 ) or ( locClassPropNbr > 0 ) then begin
|
if ( locClassPropNbr > 0 ) or ( locClassPropNbr > 0 ) then begin
|
||||||
|
okChoiceFields := (goCreateChoiceFieldsInConstructor in Self.Options);
|
||||||
NewLine();
|
NewLine();
|
||||||
WriteLn('constructor %s.Create();',[ASymbol.Name]);
|
WriteLn('constructor %s.Create();',[ASymbol.Name]);
|
||||||
WriteLn('begin');
|
WriteLn('begin');
|
||||||
@ -2559,9 +2562,15 @@ var
|
|||||||
for k := 0 to Pred(locPropCount) do begin
|
for k := 0 to Pred(locPropCount) do begin
|
||||||
p := TPasProperty(locPropList[k]);
|
p := TPasProperty(locPropList[k]);
|
||||||
pt := FindActualType(p.VarType,SymbolTable);
|
pt := FindActualType(p.VarType,SymbolTable);
|
||||||
if SymbolTable.IsOfType(pt,TPasClassType) or
|
okCreation := SymbolTable.IsOfType(pt,TPasArrayType);
|
||||||
SymbolTable.IsOfType(pt,TPasArrayType)
|
if not okCreation then begin
|
||||||
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)]);
|
Indent(); WriteLn('F%s := %s.Create();',[p.Name,GetTypeText(p,pt)]);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
@ -30,6 +30,7 @@ const
|
|||||||
sARRAY_STYLE_SCOPED = 'ARRAY_STYLE_SCOPED';
|
sARRAY_STYLE_SCOPED = 'ARRAY_STYLE_SCOPED';
|
||||||
sARRAY_STYLE_EMBEDDED = 'ARRAY_STYLE_EMBEDDED';
|
sARRAY_STYLE_EMBEDDED = 'ARRAY_STYLE_EMBEDDED';
|
||||||
sARRAY_IS_COLLECTION = 'ARRAY_COLLECTION';
|
sARRAY_IS_COLLECTION = 'ARRAY_COLLECTION';
|
||||||
|
sCHOICE = 'CHOICE';
|
||||||
sWST_PROP_STORE_PREFIX = 'wstHas_';
|
sWST_PROP_STORE_PREFIX = 'wstHas_';
|
||||||
sFILE_NAME = 'FileName';
|
sFILE_NAME = 'FileName';
|
||||||
sNS_COUNT = 'NS_Count';
|
sNS_COUNT = 'NS_Count';
|
||||||
@ -187,6 +188,8 @@ type
|
|||||||
function GetNameSpace(AType : TPasType) : string ;
|
function GetNameSpace(AType : TPasType) : string ;
|
||||||
function IsAttributeProperty(AObject : TPasVariable) : Boolean;
|
function IsAttributeProperty(AObject : TPasVariable) : Boolean;
|
||||||
procedure SetPropertyAsAttribute(AObject : TPasVariable; const AValue : 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 IsInitNeed(AType: TPasType): Boolean;
|
||||||
function IsOfType(AType: TPasType; AClass: TClass): Boolean;
|
function IsOfType(AType: TPasType; AClass: TClass): Boolean;
|
||||||
@ -1176,6 +1179,27 @@ begin
|
|||||||
Properties.SetValue(AObject,sATTRIBUTE,s);
|
Properties.SetValue(AObject,sATTRIBUTE,s);
|
||||||
end;
|
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;
|
function TwstPasTreeContainer.FindElementNS(const AName, ANameSpace: string): TPasElement;
|
||||||
var
|
var
|
||||||
mdl : TPasModule;
|
mdl : TPasModule;
|
||||||
|
@ -19,6 +19,8 @@ resourcestring
|
|||||||
' C : object arrays are generated as "collection" derived from TObjectCollectionRemotable' + sNEW_LINE +
|
' 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 +
|
' 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 +
|
' 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 +
|
' SS : XSD''string type is mapped to Object Pascal'' String' + sNEW_LINE +
|
||||||
' SU : XSD''string type is mapped to Object Pascal'' UnicodeString' + sNEW_LINE +
|
' SU : XSD''string type is mapped to Object Pascal'' UnicodeString' + sNEW_LINE +
|
||||||
' -p Generate service proxy' + sNEW_LINE +
|
' -p Generate service proxy' + sNEW_LINE +
|
||||||
@ -101,6 +103,12 @@ var
|
|||||||
end else begin
|
end else begin
|
||||||
Include(AppOptions,cloParserCaseSensitive);
|
Include(AppOptions,cloParserCaseSensitive);
|
||||||
end;
|
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;
|
end;
|
||||||
|
|
||||||
function GenerateSymbolTable() : Boolean ;
|
function GenerateSymbolTable() : Boolean ;
|
||||||
@ -288,6 +296,8 @@ var
|
|||||||
g.Options := g.Options + [goDocumentWrappedParameter];
|
g.Options := g.Options + [goDocumentWrappedParameter];
|
||||||
if ( cloGenerateObjectCollection in AppOptions ) then
|
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();
|
g.Execute();
|
||||||
FreeAndNil(g);
|
FreeAndNil(g);
|
||||||
end;
|
end;
|
||||||
|
@ -779,6 +779,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
if locIsAttribute then
|
if locIsAttribute then
|
||||||
FSymbols.SetPropertyAsAttribute(dest,True);
|
FSymbols.SetPropertyAsAttribute(dest,True);
|
||||||
|
if FSymbols.IsChoiceProperty(src) then
|
||||||
|
FSymbols.SetPropertyAsChoice(dest,True);
|
||||||
{$IFDEF HAS_EXP_TREE}
|
{$IFDEF HAS_EXP_TREE}
|
||||||
if (src.DefaultExpr <> nil) and
|
if (src.DefaultExpr <> nil) and
|
||||||
src.DefaultExpr.InheritsFrom(TPrimitiveExpr)
|
src.DefaultExpr.InheritsFrom(TPrimitiveExpr)
|
||||||
@ -1067,7 +1069,11 @@ var
|
|||||||
AMaxUnboundded := locMaxOccurUnbounded;
|
AMaxUnboundded := locMaxOccurUnbounded;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure ParseElement(AElement : TDOMNode; const ABoundInfos : TOccurrenceRec);
|
procedure ParseElement(
|
||||||
|
AElement : TDOMNode;
|
||||||
|
const ABoundInfos : TOccurrenceRec;
|
||||||
|
const AIsChoiceParent : Boolean
|
||||||
|
);
|
||||||
var
|
var
|
||||||
locAttCursor, locPartCursor : IObjectCursor;
|
locAttCursor, locPartCursor : IObjectCursor;
|
||||||
locName, locTypeName, locTypeInternalName : string;
|
locName, locTypeName, locTypeInternalName : string;
|
||||||
@ -1273,6 +1279,8 @@ var
|
|||||||
{$ELSE HAS_EXP_TREE}
|
{$ELSE HAS_EXP_TREE}
|
||||||
locProp.DefaultValue := (locPartCursor.GetCurrent() as TDOMNodeRttiExposer).NodeValue;
|
locProp.DefaultValue := (locPartCursor.GetCurrent() as TDOMNodeRttiExposer).NodeValue;
|
||||||
{$ENDIF HAS_EXP_TREE}
|
{$ENDIF HAS_EXP_TREE}
|
||||||
|
if AIsChoiceParent then
|
||||||
|
FSymbols.SetPropertyAsChoice(locProp,AIsChoiceParent);
|
||||||
ExtractExtendedMetadata(locProp,AElement);
|
ExtractExtendedMetadata(locProp,AElement);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -1286,7 +1294,8 @@ var
|
|||||||
procedure ParseElementsAndAttributes(
|
procedure ParseElementsAndAttributes(
|
||||||
AEltCrs,
|
AEltCrs,
|
||||||
AEltAttCrs : IObjectCursor;
|
AEltAttCrs : IObjectCursor;
|
||||||
ABoundInfos : TOccurrenceRec
|
ABoundInfos : TOccurrenceRec;
|
||||||
|
const AIsChoiceParent : Boolean
|
||||||
);
|
);
|
||||||
|
|
||||||
function ExtractElement(ANode : TDOMNode) : IObjectCursor;
|
function ExtractElement(ANode : TDOMNode) : IObjectCursor;
|
||||||
@ -1324,17 +1333,20 @@ var
|
|||||||
ExtractOccurences(s_choice,locEltAttCrs,locBoundInfos.MinOccurs,locBoundInfos.MaxOccurs,locBoundInfos.Unboundded);
|
ExtractOccurences(s_choice,locEltAttCrs,locBoundInfos.MinOccurs,locBoundInfos.MaxOccurs,locBoundInfos.Unboundded);
|
||||||
locBoundInfos.MinOccurs := 0;
|
locBoundInfos.MinOccurs := 0;
|
||||||
locBoundInfos.Valid := True;
|
locBoundInfos.Valid := True;
|
||||||
ParseElementsAndAttributes(locEltCrs,locEltAttCrs,locBoundInfos);
|
ParseElementsAndAttributes(locEltCrs,locEltAttCrs,locBoundInfos,AIsChoiceParent);
|
||||||
end;
|
end;
|
||||||
end else begin
|
end else begin
|
||||||
ParseElement(locNode,ABoundInfos);
|
ParseElement(locNode,ABoundInfos,AIsChoiceParent);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
if Assigned(AEltAttCrs) then begin
|
if Assigned(AEltAttCrs) then begin
|
||||||
AEltAttCrs.Reset();
|
AEltAttCrs.Reset();
|
||||||
while AEltAttCrs.MoveNext() do begin
|
while AEltAttCrs.MoveNext() do begin
|
||||||
ParseElement((AEltAttCrs.GetCurrent() as TDOMNodeRttiExposer).InnerObject,ABoundInfos);
|
ParseElement(
|
||||||
|
(AEltAttCrs.GetCurrent() as TDOMNodeRttiExposer).InnerObject,
|
||||||
|
ABoundInfos,AIsChoiceParent
|
||||||
|
);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -1397,6 +1409,7 @@ var
|
|||||||
locDefaultAncestorUsed : Boolean;
|
locDefaultAncestorUsed : Boolean;
|
||||||
locBoundInfos : TOccurrenceRec;
|
locBoundInfos : TOccurrenceRec;
|
||||||
locTempNode : TDOMNode;
|
locTempNode : TDOMNode;
|
||||||
|
locIsChoiceParent : Boolean;
|
||||||
begin
|
begin
|
||||||
ExtractBaseType();
|
ExtractBaseType();
|
||||||
eltCrs := ExtractElementCursor(nil,eltAttCrs,grpCrs,attGrpCrs,locAnyNode,locAnyAttNode);
|
eltCrs := ExtractElementCursor(nil,eltAttCrs,grpCrs,attGrpCrs,locAnyNode,locAnyAttNode);
|
||||||
@ -1443,6 +1456,7 @@ begin
|
|||||||
classDef.AncestorType.AddRef();
|
classDef.AncestorType.AddRef();
|
||||||
if Assigned(eltCrs) or Assigned(eltAttCrs) then begin
|
if Assigned(eltCrs) or Assigned(eltAttCrs) then begin
|
||||||
isArrayDef := False;
|
isArrayDef := False;
|
||||||
|
locIsChoiceParent := False;
|
||||||
FillChar(locBoundInfos,SizeOf(locBoundInfos),#0);
|
FillChar(locBoundInfos,SizeOf(locBoundInfos),#0);
|
||||||
if (eltCrs <> nil) then begin
|
if (eltCrs <> nil) then begin
|
||||||
eltCrs.Reset();
|
eltCrs.Reset();
|
||||||
@ -1457,10 +1471,11 @@ begin
|
|||||||
);
|
);
|
||||||
locBoundInfos.MinOccurs := 0;
|
locBoundInfos.MinOccurs := 0;
|
||||||
locBoundInfos.Valid := True;
|
locBoundInfos.Valid := True;
|
||||||
|
locIsChoiceParent := True;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
ParseElementsAndAttributes(eltCrs,eltAttCrs,locBoundInfos);
|
ParseElementsAndAttributes(eltCrs,eltAttCrs,locBoundInfos,locIsChoiceParent);
|
||||||
ParseGroups(classDef,grpCrs);
|
ParseGroups(classDef,grpCrs);
|
||||||
ParseGroups(classDef,attGrpCrs);
|
ParseGroups(classDef,attGrpCrs);
|
||||||
if ( arrayItems.GetCount() > 0 ) then begin
|
if ( arrayItems.GetCount() > 0 ) then begin
|
||||||
|
Loading…
Reference in New Issue
Block a user