Example usage for java.lang Class getDeclaredAnnotations

List of usage examples for java.lang Class getDeclaredAnnotations

Introduction

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

Prototype

public Annotation[] getDeclaredAnnotations() 

Source Link

Usage

From source file:com.serli.chell.framework.form.FormStructure.java

private void loadForm(Class<? extends Form> formClass) {
    FormType formType;//w  w w .j av  a  2s  .c  o m
    AnnotationMetaDataInfos annotationInfos;
    Class<?> currentClass = formClass;
    List<FormButton> buttonList = new ArrayList<FormButton>();
    boolean sortButtons = false;
    do {
        ResourceProvider.loadResourcesFromClass(resources, currentClass);
        for (Annotation annotation : currentClass.getDeclaredAnnotations()) {
            ResourceProvider.loadResourcesFromAnnotation(resources, annotation);
            annotationInfos = AnnotationMetaDataInfos.get(annotation.annotationType());
            formType = (FormType) annotationInfos.getValue(Type.FORM_TYPE, annotation);
            if (formType != null) {
                switch (formType) {
                case FORM:
                    loadForm(annotationInfos, annotation);
                    break;
                case BUTTON:
                    sortButtons |= loadButton(annotationInfos, annotation, buttonList);
                    break;
                }
            }
        }
        currentClass = currentClass.getSuperclass();
    } while (!currentClass.equals(Object.class));

    if (sortButtons) {
        buttons.clear();
        Collections.sort(buttonList);
        for (FormButton button : buttonList) {
            buttons.put(button.getName(), button);
        }
    }
}

From source file:com.bstek.dorado.view.registry.AssembledComponentTypeRegister.java

@Override
protected ComponentTypeRegisterInfo getRegisterInfo() throws Exception {
    AssembledComponentTypeRegisterInfo registerInfo = (AssembledComponentTypeRegisterInfo) super.getRegisterInfo();

    Class<? extends Component> cl = registerInfo.getClassType();
    if (cl != null && !AssembledComponent.class.isAssignableFrom(cl)) {
        throw new IllegalArgumentException(cl + " should implements " + AssembledComponent.class + ".");
    }//from  ww w  . j  a v  a 2 s. co m

    registerInfo.setSrc(src);

    String category = null;
    Widget widget = null;
    if (cl != null) {
        widget = cl.getAnnotation(Widget.class);
        if (widget != null && ArrayUtils.indexOf(cl.getDeclaredAnnotations(), widget) >= 0) {
            category = widget.category();
        }
    }
    registerInfo.setCategory((StringUtils.isEmpty(category)) ? "Others" : category);

    Map<String, VirtualPropertyDescriptor> propertieDescriptors = new HashMap<String, VirtualPropertyDescriptor>();
    if (virtualProperties != null) {
        for (Map.Entry<String, Properties> entry : virtualProperties.entrySet()) {
            String propertyName = entry.getKey();
            Properties properties = entry.getValue();
            VirtualPropertyDescriptor propertyDescriptor = new VirtualPropertyDescriptor();
            propertyDescriptor.setName(propertyName);

            String type = properties.getProperty("type");
            if (StringUtils.isNotEmpty(type)) {
                propertyDescriptor.setType(ClassUtils.forName(type));
            }

            String avialableAt = properties.getProperty("avialableAt");
            if (StringUtils.isNotEmpty(avialableAt)) {
                propertyDescriptor.setAvialableAt(VirtualPropertyAvialableAt.valueOf(avialableAt));
            }

            propertyDescriptor.setDefaultValue(properties.getProperty("defaultValue"));
            propertyDescriptor.setReferenceComponentType(properties.getProperty("referenceComponentType"));
            propertieDescriptors.put(propertyName, propertyDescriptor);
        }
    }
    registerInfo.setVirtualProperties(propertieDescriptors);

    Map<String, VirtualEventDescriptor> eventDescriptors = new HashMap<String, VirtualEventDescriptor>();
    if (virtualEvents != null) {
        for (Map.Entry<String, Properties> entry : virtualEvents.entrySet()) {
            String eventName = entry.getKey();
            VirtualEventDescriptor eventDescriptor = new VirtualEventDescriptor();
            eventDescriptor.setName(eventName);
            eventDescriptors.put(eventName, eventDescriptor);
        }
    }
    registerInfo.setVirtualEvents(eventDescriptors);
    return registerInfo;
}

From source file:org.dasein.persist.PersistentCache.java

static public PersistentCache<? extends CachedItem> getCache(Class<? extends CachedItem> forClass)
        throws PersistenceException {
    SchemaMapper[] mappers = null;/*from   w  w  w.ja  v  a2s.c  o m*/
    String schemaVersion = null;
    String entityName = null;

    for (Annotation annotation : forClass.getDeclaredAnnotations()) {
        if (annotation instanceof Schema) {
            schemaVersion = ((Schema) annotation).value();
            entityName = ((Schema) annotation).entity();

            Class<? extends SchemaMapper>[] mclasses = ((Schema) annotation).mappers();

            if (mclasses != null && mclasses.length > 0) {
                mappers = new SchemaMapper[mclasses.length];
                for (int i = 0; i < mclasses.length; i++) {
                    try {
                        mappers[i] = mclasses[i].newInstance();
                    } catch (Throwable t) {
                        throw new PersistenceException(t.getMessage());
                    }
                }
            }
        }
    }
    return getCacheWithSchema(forClass, entityName, schemaVersion == null ? "0" : schemaVersion, mappers);
}

From source file:org.dasein.persist.PersistentCache.java

static public PersistentCache<? extends CachedItem> getCache(Class<? extends CachedItem> forClass,
        String primaryKey) throws PersistenceException {
    SchemaMapper[] mappers = null;//from   w ww . j a v  a 2s  .c  o m
    String schemaVersion = null;
    String entityName = null;

    for (Annotation annotation : forClass.getDeclaredAnnotations()) {
        if (annotation instanceof Schema) {
            schemaVersion = ((Schema) annotation).value();
            entityName = ((Schema) annotation).entity();

            Class<? extends SchemaMapper>[] mclasses = ((Schema) annotation).mappers();

            if (mclasses != null && mclasses.length > 0) {
                mappers = new SchemaMapper[mclasses.length];
                for (int i = 0; i < mclasses.length; i++) {
                    try {
                        mappers[i] = mclasses[i].newInstance();
                    } catch (Throwable t) {
                        throw new PersistenceException(t.getMessage());
                    }
                }
            }
        }
    }
    return getCacheWithSchema(forClass, entityName, primaryKey, schemaVersion == null ? "0" : schemaVersion,
            mappers);
}

From source file:com.web.server.EARDeployer.java

/**
 * This method configures the executor services from the jar file.
 * /*  w  ww  . ja v  a2  s  . c o m*/
 * @param jarFile
 * @param classList
 * @throws FileSystemException
 */
public void deployExecutorServicesEar(String earFileName, FileObject earFile,
        StandardFileSystemManager fsManager) throws FileSystemException {
    try {
        System.out.println("EARFILE NAMEs=" + earFileName);
        CopyOnWriteArrayList<FileObject> fileObjects = new CopyOnWriteArrayList<FileObject>();
        CopyOnWriteArrayList<FileObject> warObjects = new CopyOnWriteArrayList<FileObject>();
        ConcurrentHashMap jarClassListMap = new ConcurrentHashMap();
        CopyOnWriteArrayList<String> classList;
        obtainUrls(earFile, earFile, fileObjects, jarClassListMap, warObjects, fsManager);
        VFSClassLoader customClassLoaderBaseLib = new VFSClassLoader(
                fileObjects.toArray(new FileObject[fileObjects.size()]), fsManager,
                Thread.currentThread().getContextClassLoader());
        VFSClassLoader customClassLoader = null;
        Set keys = jarClassListMap.keySet();
        Iterator key = keys.iterator();
        FileObject jarFileObject;
        ConcurrentHashMap classLoaderPath = new ConcurrentHashMap();
        filesMap.put(earFileName, classLoaderPath);
        for (FileObject warFileObj : warObjects) {
            if (warFileObj.getName().getBaseName().endsWith(".war")) {
                //logger.info("filePath"+filePath);
                String filePath = scanDirectory + "/" + warFileObj.getName().getBaseName();
                log.info(filePath);
                String fileName = warFileObj.getName().getBaseName();
                WebClassLoader classLoader = new WebClassLoader(new URL[] {});
                log.info(classLoader);
                warDeployer.deleteDir(
                        new File(deployDirectory + "/" + fileName.substring(0, fileName.lastIndexOf(".war"))));
                new File(deployDirectory + "/" + fileName.substring(0, fileName.lastIndexOf(".war"))).mkdirs();
                log.info(deployDirectory + "/" + fileName.substring(0, fileName.lastIndexOf(".war")));
                urlClassLoaderMap.put(
                        deployDirectory + "/" + fileName.substring(0, fileName.lastIndexOf(".war")),
                        classLoader);
                classLoaderPath.put(warFileObj.getName().getBaseName(),
                        deployDirectory + "/" + fileName.substring(0, fileName.lastIndexOf(".war")));
                warDeployer.extractWar(new File(filePath), classLoader);

                if (exec != null) {
                    exec.shutdown();
                }
                new File(scanDirectory + "/" + warFileObj.getName().getBaseName()).delete();
                exec = Executors.newSingleThreadScheduledExecutor();
                exec.scheduleAtFixedRate(task, 0, 1000, TimeUnit.MILLISECONDS);
            }
        }
        for (int keyCount = 0; keyCount < keys.size(); keyCount++) {
            jarFileObject = (FileObject) key.next();
            {
                classList = (CopyOnWriteArrayList<String>) jarClassListMap.get(jarFileObject);
                customClassLoader = new VFSClassLoader(jarFileObject, fsManager, customClassLoaderBaseLib);
                this.urlClassLoaderMap.put(
                        scanDirectory + "/" + earFileName + "/" + jarFileObject.getName().getBaseName(),
                        customClassLoader);
                classLoaderPath.put(jarFileObject.getName().getBaseName(),
                        scanDirectory + "/" + earFileName + "/" + jarFileObject.getName().getBaseName());
                for (int classCount = 0; classCount < classList.size(); classCount++) {
                    String classwithpackage = classList.get(classCount).substring(0,
                            classList.get(classCount).indexOf(".class"));
                    classwithpackage = classwithpackage.replace("/", ".");
                    // System.out.println("classList:"+classwithpackage.replace("/","."));
                    try {
                        if (!classwithpackage.contains("$")) {

                            /*System.out.println("EARFILE NAME="+fileName);
                            System.out
                                  .println(scanDirectory
                            + "/"
                            + fileName
                            + "/"
                            + jarFileObject.getName()
                                  .getBaseName());
                                    
                            System.out.println(urlClassLoaderMap);*/
                            Class executorServiceClass = customClassLoader.loadClass(classwithpackage);

                            Annotation[] classServicesAnnot = executorServiceClass.getDeclaredAnnotations();

                            if (classServicesAnnot != null) {
                                for (int annotcount = 0; annotcount < classServicesAnnot.length; annotcount++) {
                                    if (classServicesAnnot[annotcount] instanceof RemoteCall) {
                                        RemoteCall remoteCall = (RemoteCall) classServicesAnnot[annotcount];
                                        //registry.unbind(remoteCall.servicename());
                                        System.out.println(remoteCall.servicename().trim());
                                        try {
                                            for (int count = 0; count < 2; count++) {
                                                RemoteInterface reminterface = (RemoteInterface) UnicastRemoteObject
                                                        .exportObject(
                                                                (Remote) executorServiceClass.newInstance(), 0);
                                                registry.rebind(remoteCall.servicename().trim(), reminterface);
                                            }
                                        } catch (Exception ex) {
                                            ex.printStackTrace();
                                        }
                                    }
                                }
                            }
                            // System.out.println(executorServiceClass.newInstance());
                            // System.out.println("executor class in ExecutorServicesConstruct"+executorServiceClass);
                            // System.out.println();
                            Method[] methods = executorServiceClass.getDeclaredMethods();
                            for (Method method : methods) {
                                Annotation[] annotations = method.getDeclaredAnnotations();
                                for (Annotation annotation : annotations) {
                                    if (annotation instanceof ExecutorServiceAnnot) {
                                        ExecutorServiceAnnot executorServiceAnnot = (ExecutorServiceAnnot) annotation;
                                        ExecutorServiceInfo executorServiceInfo = new ExecutorServiceInfo();
                                        executorServiceInfo.setExecutorServicesClass(executorServiceClass);
                                        executorServiceInfo.setMethod(method);
                                        executorServiceInfo.setMethodParams(method.getParameterTypes());
                                        //                              System.out.println("serice name="
                                        //                                    + executorServiceAnnot
                                        //                                          .servicename());
                                        //                              System.out.println("method info="
                                        //                                    + executorServiceInfo);
                                        //                              System.out.println(method);
                                        // if(servicesMap.get(executorServiceAnnot.servicename())==null)throw
                                        // new Exception();
                                        executorServiceMap.put(executorServiceAnnot.servicename(),
                                                executorServiceInfo);
                                    }
                                }
                            }
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }
            jarFileObject.close();
        }
        for (FileObject fobject : fileObjects) {
            fobject.close();
        }
        System.out.println("Channel unlocked");
        earFile.close();
        fsManager.closeFileSystem(earFile.getFileSystem());
        // ClassLoaderUtil.closeClassLoader(customClassLoader);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:com.bstek.dorado.idesupport.initializer.CommonRuleTemplateInitializer.java

private void collectXmlNodeInfo(XmlNodeInfo xmlNodeInfo, Class<?> type) {
    XmlNode xmlNode = type.getAnnotation(XmlNode.class);
    if (xmlNode == null || ArrayUtils.indexOf(type.getDeclaredAnnotations(), xmlNode) < 0) {
        return;//  ww w .j  a  v a2  s . c  o  m
    }
    xmlNodeInfo.addSourceType(type);

    if (StringUtils.isNotEmpty(xmlNode.nodeName())) {
        xmlNodeInfo.setNodeName(xmlNode.nodeName());
    }
    if (StringUtils.isNotEmpty(xmlNode.label())) {
        xmlNodeInfo.setLabel(xmlNode.label());
    }
    if (StringUtils.isNotEmpty(xmlNode.icon())) {
        xmlNodeInfo.setIcon(xmlNode.icon());
    }
    if (StringUtils.isNotEmpty(xmlNode.definitionType())) {
        xmlNodeInfo.setDefinitionType(xmlNode.definitionType());
    }
    for (String implType : xmlNode.implTypes()) {
        if (StringUtils.isNotEmpty(implType)) {
            xmlNodeInfo.getImplTypes().add(implType);
        }
    }
    if (!xmlNodeInfo.isScopable() && xmlNode.scopable()) {
        xmlNodeInfo.setScopable(true);
    }
    if (!xmlNodeInfo.isInheritable() && xmlNode.inheritable()) {
        xmlNodeInfo.setInheritable(true);
    }
    if (!xmlNode.isPublic()) {
        xmlNodeInfo.setScope("protected");
    }

    int[] clientTypes = xmlNode.clientTypes();
    if (clientTypes != null) {
        if (clientTypes.length > 0) {
            xmlNodeInfo.setClientTypes(clientTypes);
        }
    }

    if (!xmlNodeInfo.isDeprecated() && xmlNode.deprecated()) {
        xmlNodeInfo.setDeprecated(true);
    }

    if (StringUtils.isNotEmpty(xmlNode.fixedProperties())) {
        Map<String, String> fixedProperties = xmlNodeInfo.getFixedProperties();
        for (String fixedProperty : StringUtils.split(xmlNode.fixedProperties(), ",;")) {
            int i = fixedProperty.indexOf('=');
            if (i > 0) {
                String property = fixedProperty.substring(0, i);
                fixedProperties.put(property, fixedProperty.substring(i + 1));
            }
        }
    }

    Map<String, XmlProperty> properties = xmlNodeInfo.getProperties();
    XmlProperty[] annotationProperties = xmlNode.properties();
    boolean hasPropertyAnnotation = false;
    if (annotationProperties.length == 1) {
        XmlProperty xmlProperty = annotationProperties[0];
        hasPropertyAnnotation = StringUtils.isNotEmpty(xmlProperty.propertyName())
                || StringUtils.isNotEmpty(xmlProperty.propertyType())
                || StringUtils.isNotEmpty(xmlProperty.parser());
    } else if (annotationProperties.length > 1) {
        hasPropertyAnnotation = true;
    }

    if (hasPropertyAnnotation) {
        for (XmlProperty xmlProperty : annotationProperties) {
            if (StringUtils.isEmpty(xmlProperty.propertyName())) {
                throw new IllegalArgumentException(
                        "@XmlProperty.propertyName undefined. [" + type.getName() + "]");
            }
            for (String property : StringUtils.split(xmlProperty.propertyName(), ",;")) {
                properties.put(property, xmlProperty);
            }
        }
    }

    Set<XmlSubNode> subNodes = xmlNodeInfo.getSubNodes();
    XmlSubNode[] annotationSubNodes = xmlNode.subNodes();
    boolean hasSubNodeAnnotation = (annotationSubNodes.length > 0);
    if (annotationSubNodes.length == 1) {
        XmlSubNode xmlSubNode = annotationSubNodes[0];
        hasSubNodeAnnotation = StringUtils.isNotEmpty(xmlSubNode.propertyName())
                || StringUtils.isNotEmpty(xmlSubNode.nodeName())
                || StringUtils.isNotEmpty(xmlSubNode.propertyType());
    }
    if (hasSubNodeAnnotation) {
        for (XmlSubNode xmlSubNode : annotationSubNodes) {
            if (!(StringUtils.isNotEmpty(xmlSubNode.propertyType())
                    || (StringUtils.isNotEmpty(xmlSubNode.nodeName())
                            && StringUtils.isNotEmpty(xmlSubNode.parser())))) {
                throw new IllegalArgumentException(
                        "Neither @XmlSubNode.propertyType nor @XmlSubNode.nodeName/@XmlSubNode.parser undefined. ["
                                + type.getName() + "]");
            }
            subNodes.add(xmlSubNode);
        }
    }
}

From source file:com.app.server.JarDeployer.java

/**
 * This method implements the jar deployer which configures the executor services. 
 * Frequently monitors the deploy directory and configures the executor services map 
 * once the jar is deployed in deploy directory and reconfigures if the jar is modified and 
 * placed in the deploy directory.// w w  w. java 2s  .c  o  m
 */
public void run() {

    StandardFileSystemManager fsManager = new StandardFileSystemManager();
    try {
        fsManager.init();
        DefaultFileReplicator replicator = new DefaultFileReplicator(new File(cacheDir));
        //fsManager.setReplicator(new PrivilegedFileReplicator(replicator));
        fsManager.setTemporaryFileStore(replicator);
    } catch (FileSystemException e2) {
        // TODO Auto-generated catch block
        e2.printStackTrace();
    }
    File file = new File(scanDirectory.split(";")[0]);
    File[] files = file.listFiles();
    CopyOnWriteArrayList<String> classList = new CopyOnWriteArrayList<String>();
    for (int i = 0; i < files.length; i++) {
        if (files[i].isDirectory())
            continue;
        //Long lastModified=(Long) fileMap.get(files[i].getName());
        if (files[i].getName().endsWith(".jar")) {
            String filePath = files[i].getAbsolutePath();
            FileObject jarFile = null;
            try {
                jarFile = fsManager.resolveFile("jar:" + filePath);
            } catch (FileSystemException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            //logger.info("filePath"+filePath);
            filePath = filePath.substring(0, filePath.toLowerCase().lastIndexOf(".jar"));
            WebClassLoader customClassLoader = null;
            try {
                URLClassLoader loader = (URLClassLoader) ClassLoader.getSystemClassLoader();
                URL[] urls = loader.getURLs();
                try {
                    customClassLoader = new WebClassLoader(urls);
                    log.info(customClassLoader.geturlS());
                    customClassLoader.addURL(new URL("file:/" + files[i].getAbsolutePath()));
                    CopyOnWriteArrayList<String> jarList = new CopyOnWriteArrayList();
                    getUsersJars(new File(libDir), jarList);
                    for (String jarFilePath : jarList)
                        customClassLoader.addURL(new URL("file:/" + jarFilePath.replace("\\", "/")));
                    log.info("deploy=" + customClassLoader.geturlS());
                    this.urlClassLoaderMap.put(scanDirectory + "/" + files[i].getName(), customClassLoader);
                    jarsDeployed.add(files[i].getName());
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                log.info(urlClassLoaderMap);
                getChildren(jarFile, classList);
            } catch (FileSystemException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }

            for (int classCount = 0; classCount < classList.size(); classCount++) {
                String classwithpackage = classList.get(classCount).substring(0,
                        classList.get(classCount).indexOf(".class"));
                classwithpackage = classwithpackage.replace("/", ".");
                log.info("classList:" + classwithpackage.replace("/", "."));
                try {
                    if (!classwithpackage.contains("$")) {
                        Class executorServiceClass = customClassLoader.loadClass(classwithpackage);
                        //log.info("executor class in ExecutorServicesConstruct"+executorServiceClass);
                        //log.info();
                        if (!executorServiceClass.isInterface()) {
                            Annotation[] classServicesAnnot = executorServiceClass.getDeclaredAnnotations();
                            if (classServicesAnnot != null) {
                                for (int annotcount = 0; annotcount < classServicesAnnot.length; annotcount++) {
                                    if (classServicesAnnot[annotcount] instanceof RemoteCall) {
                                        RemoteCall remoteCall = (RemoteCall) classServicesAnnot[annotcount];
                                        //registry.unbind(remoteCall.servicename());
                                        log.info(remoteCall.servicename().trim());
                                        try {
                                            //for(int count=0;count<500;count++){
                                            RemoteInterface reminterface = (RemoteInterface) UnicastRemoteObject
                                                    .exportObject((Remote) executorServiceClass.newInstance(),
                                                            2004);
                                            registry.rebind(remoteCall.servicename().trim(), reminterface);
                                            //}
                                        } catch (Exception ex) {
                                            ex.printStackTrace();
                                        }
                                    }
                                }
                            }
                        }

                        Method[] methods = executorServiceClass.getDeclaredMethods();
                        for (Method method : methods) {
                            Annotation[] annotations = method.getDeclaredAnnotations();
                            for (Annotation annotation : annotations) {
                                if (annotation instanceof ExecutorServiceAnnot) {
                                    ExecutorServiceAnnot executorServiceAnnot = (ExecutorServiceAnnot) annotation;
                                    ExecutorServiceInfo executorServiceInfo = new ExecutorServiceInfo();
                                    executorServiceInfo.setExecutorServicesClass(executorServiceClass);
                                    executorServiceInfo.setMethod(method);
                                    executorServiceInfo.setMethodParams(method.getParameterTypes());
                                    //log.info("method="+executorServiceAnnot.servicename());
                                    //log.info("method info="+executorServiceInfo);
                                    //if(servicesMap.get(executorServiceAnnot.servicename())==null)throw new Exception();
                                    executorServiceMap.put(executorServiceAnnot.servicename(),
                                            executorServiceInfo);
                                }
                            }
                        }

                    }
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            ClassLoaderUtil.closeClassLoader(customClassLoader);
            try {
                jarFile.close();
            } catch (FileSystemException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            fsManager.closeFileSystem(jarFile.getFileSystem());
        }
    }
    fsManager.close();
    fsManager = new StandardFileSystemManager();
    try {
        DefaultFileReplicator replicator = new DefaultFileReplicator(new File(cacheDir));
        //fsManager.setReplicator(new PrivilegedFileReplicator(replicator));
        fsManager.setTemporaryFileStore(replicator);
    } catch (FileSystemException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    JarFileListener jarFileListener = new JarFileListener(executorServiceMap, libDir, urlClassLoaderMap,
            jarsDeployed);
    DefaultFileMonitor fm = new DefaultFileMonitor(jarFileListener);
    jarFileListener.setFm(fm);
    FileObject listendir = null;
    String[] dirsToScan = scanDirectory.split(";");
    try {
        FileSystemOptions opts = new FileSystemOptions();
        FtpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, true);
        fsManager.init();
        for (String dir : dirsToScan) {
            if (dir.startsWith("ftp://")) {
                listendir = fsManager.resolveFile(dir, opts);
            } else {
                listendir = fsManager.resolveFile(dir);
            }
            fm.addFile(listendir);
        }
    } catch (FileSystemException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    fm.setRecursive(true);
    fm.setDelay(3000);
    fm.start();
    //fsManager.close();
}

From source file:com.web.server.JarDeployer.java

/**
 * This method implements the jar deployer which configures the executor services. 
 * Frequently monitors the deploy directory and configures the executor services map 
 * once the jar is deployed in deploy directory and reconfigures if the jar is modified and 
 * placed in the deploy directory./* w  w  w  .  j  ava  2  s.c  om*/
 */
public void run() {

    StandardFileSystemManager fsManager = new StandardFileSystemManager();
    try {
        fsManager.init();
        DefaultFileReplicator replicator = new DefaultFileReplicator(new File(cacheDir));
        //fsManager.setReplicator(new PrivilegedFileReplicator(replicator));
        fsManager.setTemporaryFileStore(replicator);
    } catch (FileSystemException e2) {
        // TODO Auto-generated catch block
        e2.printStackTrace();
    }
    File file = new File(scanDirectory.split(";")[0]);
    File[] files = file.listFiles();
    CopyOnWriteArrayList<String> classList = new CopyOnWriteArrayList<String>();
    for (int i = 0; i < files.length; i++) {
        if (files[i].isDirectory())
            continue;
        //Long lastModified=(Long) fileMap.get(files[i].getName());
        if (files[i].getName().endsWith(".jar")) {
            String filePath = files[i].getAbsolutePath();
            FileObject jarFile = null;
            try {
                jarFile = fsManager.resolveFile("jar:" + filePath);
            } catch (FileSystemException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            //logger.info("filePath"+filePath);
            filePath = filePath.substring(0, filePath.toLowerCase().lastIndexOf(".jar"));
            WebClassLoader customClassLoader = null;
            try {
                URLClassLoader loader = (URLClassLoader) ClassLoader.getSystemClassLoader();
                URL[] urls = loader.getURLs();
                try {
                    customClassLoader = new WebClassLoader(urls);
                    System.out.println(customClassLoader.geturlS());
                    new WebServer().addURL(new URL("file:/" + files[i].getAbsolutePath()), customClassLoader);
                    CopyOnWriteArrayList<String> jarList = new CopyOnWriteArrayList();
                    getUsersJars(new File(libDir), jarList);
                    for (String jarFilePath : jarList)
                        new WebServer().addURL(new URL("file:/" + jarFilePath.replace("\\", "/")),
                                customClassLoader);
                    System.out.println("deploy=" + customClassLoader.geturlS());
                    this.urlClassLoaderMap.put(scanDirectory + "/" + files[i].getName(), customClassLoader);
                    jarsDeployed.add(files[i].getName());
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                System.out.println(urlClassLoaderMap);
                getChildren(jarFile, classList);
            } catch (FileSystemException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }

            for (int classCount = 0; classCount < classList.size(); classCount++) {
                String classwithpackage = classList.get(classCount).substring(0,
                        classList.get(classCount).indexOf(".class"));
                classwithpackage = classwithpackage.replace("/", ".");
                System.out.println("classList:" + classwithpackage.replace("/", "."));
                try {
                    if (!classwithpackage.contains("$")) {
                        Class executorServiceClass = customClassLoader.loadClass(classwithpackage);
                        //System.out.println("executor class in ExecutorServicesConstruct"+executorServiceClass);
                        //System.out.println();
                        if (!executorServiceClass.isInterface()) {
                            Annotation[] classServicesAnnot = executorServiceClass.getDeclaredAnnotations();
                            if (classServicesAnnot != null) {
                                for (int annotcount = 0; annotcount < classServicesAnnot.length; annotcount++) {
                                    if (classServicesAnnot[annotcount] instanceof RemoteCall) {
                                        RemoteCall remoteCall = (RemoteCall) classServicesAnnot[annotcount];
                                        //registry.unbind(remoteCall.servicename());
                                        System.out.println(remoteCall.servicename().trim());
                                        try {
                                            //for(int count=0;count<500;count++){
                                            RemoteInterface reminterface = (RemoteInterface) UnicastRemoteObject
                                                    .exportObject((Remote) executorServiceClass.newInstance(),
                                                            2004);
                                            registry.rebind(remoteCall.servicename().trim(), reminterface);
                                            //}
                                        } catch (Exception ex) {
                                            ex.printStackTrace();
                                        }
                                    }
                                }
                            }
                        }

                        Method[] methods = executorServiceClass.getDeclaredMethods();
                        for (Method method : methods) {
                            Annotation[] annotations = method.getDeclaredAnnotations();
                            for (Annotation annotation : annotations) {
                                if (annotation instanceof ExecutorServiceAnnot) {
                                    ExecutorServiceAnnot executorServiceAnnot = (ExecutorServiceAnnot) annotation;
                                    ExecutorServiceInfo executorServiceInfo = new ExecutorServiceInfo();
                                    executorServiceInfo.setExecutorServicesClass(executorServiceClass);
                                    executorServiceInfo.setMethod(method);
                                    executorServiceInfo.setMethodParams(method.getParameterTypes());
                                    //System.out.println("method="+executorServiceAnnot.servicename());
                                    //System.out.println("method info="+executorServiceInfo);
                                    //if(servicesMap.get(executorServiceAnnot.servicename())==null)throw new Exception();
                                    executorServiceMap.put(executorServiceAnnot.servicename(),
                                            executorServiceInfo);
                                }
                            }
                        }

                    }
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            ClassLoaderUtil.closeClassLoader(customClassLoader);
            try {
                jarFile.close();
            } catch (FileSystemException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            fsManager.closeFileSystem(jarFile.getFileSystem());
        }
    }
    fsManager.close();
    fsManager = new StandardFileSystemManager();
    try {
        DefaultFileReplicator replicator = new DefaultFileReplicator(new File(cacheDir));
        //fsManager.setReplicator(new PrivilegedFileReplicator(replicator));
        fsManager.setTemporaryFileStore(replicator);
    } catch (FileSystemException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    JarFileListener jarFileListener = new JarFileListener(executorServiceMap, libDir, urlClassLoaderMap,
            jarsDeployed);
    DefaultFileMonitor fm = new DefaultFileMonitor(jarFileListener);
    jarFileListener.setFm(fm);
    FileObject listendir = null;
    String[] dirsToScan = scanDirectory.split(";");
    try {
        FileSystemOptions opts = new FileSystemOptions();
        FtpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, true);
        fsManager.init();
        for (String dir : dirsToScan) {
            if (dir.startsWith("ftp://")) {
                listendir = fsManager.resolveFile(dir, opts);
            } else {
                listendir = fsManager.resolveFile(dir);
            }
            fm.addFile(listendir);
        }
    } catch (FileSystemException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    fm.setRecursive(true);
    fm.setDelay(3000);
    fm.start();
    //fsManager.close();
}

From source file:com.bstek.dorado.idesupport.initializer.CommonRuleTemplateInitializer.java

protected List<AutoChildTemplate> getChildTemplatesBySubNode(RuleTemplate ruleTemplate, TypeInfo typeInfo,
        String propertyName, XmlSubNode xmlSubNode, TypeInfo propertyTypeInfo,
        InitializerContext initializerContext) throws Exception {
    List<AutoChildTemplate> childTemplates = new ArrayList<AutoChildTemplate>();

    boolean aggregated = xmlSubNode.aggregated();
    Class<?> propertyType = null;
    if (propertyTypeInfo != null) {
        propertyType = propertyTypeInfo.getType();
        aggregated = propertyTypeInfo.isAggregated();
    }/*w  w w. j  a  va 2s .  c o m*/

    Set<Class<?>> implTypes = ClassUtils.findClassTypes(xmlSubNode.implTypes(), propertyType);
    for (Class<?> implType : implTypes) {
        if (implType.equals(typeInfo.getType())) {
            continue;
        }

        boolean isPublic = true;
        XmlNode implXmlNode = implType.getAnnotation(XmlNode.class);
        if (implXmlNode != null && ArrayUtils.indexOf(implType.getDeclaredAnnotations(), implXmlNode) >= 0
                && !implXmlNode.isPublic()) {
            if (ArrayUtils.indexOf(xmlSubNode.implTypes(), implType.getName()) < 0) {
                continue;
            } else {
                isPublic = false;
            }
        }

        AutoChildTemplate childTemplate = getChildNodeByBeanType(null, xmlSubNode, aggregated, implType,
                "protected", initializerContext);
        if (childTemplate != null) {
            childTemplate.setPublic(isPublic);
            childTemplates.add(childTemplate);
        }
    }

    if (propertyType != null) {
        XmlNode implXmlNode = propertyType.getAnnotation(XmlNode.class);
        if (implXmlNode == null || implXmlNode.isPublic()) {
            AutoChildTemplate childTemplate = getChildNodeByBeanType(StringUtils.capitalize(propertyName),
                    xmlSubNode, aggregated, propertyType, null, initializerContext);
            if (childTemplate != null) {
                childTemplates.add(childTemplate);
            }
        }
    }

    XmlNodeWrapper wrapper = xmlSubNode.wrapper();
    String wrapperName = wrapper.nodeName();
    if (StringUtils.isNotEmpty(wrapperName)) {
        List<AutoChildTemplate> wrapperTemplates = new ArrayList<AutoChildTemplate>();
        AutoRuleTemplate wrapperRuleTemplate = new AutoRuleTemplate("Wrapper." + wrapper.nodeName());
        wrapperRuleTemplate.setLabel(StringUtils.defaultIfEmpty(wrapper.label(), wrapper.nodeName()));
        if (StringUtils.isNotEmpty(wrapper.icon())) {
            wrapperRuleTemplate.setIcon(wrapper.icon());
        }
        wrapperRuleTemplate.setNodeName(wrapper.nodeName());
        for (ChildTemplate childTemplate : childTemplates) {
            wrapperRuleTemplate.addChild(childTemplate);
        }

        AutoChildTemplate wrapperChildTemplate = new AutoChildTemplate(wrapperName, wrapperRuleTemplate,
                xmlSubNode);
        wrapperChildTemplate.setFixed(wrapper.fixed());
        wrapperTemplates.add(wrapperChildTemplate);
        return wrapperTemplates;
    } else {
        return childTemplates;
    }
}

From source file:org.springframework.core.annotation.AnnotationUtils.java

/**
 * Perform the search algorithm for {@link #findAnnotation(Class, Class)},
 * avoiding endless recursion by tracking which annotations have already
 * been <em>visited</em>.//  w  w  w . j a  v  a  2  s .c  o m
 * @param clazz the class to look for annotations on
 * @param annotationType the type of annotation to look for
 * @param visited the set of annotations that have already been visited
 * @return the first matching annotation, or {@code null} if not found
 */
@Nullable
private static <A extends Annotation> A findAnnotation(Class<?> clazz, Class<A> annotationType,
        Set<Annotation> visited) {
    try {
        A annotation = clazz.getDeclaredAnnotation(annotationType);
        if (annotation != null) {
            return annotation;
        }
        for (Annotation declaredAnn : clazz.getDeclaredAnnotations()) {
            Class<? extends Annotation> declaredType = declaredAnn.annotationType();
            if (!isInJavaLangAnnotationPackage(declaredType) && visited.add(declaredAnn)) {
                annotation = findAnnotation(declaredType, annotationType, visited);
                if (annotation != null) {
                    return annotation;
                }
            }
        }
    } catch (Throwable ex) {
        handleIntrospectionFailure(clazz, ex);
        return null;
    }

    for (Class<?> ifc : clazz.getInterfaces()) {
        A annotation = findAnnotation(ifc, annotationType, visited);
        if (annotation != null) {
            return annotation;
        }
    }

    Class<?> superclass = clazz.getSuperclass();
    if (superclass == null || Object.class == superclass) {
        return null;
    }
    return findAnnotation(superclass, annotationType, visited);
}