Example usage for java.lang Class getCanonicalName

List of usage examples for java.lang Class getCanonicalName

Introduction

In this page you can find the example usage for java.lang Class getCanonicalName.

Prototype

public String getCanonicalName() 

Source Link

Document

Returns the canonical name of the underlying class as defined by the Java Language Specification.

Usage

From source file:com.denksoft.springstarter.util.security.AclSecurityUtilImpl.java

public void deletePermission(AbstractSecureObject securedObject, Sid recipient, Permission permission,
        Class clazz) {
    ObjectIdentity oid = new ObjectIdentityImpl(clazz.getCanonicalName(), securedObject.getId());
    MutableAcl acl = (MutableAcl) mutableAclService.readAclById(oid);

    // Remove all permissions associated with this particular recipient (string equality to KISS)
    AccessControlEntry[] entries = acl.getEntries();

    for (int i = 0; i < entries.length; i++) {
        if (entries[i].getSid().equals(recipient) && entries[i].getPermission().equals(permission)) {
            acl.deleteAce(i);//  w w w.  j a v a2 s .c  o m
        }
    }

    mutableAclService.updateAcl(acl);

    if (logger.isDebugEnabled()) {
        logger.debug("Deleted securedObject " + securedObject + " ACL permissions for recipient " + recipient);
    }
}

From source file:com.mothsoft.alexis.dao.SourceDaoImpl.java

@SuppressWarnings("unchecked")
public List<Source> listSourcesWithRetrievalDateMoreThanXMinutesAgo(int minutes,
        Class<? extends Source> restrictionClass) {
    final String className = restrictionClass.getCanonicalName();
    final Date now = new Date();
    final int minutesInMilliseconds = minutes * 60 * 1000;
    final Date minutesAgo = new Date(now.getTime() - minutesInMilliseconds);

    final List<Source> sources = this.em
            .createQuery("FROM " + className
                    + " s WHERE s.retrievalDate IS NULL OR s.retrievalDate < :minutesAgo ORDER BY id ASC")
            .setParameter("minutesAgo", minutesAgo).getResultList();
    return sources;
}

From source file:com.kildeen.visor.core.api.permission.DefaultPermissionConverter.java

@Override
public String getId(Class<?> permissionClass) {
    String permission = permissionClass.getCanonicalName();
    int firstFolderIndex = permission.indexOf(".");
    firstFolderIndex++; // remove dot too.
    return permissionClass.getCanonicalName().substring(firstFolderIndex);
}

From source file:org.ff4j.aop.FeatureAutoProxy.java

private Object[] addAnnotedInterface(Class<?> currentInterface) {
    String currentInterfaceName = currentInterface.getCanonicalName();
    if (!currentInterfaceName.startsWith("java.")) {
        // Avoid process same interface several times
        Boolean isInterfaceFlipped = processedInterface.get(currentInterfaceName);
        if (isInterfaceFlipped != null) {
            if (isInterfaceFlipped) {
                return PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS;
            }/*from   w  ww  .  j a v a  2s  .c om*/
        } else {
            if (currentInterface.isAnnotationPresent(Flip.class)) {
                // If annotation is registered on Interface class 
                processedInterface.put(currentInterfaceName, true);
                return PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS;
            } else {
                for (Method method : currentInterface.getDeclaredMethods()) {
                    if (method.isAnnotationPresent(Flip.class)) {
                        processedInterface.put(currentInterfaceName, true);
                        return PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS;
                    }
                }
                processedInterface.put(currentInterfaceName, false);
            }
        }
    }
    return null;
}

From source file:de.knightsoftnet.validators.rebind.AbstractCreator.java

protected void addImports(final ClassSourceFileComposerFactory composerFactory, final Class<?>... imports) {
    for (final Class<?> imp : imports) {
        composerFactory.addImport(imp.getCanonicalName());
    }/*from   w ww.  j av  a2  s.  c  o m*/
}

From source file:com.github.hackersun.processor.factory.FactoryAnnotatedClass.java

/**
 * @throws ProcessingException if id() from annotation is null
 *//*from   w w  w .  j  a  v a  2 s . c  o  m*/
public FactoryAnnotatedClass(TypeElement classElement) throws ProcessingException {
    this.annotatedClassElement = classElement;
    Factory annotation = classElement.getAnnotation(Factory.class);
    id = annotation.id();

    if (StringUtils.isEmpty(id)) {
        throw new ProcessingException(classElement,
                "id() in @%s for class %s is null or empty! that's not allowed", Factory.class.getSimpleName(),
                classElement.getQualifiedName().toString());
    }

    // Get the full QualifiedTypeName
    try {
        Class<?> clazz = annotation.type();
        qualifiedGroupClassName = clazz.getCanonicalName();
        simpleFactoryGroupName = clazz.getSimpleName();
    } catch (MirroredTypeException mte) {
        DeclaredType classTypeMirror = (DeclaredType) mte.getTypeMirror();
        TypeElement classTypeElement = (TypeElement) classTypeMirror.asElement();
        qualifiedGroupClassName = classTypeElement.getQualifiedName().toString();
        simpleFactoryGroupName = classTypeElement.getSimpleName().toString();
    }
}

From source file:com.denksoft.springstarter.util.security.AclSecurityUtilImpl.java

public void addPermission(AbstractSecureObject securedObject, Sid recipient, Permission permission,
        Class clazz) {
    MutableAcl acl;/*from   ww  w  .  j  av  a2s  .co m*/
    ObjectIdentity oid = new ObjectIdentityImpl(clazz.getCanonicalName(), securedObject.getId());

    try {
        acl = (MutableAcl) mutableAclService.readAclById(oid);
    } catch (NotFoundException nfe) {
        acl = mutableAclService.createAcl(oid);
    }

    acl.insertAce(acl.getEntries().length, permission, recipient, true);
    mutableAclService.updateAcl(acl);

    if (logger.isDebugEnabled()) {
        logger.debug(
                "Added permission " + permission + " for Sid " + recipient + " securedObject " + securedObject);
    }
}

From source file:capital.scalable.restdocs.constraints.SkippableConstraintResolver.java

public SkippableConstraintResolver(MethodParameterConstraintResolver delegate,
        GroupDescriptionResolver descriptionResolver) {
    this.delegate = delegate;
    this.descriptionResolver = descriptionResolver;
    this.skippableConstraints = new ArrayList<>();
    for (Class<?> a : MANDATORY_VALUE_ANNOTATIONS) {
        this.skippableConstraints.add(a.getCanonicalName());
    }/*from w  ww.  jav a 2s . com*/
}

From source file:io.silverware.microservices.providers.cdi.internal.RestInterface.java

private static String getParamName(final Parameter methodParameter, Method method, final Class<?> clazz) {
    final ParamName paramName = methodParameter.getAnnotation(ParamName.class);
    if (paramName != null && paramName.value() != null && !paramName.value().trim().isEmpty()) {
        return paramName.value().trim();
    }/*ww w .ja va  2 s .c om*/
    final JsonProperty jsonProperty = methodParameter.getAnnotation(JsonProperty.class);
    if (jsonProperty != null && jsonProperty.value() != null && !jsonProperty.value().trim().isEmpty()) {
        return jsonProperty.value().trim();
    }

    if (!methodParameter.isNamePresent()) {
        log.warn(String.format(
                "Method parameter name is not present for method %s in class %s. Please use compilation argument (or test compilation argument) \"-parameters\""
                        + " or use annotation @%s or @%s for parameters of this method.",
                method.getName(), clazz.getCanonicalName(), ParamName.class.getCanonicalName(),
                JsonProperty.class.getCanonicalName()));
    }
    return methodParameter.getName();
}

From source file:Main.java

/**
 * Gets the base location of the given class.
 * <p>//from  w  ww .  j  av a2s  .  c  om
 * If the class is directly on the file system (e.g.,
 * "/path/to/my/package/MyClass.class") then it will return the base directory
 * (e.g., "file:/path/to").
 * </p>
 * <p>
 * If the class is within a JAR file (e.g.,
 * "/path/to/my-jar.jar!/my/package/MyClass.class") then it will return the
 * path to the JAR (e.g., "file:/path/to/my-jar.jar").
 * </p>
 * 
 * @param c The class whose location is desired.
 * @see FileUtils#urlToFile(URL) to convert the result to a {@link File}.
 */
public static URL getLocation(final Class<?> c) {
    if (c == null)
        return null; // could not load the class

    // try the easy way first
    try {
        final URL codeSourceLocation = c.getProtectionDomain().getCodeSource().getLocation();
        if (codeSourceLocation != null)
            return codeSourceLocation;
    } catch (SecurityException e) {
        // NB: Cannot access protection domain.
    } catch (NullPointerException e) {
        // NB: Protection domain or code source is null.
    }

    // NB: The easy way failed, so we try the hard way. We ask for the class
    // itself as a resource, then strip the class's path from the URL string,
    // leaving the base path.

    // get the class's raw resource path
    final URL classResource = c.getResource(c.getSimpleName() + ".class");
    if (classResource == null)
        return null; // cannot find class resource

    final String url = classResource.toString();
    final String suffix = c.getCanonicalName().replace('.', '/') + ".class";
    if (!url.endsWith(suffix))
        return null; // weird URL

    // strip the class's path from the URL string
    final String base = url.substring(0, url.length() - suffix.length());

    String path = base;

    // remove the "jar:" prefix and "!/" suffix, if present
    if (path.startsWith("jar:"))
        path = path.substring(4, path.length() - 2);

    try {
        return new URL(path);
    } catch (MalformedURLException e) {
        e.printStackTrace();
        return null;
    }
}