http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-core/juneau-config/src/main/java/org/apache/juneau/ini/package.html ---------------------------------------------------------------------- diff --git a/juneau-core/juneau-config/src/main/java/org/apache/juneau/ini/package.html b/juneau-core/juneau-config/src/main/java/org/apache/juneau/ini/package.html new file mode 100644 index 0000000..aeda8c4 --- /dev/null +++ b/juneau-core/juneau-config/src/main/java/org/apache/juneau/ini/package.html @@ -0,0 +1,661 @@ +<!DOCTYPE HTML> +<!-- +/*************************************************************************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + ***************************************************************************************************************************/ + --> +<html> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> + <style type="text/css"> + /* For viewing in Page Designer */ + @IMPORT url("../../../../../../javadoc.css"); + + /* For viewing in REST interface */ + @IMPORT url("../htdocs/javadoc.css"); + body { + margin: 20px; + } + </style> + <script> + /* Replace all @code and @link tags. */ + window.onload = function() { + document.body.innerHTML = document.body.innerHTML.replace(/\{\@code ([^\}]+)\}/g, '<code>$1</code>'); + document.body.innerHTML = document.body.innerHTML.replace(/\{\@link (([^\}]+)\.)?([^\.\}]+)\}/g, '<code>$3</code>'); + } + </script> +</head> +<body> +<p>INI file support</p> + +<script> + function toggle(x) { + var div = x.nextSibling; + while (div != null && div.nodeType != 1) + div = div.nextSibling; + if (div != null) { + var d = div.style.display; + if (d == 'block' || d == '') { + div.style.display = 'none'; + x.className += " closed"; + } else { + div.style.display = 'block'; + x.className = x.className.replace(/(?:^|\s)closed(?!\S)/g , '' ); + } + } + } +</script> + +<a id='TOC'></a><h5 class='toc'>Table of Contents</h5> +<ol class='toc'> + <li><p><a class='doclink' href='#Overview'>Overview</a></p> + <li><p><a class='doclink' href='#Variables'>Variables</a></p> + <li><p><a class='doclink' href='#Encoded'>Encoded Entries</a></p> + <li><p><a class='doclink' href='#Listeners'>Listeners</a></p> + <li><p><a class='doclink' href='#CommandLine'>Command Line API</a></p> + <li><p><a class='doclink' href='#Serializing'>Serializing Config Files</a></p> + <li><p><a class='doclink' href='#Merging'>Merging Config Files</a></p> +</ol> + +<!-- ======================================================================================================== --> +<a id="Overview"></a> +<h2 class='topic' onclick='toggle(this)'>1 - Overview</h2> +<div class='topic'> + <p> + The {@link org.apache.juneau.ini.ConfigFileBuilder} and {@link org.apache.juneau.ini.ConfigFile} classes + implement an API for working with INI-style configuration files such as the following: + </p> + <p class='bcode'> + <cc>#--------------------------</cc> + <cc># Default section</cc> + <cc>#--------------------------</cc> + <ck>key1</ck> = <cv>1</cv> + <ck>key2</ck> = <cv>true</cv> + <ck>key3</ck> = <cv>1,2,3</cv> + <ck>key4</ck> = <cv>http://foo</cv> + + <cc>#--------------------------</cc> + <cc># A comment about Section 1</cc> + <cc>#--------------------------</cc> + <cs>[Section1]</cs> + <ck>key1</ck> = <cv>2</cv> + <ck>key2</ck> = <cv>false</cv> + <ck>key3</ck> = <cv>4,5,6</cv> + <ck>key4</ck> = <cv>http://bar</cv> + </p> + + <p> + The {@link org.apache.juneau.ini.ConfigFileBuilder} class is used to instantiate instances of + {@link org.apache.juneau.ini.ConfigFile} which can then be used to retrieve config file values through either + <js>"key"</js> or <js>"Section/key"</js> identifiers. + </p> + + <p class='bcode'> + <jk>int</jk> key1; + <jk>boolean</jk> key2; + <jk>int</jk>[] key3; + URL key4; + + <jc>// Get our config file using the default config manager</jc> + ConfigFile f = <jk>new</jk> ConfigFileBuilder().build(<js>"C:/temp/MyConfig.cfg"</js>); + + <jc>// Read values from default section</jc> + key1 = f.getInt(<js>"key1"</js>); + key2 = f.getBoolean(<js>"key2"</js>); + key3 = f.getObject(<jk>int</jk>[].<jk>class</jk>, <js>"key3"</js>); + key4 = f.getObject(URL.<jk>class</jk>, <js>"key4"</js>); + + <jc>// Read values from Section #1</jc> + key1 = f.getInt(<js>"Section1/key1"</js>); + key2 = f.getBoolean(<js>"Section1/key2"</js>); + key3 = f.getObject(<jk>int</jk>[].<jk>class</jk>, <js>"Section1/key3"</js>); + key4 = f.getObject(URL.<jk>class</jk>, <js>"Section1/key4"</js>); + </p> + + <p> + The interface also allows config files to be constructed programmatically... + </p> + + <p class='bcode'> + <jc>// Construct the sample INI file programmatically</jc> + ConfigFile f = <jk>new</jk> ConfigFileBuilder().build(<js>"C:/temp/MyConfig.cfg"</js>, <jk>true</jk>) + .addLines(<jk>null</jk>, <jc>// The default 'null' section</jc> + <js>"# Default section"</js>, <jc>// A regular comment</jc> + <js>"key1 = 1"</js>, <jc>// A numeric entry</jc> + <js>"key2 = true"</js>, <jc>// A boolean entry</jc> + <js>"key3 = 1,2,3"</js>, <jc>// An array entry</jc> + <js>"key4 = http://foo"</js>, <jc>// A POJO entry</jc> + <js>""</js>) <jc>// A blank line</jc> + .addHeaderComments(<js>"Section1"</js>, <jc>// The 'Section1' section</jc> + <js>"A comment about Section 1"</js>) <jc>// A header comment</jc> + .addLines(<js>"Section1"</js>, <jc>// The 'Section1' section</jc> + <js>"key1 = 2"</js>, <jc>// A numeric entry</jc> + <js>"key2 = false"</js>, <jc>// A boolean entry</jc> + <js>"key3 = 4,5,6"</js>, <jc>// An array entry</jc> + <js>"key4 = http://bar"</js>) <jc>// A POJO entry</jc> + .save(); <jc>// Save to MyConfig.cfg</jc> + </p> + + <p> + The following is equivalent, except uses {@link org.apache.juneau.ini.ConfigFile#put(String,Object)} to set values. + Note how we're setting values as POJOs which will be automatically converted to strings when persisted to disk. + <p class='bcode'> + <jc>// Construct the sample INI file programmatically</jc> + ConfigFile f = <jk>new</jk> ConfigFileBuilder().build(<js>"C:/temp/MyConfig.cfg"</js>, <jk>true</jk>) + .addLines(<jk>null</jk>, + <js>"# Default section"</js>) + .addHeaderComments(<js>"Section1"</js>, + <js>"A comment about Section 1"</js>); + cf.put(<js>"key1"</js>, 1); + cf.put(<js>"key2"</js>, <jk>true</jk>); + cf.put(<js>"key3"</js>, <jk>new int</jk>[]{1,2,3}); + cf.put(<js>"key4"</js>, <jk>new</jk> URL(<js>"http://foo"</js>)); + cf.put(<js>"Section1/key1"</js>, 2); + cf.put(<js>"Section1/key2"</js>, <jk>false</jk>); + cf.put(<js>"Section1/key3"</js>, <jk>new int</jk>[]{4,5,6}); + cf.put(<js>"Section1/key4"</js>, <jk>new</jk> URL(<js>"http://bar"</js>)); + cf.save(); + </p> + <p> + Refer to {@link org.apache.juneau.ini.ConfigFile#put(String,Object,boolean)} for a description of + formats for various data types. + </p> + <p> + Various convenience getter methods are provided for retrieving different data types: + </p> + <p class='bcode'> + <jc>// Strings with default values</jc> + <jc>// key1 = foobar</jc> + String key1 = cf.getString(<js>"key1"</js>); + + <jc>// Numbers</jc> + <jc>// key2 = 123</jc> + <jk>float</jk> key2 = cf.getObject(<jk>float</jk>.<jk>class</jk>, <js>"key2"</js>); + + <jc>// Booleans</jc> + <jc>// key3 = true</jc> + <jk>boolean</jk> key3 = cf.getBoolean(<js>"key3"</js>); + + <jc>// Objects convertable to and from strings using the JSON serializer and parser</jc> + <jc>// key4 = http://foo</jc> + URL key4 = cf.getObject(URL.<jk>class</jk>, <js>"key4"</js>); + + <jc>// Arrays of strings</jc> + <jc>// key5 = foo, bar</jc> + String[] key5 = cf.getStringArray(<js>"key5"</js>); + + <jc>// Arrays of objects</jc> + <jc>// key6 = http://foo,http://bar</jc> + URL[] key6 = cf.getObject(URL[].<jk>class</jk>, <js>"key6"</js>); + + <jc>// Arrays of primitives</jc> + <jc>// key7 = 1,2,3</jc> + <jk>int</jk>[] key7 = cf.getObject(<jk>int</jk>[].<jk>class</jk>, <js>"key7"</js>); + + <jc>// Enums</jc> + <jc>// key8 = MINUTES</jc> + TimeUnit key8 = cf.getObject(TimeUnit.<jk>class</jk>, <js>"key8"</js>); + + <jc>// Beans</jc> + <jc>// key9 = {name:'John Smith', addresses:[{street:'101 Main St', city:'Anywhere', state:'TX'}]}</jc> + Person key9 = cf.getObject(Person.<jk>class</jk>, <js>"key9"</js>); + + <jc>// Generic Maps</jc> + <jc>// key10 = {foo:'bar', baz:123}</jc> + Map key10 = cf.getObject(ObjectMap.<jk>class</jk>, <js>"key10"</js>); + </p> +</div> + +<!-- ======================================================================================================== --> +<a id="Variables"></a> +<h2 class='topic' onclick='toggle(this)'>2 - Variables</h2> +<div class='topic'> + <p> + Config files can contain variables that get resolved dynamically using the + {@link org.apache.juneau.svl.VarResolver} API. + </p> + <p> + Resolving config files can be retrieved through the following methods: + </p> + <ul class='spaced-list'> + <li> + {@link org.apache.juneau.ini.ConfigFile#getResolving()} - Returns a config file that resolves a default + set of variables. + <li> + {@link org.apache.juneau.ini.ConfigFile#getResolving(VarResolver)} - Returns a config file that resolves + a custom set of variables. + </ul> + <p> + The default {@link org.apache.juneau.ini.ConfigFile#getResolving()} method returns a config file that resolves + the following variables: + </p> + <ul class='spaced-list'> + <li> + <code>$S{key}</code>, <code>$S{key,default}</code> - System properties. + <li> + <code>$E{key}</code>, <code>$E{key,default}</code> - Environment variables. + <li> + <code>$C{key}</code>, <code>$C{key,default}</code> - Values in this configuration file. + </ul> + + <h6 class='topic'>Examples:</h6> + <p class='bcode'> + <cc>#--------------------------</cc> + <cc># Examples </cc> + <cc>#--------------------------</cc> + <cs>[MyProperties]</cs> + <ck>javaHome</ck> = <cv>$S{java.home}</cv> + <ck>path</ck> = <cv>$E{PATH}</cv> + <ck>customMessage</ck> = <cv>Java home is $C{MyProperties/javaHome} and the environment path is $C{MyProperties/path}.</cv> + </p> + <p> + Support for variables is extensible. You can add support for your own variables by implementing custom + {@link org.apache.juneau.svl.VarResolver VarResolvers}. + <br>For example, the microservice <code>Resource</code> class provides access to config files that + can contain any of the following variables: + </p> + <ul> + <li><code>$C</code> - Config variables. + <li><code>$S</code> - System properties. + <li><code>$E</code> - Environment variables. + <li><code>$I</code> - Servlet init parameters. + <li><code>$ARG</code> - JVM command-line arguments. + <li><code>$MF</code> - Main jar manifest file entries. + <li><code>$L</code> - Localized strings. + <li><code>$A</code> - HTTP request attributes. + <li><code>$P</code> - HTTP request URL parameters. + <li><code>$R</code> - HTTP request variables. + <li><code>$UE</code> - URL-encoding function. + </ul> +</div> + +<!-- ======================================================================================================== --> +<a id="Encoded"></a> +<h2 class='topic' onclick='toggle(this)'>3 - Encoded Entries</h2> +<div class='topic'> + <p> + If a config file contains sensitive information such as passwords, those values can be + marked for encoding by appending <js>'*'</js> to the end of the key name. + <br>If a marked and unencoded value is detected in the file during load, it will be encoded and saved immediately. + </p> + <p> + For example, the following password is marked for encoding.... + </p> + <p class='bcode'> + <cs>[MyHost]</cs> + <ck>url</ck> = <cv>http://localhost:9080/foo</cv> + <ck>user</ck> = <cv>me</cv> + <ck>password*</ck> = <cv>mypassword</cv> + </p> + <p> + After initial loading, the file contents will contain an encoded value... + </p> + <p class='bcode'> + <cs>[MyHost]</cs> + <ck>url</ck> = <cv>http://localhost:9080/foo</cv> + <ck>user</ck> = <cv>me</cv> + <ck>password*</ck> = <cv>{AwwJVhwUQFZEMg==}</cv> + </p> + <p> + The default encoder is {@link org.apache.juneau.ini.XorEncoder} which is a simple XOR+Base64 encoder. + <br>If desired, custom encoder can be used by implementing the {@link org.apache.juneau.ini.Encoder} + interface and creating your own <code>ConfigFileBuilder</code> using the + {@link org.apache.juneau.ini.ConfigFileBuilder#encoder(Encoder)} method. + </p> +</div> + +<!-- ======================================================================================================== --> +<a id="Listeners"></a> +<h2 class='topic' onclick='toggle(this)'>4 - Listeners</h2> +<div class='topic'> + <p> + The following method is provided for listening to changes made on config files: + </p> + <p> + {@link org.apache.juneau.ini.ConfigFile#addListener(ConfigFileListener)}. + </p> + <p> + Subclasses are provided for listening for different kinds of events: + </p> + <ul class='spaced-list'> + <li> + {@link org.apache.juneau.ini.ConfigFileListener} - Config file is saved, loaded, or modified. + <li> + {@link org.apache.juneau.ini.SectionListener} - One or more entries in a section are modified. + <li> + {@link org.apache.juneau.ini.EntryListener} - An individual entry is modified. + </ul> + + <h6 class="topic">Example:</h6> + <p class='bcode'> + <jc>// Get our config file using the default config manager</jc> + ConfigFile f = <jk>new</jk> ConfigFileBuilder().build(<js>"C:/temp/MyConfig.cfg"</js>); + + <jc>// Add a listener for an entry</jc> + f.addListener( + <jk>new</jk> EntryListener(<js>"Section1/key1"</js>) { + <ja>@Override</ja> + <jk>public void</jk> onChange(ConfigFile cf) { + System.<jsf>err</jsf>.println(<js>"Entry changed! New value is "</js> + cf.getString(<js>"Section1/key1"</js>)); + } + } + ); + </p> +</div> + +<!-- ======================================================================================================== --> +<a id="CommandLine"></a> +<h2 class='topic' onclick='toggle(this)'>5 - Command Line API</h2> +<div class='topic'> + <p> + The {@link org.apache.juneau.ini.ConfigFileBuilder} class contains a + {@link org.apache.juneau.ini.ConfigFileBuilder#main(String[])} method that can be used to work with config + files through a command-line prompt. + <br>This is invoked as a normal Java command: + </p> + <p class='bcode'> + java -jar juneau.jar org.apache.juneau.ini.ConfigFileBuilder [args] + </p> + <p> + Arguments can be any of the following... + </p> + <ul class='spaced-list'> + <li> + No arguments + <br>Prints usage message. + <li> + <code>createBatchEnvFile -configfile <configFile> -envfile <batchFile> [-verbose]</code> + <br>Creates a batch file that will set each config file entry as an environment variable. + <br>Characters in the keys that are not valid as environment variable names (e.g. <js>'/'</js> and <js>'.'</js>) + will be converted to underscores. + <li> + <code>createShellEnvFile -configFile <configFile> -envFile <configFile> [-verbose]</code> + Creates a shell script that will set each config file entry as an environment variable. + <br>Characters in the keys that are not valid as environment variable names (e.g. <js>'/'</js> and <js>'.'</js>) + will be converted to underscores. + <li> + <code>setVals -configFile <configFile> -vals [var1=val1 [var2=val2...]] [-verbose]</code> + Sets values in config files. + </ul> + <p> + For example, the following command will create the file <code>'MyConfig.bat'</code> from the contents of the + file <code>'MyConfig.cfg'</code>. + </p> + <p class='bcode'> + java org.apache.juneau.ini.ConfigFileBuilder createBatchEnvFile -configfile C:\foo\MyConfig.cfg -batchfile C:\foo\MyConfig.bat + </p> +</div> + +<!-- ======================================================================================================== --> +<a id="Serializing"></a> +<h2 class='topic' onclick='toggle(this)'>6 - Serializing Config Files</h2> +<div class='topic'> + <p> + Instances of {@link org.apache.juneau.ini.ConfigFile} are POJOs that can be serialized to and parsed from + all supported Juneau languages. + </p> + <p> + The <code>org.apache.juneau.microservice.resources.ConfigResource</code> is a predefined REST interface that + allows access to the config file used by a microservice. + <br>The <code>juneau-examples-rest</code> project is a microservice that includes this resource + at <code>http://localhost:10000/sample/config</code>. + <br>The sample microservice uses the following config file <code>juneau-examples.cfg</code>: + </p> + <p class='bcode'> + <cc>#================================================================================ + # Basic configuration file for SaaS microservices + # Subprojects can use this as a starting point. + #================================================================================</cc> + + <cc>#================================================================================ + # REST settings + #================================================================================</cc> + <cs>[REST]</cs> + + <cc># The HTTP port number to use. + # Default is Rest-Port setting in manifest file, or 8000.</cc> + <ck>port</ck> = <cv>10000</cv> + + <cc># A JSON map of servlet paths to servlet classes. + # Example: + # resourceMap = {'/*':'com.foo.MyServlet'} + # Either resourceMap or resources must be specified.</cc> + <ck>resourceMap</ck> = + + <cc># A comma-delimited list of names of classes that extend from Servlet. + # Resource paths are pulled from @RestResource.path() annotation, or + # "/*" if annotation not specified. + # Example: + # resources = com.foo.MyServlet + # Default is Rest-Resources in manifest file. + # Either resourceMap or resources must be specified.</cc> + <ck>resources</ck> = + + <cc># The context root of the Jetty server. + # Default is Rest-ContextPath in manifest file, or "/".</cc> + <ck>contextPath</ck> = + + <cc># Authentication: NONE, BASIC.</cc> + <ck>authType</ck> = <cv>NONE</cv> + + <cc># The BASIC auth username. + # Default is Rest-LoginUser in manifest file.</cc> + <ck>loginUser</ck> = + + <cc># The BASIC auth password. + # Default is Rest-LoginPassword in manifest file.</cc> + <ck>loginPassword</ck> = + + <cc># The BASIC auth realm. + # Default is Rest-AuthRealm in manifest file.</cc> + <ck>authRealm</ck> = + + <cc># Stylesheet to use for HTML views. + # The default options are: + # - styles/juneau.css + # - styles/devops.css + # Other stylesheets can be referenced relative to the servlet package or working + # directory.</cc> + <ck>stylesheet</ck> = <cv>styles/devops.css</cv> + + <cc># What to do when the config file is saved. + # Possible values: + # NOTHING - Don't do anything. + # RESTART_SERVER - Restart the Jetty server. + # RESTART_SERVICE - Shutdown and exit with code '3'.</cc> + <ck>saveConfigAction</ck> = <cv>RESTART_SERVER</cv> + + <cc># Enable SSL support.</cc> + <ck>useSsl</ck> = false + + <cc>#================================================================================ + # Bean properties on the org.eclipse.jetty.util.ssl.SslSocketFactory class + #-------------------------------------------------------------------------------- + # Ignored if REST/useSsl is false. + #================================================================================</cc> + <cs>[REST-SslContextFactory]</cs> + <ck>keyStorePath</ck> = <cv>client_keystore.jks</cv> + <ck>keyStorePassword*</ck> = <cv>{HRAaRQoT}</cv> + <ck>excludeCipherSuites</ck> = <cv>TLS_DHE.*, TLS_EDH.*</cv> + <ck>excludeProtocols</ck> = <cv>SSLv3</cv> + <ck>allowRenegotiate</ck> = <cv>false</cv> + + <cc>#================================================================================ + # Logger settings + # See FileHandler Java class for details. + #================================================================================</cc> + <cs>[Logging]</cs> + + <cc># The directory where to create the log file. + # Default is "."</cc> + <ck>logDir</ck> = <cv>logs</cv> + + <cc># The name of the log file to create for the main logger. + # The logDir and logFile make up the pattern that's passed to the FileHandler + # constructor. + # If value is not specified, then logging to a file will not be set up.</cc> + <ck>logFile</ck> = <cv>microservice.%g.log</cv> + + <cc># Whether to append to the existing log file or create a new one. + # Default is false.</cc> + <ck>append</ck> = + + <cc># The SimpleDateFormat format to use for dates. + # Default is "yyyy.MM.dd hh:mm:ss".</cc> + <ck>dateFormat</ck> = + + <cc># The log message format. + # The value can contain any of the following variables: + # {date} - The date, formatted per dateFormat. + # {class} - The class name. + # {method} - The method name. + # {logger} - The logger name. + # {level} - The log level name. + # {msg} - The log message. + # {threadid} - The thread ID. + # {exception} - The localized exception message. + # Default is "[{date} {level}] {msg}%n".</cc> + <ck>format</ck> = + + <cc># The maximum log file size. + # Suffixes available for numbers. + # See ConfigFile.getInt(String,int) for details. + # Default is 1M.</cc> + <ck>limit</ck> = <cv>10M</cv> + + <cc># Max number of log files. + # Default is 1.</cc> + <ck>count</ck> = <cv>5</cv> + + <cc># Default log levels. + # Keys are logger names. + # Values are serialized Level POJOs.</cc> + <ck>levels</ck> = <cv>{ org.apache.juneau:'INFO' }</cv> + + <cc># Only print unique stack traces once and then refer to them by a simple 8 character hash identifier. + # Useful for preventing log files from filling up with duplicate stack traces. + # Default is false.</cc> + <ck>useStackTraceHashes</ck> = <cv>true</cv> + + <cc># The default level for the console logger. + # Default is WARNING.</cc> + <ck>consoleLevel</ck> = + + <cc>#================================================================================ + # System properties + #-------------------------------------------------------------------------------- + # These are arbitrary system properties that are set during startup. + #================================================================================</cc> + <cs>[SystemProperties]</cs> + + <cc># Configure Jetty for StdErrLog Logging</cc> + <ck>org.eclipse.jetty.util.log.class</ck> = <cv>org.eclipse.jetty.util.log.StrErrLog</cv> + + <cc># Jetty logging level</cc> + <ck>org.eclipse.jetty.LEVEL</ck> = <cv>WARN</cv> + </p> + <p> + The config file looks deceivingly simple. + However, it should be noticed that the config file is a VERY powerful feature with many capabilities including: + </p> + <p> + When you point your browser to this resource, you'll notice that the contents of the config file are being + serialized to HTML as a POJO: + </p> + <img class='bordered' src="doc-files/config1.png"> + <p> + Likewise, the config file can also be serialized as any of the supported languages such as JSON: + </p> + <img class='bordered' src="doc-files/config2.png"> + <p> + The code for implementing this page could not be any simpler, since it simply returns the config file returned + by the <code>RestServlet.getConfig()</code> method. + </p> + <p class='bcode'> + <jd>/** + * [GET /] - Show contents of config file. + * + * <ja>@return</ja> The config file. + * <ja>@throws</ja> Exception + */</jd> + <ja>@RestMethod</ja>(name=<js>"GET"</js>, path=<js>"/"</js>, description=<js>"Show contents of config file."</js>) + <jk>public</jk> ConfigFile getConfigContents() <jk>throws</jk> Exception { + <jk>return</jk> getConfig(); + } + </p> + <p> + The edit page takes you to an editor that allows you to modify the contents of the config file: + </p> + <img class='bordered' src="doc-files/config3.png"> + <p> + This latter page uses the {@link org.apache.juneau.ini.ConfigFile#toString()} method to retrieve the + contents of the config file in INI format. + </p> + <p> + Since config files are serializable, that mean they can also be retrieved through the <code>RestClient</code> + API. + </p> + <p class='bcode'> + <jc>// Create a new REST client with JSON support</jc> + RestClient c = <jk>new</jk> RestClientBuilder().build(); + + <jc>// Retrieve config file through REST interface</jc> + ConfigFile cf = c.doGet(<js>"http://localhost:10000/sample/config"</js>).getResponse(ConfigFileImpl.<jk>class</jk>); + </p> +</div> + +<!-- ======================================================================================================== --> +<a id="Merging"></a> +<h2 class='topic' onclick='toggle(this)'>7 - Merging Config Files</h2> +<div class='topic'> + <p> + In the previous example, an edit page was shown that allows you to edit config files through + a REST interface. + <br>Note that if only a single entry is modified in the config file, we only want to trigger + listeners for that change, not trigger all listeners. + <br>This is where the {@link org.apache.juneau.ini.ConfigFile#merge(ConfigFile)} method comes into play. + <br>This method will copy the contents of one config file over to another config file, but only + trigger listeners when the values are different. + </p> + <p> + The edit page is implemented with this method which is a simple PUT with the contents of the new INI file as + the body of the HTTP request: + </p> + <p class='bcode'> + <jd>/** + * [PUT /] - Sets contents of config file. + * + * <ja>@param</ja> contents The new contents of the config file. + * <ja>@return</ja> The new config file contents. + * <ja>@throws</ja> Exception + */</jd> + <ja>@RestMethod</ja>(name=<js>"PUT"</js>, path=<js>"/"</js>, + description=<js>"Sets contents of config file."</js>, + parameters={ + <ja>@Parameter</ja>(in=<js>"body"</js>, description=<js>"New contents in INI file format."</js>) + } + ) + <jk>public</jk> ConfigFile setConfigContents(<ja>@Body</ja> Reader contents) <jk>throws</jk> Exception { + + <jc>// Create a new in-memory config file based on the contents of the HTTP request.</jc> + ConfigFile cf2 = new ConfigFileBuilder.build().load(contents); + + <jc>// Merge the in-memory config file into the existing config file and save it. + // Then return the modified config file to be parsed as a POJO.</jc> + <jk>return</jk> getConfig().merge(cf2).save(); + } + </p> +</div> + +</body> +</html> \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-distrib/.gitignore ---------------------------------------------------------------------- diff --git a/juneau-distrib/.gitignore b/juneau-distrib/.gitignore deleted file mode 100644 index d274d47..0000000 --- a/juneau-distrib/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -/target/ -/.settings/ -/.DS_Store http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-distrib/.project ---------------------------------------------------------------------- diff --git a/juneau-distrib/.project b/juneau-distrib/.project deleted file mode 100644 index 479f33b..0000000 --- a/juneau-distrib/.project +++ /dev/null @@ -1,31 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - *************************************************************************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations under the License. * - *************************************************************************************************************************** ---> -<projectDescription> - <name>juneau-distrib</name> - <comment></comment> - <projects> - </projects> - <buildSpec> - <buildCommand> - <name>org.eclipse.m2e.core.maven2Builder</name> - <arguments> - </arguments> - </buildCommand> - </buildSpec> - <natures> - <nature>org.eclipse.m2e.core.maven2Nature</nature> - </natures> -</projectDescription> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-distrib/pom.xml ---------------------------------------------------------------------- diff --git a/juneau-distrib/pom.xml b/juneau-distrib/pom.xml deleted file mode 100644 index 463b6d2..0000000 --- a/juneau-distrib/pom.xml +++ /dev/null @@ -1,175 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - *************************************************************************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations under the License. * - *************************************************************************************************************************** ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <artifactId>juneau-distrib</artifactId> - <packaging>pom</packaging> - <name>Apache Juneau Distribution</name> - <description>Location to find fully built Juneau distributions.</description> - - <parent> - <groupId>org.apache.juneau</groupId> - <artifactId>juneau</artifactId> - <version>6.3.2-incubating-SNAPSHOT</version> - </parent> - - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-dependency-plugin</artifactId> - <executions> - <execution> - <id>copy</id> - <phase>package</phase> - <goals> - <goal>copy</goal> - </goals> - <configuration> - <artifactItems> - - <artifactItem> - <outputDirectory>${project.build.directory}/bin</outputDirectory> - <groupId>org.apache.juneau</groupId> - <artifactId>juneau-all</artifactId> - <version>${project.version}</version> - </artifactItem> - <artifactItem> - <outputDirectory>${project.build.directory}/src</outputDirectory> - <groupId>org.apache.juneau</groupId> - <artifactId>juneau-all</artifactId> - <version>${project.version}</version> - <type>jar</type> - <classifier>sources</classifier> - </artifactItem> - - <artifactItem> - <outputDirectory>${project.build.directory}/src/osgi-bundles</outputDirectory> - <groupId>org.apache.juneau</groupId> - <artifactId>juneau-core</artifactId> - <version>${project.version}</version> - <type>jar</type> - <classifier>sources</classifier> - </artifactItem> - <artifactItem> - <outputDirectory>${project.build.directory}/bin/osgi-bundles</outputDirectory> - <groupId>org.apache.juneau</groupId> - <artifactId>juneau-core</artifactId> - <version>${project.version}</version> - </artifactItem> - - <artifactItem> - <outputDirectory>${project.build.directory}/src/osgi-bundles</outputDirectory> - <groupId>org.apache.juneau</groupId> - <artifactId>juneau-core-rdf</artifactId> - <version>${project.version}</version> - <type>jar</type> - <classifier>sources</classifier> - </artifactItem> - <artifactItem> - <outputDirectory>${project.build.directory}/bin/osgi-bundles</outputDirectory> - <groupId>org.apache.juneau</groupId> - <artifactId>juneau-core-rdf</artifactId> - <version>${project.version}</version> - </artifactItem> - - <artifactItem> - <outputDirectory>${project.build.directory}/src/osgi-bundles</outputDirectory> - <groupId>org.apache.juneau</groupId> - <artifactId>juneau-rest</artifactId> - <version>${project.version}</version> - <type>jar</type> - <classifier>sources</classifier> - </artifactItem> - <artifactItem> - <outputDirectory>${project.build.directory}/bin/osgi-bundles</outputDirectory> - <groupId>org.apache.juneau</groupId> - <artifactId>juneau-rest</artifactId> - <version>${project.version}</version> - </artifactItem> - - <artifactItem> - <outputDirectory>${project.build.directory}/src/osgi-bundles</outputDirectory> - <groupId>org.apache.juneau</groupId> - <artifactId>juneau-rest-jaxrs</artifactId> - <version>${project.version}</version> - <type>jar</type> - <classifier>sources</classifier> - </artifactItem> - <artifactItem> - <outputDirectory>${project.build.directory}/bin/osgi-bundles</outputDirectory> - <groupId>org.apache.juneau</groupId> - <artifactId>juneau-rest-jaxrs</artifactId> - <version>${project.version}</version> - </artifactItem> - - <artifactItem> - <outputDirectory>${project.build.directory}/src/osgi-bundles</outputDirectory> - <groupId>org.apache.juneau</groupId> - <artifactId>juneau-rest-client</artifactId> - <version>${project.version}</version> - <type>jar</type> - <classifier>sources</classifier> - </artifactItem> - <artifactItem> - <outputDirectory>${project.build.directory}/bin/osgi-bundles</outputDirectory> - <groupId>org.apache.juneau</groupId> - <artifactId>juneau-rest-client</artifactId> - <version>${project.version}</version> - </artifactItem> - - <artifactItem> - <outputDirectory>${project.build.directory}/src/osgi-bundles</outputDirectory> - <groupId>org.apache.juneau</groupId> - <artifactId>juneau-microservice</artifactId> - <version>${project.version}</version> - <type>jar</type> - <classifier>sources</classifier> - </artifactItem> - <artifactItem> - <outputDirectory>${project.build.directory}/bin/osgi-bundles</outputDirectory> - <groupId>org.apache.juneau</groupId> - <artifactId>juneau-microservice</artifactId> - <version>${project.version}</version> - </artifactItem> - - </artifactItems> - </configuration> - </execution> - </executions> - </plugin> - <plugin> - <artifactId>maven-assembly-plugin</artifactId> - <executions> - <execution> - <id>juneau-assembly</id> - <phase>package</phase> - <goals> - <goal>single</goal> - </goals> - <configuration> - <finalName>apache-juneau-${project.version}</finalName> - <descriptors> - <descriptor>src/assembly/src.xml</descriptor> - <descriptor>src/assembly/bin.xml</descriptor> - </descriptors> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> -</project> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-distrib/src/assembly/bin.xml ---------------------------------------------------------------------- diff --git a/juneau-distrib/src/assembly/bin.xml b/juneau-distrib/src/assembly/bin.xml deleted file mode 100644 index 335f164..0000000 --- a/juneau-distrib/src/assembly/bin.xml +++ /dev/null @@ -1,44 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - *************************************************************************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations under the License. * - *************************************************************************************************************************** ---> -<assembly - xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd"> - <id>bin</id> - <formats> - <format>zip</format> - </formats> - <includeBaseDirectory>false</includeBaseDirectory> - <fileSets> - <fileSet> - <includes> - <include>**</include> - </includes> - <directory>target/bin</directory> - <outputDirectory>apache-juneau-${project.version}</outputDirectory> - </fileSet> - <fileSet> - <includes> - <include>DISCLAIMER</include> - <include>LICENSE</include> - <include>NOTICE</include> - <include>RELEASE-NOTES.txt</include> - </includes> - <directory>..</directory> - <outputDirectory>apache-juneau-${project.version}</outputDirectory> - </fileSet> - </fileSets> -</assembly> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-distrib/src/assembly/src.xml ---------------------------------------------------------------------- diff --git a/juneau-distrib/src/assembly/src.xml b/juneau-distrib/src/assembly/src.xml deleted file mode 100644 index ee6ae99..0000000 --- a/juneau-distrib/src/assembly/src.xml +++ /dev/null @@ -1,43 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - *************************************************************************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations under the License. * - *************************************************************************************************************************** ---> -<assembly - xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd"> - <id>src</id> - <formats> - <format>zip</format> - </formats> - <includeBaseDirectory>false</includeBaseDirectory> - <fileSets> - <fileSet> - <includes> - <include>**</include> - </includes> - <directory>target/src</directory> - <outputDirectory>apache-juneau-${project.version}</outputDirectory> - </fileSet> - <fileSet> - <includes> - <include>LICENSE</include> - <include>NOTICE</include> - <include>RELEASE-NOTES.txt</include> - </includes> - <directory>..</directory> - <outputDirectory>apache-juneau-${project.version}</outputDirectory> - </fileSet> - </fileSets> -</assembly> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-examples-rest/.classpath ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/.classpath b/juneau-examples-rest/.classpath deleted file mode 100644 index bfe718b..0000000 --- a/juneau-examples-rest/.classpath +++ /dev/null @@ -1,36 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<classpath> - <classpathentry kind="src" output="target/test-classes" path="src/test/java"> - <attributes> - <attribute name="optional" value="true"/> - <attribute name="maven.pomderived" value="true"/> - </attributes> - </classpathentry> - <classpathentry kind="src" output="target/classes" path="src/main/java"> - <attributes> - <attribute name="optional" value="true"/> - <attribute name="maven.pomderived" value="true"/> - </attributes> - </classpathentry> - <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"> - <attributes> - <attribute name="maven.pomderived" value="true"/> - </attributes> - </classpathentry> - <classpathentry kind="src" path="/juneau-microservice"/> - <classpathentry kind="src" path="/juneau-rest"/> - <classpathentry kind="src" path="/juneau-core"/> - <classpathentry kind="src" path="/juneau-core-rdf"/> - <classpathentry kind="src" path="/juneau-rest-client"/> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"> - <attributes> - <attribute name="maven.pomderived" value="true"/> - </attributes> - </classpathentry> - <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> - <attributes> - <attribute name="maven.pomderived" value="true"/> - </attributes> - </classpathentry> - <classpathentry kind="output" path="target/classes"/> -</classpath> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-examples-rest/.gitignore ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/.gitignore b/juneau-examples-rest/.gitignore deleted file mode 100644 index d274d47..0000000 --- a/juneau-examples-rest/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -/target/ -/.settings/ -/.DS_Store http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-examples-rest/.project ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/.project b/juneau-examples-rest/.project deleted file mode 100644 index 8a73b4c..0000000 --- a/juneau-examples-rest/.project +++ /dev/null @@ -1,41 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - *************************************************************************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations under the License. * - *************************************************************************************************************************** ---> -<projectDescription> - <name>juneau-examples-rest</name> - <comment>Sample code packaged as a microservice. NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.</comment> - <projects> - <project>juneau-microservice</project> - <project>juneau-rest</project> - <project>juneau-core</project> - <project>juneau-rest-client</project> - </projects> - <buildSpec> - <buildCommand> - <name>org.eclipse.jdt.core.javabuilder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>org.eclipse.m2e.core.maven2Builder</name> - <arguments> - </arguments> - </buildCommand> - </buildSpec> - <natures> - <nature>org.eclipse.m2e.core.maven2Nature</nature> - <nature>org.eclipse.jdt.core.javanature</nature> - </natures> -</projectDescription> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-examples-rest/examples.cfg ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/examples.cfg b/juneau-examples-rest/examples.cfg deleted file mode 100755 index b54711b..0000000 --- a/juneau-examples-rest/examples.cfg +++ /dev/null @@ -1,94 +0,0 @@ -# *************************************************************************************************************************** -# * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -# * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -# * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -# * with the License. You may obtain a copy of the License at * -# * * -# * http://www.apache.org/licenses/LICENSE-2.0 * -# * * -# * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -# * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -# * specific language governing permissions and limitations under the License. * -# *************************************************************************************************************************** - -#================================================================================ -# Basic configuration file for SaaS microservices -# Subprojects can use this as a starting point. -#================================================================================ - -#================================================================================ -# REST settings -#================================================================================ -[REST] - -jettyXml = jetty.xml - -# Stylesheet to use for HTML views. -# The default options are: -# - styles/juneau.css -# - styles/devops.css -# Other stylesheets can be referenced relative to the servlet package or working -# directory. -stylesheet = styles/devops.css - -# What to do when the config file is saved. -# Possible values: -# NOTHING - Don't do anything. -# RESTART_SERVER - Restart the Jetty server. -# RESTART_SERVICE - Shutdown and exit with code '3'. -saveConfigAction = RESTART_SERVER - -#================================================================================ -# Logger settings -# See FileHandler Java class for details. -#================================================================================ -[Logging] -logDir = $S{user.dir}/target/logs -logFile = sample.%g.log -dateFormat = yyyy.MM.dd hh:mm:ss -format = [{date} {level}] {msg}%n -append = false -limit = 10M -count = 5 -levels = { org.apache.juneau:'INFO' } -useStackTraceHashes = true -consoleLevel = WARNING - -#================================================================================ -# System properties -#-------------------------------------------------------------------------------- -# These are arbitrary system properties that can be set during startup. -#================================================================================ -[SystemProperties] - -# Configure Jetty for StdErrLog Logging -org.eclipse.jetty.util.log.class = org.eclipse.jetty.util.log.StrErrLog - -# Jetty logging level -org.eclipse.jetty.LEVEL = WARN - -derby.stream.error.file = $S{user.dir}/target/logs/derby.log - -#================================================================================ -# DockerRegistryResource properties -#================================================================================ -[DockerRegistry] -url = http://docker.apache.org:5000/v1 - -#================================================================================ -# SqlQueryResource properties -#================================================================================ -[SqlQueryResource] -driver = org.apache.derby.jdbc.EmbeddedDriver -directory = $S{user.dir}/target/derby/testDB -connectionUrl = jdbc:derby:$C{SqlQueryResource/directory};create=true -allowTempUpdates = true -includeRowNums = true - -#================================================================================ -# Source code location -#================================================================================ -[Source] -gitHub = https://github.com/apache/incubator-juneau/blob/master/juneau-examples-rest/src/main/java - - http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-examples-rest/jetty.xml ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/jetty.xml b/juneau-examples-rest/jetty.xml deleted file mode 100644 index 71e5d04..0000000 --- a/juneau-examples-rest/jetty.xml +++ /dev/null @@ -1,61 +0,0 @@ -<?xml version="1.0"?> -<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd"> -<!-- - *************************************************************************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations under the License. * - *************************************************************************************************************************** ---> - -<Configure id="ExampleServer" class="org.eclipse.jetty.server.Server"> - - <Set name="connectors"> - <Array type="org.eclipse.jetty.server.Connector"> - <Item> - <New class="org.eclipse.jetty.server.ServerConnector"> - <Arg> - <Ref refid="ExampleServer" /> - </Arg> - <Set name="port">10000</Set> - </New> - </Item> - </Array> - </Set> - - <New id="context" class="org.eclipse.jetty.servlet.ServletContextHandler"> - <Set name="contextPath">/</Set> - <Call name="addServlet"> - <Arg>org.apache.juneau.examples.rest.RootResources</Arg> - <Arg>/*</Arg> - </Call> - <Set name="sessionHandler"> - <New class="org.eclipse.jetty.server.session.SessionHandler" /> - </Set> - </New> - - <Set name="handler"> - <New class="org.eclipse.jetty.server.handler.HandlerCollection"> - <Set name="handlers"> - <Array type="org.eclipse.jetty.server.Handler"> - <Item> - <Ref refid="context" /> - </Item> - <Item> - <New class="org.eclipse.jetty.server.handler.DefaultHandler" /> - </Item> - <Item> - <New class="org.eclipse.jetty.server.session.SessionHandler" /> - </Item> - </Array> - </Set> - </New> - </Set> -</Configure> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-examples-rest/juneau-examples-rest.launch ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/juneau-examples-rest.launch b/juneau-examples-rest/juneau-examples-rest.launch deleted file mode 100644 index 4004583..0000000 --- a/juneau-examples-rest/juneau-examples-rest.launch +++ /dev/null @@ -1,32 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="no"?> -<!-- - *************************************************************************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations under the License. * - *************************************************************************************************************************** ---> -<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication"> -<stringAttribute key="bad_container_name" value="/juneau-examples"/> -<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS"> -<listEntry value="/juneau-microservice/src/main/java/org/apache/juneau/microservice/RestMicroservice.java"/> -</listAttribute> -<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES"> -<listEntry value="1"/> -</listAttribute> -<booleanAttribute key="org.eclipse.jdt.debug.ui.CONSIDER_INHERITED_MAIN" value="true"/> -<booleanAttribute key="org.eclipse.jdt.debug.ui.INCLUDE_EXTERNAL_JARS" value="true"/> -<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/> -<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.m2e.launchconfig.classpathProvider"/> -<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.apache.juneau.microservice.RestMicroservice"/> -<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="examples.cfg"/> -<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="juneau-examples-rest"/> -<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.m2e.launchconfig.sourcepathProvider"/> -</launchConfiguration> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-examples-rest/pom.xml ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/pom.xml b/juneau-examples-rest/pom.xml deleted file mode 100644 index e84d662..0000000 --- a/juneau-examples-rest/pom.xml +++ /dev/null @@ -1,157 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - *************************************************************************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations under the License. * - *************************************************************************************************************************** ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - - <modelVersion>4.0.0</modelVersion> - <artifactId>juneau-examples-rest</artifactId> - <name>Apache Juneau REST Examples</name> - <description>Sample code packaged as a microservice.</description> - - <parent> - <groupId>org.apache.juneau</groupId> - <artifactId>juneau</artifactId> - <version>6.3.2-incubating-SNAPSHOT</version> - </parent> - - <properties> - <encoding>UTF-8</encoding> - <maven.javadoc.skip>true</maven.javadoc.skip> - <derby.version>10.10.2.0</derby.version> - <fileupload.version>1.3.1</fileupload.version> - </properties> - - <dependencies> - <dependency> - <groupId>org.apache.juneau</groupId> - <artifactId>juneau-microservice</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.jena</groupId> - <artifactId>jena-core</artifactId> - </dependency> - <dependency> - <groupId>org.apache.derby</groupId> - <artifactId>derby</artifactId> - <version>${derby.version}</version> - </dependency> - <dependency> - <groupId>commons-fileupload</groupId> - <artifactId>commons-fileupload</artifactId> - <version>${fileupload.version}</version> - </dependency> - <dependency> - <groupId>org.apache.httpcomponents</groupId> - <artifactId>httpmime</artifactId> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - </dependency> - </dependencies> - - <build> - <plugins> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-source-plugin</artifactId> - <executions> - <execution> - <id>attach-sources</id> - <phase>verify</phase> - <goals> - <goal>jar-no-fork</goal> - </goals> - </execution> - </executions> - </plugin> - - <!-- - This runs the _TestSuite class. - You must run within the testsuite so the REST microservice is started for the tests. - --> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-plugin</artifactId> - <configuration> - <includes> - <include> - **/_TestSuite.java - </include> - </includes> - </configuration> - </plugin> - - <!-- - This packages the samples into an executable jar. - Use: java -jar juneau-examples-uber.jar - Needs the examples.cfg copied below in the same directory. - --> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-shade-plugin</artifactId> - <version>2.4.3</version> - <configuration> - <createDependencyReducedPom>false</createDependencyReducedPom> - <minimizeJar>false</minimizeJar> - <transformers> - <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> - <manifestEntries> - <Main-Class>org.apache.juneau.microservice.RestMicroservice</Main-Class> - <Rest-Resources>org.apache.juneau.examples.rest.RootResources</Rest-Resources> - <Main-ConfigFile>examples.cfg</Main-ConfigFile> - </manifestEntries> - </transformer> - </transformers> - </configuration> - <executions> - <execution> - <phase>package</phase> - <goals> - <goal>shade</goal> - </goals> - </execution> - </executions> - </plugin> - - <!-- Attaches the examples.cfg to this artifact --> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>build-helper-maven-plugin</artifactId> - <version>1.12</version> - <executions> - <execution> - <id>attach-artifacts</id> - <phase>package</phase> - <goals> - <goal>attach-artifact</goal> - </goals> - <configuration> - <artifacts> - <artifact> - <file>examples.cfg</file> - <type>cfg</type> - <classifier>samples</classifier> - </artifact> - </artifacts> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> -</project> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/addressbook/Address.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/addressbook/Address.java b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/addressbook/Address.java deleted file mode 100755 index c7b3685..0000000 --- a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/addressbook/Address.java +++ /dev/null @@ -1,54 +0,0 @@ -// *************************************************************************************************************************** -// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -// * with the License. You may obtain a copy of the License at * -// * * -// * http://www.apache.org/licenses/LICENSE-2.0 * -// * * -// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -// * specific language governing permissions and limitations under the License. * -// *************************************************************************************************************************** -package org.apache.juneau.examples.addressbook; - -import java.net.URI; - -import org.apache.juneau.annotation.*; -import org.apache.juneau.jena.annotation.*; -import org.apache.juneau.xml.annotation.*; - -/** - * Address bean - */ -@Xml(prefix="addr") -@Rdf(prefix="addr") -@Bean(typeName="address") -public class Address { - - private static int nextAddressId = 1; - - // Bean properties - @Rdf(beanUri=true) public URI uri; - public URI personUri; - public int id; - @Xml(prefix="mail") @Rdf(prefix="mail") public String street, city, state; - @Xml(prefix="mail") @Rdf(prefix="mail") public int zip; - public boolean isCurrent; - - /** Bean constructor - Needed for instantiating on client side */ - public Address() {} - - /** Normal constructor - Needed for instantiating on server side */ - public Address(URI addressBookUri, URI personUri, CreateAddress ca) throws Exception { - this.id = nextAddressId++; - if (addressBookUri != null) - this.uri = addressBookUri.resolve("addresses/" + id); - this.personUri = personUri; - this.street = ca.street; - this.city = ca.city; - this.state = ca.state; - this.zip = ca.zip; - this.isCurrent = ca.isCurrent; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/addressbook/AddressBook.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/addressbook/AddressBook.java b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/addressbook/AddressBook.java deleted file mode 100755 index 72c1473..0000000 --- a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/addressbook/AddressBook.java +++ /dev/null @@ -1,121 +0,0 @@ -// *************************************************************************************************************************** -// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -// * with the License. You may obtain a copy of the License at * -// * * -// * http://www.apache.org/licenses/LICENSE-2.0 * -// * * -// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -// * specific language governing permissions and limitations under the License. * -// *************************************************************************************************************************** -package org.apache.juneau.examples.addressbook; - -import java.net.URI; -import java.text.*; -import java.util.*; - -import org.apache.juneau.annotation.*; - -/** - * Address book bean - */ -@Bean(typeName="addressBook") -public class AddressBook extends LinkedList<Person> implements IAddressBook { - private static final long serialVersionUID = 1L; - - // The URL of this resource - private URI uri; - - /** Bean constructor - Needed for instantiating on server side */ - public AddressBook() {} - - /** Bean constructor - Needed for instantiating on client side */ - public AddressBook(URI uri) throws Exception { - this.uri = uri; - } - - @Override /* IAddressBook */ - public void init() throws Exception { - clear(); - createPerson( - new CreatePerson( - "Barack Obama", - toCalendar("Aug 4, 1961"), - new CreateAddress("1600 Pennsylvania Ave", "Washington", "DC", 20500, true), - new CreateAddress("5046 S Greenwood Ave", "Chicago", "IL", 60615, false) - ) - ); - createPerson( - new CreatePerson( - "George Walker Bush", - toCalendar("Jul 6, 1946"), - new CreateAddress("43 Prairie Chapel Rd", "Crawford", "TX", 76638, true), - new CreateAddress("1600 Pennsylvania Ave", "Washington", "DC", 20500, false) - ) - ); - } - - @Override /* IAddressBook */ - public List<Person> getPeople() { - return this; - } - - @Override /* IAddressBook */ - public Person createPerson(CreatePerson cp) throws Exception { - Person p = new Person(uri, cp); - add(p); - return p; - } - - @Override /* IAddressBook */ - public Person findPerson(int id) { - for (Person p : this) - if (p.id == id) - return p; - return null; - } - - @Override /* IAddressBook */ - public Address findAddress(int id) { - for (Person p : this) - for (Address a : p.addresses) - if (a.id == id) - return a; - return null; - } - - @Override /* IAddressBook */ - public Person findPersonWithAddress(int id) { - for (Person p : this) - for (Address a : p.addresses) - if (a.id == id) - return p; - return null; - } - - @Override /* IAddressBook */ - public List<Address> getAddresses() { - Set<Address> s = new LinkedHashSet<Address>(); - for (Person p : this) - for (Address a : p.addresses) - s.add(a); - return new ArrayList<Address>(s); - } - - @Override /* IAddressBook */ - public Person removePerson(int id) { - Person p = findPerson(id); - if (p != null) - this.remove(p); - return p; - } - - /** Utility method */ - public static Calendar toCalendar(String birthDate) throws Exception { - Calendar c = new GregorianCalendar(); - c.setTime(DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.US).parse(birthDate)); - return c; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/addressbook/CreateAddress.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/addressbook/CreateAddress.java b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/addressbook/CreateAddress.java deleted file mode 100755 index 3b36166..0000000 --- a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/addressbook/CreateAddress.java +++ /dev/null @@ -1,43 +0,0 @@ -// *************************************************************************************************************************** -// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -// * with the License. You may obtain a copy of the License at * -// * * -// * http://www.apache.org/licenses/LICENSE-2.0 * -// * * -// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -// * specific language governing permissions and limitations under the License. * -// *************************************************************************************************************************** -package org.apache.juneau.examples.addressbook; - -import org.apache.juneau.annotation.*; -import org.apache.juneau.jena.annotation.*; -import org.apache.juneau.xml.annotation.*; - -/** - * POJO for creating a new address - */ -@Xml(prefix="addr") -@Rdf(prefix="addr") -@Bean(typeName="address") -public class CreateAddress { - - // Bean properties - @Xml(prefix="mail") @Rdf(prefix="mail") public String street, city, state; - @Xml(prefix="mail") @Rdf(prefix="mail") public int zip; - public boolean isCurrent; - - /** Bean constructor - Needed for instantiating on server side */ - public CreateAddress() {} - - /** Normal constructor - Needed for instantiating on client side */ - public CreateAddress(String street, String city, String state, int zip, boolean isCurrent) { - this.street = street; - this.city = city; - this.state = state; - this.zip = zip; - this.isCurrent = isCurrent; - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/addressbook/CreatePerson.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/addressbook/CreatePerson.java b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/addressbook/CreatePerson.java deleted file mode 100755 index d064fd7..0000000 --- a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/addressbook/CreatePerson.java +++ /dev/null @@ -1,45 +0,0 @@ -// *************************************************************************************************************************** -// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -// * with the License. You may obtain a copy of the License at * -// * * -// * http://www.apache.org/licenses/LICENSE-2.0 * -// * * -// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -// * specific language governing permissions and limitations under the License. * -// *************************************************************************************************************************** -package org.apache.juneau.examples.addressbook; - -import java.util.*; - -import org.apache.juneau.annotation.*; -import org.apache.juneau.jena.annotation.*; -import org.apache.juneau.transforms.*; -import org.apache.juneau.xml.annotation.*; - -/** - * POJO for creating a new person - */ -@Xml(prefix="per") -@Rdf(prefix="per") -@Bean(typeName="person") -public class CreatePerson { - - // Bean properties - public String name; - @BeanProperty(swap=CalendarSwap.DateMedium.class) public Calendar birthDate; - public LinkedList<CreateAddress> addresses = new LinkedList<CreateAddress>(); - - /** Bean constructor - Needed for instantiating on server side */ - public CreatePerson() {} - - /** Normal constructor - Needed for instantiating on client side */ - public CreatePerson(String name, Calendar birthDate, CreateAddress...addresses) { - this.name = name; - this.birthDate = birthDate; - this.addresses.addAll(Arrays.asList(addresses)); - } -} - http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/addressbook/IAddressBook.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/addressbook/IAddressBook.java b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/addressbook/IAddressBook.java deleted file mode 100755 index 983ecb1..0000000 --- a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/addressbook/IAddressBook.java +++ /dev/null @@ -1,49 +0,0 @@ -// *************************************************************************************************************************** -// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -// * with the License. You may obtain a copy of the License at * -// * * -// * http://www.apache.org/licenses/LICENSE-2.0 * -// * * -// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -// * specific language governing permissions and limitations under the License. * -// *************************************************************************************************************************** -package org.apache.juneau.examples.addressbook; - -import java.util.*; - -import org.apache.juneau.remoteable.*; - -/** - * Interface used to help illustrate proxy interfaces. - * See {@link SampleRemoteableServlet}. - */ -@Remoteable -public interface IAddressBook { - - /** Initialize this address book with preset entries */ - void init() throws Exception; - - /** Return all people in the address book */ - List<Person> getPeople(); - - /** Return all addresses in the address book */ - List<Address> getAddresses(); - - /** Create a person in this address book */ - Person createPerson(CreatePerson cp) throws Exception; - - /** Find a person by id */ - Person findPerson(int id); - - /** Find an address by id */ - Address findAddress(int id); - - /** Find a person by address id */ - Person findPersonWithAddress(int id); - - /** Remove a person by id */ - Person removePerson(int id); -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/addressbook/Person.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/addressbook/Person.java b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/addressbook/Person.java deleted file mode 100755 index e95806a..0000000 --- a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/addressbook/Person.java +++ /dev/null @@ -1,73 +0,0 @@ -// *************************************************************************************************************************** -// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -// * with the License. You may obtain a copy of the License at * -// * * -// * http://www.apache.org/licenses/LICENSE-2.0 * -// * * -// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -// * specific language governing permissions and limitations under the License. * -// *************************************************************************************************************************** -package org.apache.juneau.examples.addressbook; - -import java.net.URI; -import java.util.*; - -import org.apache.juneau.annotation.*; -import org.apache.juneau.jena.annotation.*; -import org.apache.juneau.transforms.*; -import org.apache.juneau.xml.annotation.*; - -/** - * Person POJO - */ -@Xml(prefix="per") -@Rdf(prefix="per") -@Bean(typeName="person") -public class Person { - - private static int nextPersonId = 1; - - // Bean properties - @Rdf(beanUri=true) public URI uri; - private URI addressBookUri; - public int id; - public String name; - @BeanProperty(swap=CalendarSwap.DateMedium.class) public Calendar birthDate; - public LinkedList<Address> addresses = new LinkedList<Address>(); - - /** Bean constructor - Needed for instantiating on server side */ - public Person() {} - - /** Normal constructor - Needed for instantiating on client side */ - public Person(URI addressBookUri, CreatePerson cp) throws Exception { - this.id = nextPersonId++; - this.addressBookUri = addressBookUri; - if (addressBookUri != null) - this.uri = addressBookUri.resolve("people/" + id); - this.name = cp.name; - this.birthDate = cp.birthDate; - for (CreateAddress ca : cp.addresses) - this.addresses.add(new Address(addressBookUri, uri, ca)); - } - - /** Extra read-only bean property */ - public int getAge() { - return new GregorianCalendar().get(Calendar.YEAR) - birthDate.get(Calendar.YEAR); - } - - /** Convenience method - Add an address for this person */ - public Address createAddress(CreateAddress ca) throws Exception { - Address a = new Address(addressBookUri, uri, ca); - addresses.add(a); - return a; - } - - /** Extra method (for method invocation example) */ - public String sayHello(String toPerson, int age) { - return name + " says hello to " + toPerson + " who is " + age + " years old"; - } -} -