/** * Registers the given {@link JavaType}s as triggering metadata * registration. * * @param triggerTypes the type-level annotations to detect that will cause * metadata creation * @since 1.2.0 */ public void addMetadataTriggers(final JavaType... triggerTypes) { for (final JavaType triggerType : triggerTypes) { addMetadataTrigger(triggerType); } }
Validate.isTrue(isNotificationForJavaType(upstreamDependency), "Expected class-level notifications only for physical Java types (not '" + upstreamDependency + "') for metadata provider " + getClass().getName()); return createLocalIdentifier(javaType, path);
.equals(MetadataIdentificationUtils.getMetadataClass(getProvidesType())), "Unexpected request for '%s' to this provider (which uses '%s')", metadataIdentificationString, getProvidesType()); getMetadataDependencyRegistry().deregisterDependencies(metadataIdentificationString); getGovernorPhysicalTypeIdentifier(metadataIdentificationString); (PhysicalTypeMetadata) getMetadataService().get(governorPhysicalTypeIdentifier); if (governorPhysicalTypeMetadata == null || !governorPhysicalTypeMetadata.isValid()) { if (!produceMetadata && isGovernor(cid) && getFileManager().exists(itdFilename)) { deleteItd(metadataIdentificationString, itdFilename, "not required for governor " + cid.getName(), true); return null; getMetadata(metadataIdentificationString, aspectName, governorPhysicalTypeMetadata, itdFilename); deleteItd(metadataIdentificationString, itdFilename, "", false); return null; getItdDiscoveryService().addItdTypeDetails(itdTypeDetails); final String itd = itdSourceFileComposer.getOutput(); getFileManager().createOrUpdateTextFileIfRequired(itdFilename, itd, false); } else { deleteItd(metadataIdentificationString, itdFilename, null, false);
/** * Returns details of the given Java type's members * * @param type the type for which to get the members (required) * @return <code>null</code> if the member details are unavailable */ protected MemberDetails getMemberDetails(final JavaType type) { TypeLocationService typeLocationService = getTypeLocationService(); Validate.notNull(typeLocationService, "TypeLocationService is required"); final String physicalTypeIdentifier = typeLocationService.getPhysicalTypeIdentifier(type); if (physicalTypeIdentifier == null) { return null; } // We need to lookup the metadata we depend on final PhysicalTypeMetadata physicalTypeMetadata = (PhysicalTypeMetadata) getMetadataService().get(physicalTypeIdentifier); return getMemberDetails(physicalTypeMetadata); }
/** * Deletes the given ITD, either now or later. * * @param metadataIdentificationString the ITD's metadata ID * @param itdFilename the ITD's filename * @param reason the reason for deletion; ignored if now is * <code>false</code> * @param now whether to delete the ITD immediately; <code>false</code> * schedules it for later deletion; this is preferable when it's * possible that the ITD might need to be re-created in the * meantime (e.g. because some ancestor metadata has changed to * that effect), otherwise there will be spurious console * messages about the ITD being deleted and created */ private void deleteItd(final String metadataIdentificationString, final String itdFilename, final String reason, final boolean now) { if (now) { getFileManager().delete(itdFilename, reason); } else { getFileManager().createOrUpdateTextFileIfRequired(itdFilename, "", false); } getItdDiscoveryService().removeItdTypeDetails(metadataIdentificationString); // TODO do we need to notify downstream dependencies that this ITD has // gone away? }
/** * Looks up the given type's inheritance hierarchy for metadata of the given * type, starting with the given type's parent and going upwards until the * first such instance is found (i.e. lower level metadata takes priority * over higher level metadata) * * @param <T> the type of metadata to look for * @param child the child type whose parents to search (required) * @return <code>null</code> if there is no such metadata */ @SuppressWarnings("unchecked") protected <T extends MetadataItem> T getParentMetadata(final ClassOrInterfaceTypeDetails child) { T parentMetadata = null; ClassOrInterfaceTypeDetails superCid = child.getSuperclass(); while (parentMetadata == null && superCid != null) { final String superCidPhysicalTypeIdentifier = superCid.getDeclaredByMetadataId(); final LogicalPath path = PhysicalTypeIdentifier.getPath(superCidPhysicalTypeIdentifier); final String superCidLocalIdentifier = createLocalIdentifier(superCid.getName(), path); parentMetadata = (T) getMetadataService().get(superCidLocalIdentifier); superCid = superCid.getSuperclass(); } return parentMetadata; // Could be null }
public final String getIdForPhysicalJavaType(final String physicalJavaTypeIdentifier) { Validate.isTrue( MetadataIdentificationUtils.getMetadataClass(physicalJavaTypeIdentifier).equals( MetadataIdentificationUtils.getMetadataClass(PhysicalTypeIdentifier .getMetadataIdentiferType())), "Expected a valid physical Java type instance identifier (not '%s')", physicalJavaTypeIdentifier); final JavaType javaType = PhysicalTypeIdentifier.getJavaType(physicalJavaTypeIdentifier); final LogicalPath path = PhysicalTypeIdentifier.getPath(physicalJavaTypeIdentifier); return createLocalIdentifier(javaType, path); }
/** * Returns details of the given class or interface type's members * * @param cid the physical type for which to get the members (can be * <code>null</code>) * @return <code>null</code> if the member details are unavailable */ protected MemberDetails getMemberDetails(final ClassOrInterfaceTypeDetails cid) { MemberDetailsScanner memberDetailsScanner = getMemberDetailsScanner(); Validate.notNull(memberDetailsScanner, "MemberDetailsScanner is required"); if (cid == null) { return null; } return memberDetailsScanner.getMemberDetails(getClass().getName(), cid); }
/** * This service is being activated so setup it: * <ul> * <li>Create and open the {@link MetadataDependencyRegistryTracker}</li> * <li>Registers {@link RooJavaType#ROO_JAVA_BEAN} as additional JavaType * that will trigger metadata registration.</li> * </ul> */ @Override protected void activate(final ComponentContext cContext) { super.activate(cContext); BundleContext localContext = cContext.getBundleContext(); this.registryTracker = new MetadataDependencyRegistryTracker(localContext, this, PhysicalTypeIdentifier.getMetadataIdentiferType(), getProvidesType()); this.registryTracker.open(); addMetadataTrigger(ROO_JAVA_BEAN); }
/** * Returns details of the given Java type's members * * @param type the type for which to get the members (required) * @return <code>null</code> if the member details are unavailable */ protected MemberDetails getMemberDetails(final JavaType type) { TypeLocationService typeLocationService = getTypeLocationService(); Validate.notNull(typeLocationService, "TypeLocationService is required"); final String physicalTypeIdentifier = typeLocationService.getPhysicalTypeIdentifier(type); if (physicalTypeIdentifier == null) { return null; } // We need to lookup the metadata we depend on final PhysicalTypeMetadata physicalTypeMetadata = (PhysicalTypeMetadata) getMetadataService().get(physicalTypeIdentifier); return getMemberDetails(physicalTypeMetadata); }
/** * Deletes the given ITD, either now or later. * * @param metadataIdentificationString the ITD's metadata ID * @param itdFilename the ITD's filename * @param reason the reason for deletion; ignored if now is * <code>false</code> * @param now whether to delete the ITD immediately; <code>false</code> * schedules it for later deletion; this is preferable when it's * possible that the ITD might need to be re-created in the * meantime (e.g. because some ancestor metadata has changed to * that effect), otherwise there will be spurious console * messages about the ITD being deleted and created */ private void deleteItd(final String metadataIdentificationString, final String itdFilename, final String reason, final boolean now) { if (now) { getFileManager().delete(itdFilename, reason); } else { getFileManager().createOrUpdateTextFileIfRequired(itdFilename, "", false); } getItdDiscoveryService().removeItdTypeDetails(metadataIdentificationString); // TODO do we need to notify downstream dependencies that this ITD has // gone away? }
/** * Looks up the given type's inheritance hierarchy for metadata of the given * type, starting with the given type's parent and going upwards until the * first such instance is found (i.e. lower level metadata takes priority * over higher level metadata) * * @param <T> the type of metadata to look for * @param child the child type whose parents to search (required) * @return <code>null</code> if there is no such metadata */ @SuppressWarnings("unchecked") protected <T extends MetadataItem> T getParentMetadata(final ClassOrInterfaceTypeDetails child) { T parentMetadata = null; ClassOrInterfaceTypeDetails superCid = child.getSuperclass(); while (parentMetadata == null && superCid != null) { final String superCidPhysicalTypeIdentifier = superCid.getDeclaredByMetadataId(); final LogicalPath path = PhysicalTypeIdentifier.getPath(superCidPhysicalTypeIdentifier); final String superCidLocalIdentifier = createLocalIdentifier(superCid.getName(), path); parentMetadata = (T) getMetadataService().get(superCidLocalIdentifier); superCid = superCid.getSuperclass(); } return parentMetadata; // Could be null }
/** * Called whenever there is a requirement to produce a local identifier (ie * an instance identifier consistent with {@link #getProvidesType()}) for * the indicated {@link ClassOrInterfaceTypeDetails}. * @param details * @return */ protected String createLocalIdentifier(ClassOrInterfaceTypeDetails details) { final LogicalPath logicalPath = PhysicalTypeIdentifier.getPath(details.getDeclaredByMetadataId()); return createLocalIdentifier(details.getType(), logicalPath); }
/** * Returns details of the given physical type's members * * @param physicalTypeMetadata the physical type for which to get the * members (can be <code>null</code>) * @return <code>null</code> if the member details are unavailable */ protected MemberDetails getMemberDetails(final PhysicalTypeMetadata physicalTypeMetadata) { MemberDetailsScanner memberDetailsScanner = getMemberDetailsScanner(); Validate.notNull(memberDetailsScanner, "MemberDetailsScanner is required"); // We need to abort if we couldn't find dependent metadata if (physicalTypeMetadata == null || !physicalTypeMetadata.isValid()) { return null; } final ClassOrInterfaceTypeDetails cid = physicalTypeMetadata.getMemberHoldingTypeDetails(); if (cid == null) { // Abort if the type's class details aren't available (parse error // etc) return null; } return memberDetailsScanner.getMemberDetails(getClass().getName(), cid); }
/** * This service is being activated so setup it: * <ul> * <li>Create and open the {@link MetadataDependencyRegistryTracker}</li> * <li>Registers {@link RooJavaType#ROO_JAVA_BEAN} as additional JavaType * that will trigger metadata registration.</li> * </ul> */ @Override protected void activate(final ComponentContext cContext) { super.activate(cContext); BundleContext localContext = cContext.getBundleContext(); this.registryTracker = new MetadataDependencyRegistryTracker(localContext, this, PhysicalTypeIdentifier.getMetadataIdentiferType(), getProvidesType()); this.registryTracker.open(); addMetadataTrigger(ROO_JAVA_BEAN); }
.equals(MetadataIdentificationUtils.getMetadataClass(getProvidesType())), "Unexpected request for '%s' to this provider (which uses '%s')", metadataIdentificationString, getProvidesType()); getMetadataDependencyRegistry().deregisterDependencies(metadataIdentificationString); getGovernorPhysicalTypeIdentifier(metadataIdentificationString); (PhysicalTypeMetadata) getMetadataService().get(governorPhysicalTypeIdentifier); if (governorPhysicalTypeMetadata == null || !governorPhysicalTypeMetadata.isValid()) { if (!produceMetadata && isGovernor(cid) && getFileManager().exists(itdFilename)) { deleteItd(metadataIdentificationString, itdFilename, "not required for governor " + cid.getName(), true); return null; getMetadata(metadataIdentificationString, aspectName, governorPhysicalTypeMetadata, itdFilename); deleteItd(metadataIdentificationString, itdFilename, "", false); return null; getItdDiscoveryService().addItdTypeDetails(itdTypeDetails); final String itd = itdSourceFileComposer.getOutput(); getFileManager().createOrUpdateTextFileIfRequired(itdFilename, itd, false); } else { deleteItd(metadataIdentificationString, itdFilename, null, false);
Validate.isTrue(isNotificationForJavaType(upstreamDependency), "Expected class-level notifications only for physical Java types (not '" + upstreamDependency + "') for metadata provider " + getClass().getName()); return createLocalIdentifier(javaType, path);
/** * Assists creating a local metadata identification string (MID) from any * presented {@link MemberHoldingTypeDetails} implementation. This is * achieved by extracting the * {@link IdentifiableJavaStructure#getDeclaredByMetadataId()} and * converting it into a {@link JavaType} and {@link Path}, then calling * {@link #createLocalIdentifier(JavaType, Path)}. * * @param memberHoldingTypeDetails the member holder from which the * declaring type information should be extracted (required) * @return a MID produced by {@link #createLocalIdentifier(JavaType, Path)} * for the extracted Java type in the extract Path (never null) */ protected String getLocalMid(final MemberHoldingTypeDetails memberHoldingTypeDetails) { final JavaType governorType = memberHoldingTypeDetails.getName(); // Extract out the metadata provider class (we need this later to // extract just the Path it is located in) final String providesType = MetadataIdentificationUtils.getMetadataClass(memberHoldingTypeDetails .getDeclaredByMetadataId()); final LogicalPath path = PhysicalTypeIdentifierNamingUtils.getPath(providesType, memberHoldingTypeDetails.getDeclaredByMetadataId()); // Produce the local MID we're going to use to make the request return createLocalIdentifier(governorType, path); }
/** * Returns details of the given class or interface type's members * * @param cid the physical type for which to get the members (can be * <code>null</code>) * @return <code>null</code> if the member details are unavailable */ protected MemberDetails getMemberDetails(final ClassOrInterfaceTypeDetails cid) { MemberDetailsScanner memberDetailsScanner = getMemberDetailsScanner(); Validate.notNull(memberDetailsScanner, "MemberDetailsScanner is required"); if (cid == null) { return null; } return memberDetailsScanner.getMemberDetails(getClass().getName(), cid); }
/** * Registers the given {@link JavaType}s as triggering metadata * registration. * * @param triggerTypes the type-level annotations to detect that will cause * metadata creation * @since 1.2.0 */ public void addMetadataTriggers(final JavaType... triggerTypes) { for (final JavaType triggerType : triggerTypes) { addMetadataTrigger(triggerType); } }