update at 2023/08/14
This commit is contained in:
58
tools/xgen/cm-schema.xsd.go
Normal file
58
tools/xgen/cm-schema.xsd.go
Normal file
@@ -0,0 +1,58 @@
|
||||
// Code generated by xgen. DO NOT EDIT.
|
||||
|
||||
package schema
|
||||
|
||||
// FileHeader ...
|
||||
type FileHeader struct {
|
||||
TimeStamp string `xml:"TimeStamp"`
|
||||
TimeZone string `xml:"TimeZone"`
|
||||
VendorName string `xml:"VendorName"`
|
||||
ElementType string `xml:"ElementType"`
|
||||
CmVersion string `xml:"CmVersion"`
|
||||
}
|
||||
|
||||
// N ...
|
||||
type N struct {
|
||||
IAttr int `xml:"i,attr"`
|
||||
Value string `xml:",chardata"`
|
||||
}
|
||||
|
||||
// FieldName ...
|
||||
type FieldName struct {
|
||||
N *N `xml:"N"`
|
||||
}
|
||||
|
||||
// V ...
|
||||
type V struct {
|
||||
IAttr int `xml:"i,attr"`
|
||||
Value string `xml:",chardata"`
|
||||
}
|
||||
|
||||
// Object ...
|
||||
type Object struct {
|
||||
RmUIDAttr string `xml:"rmUID,attr"`
|
||||
DnAttr string `xml:"Dn,attr,omitempty"`
|
||||
UserLabelAttr string `xml:"UserLabel,attr,omitempty"`
|
||||
PVFlagAttr string `xml:"PVFlag,attr"`
|
||||
VMIDAttr string `xml:"VMID,attr,omitempty"`
|
||||
VNFInstanceIDAttr string `xml:"VNFInstanceID,attr,omitempty"`
|
||||
V *V `xml:"V"`
|
||||
}
|
||||
|
||||
// FieldValue ...
|
||||
type FieldValue struct {
|
||||
Object *Object `xml:"Object"`
|
||||
}
|
||||
|
||||
// Objects ...
|
||||
type Objects struct {
|
||||
ObjectType string `xml:"ObjectType"`
|
||||
FieldName *FieldName `xml:"FieldName"`
|
||||
FieldValue *FieldValue `xml:"FieldValue"`
|
||||
}
|
||||
|
||||
// DataFile ...
|
||||
type DataFile struct {
|
||||
FileHeader *FileHeader `xml:"FileHeader"`
|
||||
Objects []*Objects `xml:"Objects"`
|
||||
}
|
||||
65
tools/xgen/pm-schema.xsd.go
Normal file
65
tools/xgen/pm-schema.xsd.go
Normal file
@@ -0,0 +1,65 @@
|
||||
// Code generated by xgen. DO NOT EDIT.
|
||||
|
||||
package schema
|
||||
|
||||
// FileHeader ...
|
||||
type FileHeader struct {
|
||||
TimeStamp string `xml:"TimeStamp"`
|
||||
TimeZone string `xml:"TimeZone"`
|
||||
Period int `xml:"Period"`
|
||||
VendorName string `xml:"VendorName"`
|
||||
ElementType string `xml:"ElementType"`
|
||||
PmVersion string `xml:"PmVersion"`
|
||||
StartTime string `xml:"StartTime"`
|
||||
}
|
||||
|
||||
// N ...
|
||||
type N struct {
|
||||
IAttr int `xml:"i,attr"`
|
||||
Value string `xml:",chardata"`
|
||||
}
|
||||
|
||||
// PmName ...
|
||||
type PmName struct {
|
||||
N *N `xml:"N"`
|
||||
}
|
||||
|
||||
// V ...
|
||||
type V struct {
|
||||
IAttr int `xml:"i,attr"`
|
||||
Value string `xml:",chardata"`
|
||||
}
|
||||
|
||||
// CV ...
|
||||
type CV struct {
|
||||
IAttr int `xml:"i,attr"`
|
||||
SN []string `xml:"SN"`
|
||||
SV []string `xml:"SV"`
|
||||
}
|
||||
|
||||
// Object ...
|
||||
type Object struct {
|
||||
RmUIDAttr string `xml:"rmUID,attr"`
|
||||
DnAttr string `xml:"Dn,attr"`
|
||||
UserLabelAttr string `xml:"UserLabel,attr"`
|
||||
V []*V `xml:"V"`
|
||||
CV []*CV `xml:"CV"`
|
||||
}
|
||||
|
||||
// PmData ...
|
||||
type PmData struct {
|
||||
Object *Object `xml:"Object"`
|
||||
}
|
||||
|
||||
// Measurements ...
|
||||
type Measurements struct {
|
||||
ObjectType string `xml:"ObjectType"`
|
||||
PmName *PmName `xml:"PmName"`
|
||||
PmData *PmData `xml:"PmData"`
|
||||
}
|
||||
|
||||
// PmFile ...
|
||||
type PmFile struct {
|
||||
FileHeader *FileHeader `xml:"FileHeader"`
|
||||
Measurements []*Measurements `xml:"Measurements"`
|
||||
}
|
||||
128
tools/xgen/xgen.go
Normal file
128
tools/xgen/xgen.go
Normal file
@@ -0,0 +1,128 @@
|
||||
// Copyright 2020 - 2022 The xgen Authors. All rights reserved. Use of this
|
||||
// source code is governed by a BSD-style license that can be found in the
|
||||
// LICENSE file.
|
||||
//
|
||||
// xgen is a tool to automatically compiles XML schema files into the
|
||||
// multi-language type or class declarations code.
|
||||
//
|
||||
// Usage:
|
||||
//
|
||||
// $ xgen [<flag> ...] <XSD file or directory> ...
|
||||
// -i <path> Input file path or directory for the XML schema definition
|
||||
// -o <path> Output file path or directory for the generated code
|
||||
// -p Specify the package name
|
||||
// -l Specify the language of generated code (Go/C/Java/Rust/TypeScript)
|
||||
// -h Output this help and exit
|
||||
// -v Output version and exit
|
||||
//
|
||||
// If the path specified by the -i flag is a directory, all files in the
|
||||
// directory will be processed as XML schema definition.
|
||||
//
|
||||
// The default package name and output directory are "schema" and "xgen_out".
|
||||
//
|
||||
// Currently support language is Go.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/xuri/xgen"
|
||||
)
|
||||
|
||||
// Config holds user-defined overrides and filters that are used when
|
||||
// generating source code from an XSD document.
|
||||
type Config struct {
|
||||
I string
|
||||
O string
|
||||
Pkg string
|
||||
Lang string
|
||||
Version string
|
||||
}
|
||||
|
||||
// Cfg are the default config for xgen. The default package name and output
|
||||
// directory are "schema" and "xgen_out".
|
||||
var Cfg = Config{
|
||||
Pkg: "schema",
|
||||
Version: "0.1.0",
|
||||
}
|
||||
|
||||
// SupportLang defines supported language types.
|
||||
var SupportLang = map[string]bool{
|
||||
"Go": true,
|
||||
"C": true,
|
||||
"Java": true,
|
||||
"Rust": true,
|
||||
"TypeScript": true,
|
||||
}
|
||||
|
||||
// parseFlags parse flags of program.
|
||||
func parseFlags() *Config {
|
||||
iPtr := flag.String("i", "", "Input file path or directory for the XML schema definition")
|
||||
oPtr := flag.String("o", "xgen_out", "Output file path or directory for the generated code")
|
||||
pkgPtr := flag.String("p", "", "Specify the package name")
|
||||
langPtr := flag.String("l", "", "Specify the language of generated code")
|
||||
verPtr := flag.Bool("v", false, "Show version and exit")
|
||||
helpPtr := flag.Bool("h", false, "Show this help and exit")
|
||||
flag.Parse()
|
||||
if *helpPtr {
|
||||
fmt.Printf("xgen version: %s\r\nCopyright (c) 2020 - 2022 Ri Xu https://xuri.me All rights reserved.\r\n\r\nUsage:\r\n$ xgen [<flag> ...] <XSD file or directory> ...\n -i <path>\tInput file path or directory for the XML schema definition\r\n -o <path>\tOutput file path or directory for the generated code\r\n -p \tSpecify the package name\r\n -l \tSpecify the language of generated code (Go/C/Java/Rust/TypeScript)\r\n -h \tOutput this help and exit\r\n -v \tOutput version and exit\r\n", Cfg.Version)
|
||||
os.Exit(0)
|
||||
}
|
||||
if *verPtr {
|
||||
fmt.Printf("xgen version: %s\r\n", Cfg.Version)
|
||||
os.Exit(0)
|
||||
}
|
||||
if *iPtr == "" {
|
||||
fmt.Println("must specify input file path or directory for the XML schema definition")
|
||||
os.Exit(1)
|
||||
}
|
||||
Cfg.I = *iPtr
|
||||
if *langPtr == "" {
|
||||
fmt.Println("must specify the language of generated code (Go/C/Java/Rust/TypeScript)")
|
||||
os.Exit(1)
|
||||
}
|
||||
Cfg.Lang = *langPtr
|
||||
if *oPtr != "" {
|
||||
Cfg.O = *oPtr
|
||||
}
|
||||
if ok := SupportLang[Cfg.Lang]; !ok {
|
||||
fmt.Println("unsupport language", Cfg.Lang)
|
||||
os.Exit(1)
|
||||
}
|
||||
if *pkgPtr != "" {
|
||||
Cfg.Pkg = *pkgPtr
|
||||
}
|
||||
return &Cfg
|
||||
}
|
||||
|
||||
func main() {
|
||||
cfg := parseFlags()
|
||||
files, err := xgen.GetFileList(cfg.I)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
for _, file := range files {
|
||||
if err = xgen.NewParser(&xgen.Options{
|
||||
FilePath: file,
|
||||
InputDir: cfg.I,
|
||||
OutputDir: cfg.O,
|
||||
Lang: cfg.Lang,
|
||||
Package: cfg.Pkg,
|
||||
IncludeMap: make(map[string]bool),
|
||||
LocalNameNSMap: make(map[string]string),
|
||||
NSSchemaLocationMap: make(map[string]string),
|
||||
ParseFileList: make(map[string]bool),
|
||||
ParseFileMap: make(map[string][]interface{}),
|
||||
ProtoTree: make([]interface{}, 0),
|
||||
RemoteSchema: make(map[string][]byte),
|
||||
}).Parse(); err != nil {
|
||||
fmt.Printf("process error on %s: %s\r\n", file, err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
fmt.Println("done")
|
||||
}
|
||||
Reference in New Issue
Block a user