List of usage examples for java.lang Class getInterfaces
public Class<?>[] getInterfaces()
From source file:org.rifidi.emulator.io.comm.ip.tcpserver.TCPServerCommunicationIncomingMessageHandler.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 ww w . j a v a 2 s. co m * 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 TCPServerCommunicationIncomingMessageHandler(TCPServerCommunication hostCommunication) { this.hostCommunication = hostCommunication; Class reader = hostCommunication.getAbstractStreamReader(); 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:it.openprj.jValidator.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 www .j a v a 2s. co 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"), "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); 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("it.openprj.jValidator.eventtrigger.EventTrigger")) { isValid = true; } } } else if (clazz.getSuperclass() != null && clazz.getSuperclass().getName() .equalsIgnoreCase("it.openprj.jValidator.eventtrigger.EventTriggerImpl")) { isValid = true; } } } if (isValid) { result = "Success"; } else { result = I18n.getMessage("error.trigger.wrongimpl");//"Failed. Reason: Custom code should implement it.openprj.jValidator.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:fr.putnami.pwt.core.service.server.service.BasicCommandService.java
@Override public void init(ServletConfig config) throws ServletException { super.init(config); String servicesParam = config.getInitParameter(BasicCommandService.PARAM_SERVICES); if (servicesParam != null) { String[] serviceToInstanciate = servicesParam.split(";"); if (serviceToInstanciate != null && serviceToInstanciate.length > 0) { for (String serviceName : serviceToInstanciate) { if (serviceName != null && serviceName.length() > 0) { try { this.getClass(); Class<?> serviceClass = Class.forName(serviceName); Object service = serviceClass.newInstance(); for (Class<?> serviceInterface : serviceClass.getInterfaces()) { this.injectService(serviceInterface, service); }// w w w. j a v a 2s .co m } catch (ClassNotFoundException e) { throw new ServletException("Can not load service class " + serviceName, e); } catch (InstantiationException e) { throw new ServletException("Can not instantiate service " + serviceName, e); } catch (IllegalAccessException e) { throw new ServletException("Can not instantiate service " + serviceName, e); } } } } } }
From source file:org.apache.sling.ide.eclipse.m2e.EmbeddedArchetypeInstaller.java
private void getClasses(Class<? extends Object> klazz, List<Class<?>> accu) { accu.add(klazz);/*from w ww . j a va 2s .c o m*/ for (Class<?> iface : klazz.getInterfaces()) { accu.add(iface); } }
From source file:org.kuali.rice.core.api.resourceloader.LazyResourceFactoryBean.java
protected Class<?>[] detectProxyInterfaces() { Class<?> type = getObjectType(); if (type != null && type.isInterface()) { return new Class<?>[] { type }; } else if (type != null) { return type.getInterfaces(); } else {/*from w ww.ja va2 s . c o m*/ return null; } }
From source file:edu.mayo.cts2.framework.core.xml.DelegatingMarshaller.java
/** * Gets the marshaller./* w w w . ja v a2 s . c om*/ * * @param clazz the clazz * @return the marshaller */ protected Marshaller getMarshaller(Class<?> clazz) { final Class<?>[] interfaces = clazz.getInterfaces(); if (interfaces != null) { for (Class<?> interfaze : interfaces) { if (this.marshallSuperClasses.contains(interfaze.getName())) { clazz = clazz.getSuperclass(); break; } } } String packageName = ClassUtils.getPackageName(clazz); Marshaller marshaller = this.packageToMarshallerMap.get(packageName); if (marshaller == null) { return this.defaultMarshaller; } else { return marshaller; } }
From source file:org.javaan.bytecode.ReflectionClassContextBuilder.java
private Type createTypeFromClass(String className) { Type type = null;//from w ww .j av a 2s . c o m try { Class<?> clazz = Class.forName(className); if (clazz.isInterface()) { type = new Interface(className); Class<?>[] superInterfaces = clazz.getInterfaces(); addInterface((Interface) type, ClassUtils.convertClassesToClassNames(Arrays.asList(superInterfaces))); addMethods(type, clazz); } else { type = new Clazz(className); Class<?> superClass = clazz.getSuperclass(); String superClassName = (superClass == null) ? null : superClass.getName(); Class<?>[] implementedInterfaces = clazz.getInterfaces(); addClass((Clazz) type, superClassName, ClassUtils.convertClassesToClassNames(Arrays.asList(implementedInterfaces))); addMethods(type, clazz); } } catch (ClassNotFoundException e) { missingTypes.add(className); return null; } return type; }
From source file:com.bstek.dorado.data.type.manager.DefaultDataTypeManager.java
/** * ??DataType//from w w w . jav a2 s .c o m */ private Set<DataTypeWrapper> findMatchingDataTypeForInterface(Class<?> type) { Set<DataTypeWrapper> dtws = new HashSet<DataTypeWrapper>(); Class<?>[] interfaces = type.getInterfaces(); for (Class<?> interfaceType : interfaces) { DataTypeDefinition dataType = getDefinedDataTypeDefinition(interfaceType); if (dataType != null) { dtws.add(new DataTypeWrapper(dataType, interfaceType)); } else { dtws.addAll(findMatchingDataTypeForInterface(interfaceType)); } } return dtws; }
From source file:de.perdian.commons.i18n.polyglot.PolyglotImpl.java
private void appendInvocationInfos(Map<Method, PolyglotInvocationInfo> resultMap, Class<?> interfaceClass, PolyglotKeyGenerator keyGenerator) { Class<?>[] implementedInterfaces = interfaceClass.getInterfaces(); if (implementedInterfaces != null) { for (Class<?> implementedInterface : implementedInterfaces) { this.appendInvocationInfos(resultMap, implementedInterface, keyGenerator); }/*from w w w. ja va 2s . c om*/ } StringBuilder exceptionCollectionString = new StringBuilder(); Method[] interfaceMethods = interfaceClass.getMethods(); if (interfaceMethods != null) { for (Method interfaceMethod : interfaceMethods) { try { resultMap.put(interfaceMethod, this.createInvocationInfo(interfaceMethod, keyGenerator)); } catch (Exception e) { exceptionCollectionString.append("\n- ").append(interfaceMethod.getName()); exceptionCollectionString.append(": ").append(e.getMessage()); } } if (exceptionCollectionString.length() > 0) { StringBuilder exceptionString = new StringBuilder(); exceptionString.append("Analyzation of polyglot information for class '").append(interfaceClass) .append("' "); exceptionString.append("failed:").append(exceptionCollectionString); throw new IllegalArgumentException(exceptionString.toString()); } } }
From source file:org.apache.axis2.jaxws.runtime.description.marshal.impl.AnnotationBuilder.java
private static void addAnnotation(EndpointDescription endpointDesc, Class cls, Map<String, AnnotationDesc> map) { String className = cls.getCanonicalName(); if (map.get(className) == null) { AnnotationDesc desc = AnnotationDescImpl.create(cls); map.put(className, desc);// w ww. j a v a 2 s . c o m if (cls.isPrimitive()) { Class class2 = ClassUtils.getWrapperClass(cls); AnnotationDesc desc2 = AnnotationDescImpl.create(class2); map.put(class2.getCanonicalName(), desc2); } else { Class class2 = ClassUtils.getPrimitiveClass(cls); if (class2 != null) { AnnotationDesc desc2 = AnnotationDescImpl.create(class2); map.put(class2.getCanonicalName(), desc2); } } // Inspect the interfaces. This is done to pick up other // @XmlSeeAlso usages. Class[] interfaces = cls.getInterfaces(); if (interfaces != null) { for (int i = 0; i < interfaces.length; i++) { addAnnotation(endpointDesc, interfaces[i], map); } } } }