Skip to content
This repository was archived by the owner on May 28, 2018. It is now read-only.

Commit 6e7d95a

Browse files
committed
Refresh up to latest 2.8-SNAPSHOT code
1 parent f0119d9 commit 6e7d95a

File tree

21 files changed

+514
-201
lines changed

21 files changed

+514
-201
lines changed

core-common/src/main/java/org/glassfish/jersey/uri/internal/UriTemplateParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ private static Set<Character> initReserved() {
103103
*/
104104
public UriTemplateParser(final String template) throws IllegalArgumentException {
105105
if (template == null || template.length() == 0) {
106-
throw new IllegalArgumentException();
106+
throw new IllegalArgumentException("Template is null or has zero length");
107107
}
108108

109109
this.template = template;

examples/declarative-linking/src/main/java/org/glassfish/jersey/examples/linking/App.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,14 @@
4545
import java.net.URI;
4646
import java.util.logging.Level;
4747
import java.util.logging.Logger;
48+
import org.glassfish.grizzly.http.server.HttpHandler;
4849

4950
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
5051
import org.glassfish.jersey.server.ResourceConfig;
5152

5253
import org.glassfish.grizzly.http.server.HttpServer;
5354
import org.glassfish.jersey.linking.DeclarativeLinkingFeature;
54-
import org.glassfish.jersey.examples.linking.resources.ItemResource;
55+
import org.glassfish.jersey.examples.linking.resources.ItemsResource;
5556

5657
/**
5758
* Show link injection in action
@@ -66,12 +67,16 @@ public class App {
6667

6768
public static void main(String[] args) {
6869
try {
70+
Logger.getLogger(HttpHandler.class.getName()).setLevel(Level.ALL);
71+
6972
System.out.println("\"Declarative Linking\" Jersey Example App");
7073

71-
final ResourceConfig resourceConfig = new ResourceConfig(ItemResource.class);
74+
final ResourceConfig resourceConfig = new ResourceConfig(ItemsResource.class);
75+
7276
resourceConfig.register(DeclarativeLinkingFeature.class);
7377
final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, resourceConfig);
7478

79+
7580
System.out.println(String.format("Application started.\nTry out %s%s\nHit enter to stop it...",
7681
BASE_URI, ROOT_PATH));
7782
System.in.read();

examples/declarative-linking/src/main/java/org/glassfish/jersey/examples/linking/model/ItemsModel.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,10 @@ public static synchronized ItemsModel getInstance() {
6464

6565
private ItemsModel() {
6666
items = new ArrayList<ItemModel>();
67-
items.add(new ItemModel("Item 0"));
68-
items.add(new ItemModel("Item 1"));
69-
items.add(new ItemModel("Item 2"));
70-
items.add(new ItemModel("Item 3"));
71-
items.add(new ItemModel("Item 4"));
67+
for(int i=0; i < 100; i++)
68+
{
69+
items.add(new ItemModel("Item " + i));
70+
}
7271
}
7372

7473
public boolean hasNext(String currentId) {
@@ -94,4 +93,10 @@ public String getPrevId(String id) {
9493
private int getIndex(String id) {
9594
return Integer.parseInt(id);
9695
}
96+
97+
98+
public int getSize()
99+
{
100+
return items.size();
101+
}
97102
}

examples/declarative-linking/src/main/java/org/glassfish/jersey/examples/linking/representation/ItemRepresentation.java

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@
5252
import javax.xml.bind.annotation.XmlElement;
5353
import javax.xml.bind.annotation.XmlElementWrapper;
5454
import javax.xml.bind.annotation.XmlRootElement;
55+
import javax.xml.bind.annotation.XmlTransient;
5556
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
57+
import org.glassfish.jersey.examples.linking.model.ItemsModel;
5658

5759
/**
5860
* JAXB representation of an item
@@ -67,15 +69,15 @@
6769
@InjectLink(
6870
resource = ItemResource.class,
6971
style = Style.ABSOLUTE,
70-
condition = "${resource.next}",
71-
bindings = @Binding(name = "id", value = "${resource.nextId}"),
72+
condition = "${instance.next}",
73+
bindings = @Binding(name = "id", value = "${instance.nextId}"),
7274
rel = "next"
7375
),
7476
@InjectLink(
7577
resource = ItemResource.class,
7678
style = Style.ABSOLUTE,
77-
condition = "${resource.prev}",
78-
bindings = @Binding(name = "id", value = "${resource.prevId}"),
79+
condition = "${instance.prev}",
80+
bindings = @Binding(name = "id", value = "${instance.prevId}"),
7981
rel = "prev"
8082
)
8183
})
@@ -84,10 +86,16 @@ public class ItemRepresentation {
8486
@XmlElement
8587
private String name;
8688

89+
@XmlTransient
90+
private String id;
91+
@XmlTransient
92+
private ItemsModel itemsModel;
93+
94+
8795
@InjectLink(
8896
resource = ItemResource.class,
8997
style = Style.ABSOLUTE,
90-
bindings = @Binding(name = "id", value = "${resource.id}"),
98+
bindings = @Binding(name = "id", value = "${instance.id}"),
9199
rel = "self"
92100
)
93101
@XmlJavaTypeAdapter(Link.JaxbAdapter.class)
@@ -98,28 +106,56 @@ public class ItemRepresentation {
98106
@InjectLink(
99107
resource = ItemResource.class,
100108
style = Style.ABSOLUTE,
101-
condition = "${resource.next}",
102-
bindings = @Binding(name = "id", value = "${resource.nextId}"),
109+
condition = "${instance.next}",
110+
bindings = @Binding(name = "id", value = "${instance.nextId}"),
103111
rel = "next"
104112
),
105113
@InjectLink(
106114
resource = ItemResource.class,
107115
style = Style.ABSOLUTE,
108-
condition = "${resource.prev}",
109-
bindings = @Binding(name = "id", value = "${resource.prevId}"),
116+
condition = "${instance.prev}",
117+
bindings = @Binding(name = "id", value = "${instance.prevId}"),
110118
rel = "prev"
111119
)})
112120
@XmlElement(name="link")
113121
@XmlElementWrapper(name = "links")
114122
@XmlJavaTypeAdapter(Link.JaxbAdapter.class)
115123
List<Link> links;
124+
116125

117-
public ItemRepresentation() {
118-
this.name = "";
126+
public ItemRepresentation()
127+
{
128+
119129
}
120-
121-
public ItemRepresentation(String name) {
130+
131+
public ItemRepresentation(ItemsModel itemsModel, String id, String name) {
132+
this.itemsModel = itemsModel;
122133
this.name = name;
134+
this.id = id;
135+
}
136+
137+
138+
139+
public String getId() {
140+
return id;
141+
}
142+
143+
144+
public boolean isNext() {
145+
return itemsModel.hasNext(id);
146+
}
147+
148+
public boolean isPrev() {
149+
return itemsModel.hasPrev(id);
150+
}
151+
152+
public String getNextId() {
153+
return itemsModel.getNextId(id);
154+
}
155+
156+
public String getPrevId() {
157+
return itemsModel.getPrevId(id);
123158
}
159+
124160

125161
}

examples/declarative-linking/src/main/java/org/glassfish/jersey/examples/linking/representation/ItemsRepresentation.java

Lines changed: 96 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
*/
4040
package org.glassfish.jersey.examples.linking.representation;
4141

42+
import java.util.ArrayList;
4243
import org.glassfish.jersey.examples.linking.resources.ItemResource;
4344
import org.glassfish.jersey.linking.Binding;
4445
import org.glassfish.jersey.linking.InjectLinks;
@@ -52,74 +53,143 @@
5253
import javax.xml.bind.annotation.XmlElement;
5354
import javax.xml.bind.annotation.XmlElementWrapper;
5455
import javax.xml.bind.annotation.XmlRootElement;
56+
import javax.xml.bind.annotation.XmlTransient;
5557
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
58+
import org.glassfish.jersey.examples.linking.model.ItemsModel;
59+
import org.glassfish.jersey.examples.linking.resources.ItemsResource;
5660

5761
/**
58-
* JAXB representation of an item
62+
* JAXB representation of a sublist of items
5963
*
6064
*
6165
* @author Mark Hadley
6266
* @author Gerard Davison (gerard.davison at oracle.com)
6367
*/
6468
@XmlAccessorType(XmlAccessType.NONE)
65-
@XmlRootElement(name = "item")
69+
@XmlRootElement(name = "items")
6670
@InjectLinks({
6771
@InjectLink(
68-
resource = ItemResource.class,
72+
resource = ItemsResource.class,
6973
style = Style.ABSOLUTE,
70-
condition = "${resource.next}",
71-
bindings = @Binding(name = "id", value = "${resource.nextId}"),
74+
method = "query",
75+
condition = "${instance.offset + instance.limit < instance.modelLimit}",
76+
bindings = {
77+
@Binding(name = "offset", value = "${instance.offset + instance.limit}"),
78+
@Binding(name = "limit", value = "${instance.limit}")
79+
},
7280
rel = "next"
7381
),
7482
@InjectLink(
75-
resource = ItemResource.class,
83+
resource = ItemsResource.class,
7684
style = Style.ABSOLUTE,
77-
condition = "${resource.prev}",
78-
bindings = @Binding(name = "id", value = "${resource.prevId}"),
85+
method = "query",
86+
condition = "${instance.offset - instance.limit >= 0}",
87+
bindings = {
88+
@Binding(name = "offset", value = "${instance.offset - instance.limit}"),
89+
@Binding(name = "limit", value = "${instance.limit}")
90+
},
7991
rel = "prev"
80-
)
81-
})
82-
public class ItemRepresentation {
92+
)})
93+
94+
public class ItemsRepresentation {
8395

84-
@XmlElement
85-
private String name;
8696

97+
@XmlElement(name="items")
98+
private List<ItemRepresentation> items;
99+
100+
@XmlTransient
101+
private int offset, limit;
102+
103+
@XmlTransient
104+
private ItemsModel itemsModel;
105+
106+
107+
108+
109+
87110
@InjectLink(
88-
resource = ItemResource.class,
111+
resource = ItemsResource.class,
112+
method = "query",
89113
style = Style.ABSOLUTE,
90-
bindings = @Binding(name = "id", value = "${resource.id}"),
114+
bindings = {@Binding(name = "offset", value="${instance.offset}"),
115+
@Binding(name = "limit", value="${instance.limit}")
116+
},
91117
rel = "self"
92118
)
93119
@XmlJavaTypeAdapter(Link.JaxbAdapter.class)
94120
@XmlElement(name="link")
95121
Link self;
96122

123+
124+
97125
@InjectLinks({
98126
@InjectLink(
99-
resource = ItemResource.class,
127+
resource = ItemsResource.class,
100128
style = Style.ABSOLUTE,
101-
condition = "${resource.next}",
102-
bindings = @Binding(name = "id", value = "${resource.nextId}"),
129+
method = "query",
130+
condition = "${instance.offset + instance.limit < instance.modelLimit}",
131+
bindings = {
132+
@Binding(name = "offset", value = "${instance.offset + instance.limit}"),
133+
@Binding(name = "limit", value = "${instance.limit}")
134+
},
103135
rel = "next"
104136
),
105137
@InjectLink(
106-
resource = ItemResource.class,
138+
resource = ItemsResource.class,
107139
style = Style.ABSOLUTE,
108-
condition = "${resource.prev}",
109-
bindings = @Binding(name = "id", value = "${resource.prevId}"),
140+
method = "query",
141+
condition = "${instance.offset - instance.limit >= 0}",
142+
bindings = {
143+
@Binding(name = "offset", value = "${instance.offset - instance.limit}"),
144+
@Binding(name = "limit", value = "${instance.limit}")
145+
},
110146
rel = "prev"
111147
)})
112148
@XmlElement(name="link")
113149
@XmlElementWrapper(name = "links")
114150
@XmlJavaTypeAdapter(Link.JaxbAdapter.class)
115151
List<Link> links;
116152

117-
public ItemRepresentation() {
118-
this.name = "";
119-
}
120153

121-
public ItemRepresentation(String name) {
122-
this.name = name;
154+
155+
156+
157+
public ItemsRepresentation() {
158+
offset = 0;
159+
limit = 10;
160+
}
161+
162+
public ItemsRepresentation(ItemsModel itemsModel, int offset, int limit) {
163+
164+
this.offset = offset;
165+
this.limit = limit;
166+
this.itemsModel = itemsModel;
167+
168+
items = new ArrayList<ItemRepresentation>();
169+
for (int i = offset; i < (offset + limit) && i < itemsModel.getSize(); i++)
170+
{
171+
items.add(new ItemRepresentation(
172+
itemsModel,
173+
Integer.toString(i),
174+
itemsModel.getItem(Integer.toString(i)).getName()));
175+
}
176+
123177
}
124178

179+
180+
181+
public int getOffset()
182+
{
183+
return offset;
184+
}
185+
186+
public int getLimit()
187+
{
188+
return limit;
189+
}
190+
191+
public int getModelLimit()
192+
{
193+
return itemsModel.getSize();
194+
}
125195
}

0 commit comments

Comments
 (0)