Java Code Examples for org.apache.commons.lang.ClassUtils#getPackageName()
The following examples show how to use
org.apache.commons.lang.ClassUtils#getPackageName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AnnotationHelper.java From rice with Educational Community License v2.0 | 6 votes |
private boolean imported(List<ImportDeclaration> imports, String fullyQualifiedName) { final String packageName = ClassUtils.getPackageName(fullyQualifiedName); for (final ImportDeclaration i : imports) { if (!i.isStatic()) { final String importName = i.getName().toString(); if (i.isAsterisk()) { if (packageName.equals(importName)) { if ( LOG.isDebugEnabled() ) { LOG.debug("found import " + packageName + ".* on " + getTypeNameForMsg(i) + "."); } return true; } } else { if (fullyQualifiedName.equals(importName)) { if ( LOG.isDebugEnabled() ) { LOG.debug("found import " + fullyQualifiedName + " on " + getTypeNameForMsg(i) + "."); } return true; } } } } return false; }
Example 2
Source File: ConvertResolver.java From rice with Educational Community License v2.0 | 5 votes |
/** gets the annotation but also adds an import in the process if a Convert annotation is required. */ @Override protected NodeData getAnnotationNodes(String enclosingClass, String fieldName, String mappedClass) { final FieldDescriptor fd = OjbUtil.findFieldDescriptor(mappedClass, fieldName, descriptorRepositories); if (fd != null) { final FieldConversion fc = fd.getFieldConversion(); //in ojb all columns have at least the default field conversion if (fc != null && FieldConversionDefaultImpl.class != fc.getClass()) { LOG.info(enclosingClass + "." + fieldName + " for the mapped class " + mappedClass + " field has a converter " + fc.getClass().getName()); final String jpaConverter = getJpaConverterForOjbClass(fc.getClass().getName()); if (jpaConverter == null) { LOG.error(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field has a converter " + fc.getClass().getName() + " but a replacement converter was not configured, unable to set Convert class"); return new NodeData(new NormalAnnotationExpr(new NameExpr(SIMPLE_NAME), Collections.singletonList(new MemberValuePair("converter", new NameExpr(null)))), new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false)); } else if ( StringUtils.isBlank(jpaConverter) ) { LOG.info(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field has a converter " + fc.getClass().getName() + " But no converter definition is needed due to default converter configuration." ); } else { final String shortClassName = ClassUtils.getShortClassName(jpaConverter); final String packageName = ClassUtils.getPackageName(jpaConverter); return new NodeData(new NormalAnnotationExpr(new NameExpr(SIMPLE_NAME), Collections.singletonList(new MemberValuePair("converter", new NameExpr(shortClassName + ".class")))), new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false), Collections.singletonList(new ImportDeclaration(new QualifiedNameExpr(new NameExpr(packageName), shortClassName), false, false))); } } } return null; }
Example 3
Source File: ManyToOneResolver.java From rice with Educational Community License v2.0 | 4 votes |
/** gets the annotation but also adds an import in the process if a Convert annotation is required. */ @Override protected NodeData getAnnotationNodes(String enclosingClass, String fieldName, String mappedClass) { final ObjectReferenceDescriptor ord = OjbUtil.findObjectReferenceDescriptor(mappedClass, fieldName, descriptorRepositories); if (ord != null) { final List<MemberValuePair> pairs = new ArrayList<MemberValuePair>(); final Collection<ImportDeclaration> additionalImports = new ArrayList<ImportDeclaration>(); final Collection<String> fks = ord.getForeignKeyFields(); if (fks == null || fks.isEmpty()) { LOG.error(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field has a reference descriptor for " + fieldName + " but does not have any foreign keys configured"); return null; } final Collection<String> pks = OjbUtil.getPrimaryKeyNames(mappedClass, descriptorRepositories); if (!(pks.size() == fks.size() && pks.containsAll(fks))) { final String className = ord.getItemClassName(); if (StringUtils.isBlank(className)) { LOG.error(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field has a reference descriptor for " + fieldName + " but does not class name attribute"); } else { final String shortClassName = ClassUtils.getShortClassName(className); final String packageName = ClassUtils.getPackageName(className); pairs.add(new MemberValuePair("targetEntity", new NameExpr(shortClassName + ".class"))); additionalImports.add(new ImportDeclaration(new QualifiedNameExpr(new NameExpr(packageName), shortClassName), false, false)); } final boolean proxy = ord.isLazy(); if (proxy) { pairs.add(new MemberValuePair("fetch", new NameExpr("FetchType.LAZY"))); additionalImports.add(new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), "FetchType"), false, false)); } final boolean refresh = ord.isRefresh(); if (refresh) { LOG.error(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field has refresh set to " + refresh + ", unsupported conversion to @OneToOne attributes"); } final List<Expression> cascadeTypes = new ArrayList<Expression>(); final boolean autoRetrieve = ord.getCascadeRetrieve(); if (autoRetrieve) { cascadeTypes.add(new NameExpr("CascadeType.REFRESH")); } else { // updated default logging - false would result no additional annotations if ( LOG.isDebugEnabled() ) { LOG.debug(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field has auto-retrieve set to " + autoRetrieve + ", unsupported conversion to CascadeType"); } } final int autoDelete = ord.getCascadingDelete(); if (autoDelete == ObjectReferenceDescriptor.CASCADE_NONE) { // updated default logging - none would result no additional annotations if ( LOG.isDebugEnabled() ) { LOG.debug(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field has auto-delete set to none, unsupported conversion to CascadeType"); } } else if (autoDelete == ObjectReferenceDescriptor.CASCADE_LINK) { LOG.warn(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field has auto-delete set to link, unsupported conversion to CascadeType"); } else if (autoDelete == ObjectReferenceDescriptor.CASCADE_OBJECT) { cascadeTypes.add(new NameExpr("CascadeType.REMOVE")); } else { LOG.error(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field has auto-delete set to an invalid value"); } final int autoUpdate = ord.getCascadingStore(); if (autoUpdate == ObjectReferenceDescriptor.CASCADE_NONE) { // updated default logging - none would result no additional annotations if ( LOG.isDebugEnabled() ) { LOG.debug(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field has auto-update set to none, unsupported conversion to CascadeType"); } } else if (autoUpdate == ObjectReferenceDescriptor.CASCADE_LINK) { LOG.warn(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field has auto-update set to link, unsupported conversion to CascadeType"); } else if (autoUpdate == ObjectReferenceDescriptor.CASCADE_OBJECT) { cascadeTypes.add(new NameExpr("CascadeType.PERSIST")); } else { LOG.error(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field has auto-update set to an invalid value"); } if (!cascadeTypes.isEmpty()) { pairs.add(new MemberValuePair("cascade", new ArrayInitializerExpr(cascadeTypes))); additionalImports.add(new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), "CascadeType"), false, false)); } return new NodeData(new NormalAnnotationExpr(new NameExpr(SIMPLE_NAME), pairs), new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false), additionalImports); } } return null; }
Example 4
Source File: OneToOneResolver.java From rice with Educational Community License v2.0 | 4 votes |
/** gets the annotation but also adds an import in the process if a Convert annotation is required. */ @Override protected NodeData getAnnotationNodes(String enclosingClass, String fieldName, String mappedClass) { final ObjectReferenceDescriptor ord = OjbUtil.findObjectReferenceDescriptor(mappedClass, fieldName, descriptorRepositories); if (ord != null) { final List<MemberValuePair> pairs = new ArrayList<MemberValuePair>(); final Collection<ImportDeclaration> additionalImports = new ArrayList<ImportDeclaration>(); final Collection<String> fks = ord.getForeignKeyFields(); if (fks == null || fks.isEmpty()) { LOG.error(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field has a reference descriptor for " + fieldName + " but does not have any foreign keys configured"); return null; } final Collection<String> pks = OjbUtil.getPrimaryKeyNames(mappedClass, descriptorRepositories); if (pks.size() == fks.size() && pks.containsAll(fks)) { final String itemClassName = ord.getItemClassName(); if (StringUtils.isBlank(itemClassName)) { LOG.error(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field has a reference descriptor for " + fieldName + " but does not class name attribute"); } else { final String shortClassName = ClassUtils.getShortClassName(itemClassName); final String packageName = ClassUtils.getPackageName(itemClassName); pairs.add(new MemberValuePair("targetEntity", new NameExpr(shortClassName + ".class"))); additionalImports.add(new ImportDeclaration(new QualifiedNameExpr(new NameExpr(packageName), shortClassName), false, false)); } final boolean proxy = ord.isLazy(); if (proxy) { pairs.add(new MemberValuePair("fetch", new NameExpr("FetchType.LAZY"))); additionalImports.add(new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), "FetchType"), false, false)); } final boolean refresh = ord.isRefresh(); if (refresh) { LOG.error(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field has refresh set to " + refresh + ", unsupported conversion to @OneToOne attributes"); } final List<Expression> cascadeTypes = new ArrayList<Expression>(); final boolean autoRetrieve = ord.getCascadeRetrieve(); if (autoRetrieve) { cascadeTypes.add(new NameExpr("CascadeType.REFRESH")); } else { LOG.warn(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field has auto-retrieve set to " + autoRetrieve + ", unsupported conversion to CascadeType"); } final int autoDelete = ord.getCascadingDelete(); if (autoDelete == ObjectReferenceDescriptor.CASCADE_NONE) { LOG.warn(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field has auto-delete set to none, unsupported conversion to CascadeType"); } else if (autoDelete == ObjectReferenceDescriptor.CASCADE_LINK) { LOG.warn(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field has auto-delete set to link, unsupported conversion to CascadeType"); } else if (autoDelete == ObjectReferenceDescriptor.CASCADE_OBJECT) { cascadeTypes.add(new NameExpr("CascadeType.REMOVE")); pairs.add(new MemberValuePair("orphanRemoval", new BooleanLiteralExpr(true))); } else { LOG.error(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field has auto-delete set to an invalid value"); } final int autoUpdate = ord.getCascadingStore(); if (autoUpdate == ObjectReferenceDescriptor.CASCADE_NONE) { LOG.warn(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field has auto-update set to none, unsupported conversion to CascadeType"); } else if (autoUpdate == ObjectReferenceDescriptor.CASCADE_LINK) { LOG.warn(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field has auto-update set to link, unsupported conversion to CascadeType"); } else if (autoUpdate == ObjectReferenceDescriptor.CASCADE_OBJECT) { cascadeTypes.add(new NameExpr("CascadeType.PERSIST")); } else { LOG.error(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field has auto-update set to an invalid value"); } if (!cascadeTypes.isEmpty()) { pairs.add(new MemberValuePair("cascade", new ArrayInitializerExpr(cascadeTypes))); additionalImports.add(new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), "CascadeType"), false, false)); } final NodeData nodeData; if (isBidirectional(mappedClass, itemClassName)) { LOG.info(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " bi-directional OneToOne relationship detected"); final String mappedBy = getMappedBy(mappedClass, itemClassName); final Comment fixme = new BlockComment("\nFIXME: JPA_CONVERSION \n" + "For one-to-one bidirectional relationships, the owning side corresponds to the side that contains the corresponding foreign key.\n" + "Even in the absence of a foreign key, one side must be the owning side.\n" + "If this is not the owning side, the required annotation should be:\n@OneToOne(mappedBy=\"" + mappedBy + "\")\n"); final NormalAnnotationExpr annotation = new NormalAnnotationExpr(new NameExpr(SIMPLE_NAME), pairs); annotation.setComment(fixme); nodeData = new NodeData(annotation, new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false), additionalImports); } else { nodeData = new NodeData(new NormalAnnotationExpr(new NameExpr(SIMPLE_NAME), pairs), new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false), additionalImports); } return nodeData; } } return null; }