本文整理匯總了Java中org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder.setAnnotations方法的典型用法代碼示例。如果您正苦於以下問題:Java ClassOrInterfaceTypeDetailsBuilder.setAnnotations方法的具體用法?Java ClassOrInterfaceTypeDetailsBuilder.setAnnotations怎麽用?Java ClassOrInterfaceTypeDetailsBuilder.setAnnotations使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder
的用法示例。
在下文中一共展示了ClassOrInterfaceTypeDetailsBuilder.setAnnotations方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createIdentifierClass
import org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder; //導入方法依賴的package包/類
private void createIdentifierClass(final JavaType identifierType) {
final List<AnnotationMetadataBuilder> identifierAnnotations = new ArrayList<AnnotationMetadataBuilder>();
final AnnotationMetadataBuilder identifierBuilder = new AnnotationMetadataBuilder(
ROO_IDENTIFIER);
identifierBuilder.addBooleanAttribute(DB_MANAGED.getSymbolName(), true);
identifierAnnotations.add(identifierBuilder);
// Produce identifier itself
final String declaredByMetadataId = PhysicalTypeIdentifier
.createIdentifier(identifierType, projectOperations
.getPathResolver().getFocusedPath(Path.SRC_MAIN_JAVA));
final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(
declaredByMetadataId, Modifier.PUBLIC | Modifier.FINAL,
identifierType, PhysicalTypeCategory.CLASS);
cidBuilder.setAnnotations(identifierAnnotations);
typeManagementService.createOrUpdateTypeOnDisk(cidBuilder.build());
shell.flash(Level.FINE,
"Created " + identifierType.getFullyQualifiedTypeName(),
DbreDatabaseListenerImpl.class.getName());
shell.flash(Level.FINE, "", DbreDatabaseListenerImpl.class.getName());
}
示例2: newEmbeddableClass
import org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder; //導入方法依賴的package包/類
public void newEmbeddableClass(final JavaType name,
final boolean serializable) {
if(pathResolver == null){
pathResolver = getPathResolver();
}
Validate.notNull(pathResolver, "PathResolver is required");
if(typeManagementService == null){
typeManagementService = getTypeManagementService();
}
Validate.notNull(typeManagementService, "TypeManagementService is required");
Validate.notNull(name, "Embeddable name required");
final String declaredByMetadataId = PhysicalTypeIdentifier
.createIdentifier(name,
pathResolver.getFocusedPath(Path.SRC_MAIN_JAVA));
final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>(
Arrays.asList(new AnnotationMetadataBuilder(ROO_JAVA_BEAN),
new AnnotationMetadataBuilder(ROO_TO_STRING),
new AnnotationMetadataBuilder(EMBEDDABLE)));
if (serializable) {
annotations.add(new AnnotationMetadataBuilder(ROO_SERIALIZABLE));
}
final int modifier = Modifier.PUBLIC;
final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(
declaredByMetadataId, modifier, name,
PhysicalTypeCategory.CLASS);
cidBuilder.setAnnotations(annotations);
typeManagementService.createOrUpdateTypeOnDisk(cidBuilder.build());
}
示例3: newIdentifier
import org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder; //導入方法依賴的package包/類
public void newIdentifier(final JavaType identifierType,
final String identifierField, final String identifierColumn) {
if(pathResolver == null){
pathResolver = getPathResolver();
}
Validate.notNull(pathResolver, "PathResolver is required");
if(typeManagementService == null){
typeManagementService = getTypeManagementService();
}
Validate.notNull(typeManagementService, "TypeManagementService is required");
Validate.notNull(identifierType, "Identifier type required");
final String declaredByMetadataId = PhysicalTypeIdentifier
.createIdentifier(identifierType,
pathResolver.getFocusedPath(Path.SRC_MAIN_JAVA));
final List<AnnotationMetadataBuilder> identifierAnnotations = Arrays
.asList(new AnnotationMetadataBuilder(ROO_TO_STRING),
new AnnotationMetadataBuilder(ROO_EQUALS),
new AnnotationMetadataBuilder(ROO_IDENTIFIER));
final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(
declaredByMetadataId, Modifier.PUBLIC | Modifier.FINAL,
identifierType, PhysicalTypeCategory.CLASS);
cidBuilder.setAnnotations(identifierAnnotations);
typeManagementService.createOrUpdateTypeOnDisk(cidBuilder.build());
}
示例4: build
import org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder; //導入方法依賴的package包/類
public MemberHoldingTypeDetails build() {
if (existing instanceof ItdTypeDetails) {
final ItdTypeDetailsBuilder itdBuilder = new ItdTypeDetailsBuilder(
(ItdTypeDetails) existing);
// Push in all members that may have been modified
itdBuilder.setDeclaredFields(getDeclaredFields());
itdBuilder.setDeclaredMethods(getDeclaredMethods());
itdBuilder.setAnnotations(getAnnotations());
itdBuilder.setCustomData(getCustomData());
itdBuilder.setDeclaredConstructors(getDeclaredConstructors());
itdBuilder.setDeclaredInitializers(getDeclaredInitializers());
itdBuilder.setDeclaredInnerTypes(getDeclaredInnerTypes());
itdBuilder.setExtendsTypes(getExtendsTypes());
itdBuilder.setImplementsTypes(getImplementsTypes());
itdBuilder.setModifier(getModifier());
return itdBuilder.build();
}
else if (existing instanceof ClassOrInterfaceTypeDetails) {
final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(
(ClassOrInterfaceTypeDetails) existing);
// Push in all members that may
cidBuilder.setDeclaredFields(getDeclaredFields());
cidBuilder.setDeclaredMethods(getDeclaredMethods());
cidBuilder.setAnnotations(getAnnotations());
cidBuilder.setCustomData(getCustomData());
cidBuilder.setDeclaredConstructors(getDeclaredConstructors());
cidBuilder.setDeclaredInitializers(getDeclaredInitializers());
cidBuilder.setDeclaredInnerTypes(getDeclaredInnerTypes());
cidBuilder.setExtendsTypes(getExtendsTypes());
cidBuilder.setImplementsTypes(getImplementsTypes());
cidBuilder.setModifier(getModifier());
return cidBuilder.build();
}
else {
throw new IllegalStateException(
"Unknown instance of MemberHoldingTypeDetails");
}
}
示例5: newDod
import org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder; //導入方法依賴的package包/類
public void newDod(final JavaType entity, final JavaType name) {
Validate.notNull(entity,
"Entity to produce a data on demand provider for is required");
Validate.notNull(name,
"Name of the new data on demand provider is required");
final LogicalPath path = LogicalPath.getInstance(Path.SRC_TEST_JAVA,
projectOperations.getFocusedModuleName());
Validate.notNull(path,
"Location of the new data on demand provider is required");
// Verify the requested entity actually exists as a class and is not
// abstract
final ClassOrInterfaceTypeDetails cid = getEntity(entity);
Validate.isTrue(
cid.getPhysicalTypeCategory() == PhysicalTypeCategory.CLASS,
"Type %s is not a class", entity.getFullyQualifiedTypeName());
Validate.isTrue(!Modifier.isAbstract(cid.getModifier()),
"Type %s is abstract", entity.getFullyQualifiedTypeName());
// Check if the requested entity is a JPA @Entity
final MemberDetails memberDetails = memberDetailsScanner
.getMemberDetails(DataOnDemandOperationsImpl.class.getName(),
cid);
final AnnotationMetadata entityAnnotation = memberDetails
.getAnnotation(ENTITY);
final AnnotationMetadata persistentAnnotation = memberDetails
.getAnnotation(PERSISTENT);
Validate.isTrue(entityAnnotation != null
|| persistentAnnotation != null,
"Type %s must be a persistent type",
entity.getFullyQualifiedTypeName());
// Everything is OK to proceed
final String declaredByMetadataId = PhysicalTypeIdentifier
.createIdentifier(name, path);
if (metadataService.get(declaredByMetadataId) != null) {
// The file already exists
return;
}
final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
final List<AnnotationAttributeValue<?>> dodConfig = new ArrayList<AnnotationAttributeValue<?>>();
dodConfig.add(new ClassAttributeValue(new JavaSymbolName("entity"),
entity));
annotations.add(new AnnotationMetadataBuilder(
RooJavaType.ROO_DATA_ON_DEMAND, dodConfig));
final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(
declaredByMetadataId, Modifier.PUBLIC, name,
PhysicalTypeCategory.CLASS);
cidBuilder.setAnnotations(annotations);
typeManagementService.createOrUpdateTypeOnDisk(cidBuilder.build());
}
示例6: createManualController
import org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder; //導入方法依賴的package包/類
/**
* Creates a new Spring MVC controller.
* <p>
* Request mappings assigned by this method will always commence with "/"
* and end with "/**". You may present this prefix and/or this suffix if you
* wish, although it will automatically be added should it not be provided.
*
* @param controller the controller class to create (required)
* @param preferredMapping the mapping this controller should adopt
* (optional; if unspecified it will be based on the controller
* name)
*/
public void createManualController(final JavaType controller,
final String preferredMapping, final LogicalPath webappPath) {
Validate.notNull(controller, "Controller Java Type required");
// Create annotation @RequestMapping("/myobject/**")
final ImmutablePair<String, String> folderAndMapping = getFolderAndMapping(
preferredMapping, controller);
final String folderName = folderAndMapping.getKey();
final String resourceIdentifier = pathResolver.getFocusedCanonicalPath(
Path.SRC_MAIN_JAVA, controller);
final String declaredByMetadataId = PhysicalTypeIdentifier
.createIdentifier(controller, projectOperations
.getPathResolver().getPath(resourceIdentifier));
final List<MethodMetadataBuilder> methods = new ArrayList<MethodMetadataBuilder>();
// Add HTTP post method
methods.add(getHttpPostMethod(declaredByMetadataId));
// Add index method
methods.add(getIndexMethod(folderName, declaredByMetadataId));
// Create Type definition
final List<AnnotationMetadataBuilder> typeAnnotations = new ArrayList<AnnotationMetadataBuilder>();
final List<AnnotationAttributeValue<?>> requestMappingAttributes = new ArrayList<AnnotationAttributeValue<?>>();
requestMappingAttributes.add(new StringAttributeValue(
new JavaSymbolName("value"), folderAndMapping.getValue()));
final AnnotationMetadataBuilder requestMapping = new AnnotationMetadataBuilder(
REQUEST_MAPPING, requestMappingAttributes);
typeAnnotations.add(requestMapping);
// Create annotation @Controller
final List<AnnotationAttributeValue<?>> controllerAttributes = new ArrayList<AnnotationAttributeValue<?>>();
final AnnotationMetadataBuilder controllerAnnotation = new AnnotationMetadataBuilder(
CONTROLLER, controllerAttributes);
typeAnnotations.add(controllerAnnotation);
final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(
declaredByMetadataId, Modifier.PUBLIC, controller,
PhysicalTypeCategory.CLASS);
cidBuilder.setAnnotations(typeAnnotations);
cidBuilder.setDeclaredMethods(methods);
typeManagementService.createOrUpdateTypeOnDisk(cidBuilder.build());
installView(
folderName,
"/index",
new JavaSymbolName(controller.getSimpleTypeName())
.getReadableSymbolName() + " View", "Controller", null,
false, webappPath);
}
示例7: newEntity
import org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder; //導入方法依賴的package包/類
public void newEntity(final JavaType name, final boolean createAbstract,
final JavaType superclass, final JavaType implementsType,
final List<AnnotationMetadataBuilder> annotations) {
if(pathResolver == null){
pathResolver = getPathResolver();
}
Validate.notNull(pathResolver, "PathResolver is required");
if(typeLocationService == null){
typeLocationService = getTypeLocationService();
}
Validate.notNull(typeLocationService, "TypeLocationService is required");
if(typeManagementService == null){
typeManagementService = getTypeManagementService();
}
Validate.notNull(typeManagementService, "TypeManagementService is required");
Validate.notNull(name, "Entity name required");
Validate.isTrue(
!JdkJavaType.isPartOfJavaLang(name.getSimpleTypeName()),
"Entity name '%s' must not be part of java.lang",
name.getSimpleTypeName());
int modifier = Modifier.PUBLIC;
if (createAbstract) {
modifier |= Modifier.ABSTRACT;
}
final String declaredByMetadataId = PhysicalTypeIdentifier
.createIdentifier(name,
pathResolver.getFocusedPath(Path.SRC_MAIN_JAVA));
final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(
declaredByMetadataId, modifier, name,
PhysicalTypeCategory.CLASS);
if (!superclass.equals(OBJECT)) {
final ClassOrInterfaceTypeDetails superclassClassOrInterfaceTypeDetails = typeLocationService
.getTypeDetails(superclass);
if (superclassClassOrInterfaceTypeDetails != null) {
cidBuilder
.setSuperclass(new ClassOrInterfaceTypeDetailsBuilder(
superclassClassOrInterfaceTypeDetails));
}
}
cidBuilder.setExtendsTypes(Arrays.asList(superclass));
if (implementsType != null) {
final Set<JavaType> implementsTypes = new LinkedHashSet<JavaType>();
final ClassOrInterfaceTypeDetails typeDetails = typeLocationService
.getTypeDetails(declaredByMetadataId);
if (typeDetails != null) {
implementsTypes.addAll(typeDetails.getImplementsTypes());
}
implementsTypes.add(implementsType);
cidBuilder.setImplementsTypes(implementsTypes);
}
cidBuilder.setAnnotations(annotations);
typeManagementService.createOrUpdateTypeOnDisk(cidBuilder.build());
}
示例8: createNewManagedEntityFromTable
import org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder; //導入方法依賴的package包/類
/**
* Creates a new DBRE-managed entity from the given table
*
* @param javaType the name of the entity to be created (required)
* @param table the table from which to create the entity (required)
* @param activeRecord whether to create "active record" CRUD methods in the
* new entity
* @return the newly created entity
*/
private ClassOrInterfaceTypeDetails createNewManagedEntityFromTable(
final JavaType javaType, final Table table,
final boolean activeRecord) {
// Create type annotations for new entity
final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
annotations.add(new AnnotationMetadataBuilder(ROO_JAVA_BEAN));
annotations.add(new AnnotationMetadataBuilder(ROO_TO_STRING));
// Find primary key from db metadata and add identifier attributes to
// @RooJpaEntity
final AnnotationMetadataBuilder jpaAnnotationBuilder = new AnnotationMetadataBuilder(
activeRecord ? ROO_JPA_ACTIVE_RECORD : ROO_JPA_ENTITY);
manageIdentifier(javaType, jpaAnnotationBuilder,
new HashSet<JavaSymbolName>(), table);
if (!hasVersionField(table)) {
jpaAnnotationBuilder.addStringAttribute(VERSION_FIELD, "");
}
if (table.isDisableGeneratedIdentifiers()) {
jpaAnnotationBuilder.addStringAttribute(SEQUENCE_NAME_FIELD, "");
}
jpaAnnotationBuilder.addStringAttribute("table", table.getName());
if (!DbreModelService.NO_SCHEMA_REQUIRED.equals(table.getSchema()
.getName())) {
jpaAnnotationBuilder.addStringAttribute("schema", table.getSchema()
.getName());
}
annotations.add(jpaAnnotationBuilder);
// Add @RooDbManaged
annotations.add(getRooDbManagedAnnotation());
final JavaType superclass = OBJECT;
final List<JavaType> extendsTypes = new ArrayList<JavaType>();
extendsTypes.add(superclass);
// Create entity class
final String declaredByMetadataId = PhysicalTypeIdentifier
.createIdentifier(javaType, projectOperations.getPathResolver()
.getFocusedPath(Path.SRC_MAIN_JAVA));
final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(
declaredByMetadataId, Modifier.PUBLIC, javaType,
PhysicalTypeCategory.CLASS);
cidBuilder.setExtendsTypes(extendsTypes);
cidBuilder.setAnnotations(annotations);
final ClassOrInterfaceTypeDetails entity = cidBuilder.build();
typeManagementService.createOrUpdateTypeOnDisk(entity);
shell.flash(Level.FINE,
"Created " + javaType.getFullyQualifiedTypeName(),
DbreDatabaseListenerImpl.class.getName());
shell.flash(Level.FINE, "", DbreDatabaseListenerImpl.class.getName());
return entity;
}
示例9: newIntegrationTest
import org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder; //導入方法依賴的package包/類
public void newIntegrationTest(final JavaType entity,
final boolean transactional) {
Validate.notNull(entity,
"Entity to produce an integration test for is required");
// Verify the requested entity actually exists as a class and is not
// abstract
final ClassOrInterfaceTypeDetails cid = getEntity(entity);
Validate.isTrue(!Modifier.isAbstract(cid.getModifier()),
"Type %s is abstract", entity.getFullyQualifiedTypeName());
final LogicalPath path = PhysicalTypeIdentifier.getPath(cid
.getDeclaredByMetadataId());
dataOnDemandOperations.newDod(entity,
new JavaType(entity.getFullyQualifiedTypeName()
+ "DataOnDemand"));
final JavaType name = new JavaType(entity + "IntegrationTest");
final String declaredByMetadataId = PhysicalTypeIdentifier
.createIdentifier(name,
Path.SRC_TEST_JAVA.getModulePathId(path.getModule()));
if (metadataService.get(declaredByMetadataId) != null) {
// The file already exists
return;
}
final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
final List<AnnotationAttributeValue<?>> config = new ArrayList<AnnotationAttributeValue<?>>();
config.add(new ClassAttributeValue(new JavaSymbolName("entity"), entity));
if (!transactional) {
config.add(new BooleanAttributeValue(new JavaSymbolName(
"transactional"), false));
}
annotations.add(new AnnotationMetadataBuilder(ROO_INTEGRATION_TEST,
config));
final List<MethodMetadataBuilder> methods = new ArrayList<MethodMetadataBuilder>();
final List<AnnotationMetadataBuilder> methodAnnotations = new ArrayList<AnnotationMetadataBuilder>();
methodAnnotations.add(new AnnotationMetadataBuilder(TEST));
final MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(
declaredByMetadataId, Modifier.PUBLIC, new JavaSymbolName(
"testMarkerMethod"), JavaType.VOID_PRIMITIVE,
new InvocableMemberBodyBuilder());
methodBuilder.setAnnotations(methodAnnotations);
methods.add(methodBuilder);
final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(
declaredByMetadataId, Modifier.PUBLIC, name,
PhysicalTypeCategory.CLASS);
cidBuilder.setAnnotations(annotations);
cidBuilder.setDeclaredMethods(methods);
typeManagementService.createOrUpdateTypeOnDisk(cidBuilder.build());
}
示例10: newMockTest
import org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder; //導入方法依賴的package包/類
/**
* Creates a mock test for the entity. Silently returns if the mock test
* file already exists.
*
* @param entity to produce a mock test for (required)
*/
public void newMockTest(final JavaType entity) {
Validate.notNull(entity,
"Entity to produce a mock test for is required");
final JavaType name = new JavaType(entity + "Test");
final String declaredByMetadataId = PhysicalTypeIdentifier
.createIdentifier(name, Path.SRC_TEST_JAVA
.getModulePathId(projectOperations
.getFocusedModuleName()));
if (metadataService.get(declaredByMetadataId) != null) {
// The file already exists
return;
}
// Determine if the mocking infrastructure needs installing
final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
final List<AnnotationAttributeValue<?>> config = new ArrayList<AnnotationAttributeValue<?>>();
config.add(new ClassAttributeValue(new JavaSymbolName("value"), JUNIT_4));
annotations.add(new AnnotationMetadataBuilder(RUN_WITH, config));
annotations.add(new AnnotationMetadataBuilder(
MOCK_STATIC_ENTITY_METHODS));
final List<MethodMetadataBuilder> methods = new ArrayList<MethodMetadataBuilder>();
final List<AnnotationMetadataBuilder> methodAnnotations = new ArrayList<AnnotationMetadataBuilder>();
methodAnnotations.add(new AnnotationMetadataBuilder(TEST));
// Get the entity so we can hopefully make a demo method that will be
// usable
final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
final ClassOrInterfaceTypeDetails cid = typeLocationService
.getTypeDetails(entity);
if (cid != null) {
final MemberDetails memberDetails = memberDetailsScanner
.getMemberDetails(
IntegrationTestOperationsImpl.class.getName(), cid);
final List<MethodMetadata> countMethods = memberDetails
.getMethodsWithTag(CustomDataKeys.COUNT_ALL_METHOD);
if (countMethods.size() == 1) {
final String countMethod = entity.getSimpleTypeName() + "."
+ countMethods.get(0).getMethodName().getSymbolName()
+ "()";
bodyBuilder.appendFormalLine("int expectedCount = 13;");
bodyBuilder.appendFormalLine(countMethod + ";");
bodyBuilder
.appendFormalLine("org.springframework.mock.staticmock.AnnotationDrivenStaticEntityMockingControl.expectReturn(expectedCount);");
bodyBuilder
.appendFormalLine("org.springframework.mock.staticmock.AnnotationDrivenStaticEntityMockingControl.playback();");
bodyBuilder
.appendFormalLine("org.junit.Assert.assertEquals(expectedCount, "
+ countMethod + ");");
}
}
final MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(
declaredByMetadataId, Modifier.PUBLIC, new JavaSymbolName(
"testMethod"), JavaType.VOID_PRIMITIVE, bodyBuilder);
methodBuilder.setAnnotations(methodAnnotations);
methods.add(methodBuilder);
final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(
declaredByMetadataId, Modifier.PUBLIC, name,
PhysicalTypeCategory.CLASS);
cidBuilder.setAnnotations(annotations);
cidBuilder.setDeclaredMethods(methods);
typeManagementService.createOrUpdateTypeOnDisk(cidBuilder.build());
}
示例11: createClass
import org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder; //導入方法依賴的package包/類
@Override
public void createClass(final JavaType name, final boolean rooAnnotations,
final LogicalPath path, final JavaType superclass,
final JavaType implementsType, final boolean createAbstract,
final boolean permitReservedWords) {
if (!permitReservedWords) {
ReservedWords.verifyReservedWordsNotPresent(name);
}
Validate.isTrue(
!JdkJavaType.isPartOfJavaLang(name.getSimpleTypeName()),
"Class name '%s' is part of java.lang",
name.getSimpleTypeName());
int modifier = Modifier.PUBLIC;
if (createAbstract) {
modifier |= Modifier.ABSTRACT;
}
final String declaredByMetadataId = PhysicalTypeIdentifier
.createIdentifier(name, path);
final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(
declaredByMetadataId, modifier, name,
PhysicalTypeCategory.CLASS);
if (!superclass.equals(OBJECT)) {
final ClassOrInterfaceTypeDetails superclassClassOrInterfaceTypeDetails = typeLocationService
.getTypeDetails(superclass);
if (superclassClassOrInterfaceTypeDetails != null) {
cidBuilder
.setSuperclass(new ClassOrInterfaceTypeDetailsBuilder(
superclassClassOrInterfaceTypeDetails));
}
}
final List<JavaType> extendsTypes = new ArrayList<JavaType>();
extendsTypes.add(superclass);
cidBuilder.setExtendsTypes(extendsTypes);
if (implementsType != null) {
final Set<JavaType> implementsTypes = new LinkedHashSet<JavaType>();
final ClassOrInterfaceTypeDetails typeDetails = typeLocationService
.getTypeDetails(declaredByMetadataId);
if (typeDetails != null) {
implementsTypes.addAll(typeDetails.getImplementsTypes());
}
implementsTypes.add(implementsType);
cidBuilder.setImplementsTypes(implementsTypes);
}
if (rooAnnotations) {
final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
annotations.add(new AnnotationMetadataBuilder(ROO_JAVA_BEAN));
annotations.add(new AnnotationMetadataBuilder(ROO_TO_STRING));
annotations.add(new AnnotationMetadataBuilder(ROO_EQUALS));
annotations.add(new AnnotationMetadataBuilder(ROO_SERIALIZABLE));
cidBuilder.setAnnotations(annotations);
}
typeManagementService.createOrUpdateTypeOnDisk(cidBuilder.build());
}
示例12: create
import org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder; //導入方法依賴的package包/類
/** {@inheritDoc} */
@Override
public void create(JavaType entity, JavaType target,
boolean failIfAlreadySet) {
Validate.notNull(entity, "Entity required");
if (target == null) {
target = generateListenerJavaType(entity, null);
}
Validate.isTrue(
!JdkJavaType.isPartOfJavaLang(target.getSimpleTypeName()),
"Target name '%s' must not be part of java.lang",
target.getSimpleTypeName());
int modifier = Modifier.PUBLIC;
final String declaredByMetadataId = PhysicalTypeIdentifier
.createIdentifier(target,
pathResolver.getFocusedPath(Path.SRC_MAIN_JAVA));
File targetFile = new File(
typeLocationService
.getPhysicalTypeCanonicalPath(declaredByMetadataId));
if (targetFile.exists()) {
if (failIfAlreadySet) {
Validate.isTrue(!targetFile.exists(),
"Type '%s' already exists", target);
}
else {
LOGGER.info(String.format(
"Ignoring entity '%s': Type '%s' already exists",
entity, target));
return;
}
}
// Prepare class builder
final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(
declaredByMetadataId, modifier, target,
PhysicalTypeCategory.CLASS);
// Prepare annotations array
List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>(
2);
// Add @GvNIXJpaAuditListener annotation
AnnotationMetadataBuilder jpaAuditListenerAnnotation = new AnnotationMetadataBuilder(
new JavaType(GvNIXJpaAuditListener.class));
jpaAuditListenerAnnotation.addClassAttribute("entity", entity);
annotations.add(jpaAuditListenerAnnotation);
// Set annotations
cidBuilder.setAnnotations(annotations);
// Add GvNIXJpaAudit annotation to entity
if (!annotateEntity(entity)) {
// Already set annotation. Nothing to do
LOGGER.info(String
.format("Entity %s is already annotated with %s: ignore this entity.",
entity.getFullyQualifiedTypeName(),
GvNIXJpaAudit.class.getSimpleName()));
return;
}
// Create Listener class
typeManagementService.createOrUpdateTypeOnDisk(cidBuilder.build());
}
示例13: installRevisonEntity
import org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder; //導入方法依賴的package包/類
/**
* Create the class for entity which will hold the revision information for
* Hibernate Envers
* <p/>
* This use {@link #REVISION_LOG_ENTITY_NAME} as class name and look for
* <em>the first package which contains a entity</em> to place it.
*
*/
public void installRevisonEntity(JavaType revisionEntity) {
PathResolver pathResolver = projectOperations.getPathResolver();
JavaType target;
if (revisionEntity == null) {
target = generateRevionEntityJavaType();
}
else {
target = revisionEntity;
}
int modifier = Modifier.PUBLIC;
final String declaredByMetadataId = PhysicalTypeIdentifier
.createIdentifier(target,
pathResolver.getFocusedPath(Path.SRC_MAIN_JAVA));
File targetFile = new File(
typeLocationService
.getPhysicalTypeCanonicalPath(declaredByMetadataId));
if (targetFile.exists()) {
Validate.isTrue(!targetFile.exists(), "Type '%s' already exists",
target);
}
// Prepare class builder
final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(
declaredByMetadataId, modifier, target,
PhysicalTypeCategory.CLASS);
// Prepare annotations array
List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>(
1);
// Add @GvNIXJpaAuditListener annotation
AnnotationMetadataBuilder jpaAuditRevEntAnn = new AnnotationMetadataBuilder(
new JavaType(GvNIXJpaAuditRevisionEntity.class));
annotations.add(jpaAuditRevEntAnn);
// Set annotations
cidBuilder.setAnnotations(annotations);
// Create Revision entity class
typeManagementService.createOrUpdateTypeOnDisk(cidBuilder.build());
}
示例14: create
import org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder; //導入方法依賴的package包/類
/** {@inheritDoc} */
@Override
public void create(JavaType entity, JavaType target) {
Validate.notNull(entity, "Entity required");
if (target == null) {
target = generateJavaType(entity, null);
}
Validate.isTrue(
!JdkJavaType.isPartOfJavaLang(target.getSimpleTypeName()),
"Target name '%s' must not be part of java.lang",
target.getSimpleTypeName());
int modifier = Modifier.PUBLIC;
final String declaredByMetadataId = PhysicalTypeIdentifier
.createIdentifier(target,
pathResolver.getFocusedPath(Path.SRC_MAIN_JAVA));
File targetFile = new File(
typeLocationService
.getPhysicalTypeCanonicalPath(declaredByMetadataId));
Validate.isTrue(!targetFile.exists(), "Type '%s' already exists",
target);
// Prepare class builder
final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(
declaredByMetadataId, modifier, target,
PhysicalTypeCategory.CLASS);
// Prepare annotations array
List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>(
2);
// Add @Service annotations
annotations.add(new AnnotationMetadataBuilder(SpringJavaType.SERVICE));
// Add @GvNIXJpaBatch annotation
AnnotationMetadataBuilder jpaBatchAnnotation = new AnnotationMetadataBuilder(
new JavaType(GvNIXJpaBatch.class));
jpaBatchAnnotation.addClassAttribute("entity", entity);
annotations.add(jpaBatchAnnotation);
// Set annotations
cidBuilder.setAnnotations(annotations);
typeManagementService.createOrUpdateTypeOnDisk(cidBuilder.build());
}
示例15: generatePasswordHandler
import org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder; //導入方法依賴的package包/類
/**
* This method generates the file PasswordHandler.java with the annotation
* <code>@GvNIXPasswordHandlerSAFE</code>
*
*/
public void generatePasswordHandler(JavaPackage targetPackage) {
JavaType entity = new JavaType(String.format("%s.PasswordHandler",
targetPackage.getFullyQualifiedPackageName()));
Validate.notNull(entity, "Entity required");
int modifier = Modifier.PUBLIC;
final String declaredByMetadataId = PhysicalTypeIdentifier
.createIdentifier(entity,
pathResolver.getFocusedPath(Path.SRC_MAIN_JAVA));
File targetFile = new File(
typeLocationService
.getPhysicalTypeCanonicalPath(declaredByMetadataId));
Validate.isTrue(!targetFile.exists(), "Type '%s' already exists",
entity);
// Prepare class builder
final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(
declaredByMetadataId, modifier, entity,
PhysicalTypeCategory.CLASS);
// Prepare annotations array
List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>(
1);
// Add @GvNIXPasswordHandlerSAFE annotation
AnnotationMetadataBuilder gvnixPasswordHandlerAnnotation = new AnnotationMetadataBuilder(
new JavaType(GvNIXPasswordHandlerSAFE.class));
annotations.add(gvnixPasswordHandlerAnnotation);
// Add Implements Type
cidBuilder.addImplementsType(new JavaType(
"javax.security.auth.callback.CallbackHandler"));
// Set annotations
cidBuilder.setAnnotations(annotations);
typeManagementService.createOrUpdateTypeOnDisk(cidBuilder.build());
}