Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
frascati
frascati
Commits
e2e26ea5
Commit
e2e26ea5
authored
Aug 13, 2012
by
Lionel Seinturier
Browse files
COMP mode: Check that the content class implements the server interfaces.
parent
9b79c886
Changes
5
Hide whitespace changes
Inline
Side-by-side
tinfi/mixins/src/main/java/org/ow2/frascati/tinfi/control/content/TypeCheckSCAContentMixin.java
View file @
e2e26ea5
...
...
@@ -54,8 +54,8 @@ implements SCAContentController {
public
void
setFcContent
(
Object
content
)
throws
IllegalLifeCycleException
,
ContentInstantiationException
{
Type
type
=
_this_weaveableC
.
getFcType
();
Class
<?>
c
l
=
content
.
getClass
();
checkType
(
type
,
c
l
);
Class
<?>
c
=
content
.
getClass
();
checkType
(
type
,
c
);
_super_setFcContent
(
content
);
}
...
...
tinfi/module/opt-comp/mixins/src/main/java/org/ow2/frascati/tinfi/control/content/SCAContentControllerTrait.scala
View file @
e2e26ea5
...
...
@@ -34,4 +34,5 @@ import org.objectweb.fractal.julia.BasicControllerTrait
*/
trait
SCAContentControllerTrait
extends
BasicControllerTrait
with
RequestContextSCAContentTrait
with
SCABasicContentControllerTrait
with
LifeCycleSCAContentTrait
with
SCAExtendedContentController
with
TypeCheckSCAContentTrait
with
LifeCycleSCAContentTrait
with
SCAExtendedContentController
tinfi/module/opt-comp/mixins/src/main/java/org/ow2/frascati/tinfi/control/content/TypeCheckSCAContentTrait.scala
0 → 100644
View file @
e2e26ea5
/***
* OW2 FraSCAti Tinfi
* Copyright (C) 2012 INRIA, USTL
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: frascati@ow2.org
*
* Author: Lionel Seinturier
*/
package
org.ow2.frascati.tinfi.control.content
import
org.oasisopen.sca.RequestContext
import
org.objectweb.fractal.julia.UseComponentTrait
import
org.objectweb.fractal.api.Type
import
org.objectweb.fractal.api.
`type`
.
ComponentType
import
org.ow2.frascati.tinfi.api.control.ContentInstantiationException
/**
* Request context management.
*
* @author Lionel <Lionel.Seinturier@univ-lille1.fr>
* @since 1.4.5
*/
trait
TypeCheckSCAContentTrait
extends
SCABasicContentControllerTrait
with
UseComponentTrait
{
// -------------------------------------------------------------------------
// Implementation of the SCAContentController interface
// -------------------------------------------------------------------------
override
def
setFcContentClass
(
c
:
Class
[
_
]
)
=
{
val
typ
=
weaveableC
.
getFcType
checkType
(
typ
,
c
)
super
.
setFcContentClass
(
c
)
}
override
def
setFcContent
(
content
:
Object
)
=
{
val
typ
=
weaveableC
.
getFcType
val
c
=
content
.
getClass
checkType
(
typ
,
c
)
super
.
setFcContent
(
content
)
}
// -------------------------------------------------------------------------
// Implementation specific
// -------------------------------------------------------------------------
private
def
checkType
(
typ
:
Type
,
contentClass
:
Class
[
_
]
)
=
{
/*
* Check that the content class implements the server interfaces.
*/
val
ct
=
typ
.
asInstanceOf
[
ComponentType
]
val
its
=
ct
.
getFcInterfaceTypes
its
.
foreach
(
it
=>
{
var
continue
=
false
// Skip client interfaces
if
(
it
.
isFcClientItf
)
{
continue
=
true
}
// Skip control interfaces
val
name
=
it
.
getFcItfName
if
(
name
.
equals
(
"component"
)
||
name
.
endsWith
(
"-controller"
)
)
{
continue
=
true
}
if
(
!
continue
)
{
/*
* Workaround since Object.class.getClassLoader() returns null.
* Object.class as a content class is not a priori a useful case,
* but it uses it in test cases, and anyway the workaround is needed
* if Object.class is used elsewhere.
*/
val
signature
=
it
.
getFcItfSignature
if
(
contentClass
.
equals
(
classOf
[
Object
])
)
{
val
msg
=
"Object.class is not adequate since the content class "
+
"should implement "
+
signature
;
throw
new
ContentInstantiationException
(
msg
)
}
// Check that the class implements the server interface
val
cl
=
load
(
contentClass
,
signature
)
if
(
!
cl
.
isAssignableFrom
(
contentClass
)
)
{
val
msg
=
contentClass
+
" should implement "
+
signature
throw
new
ContentInstantiationException
(
msg
)
}
}
})
}
/**
* Load the class whose name is specified with the class loader of the
* specified class.
*
* @param main the class used to retrieve the class loader
* @param name the name of the class to load
* @throws ContentInstantiationException if the class cannot be loader
*/
private
def
load
(
main
:
Class
[
_
],
name
:
String
)
:
Class
[
_
]
=
{
val
loader
=
main
.
getClassLoader
try
{
return
loader
.
loadClass
(
name
);
}
catch
{
case
cnfe
:
ClassNotFoundException
=>
throw
new
ContentInstantiationException
(
cnfe
)
}
}
}
tinfi/tests/comp/src/test/java/org/ow2/frascati/tinfi/SCAContentControllerTestCase.java
View file @
e2e26ea5
...
...
@@ -137,6 +137,32 @@ public class SCAContentControllerTestCase {
catch
(
IllegalLifeCycleException
ilce
)
{}
}
/**
* Test that when the content class of <code>scaPrimitive</code> components
* is changed, the new class implements the server interfaces.
*
* @since 1.4.5
*/
@Test
public
void
testSetContentClassImplementsServices
()
throws
IllegalLifeCycleException
,
NoSuchInterfaceException
{
// Start and invoke the component once
Fractal
.
getLifeCycleController
(
client
).
startFc
();
r
.
getContentClass
();
// Reconfigure the content class
Fractal
.
getLifeCycleController
(
client
).
stopFc
();
SCAContentController
scacc
=
(
SCAContentController
)
client
.
getFcInterface
(
SCAContentController
.
NAME
);
try
{
scacc
.
setFcContentClass
(
Object
.
class
);
String
msg
=
"Class must implement server interfaces"
;
Assert
.
fail
(
msg
);
}
catch
(
ContentInstantiationException
cie
)
{}
}
/**
* @since 1.4.3
*/
...
...
@@ -219,4 +245,27 @@ public class SCAContentControllerTestCase {
}
catch
(
ContentInstantiationException
cie
)
{}
}
/**
* @since 1.4.5
*/
@Test
public
void
testSetContentImplementsServices
()
throws
IllegalLifeCycleException
,
NoSuchInterfaceException
{
// Check that the component is instantiated with the regular content instance
String
value
=
r
.
getProp
();
Assert
.
assertEquals
(
SCAContentControllerImpl1
.
DEFAULT
,
value
);
Fractal
.
getLifeCycleController
(
client
).
stopFc
();
// Associate the ad hoc content instance with the component
SCAContentController
scacc
=
(
SCAContentController
)
client
.
getFcInterface
(
SCAContentController
.
NAME
);
try
{
scacc
.
setFcContent
(
new
Object
());
String
msg
=
"Object must implement services"
;
Assert
.
fail
(
msg
);
}
catch
(
ContentInstantiationException
cie
)
{}
}
}
tinfi/tests/oasis/src/test/java/org/ow2/frascati/tinfi/SCAContentControllerTestCase.java
View file @
e2e26ea5
...
...
@@ -157,9 +157,7 @@ public class SCAContentControllerTestCase {
client
.
getFcInterface
(
SCAContentController
.
NAME
);
try
{
scacc
.
setFcContentClass
(
Object
.
class
);
String
msg
=
"Classes that do not implement server interfaces should not "
+
"be allowed"
;
String
msg
=
"Class must implement server interfaces"
;
Assert
.
fail
(
msg
);
}
catch
(
ContentInstantiationException
cie
)
{}
...
...
@@ -265,9 +263,7 @@ public class SCAContentControllerTestCase {
client
.
getFcInterface
(
SCAContentController
.
NAME
);
try
{
scacc
.
setFcContent
(
new
Object
());
String
msg
=
"Objects that do not implement server interfaces should not "
+
"be allowed"
;
String
msg
=
"Object must implement services"
;
Assert
.
fail
(
msg
);
}
catch
(
ContentInstantiationException
cie
)
{}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment