Example usage for java.lang Class isAnnotationPresent

List of usage examples for java.lang Class isAnnotationPresent

Introduction

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

Prototype

@Override
public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) 

Source Link

Usage

From source file:com.mmnaseri.dragonfly.metadata.impl.AnnotationTableMetadataResolver.java

@Override
public boolean accepts(Class<?> entityType) {
    return entityType.isAnnotationPresent(Entity.class);
}

From source file:edu.kit.dama.mdm.core.jpa.MetaDataManagerJpa.java

/**
 * Set the field annotated with <code>@Id</code> of the provided entity to
 * null. This method is used to 'mark' an entity as 'removed'. If the field
 * cannot be accessed, an UnauthorizedAccessAttemptException is thrown.
 * Otherwise, true is returned./*from w  w  w  .  j  a  va2  s .  co  m*/
 *
 * @param <T> Generic entity type.
 * @param entityClass The entity class.
 * @param entity The entity.
 *
 * @return TRUE if the Id field could be set to null or if the provided
 * entity is not a JPA entity.
 *
 * @throws UnauthorizedAccessAttemptException If the Id field cannot be
 * accessed.
 */
private <T> boolean setIdOfEntity2Null(Class entityClass, T entity) throws UnauthorizedAccessAttemptException {
    boolean success = false;
    if (entityClass.isAnnotationPresent(Entity.class)) {
        Field[] fields = entityClass.getDeclaredFields();
        for (Field field : fields) {
            Id entityId = field.getAnnotation(Id.class);
            if (entityId != null) {
                field.setAccessible(true);
                try {
                    field.set(entity, null);
                } catch (IllegalAccessException iae) {
                    throw new UnauthorizedAccessAttemptException(
                            "Failed to access value of field '" + field.getName() + "' annotated by 'Id", iae);
                } finally {
                    field.setAccessible(false);
                    // exit loop
                    break;
                }
            }
        }
        if (!success) {
            success = setIdOfEntity2Null(entityClass.getSuperclass(), entity);
        }
    } else {
        success = true;
    }
    return success;
}

From source file:org.kuali.rice.krad.service.impl.DataDictionaryComponentPublisherServiceImpl.java

protected String deriveComponentName(Class<?> componentSourceClass) {
    if (componentSourceClass == null) {
        throw new IllegalArgumentException(
                "The deriveComponentName method requires non-null componentSourceClass");
    }//  www .  j av  a2 s  .c  om

    /*
     * Some business objects have a Component annotation that sets the value
     * of the classes annotation.  This if block will test to see if it is there, try to get the
     * component value from the Data Dictionary if the BusinessObjectEntry exists, if it doesn't
     * exist, it will fall back to the annotation's value.
     */
    if (componentSourceClass.isAnnotationPresent(ParameterConstants.COMPONENT.class)) {
        DataObjectEntry doe = getDataDictionaryService().getDataDictionary()
                .getDataObjectEntry(componentSourceClass.getName());
        if (doe != null) {
            return doe.getObjectLabel();
        } else {
            return componentSourceClass.getAnnotation(ParameterConstants.COMPONENT.class).component();
        }
    }

    /*
     * If block that determines if the class is either a BusinessObject or a TransactionalDocument
     * return calls try to either get the BusinessObjectEntry's ObjectLable, or grabbing the
     * data dictionary's BusinessTitleForClass if it is a BusinessObject, or the DocumentLabel if it is a
     * TransactionalDocument
     */
    if (TransactionalDocument.class.isAssignableFrom(componentSourceClass)) {
        return getDataDictionaryService().getDocumentLabelByClass(componentSourceClass);
    }
    DataObjectEntry doe = getDataDictionaryService().getDataDictionary()
            .getDataObjectEntry(componentSourceClass.getName());
    if (doe != null) {
        return doe.getObjectLabel();
    } else {
        return KRADUtils.getBusinessTitleForClass(componentSourceClass);
    }
}

From source file:net.frontlinesms.FrontlineSMS.java

/**
 * Gets a list of configLocations required for initialising Spring {@link ApplicationContext}.
 * This method should only be called from within {@link FrontlineSMS#initApplicationContext()}
 * @param externalConfigPath Spring path to the external Spring database config file 
 * @return list of configLocations used for initialising {@link ApplicationContext}
 *///from   ww w  . j a  va 2 s  .  com
private String[] getSpringConfigLocations(String... externalConfigPaths) {
    ArrayList<String> configLocations = new ArrayList<String>();

    // Custom Spring configurations
    for (String externalConfigPath : externalConfigPaths) {
        LOG.info("Loading spring application context from: " + externalConfigPath);
        configLocations.add("file:" + externalConfigPath);
    }

    // Main Spring configuration
    configLocations.add("classpath:frontlinesms-spring-hibernate.xml");

    // Add config locations for plugins
    for (Class<PluginController> pluginControllerClass : PluginProperties.getInstance().getPluginClasses()) {
        if (pluginControllerClass.isAnnotationPresent(PluginControllerProperties.class)) {
            PluginControllerProperties properties = pluginControllerClass
                    .getAnnotation(PluginControllerProperties.class);
            String pluginConfigLocation = properties.springConfigLocation();
            if (!PluginControllerProperties.NO_VALUE.equals(pluginConfigLocation)) {
                LOG.trace("Adding plugin Spring config location: " + pluginConfigLocation);
                configLocations.add(pluginConfigLocation);
            }
        }
    }

    return configLocations.toArray(new String[configLocations.size()]);
}

From source file:org.squidy.designer.knowledgebase.RepositoryItem.java

/**
 * @param goalDirectedZoom//from  www . ja  v a2s . com
 */
public RepositoryItem(Class<? extends Processable> processable) throws SquidyException {
    setBounds(Constants.DEFAULT_NODE_BOUNDS);

    setTitle("N/A");

    this.processableClass = processable;

    if (processable.isAnnotationPresent(Processor.class)) {
        Processor processor = processable.getAnnotation(Processor.class);
        setTitle(processor.name());
        stable = processor.status().equals(Status.STABLE);
        information = processor.description();
        try {
            image = new PImage(ImageUtils.getProcessorIconURL(processor));
        } catch (Exception e) {
            if (LOG.isErrorEnabled()) {
                LOG.error(e.getMessage(), e);
            }
        }
    }

    if (image != null) {
        image.setScale(10);
        image.setPickable(false);
        image.setChildrenPickable(false);
        addChild(image);
    }
    addInputEventListener(new KnowledgeBaseEventHandler());
}

From source file:com.github.gekoh.yagen.ddl.TableConfig.java

private void gatherPkColumn(Class entityClass) {
    Set<AccessibleObject> fieldsOrMethods = getAnnotatedFieldOrMethod(new HashSet<AccessibleObject>(), Id.class,
            entityClass, true);// w  w w . ja v a2 s  .c om

    if (entityClass.isAnnotationPresent(PrimaryKeyJoinColumn.class)) {
        pkColnames = Arrays
                .asList(((PrimaryKeyJoinColumn) entityClass.getAnnotation(PrimaryKeyJoinColumn.class)).name());
    } else if (fieldsOrMethods.size() > 0) {
        pkColnames = new ArrayList<String>();
        for (AccessibleObject fieldOrMethod : fieldsOrMethods) {
            String colName = null;
            if (fieldOrMethod.isAnnotationPresent(Column.class)) {
                colName = fieldOrMethod.getAnnotation(Column.class).name();
            }
            if (colName == null && fieldOrMethod instanceof Field) {
                colName = ((Field) fieldOrMethod).getName();
            }
            if (colName != null) {
                pkColnames.add(colName);
            }
        }
    }
}

From source file:org.codehaus.enunciate.modules.xfire.EnunciatedJAXWSOperationBinding.java

/**
 * Loads the set of output properties for the specified operation.
 *
 * @param op The operation./* w  ww .j  ava  2  s  .c o  m*/
 * @return The output properties.
 */
protected OperationBeanInfo getResponseInfo(OperationInfo op) throws XFireFault {
    Method method = op.getMethod();
    Class ei = method.getDeclaringClass();
    Package pckg = ei.getPackage();
    SOAPBinding.ParameterStyle paramStyle = SOAPBinding.ParameterStyle.WRAPPED;
    if (method.isAnnotationPresent(SOAPBinding.class)) {
        SOAPBinding annotation = method.getAnnotation(SOAPBinding.class);
        paramStyle = annotation.parameterStyle();
    } else if (ei.isAnnotationPresent(SOAPBinding.class)) {
        SOAPBinding annotation = ((SOAPBinding) ei.getAnnotation(SOAPBinding.class));
        paramStyle = annotation.parameterStyle();
    }

    if (paramStyle == SOAPBinding.ParameterStyle.BARE) {
        //bare return type.
        //todo: it's not necessarily the return type! it could be an OUT parameter...
        return new OperationBeanInfo(method.getReturnType(), null, op.getOutputMessage());
    } else {
        String responseWrapperClassName;
        ResponseWrapper responseWrapperInfo = method.getAnnotation(ResponseWrapper.class);
        if ((responseWrapperInfo != null) && (responseWrapperInfo.className() != null)
                && (responseWrapperInfo.className().length() > 0)) {
            responseWrapperClassName = responseWrapperInfo.className();
        } else {
            StringBuilder builder = new StringBuilder(pckg == null ? "" : pckg.getName());
            if (builder.length() > 0) {
                builder.append(".");
            }

            builder.append("jaxws.");

            String methodName = method.getName();
            builder.append(capitalize(methodName)).append("Response");
            responseWrapperClassName = builder.toString();
        }

        Class wrapperClass;
        try {
            wrapperClass = ClassLoaderUtils.loadClass(responseWrapperClassName, getClass());
        } catch (ClassNotFoundException e) {
            LOG.debug("Unabled to find request wrapper class " + responseWrapperClassName + "... Operation "
                    + op.getQName() + " will not be able to send...");
            return null;
        }

        return new OperationBeanInfo(wrapperClass, loadOrderedProperties(wrapperClass), op.getOutputMessage());
    }
}

From source file:net.ymate.platform.core.beans.impl.DefaultBeanFactory.java

protected Object __wrapProxy(IProxyFactory proxyFactory, Object targetObject) {
    final Class<?> _targetClass = targetObject.getClass();
    ////w  ww .j a v a 2s .c o m
    List<IProxy> _targetProxies = proxyFactory.getProxies(new IProxyFilter() {

        private boolean __doCheckAnnotation(Proxy targetProxyAnno) {
            // targetClass???true
            if (targetProxyAnno.annotation().length > 0) {
                for (Class<? extends Annotation> _annoClass : targetProxyAnno.annotation()) {
                    if (_targetClass.isAnnotationPresent(_annoClass)) {
                        return true;
                    }
                }
                return false;
            }
            return true;
        }

        public boolean filter(IProxy targetProxy) {
            CleanProxy _cleanProxy = _targetClass.getAnnotation(CleanProxy.class);
            if (_cleanProxy != null) {
                if (_cleanProxy.value().length > 0) {
                    for (Class<? extends IProxy> _proxyClass : _cleanProxy.value()) {
                        if (_proxyClass.equals(targetProxy.getClass())) {
                            return false;
                        }
                    }
                } else {
                    return false;
                }
            }
            Proxy _targetProxyAnno = targetProxy.getClass().getAnnotation(Proxy.class);
            // 
            if (StringUtils.isNotBlank(_targetProxyAnno.packageScope())) {
                // ??
                if (!StringUtils.startsWith(_targetClass.getPackage().getName(),
                        _targetProxyAnno.packageScope())) {
                    return false;
                }
            }
            return __doCheckAnnotation(_targetProxyAnno);
        }
    });
    if (!_targetProxies.isEmpty()) {
        // ????????
        return ClassUtils.wrapper(targetObject)
                .duplicate(proxyFactory.createProxy(_targetClass, _targetProxies));
    }
    return targetObject;
}

From source file:com.m4rc310.cb.builders.ComponentBuilder.java

public void _showDialog(Object objAnnotated, String ref, Object relative, Object... args) {

    if (objAnnotated != null) {
        objectAnnotated = objAnnotated;//from   w w w  . j  a va 2 s .c  om
        //            Class[] classArgs = new Class[args.length];
        //            MethodUtils.method(objectAnnotated, "setValuesToSearch", classArgs).invoke(args[0]);
    } else {
        objectAnnotated = getNewInstanceObjectAnnotated(ref, args);
    }

    Class<? extends Object> objectAnnotatedClass = objectAnnotated.getClass();

    dialog = new JDialogDefalt();

    if (objectAnnotatedClass.isAnnotationPresent(Amethod.class)) {
        Amethod am = objectAnnotatedClass.getDeclaredAnnotation(Amethod.class);
        final String methodOnError = am.methodOnError();
        LogServer.getInstance().debug(null, "Adicionando Listener de erro: {0}", methodOnError);
        if (!methodOnError.isEmpty()) {
            dialog.addPropertyChangeListener("onError", (PropertyChangeEvent evt) -> {
                getTargetsForMethodName(methodOnError).stream().forEach((tar) -> {
                    MethodUtils.declaredMethod(tar, methodOnError, String.class, String.class)
                            .invoke(evt.getPropertyName(), evt.getNewValue());
                });
            });
        }
    }

    Adialog ad = objectAnnotatedClass.getDeclaredAnnotation(Adialog.class);

    String title = getString(ad.title(), ref);
    if (ad.debug()) {
        title = getString("title.title.mode.debug", title);
    }
    dialog.setTitle(title);

    dialog.addWindowListener(new WindowAdapter() {
        @Override
        public void windowOpened(WindowEvent e) {
            MethodUtils.method(objectAnnotated, "setComponentsBuilder", ComponentBuilder.class)
                    .invoke(ComponentBuilder.this);
            MethodUtils.method(objectAnnotated, "setDialog", Dialog.class).invoke(dialog);
            MethodUtils.method(objectAnnotated, "setGui", GuiUtils.class).invoke(gui);
        }
    });

    dialog.setLayout(new MigLayout(ad.layoutDialog()));
    dialog.abiliteCloseOnESC();

    putContainer(objectAnnotated.hashCode(), dialog);

    addTargets(objectAnnotated);
    loadAllFields(objectAnnotated, objectAnnotated.getClass());

    buildAllComponents();
    printDialog();

    dialog.setFontSize(ad.fontSize());
    dialog.setModal(ad.modal());
    dialog.setResizable(ad.resizable());
    dialog.pack();

    dialog.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);

    dialog.setLocationRelativeTo((Component) relative);
    dialog.showWindow();
}

From source file:net.frontlinesms.FrontlineSMS.java

/**
 * Create the configLocations bean for the Hibernate config.
 * This method should only be called from within {@link FrontlineSMS#initApplicationContext()}
 * @return {@link BeanDefinition} containing details of the hibernate config for the app and its plugins.
 *//*from   w w w.  j  av  a2 s  .c  om*/
private BeanDefinition createHibernateConfigLocationsBeanDefinition() {
    // Initialise list of hibernate config files
    List<String> hibernateConfigList = new ArrayList<String>();
    // Add main hibernate config location
    hibernateConfigList.add("classpath:frontlinesms.hibernate.cfg.xml");
    // Add hibernate config locations for plugins
    for (Class<PluginController> pluginClass : PluginProperties.getInstance().getPluginClasses()) {
        LOG.info("Processing plugin class: " + pluginClass.getName());
        if (pluginClass.isAnnotationPresent(PluginControllerProperties.class)) {
            PluginControllerProperties properties = pluginClass.getAnnotation(PluginControllerProperties.class);
            String pluginHibernateLocation = properties.hibernateConfigPath();
            if (!PluginControllerProperties.NO_VALUE.equals(pluginHibernateLocation)) {
                hibernateConfigList.add(pluginHibernateLocation);
            }
        }
    }

    GenericBeanDefinition myBeanDefinition = new GenericBeanDefinition();
    myBeanDefinition.setBeanClass(ListFactoryBean.class);
    MutablePropertyValues values = new MutablePropertyValues();
    values.addPropertyValue("sourceList", hibernateConfigList);
    myBeanDefinition.setPropertyValues(values);

    return myBeanDefinition;
}