/** * Static factory method to allow the standard code of * {@code Schema.builder()} to return something useful. */ public static MetadataRegistry builder() { return new MetadataRegistry(); }
/** * Registers the metadata for this element. */ public static void registerMetadata(MetadataRegistry registry) { if (registry.isRegistered(KEY)) { return; } // The builder for this element ElementCreator builder = registry.build(KEY); }
/** * Creates a {@link Schema} out of this registry. Will return a cached * instance if the registry has not changed since last time create() was * called. */ public Schema createSchema() { Schema instance = cachedSchema; return (instance != null) ? instance : buildSchema(); }
/** * Registers the metadata for this element. */ public static void registerMetadata(MetadataRegistry registry) { if (registry.isRegistered(KEY)) { return; } Content.registerMetadata(registry); ElementCreator builder = registry.build(KEY); builder.addElement(Feed.KEY); builder.addElement(Entry.KEY); registry.adapt(Content.KEY, KIND, KEY); }
/** * Set the metadata to visible or hidden. */ public MetadataCreatorImpl setVirtualValue(VirtualValue virtualValue) { synchronized (registry) { this.virtualValue = virtualValue; registry.dirty(); } return this; }
/** * Builds metadata for when the {@code key} is inside the {@code parent} and * used in a context compatible with {@code context}. Note that this will not * declare the element as part of the parent element, that must be done using * {@link ElementCreator#addElement(ElementKey)} or * {@link ElementCreator#replaceElement(ElementKey)}. * * <p>This will also guarantee that any element types that are referenced * have been registered in this registry. */ public ElementCreator build(ElementKey<?, ?> parent, ElementKey<?, ?> element, MetadataContext context) { ElementCreatorImpl creator = getOrCreateElement(element).build( parent, element, context); // If there is a parent or context this isn't a basic registration, so force // basic registration to take place. if (parent != null || context != null) { register(element); } return creator; }
/** * Builds metadata for when the {@code key} is inside the {@code parent}. * Note that this will not declare the element as part of the parent element, * that must be done using {@link ElementCreator#addElement(ElementKey)} or * {@link ElementCreator#replaceElement(ElementKey)}. */ public ElementCreator build(ElementKey<?, ?> parent, ElementKey<?, ?> element) { return build(parent, element, null); }
/** * Builds the metadata for the attribute inside the parent, during the * context. Note that this will not declare the attribute as part of the * parent element, that must be done using * {@link ElementCreator#addAttribute(AttributeKey)} or * {@link ElementCreator#replaceAttribute(AttributeKey)}. */ public AttributeCreator build(ElementKey<?, ?> parent, AttributeKey<?> attribute, MetadataContext context) { return getOrCreateAttribute(attribute).build(parent, attribute, context); }
/** * Returns the {@link Schema} that contains the metadata about * element types parsed or generated by this service. */ public Schema getSchema() { return metadataRegistry.createSchema(); }
/** * Creates the immutable map of attribute key -> attribute registry. Once * this is created there is no more modifying attribute metadata, its all set. */ private static ImmutableMap<RootKey, AttributeMetadataRegistry> buildAttributes(MetadataRegistry registry, Schema schema) { Builder<RootKey, AttributeMetadataRegistry> attributeBuilder = ImmutableMap.builder(); for (Map.Entry<RootKey, AttributeMetadataRegistryBuilder> entry : registry.getAttributes().entrySet()) { attributeBuilder.put(entry.getKey(), entry.getValue().create(schema)); } return attributeBuilder.build(); }
/** * Creates the immutable map of element key -> element registry. Once this * is created there is no more modifying element metadata, its all set. */ private static ImmutableMap<RootKey, ElementMetadataRegistry> buildElements(MetadataRegistry registry, Schema schema) { Builder<RootKey, ElementMetadataRegistry> elementBuilder = ImmutableMap.builder(); for (Map.Entry<RootKey, ElementMetadataRegistryBuilder> entry : registry.getElements().entrySet()) { elementBuilder.put(entry.getKey(), entry.getValue().create(schema)); } return elementBuilder.build(); }
/** * Registers the metadata for this element. */ public static void registerMetadata(MetadataRegistry registry) { if (registry.isRegistered(KEY)) { return; } Content.registerMetadata(registry); ElementCreator builder = registry.build(KEY); builder.addElement(Feed.KEY); builder.addElement(Entry.KEY); registry.adapt(Content.KEY, KIND, KEY); }
/** * Set the name of the metadata. */ public MetadataCreatorImpl setName(QName name) { synchronized (registry) { this.name = name; registry.dirty(); } return this; }
/** * Builds metadata for when the {@code key} is inside the {@code parent} and * used in a context compatible with {@code context}. Note that this will not * declare the element as part of the parent element, that must be done using * {@link ElementCreator#addElement(ElementKey)} or * {@link ElementCreator#replaceElement(ElementKey)}. * * <p>This will also guarantee that any element types that are referenced * have been registered in this registry. */ public ElementCreator build(ElementKey<?, ?> parent, ElementKey<?, ?> element, MetadataContext context) { ElementCreatorImpl creator = getOrCreateElement(element).build( parent, element, context); // If there is a parent or context this isn't a basic registration, so force // basic registration to take place. if (parent != null || context != null) { register(element); } return creator; }
/** * Adapts from the source type to the adaptation type on the given kind. */ public <D, E extends Element> void adapt(ElementKey<D, E> source, String kind, ElementKey<? extends D, ? extends E> adaptation) { build(source).adapt(kind, adaptation); }
/** * Builds the metadata for the attribute inside the parent, during the * context. Note that this will not declare the attribute as part of the * parent element, that must be done using * {@link ElementCreator#addAttribute(AttributeKey)} or * {@link ElementCreator#replaceAttribute(AttributeKey)}. */ public AttributeCreator build(ElementKey<?, ?> parent, AttributeKey<?> attribute, MetadataContext context) { return getOrCreateAttribute(attribute).build(parent, attribute, context); }
/** * Returns the {@link Schema} that contains the metadata about * element types parsed or generated by this service. */ public Schema getSchema() { return metadataRegistry.createSchema(); }
/** * Creates the immutable map of attribute key -> attribute registry. Once * this is created there is no more modifying attribute metadata, its all set. */ private static ImmutableMap<RootKey, AttributeMetadataRegistry> buildAttributes(MetadataRegistry registry, Schema schema) { Builder<RootKey, AttributeMetadataRegistry> attributeBuilder = ImmutableMap.builder(); for (Map.Entry<RootKey, AttributeMetadataRegistryBuilder> entry : registry.getAttributes().entrySet()) { attributeBuilder.put(entry.getKey(), entry.getValue().create(schema)); } return attributeBuilder.build(); }