001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.wicket.jmx.wrapper;
018
019import java.time.Duration;
020import java.util.List;
021import org.apache.wicket.Application;
022import org.apache.wicket.jmx.ResourceSettingsMBean;
023import org.apache.wicket.resource.loader.IStringResourceLoader;
024import org.apache.wicket.util.file.IResourceFinder;
025import org.apache.wicket.util.lang.Generics;
026
027
028/**
029 * Exposes Application related functionality for JMX.
030 * 
031 * @author eelcohillenius
032 */
033public class ResourceSettings implements ResourceSettingsMBean
034{
035        private final Application application;
036
037        /**
038         * Create.
039         * 
040         * @param application
041         */
042        public ResourceSettings(final Application application)
043        {
044                this.application = application;
045        }
046
047        /**
048         * {@inheritDoc}
049         */
050        @Override
051        public String getLocalizer()
052        {
053                return Stringz.className(application.getResourceSettings().getLocalizer());
054        }
055
056        /**
057         * {@inheritDoc}
058         */
059        @Override
060        public String getPackageResourceGuard()
061        {
062                return Stringz.className(application.getResourceSettings().getPackageResourceGuard());
063        }
064
065        /**
066         * {@inheritDoc}
067         */
068        @Override
069        public String getPropertiesFactory()
070        {
071                return Stringz.className(application.getResourceSettings().getPropertiesFactory());
072        }
073
074        /**
075         * {@inheritDoc}
076         */
077        @Override
078        public String getResourceFinders()
079        {
080                StringBuilder builder = new StringBuilder();
081                for (IResourceFinder rf : application.getResourceSettings().getResourceFinders())
082                {
083                        builder.append(Stringz.className(rf));
084                }
085                return builder.toString();
086        }
087
088        /**
089         * {@inheritDoc}
090         */
091        @Override
092        public String getResourcePollFrequency()
093        {
094                Duration duration = application.getResourceSettings().getResourcePollFrequency();
095                return (duration != null) ? duration.toString() : null;
096        }
097
098        /**
099         * {@inheritDoc}
100         */
101        @Override
102        public String getResourceStreamLocator()
103        {
104                return Stringz.className(application.getResourceSettings().getResourceStreamLocator());
105        }
106
107        /**
108         * {@inheritDoc}
109         */
110        @Override
111        public String[] getStringResourceLoaders()
112        {
113                List<IStringResourceLoader> loaders = application.getResourceSettings()
114                        .getStringResourceLoaders();
115                if (loaders != null)
116                {
117                        List<String> list = Generics.newArrayList();
118                        for (Object loader : loaders)
119                        {
120                                list.add(loader.toString());
121                        }
122                        return list.toArray(new String[0]);
123                }
124                return null;
125        }
126
127        /**
128         * {@inheritDoc}
129         */
130        @Override
131        public boolean getThrowExceptionOnMissingResource()
132        {
133                return application.getResourceSettings().getThrowExceptionOnMissingResource();
134        }
135
136        /**
137         * {@inheritDoc}
138         */
139        @Override
140        public boolean getUseDefaultOnMissingResource()
141        {
142                return application.getResourceSettings().getUseDefaultOnMissingResource();
143        }
144
145        /**
146         * {@inheritDoc}
147         */
148        @Override
149        public void setThrowExceptionOnMissingResource(final boolean throwExceptionOnMissingResource)
150        {
151                application.getResourceSettings().setThrowExceptionOnMissingResource(
152                        throwExceptionOnMissingResource);
153        }
154
155        /**
156         * {@inheritDoc}
157         */
158        @Override
159        public void setUseDefaultOnMissingResource(final boolean useDefaultOnMissingResource)
160        {
161                application.getResourceSettings().setUseDefaultOnMissingResource(
162                        useDefaultOnMissingResource);
163        }
164}