List of usage examples for java.lang Class getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:com.erinors.hpb.server.handler.UninitializedHibernateProxyHandler.java
@Override public Object clone(CloningContext context, Object object) { ///*from w w w.ja va2s. c o m*/ // Check if the object is an uninitialized hibernate proxy, return false otherwise // if (!(object instanceof HibernateProxy)) { return null; } HibernateProxy hibernateProxy = (HibernateProxy) object; LazyInitializer lazyInitializer = hibernateProxy.getHibernateLazyInitializer(); if (!lazyInitializer.isUninitialized()) { return null; } // // Check if the proxied object can be cloned // Class<?> persistentClass = lazyInitializer.getPersistentClass(); if (!HibernateProxyPojoSupport.class.isAssignableFrom(persistentClass)) { // TODO tesztet r throw new RuntimeException("Uninitialized hibernate proxy should implement " + HibernateProxyPojoSupport.class.getName() + " to be cloneable: " + persistentClass); } // // Clone // HibernateProxyPojoSupport result; try { Constructor<?> constructor = ClassUtils.getAccessibleInstanceConstructor(persistentClass); result = (HibernateProxyPojoSupport) constructor.newInstance(); } catch (Exception e) { throw new RuntimeException("Cannot instantiate: " + persistentClass.getClass(), e); } result.setUninitializedHibernateProxy(true); result.setUninitializedHibernateProxyId(lazyInitializer.getIdentifier()); context.addProcessedObject(object, result); return result; }
From source file:org.apache.hadoop.yarn.server.api.ServerRMProxy.java
@InterfaceAudience.Private @Override// ww w . ja v a 2 s. c o m protected InetSocketAddress getRMAddress(YarnConfiguration conf, Class<?> protocol) { if (protocol == ResourceTracker.class) { return conf.getSocketAddr(YarnConfiguration.RM_RESOURCE_TRACKER_ADDRESS, YarnConfiguration.DEFAULT_RM_RESOURCE_TRACKER_ADDRESS, YarnConfiguration.DEFAULT_RM_RESOURCE_TRACKER_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:com.cloudbees.plugins.credentials.CredentialsProvider.java
/** * Returns all credentials which are available to the specified {@link Authentication} * for use by the specified {@link Item}. * * @param type the type of credentials to get. * @param authentication the authentication. * @param item the item.//from w w w .jav a 2 s. c o m * @param domainRequirements the credential domains to match. * @param <C> the credentials type. * @return the list of credentials. * @since 1.5 */ @NonNull @SuppressWarnings("unused") // API entry point for consumers public static <C extends Credentials> List<C> lookupCredentials(@NonNull Class<C> type, @Nullable Item item, @Nullable Authentication authentication, @Nullable List<DomainRequirement> domainRequirements) { type.getClass(); // throw NPE if null if (item == null) { return lookupCredentials(type, Jenkins.getInstance(), authentication, domainRequirements); } if (item instanceof ItemGroup) { return lookupCredentials(type, (ItemGroup) item, authentication, domainRequirements); } authentication = authentication == null ? ACL.SYSTEM : authentication; domainRequirements = domainRequirements == null ? Collections.<DomainRequirement>emptyList() : domainRequirements; CredentialsResolver<Credentials, C> resolver = CredentialsResolver.getResolver(type); if (resolver != null) { LOGGER.log(Level.FINE, "Resolving legacy credentials of type {0} with resolver {1}", new Object[] { type, resolver }); final List<Credentials> originals = lookupCredentials(resolver.getFromClass(), item, authentication, domainRequirements); LOGGER.log(Level.FINE, "Original credentials for resolving: {0}", originals); return resolver.resolve(originals); } List<C> result = new ArrayList<C>(); Set<String> ids = new HashSet<String>(); for (CredentialsProvider provider : all()) { if (provider.isEnabled(item) && provider.isApplicable(type)) { try { for (C c : provider.getCredentials(type, item, authentication, domainRequirements)) { if (!(c instanceof IdCredentials) || ids.add(((IdCredentials) c).getId())) { // if IdCredentials, only add if we havent added already // if not IdCredentials, always add result.add(c); } } } catch (NoClassDefFoundError e) { LOGGER.log(Level.FINE, "Could not retrieve provider credentials from " + provider + " likely due to missing optional dependency", e); } } } Collections.sort(result, new CredentialsNameComparator()); return result; }
From source file:org.apache.hadoop.yarn.server.api.ServerRMProxy.java
protected InetSocketAddress getRMAddress(YarnConfiguration conf, Class<?> protocol, String host) { if (protocol == ResourceTracker.class) { return conf.getSocketAddr(YarnConfiguration.RM_RESOURCE_TRACKER_ADDRESS, YarnConfiguration.DEFAULT_RM_RESOURCE_TRACKER_ADDRESS, YarnConfiguration.DEFAULT_RM_RESOURCE_TRACKER_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 {// w ww . jav a 2s. c o m 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.cloudbees.plugins.credentials.CredentialsProvider.java
/** * Returns all credentials which are available to the specified {@link Authentication} * for use by the {@link Item}s in the specified {@link ItemGroup}. * * @param type the type of credentials to get. * @param itemGroup the item group. * @param authentication the authentication. * @param domainRequirements the credential domains to match. * @param <C> the credentials type. * @return the list of credentials./* w w w . j a v a2 s. c o m*/ * @since 1.5 */ @NonNull @SuppressWarnings({ "unchecked", "unused" }) // API entry point for consumers public static <C extends Credentials> List<C> lookupCredentials(@NonNull Class<C> type, @Nullable ItemGroup itemGroup, @Nullable Authentication authentication, @Nullable List<DomainRequirement> domainRequirements) { type.getClass(); // throw NPE if null // TODO switch to Jenkins.getInstance() once 2.0+ is the baseline Jenkins jenkins = Jenkins.getActiveInstance(); itemGroup = itemGroup == null ? jenkins : itemGroup; authentication = authentication == null ? ACL.SYSTEM : authentication; domainRequirements = domainRequirements == null ? Collections.<DomainRequirement>emptyList() : domainRequirements; CredentialsResolver<Credentials, C> resolver = CredentialsResolver.getResolver(type); if (resolver != null) { LOGGER.log(Level.FINE, "Resolving legacy credentials of type {0} with resolver {1}", new Object[] { type, resolver }); final List<Credentials> originals = lookupCredentials(resolver.getFromClass(), itemGroup, authentication, domainRequirements); LOGGER.log(Level.FINE, "Original credentials for resolving: {0}", originals); return resolver.resolve(originals); } List<C> result = new ArrayList<C>(); Set<String> ids = new HashSet<String>(); for (CredentialsProvider provider : all()) { if (provider.isEnabled(itemGroup) && provider.isApplicable(type)) { try { for (C c : provider.getCredentials(type, itemGroup, authentication, domainRequirements)) { if (!(c instanceof IdCredentials) || ids.add(((IdCredentials) c).getId())) { // if IdCredentials, only add if we havent added already // if not IdCredentials, always add result.add(c); } } } catch (NoClassDefFoundError e) { LOGGER.log(Level.FINE, "Could not retrieve provider credentials from " + provider + " likely due to missing optional dependency", e); } } } Collections.sort(result, new CredentialsNameComparator()); return result; }
From source file:com.cloudbees.plugins.credentials.CredentialsProvider.java
/** * A common requirement for plugins is to resolve a specific credential by id in the context of a specific run. * Given that the credential itself could be resulting from a build parameter expression and the complexities of * determining the scope of items from which the credential should be resolved in a chain of builds, this method * provides the correct answer.//from w w w . ja v a2s .c om * * @param id either the id of the credential to find or a parameter expression for the id. * @param type the type of credential to find. * @param run the {@link Run} defining the context within which to find the credential. * @param domainRequirements the domain requirements of the credential. * @param <C> the credentials type. * @return the credential or {@code null} if either the credential cannot be found or the user triggering the run * is not permitted to use the credential in the context of the run. * @since 1.16 */ @CheckForNull public static <C extends IdCredentials> C findCredentialById(@NonNull String id, @NonNull Class<C> type, @NonNull Run<?, ?> run, @Nullable List<DomainRequirement> domainRequirements) { id.getClass(); // throw NPE if null; type.getClass(); // throw NPE if null; run.getClass(); // throw NPE if null; // first we need to find out if this id is pre-selected or a parameter id = id.trim(); boolean isParameter = false; boolean isDefaultValue = false; if (id.startsWith("${") && id.endsWith("}")) { final ParametersAction action = run.getAction(ParametersAction.class); if (action != null) { final ParameterValue parameter = action.getParameter(id.substring(2, id.length() - 1)); if (parameter instanceof CredentialsParameterValue) { isParameter = true; isDefaultValue = ((CredentialsParameterValue) parameter).isDefaultValue(); id = ((CredentialsParameterValue) parameter).getValue(); } } } // non parameters or default parameter values can only come from the job's context if (!isParameter || isDefaultValue) { // we use the default authentication of the job as those are the only ones that can be configured // if a different strategy is in play it doesn't make sense to consider the run-time authentication // as you would have no way to configure it Authentication runAuth = CredentialsProvider.getDefaultAuthenticationOf(run.getParent()); List<C> candidates = new ArrayList<C>(); // we want the credentials available to the user the build is running as candidates.addAll( CredentialsProvider.lookupCredentials(type, run.getParent(), runAuth, domainRequirements)); // if that user can use the item's credentials, add those in too if (runAuth != ACL.SYSTEM && run.getACL().hasPermission(runAuth, CredentialsProvider.USE_ITEM)) { candidates.addAll(CredentialsProvider.lookupCredentials(type, run.getParent(), ACL.SYSTEM, domainRequirements)); } return CredentialsMatchers.firstOrNull(candidates, CredentialsMatchers.withId(id)); } // this is a parameter and not the default value, we need to determine who triggered the build final Map.Entry<User, Run<?, ?>> triggeredBy = triggeredBy(run); final Authentication a = triggeredBy == null ? Jenkins.ANONYMOUS : triggeredBy.getKey().impersonate(); List<C> candidates = new ArrayList<C>(); if (triggeredBy != null && run == triggeredBy.getValue() && run.getACL().hasPermission(a, CredentialsProvider.USE_OWN)) { // the user triggered this job directly and they are allowed to supply their own credentials, so // add those into the list. We do not want to follow the chain for the user's authentication // though, as there is no way to limit how far the passed-through parameters can be used candidates.addAll(CredentialsProvider.lookupCredentials(type, run.getParent(), a, domainRequirements)); } if (run.getACL().hasPermission(a, CredentialsProvider.USE_ITEM)) { // the triggering user is allowed to use the item's credentials, so add those into the list // we use the default authentication of the job as those are the only ones that can be configured // if a different strategy is in play it doesn't make sense to consider the run-time authentication // as you would have no way to configure it Authentication runAuth = CredentialsProvider.getDefaultAuthenticationOf(run.getParent()); // we want the credentials available to the user the build is running as candidates.addAll( CredentialsProvider.lookupCredentials(type, run.getParent(), runAuth, domainRequirements)); // if that user can use the item's credentials, add those in too if (runAuth != ACL.SYSTEM && run.getACL().hasPermission(runAuth, CredentialsProvider.USE_ITEM)) { candidates.addAll(CredentialsProvider.lookupCredentials(type, run.getParent(), ACL.SYSTEM, domainRequirements)); } } C result = CredentialsMatchers.firstOrNull(candidates, CredentialsMatchers.withId(id)); // if the run has not completed yet then we can safely assume that the credential is being used for this run // so we will track it's usage. We use isLogUpdated() as it could be used during post production return run.isLogUpdated() ? track(run, result) : result; }
From source file:org.apache.openjpa.persistence.validation.ValidatorImpl.java
/** * Validates a value based upon the constraints applied to a given class * attribute./*from w w w .ja v a 2 s . c o m*/ * @param <T> The instance type to base validation upon * @param arg0 The class of type T to validate * @param arg1 The property to validate * @param arg2 The property value to validate * @param event The event id * @return ValidationException if the validator produces one or more * constraint violations. */ @Override public <T> ValidationException validateValue(Class<T> arg0, String arg1, Object arg2, int event) { if (!isValidating(event)) return null; Set<ConstraintViolation<T>> violations = _validator.validateValue(arg0, arg1, arg2, getValidationGroup(event)); if (violations != null && violations.size() > 0) { return new ValidationException(new ConstraintViolationException( // A validation constraint failure occurred for // value "{2}" of property "{1}" in class "{0}". _loc.get("validate-value-failed", arg0.getClass().getName(), arg1, arg2.toString()) .getMessage(), (Set) violations), true); } return null; }
From source file:com.cloudbees.plugins.credentials.CredentialsProvider.java
/** * Returns a {@link ListBoxModel} of all credentials which are available to the specified {@link Authentication} * for use by the specified {@link Item}. * * @param type the type of credentials to get. * @param authentication the authentication. * @param item the item./* ww w. j a v a 2 s . c o m*/ * @param domainRequirements the credential domains to match. * @param matcher the additional filtering to apply to the credentials * @param <C> the credentials type. * @return the {@link ListBoxModel} of {@link IdCredentials#getId()} with the corresponding display names as * provided by {@link CredentialsNameProvider}. * @since 2.1.0 */ @NonNull public static <C extends IdCredentials> ListBoxModel listCredentials(@NonNull Class<C> type, @Nullable Item item, @Nullable Authentication authentication, @Nullable List<DomainRequirement> domainRequirements, @Nullable CredentialsMatcher matcher) { type.getClass(); // throw NPE if null if (item == null) { return listCredentials(type, Jenkins.getInstance(), authentication, domainRequirements, matcher); } if (item instanceof ItemGroup) { return listCredentials(type, (ItemGroup) item, authentication, domainRequirements, matcher); } authentication = authentication == null ? ACL.SYSTEM : authentication; domainRequirements = domainRequirements == null ? Collections.<DomainRequirement>emptyList() : domainRequirements; CredentialsResolver<Credentials, C> resolver = CredentialsResolver.getResolver(type); if (resolver != null && IdCredentials.class.isAssignableFrom(resolver.getFromClass())) { LOGGER.log(Level.FINE, "Listing legacy credentials of type {0} identified by resolver {1}", new Object[] { type, resolver }); return listCredentials((Class) resolver.getFromClass(), item, authentication, domainRequirements, matcher); } ListBoxModel result = new ListBoxModel(); Set<String> ids = new HashSet<String>(); for (CredentialsProvider provider : all()) { if (provider.isEnabled(item) && provider.isApplicable(type)) { try { for (ListBoxModel.Option option : provider.getCredentialIds(type, item, authentication, domainRequirements, matcher)) { if (ids.add(option.value)) { result.add(option); } } } catch (NoClassDefFoundError e) { LOGGER.log(Level.FINE, "Could not retrieve provider credentials from " + provider + " likely due to missing optional dependency", e); } } } Collections.sort(result, new ListBoxModelOptionComparator()); return result; }
From source file:com.cloudbees.plugins.credentials.CredentialsProvider.java
/** * Returns a {@link ListBoxModel} of all credentials which are available to the specified {@link Authentication} * for use by the {@link Item}s in the specified {@link ItemGroup}. * * @param type the type of credentials to get. * @param authentication the authentication. * @param itemGroup the item group. * @param domainRequirements the credential domains to match. * @param matcher the additional filtering to apply to the credentials * @param <C> the credentials type. * @return the {@link ListBoxModel} of {@link IdCredentials#getId()} with the corresponding display names as * provided by {@link CredentialsNameProvider}. * @since 2.1.0// w ww . j av a 2 s . c o m */ public static <C extends IdCredentials> ListBoxModel listCredentials(@NonNull Class<C> type, @Nullable ItemGroup itemGroup, @Nullable Authentication authentication, @Nullable List<DomainRequirement> domainRequirements, @Nullable CredentialsMatcher matcher) { type.getClass(); // throw NPE if null // TODO switch to Jenkins.getInstance() once 2.0+ is the baseline Jenkins jenkins = Jenkins.getActiveInstance(); itemGroup = itemGroup == null ? jenkins : itemGroup; authentication = authentication == null ? ACL.SYSTEM : authentication; domainRequirements = domainRequirements == null ? Collections.<DomainRequirement>emptyList() : domainRequirements; matcher = matcher == null ? CredentialsMatchers.always() : matcher; CredentialsResolver<Credentials, C> resolver = CredentialsResolver.getResolver(type); if (resolver != null && IdCredentials.class.isAssignableFrom(resolver.getFromClass())) { LOGGER.log(Level.FINE, "Listing legacy credentials of type {0} identified by resolver {1}", new Object[] { type, resolver }); return listCredentials((Class) resolver.getFromClass(), itemGroup, authentication, domainRequirements, matcher); } ListBoxModel result = new ListBoxModel(); Set<String> ids = new HashSet<String>(); for (CredentialsProvider provider : all()) { if (provider.isEnabled(itemGroup) && provider.isApplicable(type)) { try { for (ListBoxModel.Option option : provider.getCredentialIds(type, itemGroup, authentication, domainRequirements, matcher)) { if (ids.add(option.value)) { result.add(option); } } } catch (NoClassDefFoundError e) { LOGGER.log(Level.FINE, "Could not retrieve provider credentials from " + provider + " likely due to missing optional dependency", e); } } } Collections.sort(result, new ListBoxModelOptionComparator()); return result; }
From source file:com.github.helenusdriver.driver.StatementBuilder.java
/** * Gets all the column names defined for a given field based on the specified * POJO class. The field must be annotated with {@link Column} and be part of * a class hierarchy annotated as an entity. * * @author paouelle//from w w w. j a va 2 s . c o m * * @param <T> The type of POJO associated with the request. * * @param clazz the POJO class to get all the column names for * @param field the field to get all the column names for * @return a non-<code>null</code> set of all the column names the specified * field is annotated with * @throws NullPointerException if <code>clazz</code> or <code>name</code> * is <code>null</code> * @throws IllegalArgumentException if the field or its class are not properly * annotated or the field is not in a class that is the same or a base * class of the specified class */ public static <T> Set<String> getColumnNamesFor(Class<T> clazz, Field field) { org.apache.commons.lang3.Validate.notNull(clazz, "invalid null class"); org.apache.commons.lang3.Validate.notNull(field, "invalid null field name"); org.apache.commons.lang3.Validate.isTrue(field.getDeclaringClass().isAssignableFrom(clazz), "field '%s.%s' is not defined in the class hieriarchy of: %s", field.getDeclaringClass().getName(), field.getName(), clazz.getClass().getName()); return StatementManager.getManager().getColumnNamesFor(clazz, field); }