Skip to content

Commit

Permalink
Support for PolyString translation
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Mar 1, 2019
1 parent 5376424 commit 8cf60b7
Show file tree
Hide file tree
Showing 23 changed files with 598 additions and 38 deletions.
Expand Up @@ -25,6 +25,8 @@
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.util.ShortDumpable;
import com.evolveum.midpoint.util.annotation.Experimental;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringTranslationType;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;

import java.io.Serializable;
Expand All @@ -50,9 +52,11 @@ public class PolyString implements Matchable<PolyString>, Recomputable, Structur

public static final ItemName F_ORIG = new ItemName(PrismConstants.NS_TYPES, "orig");
public static final ItemName F_NORM = new ItemName(PrismConstants.NS_TYPES, "norm");
public static final ItemName F_TRANSLATION = new ItemName(PrismConstants.NS_TYPES, "translation");

private final String orig;
private String norm = null;
private PolyStringTranslationType translation;

public PolyString(String orig) {
super();
Expand All @@ -70,6 +74,11 @@ public PolyString(String orig, String norm) {
this.orig = orig;
this.norm = norm;
}

public PolyString(String orig, String norm, PolyStringTranslationType translation) {
this(orig, norm);
this.translation = translation;
}

public String getOrig() {
return orig;
Expand All @@ -79,6 +88,19 @@ public String getNorm() {
return norm;
}

public PolyStringTranslationType getTranslation() {
return translation;
}

/**
* Do NOT rely on this method too much. It may disappear later, e.g. when we align PolyString and PolyString type and
* make PolyString really immutable.
*/
@Experimental
public void setTranslation(PolyStringTranslationType translation) {
this.translation = translation;
}

public boolean isEmpty() {
if (orig == null) {
return true;
Expand Down Expand Up @@ -111,6 +133,8 @@ public Object resolve(ItemPath subpath) {
return orig;
} else if (QNameUtil.match(F_NORM, itemName)) {
return norm;
} else if (QNameUtil.match(F_TRANSLATION, itemName)) {
return translation;
} else {
throw new IllegalArgumentException("Unknown path segment "+itemName);
}
Expand Down Expand Up @@ -184,6 +208,7 @@ public int hashCode() {
int result = 1;
result = prime * result + ((norm == null) ? 0 : norm.hashCode());
result = prime * result + ((orig == null) ? 0 : orig.hashCode());
result = prime * result + ((translation == null) ? 0 : translation.hashCode());
return result;
}

Expand All @@ -206,6 +231,11 @@ public boolean equals(Object obj) {
return false;
} else if (!orig.equals(other.orig))
return false;
if (translation == null) {
if (other.translation != null)
return false;
} else if (!translation.equals(other.translation))
return false;
return true;
}

Expand Down Expand Up @@ -241,6 +271,10 @@ public String debugDump(int indent) {
sb.append(",");
sb.append(norm);
}
if (translation != null) {
sb.append(";translation=");
sb.append(translation.getKey());
}
sb.append(")");
return sb.toString();
}
Expand Down Expand Up @@ -278,6 +312,15 @@ public boolean matches(String regex) {
return Pattern.matches(regex, norm) || Pattern.matches(regex, orig);
}

/**
* Returns true if the PolyString form contains only simple string.
* I.e. returns true if the polystring can be serialized in a simplified form of a single string.
* Returns true in case that there are language mutations, translation, etc.
*/
public boolean isSimple() {
return translation == null;
}

@Override
public void checkConsistence() {
if (orig == null) {
Expand All @@ -299,4 +342,5 @@ public static PolyStringType toPolyStringType(PolyString value) {
public static PolyString fromOrig(String orig) {
return new PolyString(orig);
}

}
@@ -0,0 +1,115 @@
/*
* Copyright (c) 2019 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2014.02.04 at 01:34:24 PM CET
//


package com.evolveum.prism.xml.ns._public.types_3;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
import javax.xml.namespace.QName;


/**
* WARNING: this is NOT a generated code.
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "PolyStringTranslationArgumentType", propOrder = {
"value",
"translation"
})
public class PolyStringTranslationArgumentType implements Serializable, Cloneable {
private static final long serialVersionUID = 1L;

public static final QName COMPLEX_TYPE = new QName("http://prism.evolveum.com/xml/ns/public/types-3", "PolyStringTranslationArgumentType");

protected String value;
protected PolyStringTranslationType translation;

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}

public PolyStringTranslationType getTranslation() {
return translation;
}

public void setTranslation(PolyStringTranslationType translation) {
this.translation = translation;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((translation == null) ? 0 : translation.hashCode());
result = prime * result + ((value == null) ? 0 : value.hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
PolyStringTranslationArgumentType other = (PolyStringTranslationArgumentType) obj;
if (translation == null) {
if (other.translation != null)
return false;
} else if (!translation.equals(other.translation))
return false;
if (value == null) {
if (other.value != null)
return false;
} else if (!value.equals(other.value))
return false;
return true;
}

@Override
public String toString() {
return "PolyStringTranslationArgumentType(value=" + value + ", translation=" + translation + ")";
}

@Override
public PolyStringTranslationArgumentType clone() {
PolyStringTranslationArgumentType cloned = new PolyStringTranslationArgumentType();
cloned.setValue(value);
if (translation != null) {
cloned.setTranslation(translation.clone());
}
return cloned;
}
}
@@ -0,0 +1,129 @@
/*
* Copyright (c) 2019 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2014.02.04 at 01:34:24 PM CET
//


package com.evolveum.prism.xml.ns._public.types_3;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
import javax.xml.namespace.QName;


/**
* WARNING: this is NOT a generated code.
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "PolyStringTranslationType", propOrder = {
"key",
"fallback",
"argument"
})
public class PolyStringTranslationType implements Serializable, Cloneable {
private static final long serialVersionUID = 1L;

public static final QName COMPLEX_TYPE = new QName("http://prism.evolveum.com/xml/ns/public/types-3", "PolyStringTranslationType");

@XmlElement(required = true)
protected String key;
protected String fallback;
protected final List<PolyStringTranslationArgumentType> argument = new ArrayList<>();

public String getKey() {
return key;
}

public void setKey(String key) {
this.key = key;
}

public String getFallback() {
return fallback;
}

public void setFallback(String fallback) {
this.fallback = fallback;
}

public List<PolyStringTranslationArgumentType> getArgument() {
return argument;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((argument == null) ? 0 : argument.hashCode());
result = prime * result + ((fallback == null) ? 0 : fallback.hashCode());
result = prime * result + ((key == null) ? 0 : key.hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
PolyStringTranslationType other = (PolyStringTranslationType) obj;
if (argument == null) {
if (other.argument != null)
return false;
} else if (!argument.equals(other.argument))
return false;
if (fallback == null) {
if (other.fallback != null)
return false;
} else if (!fallback.equals(other.fallback))
return false;
if (key == null) {
if (other.key != null)
return false;
} else if (!key.equals(other.key))
return false;
return true;
}

@Override
public String toString() {
return "PolyStringTranslationType(key=" + key + ", fallback=" + fallback + ", argument=" + argument + ")";
}

@Override
public PolyStringTranslationType clone() {
PolyStringTranslationType cloned = new PolyStringTranslationType();
cloned.setKey(getKey());
cloned.setFallback(getFallback());
for (PolyStringTranslationArgumentType argument : getArgument()) {
cloned.getArgument().add(argument.clone());
}
return cloned;
}
}

0 comments on commit 8cf60b7

Please sign in to comment.