Following code will help you to understand and write the basic steps of Drools. It;s not a executable code. Hope this will help to write your logic.
RuleAdministrator mVRuleAdministrator = serviceProviderBean.getRuleServiceProvider().getRuleAdministrator();
LocalRuleExecutionSetProvider mVRuleExecutionSetProvider = mVRuleAdministrator.getLocalRuleExecutionSetProvider(null);
SpreadsheetCompiler mVCompiler = new SpreadsheetCompiler();
String mSDrl = mVCompiler.compile(new FileInputStream(INPUT_EXCEL_FILE), InputType.XLS);
Reader mVReader = new StringReader(mSDrl);
RuleExecutionSet cachedRuleSet = mVRuleExecutionSetProvider.createRuleExecutionSet(mVRuleReader, null);
String mSUri = cachedRuleSet.getName();
mVRuleAdministrator.registerRuleExecutionSet(mSUri, cachedRuleSet, null);
String serviceProviderClass = "org.drools.jsr94.rules.RuleServiceProviderImpl";
String serviceProvider = "http://drools.org";
RuleServiceProviderManager.registerRuleServiceProvider(
serviceProvider, Class.forName(serviceProviderClass));
RuleServiceProvider ruleServiceProvider = RuleServiceProviderManager.getRuleServiceProvider(serviceProvider);
RuleRuntime mVRuleRuntime = ruleServiceProvider.getRuleRuntime();
List mVRegistrations = mVRuleRuntime.getRegistrations();
StatelessRuleSession mVStatelessRuleSession =
(StatelessRuleSession) mVRuleRuntime.createRuleSession(
mSUri, new HashMap(), RuleRuntime.STATELESS_SESSION_TYPE);
mVInputList.add(null/* Add all objects for which rule should be executed */);
List mRResults = mVStatelessRuleSession.executeRules(mVInputList);
If I add the @XmlRootElement annotation it works, but auto generated class not...why?
XJC does try to put @XmlRootElement
annotation on a class that we generate from a complex type. if we
can statically guarantee that a complex type won't be used by
multiple different tag names, we put @XmlRootElement annotation.
If:
<schema>
<element name="Abc">
<complexType> ...</complexType>
</element>
</schema>
then
@XmlRootElement
class Abc {
...
}
But if the schema is as follows,
then XJC can't eliminate the possibility that your type might be
used in other schemas (that can be compiled separately and put
together at runtime):
<schema>
<element name="Abc" type="Xyz" />
<complexType name="Xyz" />
</schema>
we will get,
class Bar {
}
class ObjectFactory {
JAXBElementcreateFoo(Xyz value) { ... }
}
Now, the crucial part in the above
inference done by XJC is that "your
schema might be used by other schemas that XJC isn't compiling right
now". This is certainly true for some users (and we learned that
the hard way), but it's also true that for many users this is too
conservative an assumption. It's often the case that what you are
compiling is indeed the whole thing, and you want XJC to know that
so that it can optimize the generated code more aggressively.
Work around:
If all you want is just to marshal an object without @XmlRootElement,
then you can just do:
marshaller.marshal( new JAXBElement(QName("uri","local"),
MessageType.class, messageType ));
If you work in a CMT environment, you might also want to use the same entity manager in different parts of your code. Typically, in a non-managed environment you would use a ThreadLocal variable to hold the entity manager, but a single EJB request might execute in different threads (e.g. session bean calling another session bean). The EJB3 container takes care of the persistence context propagation for you. Either using injection or lookup, the EJB3 container will return an entity manager with the same persistence context bound to the JTA context if any, or create a new one and bind it. In other words, all you have to do in a managed environment is to inject the EntityManager, do your data access work, and leave the rest to the container. Transaction boundaries are set declaratively in the annotations or deployment descriptors of your session beans.
The life cycle of the entity manager and persistence context is completely managed by the container. The persistence context lifetime has transaction scope, so the persistence context ends when the transaction is committed or rolls back. Transaction management uses container-managed transactions with the required transaction attribute. This means that any business method will get invoked by the container in the context of a transaction (either an existing or a new one).our persistence context ends when the method returns because that is when the transaction ends. At this stage, the connection between all managed entities and the entity manager is removed and the entities change to the detached state. In the detached state, entity state is not synchronized with the database.
So, how do we change the account so that the database is actually updated? We need to do two things: get a new persistence context, and transfer the entity to the managed state again.
//CMT idiom through injection @PersistenceContext(name="PU Name")
EntityManager em;
You can submit your site in yahoo or google or most of other search engines for free. This will help the search engines know about the existence of your website and will be indexed for search results. Typically most of the search engines are based upon yahoo, msn or google and display the search results by using these search engines.
here are links to submit your site to yahoo, google and msn.
Yahoo: https://siteexplorer.search.yahoo.com/submit
Google Page rank is based on back links. Back links are Links pointing to your website from another website. The more back links you have the higher your PR will be.
1. Join forums, forums are a great way to achieve links to your website. In most forums you are allowed to have a signature and in your signature you can put a link to your website. But another important note to look on is making sure the forum is somewhat related to your website. You will still get credit if it's not, but if it's related to your website than you will be accomplishing two tasks at once.
You will be advertising for your website (bringing in targeted traffic) You will also be building your websites presence.
Your websites presence is very important to your survival. The more people see, or hear about your website the more credibility you will have and this increases your chances of having these visitors come back and possibly become leads.
2. Submit to search engine directories. Search engine directories are a good way to get a free link to your website. They also increase your chances at being listed higher on popular search engines like Google, and overture.
Most search engine directories allow you to submit to their website for free. This will allow you to increase your web presence by being listed on another search engine, and it will also be a free link.
Remember the more links you have the higher your PR will be
3. Using ezine ads (or newsletters). Creating an ezine will probably be the most beneficial step you can take to increasing your web presence. When you create an ezine you will be able to keep visitors coming back to your website for more by using signatures and giving special deals.
Ezine's will also allow you to increase your back links. By creating an ezine you can submit your information about your ezine to an ezine directory. This directory will than link to your website(thus giving you a free link).
4. Creating and publishing articles. Articles are an easy source of generating new traffic. You can include your signature in your article. This will bring in more traffic from article submission directories.
Your signature usually consists of 4 to 8 lines. Usually the first line would be the title of the website that you are trying to advertise. The last line would be the link to the website and the lines in between these would be a sales pitch to draw your viewers into your website.
5. Links from related websites. Gaining links from related websites can be one of the most frustrating tasks you can attempt.
/** Created on Feb 01, 2008
*/
package misc.listener;
import java.io.PrintWriter;
import java.util.Map;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseEvent;import javax.faces.event.PhaseId;
import javax.faces.event.PhaseListener;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* @author Hiren
*/
public class AjaxPhaseListener implements PhaseListener {
/* (non-Javadoc)* @see javax.faces.event.PhaseListener#afterPhase(javax.faces.event.PhaseEvent)
*/
public void afterPhase(PhaseEvent evt){
System.out.println("******Phase Id: *****"+ evt.getPhaseId());FacesContext ctx = evt.getFacesContext();
Map headers = ctx.getExternalContext().getRequestHeaderMap();
HttpServletResponse response = (HttpServletResponse)ctx.getExternalContext().getResponse();
//Capturing each request after each phase of JSF lifecycle
HttpServletRequest request = (HttpServletRequest)ctx.getExternalContext().getRequest();
if("Test-Ajax".equalsIgnoreCase((String)headers.get("Ajax-Request"))){
System.out.println("********This is an TEST-AJAX call");
System.out.println("******* Query String=> " + request.getQueryString());
response.setContentType("text/xml");
response.setHeader("Cache-Control", "no-cache");
try{
PrintWriter out = response.getWriter();
out.write("Hiren Dutta");
out.flush();
}catch(Exception ex){ //too lazy too write nythin :)
}
ctx.responseComplete();//LetJSF know to skip rest of the lifecycle.
}
}
//Terminating condition for this phase listener.Here we are plugging our own //component
/* (non-Javadoc)
* @see javax.faces.event.PhaseListener#beforePhase(javax.faces.event.PhaseEvent)
*/
public void beforePhase(PhaseEvent arg0) {
// Feelin lazy....
}
/* (non-Javadoc)
* @see javax.faces.event.PhaseListener#getPhaseId()
*/
public PhaseId getPhaseId() {
return PhaseId.PROCESS_VALIDATIONS;
}
}
/**
* Convert java.util.Date into XMLGregorianCalendar object.
* @param date Date Object.
* @return XMLGregorianCalendar Object.
* @see XMLGregorianCalendar XMLGregorianCalendar.
*/
public static XMLGregorianCalendar toXMLGregorianCalendar(final Date aDtDate) {
XMLGregorianCalendar mVReturnCal = null;
try {
final GregorianCalendar mVCalendar = new GregorianCalendar();
mVCalendar.setTime(aDtDate);
mVReturnCal = DatatypeFactory.newInstance()
.newXMLGregorianCalendar(mVCalendar);
} catch (DatatypeConfigurationException ex) {
APPLICATION_LOG.error("Exception is=>",ex);
}
return mVReturnCal;
}
/**
* Convert java.util.Date into XMLGregorianCalendar object. Time Format.
* @param date Date Object.
* @return XMLGregorianCalendar Object.
* @see XMLGregorianCalendar XMLGregorianCalendar.
*/
public static XMLGregorianCalendar toXMLGregorianCalendarTime(final Date aDtDate) {
XMLGregorianCalendar mVReturnCal = null;
try {
final XMLGregorianCalendar mvTempCal = toXMLGregorianCalendar(aDtDate);
mVReturnCal = DatatypeFactory.newInstance()
.newXMLGregorianCalendarTime(
mvTempCal.getHour(),
mvTempCal.getMinute(),
mvTempCal.getSecond(),
mvTempCal.getTimezone());
} catch (DatatypeConfigurationException ex) {
APPLICATION_LOG.error("Exception is=>",ex);
}
return mVReturnCal;
}
/**
* Convert XMLGregorianCalendar to java.util.Date object.
* @param mVXMLCal XMLGregorianCalendar Object
* @return Date Object
* @see XMLGregorianCalendar
*/
public static java.util.Date toDate(final XMLGregorianCalendar mVXMLCal) {
java.util.Date mDtDate = null;
try {
final GregorianCalendar mVGregCalendar =
mVXMLCal.toGregorianCalendar();
mDtDate = mVGregCalendar.getTime();
} catch (Exception ex) {
APPLICATION_LOG.error("Exception is=>",ex);
}
return mDtDate;
}