List of usage examples for java.lang Class getInterfaces
public Class<?>[] getInterfaces()
From source file:org.gradle.model.internal.manage.schema.ModelSchemaExtractor.java
public <T> void validateType(Class<T> type) { if (!type.isInterface()) { throw invalid(type, "must be defined as an interface"); }/*from ww w. j av a2s.co m*/ if (type.getInterfaces().length != 0) { throw invalid(type, "cannot extend other types"); } if (type.getTypeParameters().length != 0) { throw invalid(type, "cannot be a parameterized type"); } }
From source file:de.knurt.fam.plugin.DefaultPluginResolver.java
private boolean implementz(Class<?> clazz, String interfaceName) { boolean result = false; Class<?>[] interfaces = clazz.getInterfaces(); for (Class<?> interfaze : interfaces) { if (interfaze.getName().equals(interfaceName)) { result = true;//from w w w.j ava 2 s.co m break; } } return result; }
From source file:javazoom.jlgui.player.amp.playlist.PlaylistFactory.java
/** * Returns Playlist instantied from full qualified class name. *///from w ww .j a va 2 s . c om public Playlist getPlaylist() { if (_playlistInstance == null) { String classname = _config.getPlaylistClassName(); boolean interfaceFound = false; try { Class aClass = Class.forName(classname); Class superClass = aClass; // Looking for Playlist interface implementation. while (superClass != null) { Class[] interfaces = superClass.getInterfaces(); for (int i = 0; i < interfaces.length; i++) { if ((interfaces[i].getName()).equals("javazoom.jlgui.player.amp.playlist.Playlist")) { interfaceFound = true; break; } } if (interfaceFound == true) break; superClass = superClass.getSuperclass(); } if (interfaceFound == false) { log.error("Error : Playlist implementation not found in " + classname + " hierarchy"); } else { Class[] argsClass = new Class[] {}; Constructor c = aClass.getConstructor(argsClass); _playlistInstance = (Playlist) (c.newInstance(null)); log.info(classname + " loaded"); } } catch (Exception e) { log.error("Error : " + classname + " : " + e.getMessage()); } } return _playlistInstance; }
From source file:com.seer.datacruncher.spring.ExtraCheckCustomCodeValidator.java
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String code = request.getParameter("value"); String name = request.getParameter("name"); String addReq = request.getParameter("addReq"); //TODO: take the result message from "locale" String result = null;/*w w w .j av a2s . com*/ ObjectMapper mapper = new ObjectMapper(); ServletOutputStream out = null; response.setContentType("application/json"); out = response.getOutputStream(); if (StringUtils.isEmpty(code) || StringUtils.isEmpty(name)) { result = I18n.getMessage("error.extracheck.invaliddata"); } else { name = name.trim(); if (addReq.equalsIgnoreCase("true")) { ReadList list = checksTypeDao.findCustomCodeByName(name); if (list != null && CollectionUtils.isNotEmpty(list.getResults())) { result = I18n.getMessage("error.extracheck.name.alreadyexist"); out.write(mapper.writeValueAsBytes(result)); out.flush(); out.close(); return null; } } try { File sourceDir = new File(System.getProperty("java.io.tmpdir"), "DataCruncher/src"); sourceDir.mkdirs(); String classNamePack = name.replace('.', File.separatorChar); String srcFilePath = sourceDir + "" + File.separatorChar + classNamePack + ".java"; File sourceFile = new File(srcFilePath); if (sourceFile.exists()) { sourceFile.delete(); } FileUtils.writeStringToFile(new File(srcFilePath), code); DynamicClassLoader dynacode = DynamicClassLoader.getInstance(); dynacode.addSourceDir(sourceDir); CustomCodeValidator customCodeValidator = (CustomCodeValidator) dynacode .newProxyInstance(CustomCodeValidator.class, name); boolean isValid = false; if (customCodeValidator != null) { Class clazz = dynacode.getLoadedClass(name); if (clazz != null) { Class[] interfaces = clazz.getInterfaces(); if (ArrayUtils.isNotEmpty(interfaces)) { for (Class clz : interfaces) { if ((clz.getName().equalsIgnoreCase( "com.seer.datacruncher.utils.validation.SingleValidation"))) { isValid = true; } } } } } if (isValid) { result = "Success"; } else { result = I18n.getMessage("error.extracheck.wrongimpl"); } } catch (Exception e) { result = "Failed. Reason:" + e.getMessage(); } } out.write(mapper.writeValueAsBytes(result)); out.flush(); out.close(); return null; }
From source file:org.duracloud.account.db.util.security.impl.AnnotationParserImpl.java
private Class getAnnotatedInterface(Class annotationClass, Class targetClass) { if (hasAnnotatedMethods(annotationClass, targetClass)) { return targetClass; }//from w w w . ja v a 2 s.c om for (Class iface : targetClass.getInterfaces()) { if (hasAnnotatedMethods(annotationClass, iface)) { return iface; } } throw new DuraCloudRuntimeException( "No annotationMetadata found of " + annotationClass.getName() + " over " + targetClass.getName()); }
From source file:org.rifidi.emulator.io.comm.ip.tcpclient.TCPClientCommunicationIncomingMessageHandler.java
/** * Creates a TCPServerCommunicationIncomingMessageHandler which is bound to * the passed TCPServerCommunication. This constructor has default access so * that only tcpserver-package classes can create these. * //from w ww . j av a 2 s .c om * It also takes in a class which implements the AbstractStreamReader class * that is used to parse the bytes on the input socket in a way required by * the specific RFID reader being emulated. * * @param hostCommunication * The TCPServerCommunication this object is bound to. * @param reader * The AbstractStreamReader with an overridden read() method. */ @SuppressWarnings("unchecked") public TCPClientCommunicationIncomingMessageHandler(TCPClientCommunication hostCommunication) { this.hostCommunication = hostCommunication; // TODO Get AbstractStreamReader !!!! // Class reader = hostCommunication.getAbstractStreamReader(); Class reader = GenericByteStreamReader.class; Class[] interfaces = reader.getInterfaces(); boolean interfaceFound = false; for (Class i : interfaces) { if (i.equals(AbstractStreamReader.class)) { interfaceFound = true; } } if (interfaceFound) { this.readerClass = reader; } else { logger.error("Expected class that implemets AbstractStreamReader, but got class of type: " + reader.getClass()); throw (new RuntimeException( "Expected class that implemets AbstractStreamReader, but got class of type: " + reader.getClass())); } }
From source file:com.cloudera.impala.extdatasource.ExternalDataSourceExecutor.java
/** * @param jarPath The local path to the jar containing the ExternalDataSource. * @param className The name of the class implementing the ExternalDataSource. * @param apiVersionStr The API version the ExternalDataSource implements. * Must be a valid value of {@link ApiVersion}. */// w w w.j av a2s . c o m public ExternalDataSourceExecutor(String jarPath, String className, String apiVersionStr) throws ImpalaException { Preconditions.checkNotNull(jarPath); apiVersion_ = ApiVersion.valueOf(apiVersionStr); if (apiVersion_ == null) { throw new ImpalaRuntimeException("Invalid API version: " + apiVersionStr); } jarPath_ = jarPath; className_ = className; try { URL url = new File(jarPath).toURI().toURL(); URLClassLoader loader = URLClassLoader.newInstance(new URL[] { url }, getClass().getClassLoader()); Class<?> c = Class.forName(className, true, loader); if (!ArrayUtils.contains(c.getInterfaces(), apiVersion_.getApiInterface())) { throw new ImpalaRuntimeException( String.format("Class '%s' does not implement interface '%s' required for API version %s", className, apiVersion_.getApiInterface().getName(), apiVersionStr)); } Constructor<?> ctor = c.getConstructor(); dataSource_ = (ExternalDataSource) ctor.newInstance(); } catch (Exception ex) { throw new ImpalaRuntimeException(String.format( "Unable to load external data " + "source library from path=%s className=%s apiVersion=%s", jarPath, className, apiVersionStr), ex); } }
From source file:org.openehealth.ipf.modules.cda.builder.CDAR2MetaObjectGraphBuilder.java
/** * Reflect the attribute type and instanciate it properly from factory This * needs a revision if no factory is found: for generic Boolean, Real etc. * values// ww w. j av a2 s. co m */ @SuppressWarnings("unchecked") protected Object createAttributeByNameFromString(Class klass, String key, String value) { EClassImpl classifierImpl = (EClassImpl) ePackage.getEClassifier(klass.getInterfaces()[0].getSimpleName()); if (classifierImpl != null) { EList eList = classifierImpl.getEAllAttributes(); for (Object anEList : eList) { EAttributeImpl attrImpl = (EAttributeImpl) anEList; if (attrImpl.getName().equals(key)) { Class valueClass = attrImpl.getEAttributeType().getInstanceClass(); if (Enumerator.class.isAssignableFrom(valueClass)) { // create // enumeration // instance Object instance = ((CDAR2Factory) getMetaBuilder().getDefaultBuildNodeFactory()) .createFromString(attrImpl.basicGetEAttributeType(), value); return instance; } else if (boolean.class.isAssignableFrom(valueClass) || Boolean.class.isAssignableFrom(valueClass)) { return value; } else if (Number.class.isAssignableFrom(valueClass)) { // call // the // string // constructor return value; } } } return value; } else { return null; } }
From source file:com.seer.datacruncher.spring.EventTriggerValidator.java
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String code = request.getParameter("code"); String name = request.getParameter("name"); String addReq = request.getParameter("addReq"); String result = null;//from w w w. j a v a2 s .c o m ObjectMapper mapper = new ObjectMapper(); ServletOutputStream out = null; response.setContentType("application/json"); out = response.getOutputStream(); if (StringUtils.isEmpty(code) || StringUtils.isEmpty(name)) { result = I18n.getMessage("error.trigger.invaliddata");//"Failed. Reason:Invalid Data"; } else { name = name.trim(); if (addReq.equalsIgnoreCase("true")) { ReadList list = eventTriggerDao.findTriggersByName(name); if (list != null && CollectionUtils.isNotEmpty(list.getResults())) { result = I18n.getMessage("error.trigger.name.alreadyexist");//"Failed. Reason:Name alredy exist"; out.write(mapper.writeValueAsBytes(result)); out.flush(); out.close(); return null; } } try { File sourceDir = new File(System.getProperty("java.io.tmpdir"), "DataCruncher/src"); sourceDir.mkdirs(); String classNamePack = name.replace('.', File.separatorChar); String srcFilePath = sourceDir + "" + File.separatorChar + classNamePack + ".java"; File sourceFile = new File(srcFilePath); if (sourceFile.exists()) { sourceFile.delete(); } FileUtils.writeStringToFile(new File(srcFilePath), code); DynamicClassLoader dynacode = DynamicClassLoader.getInstance(); dynacode.addSourceDir(sourceDir); EventTrigger eventTrigger = (EventTrigger) dynacode.newProxyInstance(EventTrigger.class, name); boolean isValid = false; if (eventTrigger != null) { Class clazz = dynacode.getLoadedClass(name); if (clazz != null) { Class[] interfaces = clazz.getInterfaces(); if (ArrayUtils.isNotEmpty(interfaces)) { for (Class clz : interfaces) { if (clz.getName() .equalsIgnoreCase("com.seer.datacruncher.eventtrigger.EventTrigger")) { isValid = true; } } } else if (clazz.getSuperclass() != null && clazz.getSuperclass().getName() .equalsIgnoreCase("com.seer.datacruncher.eventtrigger.EventTriggerImpl")) { isValid = true; } } } if (isValid) { result = "Success"; } else { result = I18n.getMessage("error.trigger.wrongimpl");//"Failed. Reason: Custom code should implement com.seer.datacruncher.eventtrigger.EventTrigger Interface"; } } catch (Exception e) { result = "Failed. Reason:" + e.getMessage(); } } out.write(mapper.writeValueAsBytes(result)); out.flush(); out.close(); return null; }
From source file:it.openprj.jValidator.spring.ExtraCheckCustomCodeValidator.java
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String code = request.getParameter("value"); String name = request.getParameter("name"); String addReq = request.getParameter("addReq"); //TODO: take the result message from "locale" String result = null;/*from w w w.j a v a2s . c om*/ ObjectMapper mapper = new ObjectMapper(); ServletOutputStream out = null; response.setContentType("application/json"); out = response.getOutputStream(); if (StringUtils.isEmpty(code) || StringUtils.isEmpty(name)) { result = I18n.getMessage("error.extracheck.invaliddata"); } else { name = name.trim(); if (addReq.equalsIgnoreCase("true")) { ReadList list = checksTypeDao.findCustomCodeByName(name); if (list != null && CollectionUtils.isNotEmpty(list.getResults())) { result = I18n.getMessage("error.extracheck.name.alreadyexist"); out.write(mapper.writeValueAsBytes(result)); out.flush(); out.close(); return null; } } try { File sourceDir = new File(System.getProperty("java.io.tmpdir"), "jValidator/src"); sourceDir.mkdirs(); String classNamePack = name.replace('.', File.separatorChar); String srcFilePath = sourceDir + "" + File.separatorChar + classNamePack + ".java"; File sourceFile = new File(srcFilePath); if (sourceFile.exists()) { sourceFile.delete(); } FileUtils.writeStringToFile(new File(srcFilePath), code); DynamicClassLoader dynacode = DynamicClassLoader.getInstance(); dynacode.addSourceDir(sourceDir); CustomCodeValidator customCodeValidator = (CustomCodeValidator) dynacode .newProxyInstance(CustomCodeValidator.class, name); boolean isValid = false; if (customCodeValidator != null) { Class clazz = dynacode.getLoadedClass(name); if (clazz != null) { Class[] interfaces = clazz.getInterfaces(); if (ArrayUtils.isNotEmpty(interfaces)) { for (Class clz : interfaces) { if ((clz.getName().equalsIgnoreCase( "it.openprj.jValidator.utils.validation.SingleValidation"))) { isValid = true; } } } } } if (isValid) { result = "Success"; } else { result = I18n.getMessage("error.extracheck.wrongimpl"); } } catch (Exception e) { result = "Failed. Reason:" + e.getMessage(); } } out.write(mapper.writeValueAsBytes(result)); out.flush(); out.close(); return null; }