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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// This Source Code is in the Public Domain per: http://litesoft.org/License.txt
package org.litesoft.configuration;

import java.util.*;

import org.litesoft.core.typeutils.*;
import org.litesoft.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( Objects.assertNotNull( "ProxyForAccessorFactory", pProxyForAccessorFactory ), null );
    }

    public ServerConfigDataAccessorFactoryProxy( ConfigDataAccessor pProxyForAccessor )
    {
        this( null, Objects.assertNotNull( "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 = Strings.noEmpty( Utils.toString( zEntry.getKey() ) );
                    String zValue = Strings.noEmpty( 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 : Strings.deNull( 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
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 Diff Diff GeorgeS picture GeorgeS Fri 02 Sep, 2011 14:29:50 +0000

Switch to Properties and eliminate some of the Per App shit

49 Diff Diff GeorgeS picture GeorgeS Mon 12 Apr, 2010 02:59:10 +0000

License Text

2 GeorgeS picture GeorgeS Sun 07 Feb, 2010 12:50:58 +0000