Given that we can't create a hierarchy of annoations, why-is-not-possible-to-extend-annotations-in-java
how to decalare an array of object to store an ordered list of different annotations
public @interface View {
Object[] elements();
//Invalid type Object[] for the annotation attribute View.elements; only
primitive type, String, Class, annotation, enumeration are permitted
or 1-dimensional arrays thereof
}
Elements could be @Field, @Tab, @Listing .... but i need to know the order
The needs is that i have a xml hierarchy tree like this
<view id="StkEntranceVoucher" name="StkEntranceVoucher" >
<listingHeader />
<listing >
<ref mode="vp" target="titleText"/>
<ref mode="vp" target="voucherNumber"/>
</listing>
<panel>
<tab>
<tab>
<panel>
<field name="title" />
</panel>
<field name="titleText" />
<field name="voucherNumber">
</tab>
</tab>
</panel>
</view>
i want to be able to generate this XML config, with anotation configuration on the model : i am already able to do this
@View(queryFilter=@QueryFilter(orderBy="(?).id.num"), detailSize="580px",
listingHeader=@ListingHeader(actions="printAll"),
listing={ "id.num", "reference", "onDate", "fromSection", "supplier",
"totalField", "buyOrder.id.num", "buyOrder.onDate", "receiptVcr.id.num", "receiptVcr.onDate",
"prdExitOrd.id.num", "prdExitOrd.onDate", "invExtract.id.num", "invExtract.onDate" },
tabs={
@Tab(name="GeneralTab",
SubTabs={
@SubTab( name="HeaderTab",
style =@Style(type=StlType.print, colWidths={"50", "400"}, width="450", marginB=2, marginT=8 ),
fields={
@Field(name="titleText", mode="p", valueExpr="#{bean.mapID( wcx,'reportTitle')}", expectedType=String.class,
style=@Style(type=StlType.print, align="center", bold=true, fontSize=16, marginT=20, paddingB=4, paddingL=4, paddingR=4, paddingT=4, textAlign="center", width="200")),
@Field(name="voucherNumberText", mode="p", valueExpr="#{bean.mapID( wcx,'VoucherNum')} : #{(?).id.num} #{bean.mapID( wcx,'VoucherOf')} #{util.format((?).onDate, 'dd/MM/yyyy')}", expectedType=String.class,
style=@Style(type=StlType.print, align="center", fontSize=10, textAlign="center" )),
@Field(name="id.sgSr", mode="", queryFilter=true),
@Field(name="id.num", width="60px", mode="v"),
@Field(name="reference"),
@Field(name="onDate", mode="v"),
@Field(name="fromSection"),
@Field(name="supplier") }
),
@SubTab( name="ItemsTab", subView=
@SubView( name="StkEntranceVoucherItem", entityType=StkInputVoucherItem.class, editable=true,
listingFields={
@Field(name="id.vcr", mode="", queryFilter=true),
@Field(name="id.item", width="60px", codeLabel=true),
@Field(name="id.item.label", width="150px", mode="rvp"),
@Field(name="quantity", width="60px"),
@Field(name="id.item.measureUnit", width="50px", mode="rpv"),
@Field(name="unitPrice", width="60px"),
@Field(name="amount", width="80px", mode="rvp",
calcExpr="#{(?).quantity*(?).unitPrice}"),
@Field(name="batch", jsfCpn=JsfCpn.button, linkedViewName="StkInputVoucherBatch",
styleClass="no_padding", width="24px"),
@Field(name="comment", width="100px") }) ),
@SubTab( name="StkEntranceVoucherTotalTab", style=@Style(css="float:right;"),
fields={
@Field( name="totalField", ofColFooter="amount", mode="rvp",
valueExpr="(?).amount", expectedType=Double.class,
calcExpr="#{(?)==bean.record?bean.sum(':amount'):(?).amount}") })
})
})
but its not fully the same syntax because here i use an array of @Tab and an array of @Field but i can't have an array of different annotations
I hope, I got your idea. You want to achieve something like the following:
@MyAnnotationContainer(
{@MyAnnotation1, @MyAnntation2, @MyAnntation3}
)
class MyClass {}
It is impossible in java. But you actually do not need this. You can put your annotations directly on the class:
@MyAnnotation1
@MyAnnotation2
@MyAnnotation3
class MyClass {}
Now you can get declared annotations from your class, so that you will actually get the ordered list that you want. Obviously you can filter the relevant annotations only and omit other (not yours) annotations.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.