allo
Also ich habe den einen Tag meine WebService soweit fertig programmiert und wollte meine WebService umstellen
und ihn mit JaxB nutzen. Also ich benutze Eclipse 3.5, JDK 1.5 ( JaxB implementiert ) JRE 1.5 und als Server JBoss.
So ich weis jedoch nicht so genau wie ich das genau mache, mit der Umstellung auf JaxB und ob es unbedingt sinnvoll ist.
Es geht darum, dass in meinen WebService eine Suchfunktion drin ist die einen Index nach Dokumenten durchsucht und diese Ausgibt. Diese Dokumente methoden (ID ; Name ) kommen aus der Klasse "Document" und diese sollen dann in meinen Webservice durchsucht werden und in eine Liste gebracht werden. Jedoch hat dieses nie funktioniert, weil er immer Probleme mit der Arrayumwandlung hatte und XML usw. Ich hatte es so gelöst, das ich die Methoden ID ; Name in eine eigene Klasse gekapselt habe und diese dann erste separat aufgerufen habe und damit hatte es funktioniet. Natürlich wäre das sehr umständlich wenn ich immer alles extra kapseln müsste und nun stellt sich die Frage ob es nicht jaxB und den xml annotation nicht einfacher geht und es doch möglich macht das ganze ohne kapseln. Schaut euch einfach den Quelltext an und ihr seht bestimmt was ich meine.
Wie genau schreibe ich das um mit JaxB und xml annotation.
Danke
Mein Webservice
@WebService(name = "SearchService", serviceName = "SearchService", targetNamespace = "http://www.test.de")
@SOAPBinding(style = SOAPBinding.Style.RPC) ////Kommunikation über SOAP prozedurorientiert
public class SearchService {
@EJB
SearchLocal searchBean;
SearchLocal getSearchBean() {
if (searchBean == null) {
try {
searchBean = (SearchLocal) new InitialContext()
.lookup("java:comp/env/ejb/SearchEJB");
} catch (Exception a) {
throw new RuntimeException(a);
}
}
return searchBean;
}
@WebMethod
public void createIndex ()
{ try {
getSearchBean().createIndex();
} catch (Exception e) {
e.printStackTrace();
}
}
@WebMethod
public WSDocument [] searchInDocumentFieldsForSimpleSearch(final String and_search, final Long userId)
{
List<Document> documents=
getSearchBean().searchInDocumentFieldsForSimpleSearch(and_search, userId);
WSDocument ret[] = new WSDocument[documents.size()];
for(int x = 0; x != documents.size(); x++) //durchläuft class WSDocument
{
ret[x] = new WSDocument(documents.get(x));
}
return ret;
}
Meine Klasse Document
@Entity
@Indexed(index = Item.INDEXNAME)
@Table(name = "DOCUMENT")
@PrimaryKeyJoinColumn(name = "itemid")
@OnDelete(action = OnDeleteAction.CASCADE)
public class Document extends Item {
private static final long serialVersionUID = 4383112294280993163L;
@Embeddable
static public class NumberingFormat implements Serializable {
private static final long serialVersionUID = -6523464405795614043L;
private String format;
private Integer sequenceId;
@Column(name = "format", length = 100, nullable = true)
public String getFormat() {
return format;
}
public void setFormat(String format) {
this.format = format;
}
@Column(name = "sequenceId", nullable = true)
public Integer getSequenceId() {
return sequenceId;
}
public void setSequenceId(Integer sequenceId) {
this.sequenceId = sequenceId;
}
}
private String name;
private NumberingFormat numberingFormat;
private Workflow workflow;
private WorkflowStatus status;
private Community community;
private Template template;
private Integer majorVersion;
private Integer minorVersion;
private java.util.Date expiryDate;
private User originator;
private User lastModifier;
private User lockingUser;
private Long revisionId;
private Document revision;
private Document previous;
private List<DocumentField> documentFields = new ArrayList<DocumentField>(0);
private Set<DocumentParticipant> participants = new HashSet<DocumentParticipant>(
0);
private Set<DocumentAuthor> authors = new HashSet<DocumentAuthor>(0);
private Set<DocumentCategory> categories = new HashSet<DocumentCategory>(0);
private Set<DocumentRating> ratings = new HashSet<DocumentRating>(0);
private Set<Commentary> commentaries = new HashSet<Commentary>(0);
/** The favorites. */
private Set<User> inFavorOfUsers = new HashSet<User>(0);
protected Set<DocumentStatusTask> documentStatusTasks = new HashSet<DocumentStatusTask>(
0);
public Document() {
}
@OneToMany(mappedBy = "document")
@OnDelete(action = OnDeleteAction.CASCADE)
public Set<Commentary> getCommentaries() {
return commentaries;
}
public void setCommentaries(Set<Commentary> commentaries) {
this.commentaries = commentaries;
}
@OneToMany(mappedBy = "document")
@OnDelete(action = OnDeleteAction.CASCADE)
public Set<DocumentRating> getRatings() {
return ratings;
}
public void setRatings(Set<DocumentRating> ratings) {
this.ratings = ratings;
}
@OneToMany(mappedBy = "document")
@OnDelete(action = OnDeleteAction.CASCADE)
public Set<DocumentCategory> getCategories() {
return categories;
}
public void setCategories(Set<DocumentCategory> categories) {
this.categories = categories;
}
@OneToMany(mappedBy = "document")
@OnDelete(action = OnDeleteAction.CASCADE)
public Set<DocumentAuthor> getAuthors() {
return authors;
}
public void setAuthors(Set<DocumentAuthor> authors) {
this.authors = authors;
}
@OneToMany(mappedBy = "document")
@OrderBy(value = "orderno")
@OnDelete(action = OnDeleteAction.CASCADE)
public List<DocumentField> getDocumentFields() {
return documentFields;
}
public void setDocumentFields(List<DocumentField> documentFields) {
this.documentFields = documentFields;
}
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "expirydate")
public java.util.Date getExpiryDate() {
return expiryDate;
}
public void setExpiryDate(java.util.Date expiryDate) {
this.expiryDate = expiryDate;
}
@ManyToOne
@ForeignKey(name = "FK_DOCUMENT_MODIFIER")
@JoinColumn(name = "changeuserid")
public User getLastModifier() {
return lastModifier;
}
public void setLastModifier(User lastModifyer) {
this.lastModifier = lastModifyer;
}
@Column(name = "major_version", nullable = false)
public Integer getMajorVersion() {
return majorVersion;
}
public void setMajorVersion(Integer majorVersion) {
this.majorVersion = majorVersion;
}
@Column(name = "minor_version", nullable = false)
public Integer getMinorVersion() {
return minorVersion;
}
public void setMinorVersion(Integer minorVersion) {
this.minorVersion = minorVersion;
}
@Column(name = "name", nullable = false)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
....... geht noch weiter aber das reicht
Mein gekapselte Klasse WSDocument
public class WSDocument {
Document document = new Document();
public WSDocument() {
super();
}
public WSDocument(Document document) {
super();
this.document = document;
}
public Long getId() {
return document.getId();
}
public String getName() {
return document.getName();
}
public void setId(Long id) {
document.setId(id);
}
public void setName(String name) {
document.setName(name);
}
}