/** * Constructs an instance with the incomplete annotation type and the name * of the element that's missing. * * @param annotationType * the annotation type. * @param elementName * the name of the incomplete element. */ public IncompleteAnnotationException( java.lang.Class annotationType, String elementName) : base("The element, "+elementName+", is not complete for the annotation "+annotationType.getName()+".") { //$NON-NLS-1$ this.annotationTypeJ = annotationType; this.elementNameJ = elementName; }
/** * Constructor that performs no validation. * Use <code>getInstance</code> if you want that. * * @param classToInstantiate the class to instantiate */ public InstantiateFactory(java.lang.Class classToInstantiate) : base() { iClassToInstantiate = classToInstantiate; iParamTypes = null; iArgs = null; findConstructor(); }
/** * Constructs a new {@code IllegalFormatConversionException} with the class * of the mismatched conversion and corresponding parameter. * * @param c * the class of the mismatched conversion. * @param arg * the corresponding parameter. */ public IllegalFormatConversionException(char c, java.lang.Class arg) { this.c = c; if (arg == null) { throw new java.lang.NullPointerException(); } this.arg = arg; }
/** * <p> * Constructs an instance with the bean's {@link Class} and a customizer * {@link Class}. The descriptor's {@link #getName()} is set as the * unqualified name of the <code>beanClass</code>. * </p> * * @param beanClass * The bean's Class. * @param customizerClass * The bean's customizer Class. */ public BeanDescriptor(java.lang.Class beanClass, java.lang.Class customizerClass) { if (beanClass == null) { throw new java.lang.NullPointerException(); } setName(getShortClassName(beanClass)); this.beanClass = beanClass; this.customizerClass = customizerClass; }
public java.lang.Class[] getParameterTypes() { ParameterInfo[] pi = this.delegateInstance.GetParameters(); java.lang.Class[] returnValue = new java.lang.Class[pi.Length]; for (int i = 0; i < pi.Length; i++) { returnValue[i] = new java.lang.Class(pi[i].ParameterType); } return returnValue; }
// Note: This can't be set to "void.class", since *that* is // defined to be "java.lang.Void.TYPE"; private static java.lang.Class lookupType() { java.lang.Class voidType = null; try { java.lang.reflect.Method method = new java.lang.Class(typeof(java.lang.Runnable)).getMethod("run", new Class[0]); //$NON-NLS-1$ voidType = method.getReturnType(); } catch (Exception e) { throw new RuntimeException(e); } return voidType; }
private bool allEnabled; // = false; /** * Adds the given {@code Permission} to this heterogeneous {@code * PermissionCollection}. The {@code permission} is stored in its * appropriate {@code PermissionCollection}. * * @param permission * the {@code Permission} to be added. * @throws SecurityException * if this collection's {@link #isReadOnly()} method returns * {@code true}. * @throws NullPointerException * if {@code permission} is {@code null}. */ public override void add(Permission permission) { if (isReadOnly()) { throw new java.lang.SecurityException("collection is read-only"); //$NON-NLS-1$ } if (permission == null) { throw new java.lang.NullPointerException("invalid null permission"); //$NON-NLS-1$ } java.lang.Class klass = permission.getClass(); PermissionCollection klassMates = (PermissionCollection)klasses .get(klass); if (klassMates == null) { lock (klasses) { klassMates = (PermissionCollection)klasses.get(klass); if (klassMates == null) { klassMates = permission.newPermissionCollection(); if (klassMates == null) { klassMates = new PermissionsHash(); } klasses.put(klass, klassMates); } } } klassMates.add(permission); if (klass == typeof(AllPermission).getClass()) { allEnabled = true; } }
public void setWriteMethod(java.lang.reflect.Method setter) {//throws IntrospectionException { if (setter != null) { int modifiers = setter.getModifiers(); if (!java.lang.reflect.Modifier.isPublic(modifiers)) { throw new IntrospectionException("Modifier for setter method should be public.");//Messages.getString("beans.05")); //$NON-NLS-1$ } java.lang.Class[] parameterTypes = setter.getParameterTypes(); if (parameterTypes.Length != 1) { throw new IntrospectionException("Number of parameters in setter method is not equal to 1.");//Messages.getString("beans.06")); //$NON-NLS-1$ } java.lang.Class parameterType = parameterTypes[0]; java.lang.Class propertyType = getPropertyType(); if (propertyType != null && !propertyType.equals(parameterType)) { throw new IntrospectionException("Parameter type in setter method does not corresponds to predefined.");//Messages.getString("beans.07")); //$NON-NLS-1$ } } this.setter = setter; }
/** * Converts the given value to the given type. First, reflection is * is used to find a public constructor declared by the given class * that takes one argument, which must be the precise type of the * given value. If such a constructor is found, a new object is * created by passing the given value to that constructor, and the * newly constructed object is returned.<P> * * If no such constructor exists, and the given type is a primitive * type, then the given value is converted to a string using its * {@link Object#toString() toString()} method, and that string is * parsed into the correct primitive type using, for instance, * {@link Integer#valueOf(String)} to convert the string into an * <code>int</code>.<P> * * If no special constructor exists and the given type is not a * primitive type, this method returns the original value. * * @param newType the type to convert the value to * @param value the value to convert * @return the converted value * @throws NumberFormatException if newType is a primitive type, and * the string representation of the given value cannot be converted * to that type * @throws InstantiationException if the constructor found with * reflection raises it * @throws InvocationTargetException if the constructor found with * reflection raises it * @throws IllegalAccessException never * @throws IllegalArgumentException never */ protected Object convertType(java.lang.Class newType, Object value) { //throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { // try call constructor java.lang.Class[] types = { value.getClass() }; try { java.lang.reflect.Constructor constructor = newType.getConstructor(types); Object[] arguments = { value }; return(constructor.newInstance(arguments)); } catch (java.lang.NoSuchMethodException) { // try using the transformers Transformer transformer = getTypeTransformer(newType); if (transformer != null) { return(transformer.transform(value)); } return(value); } }
// use SystemClassLoader to load class from system classpath internal static Object getInstanceByClass(String className) { try { java.lang.Class clazz = java.lang.ClassLoader.getSystemClassLoader().loadClass(className); return(clazz.newInstance()); } catch (Exception e) { try { java.lang.Class clazz = java.lang.Thread.currentThread().getContextClassLoader().loadClass(className); return(clazz.newInstance()); } catch (Exception innerE) { // logging.20=Loading class "{0}" failed java.lang.SystemJ.err.println("Loading class " + className + " failed"); //$NON-NLS-1$ java.lang.SystemJ.err.println(innerE.ToString()); return(null); } } }
/** * Factory method that performs validation. * * @param classToInstantiate the class to instantiate, not null * @param paramTypes the constructor parameter types * @param args the constructor arguments * @return a new instantiate factory */ public static Factory getInstance(java.lang.Class classToInstantiate, java.lang.Class[] paramTypes, Object[] args) { if (classToInstantiate == null) { throw new java.lang.IllegalArgumentException("Class to instantiate must not be null"); } if (((paramTypes == null) && (args != null)) || ((paramTypes != null) && (args == null)) || ((paramTypes != null) && (args != null) && (paramTypes.Length != args.Length))) { throw new java.lang.IllegalArgumentException("Parameter types must match the arguments"); } if (paramTypes == null || paramTypes.Length == 0) { return(new InstantiateFactory(classToInstantiate)); } else { paramTypes = (java.lang.Class[])paramTypes.clone(); args = (Object[])args.clone(); return(new InstantiateFactory(classToInstantiate, paramTypes, args)); } }
//Basties note: not implemented methods following... public bool isWrapperFor(java.lang.Class clazz) { return(false); }
/// <summary> /// Create new Array of type with giving length /// </summary> /// <param name="type">type / classe</param> /// <param name="length">size of array</param> /// <returns></returns> public static Object newInstance(java.lang.Class clazz, int length) { return(System.Array.CreateInstance(clazz.GetType(), length)); }
public T getServiceProviderByClass <T>(java.lang.Class providerClass) { return(categories.getServiceProviderByClass <T>(providerClass)); }
public bool deregisterServiceProvider <T>(T provider, java.lang.Class category) { return(categories.removeProvider(provider, category)); }
internal T getServiceProviderByClass <T>(java.lang.Class providerClass) { return((T)providers.get(providerClass)); }
/** * Returns a typed list backed by the given list. * <p> * Only objects of the specified type can be added to the list. * * @param list the list to limit to a specific type, must not be null * @param type the type of objects which may be added to the list * @return a typed list backed by the specified list */ public static java.util.List <Object> typedList(java.util.List <Object> list, java.lang.Class type) { return(TypedList.decorate(list, type)); }
/** * Clone this bean map using the following process: * * <ul> * <li>If there is no underlying bean, return a cloned BeanMap without a * bean. * * <li>Since there is an underlying bean, try to instantiate a new bean of * the same type using Class.newInstance(). * * <li>If the instantiation fails, throw a CloneNotSupportedException * * <li>Clone the bean map and set the newly instantiated bean as the * underlying bean for the bean map. * * <li>Copy each property that is both readable and writable from the * existing object to a cloned bean map. * * <li>If anything fails along the way, throw a * CloneNotSupportedException. * * <ul> */ public Object clone() {//throws CloneNotSupportedException { BeanMap newMap = (BeanMap)base.MemberwiseClone(); if (bean == null) { // no bean, just an empty bean map at the moment. return a newly // cloned and empty bean map. return(newMap); } Object newBean = null; java.lang.Class beanClass = null; try { beanClass = bean.getClass(); newBean = beanClass.newInstance(); } catch (Exception e) { // unable to instantiate throw new java.lang.CloneNotSupportedException ("Unable to instantiate the underlying bean \"" + beanClass.getName() + "\": " + e); } try { newMap.setBean(newBean); } catch (Exception exception) { throw new java.lang.CloneNotSupportedException ("Unable to set bean in the cloned bean map: " + exception); } try { // copy only properties that are readable and writable. If its // not readable, we can't get the value from the old map. If // its not writable, we can't write a value into the new map. java.util.Iterator <Object> readableKeys = readMethods.keySet().iterator(); while (readableKeys.hasNext()) { Object key = readableKeys.next(); if (getWriteMethod(key) != null) { newMap.put(key, get(key)); } } } catch (Exception exception) { throw new java.lang.CloneNotSupportedException ("Unable to copy bean values to cloned bean map: " + exception); } return(newMap); }
/** * Creates a map which decorates the given <code>map</code> and * maps keys to collections of type <code>collectionClass</code>. * * @param map the map to wrap * @param collectionClass the type of the collection class */ public static MultiValueMap decorate(java.util.Map <Object, Object> map, java.lang.Class collectionClass) { return(new MultiValueMap(map, new ReflectionFactory(collectionClass))); }
public ReflectionFactory(java.lang.Class clazz) { this.clazz = clazz; }
/* * Creates and returns a new instance of the implementation described by * this {@code Service}. * * @param constructorParameter * the parameter that is used by the constructor, or {@code * null} if the implementation does not declare a constructor * parameter. * @return a new instance of the implementation described by this * {@code Service}. * @throws NoSuchAlgorithmException * if the instance could not be constructed. * @throws InvalidParameterException * if the implementation does not support the specified * {@code constructorParameter}. */ public Object newInstance(Object constructorParameter) {//throws NoSuchAlgorithmException { if (implementation == null || !className.equals(lastClassName)) { java.lang.ClassLoader cl = provider.getClass() .getClassLoader(); if (cl == null) { cl = java.lang.ClassLoader.getSystemClassLoader(); } try { implementation = java.lang.Class.forName(className, true, cl); } catch (Exception e) { return(new NoSuchAlgorithmException( type + " " + algorithm + " implementation not found: " + e)); } lastClassName = className; } java.lang.Class[] parameterTypes = new java.lang.Class[1]; if (constructorParameter != null && !supportsParameter(constructorParameter)) { throw new InvalidParameterException(type + ": service cannot use the parameter"); //$NON-NLS-1$ } Object[] initargs = { constructorParameter }; try { if (type.equalsIgnoreCase("CertStore")) { //$NON-NLS-1$ parameterTypes[0] = java.lang.Class .forName("java.security.cert.CertStoreParameters"); //$NON-NLS-1$ } else if (type.equalsIgnoreCase("Configuration")) { parameterTypes[0] = java.lang.Class .forName("javax.security.auth.login.Configuration$Parameters"); } if (parameterTypes[0] == null) { if (constructorParameter == null) { return(implementation.newInstance()); } else { parameterTypes[0] = constructorParameter.getClass(); } } return(implementation.getConstructor(parameterTypes) .newInstance(initargs)); } catch (java.lang.Exception e) { throw new NoSuchAlgorithmException(type + " " + algorithm + " implementation not found: ", e); } }
/** * Creates and returns a new instance of the implementation described by * this {@code Service}. * * @param constructorParameter * the parameter that is used by the constructor, or {@code * null} if the implementation does not declare a constructor * parameter. * @return a new instance of the implementation described by this * {@code Service}. * @throws NoSuchAlgorithmException * if the instance could not be constructed. * @throws InvalidParameterException * if the implementation does not support the specified * {@code constructorParameter}. */ public Object newInstance(Object constructorParameter) { //throws NoSuchAlgorithmException { if (implementation == null || !className.equals(lastClassName)) { java.lang.ClassLoader cl = provider.getClass() .getClassLoader(); if (cl == null) { cl = java.lang.ClassLoader.getSystemClassLoader(); } try { implementation = java.lang.Class.forName(className, true, cl); } catch (Exception e) { return new NoSuchAlgorithmException( type + " " + algorithm + " implementation not found: " + e); } lastClassName = className; } java.lang.Class[] parameterTypes = new java.lang.Class[1]; if (constructorParameter != null && !supportsParameter(constructorParameter)) { throw new InvalidParameterException(type + ": service cannot use the parameter"); //$NON-NLS-1$ } Object[] initargs = { constructorParameter }; try { if (type.equalsIgnoreCase("CertStore")) { //$NON-NLS-1$ parameterTypes[0] = java.lang.Class .forName("java.security.cert.CertStoreParameters"); //$NON-NLS-1$ } else if (type.equalsIgnoreCase("Configuration")) { parameterTypes[0] = java.lang.Class .forName("javax.security.auth.login.Configuration$Parameters"); } if (parameterTypes[0] == null) { if (constructorParameter == null) { return implementation.newInstance(); } else { parameterTypes[0] = constructorParameter.getClass(); } } return implementation.getConstructor(parameterTypes) .newInstance(initargs); } catch (java.lang.Exception e) { throw new NoSuchAlgorithmException(type + " " + algorithm + " implementation not found: ", e); } }
/** * Returns a transformer for the given primitive type. * * @param aType the primitive type whose transformer to return * @return a transformer that will convert strings into that type, * or null if the given type is not a primitive type */ protected Transformer getTypeTransformer(java.lang.Class aType) { return((Transformer)defaultTransformers.get(aType)); }
public static java.util.Iterator <T> lookupProviders <T>(java.lang.Class providerClass, java.lang.ClassLoader loader) { return(new LookupProvidersIterator <T>(providerClass, loader)); }
public static java.lang.Class getClass(this System.Object t) { java.lang.Class clazz = new java.lang.Class(t.GetType()); return clazz; }
public static java.util.Iterator <T> lookupProviders <T>(java.lang.Class providerClass) { return(lookupProviders <T>(providerClass, java.lang.Thread.currentThread().getContextClassLoader())); }
/** * Returns a typed buffer backed by the given buffer. * <p> * Only elements of the specified type can be added to the buffer. * * @param buffer the buffer to predicate, must not be null * @param type the type to allow into the buffer, must not be null * @return a typed buffer * @throws IllegalArgumentException if the buffer or type is null */ public static Buffer typedBuffer(Buffer buffer, java.lang.Class type) { return(TypedBuffer.decorate(buffer, type)); }
public java.util.Iterator <T> getServiceProviders <T>(java.lang.Class category, bool useOrdering) { return((java.util.Iterator <T>)categories.getProviders(category, useOrdering)); }
public static java.lang.Class getClass(this System.Object t) { Type runtimeType = t.GetType(); Reflection.PropertyInfo propInfo = runtimeType.GetProperty("UnderlyingSystemType"); Type type = null == propInfo ? runtimeType : (Type)propInfo.GetValue(t, null); java.lang.Class clazz = null; if (loadedClasses.containsKey(type)) { clazz = loadedClasses.get(type); } else { clazz = new java.lang.Class(type); loadedClasses.put(type, clazz); } return clazz; }
public bool unsetOrdering <T>(java.lang.Class category, T firstProvider, T secondProvider) { return(categories.unsetOrdering(category, firstProvider, secondProvider)); }
/** * Factory method to create a typed bag. * <p> * If there are any elements already in the bag being decorated, they * are validated. * * @param bag the bag to decorate, must not be null * @param type the type to allow into the bag, must not be null * @return a new typed Bag * @throws IllegalArgumentException if bag or type is null * @throws IllegalArgumentException if the bag contains invalid elements */ public static Bag decorate(Bag bag, java.lang.Class type) { return(new PredicatedBag(bag, InstanceofPredicate.getInstance(type))); }
/** * Factory method to create a typed sorted set. * <p> * If there are any elements already in the set being decorated, they * are validated. * * @param set the set to decorate, must not be null * @param type the type to allow into the collection, must not be null * @throws IllegalArgumentException if set or type is null * @throws IllegalArgumentException if the set contains invalid elements */ public static java.util.SortedSet <Object> decorate(java.util.SortedSet <Object> set, java.lang.Class type) { return(new PredicatedSortedSet(set, InstanceofPredicate.getInstance(type))); }
/** * Factory method to create a typed list. * <p> * If there are any elements already in the list being decorated, they * are validated. * * @param list the list to decorate, must not be null * @param type the type to allow into the collection, must not be null * @throws IllegalArgumentException if list or type is null * @throws IllegalArgumentException if the list contains invalid elements */ public static java.util.List <Object> decorate(java.util.List <Object> list, java.lang.Class type) { return(new PredicatedList(list, InstanceofPredicate.getInstance(type))); }
/** * Factory to create the identity predicate. * * @param type the type to check for, may not be null * @return the predicate * @throws IllegalArgumentException if the class is null */ public static Predicate getInstance(java.lang.Class type) { return(getInstance(type.getDelegateInstance())); }
/** * Constructor that performs no validation. * Use <code>getInstance</code> if you want that. * * @param classToInstantiate the class to instantiate * @param paramTypes the constructor parameter types, not cloned * @param args the constructor arguments, not cloned */ public InstantiateFactory(java.lang.Class classToInstantiate, java.lang.Class[] paramTypes, Object[] args) : base() { iClassToInstantiate = classToInstantiate; iParamTypes = paramTypes; iArgs = args; findConstructor(); }
public T unwrap <T>(java.lang.Class iface) { throw new TinySQLException(); }
public void deregisterAll(java.lang.Class category) { categories.removeAll(category); }
/* * <p> * Constructs an instance with the bean's {@link Class}. The descriptor's * {@link #getName()} is set as the unqualified name of the * <code>beanClass</code>. * </p> * * @param beanClass * The bean's Class. */ public BeanDescriptor(java.lang.Class beanClass) : this(beanClass, null) { }
internal void addCategory(java.lang.Class category) { categories.put(category, new ProvidersMap()); }
/** * Factory method to create a typed list. * <p> * If there are any elements already in the buffer being decorated, they * are validated. * * @param buffer the buffer to decorate, must not be null * @param type the type to allow into the buffer, must not be null * @return a new typed Buffer * @throws IllegalArgumentException if buffer or type is null * @throws IllegalArgumentException if the buffer contains invalid elements */ public static Buffer decorate(Buffer buffer, java.lang.Class type) { return(new PredicatedBuffer(buffer, InstanceofPredicate.getInstance(type))); }
/** * Adds a permission to the collection. The first added permission must be a * subclass of BasicPermission, next permissions must be of the same class * as the first one. * * @see java.security.PermissionCollection#add(java.security.Permission) */ public override void add(Permission permission) { if (isReadOnly()) { throw new java.lang.SecurityException("collection is read-only"); //$NON-NLS-1$ } if (permission == null) { throw new java.lang.IllegalArgumentException("invalid null permission"); //$NON-NLS-1$ } java.lang.Class inClass = permission.getClass(); if (permClass != null) { if (permClass != inClass) { throw new java.lang.IllegalArgumentException("invalid permission: "+permission); } } else if( !(permission is BasicPermission)) { throw new java.lang.IllegalArgumentException("invalid permission: " + permission); } else { // this is the first element provided that another thread did not add lock (this) { if (permClass != null && inClass != permClass) { throw new java.lang.IllegalArgumentException("invalid permission: " + permission); } permClass = inClass; } } String name = permission.getName(); items.put(name, permission); allEnabled = allEnabled || (name.length() == 1 && '*' == name.charAt(0)); }