- 浏览: 73941 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
george.gu:
lqjacklee 写道怎么解决。。 First: Conf ...
Bad version number in .class file -
lqjacklee:
怎么解决。。
Bad version number in .class file -
flyqantas:
would you pleade left more mate ...
UML Extension
1.1.1 JAXB 2.0: ObjectàXML
Using JAXB 2.0 embedded in JDK 1.6.
Marshal Object to XML bytes:
public byte[] marshalToBytes(Object o) throws Exception { JAXBContext context = JAXBContext.newInstance(o.getClass());
ByteArrayOutputStream bos = new ByteArrayOutputStream(); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); //set XML encoding. m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); //output formatted xml. m.setProperty(Marshaller.JAXB_FRAGMENT, false);// ignore XML header or not. m.marshal(o, bos);
return bos.toByteArray(); } |
If you want to output XML to specific file, please udpate "ByteArrayOutputStream bos" to write XML into external file.
1.1.2 Object class should have empty constructor
1.1.3 @XmlTransient to ignore some properties
Some temporary data or some cycle reference relation.
For example, DDFNode.parentDDFNode.
1.1.4 @XmlJavaTypeAdapter
@XmlJavaTypeAdapter is used to adapter complex Object which is not recognized by JAXB into a simple or customized Object.
1) XmlAdapter.marshal(BoundType):
a. Convert Object to another ValueType which is recognized by JAXB. Or Which is customized rather than JAXB.
b. Used when ObjectàXml
2) XmlAdapter.unmarshal(ValueType):
a. Convert ValueType Object to java Object requested by business logical.
b. Used when XmlàObject
“List<String> tacs” instead of “Set tacs”
@XmlJavaTypeAdapter on field will lead to additional container tag. For example:
@XmlJavaTypeAdapter(FileNamesAdapter.class)
Map<String, String> profileMappings;
Will lead to XML like following:
…
< profileMappings >
<profile-mapping …/>
<!--your wrapper xml element-->;
</ profileMappings >
But not:
<profile-mapping …/>
It’s better to use List<> as collection implementation. And all the Object use simple type.
There should be dedicated Xml Java adapter for DDFNode, because:
1) DFPropterties is dedicated complex element
2) Some elements have empty tag
3) List of child Nodes
4) …
1.1.5 @XmlType: Order of the Element: @XmlType(propOrder = {“parameterNames”})
Use field name but not element name.
All the fields should be specified, even some of them are ignored by @XmlTransient.
1.1.6 Do not set CYCLE reference on Objects.
Normally, JAXB can detect the cycle reference problem.
1.1.7 @XmlSeeAlso: used to bind related InteriorDDFNode and LeafDDFNode
@XmlSeeAlso({InteriorDDFNode.class, LeafDDFNode.class})
public abstract class DDFNode extends IdClass {
…
}
@XmlSeeAlso can be used to link the bund to its related subclasses. It will be used to define InteriorDDFNode and LeafDDFNode. Because DDFTree use following definition:
@XmlElement(name = "Node") private List<DDFNode> ddfNodes; |
1.1.8 @XmlElementWrapper or not
@XmlElementWrapper is used to add a container tag for list,
For model/ddf, model/profile-mapping, there is no @XmlElementWrapper.
But for ddf*.xml, @XmlElementWrapper is used to define container, such as Node/DFProperties/AccessType(Get?, Add?, …).
1.1.9 @XmlSeeAlso + @XmlJavaTypeAdapter = what will happen????
1.1.10 @XmlElements + @XmlJavaTypeAdapter to generate DDFNode/DFProperties
There is no dedicated DFProperties bean object inside DDFNode.java.
Information for DFProperties are dynamic and has different value types.
Use XmlJavaTypeAdapter convert String value list to AccessType Object List:
List<AccessTypeBase> accessTypes = new ArrayList<AccessTypeBase>(); for (String access : b.accessTypes) { if (access.equalsIgnoreCase(AccessTypeAdd.ACCESS)) { accessTypes.add(new AccessTypeAdd()); } else if (access.equalsIgnoreCase(AccessTypeCopy.ACCESS)) { accessTypes.add(new AccessTypeCopy()); } else if (access.equalsIgnoreCase(AccessTypeDelete.ACCESS)) { accessTypes.add(new AccessTypeDelete()); } else if (access.equalsIgnoreCase(AccessTypeExec.ACCESS)) { accessTypes.add(new AccessTypeExec()); } else if (access.equalsIgnoreCase(AccessTypeReplace.ACCESS)) { accessTypes.add(new AccessTypeReplace()); } else { accessTypes.add(new AccessTypeGet()); } } |
We can also use Map<accessTyeString, classNameString> to ignore many if...else....
Define XmlElements according to different Access Type class instance:
@XmlElementWrapper(name = "AccessType") @XmlElements( { @XmlElement(name="Add",type=AccessTypeAdd.class), @XmlElement(name="Copy",type=AccessTypeCopy.class), @XmlElement(name="Delete",type=AccessTypeDelete.class), @XmlElement(name="Exec",type=AccessTypeExec.class), @XmlElement(name="Get",type=AccessTypeGet.class), @XmlElement(name="Replace",type=AccessTypeReplace.class) }) public List<AccessTypeBase> accessTypes; |
Then it will generate the XML format like following:
<AccessType> <Get/> <Add/> <Replace/> </AccessType> |
发表评论
文章已被作者锁定,不允许评论。
-
javax.naming.CommunicationException: remote side declared peer gone on this JVM.
2012-07-11 09:44 2388javax.naming.ServiceUnavailable ... -
Generate special format numbers
2012-04-27 00:06 951DecimalFormat df = new DecimalF ... -
Singleton Service in Weblogic Cluster
2012-03-21 00:12 725http://blog.csdn.net/mobicents/ ... -
Scheduled ThreadPool Executor suppressed or stopped after error happen
2012-03-20 16:54 1049ScheduledThreadPoolExecutor ... -
Bad version number in .class file
2012-01-27 00:35 901Bad version number in .class fi ... -
User Data Header in SMPP SUBMIT_SM
2012-01-25 22:30 2335SMPP optional Parameters for ... -
jQuery study
2011-12-28 00:44 0to be study -
Java is Pass-by-Value or Pass-by-Reference?
2011-12-19 19:18 691What's saved in Object Referenc ... -
java.util.Properties: a subclass of java.util.Hashtable
2011-12-13 06:57 779I met a problem this afternoon ... -
Jmock usage
2011-12-02 05:37 0Discuss how Jmock working. -
Oracle Index Usage
2011-12-15 05:26 633Like a hash mapping for record' ... -
AOP(2):AOP与动态代理JDK Proxy and Cglib Proxy
2011-05-12 16:20 1047使用动态代理(JDK Proxy 或者Cglib Proxy) ... -
AOP(1):应用中的几个小故事
2011-05-09 21:49 979I had heared about AOP almost 7 ... -
异步系统设计:push vs pull
2011-05-02 23:59 1142今天讨论问题时,有个同事说系统A是主动去系统B里“拿”消息,我 ... -
Velocity Usage
2011-04-28 22:52 1010You can find velocity mannua ... -
Java Regular Expression (Java正则表达式)
2011-04-23 06:58 954In current Project, we need to ... -
XML Parser:DOM + XPath
2011-04-23 06:30 1224There are many kinds of XML Par ... -
File upload and download in Java Web Application.
2011-04-21 21:08 1718最近在项目中遇到一个下载文件的老问题。之所以说是老问题,因为在 ... -
Manage zip content using Java APIs
2011-04-21 18:14 1044JDK provide a set of utils to c ... -
Beanshell: how and where to use beanshell
2011-04-21 00:33 2099How to use beanshell beansh ...
相关推荐
春毒Spring3 JAXB编组和反编组。 #先决条件:-您应该拥有jdk1.7.x,apache tomcat7.x,apache-maven-3.2.3-bin和Git-1.9.4客户端工具。 #step1:-从回购中克隆项目。 #step2:-运行项目中已经存在的pom.xml Maven...
2. **JAXB2**:JAXB 提供了对象到 XML 的映射功能,实现了 OXM(Object XML Mapping),使得对象和 XML 文档之间的转换更加方便。 ### Java JDK 1.7 新特性 尽管没有直接给出 JDK 1.7 的特性,但这里可以列出一些...
现在我们可以用 JDK1.6 的 Compiler API(JSR 199)去动态编译 Java 源文件,Compiler API 结合反射功能就可以实现动态的产生 Java 代码并编译执行这些代码,有点动态语言的特征。这个特性对于某些需要用到动态编译...
<bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller"> <value>com.yourcompany.yourproject.YourRequestType</value> <value>com.yourcompany.yourproject.YourResponseType</value>...
"春使用OXM进行对象XML映射解析" 春框架中使用OXM(Object-XML Mapping)对对象进行XML映射解析,具有一定借鉴价值。下面将详细介绍春使用OXM进行对象XML映射解析的技术要点。 1. 认识XML解析技术 XML...
hibernate-jpa-2.0-api-1.0.1.Final.jar hibernate-validator-4.0.2.GA.jar httpclient-4.1.2.jar httpcore-4.1.2.jar jackson-core-asl-1.7.2.jar jackson-core-asl-1.9.9.jar jackson-jaxrs-1.7.2.jar jackson-jax...
5. **数据访问/集成**: 包括JDBC、ORM(Object-Relational Mapping,如Hibernate)、OXM(Object-XML Mapping,如JAXB)等支持,方便数据库和XML的交互。 6. **Web模块**: 提供了MVC框架、WebSocket支持、Servlet...
6. **数据访问/集成**:Spring支持多种数据访问技术,包括JDBC、ORM(Object-Relational Mapping,如Hibernate、JPA)和OXM(Object-XML Mapping,如JAXB)。 7. **MVC框架**:Spring MVC是Spring为构建Web应用程序...
6. **数据访问集成**:Spring提供了对各种数据库访问技术的支持,包括JDBC、ORM(Object-Relational Mapping,如Hibernate、MyBatis)和OXM(Object-XML Mapping,如JAXB)。Spring JDBC提供了一套模板方法来简化...
它与spring-aspects.jar配合,支持JDK动态代理和AspectJ的编译时及运行时织入。 5. **spring-expression.jar (SpEL)**:Spring表达式语言,提供强大且灵活的在运行时查询和操作对象图的能力。它用于在配置文件中...
12. **spring-oxm.jar**:对象/XML映射模块,提供了对不同XML绑定技术如JAXB、Castor、XStream的集成。 13. **spring-instrument.jar**:提供了类加载器的工具和接口,主要用于服务器端的应用,如Tomcat,提升类的...
11. **spring-oxm.jar**:提供了对象到XML映射的支持,支持如JAXB、Castor、XMLBeans和XStream等库,用于对象的序列化和反序列化。 在开发基于Spring的应用程序时,通常根据项目需求选择上述jar包的子集。这些基础...
1.6 Spring对Java版本的要求 1.7 如何获取Spring 1.8 小结 第2章 快速入门 2.1 实例功能概述 2.1.1 比Hello World更适用的实例 2.1.2 实例功能简介 2.2 环境准备 2.2.1 创建库表 2.2.2 建立工程 2.2.3 类包及Spring...
1.6 Spring对Java版本的要求 1.7 如何获取Spring 1.8 小结 第2章 快速入门 2.1 实例功能概述 2.1.1 比Hello World更适用的实例 2.1.2 实例功能简介 2.2 环境准备 2.2.1 创建库表 2.2.2 建立工程 2.2.3 类包及Spring...
- **OXM模块**:提供对象/XML映射的抽象层,支持JAXB、Castor、XMLBeans、JiBX和XStream等。 - **JMS模块**:用于处理Java消息服务。 - **事务模块**:支持编程和声明式的事务管理。 3. **Web层**: - **Web...