Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8409869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:02:09+00:00 2026-06-10T00:02:09+00:00

I have an enum ContentType and it has a method like ContentType.getName() which can

  • 0

I have an enum ContentType and it has a method like ContentType.getName() which can evaluate to regText OR session. So, how do I do the below where I can instantiate the bean based on the return value of this method. Also, I only want to do this in XML config and not annotations.

<property name="contentCaptureRegEx" ref="${ContentType.getName()}">
</property>

<bean id="regText" class="java.util.regex.Pattern" factory-method="compile" lazy-init="true">
<constructor-arg value="xyz" /></bean>

<bean id="session" class="java.util.regex.Pattern" factory-method="compile" lazy-init="true">
<constructor-arg value="abc" /></bean>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T00:02:10+00:00Added an answer on June 10, 2026 at 12:02 am

    I would suggest a static factory method since the pattern regexes are already using that pattern. Just eliminate them and add:

    package com.mine;
    
    public class MyFactory {
    
        public static Pattern newContentCaptureRegEx() {
            String patternString;
            if ("regText".equals(ContentType.getName())) {
                patternString = "xyz";
            } else if ("session".equals(ContentType.getName())) {
                patternString = "abc";
            } else {
                throw new IllegalStateException("ContentType must be regText or session");
            }
            Pattern.compile(patternString);
        }
    
    }
    

    which you can wire as:

    <bean id="ContentCaptureRegEx" class="com.mine.MyFactory"
        factory-method="newContentCaptureRegEx" />
    

    And then you can ref that bean anywhere as:

    <property name="contentCaptureRegEx" ref="ContentCaptureRegEx" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have in my database a coloumn say agent which can have enum values
I have an enum which is defined like this: public enum eRat { A
I have this enum: public enum Direction { LEFT, RIGHT, ABOVE, BELOW } Can
I have enum like this [Flags] public enum Key { None = 0, A
I have enum like this: public enum ObectTypes { TypeOne, TypeTwo, TypeThree, ... TypeTwenty
I have enum list and method and i get error: not all code paths
I'm looking for a way to have Enum a => UArray a (which makes
I have enum like this public enum PetType { Dog = 1, Cat =
I have enum like this public enum Sizes { Normal(232), Large(455); private final int
I have an enum that looks like the following: public enum EnumWeapons { Fists

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.