List of usage examples for java.lang Class getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:org.jboss.processFlow.knowledgeService.BaseKnowledgeSessionBean.java
/****************************************************************************** * ************* WorkItemHandler Management *********/ public String printWorkItemHandlers() { StringBuilder sBuilder = new StringBuilder("Programmatically Loaded Work Item Handlers :"); for (String name : programmaticallyLoadedWorkItemHandlers.keySet()) { sBuilder.append("\n\t"); sBuilder.append(name);/*from ww w .jav a 2s. c o m*/ sBuilder.append(" : "); sBuilder.append(programmaticallyLoadedWorkItemHandlers.get(name)); } sBuilder.append("\nWork Item Handlers loaded from drools session template:"); SessionTemplate sTemplate = newSessionTemplate(null); if (sTemplate != null && (sTemplate.getWorkItemHandlers() != null)) { for (Map.Entry<?, ?> entry : sTemplate.getWorkItemHandlers().entrySet()) { Class wiClass = entry.getValue().getClass(); sBuilder.append("\n\t"); sBuilder.append(entry.getKey()); sBuilder.append(" : "); sBuilder.append(wiClass.getClass()); } } else { sBuilder.append("\n\tsessionTemplate not instantiated or is empty... check previous exceptions"); } sBuilder.append("\nConfiguration Loaded Work Item Handlers :"); SessionConfiguration ksConfig = (SessionConfiguration) KnowledgeBaseFactory .newKnowledgeSessionConfiguration(ksconfigProperties); try { Map<String, WorkItemHandler> wiHandlers = ksConfig.getWorkItemHandlers(); if (wiHandlers.size() == 0) { sBuilder.append("\n\t no work item handlers defined"); Properties badProps = createPropsFromDroolsSessionConf(); if (badProps == null) sBuilder.append("\n\tunable to locate " + DROOLS_SESSION_CONF_PATH); else sBuilder.append("\n\tlocated" + DROOLS_SESSION_CONF_PATH); } else { for (String name : wiHandlers.keySet()) { sBuilder.append("\n\t"); sBuilder.append(name); sBuilder.append(" : "); Class wiClass = wiHandlers.get(name).getClass(); sBuilder.append(wiClass); } } } catch (NullPointerException x) { sBuilder.append( "\n\tError intializing at least one of the configured work item handlers via drools.session.conf.\n\tEnsure all space delimited work item handlers listed in drools.session.conf exist on the classpath"); Properties badProps = createPropsFromDroolsSessionConf(); if (badProps == null) { sBuilder.append("\n\tunable to locate " + DROOLS_SESSION_CONF_PATH); } else { try { Enumeration badEnums = badProps.propertyNames(); while (badEnums.hasMoreElements()) { String handlerConfName = (String) badEnums.nextElement(); if (DROOLS_WORK_ITEM_HANDLERS.equals(handlerConfName)) { String[] badHandlerNames = ((String) badProps.get(handlerConfName)).split("\\s"); for (String badHandlerName : badHandlerNames) { sBuilder.append("\n\t\t"); sBuilder.append(badHandlerName); InputStream iStream = this.getClass() .getResourceAsStream("/META-INF/" + badHandlerName); if (iStream != null) { sBuilder.append("\t : found on classpath"); iStream.close(); } else { sBuilder.append("\t : NOT FOUND on classpath !!!!! "); } } } } } catch (Exception y) { y.printStackTrace(); } } } catch (org.mvel2.CompileException x) { sBuilder.append("\n\t located " + DROOLS_SESSION_CONF_PATH); sBuilder.append( "\n\t however, following ClassNotFoundException encountered when instantiating defined work item handlers : \n\t\t"); sBuilder.append(x.getLocalizedMessage()); } sBuilder.append("\n"); return sBuilder.toString(); }
From source file:com.hablutzel.cmdline.CommandLineApplication.java
/** * Validate a Method to be a command line option methods. * * Methods with more than 1 argument are not allowed. Methods with return types * other than boolean are not allowed. Methods that throw an exception other than * org.apache.commons.cli.CommandLineException are not allowed, * * @param method the method to validate/*from ww w .j a v a 2 s . c o m*/ * @param commandLineOption the options on that method * @return A new method helper for the method */ private CommandLineMethodHelper getHelperForCommandOption(Method method, CommandLineOption commandLineOption) throws CommandLineException { // Validate that the return type is a boolean or void if (!method.getReturnType().equals(Boolean.TYPE) && !method.getReturnType().equals(Void.TYPE)) { throw new CommandLineException( "For method " + method.getName() + ", the return type is not boolean or void"); } // Validate the exceptions throws by the method for (Class<?> clazz : method.getExceptionTypes()) { if (!clazz.equals(CommandLineException.class)) { throw new CommandLineException("For method " + method.getName() + ", there is an invalid exception class " + clazz.getName()); } } // In order to get ready to create the configuration instance, // we will need to know the command line option type // and the element type. Class<?> elementClass = null; MethodType methodType; Converter converter; // Get the parameters of the method. We'll use these to // determine what type of option we have - scalar, boolean, etc. Class<?> parameterClasses[] = method.getParameterTypes(); // See what the length tells us switch (parameterClasses.length) { case 0: methodType = MethodType.Boolean; converter = null; break; case 1: { // For a method with one argument, we have to look // more closely at the argument. It has to be a simple // scalar object, an array, or a list. Class<?> parameterClass = parameterClasses[0]; if (parameterClass.isArray()) { // For an array, we get the element class based on the // underlying component type methodType = MethodType.Array; elementClass = parameterClass.getComponentType(); } else if (List.class.isAssignableFrom(parameterClass)) { // For a list, we get the element class from the command // line options annotation methodType = MethodType.List; elementClass = commandLineOption.argumentType(); } else { // For a scalar, we get the element type from the // type of the parameter. methodType = MethodType.Scalar; elementClass = parameterClass.getClass(); } // Now that we have the element type, make sure it's convertable converter = ConvertUtils.lookup(String.class, elementClass); if (converter == null) { throw new CommandLineException("Cannot find a conversion from String to " + elementClass.getName() + " for method " + method.getName()); } break; } default: { // Other method types not allowed. throw new CommandLineException("Method " + method.getName() + " has too many arguments"); } } // Now we can return the configuration for this method return new CommandLineMethodHelper(method, methodType, elementClass, converter); }
From source file:org.unitime.commons.hibernate.util.HibernateUtil.java
public static void clearCache(Class persistentClass, boolean evictQueries) { _RootDAO dao = new _RootDAO(); org.hibernate.Session hibSession = dao.getSession(); SessionFactory hibSessionFactory = hibSession.getSessionFactory(); if (persistentClass == null) { for (Iterator i = hibSessionFactory.getAllClassMetadata().entrySet().iterator(); i.hasNext();) { Map.Entry entry = (Map.Entry) i.next(); String className = (String) entry.getKey(); ClassMetadata classMetadata = (ClassMetadata) entry.getValue(); try { hibSessionFactory.getCache().evictEntityRegion(Class.forName(className)); for (int j = 0; j < classMetadata.getPropertyNames().length; j++) { if (classMetadata.getPropertyTypes()[j].isCollectionType()) { try { hibSessionFactory.getCache().evictCollectionRegion( className + "." + classMetadata.getPropertyNames()[j]); } catch (MappingException e) { }/*from w ww . ja v a2s. c o m*/ } } } catch (ClassNotFoundException e) { } } hibSessionFactory.getCache().evictEntityRegions(); hibSessionFactory.getCache().evictCollectionRegions(); } else { ClassMetadata classMetadata = hibSessionFactory.getClassMetadata(persistentClass); hibSessionFactory.getCache().evictEntityRegion(persistentClass); if (classMetadata != null) { for (int j = 0; j < classMetadata.getPropertyNames().length; j++) { if (classMetadata.getPropertyTypes()[j].isCollectionType()) { try { hibSessionFactory.getCache().evictCollectionRegion(persistentClass.getClass().getName() + "." + classMetadata.getPropertyNames()[j]); } catch (MappingException e) { } } } } } if (evictQueries) { hibSessionFactory.getCache().evictQueryRegions(); hibSessionFactory.getCache().evictDefaultQueryRegion(); } }
From source file:org.kuali.ole.select.businessobject.inquiry.OlePersonRequestorInquirableImpl.java
@Override public AnchorHtmlData getInquiryUrlForPrimaryKeys(Class clazz, Object businessObject, List<String> primaryKeys, String displayText) {/*from ww w . j a va 2s. com*/ Map<String, String> fieldList = new HashMap<String, String>(); if (businessObject == null) { return new AnchorHtmlData(KRADConstants.EMPTY_STRING, KRADConstants.EMPTY_STRING); } Properties parameters = new Properties(); parameters.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.START_METHOD); OlePersonRequestor olePersonRequestor = (OlePersonRequestor) businessObject; if (olePersonRequestor.getInternalRequestorId() != null) { parameters.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, "org.kuali.rice.kim.api.identity.Person"); parameters.put("principalId", olePersonRequestor.getInternalRequestorId()); fieldList.put("principalId", olePersonRequestor.getInternalRequestorId()); } else if (olePersonRequestor.getExternalRequestorId() != null) { parameters.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, "org.kuali.ole.select.businessobject.OleRequestor"); parameters.put("requestorId", olePersonRequestor.getExternalRequestorId()); fieldList.put("requestorId", olePersonRequestor.getExternalRequestorId()); } else { parameters.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, clazz.getClass()); String titleAttributeValue; for (String primaryKey : primaryKeys) { titleAttributeValue = ObjectUtils.getPropertyValue(businessObject, primaryKey).toString(); parameters.put(primaryKey, titleAttributeValue); fieldList.put(primaryKey, titleAttributeValue); } } if (StringUtils.isEmpty(displayText)) { return getHyperLink(clazz, fieldList, UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, parameters)); } else { return getHyperLink(clazz, fieldList, UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, parameters), displayText); } }
From source file:org.mqnaas.core.impl.BindingManagement.java
@Override public void addResourceNode(ResourceNode resource, ApplicationNode managedBy, Class<? extends IApplication> parentInterface) { if (resource == null || managedBy == null || parentInterface == null) throw new NullPointerException( "Resource, application instance managing it, and the application interface are required to add a resource node."); log.trace("Adding resource node:[resourceNode=" + resource + ",managedBy=" + managedBy + ",parentInterface=" + parentInterface.getClass().getName() + "]"); // 1. Update the model ResourceCapabilityTreeController.addResourceNode(resource, managedBy, parentInterface); // 2. Notify this class about the addition // (it will attempt to bind available capabilities to the new resource) resourceAdded(resource, managedBy);// w ww . j a v a 2 s. c o m }
From source file:org.apache.hadoop.yarn.client.ClientRMProxy.java
@Private @Override/*from w w w. j a v a2 s .c om*/ protected InetSocketAddress getRMAddress(YarnConfiguration conf, Class<?> protocol) throws IOException { if (protocol == ApplicationClientProtocol.class) { return conf.getSocketAddr(YarnConfiguration.RM_ADDRESS, YarnConfiguration.DEFAULT_RM_ADDRESS, YarnConfiguration.DEFAULT_RM_PORT); } else if (protocol == ResourceManagerAdministrationProtocol.class) { return conf.getSocketAddr(YarnConfiguration.RM_ADMIN_ADDRESS, YarnConfiguration.DEFAULT_RM_ADMIN_ADDRESS, YarnConfiguration.DEFAULT_RM_ADMIN_PORT); } else if (protocol == ApplicationMasterProtocol.class) { setAMRMTokenService(conf); return conf.getSocketAddr(YarnConfiguration.RM_SCHEDULER_ADDRESS, YarnConfiguration.DEFAULT_RM_SCHEDULER_ADDRESS, YarnConfiguration.DEFAULT_RM_SCHEDULER_PORT); } else if (protocol == GroupMembership.class) { return conf.getSocketAddr(YarnConfiguration.RM_GROUP_MEMBERSHIP_ADDRESS, YarnConfiguration.DEFAULT_RM_GROUP_MEMBERSHIP_ADDRESS, YarnConfiguration.DEFAULT_RM_GROUP_MEMBERSHIP_PORT); } else { String message = "Unsupported protocol found when creating the proxy " + "connection to ResourceManager: " + ((protocol != null) ? protocol.getClass().getName() : "null"); LOG.error(message); throw new IllegalStateException(message); } }
From source file:org.dozer.util.ReflectionUtils.java
public static DeepHierarchyElement[] getDeepFieldHierarchy(Class<?> parentClass, String field, HintContainer deepIndexHintContainer) { if (!MappingUtils.isDeepMapping(field)) { MappingUtils.throwMappingException("Field does not contain deep field delimitor"); }//from w w w . j av a 2 s. c o m StringTokenizer toks = new StringTokenizer(field, DozerConstants.DEEP_FIELD_DELIMITER); Class<?> latestClass = parentClass; DeepHierarchyElement[] hierarchy = new DeepHierarchyElement[toks.countTokens()]; int index = 0; int hintIndex = 0; while (toks.hasMoreTokens()) { String aFieldName = toks.nextToken(); String theFieldName = aFieldName; int collectionIndex = -1; if (aFieldName.contains("[")) { theFieldName = aFieldName.substring(0, aFieldName.indexOf("[")); collectionIndex = Integer .parseInt(aFieldName.substring(aFieldName.indexOf("[") + 1, aFieldName.indexOf("]"))); } PropertyDescriptor propDescriptor = findPropertyDescriptor(latestClass, theFieldName, deepIndexHintContainer); DeepHierarchyElement r = new DeepHierarchyElement(propDescriptor, collectionIndex); if (propDescriptor == null) { MappingUtils .throwMappingException("Exception occurred determining deep field hierarchy for Class --> " + parentClass.getName() + ", Field --> " + field + ". Unable to determine property descriptor for Class --> " + latestClass.getName() + ", Field Name: " + aFieldName); } latestClass = propDescriptor.getPropertyType(); if (toks.hasMoreTokens()) { if (latestClass.isArray()) { latestClass = latestClass.getComponentType(); } else if (Collection.class.isAssignableFrom(latestClass)) { Class<?> genericType = determineGenericsType(parentClass.getClass(), propDescriptor); if (genericType == null && deepIndexHintContainer == null) { MappingUtils.throwMappingException( "Hint(s) or Generics not specified. Hint(s) or Generics must be specified for deep mapping with indexed field(s). Exception occurred determining deep field hierarchy for Class --> " + parentClass.getName() + ", Field --> " + field + ". Unable to determine property descriptor for Class --> " + latestClass.getName() + ", Field Name: " + aFieldName); } if (genericType != null) { latestClass = genericType; } else { latestClass = deepIndexHintContainer.getHint(hintIndex); hintIndex += 1; } } } hierarchy[index++] = r; } return hierarchy; }
From source file:org.helios.jzab.agent.net.active.ActiveClient.java
/** * Modifies the passed channel's pipeline to handle a request response * @param channel The channel to modify the pipeline for * @param result A reference container for the result * @param exception A reference container for any thrown exception * @return the modified channel/*from w w w. j a v a2 s .c o m*/ */ protected <T> Channel modfyRequestResponseChannel(Channel channel, final Class<T> responseType, final AtomicReference<T> result, final AtomicReference<Throwable> exception) { channel.getPipeline().remove("routingHandler1"); channel.getPipeline().remove("routingHandler2"); channel.getPipeline().addAfter("responseDecoder", "requestResponseHandler", new SimpleChannelUpstreamHandler() { @Override public void messageReceived(ChannelHandlerContext ctx, final MessageEvent e) throws Exception { final Object response = e.getMessage(); try { result.set(responseType.cast(response)); } catch (Exception ex) { exception.set(new Exception("Incompatible Result Type [" + response == null ? "<null>" : response.getClass().getName() + "] but was expecting [" + responseType.getClass().getName() + "]", ex)); } super.messageReceived(ctx, e); } @Override public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception { exception.set(e.getCause()); } }); return channel; }
From source file:org.apache.hadoop.yarn.client.ClientRMProxy.java
protected InetSocketAddress getRMAddress(YarnConfiguration conf, Class<?> protocol, String host) throws IOException { if (protocol == ApplicationClientProtocol.class) { return conf.getSocketAddr(YarnConfiguration.RM_ADDRESS, YarnConfiguration.DEFAULT_RM_ADDRESS, YarnConfiguration.DEFAULT_RM_PORT, host); } else if (protocol == ResourceManagerAdministrationProtocol.class) { return conf.getSocketAddr(YarnConfiguration.RM_ADMIN_ADDRESS, YarnConfiguration.DEFAULT_RM_ADMIN_ADDRESS, YarnConfiguration.DEFAULT_RM_ADMIN_PORT, host); } else if (protocol == ApplicationMasterProtocol.class) { setAMRMTokenService(conf);/*from ww w.j av a 2s . co m*/ return conf.getSocketAddr(YarnConfiguration.RM_SCHEDULER_ADDRESS, YarnConfiguration.DEFAULT_RM_SCHEDULER_ADDRESS, YarnConfiguration.DEFAULT_RM_SCHEDULER_PORT, host); } else if (protocol == GroupMembership.class) { return conf.getSocketAddr(YarnConfiguration.RM_GROUP_MEMBERSHIP_ADDRESS, YarnConfiguration.DEFAULT_RM_GROUP_MEMBERSHIP_ADDRESS, YarnConfiguration.DEFAULT_RM_GROUP_MEMBERSHIP_PORT, host); } else { String message = "Unsupported protocol found when creating the proxy " + "connection to ResourceManager: " + ((protocol != null) ? protocol.getClass().getName() : "null"); LOG.error(message); throw new IllegalStateException(message); } }
From source file:com.github.dozermapper.core.util.ReflectionUtils.java
public static DeepHierarchyElement[] getDeepFieldHierarchy(Class<?> parentClass, String field, HintContainer deepIndexHintContainer) { if (!MappingUtils.isDeepMapping(field)) { MappingUtils.throwMappingException("Field does not contain deep field delimitor"); }/*from w ww .j a v a 2 s . c o m*/ StringTokenizer toks = new StringTokenizer(field, DozerConstants.DEEP_FIELD_DELIMITER); Class<?> latestClass = parentClass; DeepHierarchyElement[] hierarchy = new DeepHierarchyElement[toks.countTokens()]; int index = 0; int hintIndex = 0; while (toks.hasMoreTokens()) { String aFieldName = toks.nextToken(); String theFieldName = aFieldName; int collectionIndex = -1; if (aFieldName.contains("[")) { theFieldName = aFieldName.substring(0, aFieldName.indexOf("[")); collectionIndex = Integer .parseInt(aFieldName.substring(aFieldName.indexOf("[") + 1, aFieldName.indexOf("]"))); } PropertyDescriptor propDescriptor = findPropertyDescriptor(latestClass, theFieldName, deepIndexHintContainer); DeepHierarchyElement r = new DeepHierarchyElement(propDescriptor, collectionIndex); if (propDescriptor == null) { MappingUtils .throwMappingException("Exception occurred determining deep field hierarchy for Class --> " + parentClass.getName() + ", Field --> " + field + ". Unable to determine property descriptor for Class --> " + latestClass.getName() + ", Field Name: " + aFieldName); } latestClass = propDescriptor.getPropertyType(); if (toks.hasMoreTokens()) { if (latestClass.isArray()) { latestClass = latestClass.getComponentType(); } else if (Collection.class.isAssignableFrom(latestClass)) { Class<?> genericType = determineGenericsType(parentClass.getClass(), propDescriptor); if (genericType == null && deepIndexHintContainer == null) { MappingUtils.throwMappingException( "Hint(s) or Generics not specified. Hint(s) or Generics must be specified for deep mapping with indexed field(s). " + "Exception occurred determining deep field hierarchy for Class --> " + parentClass.getName() + ", Field --> " + field + ". Unable to determine property descriptor for Class --> " + latestClass.getName() + ", Field Name: " + aFieldName); } if (genericType != null) { latestClass = genericType; } else { latestClass = deepIndexHintContainer.getHint(hintIndex); hintIndex += 1; } } } hierarchy[index++] = r; } return hierarchy; }