null-preserving static parsers instead of constructors
parent
9244d6413c
commit
0d25d4cb17
|
@ -8,6 +8,7 @@ import javax.persistence.Embeddable;
|
|||
import javax.persistence.Entity;
|
||||
import javax.persistence.Transient;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.nimbusds.jose.JWEAlgorithm;
|
||||
|
||||
/**
|
||||
|
@ -30,8 +31,14 @@ public class JWEAlgorithmEntity {
|
|||
this.algorithm = algorithm;
|
||||
}
|
||||
|
||||
public JWEAlgorithmEntity(String algorithmName) {
|
||||
setAlgorithmName(algorithmName);
|
||||
public static JWEAlgorithmEntity getForAlgorithmName (String algorithmName) {
|
||||
JWEAlgorithmEntity ent = new JWEAlgorithmEntity();
|
||||
ent.setAlgorithmName(algorithmName);
|
||||
if (ent.getAlgorithm() == null) {
|
||||
return null;
|
||||
} else {
|
||||
return ent;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -53,7 +60,7 @@ public class JWEAlgorithmEntity {
|
|||
* @param algorithmName
|
||||
*/
|
||||
public void setAlgorithmName(String algorithmName) {
|
||||
if (algorithmName != null) {
|
||||
if (!Strings.isNullOrEmpty(algorithmName)) {
|
||||
algorithm = JWEAlgorithm.parse(algorithmName);
|
||||
} else {
|
||||
algorithm = null;
|
||||
|
|
|
@ -7,6 +7,7 @@ import javax.persistence.Basic;
|
|||
import javax.persistence.Embeddable;
|
||||
import javax.persistence.Transient;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.nimbusds.jose.EncryptionMethod;
|
||||
import com.nimbusds.jose.JWEAlgorithm;
|
||||
|
||||
|
@ -27,8 +28,14 @@ public class JWEEncryptionMethodEntity {
|
|||
this.algorithm = algorithm;
|
||||
}
|
||||
|
||||
public JWEEncryptionMethodEntity(String algorithmName) {
|
||||
setAlgorithmName(algorithmName);
|
||||
public static JWEEncryptionMethodEntity getForAlgorithmName (String algorithmName) {
|
||||
JWEEncryptionMethodEntity ent = new JWEEncryptionMethodEntity();
|
||||
ent.setAlgorithmName(algorithmName);
|
||||
if (ent.getAlgorithm() == null) {
|
||||
return null;
|
||||
} else {
|
||||
return ent;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -46,11 +53,11 @@ public class JWEEncryptionMethodEntity {
|
|||
|
||||
/**
|
||||
* Set the name of this algorithm.
|
||||
* Calls JWEAlgorithm.parse()
|
||||
* Calls EncryptionMethod.parse()
|
||||
* @param algorithmName
|
||||
*/
|
||||
public void setAlgorithmName(String algorithmName) {
|
||||
if (algorithmName != null) {
|
||||
if (!Strings.isNullOrEmpty(algorithmName)) {
|
||||
algorithm = EncryptionMethod.parse(algorithmName);
|
||||
} else {
|
||||
algorithm = null;
|
||||
|
|
|
@ -9,6 +9,7 @@ import javax.persistence.Entity;
|
|||
import javax.persistence.Id;
|
||||
import javax.persistence.Transient;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.nimbusds.jose.JWSAlgorithm;
|
||||
|
||||
/**
|
||||
|
@ -31,8 +32,14 @@ public class JWSAlgorithmEntity {
|
|||
this.algorithm = algorithm;
|
||||
}
|
||||
|
||||
public JWSAlgorithmEntity(String algorithmName) {
|
||||
setAlgorithmName(algorithmName);
|
||||
public static JWSAlgorithmEntity getForAlgorithmName (String algorithmName) {
|
||||
JWSAlgorithmEntity ent = new JWSAlgorithmEntity();
|
||||
ent.setAlgorithmName(algorithmName);
|
||||
if (ent.getAlgorithm() == null) {
|
||||
return null;
|
||||
} else {
|
||||
return ent;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -54,7 +61,7 @@ public class JWSAlgorithmEntity {
|
|||
* @param algorithmName
|
||||
*/
|
||||
public void setAlgorithmName(String algorithmName) {
|
||||
if (algorithmName != null) {
|
||||
if (!Strings.isNullOrEmpty(algorithmName)) {
|
||||
algorithm = JWSAlgorithm.parse(algorithmName);
|
||||
} else {
|
||||
algorithm = null;
|
||||
|
|
|
@ -67,7 +67,7 @@ public class ClientAPI {
|
|||
@Override
|
||||
public JWSAlgorithmEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
if (json.isJsonPrimitive()) {
|
||||
return new JWSAlgorithmEntity(json.getAsString());
|
||||
return JWSAlgorithmEntity.getForAlgorithmName(json.getAsString());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ public class ClientAPI {
|
|||
@Override
|
||||
public JWEAlgorithmEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
if (json.isJsonPrimitive()) {
|
||||
return new JWEAlgorithmEntity(json.getAsString());
|
||||
return JWEAlgorithmEntity.getForAlgorithmName(json.getAsString());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ public class ClientAPI {
|
|||
@Override
|
||||
public JWEEncryptionMethodEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
if (json.isJsonPrimitive()) {
|
||||
return new JWEEncryptionMethodEntity(json.getAsString());
|
||||
return JWEEncryptionMethodEntity.getForAlgorithmName(json.getAsString());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -263,7 +263,7 @@ public class ClientDynamicRegistrationEndpoint {
|
|||
private JWSAlgorithmEntity getAsJwsAlgorithm(JsonObject o, String member) {
|
||||
String s = getAsString(o, member);
|
||||
if (s != null) {
|
||||
return new JWSAlgorithmEntity(s);
|
||||
return JWSAlgorithmEntity.getForAlgorithmName(s);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
@ -275,7 +275,7 @@ public class ClientDynamicRegistrationEndpoint {
|
|||
private JWEAlgorithmEntity getAsJweAlgorithm(JsonObject o, String member) {
|
||||
String s = getAsString(o, member);
|
||||
if (s != null) {
|
||||
return new JWEAlgorithmEntity(s);
|
||||
return JWEAlgorithmEntity.getForAlgorithmName(s);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
@ -288,7 +288,7 @@ public class ClientDynamicRegistrationEndpoint {
|
|||
private JWEEncryptionMethodEntity getAsJweEncryptionMethod(JsonObject o, String member) {
|
||||
String s = getAsString(o, member);
|
||||
if (s != null) {
|
||||
return new JWEEncryptionMethodEntity(s);
|
||||
return JWEEncryptionMethodEntity.getForAlgorithmName(s);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue