当前位置: 首页>>代码示例>>Java>>正文


Java MetadataException类代码示例

本文整理汇总了Java中org.apache.ojb.broker.metadata.MetadataException的典型用法代码示例。如果您正苦于以下问题:Java MetadataException类的具体用法?Java MetadataException怎么用?Java MetadataException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MetadataException类属于org.apache.ojb.broker.metadata包,在下文中一共展示了MetadataException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getValueFrom

import org.apache.ojb.broker.metadata.MetadataException; //导入依赖的package包/类
private Object getValueFrom(PropertyDescriptor pd, Object target)
{
    if (target == null) return null;
    Method m = pd.getReadMethod();
    if (m != null)
    {
        try
        {
            return m.invoke(ProxyHelper.getRealObject(target), null);
        }
        catch (Throwable e)
        {
            logProblem(pd, target, null, "Can't read value from given object");
            throw new MetadataException("Error invoking method:" + m.getName() + " in object " + target.getClass().getName(), e);
        }
    }
    else
    {
        throw new MetadataException("Can't get ReadMethod for property:" + pd.getName() + " in object " + target.getClass().getName());
    }
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:22,代码来源:PersistentFieldIntrospectorImpl.java

示例2: get

import org.apache.ojb.broker.metadata.MetadataException; //导入依赖的package包/类
public Object get(Object anObject) throws MetadataException
{
    try
    {
        return getCurrent().get(anObject);
    }
    catch (Exception e)
    {
        if(e instanceof AutoDetectException)
        {
            throw (MetadataException) e;
        }
        else
        {
            handleException("Can't extract field value for field " + getName()
                    + " from object " + (anObject != null ? anObject.getClass() : null), e);
            return get(anObject);
        }
    }
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:21,代码来源:PersistentFieldAutoProxyImpl.java

示例3: set

import org.apache.ojb.broker.metadata.MetadataException; //导入依赖的package包/类
public void set(Object obj, Object value) throws MetadataException
{
    try
    {
        getCurrent().set(obj, value);
    }
    catch (Exception e)
    {
        if(e instanceof AutoDetectException)
        {
            throw (MetadataException) e;
        }
        else
        {
            handleException("Can't set value for field " + getName()
                    + " to object " + (obj != null ? obj.getClass() : null), e);
            set(obj, value);
        }
    }
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:21,代码来源:PersistentFieldAutoProxyImpl.java

示例4: getType

import org.apache.ojb.broker.metadata.MetadataException; //导入依赖的package包/类
public Class getType()
{
    try
    {
        return getCurrent().getType();
    }
    catch (Exception e)
    {
        if(e instanceof AutoDetectException)
        {
            throw (MetadataException) e;
        }
        else
        {
            handleException("Can't identify field type for field " + getName(), null);
            return getType();
        }
    }
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:20,代码来源:PersistentFieldAutoProxyImpl.java

示例5: get

import org.apache.ojb.broker.metadata.MetadataException; //导入依赖的package包/类
/**
 * do not override this method, have a look at {@link #getValueFrom(java.lang.reflect.Field, Object)}
 */
public Object get(Object target) throws MetadataException
{
    Object result = target;
    if (isNestedField())
    {
        List fields = getFieldsList();
        for (int i = 0; i < fields.size(); i++)
        {
            if (result == null) break;
            result = getValueFrom((Field) fields.get(i), result);
        }
    }
    else
    {
        result = result != null ? getValueFrom(getField(), result) : null;
    }
    return result;
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:22,代码来源:PersistentFieldDirectImpl.java

示例6: createPersistentField

import org.apache.ojb.broker.metadata.MetadataException; //导入依赖的package包/类
public static PersistentField createPersistentField(String persistentFieldClassName, Class attributeType, String attributeName)
{
    try
    {
        if (persistentFieldClassName == null)
        {
            synchronized (PersistentFieldFactory.class)
            {
                persistentFieldClassName = getDefaultPersistentFieldClassName();
            }
        }
        Object[] args = {attributeType, attributeName};
        return (PersistentField) ClassHelper.newInstance(persistentFieldClassName, METHOD_PARAMETER_TYPES, args);
        
    }
    catch (Exception ex)
    {
        throw new MetadataException("Error creating PersistentField: " +
                attributeType.getName() + ", " + attributeName, ex);
    }
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:22,代码来源:PersistentFieldFactory.java

示例7: ojbAdd

import org.apache.ojb.broker.metadata.MetadataException; //导入依赖的package包/类
public void ojbAdd(Object anObject)
{
	if (anObject != null)
	{
		ClassDescriptor cd = MetadataManager.getInstance().getRepository().getDescriptorFor(anObject.getClass());
           FieldDescriptor[] fields = cd.getPkFields();
           if(fields.length > 1 || fields.length == 0)
           {
               throw new MetadataException("ManageableHashMap can only be used for persistence capable objects with" +
                       " exactly one primiary key field defined in metadata, for " + anObject.getClass() + " the" +
                       " PK field count is " + fields.length);
           }
           else
           {
               Object key = fields[0].getPersistentField().get(anObject);
		    put(key,anObject);
           }
	}
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:20,代码来源:ManageableHashMap.java

示例8: CollectionProxyDefaultImpl

import org.apache.ojb.broker.metadata.MetadataException; //导入依赖的package包/类
/**
 * Creates a new collection proxy that uses the given collection type.
 * 
 * @param brokerKey The key of the persistence broker
 * @param collClass The collection type
 * @param query     The defining query
 */
public CollectionProxyDefaultImpl(PBKey brokerKey, Class collClass, Query query)
{
    MetadataManager mm = MetadataManager.getInstance();
    _perThreadDescriptorsEnabled = mm.isEnablePerThreadChanges();
    if (_perThreadDescriptorsEnabled)
    {
        // mkalen:  To minimize memory footprint we remember only the OJB profile key
        //          (instead of all active class-mappings).
        final Object key = mm.getCurrentProfileKey();
        if (key == null)
        {
            // mkalen:  Unsupported: using proxies with per-thread metadata changes without profile keys.
            throw new MetadataException("Trying to create a Collection proxy with per-thread metadata changes enabled, but no profile key.");
        }
        setProfileKey(key);
    }
    setBrokerKey(brokerKey);
    setCollectionClass(collClass);
    setQuery(query);
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:28,代码来源:CollectionProxyDefaultImpl.java

示例9: getIndirectionHandlerConstructor

import org.apache.ojb.broker.metadata.MetadataException; //导入依赖的package包/类
/**
 * Returns the constructor of the indirection handler class.
 *
 * @return The constructor for indirection handlers
 */
private synchronized Constructor getIndirectionHandlerConstructor()
{
    if(_indirectionHandlerConstructor == null)
    {
        Class[] paramType = {PBKey.class, Identity.class};

        try
        {
            _indirectionHandlerConstructor = getIndirectionHandlerClass().getConstructor(paramType);
        }
        catch(NoSuchMethodException ex)
        {
            throw new MetadataException("The class "
                    + _indirectionHandlerClass.getName()
                    + " specified for IndirectionHandlerClass"
                    + " is required to have a public constructor with signature ("
                    + PBKey.class.getName()
                    + ", "
                    + Identity.class.getName()
                    + ").");
        }
    }
    return _indirectionHandlerConstructor;
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:30,代码来源:AbstractProxyFactory.java

示例10: setIndirectionHandlerClass

import org.apache.ojb.broker.metadata.MetadataException; //导入依赖的package包/类
/**
 * Sets the indirection handler class.
 *
 * @param indirectionHandlerClass The class for indirection handlers
 */
public void setIndirectionHandlerClass(Class indirectionHandlerClass)
{
    if(indirectionHandlerClass == null)
    {
        //throw new MetadataException("No IndirectionHandlerClass specified.");
        /**
         * andrew.clute
         * Allow the default IndirectionHandler for the given ProxyFactory implementation
         * when the parameter is not given
         */
        indirectionHandlerClass = getDefaultIndirectionHandlerClass();
    }
    if(indirectionHandlerClass.isInterface()
            || Modifier.isAbstract(indirectionHandlerClass.getModifiers())
            || !getIndirectionHandlerBaseClass().isAssignableFrom(indirectionHandlerClass))
    {
        throw new MetadataException("Illegal class "
                + indirectionHandlerClass.getName()
                + " specified for IndirectionHandlerClass. Must be a concrete subclass of "
                + getIndirectionHandlerBaseClass().getName());
    }
    _indirectionHandlerClass = indirectionHandlerClass;
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:29,代码来源:AbstractProxyFactory.java

示例11: set

import org.apache.ojb.broker.metadata.MetadataException; //导入依赖的package包/类
public void set(Object target, Object value) throws MetadataException
{
    if(target == null) return;
    List propertyDescriptors = getPropertyGraph();
    int size = propertyDescriptors.size() - 1;
    PropertyDescriptor pd;
    for (int i = 0; i < size; i++)
    {
        Object attribute;
        pd = (PropertyDescriptor) propertyDescriptors.get(i);
        attribute = getValueFrom(pd, target);
        if (attribute != null || value != null)
        {
            if (attribute == null)
            {
                try
                {
                    attribute = ClassHelper.newInstance(pd.getPropertyType());
                }
                catch (Exception e)
                {
                    throw new MetadataException("Can't instantiate nested object of type '"
                            + pd.getPropertyType() + "' for field '"
                            + pd.getName() + "'", e);
                }
            }
            setValueFor(pd, target, attribute);
        }
        else
        {
            return;
        }
        target = attribute;
    }
    pd = (PropertyDescriptor) propertyDescriptors.get(size);
    setValueFor(pd, target, value);
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:38,代码来源:PersistentFieldIntrospectorImpl.java

示例12: get

import org.apache.ojb.broker.metadata.MetadataException; //导入依赖的package包/类
public Object get(Object target) throws MetadataException
{
    List propertyDescriptors = getPropertyGraph();
    for (int i = 0; i < propertyDescriptors.size(); i++)
    {
        PropertyDescriptor pd = (PropertyDescriptor) propertyDescriptors.get(i);
        target = getValueFrom(pd, target);
        if (target == null) break;
    }
    return target;
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:12,代码来源:PersistentFieldIntrospectorImpl.java

示例13: setValueFor

import org.apache.ojb.broker.metadata.MetadataException; //导入依赖的package包/类
private void setValueFor(PropertyDescriptor pd, Object target, Object value)
{
    Method m = pd.getWriteMethod();
    Object[] args = {value};
    if (m != null)
    {
        try
        {
            /**
             * MBAIRD: it is safe to call getParameterTypes()[0] because this is
             * the "set" method and it needs to take one parameter only.
             * we need to be able to set values to null. We can only set something to null if
             * the type is not a primitive (assignable from Object).
             */
            if ((value != null) || !m.getParameterTypes()[0].isPrimitive())
            {
                m.invoke(ProxyHelper.getRealObject(target), args);
            }
        }
        catch (Throwable e)
        {
            logProblem(pd, target, value, "Can't set value on given object.");
            throw new MetadataException("Error invoking method:" + m.getName() + " in object:" + target.getClass().getName(), e);
        }
    }
    else
    {
        throw new MetadataException("Can't get WriteMethod for property:" + pd.getName() + " in object:" + target.getClass().getName());
    }
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:31,代码来源:PersistentFieldIntrospectorImpl.java

示例14: findPropertyDescriptor

import org.apache.ojb.broker.metadata.MetadataException; //导入依赖的package包/类
/**
 * Get the PropertyDescriptor for aClass and aPropertyName
 */
protected static PropertyDescriptor findPropertyDescriptor(Class aClass, String aPropertyName)
{
    BeanInfo info;
    PropertyDescriptor[] pd;
    PropertyDescriptor descriptor = null;

    try
    {
        info = Introspector.getBeanInfo(aClass);
        pd = info.getPropertyDescriptors();
        for (int i = 0; i < pd.length; i++)
        {
            if (pd[i].getName().equals(aPropertyName))
            {
                descriptor = pd[i];
                break;
            }
        }
        if (descriptor == null)
        {
            /*
 * Daren Drummond: 	Throw here so we are consistent
 * 					with PersistentFieldDefaultImpl.
 */
            throw new MetadataException("Can't find property " + aPropertyName + " in " + aClass.getName());
        }
        return descriptor;
    }
    catch (IntrospectionException ex)
    {
        /*
* Daren Drummond: 	Throw here so we are consistent
* 					with PersistentFieldDefaultImpl.
*/
        throw new MetadataException("Can't find property " + aPropertyName + " in " + aClass.getName(), ex);
    }
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:41,代码来源:PersistentFieldIntrospectorImpl.java

示例15: setValueFor

import org.apache.ojb.broker.metadata.MetadataException; //导入依赖的package包/类
protected void setValueFor(Field field, Object target, final Object value)
{
    try
    {
        /**
         * MBAIRD
         * we need to be able to set values to null. We can only set something to null if
         * the type is not a primitive (assignable from Object).
         */
        // thanks to Tomasz Wysocki for this trick
        if ((value != null) || !field.getType().isPrimitive())
        {
            field.set(ProxyHelper.getRealObject(target), value);
            // TODO: don't make costly proxy test on field level use
            // field.set(target, value);
        }
    }
    catch (NullPointerException ignored)
    {
        getLog().info("Target object '" + (target != null ? target.getClass().getName() : null)
                + "' for field '" + (field != null ? field.getName() : null)
                + "' of type '" + (field != null ? field.getType().getName() : null)
                + "' seems to be null. Can't write into null.", ignored);
    }
    catch (Exception e)
    {
        getLog().error("while set field: " + buildErrorSetMsg(target, value, field));
        throw new MetadataException("IllegalAccess error setting field:" +
                (field != null ? field.getName() : null) + " in object:" + target.getClass().getName(), e);
    }
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:32,代码来源:PersistentFieldDirectImpl.java


注:本文中的org.apache.ojb.broker.metadata.MetadataException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。