Skip to content

Commit

Permalink
Completed initial refactor of model classes. Still need to cleanup co…
Browse files Browse the repository at this point in the history
…ntainer classes.
  • Loading branch information
david-waltermire committed May 6, 2024
1 parent be5fbc1 commit ca65219
Show file tree
Hide file tree
Showing 37 changed files with 86 additions and 748 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,17 +209,17 @@ public Exports(@NonNull List<? extends M> importedModules) {
// as an imported one
Map<QName, FL> exportedFlagDefinitions = flags.collect(
CustomCollectors.toMap(
IFlagDefinition::getXmlQName,
IFlagDefinition::getDefinitionQName,
CustomCollectors.identity(),
AbstractModule::handleShadowedDefinitions));
Map<QName, FI> exportedFieldDefinitions = fields.collect(
CustomCollectors.toMap(
IFieldDefinition::getXmlQName,
IFieldDefinition::getDefinitionQName,
CustomCollectors.identity(),
AbstractModule::handleShadowedDefinitions));
Map<QName, A> exportedAssemblyDefinitions = assemblies.collect(
CustomCollectors.toMap(
IAssemblyDefinition::getXmlQName,
IAssemblyDefinition::getDefinitionQName,
CustomCollectors.identity(),
AbstractModule::handleShadowedDefinitions));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ public abstract class AbstractNamedInstance<
* Construct a new instance.
*
* @param parent
* the parent containing the instance.
* the parent containing the instance
* @param initializer
* used to generate the instance qualified name
*/
protected AbstractNamedInstance(@NonNull PARENT parent, @NonNull NameInitializer initializer) {
super(parent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ default boolean hasChildren() {
*
* @return the flag instance if a JSON key is configured, or {@code null}
* otherwise
* @see #hasJsonKey()
*/
// TODO: remove once moved to the instance side
// TODO: Reconsider using toFlagName in favor of getReferencedDefinitionQName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
* can be accessed using {@link #getImportedModules()}.
* <p>
* Global scoped Metaschema definitions can be accessed using
* {@link #getScopedAssemblyDefinitionByName(String)},
* {@link #getScopedFieldDefinitionByName(String)}, and
* {@link #getScopedFlagDefinitionByName(String)}. These methods take into
* {@link #getScopedAssemblyDefinitionByName(QName)},
* {@link #getScopedFieldDefinitionByName(QName)}, and
* {@link #getScopedFlagDefinitionByName(QName)}. These methods take into
* consideration the import order to provide the global definitions that are in
* scope within the given Metschema module.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ public interface INamedModelInstance extends IModelInstance, INamedInstance {
* cases, the flag will not appear in the object. This is only allowed if the
* flag is required, as determined by a {@code true} result from
* {@link IFlagInstance#isRequired()}. The {@link IFlagInstance} can be
* retrieved using {@link #getJsonKeyFlagInstance()}.
* retrieved using {@link #getEffectiveJsonKey()}.
*
* @return {@code true} if the flag's value can be used as a property name, or
* {@code false} otherwise
* @see #getJsonKeyFlagInstance()
* @see #getEffectiveJsonKey()
*/
// TODO: remove once moved to the instance side
default boolean hasJsonKey() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void testExamineAssemblyDefinitionByName() throws MetaschemaException, IOExcepti
IMetaschemaModule module = loader.load(moduleUri);

IAssemblyDefinition definition = module.getScopedAssemblyDefinitionByName(
new QName("http://csrc.nist.gov/ns/oscal/1.0", "prop"));
new QName("http://csrc.nist.gov/ns/oscal/1.0", "property"));
assertNotNull(definition, "definition not found");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ default IConstraintValidator newValidator(@NonNull IConstraintValidationHandler
*
* @param nodeItem
* the node item to validate
* @param loader
* a module loader used to load and resolve referenced resources
* @return the validation result
* @throws IllegalArgumentException
* if the provided class is not bound to a Module assembly or field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,19 @@

package gov.nist.secauto.metaschema.databind.codegen;

import gov.nist.secauto.metaschema.databind.codegen.impl.NameConverter;
import org.apache.xmlbeans.impl.common.NameUtil;

import java.util.Map;

import edu.umd.cs.findbugs.annotations.NonNull;

/**
* A variety of utility methods for normalizing Java class related names.
*/
public final class ClassUtils {
private static final Map<String, String> JAVA_NAME_MAPPER = Map.ofEntries(
Map.entry("Class", "Clazz"));

private ClassUtils() {
// disable construction
}
Expand All @@ -49,7 +54,8 @@ private ClassUtils() {
@SuppressWarnings("null")
@NonNull
public static String toPropertyName(@NonNull String name) {
return NameConverter.STANDARD.toPropertyName(name);
String property = NameUtil.upperCamelCase(name);
return JAVA_NAME_MAPPER.getOrDefault(property, property);
}

/**
Expand All @@ -63,7 +69,7 @@ public static String toPropertyName(@NonNull String name) {
@SuppressWarnings("null")
@NonNull
public static String toVariableName(@NonNull String name) {
return NameConverter.STANDARD.toVariableName(name);
return NameUtil.lowerCamelCase(name);
}

/**
Expand All @@ -77,7 +83,7 @@ public static String toVariableName(@NonNull String name) {
@SuppressWarnings("null")
@NonNull
public static String toClassName(@NonNull String name) {
return NameConverter.STANDARD.toClassName(name);
return NameUtil.upperCamelCase(name, false);
}

/**
Expand All @@ -91,7 +97,6 @@ public static String toClassName(@NonNull String name) {
@SuppressWarnings("null")
@NonNull
public static String toPackageName(@NonNull String name) {
return NameConverter.STANDARD.toPackageName(name);
return NameUtil.getPackageFromNamespace(name, false);
}

}
Loading

0 comments on commit ca65219

Please sign in to comment.