Subversion Repository Public Repository

litesoft

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// This Source Code is in the Public Domain per: http://unlicense.org
package org.litesoft.configuration;

import org.litesoft.commonfoundation.base.*;
import org.litesoft.util.*;

import java.util.*;

public class ServerConfigDataAccessorFactoryProxy implements ConfigDataAccessorFactory {
    private final ConfigDataAccessorFactory mProxyForAccessorFactory;
    private final ConfigDataAccessor mProxyForAccessor;

    private ServerConfigDataAccessorFactoryProxy( ConfigDataAccessorFactory pFactory, ConfigDataAccessor pAccessor ) {
        mProxyForAccessorFactory = pFactory;
        mProxyForAccessor = pAccessor;
    }

    public ServerConfigDataAccessorFactoryProxy( ConfigDataAccessorFactory pProxyForAccessorFactory ) {
        this( Confirm.isNotNull( "ProxyForAccessorFactory", pProxyForAccessorFactory ), null );
    }

    public ServerConfigDataAccessorFactoryProxy( ConfigDataAccessor pProxyForAccessor ) {
        this( null, Confirm.isNotNull( "ProxyForAccessor", pProxyForAccessor ) );
    }

    @Override
    public ConfigDataAccessor createConfigDataAccessor() {
        return new ConfigDataAccessorProxy( (mProxyForAccessorFactory == null) ? mProxyForAccessor : mProxyForAccessorFactory.createConfigDataAccessor() );
    }

    private static class ConfigDataAccessorProxy implements ConfigDataAccessor {
        private final ConfigDataAccessor mProxyFor;
        private Map<String, String> mSystemKeyValues = new HashMap<String, String>();

        private ConfigDataAccessorProxy( ConfigDataAccessor pProxyFor ) {
            mProxyFor = pProxyFor;
            try {
                mSystemKeyValues.putAll( System.getenv() );
            }
            catch ( SecurityException e ) {
                System.err.println( "Unable to access Environment Variables" );
            }
            try {
                Properties properties = System.getProperties();
                for ( Map.Entry<Object, Object> zEntry : properties.entrySet() ) {
                    String zKey = ConstrainTo.significantOrNull( Utils.toString( zEntry.getKey() ) );
                    String zValue = ConstrainTo.significantOrNull( Utils.toString( zEntry.getValue() ) );
                    if ( (zKey != null) && (zValue != null) ) {
                        mSystemKeyValues.put( zKey, zValue );
                    }
                }
            }
            catch ( SecurityException e ) {
                System.err.println( "Unable to access System Properties" );
            }
        }

        @Override
        public ConfigDataAccessor createConfigDataAccessor() {
            return this;
        }

        @Override
        public String[] getAllKeys() {
            Set<String> keys = new HashSet<String>( mSystemKeyValues.keySet() ); // Copy it for Mutation
            keys.addAll( Arrays.asList( mProxyFor.getAllKeys() ) );
            return keys.toArray( new String[keys.size()] );
        }

        @Override
        public String loadedFrom() {
            return mProxyFor.loadedFrom();
        }

        @Override
        public String loadedFromDirectory() {
            return mProxyFor.loadedFromDirectory();
        }

        @Override
        public Level[] getSetableSupportedLevels() {
            return mProxyFor.getSetableSupportedLevels();
        }

        @Override
        public void setKeyValue( Level pLevel, String pKey, String pValue )
                throws UnsupportedOperationException {
            synchronized ( mProxyFor ) {
                mProxyFor.setKeyValue( pLevel, pKey, pValue ); // Will validate pKey
                mSkipKeysEqual.add( pKey );
            }
        }

        @Override
        public void overrideAllStartingWith( String pKeyPrefix, String pValue ) {
            synchronized ( mProxyFor ) {
                mProxyFor.overrideAllStartingWith( pKeyPrefix, pValue ); // Will validate pKeyPrefix
                mSkipKeysStartsWith.add( pKeyPrefix );
            }
        }

        @Override
        public String getString( String pKey ) {
            synchronized ( mProxyFor ) {
                String zValue = mProxyFor.getString( pKey ); // Will validate pKey
                return skip( pKey ) ? zValue : ConstrainTo.firstNonNull( getSystemString( pKey ), zValue );
            }
        }

        private Set<String> mSkipKeysEqual = new HashSet<String>();
        private Set<String> mSkipKeysStartsWith = new HashSet<String>();

        private boolean skip( String pKey ) {
            if ( mSkipKeysEqual.contains( pKey ) ) {
                return true;
            }
            for ( String zKeyPrefix : mSkipKeysStartsWith ) {
                if ( pKey.startsWith( zKeyPrefix ) ) {
                    return true;
                }
            }
            return false;
        }

        private String getSystemString( String pKey ) {
            return mSystemKeyValues.get( pKey );
        }
    }
}

Commits for litesoft/trunk/Java/core/Server/src/org/litesoft/configuration/ServerConfigDataAccessorFactoryProxy.java

Diff revisions: vs.
Revision Author Commited Message
950 Diff Diff GeorgeS picture GeorgeS Thu 19 Jun, 2014 17:57:04 +0000

New Lines

948 Diff Diff GeorgeS picture GeorgeS Sat 07 Jun, 2014 23:42:39 +0000

Jusefuls Formatter Updated to New Code Format

947 Diff Diff GeorgeS picture GeorgeS Fri 06 Jun, 2014 23:36:56 +0000

Correct Spelling of package!

939 Diff Diff GeorgeS picture GeorgeS Mon 02 Jun, 2014 21:30:31 +0000

Extracting commonfoundation

917 Diff Diff GeorgeS picture GeorgeS Sun 08 Dec, 2013 20:49:56 +0000

1.7 prep & VersionedStaticContentFilter upgrade to new “/ver” model!

804 Diff Diff GeorgeS picture GeorgeS Wed 15 Aug, 2012 12:48:51 +0000
802 Diff Diff GeorgeS picture GeorgeS Wed 15 Aug, 2012 04:04:47 +0000
801 Diff Diff GeorgeS picture GeorgeS Wed 15 Aug, 2012 03:59:02 +0000
499 Diff Diff GeorgeS picture GeorgeS Sun 11 Sep, 2011 19:58:57 +0000

Fixed Admin Data Loading & Shared Run Configs.

474 GeorgeS picture GeorgeS Fri 02 Sep, 2011 14:29:50 +0000

Switch to Properties and eliminate some of the Per App shit