[英]how to declare an Array of Object in annoation?
鑒於我們無法創建注釋層次結構, 因此為什么無法在Java中擴展注釋
如何對對象數組進行貼花處理以存儲不同批注的有序列表
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
需要的是我有一個像這樣的xml層次樹
<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>
我希望能夠生成該XML配置以及模型上的注釋配置:我已經能夠做到這一點
@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}") })
})
})
但是它的語法不完全相同,因為在這里我使用@Tab數組和@Field數組,但是我不能使用不同注解數組
希望我知道您的想法。 您想要實現以下目標:
@MyAnnotationContainer(
{@MyAnnotation1, @MyAnntation2, @MyAnntation3}
)
class MyClass {}
在Java中是不可能的。 但是您實際上不需要這個。 您可以將注釋直接放在類上:
@MyAnnotation1
@MyAnnotation2
@MyAnnotation3
class MyClass {}
現在,您可以從類中獲取已聲明的批注,以便實際上將獲取所需的有序列表。 顯然,您只能過濾相關的注釋,而忽略其他(不是您的)注釋。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.