Utility class : EJB Session or Simple Object?

Utility class : EJB Session or Simple Object?

By : Arun Purushothaman
Date : November 21 2020, 11:01 PM
hop of those help? What you're trying to accomplish looks like 'Generic Pattern DAO', there're many "ready" implementations out there.One from AdamBien: "Generic CRUD Service" More elaborate, eliminating the need for custom solution and approaching the simplicity of Spring templates from Apache DeltaSpike: DeltaSpike Data module
Now back to you original question, EJB or POJO, in your case, when working in an EE container the use of Entity manager, must be "container managed", so your "correct" options are EJB or CDI but not plain unmanaged POJO.
code :

Share : facebook icon twitter icon
Developing a simple utility class( like a Date class )in java

Developing a simple utility class( like a Date class )in java

By : user3286437
Date : March 29 2020, 07:55 AM
wish helps you You don't have to implement all the interfaces to have a simple working Date class.
I would suggest that you forget about Java's Date class and consider what you think is needed for a date class. For example:
How to use a static utility method for property setters in a utility class

How to use a static utility method for property setters in a utility class

By : berkbaykal
Date : March 29 2020, 07:55 AM
this will help 1: All non-void methods need to have explicit return statements.
2: CMBI.Common is the namespace. Utilities is the name of your class. Set() is a function of your class.
XML Utility class exist for simple modification - add, remove/delete, change/modify?

XML Utility class exist for simple modification - add, remove/delete, change/modify?

By : S.Ash
Date : March 29 2020, 07:55 AM
I wish this help you Whether you use something already existing like dom4j or jdom or as I said in my comment you create a simple class that wraps call to finding nodes using XPath and adding/removing what you want (Nodes, Attributes etc).
This is a sample class, I'll let you add what's missing (modifyAttribute, setNodeValue etc)
code :
import java.io.*;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
import javax.xml.xpath.*;
import org.w3c.dom.*;

public class MagicXml {
    static XPath xpath = XPathFactory.newInstance().newXPath();
    Document doc;
    Element root;

    public MagicXml(String xml) throws Exception {
        doc = parseXml(xml);
        root = doc.getDocumentElement();

    private static Document parseXml(String xml) throws Exception {
        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
        ByteArrayInputStream bis = new ByteArrayInputStream(xml.getBytes());
        return docBuilder.parse(bis);

    private String asXPath(String path) {
        return path.startsWith("/") ? path : "//" + path;

    private static Node findNode(Document doc, String xPath) throws Exception {
        XPathExpression expr = xpath.compile(xPath);
        return (Node) expr.evaluate(doc, XPathConstants.NODE);

    public static MagicXml createXml(String xml) throws Exception {
        return new MagicXml(xml);

    public MagicXml addNode(String path, String xml) throws Exception {
        Document subDoc = parseXml(xml);
        Node destNode = findNode(doc, asXPath(path));
        Node srcNode = subDoc.getFirstChild();
        return this;

    public MagicXml removeNode(String path) throws Exception {
        Node destNode = findNode(doc, asXPath(path));
        return this;

    public MagicXml addAttribute(String path, String attr, String value) throws Exception {
        Element destNode = (Element)findNode(doc, asXPath(path));
        destNode.setAttribute(attr, value);
        return this;

    public MagicXml removeAttribute(String path, String attr) throws Exception {
        Element destNode = (Element)findNode(doc, asXPath(path));
        return this;

    public String docToString(Document doc) {
        try {
            Transformer transformer = TransformerFactory.newInstance().newTransformer();
            transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
            transformer.setOutputProperty(OutputKeys.INDENT, "yes");
            transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
            StringWriter sw = new StringWriter();
            transformer.transform(new DOMSource(doc), new StreamResult(sw));
            return sw.toString();
        } catch (Exception e) {
            return "";

    public String toString() {
        return docToString(doc);

    public static void main(String[] args) throws Exception {
                MagicXml.createXml("<team name='cougars'><players><player name='Michael'/></players></team>")//
                .addNode("players", "<player name='Frank'/>")//
                .addNode("players", "<player name='Delete Me'/>")//
                .removeNode("player[@name='Delete Me']") //
                .addAttribute("player[@name='Frank']", "foo", "bar") //
                .addAttribute("player[@name='Frank']", "bar", "bazz") //
                .removeAttribute("player[@name='Frank']", "bar") //
Seeing error: session must be <requests.session.Session object> not <class 'str'> - Not sure what it means

Seeing error: session must be <requests.session.Session object> not <class 'str'> - Not sure what it means

By : yumyumyum
Date : March 29 2020, 07:55 AM
I hope this helps . When your function sees 'GBPUSD','NZDGBP', its assigning NZDGBP to the session variable and hence crashing.
Try running:
How to make utility class or functional component to expose few common utility methods

How to make utility class or functional component to expose few common utility methods

By : Enguerran Gillet
Date : March 29 2020, 07:55 AM
I wish did fix the issue. You can definitely add them to a js file and have them imported to the component you want. You can have your methods as static like this.
code :
export default class MyUtility {
    static postPhoto(selectedFile) {
        return true;

    static postData(data) {
        return true;

    static getPhoto() {
        return photo;

    static getData() {
        return data;
import MyUtility from '../../Common/myUtility';

let result = MyUtility.postPhoto(mySelectedFile);
Related Posts Related Posts :
  • Use JOOQ to do a delete specifying multiple columns in a "not in" clause
  • user input name times age
  • ConcurrentHashmap simultaneous write and get operations
  • How to concatenate a string from path to directory and a multiple zip files names in a directory?
  • Spring MVC Encode non-English parameters
  • How to join two (or more) streams (JavaDStream) in apache spark
  • Unable to restart glassfish 3 server
  • Could not find support-v4.aar(com.android.support:support-v4:24.1.1)
  • How to create jar file from existing jar file?
  • Whats difference between this two: BigInteger.valueOf(10000) and BigInteger.valueOf(0010000)?
  • Firebase Messaging - "too many alarms" on Samsung's Android devices
  • Apache POI: How do you restart numbering on a numbered list in word document?
  • Unsupported field: Year when formatting an instant to Date ISO
  • java serialize transient elements
  • why the program hang up when using ArrayBlockingQueue
  • Data objects conversion - instance method vs static method
  • Which checksum algorithm is being used by adobe acrobat pdf for file attachment
  • how to get list of all available images for a region in amazon web services using aws-java-sdk?
  • BufferedReader can not read the int in text
  • How to configure hadoop's mapper so that it takes <Text,IntWritable>
  • Change name of libGDX DesktopLauncher in mac OSX menu bar
  • parse the json file with mutiple objects using Jackson
  • It the planning entity must have one to one relationship with planning value?
  • My code is showing error
  • How can I modify the colors of pixels in a Texture?
  • compiling and executing java from bash script
  • How to test Spring mvc controller tests for response entity?
  • How to Switch between Native Mobile App to Web Application to verify the elements on it
  • Command 'web mvc all --package ~.web' not found
  • Reverse an array using swapping in Java
  • Trying to create a chessboard using an array and graphics
  • Can DatagramSocket Receive multicast Packets
  • What is abstract data type ? Is it a class in Java?
  • Non-gui checkout register menu: how to format it?
  • Glassfish The server exited prematurely with exit code 134
  • android: SharedPreferences not saving data
  • How to implement different log output by classloader in just one Java application?
  • Migrating to Google Cloud Endpoints Framework for Java
  • Does the Swing event dispatch thread run at higher priority than the main thread?
  • Android Studio Failing to Store Arguments as Part of Fragment Bundle
  • Reading a JSON Array in JAVA
  • Faster way (performance) to check if a letter is uppercase?
  • How to generate a .wav file with a sinusoidal wave and user-defined duration and frequency?
  • Compare int values from objects in an array list, and then display the top 3 objects
  • Producing the Nth value of Fibonacci Sequence in Java
  • Kafka ACL authorization issue using Java code
  • easiest way to access to device credentials from a Driver implementation?
  • YoutubeThumbnailLoader taking too long to show a thumbnail?
  • Java inheritance why does this toString prints BB and not AB, AB?
  • how to set up a while loop for
  • Processing 3.x not recognizing random() function
  • Understanding 2D Arrays in Java
  • Counting a String's Lowercase Letters
  • sparkjava: Load PNG as base64 from InputStream
  • Target folder is there but still getting no file found error, what can be the reason?
  • Cannot call constructor component from ActionPerformed
  • How does java global variable work?
  • How to use a Java variable with LIKE and '%' in sql?
  • Converting code using array to a code using Stacks/Queue
  • Product of two numbers using recursion java
  • shadow
    Privacy Policy - Terms - Contact Us © soohba.com