List of usage examples for java.lang Class getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:org.openehr.rm.binding.DADLBinding.java
/** * Return a map with name as the key and index of position as the value for * all parameters of the full constructor in the RMObject * //from www . j a v a 2s. c om * @param rmClass * @return */ private SortedMap<String, Attribute> attributeMap(Class rmClass) { SortedMap<String, Attribute> map = new TreeMap<String, Attribute>(); Constructor constructor = fullConstructor(rmClass); if (constructor == null) { throw new IllegalArgumentException("Unknown RM Class: " + rmClass.getClass().getCanonicalName()); } Annotation[][] annotations = constructor.getParameterAnnotations(); for (int i = 0; i < annotations.length; i++) { if (annotations[i].length == 0) { throw new IllegalArgumentException("missing annotation at position " + i); } Attribute attribute = (Attribute) annotations[i][0]; map.put(attribute.name(), attribute); } return map; }
From source file:org.shept.org.springframework.web.servlet.mvc.delegation.command.AssociationCommandFactory.java
/** * //from w ww.j a v a2 s . com * @see org.shept.org.springframework.web.servlet.mvc.delegation.command.CommandFactory#getCommand(org.shept.org.springframework.web.servlet.mvc.delegation.ComponentConfiguration, java.lang.Object, java.lang.String) * * @param model * @param jp * @param mth * @return */ @Override public Object getCommand(TargetConfiguration config, Object model) { if (model == null) { throw new ChainConfigurationException("Configuration error in '" + config.getChainNameDisplay() + "'. <Null> model is not allowed for associations"); } // param contains the subForm name that will be overriden if there is an relation defined String assoc = relation == null ? config.getTo().getBeanName() : relation; if (assoc != null && assoc.startsWith("get")) { assoc = relation.substring("get".length()); } String methodGetter = "get" + StringUtils.capitalize(assoc); Method mth = ReflectionUtils.findMethod(model.getClass(), methodGetter); if (mth == null) { return null; } Class<?> rt = Object.class; if (null != mth) { rt = mth.getReturnType(); } if (List.class.isAssignableFrom(rt)) { return createWrappedList(config, mth, model); } // TODO better checks for the different result conditions ... else if (Collection.class.isAssignableFrom(rt)) { throw new ChainConfigurationException("Collection types other than 'List' are currently not supported. " + "Type " + rt.getClass().toString() + " is not supported. Use List instead"); } // load a single entity object else { return createWrappedEntity(config, mth, model); } }
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. * // ww w. j a va 2s . c o 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 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: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 w w w.j a va 2s . com*/ * 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:atg.test.AtgDustCase.java
/** * @param configurationStagingLocation//from www . jav a 2 s . com * The location where the property file should be created. This * will also set the {@link AtgDustCase#configurationLocation}. * * @param nucleusComponentPath * Nucleus component path (e.g /Some/Service/Impl). * * @param clazz * The {@link Class} implementing the nucleus component specified * in previous argument. * * @throws IOException * If we have some File related errors */ protected final void createPropertyFile(final String configurationStagingLocation, final String nucleusComponentPath, final Class<?> clazz) throws IOException { this.configurationLocation = new File(configurationStagingLocation); FileUtil.createPropertyFile(nucleusComponentPath, configurationLocation, clazz.getClass(), new HashMap<String, String>()); }
From source file:io.coala.config.AbstractPropertyGetter.java
/** * @param valueType// ww w . j a v a 2 s. c o m * @return * @throws CoalaException if value was not configured nor any default was * set */ public <T> T getJSON(final Class<T> valueType) throws CoalaRuntimeException { final String value = get(); try { return JsonUtil.getJOM().readValue(value, valueType); } catch (final Throwable e) { throw CoalaExceptionFactory.UNMARSHAL_FAILED.createRuntime(e, value, valueType.getClass()); } }
From source file:org.kuali.rice.krad.criteria.CriteriaLookupDaoJpa.java
@Override public <T> GenericQueryResults<T> lookup(final Class<T> queryClass, final QueryByCriteria criteria, LookupCustomizer<T> customizer) { if (queryClass == null) { throw new IllegalArgumentException("queryClass is null"); }/*w w w . j av a 2 s . c o m*/ if (criteria == null) { throw new IllegalArgumentException("criteria is null"); } if (customizer == null) { throw new IllegalArgumentException("customizer is null"); } final Criteria parent = new Criteria(queryClass.getClass().getName()); if (criteria.getPredicate() != null) { addPredicate(criteria.getPredicate(), parent, customizer.getPredicateTransform()); } switch (criteria.getCountFlag()) { case ONLY: return forCountOnly(queryClass, criteria, parent); case NONE: return forRowResults(queryClass, criteria, parent, criteria.getCountFlag(), customizer.getResultTransform()); case INCLUDE: return forRowResults(queryClass, criteria, parent, criteria.getCountFlag(), customizer.getResultTransform()); default: throw new UnsupportedCountFlagException(criteria.getCountFlag()); } }
From source file:org.apache.hadoop.hdfs.NameNodeProxies.java
/** * Creates an explicitly non-HA-enabled proxy object. Most of the time you * don't want to use this, and should instead use {@link NameNodeProxies#createProxy}. * * @param conf the configuration object/*from w ww .j a v a2s . c o m*/ * @param nnAddr address of the remote NN to connect to * @param xface the IPC interface which should be created * @param ugi the user who is making the calls on the proxy object * @param withRetries certain interfaces have a non-standard retry policy * @param fallbackToSimpleAuth - set to true or false during this method to * indicate if a secure client falls back to simple auth * @return an object containing both the proxy and the associated * delegation token service it corresponds to * @throws IOException */ @SuppressWarnings("unchecked") public static <T> ProxyAndInfo<T> createNonHAProxy(Configuration conf, InetSocketAddress nnAddr, Class<T> xface, UserGroupInformation ugi, boolean withRetries, AtomicBoolean fallbackToSimpleAuth) throws IOException { Text dtService = SecurityUtil.buildTokenService(nnAddr); T proxy; if (xface == ClientProtocol.class) { proxy = (T) createNNProxyWithClientProtocol(nnAddr, conf, ugi, withRetries, fallbackToSimpleAuth); } else if (xface == NamenodeProtocol.class) { proxy = (T) createNNProxyWithNamenodeProtocol(nnAddr, conf, ugi, withRetries); } else if (xface == GetUserMappingsProtocol.class) { proxy = (T) createNNProxyWithGetUserMappingsProtocol(nnAddr, conf, ugi); } else if (xface == RefreshUserMappingsProtocol.class) { proxy = (T) createNNProxyWithRefreshUserMappingsProtocol(nnAddr, conf, ugi); } else if (xface == RefreshAuthorizationPolicyProtocol.class) { proxy = (T) createNNProxyWithRefreshAuthorizationPolicyProtocol(nnAddr, conf, ugi); } else if (xface == RefreshCallQueueProtocol.class) { proxy = (T) createNNProxyWithRefreshCallQueueProtocol(nnAddr, conf, ugi); } else { String message = "Unsupported protocol found when creating the proxy " + "connection to NameNode: " + ((xface != null) ? xface.getClass().getName() : "null"); LOG.error(message); throw new IllegalStateException(message); } return new ProxyAndInfo<T>(proxy, dtService); }
From source file:org.pentaho.hadoop.shim.cdh51.authentication.PropertyAuthenticationProviderParser.java
private void processPrefix(String prefix) { AuthenticationProvider provider = authenticationProviderInstantiator .instantiate(properties.getProperty(prefix + ".class")); if (provider != null) { for (Method method : provider.getClass().getMethods()) { if (method.getName().startsWith("set") && method.getName().length() >= 4 && method.getParameterTypes().length == 1) { String propName = prefix + "." + method.getName().substring(3, 4).toLowerCase(); if (method.getName().length() > 4) { propName += method.getName().substring(4); }//w w w . j a v a 2s.co m if (properties.containsKey(propName)) { String strValue = Encr.decryptPasswordOptionallyEncrypted(properties.getProperty(propName)); Object actualValue = null; Class<?> argType = method.getParameterTypes()[0]; if (argType.isPrimitive()) { argType = ClassUtils.primitiveToWrapper(argType); } if (argType == String.class) { actualValue = strValue; } else { Method valueOf = null; try { valueOf = argType.getMethod("valueOf", String.class); } catch (NoSuchMethodException e1) { logger.warn("Unable to find valueOf method on " + argType.getClass().getCanonicalName()); } if (valueOf != null && Modifier.isStatic(valueOf.getModifiers())) { try { actualValue = valueOf.invoke(null, strValue); } catch (Exception e) { logger.warn("Unable to convert string property " + propName + "(" + strValue + ") to " + argType.getClass().getCanonicalName() + " to invoke setter " + method.getName(), e); } } else { logger.warn("Could not find method to convert " + propName + "(" + strValue + ") to " + argType.getClass().getCanonicalName() + " (currently only primitives and their wrappers are supported)"); } } if (actualValue != null) { try { method.invoke(provider, actualValue); } catch (Exception e) { Throwable cause = e; if (e instanceof InvocationTargetException) { cause = e.getCause(); } logger.warn("Error invoking setter " + method.toString() + " with property " + propName + "(" + strValue + ")", cause); } } } } } manager.registerAuthenticationProvider(provider); } }
From source file:org.pentaho.hadoop.shim.mapr31.authentication.PropertyAuthenticationProviderParser.java
private void processPrefix(String prefix) { AuthenticationProvider provider = authenticationProviderInstantiator .instantiate(properties.getProperty(prefix + ".class")); if (provider != null) { for (Method method : provider.getClass().getMethods()) { if (method.getName().startsWith("set") && method.getName().length() >= 4 && method.getParameterTypes().length == 1) { String propName = prefix + "." + method.getName().substring(3, 4).toLowerCase(); if (method.getName().length() > 4) { propName += method.getName().substring(4); }//from w w w. j a va 2s .co m if (properties.containsKey(propName)) { String strValue = Encr.decryptPasswordOptionallyEncrypted(properties.getProperty(propName)); Object actualValue = null; Class<?> argType = method.getParameterTypes()[0]; if (argType.isPrimitive()) { argType = ClassUtils.primitiveToWrapper(argType); } if (argType == String.class) { actualValue = strValue; } else { Method valueOf = null; try { valueOf = argType.getMethod("valueOf", String.class); } catch (NoSuchMethodException e1) { logger.warn("Unable to find valueOf method on " + argType.getClass().getCanonicalName()); } if (valueOf != null && Modifier.isStatic(valueOf.getModifiers())) { try { actualValue = valueOf.invoke(null, strValue); } catch (Exception e) { logger.warn("Unable to convert string property " + propName + "(" + strValue + ") to " + argType.getClass().getCanonicalName() + " to invoke setter " + method.getName(), e); } } else { logger.warn("Could not find method to convert " + propName + "(" + strValue + ") to " + argType.getClass().getCanonicalName() + " (currently only primitives and their wrappers are supported)"); } } if (actualValue != null) { try { method.invoke(provider, strValue); } catch (Exception e) { Throwable cause = e; if (e instanceof InvocationTargetException) { cause = e.getCause(); } logger.warn("Error invoking setter " + method.toString() + " with property " + propName + "(" + strValue + ")", cause); } } } } } manager.registerAuthenticationProvider(provider); } }