Razvan Prichici wrote:
>
>
> Here is my interceptor :
>
> public Object instantiate(String entityName, EntityMode entityMode,
> Serializable id)
> throws CallbackException {
>
> Object returnObject=null;
>
> try {
> _classReflector=new ClassReflector(entityName);
> } catch (ReflectionException e) {
> if (_logger.isDebugEnabled()) {
> _logger.error(e.getMessage());
> }
> }
>
>
> if(_classReflector.implementsOrExtends(XmlObject.class))
> {
>
>
> if (_logger.isDebugEnabled()) {
> _logger.debug("Start overriding default constructor");
> }
> try {
> _innerClassReflector=new ClassReflector(
> new ClassReflector(_classReflector.getDefaultInterface())
> .getInnerClass(FACTORY_CLASS));
> returnObject =
> _innerClassReflector.invokeStaticMethod(FACTORY_NEW_INSTANCE);
> } catch (ReflectionException e) {
> if (_logger.isDebugEnabled()) {
> _logger.error(e.getMessage());
> }
> }
>
> ((Persistable)returnObject).setPersistentId(id);
>
>
> if (_logger.isDebugEnabled()) {
> _logger.debug("End overriding default constructor");
> }
> return returnObject ;
>
> else ... default ..
>
>
>
>
> ClassReflector is a helper class ,nothing special ..
>
> public ClassReflector( String aClassName ) throws ReflectionException {
> try {
> _class = Class.forName( aClassName );
> } catch ( ClassNotFoundException e ) {
> throw new ReflectionException( "Class not found: "
> + aClassName, e );
> }
> }
>
> /**
> * Constructs the object.
> *
> * @param aClass
> * Class to do reflection on.
> */
> public ClassReflector( Class aClass ) {
> _class = aClass;
> }
>
> /**
> * Gets the class object.
> */
> public Class getClassObject() {
> return _class;
> }
>
> /**
> * Constructs a default instance of the class and verifies it implements
> a
> * specified interface.
> *
> * @param aRequiredInterface
> * Interface that must be implemented by the object.
> * @return Object.
> * @throws ReflectionException
> * In case the object cannot be constructed or does not
> * implement the required interface.
> */
> public Object constructDefaultObject( Class aRequiredInterface )
> throws ReflectionException {
> if ( !aRequiredInterface.isAssignableFrom( _class ) ) {
> throw new ReflectionException( "Class '" + _class.getName( )
> + "' does not implement the required interface '"
> + aRequiredInterface.getName( ) + "'" );
> }
> return constructDefaultObject( );
> }
>
> /**
> * Constructs a default instance of the class. This also works if the
> * constructor is private.
> *
> * @return Constructed object.
> * @throws ReflectionException
> * In case the object cannot be constructed.
> */
> public Object constructDefaultObject( ) throws ReflectionException {
> try {
> try {
> Constructor constructor = _class
> .getDeclaredConstructor( new Class[0] );
> constructor.setAccessible( true ); // allow access to private
> // constructor.
>
> return constructor.newInstance( new Object[0] );
> } catch ( NoSuchMethodException e ) {
> // Use default no-arg constructor.
> return _class.newInstance( );
> }
> } catch ( InvocationTargetException e ) {
> throw new ReflectionException( e.getMessage( ), e );
> } catch ( InstantiationException e ) {
> throw new ReflectionException( e.getMessage( ), e );
> } catch ( IllegalAccessException e ) {
> throw new ReflectionException( e.getMessage( ), e );
> }
> }
>
> /**
> * Determines if the class implements or extends another class.
> *
> * @param aSuperClass
> * Super class.
> * @return True if the class implements or extends the other class.
> */
> public boolean implementsOrExtends( Class aSuperClass ) {
> return aSuperClass.isAssignableFrom( _class );
> }
>
>
> public Object invokeStaticMethod(String aMethodName) throws
> ReflectionException
> {
>
> try {
> Method m = _class.getMethod(aMethodName, new Class[] {} );
> return m.invoke(null,null);
> } catch (SecurityException e) {
> throw new ReflectionException( e.getMessage( ), e );
> } catch (IllegalArgumentException e) {
> throw new ReflectionException( e.getMessage( ), e );
> } catch (NoSuchMethodException e) {
> throw new ReflectionException( e.getMessage( ), e );
> } catch (IllegalAccessException e) {
> throw new ReflectionException( e.getMessage( ), e );
> } catch (InvocationTargetException e) {
> throw new ReflectionException( e.getMessage( ), e );
> }
>
> }
>
> /**
> * Gets the first interface implemented by the class .
>
> * @throws ReflectionException
> * In case the class does not implement any interface.
> */
> public Class getDefaultInterface() throws ReflectionException
> {
> try {
> return _class.getInterfaces()[0];
> } catch (RuntimeException e) {
> throw new ReflectionException( "Class does not implement any
> interface "
> , e );
> }
> }
>
> /**
> * Gets the inner class object.
> * @param aInnerClassName
> * inner class name.
> * @throws ReflectionException
> * In case the inner class cannot be found.
> */
> public Class getInnerClass(String aInnerClassName) throws
> ReflectionException
> {
> try {
> return Class.forName(_class.getName()+"$"+aInnerClassName);
> } catch (ClassNotFoundException e) {
> throw new ReflectionException( "Class not found: "
> + _class.getName()+"$"+aInnerClassName, e );
> }
> }
>
>
> The problem is when I tried to load this XmlObject bastards. To load a
> single object is OK ,but trying to load a Object which has one-to-many
> relations with another object and so on .. . It fails .It throws
> NonUniqueObjectException at load . It's trying to flush the session
> immediatly after load and it finds dirty ,I don't know ,but it sucks .
>
>
--
View this message in context:
http://www.nabble.com/object-oriented-persistence-layer--tf4192422.html#a12271017
Sent from the Xml Beans - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]