Skip to content

Commit

Permalink
Merge branch 'master' into feature/repo-ng
Browse files Browse the repository at this point in the history
  • Loading branch information
virgo47 committed Jun 29, 2020
2 parents 1a3e938 + 3dd3979 commit e7efae4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
@@ -1,25 +1,22 @@
/*
* Copyright (c) 2010-2019 Evolveum and contributors
* Copyright (c) 2010-2020 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
package com.evolveum.midpoint.schema.constants;

import com.evolveum.midpoint.schema.SchemaConstantsGenerated;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import java.util.ArrayList;
import java.util.List;
import javax.xml.namespace.QName;

import org.apache.commons.lang.Validate;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.ResourceBundle;
import com.evolveum.midpoint.schema.SchemaConstantsGenerated;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

/**
* @author lazyman
Expand Down Expand Up @@ -73,10 +70,10 @@ public enum ObjectTypes {
REPORT(ReportType.COMPLEX_TYPE, SchemaConstants.C_REPORT, ReportType.class, ObjectManager.MODEL, "reports"),

REPORT_OUTPUT(ReportOutputType.COMPLEX_TYPE, SchemaConstants.C_REPORT_OUTPUT, ReportOutputType.class,
ObjectManager.MODEL, "reportOutputs"),
ObjectManager.MODEL, "reportOutputs"),

SECURITY_POLICY(SecurityPolicyType.COMPLEX_TYPE, SchemaConstants.C_SECURITY_POLICY, SecurityPolicyType.class,
ObjectManager.MODEL, "securityPolicies"),
ObjectManager.MODEL, "securityPolicies"),

LOOKUP_TABLE(LookupTableType.COMPLEX_TYPE, SchemaConstantsGenerated.C_LOOKUP_TABLE, LookupTableType.class,
ObjectManager.MODEL, "lookupTables"),
Expand Down Expand Up @@ -132,6 +129,10 @@ public enum ObjectManager {
}

@NotNull private final QName type;

/**
* As of 2020-06, this is used only for ObjectTypeUtil#toShortString+getShortTypeName.
*/
@NotNull private final QName elementName;
@NotNull private final Class<? extends ObjectType> classDefinition;
@NotNull private final ObjectManager objectManager;
Expand Down Expand Up @@ -205,7 +206,7 @@ public static ObjectTypes getObjectTypeFromTypeQName(QName typeQName) {
// HACK WARNING! FIXME
// UGLY HORRIBLE TERRIBLE AWFUL HACK FOLLOWS
// The JAXB fails to correctly process QNames in default namespace (no prefix)
// e.g it will not understand this: type="RoleType", even if defatult namespace
// e.g it will not understand this: type="RoleType", even if default namespace
// is set, it will parse it as null namespace.
// Therefore substitute null namespace with common namespace
if (typeQName.getNamespaceURI() == null || typeQName.getNamespaceURI().isEmpty()) {
Expand Down Expand Up @@ -249,13 +250,13 @@ public static Class<? extends ObjectType> getObjectTypeClass(String typeNameLoca
public static <O extends ObjectType> Class<O> getObjectTypeClass(QName typeName) {
for (ObjectTypes type : values()) {
if (QNameUtil.match(type.getTypeQName(), typeName)) {
//noinspection unchecked
return (Class<O>) type.getClassDefinition();
}
}
throw new IllegalArgumentException("Unsupported object type " + typeName);
}

@SuppressWarnings("unchecked")
@NotNull
public static ObjectTypes getObjectType(@NotNull Class<? extends ObjectType> objectType) {
ObjectTypes rv = getObjectTypeIfKnown(objectType);
Expand Down Expand Up @@ -390,4 +391,3 @@ public static QName canonizeObjectType(QName inputQName) {
return new QName(SchemaConstants.NS_C, inputQName.getLocalPart());
}
}

Expand Up @@ -94,9 +94,15 @@ public static QName qualifyIfNeeded(QName name, String defaultNamespace) {
return hasNamespace(name)
? name
: new QName(defaultNamespace, name.getLocalPart());

}

public static <V> V getKey(@NotNull Map<QName, V> map, @NotNull QName key) {
/**
* Finds value in the map by QName key using {@link #match(QName, QName)}.
* Fails if multiple matches are found.
* Returns {@code null} if no match is found.
*/
public static <V> V getByQName(@NotNull Map<QName, V> map, @NotNull QName key) {
if (hasNamespace(key)) {
return map.get(key);
}
Expand Down
Expand Up @@ -152,7 +152,7 @@ public String debugDump(int indent) {
public JpaEntityDefinition findEntityDefinition(QName typeName) {
Objects.requireNonNull(typeName, "Type name must not be null.");

JpaEntityDefinition def = QNameUtil.getKey(DEFINITIONS, typeName);
JpaEntityDefinition def = QNameUtil.getByQName(DEFINITIONS, typeName);
if (def == null) {
throw new IllegalStateException("Type " + typeName + " couldn't be found in type registry");
}
Expand Down

0 comments on commit e7efae4

Please sign in to comment.