Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
java_dzienna_15_09
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patryk Czarnik
java_dzienna_15_09
Commits
8fb7b555
Commit
8fb7b555
authored
Oct 06, 2022
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adnotacje JAX-WS i JAXB, aby zcustomizować XMLa
parent
4c17a0b0
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
70 additions
and
7 deletions
+70
-7
AdapterDaty.java
PC32-SoapSerwer/src/main/java/sklep/model/AdapterDaty.java
+17
-0
Customer.java
PC32-SoapSerwer/src/main/java/sklep/model/Customer.java
+4
-0
Order.java
PC32-SoapSerwer/src/main/java/sklep/model/Order.java
+16
-0
Product.java
PC32-SoapSerwer/src/main/java/sklep/model/Product.java
+11
-1
package-info.java
PC32-SoapSerwer/src/main/java/sklep/model/package-info.java
+5
-0
Sklep.java
PC32-SoapSerwer/src/main/java/sklep/soap/Sklep.java
+17
-6
No files found.
PC32-SoapSerwer/src/main/java/sklep/model/AdapterDaty.java
0 → 100644
View file @
8fb7b555
package
sklep
.
model
;
import
java.time.LocalDateTime
;
import
javax.xml.bind.annotation.adapters.XmlAdapter
;
public
class
AdapterDaty
extends
XmlAdapter
<
String
,
LocalDateTime
>
{
@Override
public
String
marshal
(
LocalDateTime
d
)
{
return
d
.
toString
();
}
@Override
public
LocalDateTime
unmarshal
(
String
s
)
{
return
LocalDateTime
.
parse
(
s
);
}
}
PC32-SoapSerwer/src/main/java/sklep/model/Customer.java
View file @
8fb7b555
...
...
@@ -2,11 +2,15 @@ package sklep.model;
import
java.util.Objects
;
import
javax.xml.bind.annotation.XmlElement
;
public
class
Customer
{
private
String
email
;
private
String
name
;
@XmlElement
(
name
=
"phone"
)
private
String
phoneNumber
;
private
String
address
;
@XmlElement
(
name
=
"postal-code"
)
private
String
postalCode
;
private
String
city
;
...
...
PC32-SoapSerwer/src/main/java/sklep/model/Order.java
View file @
8fb7b555
...
...
@@ -7,11 +7,27 @@ import java.util.Collections;
import
java.util.List
;
import
java.util.Objects
;
import
javax.xml.bind.annotation.XmlAttribute
;
import
javax.xml.bind.annotation.XmlElement
;
import
javax.xml.bind.annotation.XmlElementWrapper
;
import
javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter
;
public
class
Order
{
@XmlAttribute
(
name
=
"id"
)
private
Integer
orderId
;
@XmlElement
(
name
=
"customer-email"
)
private
String
customerEmail
;
@XmlElement
(
name
=
"order-date"
)
@XmlJavaTypeAdapter
(
AdapterDaty
.
class
)
private
LocalDateTime
orderDate
;
@XmlAttribute
(
name
=
"status"
)
private
Status
orderStatus
;
@XmlElementWrapper
(
name
=
"products"
)
@XmlElement
(
name
=
"product"
)
public
final
List
<
OrderProduct
>
products
=
new
ArrayList
<>();
public
Order
()
{
...
...
PC32-SoapSerwer/src/main/java/sklep/model/Product.java
View file @
8fb7b555
...
...
@@ -3,8 +3,18 @@ package sklep.model;
import
java.math.BigDecimal
;
import
java.util.Objects
;
import
javax.xml.bind.annotation.XmlAttribute
;
import
javax.xml.bind.annotation.XmlElement
;
/* Technologia JAXB jest odpowiedzialna za automatyczne tłumaczenie obiektów Javy do postaci XML i odwrotnie.
* To działa w oparciu o adnotacje, których większośc rozpoczyna się od @Xml....
* Za pomocą takich adnotacji możemy wpłynąć na postać XML (nazwy, kolejność, sposób konwersji).
*/
public
class
Product
{
@XmlAttribute
(
name
=
"id"
)
private
Integer
productId
;
@XmlElement
(
name
=
"name"
)
private
String
productName
;
private
BigDecimal
price
;
private
BigDecimal
vat
;
...
...
@@ -30,7 +40,7 @@ public class Product {
}
public
String
getProductName
()
{
return
productName
;
return
"blablabla "
+
productName
.
toUpperCase
()
+
"beleble"
;
}
public
void
setProductName
(
String
productName
)
{
...
...
PC32-SoapSerwer/src/main/java/sklep/model/package-info.java
0 → 100644
View file @
8fb7b555
@XmlAccessorType
(
XmlAccessType
.
FIELD
)
package
sklep
.
model
;
import
javax.xml.bind.annotation.XmlAccessType
;
import
javax.xml.bind.annotation.XmlAccessorType
;
PC32-SoapSerwer/src/main/java/sklep/soap/Sklep.java
View file @
8fb7b555
...
...
@@ -3,6 +3,8 @@ package sklep.soap;
import
java.math.BigDecimal
;
import
java.util.List
;
import
javax.jws.WebParam
;
import
javax.jws.WebResult
;
import
javax.jws.WebService
;
import
sklep.db.CustomerDAO
;
...
...
@@ -17,7 +19,7 @@ import sklep.model.Product;
@WebService
public
class
Sklep
{
@WebResult
(
name
=
"product"
)
public
List
<
Product
>
odczytajWszystkieProdukty
()
throws
DBException
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
ProductDAO
productDAO
=
db
.
productDAO
();
...
...
@@ -25,20 +27,26 @@ public class Sklep {
}
}
public
List
<
Product
>
produktyWgCeny
(
BigDecimal
min
,
BigDecimal
max
)
throws
DBException
{
@WebResult
(
name
=
"product"
)
public
List
<
Product
>
produktyWgCeny
(
@WebParam
(
name
=
"min"
)
BigDecimal
minPrice
,
@WebParam
(
name
=
"max"
)
BigDecimal
maxPrice
)
throws
DBException
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
ProductDAO
productDAO
=
db
.
productDAO
();
return
productDAO
.
findByPrice
(
min
,
max
);
return
productDAO
.
findByPrice
(
min
Price
,
maxPrice
);
}
}
public
Product
odczytajJedenProdukt
(
int
productId
)
throws
DBException
,
RecordNotFound
{
@WebResult
(
name
=
"product"
)
public
Product
odczytajJedenProdukt
(
@WebParam
(
name
=
"id"
)
int
productId
)
throws
DBException
,
RecordNotFound
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
ProductDAO
productDAO
=
db
.
productDAO
();
return
productDAO
.
findById
(
productId
);
}
}
@WebResult
(
name
=
"order"
)
public
List
<
Order
>
odczytajWszystkieZamowienia
()
throws
DBException
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
OrderDAO
orderDAO
=
db
.
orderDAO
();
...
...
@@ -46,13 +54,15 @@ public class Sklep {
}
}
public
Order
odczytajJednoZamowienie
(
int
orderId
)
throws
DBException
,
RecordNotFound
{
@WebResult
(
name
=
"order"
)
public
Order
odczytajJednoZamowienie
(
@WebParam
(
name
=
"id"
)
int
orderId
)
throws
DBException
,
RecordNotFound
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
OrderDAO
orderDAO
=
db
.
orderDAO
();
return
orderDAO
.
findById
(
orderId
);
}
}
@WebResult
(
name
=
"customer"
)
public
List
<
Customer
>
odczytajWszystkichKlientow
()
throws
DBException
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
CustomerDAO
customerDAO
=
db
.
customerDAO
();
...
...
@@ -60,7 +70,8 @@ public class Sklep {
}
}
public
Customer
odczytajJednegoKlienta
(
String
email
)
throws
DBException
,
RecordNotFound
{
@WebResult
(
name
=
"customer"
)
public
Customer
odczytajJednegoKlienta
(
@WebParam
(
name
=
"email"
)
String
email
)
throws
DBException
,
RecordNotFound
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
CustomerDAO
customerDAO
=
db
.
customerDAO
();
return
customerDAO
.
findByEmail
(
email
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment