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 7936279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:09:57+00:00 2026-06-03T22:09:57+00:00

Properties properties = AppConfigurationManager.getInstance().getProperties(ObjectContainer.class); I have this code that populates properties. i want to

  • 0
Properties properties = AppConfigurationManager.getInstance().getProperties(ObjectContainer.class);

I have this code that populates properties.

i want to decorate this for validation for one field.

public class PropertiesDecorator extends Properties{

    public void ValidateFooservHost(){
        for(Entry<Object, Object> element : this.entrySet()){
            if(element.getKey().toString().equals("ffxserv_host")){
                String newHostValue = ffxServHostCheck(element.getValue().toString());
                put(element.getKey(), newHostValue);
            } 
        }
    }

    @Override
    public Object setProperty(String name, String value) {

        if(name.equals("foo")){
            value = fooHostCheck(value);

        }
        return put(name, value);
    }

    public String fooHostCheck(String valueFromConfig){
        String firstTwoChars = valueFromConfig.substring(0, 2);

        if(firstTwoChars.equals("1:")){
            return valueFromConfig.substring(2, valueFromConfig.length());
        }

        return valueFromConfig;
    }
}

However,

PropertiesDecorator properties = (PropertiesDecorator) AppConfigurationManager.getInstance().getProperties(ObjectContainer.class);

this fails. I dont have a informative description but it just says it failed. not sure. what.

What am i doing wrong here? also?

How can i fix this?

Or would u recommend something differnt?

Should i use Strategy pattern? pass Properties to the PropertiesDecorator, and make the validation there ?

EDIT:
I have seen that I m getting class cast exception.

Thanks.

  • 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-03T22:09:58+00:00Added an answer on June 3, 2026 at 10:09 pm

    You are getting a ClassCastException because the third party code is returning an instance of Properties, and not an instance of your PropertiesDecorator. A simple solution would be to have your PropertiesDecorator accept a Properties object, and have it merge all of its properties into yours. That is if you want your PropertiesDecorator to have an “is a” relationship with Properties.

    Otherwise, you could just have a PropertiesAdapter using the Adapter pattern that delegates to an underlying Properties instance and does your validation. For completeness, below is a very basic adapter class for Properties. Add validation code and additional delegate mthods where necessary.

    public class PropertiesAdapter{
        private Properties props;
    
        public PropertiesAdapter(){
            this.props = new Properties();
        }
    
        public PropertiesAdapter(Properties props){
            this.props = props;
        }
    
        public Object set(String name, String value){
            return this.props.setProperty(name, value);
        }
    
        public String get(String name){
            return this.props.getProperty(name);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get child properties of an object with this code, PropertyDescriptorCollection childProperties = TypeDescriptor.GetProperties(theObject)[childNode.Name].GetChildProperties();
My base class has properties that are used by a subclass. where should Release
I have a properties file, let say my-file.properties. In addition to that, I have
I'm writing properties in C++. I came up with this code (not as good
I have two properties of type int in my view model that broadcast their
Automatic properties let me replace this code: private MyType myProperty; public MyType MyProperty {
What properties should the problem have so that I can decide which method to
I have two properties files that are not the same and I need to
I have a .properties file I want to load in a Java Properties object.
I have several properties that are dependent on the environment the application is running.

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.