I have developed a Application using pointcut(AOP Around) in java.i.e.
pointcut ps(String s,int iTemp1,int iTemp2) :
call (void java.awt.Graphics.drawString(String,int,int)) && args(s,iTemp1,iTemp2);
void around(String s,int i1,int i2) : ps(s,i1,i2)
{
if(flag1)
{
try
{
//Some code
}
catch(Exception ex)
{
}
}
s=image_applet.foo(s);
if(flag2)
{
try
{
//code
}
catch(Exception ex)
{
}
}
proceed(s,iTemp1,iTemp2);
}
and I want to develop same pointcut in our methods which is used in my c# code.If it is possible den please give me some directions.
I've used Spring.NET's AOP implementations with great success - maybe that could work for you?
Checkout the NKalore project #
http://aspectsharpcomp.sourceforge.net/
There are loads of AOP spoofs in .NET including the handicapped Code Contracts. However to my knowledge NKalore is the only one that mirrors AspectJ grammar and patterns. Other frameworks like LinFu, post sharp (starter edition) require you to place attributes and follow a different pattern. There is no AOP grammar support because they lack AOP compilers.
Related
What is the use of the static initialization block in Groovy. Why does Geb use it? If the use of it is the same as in Java, then how can you initialize non-declared fields in a situtation like this?
class ManualsMenuModule extends Module {
static content = {
toggle { $("div.menu a.manuals") }
linksContainer { $("#manuals-menu") }
links { linksContainer.find("a") }
}
void open() {
toggle.click()
waitFor { !linksContainer.hasClass("animating") }
}
}
Some answers to your questions are provided in the section about the content DSL of the Geb manual.
The DSL is implemented using Groovy's methodMissing() mechanism and modification of the delegate of the closure assigned to the static content field. If you are interested in digging deeper then you can always look at the implementation in PageContentTemplateBuilder.
I'm not expert on Geb, I can only explain the groovy meaning of the code.
1st off, it's not the static initialization block like in java. In those lines static content = {...} you are assigning to a static variable a Closure instance which is evaluated and executed LATER (hence, lazy).
The closure represents a (part of) a Geb's Groovy Builder which is called by Geb framework to register/perform some tasks.
There's no Java counterpart to achieve the same, and that's the reason why groovy-based frameworks are so nice to use for testing purposes and they follow the general rule of thumb:
test code should be more abstract then the code under test
UPDATE:
This line:
toggle { $("div.menu a.manuals") }
can be rewritten like
toggle( { $("div.menu a.manuals") } )
or
def a = { $("div.menu a.manuals") }
toggle a
so it's a method invocation and not an assignment. In groovy you can omit the brackets in some cases.
Some optimizations/algorithms make code considerably less readable, so it's useful to keep the ability to disable the complex-and-unwieldily functionality within a file/module so any errors introduced when modifying this code can be quickly tested against the simple code.
Currently using const USE_SOME_FEATURE: bool = true; seems a reasonable way, but makes the code read a little strangely, since USE_SOME_FEATURE is being used like an ifdef in C.
For instance, clippy wants you to write:
if foo {
{ ..other code.. }
} else {
// final case
if USE_SOME_FEATURE {
{ ..fancy_code.. }
} else {
{ ..simple_code.. }
}
}
As:
if foo {
{ ..other code.. }
} else if USE_SOME_FEATURE {
// final case
{ ..fancy_code.. }
} else {
// final case
{ ..simple_code.. }
}
Which IMHO hurts readability, and can be ignored - but is caused by using a boolean where a feature might make more sense.
Is there a way to expose a feature within a file without having it listed in the crate?(since this is only for internal debugging and testing changes to code).
You can use a build script to create new cfg conditions. Use println!("cargo:rustc-cfg=whatever") in the build script, and then you can use #[cfg(whatever)] on your functions and statements.
Spring-WS provides the following support as part of their template.
http://docs.spring.io/spring-ws/site/apidocs/org/springframework/ws/client/core/WebServiceTemplate.html#setCheckConnectionForFault(boolean)
Trying to determine if Spring Integration exposes this. Found the following from 2012, however I was hoping it would be part of the framework.
http://forum.spring.io/forum/spring-projects/integration/119981-ws-outbound-gateway-and-soap-fault
No, we don't support yet.
As I said there: feel free to raise a JIRA issue! :-)
Example configuration based on explanation from 2012 link ...
#Bean
#Description("Workaround for non conforming services")
AbstractWebServiceOutboundGateway initializeWebserviceGateway(
#Qualifier("wsOutboundGateway.handler") Object bean) {
Advised advised = (Advised) bean;
AbstractWebServiceOutboundGateway gateway = null;
try {
gateway = (AbstractWebServiceOutboundGateway) advised
.getTargetSource().getTarget();
} catch (Exception e) {
throw new IllegalStateException("Unable to configure webServiceTemplate for non conforming services");
}
DirectFieldAccessor dfa = new DirectFieldAccessor(gateway);
WebServiceTemplate wst = (WebServiceTemplate) dfa
.getPropertyValue("webServiceTemplate");
wst.setCheckConnectionForError(false);
wst.setCheckConnectionForFault(false);
return gateway;
}
Here is my Traverse method code
protected boolean traverse(int dir, int viewportWidth, int viewportHeight,
int[] visRect_inout) {
try {
if (hori && vert) {
// CustomItems items=new CustomItems("Hi");
switch (dir) {
case Canvas.DOWN:
this.a=dir; //Canvas.DOWN
this.b=viewportWidth; //b=2
this.c=viewportHeight; //c=3
this.d=visRect_inout; //d={2,2,250,250}
this.traverse(Canvas.UP, b, c, d);
break;
case Canvas.UP:
this.a=dir;
this.j=viewportWidth;
this.k=viewportHeight;
this.d=visRect_inout;
this.traverse(Canvas.UP, j, k, d);
break;
case Canvas.LEFT:
this.a=dir;
this.j=viewportWidth;
this.k=viewportHeight;
this.d=visRect_inout;
this.traverse(Canvas.LEFT, j, k, d);
break;
case Canvas.RIGHT:
break;
}
}
} catch (Exception e) {
System.out.println("Exception " + e);
}
return false;
}
I am very new to Custom Item.
If I had done any wrong, let me know.
The way how you invoke traverse from within switch statement looks slippery to me:
this.traverse(Canvas.UP, b, c, d); // ...
// ...and similar in cases Canvas.UP, LEFT
The code you posted so far is quite fragmentary but as far as I can tell, above will lead to infinite recursive calls for traverse, eventually ending in stack overflow error.
In your particular case this might be harmless though because you unconditionally return false from your method. Per my understanding this means that device will never attempt to invoke traverse with Canvas UP and other potentially dangerous values. Feel free to check lcdui CustomItem#traverse API documentation for more details if you're interested.
Given your code I think it makes good sense for you to study introductory code examples in tutorials. There are plenty available online - search the web for something like "MIDP tutorial CustomItem". Here's the link to one for example: Adding Custom Items to MIDP 2.0 Forms
Also, if you are using Wireless Toolkit / Java ME SDK, you could check their code examples. Per my recollection, there were nice working examples of CustomItem code there.
I'm currently using Subsonic 3.03 Active Record repository.
I have setup a Test connection string to utilise the dummy internal storage.
[TestInitialize]
public void TestInitialize()
{
List<ServiceJob> jobs = new List<ServiceJob>()
{
new ServiceJob() { ServiceJobID = 1 },
new ServiceJob() { ServiceJobID = 2 }
};
ServiceJob.Setup(jobs);
}
[TestMethod]
public void TestMethod()
{
ServiceJob job = ServiceJob.SingleOrDefault(s => s.ServiceJobID == 2);
Assert.AreEqual(2, job.ServiceJobID);
}
I'm expecting this unit-test to pass, but it pulls out the first service job and fails.
I've also experienced problems using other sugar methods such as .Find().
It works fine when using the IQueryable interface such as ServiceJob.All.Where(s => s.ServiceJobID == 2) but don't fancy stripping out the sugar for testing purposes!
Great product by the way, really impressed so far.
As you say this looks like it's definitely a bug. You should submit it as an issue to github:
http://github.com/subsonic/SubSonic-3.0/issues