diff --git a/.gitignore b/.gitignore index 9139e008a..4302b9a91 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ -**/target/** -*.class -target -*.releaseBackup -release.properties -/nbactions.xml +**/target/** +*.class +target +*.releaseBackup +release.properties +/nbactions.xml /bridje-cfg/nbproject/ \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 0982eea7e..b1c1e8e4f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ -language: java -jdk: - - oraclejdk8 - -script: mvn -Dgpg.skip=true test +language: java +jdk: + - oraclejdk8 + +script: mvn -Dgpg.skip=true test diff --git a/LICENSE b/LICENSE index 8f71f43fe..113e84387 100644 --- a/LICENSE +++ b/LICENSE @@ -1,202 +1,202 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "{}" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright {yyyy} {name of copyright owner} - - Licensed 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. - + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + Licensed 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. + diff --git a/README.md b/README.md index bcd84b928..318bb2b8a 100644 --- a/README.md +++ b/README.md @@ -1,44 +1,44 @@ -[![Build Status](https://travis-ci.org/bridje/bridje-framework.svg?branch=master)](https://travis-ci.org/bridje/bridje-framework) - -Introduction -============ - -This package contains the Bridje Java Applications Framework. A project providing Java API for building Fast, Roboust Java Aplications with Maven. -The project is licensed under the Apache License: - - Licensed 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. - -Dependencies -============ - -The project libraries can be use without dependencies. - -Installation and Usage -====================== - -Bridje Core library is availables on the Maven Central Repository - - - .... - - org.bridje - bridje-ioc - 0.1.2 - - .... - - -About the Project -================= - -The project provides a set of tools for creating Java Applications. +[![Build Status](https://travis-ci.org/bridje/bridje-framework.svg?branch=master)](https://travis-ci.org/bridje/bridje-framework) + +Introduction +============ + +This package contains the Bridje Java Applications Framework. A project providing Java API for building Fast, Roboust Java Aplications with Maven. +The project is licensed under the Apache License: + + Licensed 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. + +Dependencies +============ + +The project libraries can be use without dependencies. + +Installation and Usage +====================== + +Bridje Core library is availables on the Maven Central Repository + + + .... + + org.bridje + bridje-ioc + 0.1.2 + + .... + + +About the Project +================= + +The project provides a set of tools for creating Java Applications. diff --git a/bridje-cfg/pom.xml b/bridje-cfg/pom.xml index e54ee5111..8829d1ffc 100644 --- a/bridje-cfg/pom.xml +++ b/bridje-cfg/pom.xml @@ -1,29 +1,29 @@ - - - 4.0.0 - - - org.bridje - bridje-parent - 0.1.3-SNAPSHOT - - - bridje-cfg - - Bridje Cfg - Bridje Cfg API - http://www.bridje.org - - - - junit - junit - test - - - ${project.groupId} - bridje-ioc - ${project.version} - - - + + + 4.0.0 + + + org.bridje + bridje-parent + 0.1.3-SNAPSHOT + + + bridje-cfg + + Bridje Cfg + Bridje Cfg API + http://www.bridje.org + + + + junit + junit + test + + + ${project.groupId} + bridje-ioc + ${project.version} + + + diff --git a/bridje-cfg/src/main/java/org/bridje/cfg/ConfigRepository.java b/bridje-cfg/src/main/java/org/bridje/cfg/ConfigRepository.java index 1db4f7857..1ba8fe16a 100644 --- a/bridje-cfg/src/main/java/org/bridje/cfg/ConfigRepository.java +++ b/bridje-cfg/src/main/java/org/bridje/cfg/ConfigRepository.java @@ -1,58 +1,58 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.cfg; - -import java.io.IOException; -import java.io.Reader; -import java.io.Writer; - -/** - * An interface that every configuration repository must implements. - * - * The ConfigService will use all the config repositories components to find and - * saves configurations. - */ -public interface ConfigRepository -{ - /** - * Obtains a reader to the configuration resource by the given name. - * - * @param configName The name of the configuration. - * @return A Reader from wich to read the configuracion instance. - * @throws java.io.IOException If any IOException occurs during configuration retreval. - */ - Reader findConfig(String configName) throws IOException; - - /** - * Obtains a writer to the configuration resource by the given name. - * - * @param configName The name for this configuration instance. - * @return The writer in wich to put the new configuration instance, - * or null if this repository does not allows configuration saving. - * @throws java.io.IOException If any IOException occurs during configuration saving. - */ - Writer saveConfig(String configName) throws IOException; - - /** - * Especifies when ever this repository allows to save configuration - * instances or not. - * - * @return true this repository allows to save configuration instances, - * false otherwise. - */ - boolean canSave(); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.cfg; + +import java.io.IOException; +import java.io.Reader; +import java.io.Writer; + +/** + * An interface that every configuration repository must implements. + * + * The ConfigService will use all the config repositories components to find and + * saves configurations. + */ +public interface ConfigRepository +{ + /** + * Obtains a reader to the configuration resource by the given name. + * + * @param configName The name of the configuration. + * @return A Reader from wich to read the configuracion instance. + * @throws java.io.IOException If any IOException occurs during configuration retreval. + */ + Reader findConfig(String configName) throws IOException; + + /** + * Obtains a writer to the configuration resource by the given name. + * + * @param configName The name for this configuration instance. + * @return The writer in wich to put the new configuration instance, + * or null if this repository does not allows configuration saving. + * @throws java.io.IOException If any IOException occurs during configuration saving. + */ + Writer saveConfig(String configName) throws IOException; + + /** + * Especifies when ever this repository allows to save configuration + * instances or not. + * + * @return true this repository allows to save configuration instances, + * false otherwise. + */ + boolean canSave(); +} diff --git a/bridje-cfg/src/main/java/org/bridje/cfg/ConfigService.java b/bridje-cfg/src/main/java/org/bridje/cfg/ConfigService.java index 11ad4e560..59a0b1b41 100644 --- a/bridje-cfg/src/main/java/org/bridje/cfg/ConfigService.java +++ b/bridje-cfg/src/main/java/org/bridje/cfg/ConfigService.java @@ -1,103 +1,103 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.cfg; - -import java.io.IOException; - -/** - * A service for access the configurations of applications in multiple - * environments. - *

- * Configuration classes must be serializable in xml format. - */ -public interface ConfigService -{ - /** - * Obtains a configuration by its class. - *

- * @param The type of the configuration. - * @param configClass The class of the configuration instance. - * @return The object with the configuration or {@literal null} if no - * configuration of the specified type was found. - * @throws java.io.IOException If any IOException occurs during configuration retreval. - */ - T findConfig(Class configClass) throws IOException; - - /** - * Obtains a configuration by its class. - *

- * @param The type of the configuration. - * @param configName The name of the representative configuration file. - * @param configClass The class of the configuration instance. - * @return The object with the configuration or {@literal null} if no - * configuration of the specified type was found. - * @throws java.io.IOException If any IOException occurs during configuration retreval. - */ - T findConfig(String configName, Class configClass) throws IOException; - - /** - * Obtains a configuration by its class, or create it if no found. - *

- * @param The type of the configuration. - * @param configClass The class of the configuration instance. - * @param defaultConfig The default configuration if not exists. - * @return The object with the configuration or {@literal null} if no - * configuration of the specified type was found. - * @throws java.io.IOException If any IOException occurs during configuration saving or retreval. - */ - T findOrCreateConfig(Class configClass, T defaultConfig) throws IOException; - - /** - * Obtains a configuration by its class, or create it if no found. - *

- * @param The type of the configuration. - * @param configName The name of the representative configuration file. - * @param configClass The class of the configuration instance. - * @param defaultConfig The default configuration if not exists. - * @return The object with the configuration or {@literal null} if no - * configuration of the specified type was found. - * @throws java.io.IOException If any IOException occurs during configuration saving or retreval. - */ - T findOrCreateConfig(String configName, Class configClass, T defaultConfig) throws IOException; - - /** - * Saves the default configuration instance to the highest priority - * repository with save capability so it may be obtained by the findConig - * method with the class of the saved object. - * - * @param The type of the configuration object. - * @param newConfig The configuration object to be save as the default - * instance of the object´s class config. - * @return The newConfig object passed to this method. - * @throws java.io.IOException If any IOException occurs during configuration saving. - */ - T saveConfig(T newConfig) throws IOException; - - /** - * Saves the named configuration instance to the the highest priority - * repository with save capability so it may be obtained by the findConig - * method with the name and class of the saved object. - * - * @param The type of the configuration object. - * @param configName The name for this configuration instance. - * @param newConfig The configuration object to be save as the named - * instance of the object´s class config. - * @return The newConfig object passed to this method. - * @throws java.io.IOException If any IOException occurs during configuration saving. - */ - T saveConfig(String configName, T newConfig) throws IOException; -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.cfg; + +import java.io.IOException; + +/** + * A service for access the configurations of applications in multiple + * environments. + *

+ * Configuration classes must be serializable in xml format. + */ +public interface ConfigService +{ + /** + * Obtains a configuration by its class. + *

+ * @param The type of the configuration. + * @param configClass The class of the configuration instance. + * @return The object with the configuration or {@literal null} if no + * configuration of the specified type was found. + * @throws java.io.IOException If any IOException occurs during configuration retreval. + */ + T findConfig(Class configClass) throws IOException; + + /** + * Obtains a configuration by its class. + *

+ * @param The type of the configuration. + * @param configName The name of the representative configuration file. + * @param configClass The class of the configuration instance. + * @return The object with the configuration or {@literal null} if no + * configuration of the specified type was found. + * @throws java.io.IOException If any IOException occurs during configuration retreval. + */ + T findConfig(String configName, Class configClass) throws IOException; + + /** + * Obtains a configuration by its class, or create it if no found. + *

+ * @param The type of the configuration. + * @param configClass The class of the configuration instance. + * @param defaultConfig The default configuration if not exists. + * @return The object with the configuration or {@literal null} if no + * configuration of the specified type was found. + * @throws java.io.IOException If any IOException occurs during configuration saving or retreval. + */ + T findOrCreateConfig(Class configClass, T defaultConfig) throws IOException; + + /** + * Obtains a configuration by its class, or create it if no found. + *

+ * @param The type of the configuration. + * @param configName The name of the representative configuration file. + * @param configClass The class of the configuration instance. + * @param defaultConfig The default configuration if not exists. + * @return The object with the configuration or {@literal null} if no + * configuration of the specified type was found. + * @throws java.io.IOException If any IOException occurs during configuration saving or retreval. + */ + T findOrCreateConfig(String configName, Class configClass, T defaultConfig) throws IOException; + + /** + * Saves the default configuration instance to the highest priority + * repository with save capability so it may be obtained by the findConig + * method with the class of the saved object. + * + * @param The type of the configuration object. + * @param newConfig The configuration object to be save as the default + * instance of the object´s class config. + * @return The newConfig object passed to this method. + * @throws java.io.IOException If any IOException occurs during configuration saving. + */ + T saveConfig(T newConfig) throws IOException; + + /** + * Saves the named configuration instance to the the highest priority + * repository with save capability so it may be obtained by the findConig + * method with the name and class of the saved object. + * + * @param The type of the configuration object. + * @param configName The name for this configuration instance. + * @param newConfig The configuration object to be save as the named + * instance of the object´s class config. + * @return The newConfig object passed to this method. + * @throws java.io.IOException If any IOException occurs during configuration saving. + */ + T saveConfig(String configName, T newConfig) throws IOException; +} diff --git a/bridje-cfg/src/main/java/org/bridje/cfg/Configuration.java b/bridje-cfg/src/main/java/org/bridje/cfg/Configuration.java index b9f0923a9..4025cfcc1 100644 --- a/bridje-cfg/src/main/java/org/bridje/cfg/Configuration.java +++ b/bridje-cfg/src/main/java/org/bridje/cfg/Configuration.java @@ -1,39 +1,39 @@ -/* - * Copyright 2016 Bridje Framework. - * - * Licensed 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.bridje.cfg; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * This annotation is used to especify the configuration adapter for the given - * configuration definition class. - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -public @interface Configuration -{ - /** - * The adapter to be use to serialice/parse this configuration definicion - * class. - * - * @return The adapter class to be use. - */ - Class value(); -} +/* + * Copyright 2016 Bridje Framework. + * + * Licensed 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.bridje.cfg; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * This annotation is used to especify the configuration adapter for the given + * configuration definition class. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface Configuration +{ + /** + * The adapter to be use to serialice/parse this configuration definicion + * class. + * + * @return The adapter class to be use. + */ + Class value(); +} diff --git a/bridje-cfg/src/main/java/org/bridje/cfg/ConfigurationAdapter.java b/bridje-cfg/src/main/java/org/bridje/cfg/ConfigurationAdapter.java index 70003890d..c4369db49 100644 --- a/bridje-cfg/src/main/java/org/bridje/cfg/ConfigurationAdapter.java +++ b/bridje-cfg/src/main/java/org/bridje/cfg/ConfigurationAdapter.java @@ -1,63 +1,63 @@ -/* - * Copyright 2016 Bridje Framework. - * - * Licensed 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.bridje.cfg; - -import java.io.IOException; -import java.io.Reader; -import java.io.Writer; - -/** - * Represents an adapter witch can be use to read/write configuration objects. - */ -public interface ConfigurationAdapter -{ - /** - * Obtains the file name for the especified configuration name and class. - * - * @param name The name of the configuration instance. - * @param cls The class of the configuration - * @return The real file name to be use to find the configuration instance. - */ - String findFileName(String name, Class cls); - - /** - * Obtains the file name for the especified configuration class. - * - * @param cls The class of the configuration - * @return The real file name to be use to find the configuration instance. - */ - String findDefaultFileName(Class cls); - - /** - * Writes the configuration object to the especified writer. - * - * @param newConfig The configuration object to write. - * @param writer The writer to write to. - * @throws java.io.IOException If the writing operation failed. - */ - void write(Object newConfig, Writer writer) throws IOException; - - /** - * Reads the especified configuration class into an object. - * - * @param cls The configuration class to read. - * @param reader The reader to read from. - * @return The configuration object readed. - * @throws java.io.IOException If the reading operation failed. - */ - Object read(Class cls, Reader reader) throws IOException; -} +/* + * Copyright 2016 Bridje Framework. + * + * Licensed 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.bridje.cfg; + +import java.io.IOException; +import java.io.Reader; +import java.io.Writer; + +/** + * Represents an adapter witch can be use to read/write configuration objects. + */ +public interface ConfigurationAdapter +{ + /** + * Obtains the file name for the especified configuration name and class. + * + * @param name The name of the configuration instance. + * @param cls The class of the configuration + * @return The real file name to be use to find the configuration instance. + */ + String findFileName(String name, Class cls); + + /** + * Obtains the file name for the especified configuration class. + * + * @param cls The class of the configuration + * @return The real file name to be use to find the configuration instance. + */ + String findDefaultFileName(Class cls); + + /** + * Writes the configuration object to the especified writer. + * + * @param newConfig The configuration object to write. + * @param writer The writer to write to. + * @throws java.io.IOException If the writing operation failed. + */ + void write(Object newConfig, Writer writer) throws IOException; + + /** + * Reads the especified configuration class into an object. + * + * @param cls The configuration class to read. + * @param reader The reader to read from. + * @return The configuration object readed. + * @throws java.io.IOException If the reading operation failed. + */ + Object read(Class cls, Reader reader) throws IOException; +} diff --git a/bridje-cfg/src/main/java/org/bridje/cfg/XmlConfigAdapter.java b/bridje-cfg/src/main/java/org/bridje/cfg/XmlConfigAdapter.java index 68b15699c..f497478a4 100644 --- a/bridje-cfg/src/main/java/org/bridje/cfg/XmlConfigAdapter.java +++ b/bridje-cfg/src/main/java/org/bridje/cfg/XmlConfigAdapter.java @@ -1,87 +1,87 @@ -/* - * Copyright 2016 Bridje Framework. - * - * Licensed 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.bridje.cfg; - -import java.io.IOException; -import java.io.Reader; -import java.io.Writer; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Marshaller; -import javax.xml.bind.Unmarshaller; -import javax.xml.bind.annotation.XmlRootElement; -import org.bridje.ioc.Component; - -/** - * This adapter use JAXB to write an read configuration objects into/from xml - * files, configuration classes using this adapter must be annotated with - * XmlRootElement annotation. - */ -@Component -public class XmlConfigAdapter implements ConfigurationAdapter -{ - @Override - public String findFileName(String name, Class cls) - { - return name + ".xml"; - } - - @Override - public String findDefaultFileName(Class cls) - { - XmlRootElement ann = cls.getAnnotation(XmlRootElement.class); - if(ann != null) - { - if(ann.name() != null && !ann.name().trim().isEmpty() && !ann.name().equalsIgnoreCase("##default")) - { - return ann.name() + ".xml"; - } - } - return cls.getSimpleName().toLowerCase() + ".xml"; - } - - @Override - public void write(Object newConfig, Writer writer) throws IOException - { - try - { - JAXBContext context = JAXBContext.newInstance(newConfig.getClass()); - Marshaller marshaller = context.createMarshaller(); - marshaller.marshal(newConfig, writer); - } - catch (JAXBException ex) - { - throw new IOException(ex.getMessage(), ex); - } - } - - @Override - public Object read(Class cls, Reader reader) throws IOException - { - try - { - JAXBContext context = JAXBContext.newInstance(cls); - Unmarshaller unmarshaller = context.createUnmarshaller(); - Object result = unmarshaller.unmarshal(reader); - return result; - } - catch (JAXBException ex) - { - throw new IOException(ex.getMessage(), ex); - } - } -} +/* + * Copyright 2016 Bridje Framework. + * + * Licensed 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.bridje.cfg; + +import java.io.IOException; +import java.io.Reader; +import java.io.Writer; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; +import javax.xml.bind.annotation.XmlRootElement; +import org.bridje.ioc.Component; + +/** + * This adapter use JAXB to write an read configuration objects into/from xml + * files, configuration classes using this adapter must be annotated with + * XmlRootElement annotation. + */ +@Component +public class XmlConfigAdapter implements ConfigurationAdapter +{ + @Override + public String findFileName(String name, Class cls) + { + return name + ".xml"; + } + + @Override + public String findDefaultFileName(Class cls) + { + XmlRootElement ann = cls.getAnnotation(XmlRootElement.class); + if(ann != null) + { + if(ann.name() != null && !ann.name().trim().isEmpty() && !ann.name().equalsIgnoreCase("##default")) + { + return ann.name() + ".xml"; + } + } + return cls.getSimpleName().toLowerCase() + ".xml"; + } + + @Override + public void write(Object newConfig, Writer writer) throws IOException + { + try + { + JAXBContext context = JAXBContext.newInstance(newConfig.getClass()); + Marshaller marshaller = context.createMarshaller(); + marshaller.marshal(newConfig, writer); + } + catch (JAXBException ex) + { + throw new IOException(ex.getMessage(), ex); + } + } + + @Override + public Object read(Class cls, Reader reader) throws IOException + { + try + { + JAXBContext context = JAXBContext.newInstance(cls); + Unmarshaller unmarshaller = context.createUnmarshaller(); + Object result = unmarshaller.unmarshal(reader); + return result; + } + catch (JAXBException ex) + { + throw new IOException(ex.getMessage(), ex); + } + } +} diff --git a/bridje-cfg/src/main/java/org/bridje/cfg/impl/BridjeEtcRepository.java b/bridje-cfg/src/main/java/org/bridje/cfg/impl/BridjeEtcRepository.java index 38cf574ab..bc674eef6 100644 --- a/bridje-cfg/src/main/java/org/bridje/cfg/impl/BridjeEtcRepository.java +++ b/bridje-cfg/src/main/java/org/bridje/cfg/impl/BridjeEtcRepository.java @@ -1,53 +1,53 @@ -/* - * Copyright 2016 Bridje Framework. - * - * Licensed 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.bridje.cfg.impl; - -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.Reader; -import java.io.Writer; -import java.net.URL; -import org.bridje.cfg.ConfigRepository; -import org.bridje.ioc.Component; - -@Component -public class BridjeEtcRepository implements ConfigRepository -{ - @Override - public Reader findConfig(String configName) throws IOException - { - URL resource = this.getClass().getResource("/BRIDJE-INF/etc/" + configName); - if(resource != null) - { - return new InputStreamReader(resource.openStream()); - } - return null; - } - - @Override - public Writer saveConfig(String configName) throws IOException - { - return null; - } - - @Override - public boolean canSave() - { - return false; - } - -} +/* + * Copyright 2016 Bridje Framework. + * + * Licensed 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.bridje.cfg.impl; + +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; +import java.io.Writer; +import java.net.URL; +import org.bridje.cfg.ConfigRepository; +import org.bridje.ioc.Component; + +@Component +public class BridjeEtcRepository implements ConfigRepository +{ + @Override + public Reader findConfig(String configName) throws IOException + { + URL resource = this.getClass().getResource("/BRIDJE-INF/etc/" + configName); + if(resource != null) + { + return new InputStreamReader(resource.openStream()); + } + return null; + } + + @Override + public Writer saveConfig(String configName) throws IOException + { + return null; + } + + @Override + public boolean canSave() + { + return false; + } + +} diff --git a/bridje-cfg/src/main/java/org/bridje/cfg/impl/ConfigServiceImpl.java b/bridje-cfg/src/main/java/org/bridje/cfg/impl/ConfigServiceImpl.java index 8aeb1a554..223f92380 100644 --- a/bridje-cfg/src/main/java/org/bridje/cfg/impl/ConfigServiceImpl.java +++ b/bridje-cfg/src/main/java/org/bridje/cfg/impl/ConfigServiceImpl.java @@ -1,168 +1,168 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.cfg.impl; - -import java.io.IOException; -import java.io.Reader; -import java.io.Writer; -import org.bridje.cfg.ConfigRepository; -import org.bridje.cfg.ConfigService; -import org.bridje.cfg.Configuration; -import org.bridje.cfg.ConfigurationAdapter; -import org.bridje.cfg.XmlConfigAdapter; -import org.bridje.ioc.Component; -import org.bridje.ioc.Inject; -import org.bridje.ioc.Ioc; - -@Component -class ConfigServiceImpl implements ConfigService -{ - @Inject - private ConfigRepository[] repos; - - @Override - public T findConfig(Class configClass) throws IOException - { - return findConfigInternal(findFileName(configClass), configClass); - } - - @Override - public T findOrCreateConfig(Class configClass, T defaultConfig) throws IOException - { - return findOrCreateConfigInternal(findFileName(configClass), configClass, defaultConfig); - } - - @Override - public T findConfig(String configName, Class configClass) throws IOException - { - return findConfigInternal(findFileName(configName, configClass), configClass); - } - - @Override - public T findOrCreateConfig(String configName, Class configClass, T defaultConfig) throws IOException - { - return findOrCreateConfigInternal(findFileName(configName, configClass), configClass, defaultConfig); - } - - @Override - public T saveConfig(T newConfig) throws IOException - { - return saveConfigInternal(findFileName(newConfig.getClass()), newConfig); - } - - @Override - public T saveConfig(String configName, T newConfig) throws IOException - { - return saveConfigInternal(findFileName(configName, newConfig.getClass()), newConfig); - } - - private T saveConfigInternal(String configFileName, T newConfig) throws IOException - { - for (ConfigRepository repo : repos) - { - if(repo.canSave()) - { - return saveConfigToRepo(configFileName, newConfig, repo); - } - } - return newConfig; - } - - private T findConfigInternal(String configFileName, Class configClass) throws IOException - { - for (ConfigRepository repo : repos) - { - T result = findConfigFromRepo(configFileName, configClass, repo); - if(result != null) - { - return result; - } - } - return null; - } - - private T findOrCreateConfigInternal(String configFileName, Class configClass, T defaultConfig) throws IOException - { - T result = findConfigInternal(configFileName, configClass); - if(result == null) - { - result = saveConfigInternal(configFileName, defaultConfig); - } - return result; - } - - private String findFileName(Class cls) - { - return findAdapter(cls).findDefaultFileName(cls); - } - - private String findFileName(String configName, Class cls) - { - return findAdapter(cls).findFileName(configName, cls); - } - - private T saveConfigToRepo(String configName, T newConfig, ConfigRepository repo) throws IOException - { - try (Writer writer = repo.saveConfig(configName)) - { - if(writer != null) - { - writeConfig(writer, newConfig); - writer.flush(); - } - } - return newConfig; - } - - private T findConfigFromRepo(String configName, Class configClass, ConfigRepository repo) throws IOException - { - T configInstance = null; - try (Reader reader = repo.findConfig(configName)) - { - if(reader != null) - { - configInstance = readConfig(reader, configClass); - } - } - return configInstance; - } - - private void writeConfig(Writer writer, T newConfig) throws IOException - { - findAdapter(newConfig.getClass()).write(newConfig, writer); - } - - private T readConfig(Reader reader, Class configClass) throws IOException - { - return (T)findAdapter(configClass).read(configClass, reader); - } - - private ConfigurationAdapter findAdapter(Class cfgClass) - { - Configuration cfgAnnot = cfgClass.getAnnotation(Configuration.class); - Class configAdapter = null; - if(cfgAnnot != null) - { - configAdapter = cfgAnnot.value(); - } - if(configAdapter == null) - { - configAdapter = XmlConfigAdapter.class; - } - return Ioc.context().find(configAdapter); - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.cfg.impl; + +import java.io.IOException; +import java.io.Reader; +import java.io.Writer; +import org.bridje.cfg.ConfigRepository; +import org.bridje.cfg.ConfigService; +import org.bridje.cfg.Configuration; +import org.bridje.cfg.ConfigurationAdapter; +import org.bridje.cfg.XmlConfigAdapter; +import org.bridje.ioc.Component; +import org.bridje.ioc.Inject; +import org.bridje.ioc.Ioc; + +@Component +class ConfigServiceImpl implements ConfigService +{ + @Inject + private ConfigRepository[] repos; + + @Override + public T findConfig(Class configClass) throws IOException + { + return findConfigInternal(findFileName(configClass), configClass); + } + + @Override + public T findOrCreateConfig(Class configClass, T defaultConfig) throws IOException + { + return findOrCreateConfigInternal(findFileName(configClass), configClass, defaultConfig); + } + + @Override + public T findConfig(String configName, Class configClass) throws IOException + { + return findConfigInternal(findFileName(configName, configClass), configClass); + } + + @Override + public T findOrCreateConfig(String configName, Class configClass, T defaultConfig) throws IOException + { + return findOrCreateConfigInternal(findFileName(configName, configClass), configClass, defaultConfig); + } + + @Override + public T saveConfig(T newConfig) throws IOException + { + return saveConfigInternal(findFileName(newConfig.getClass()), newConfig); + } + + @Override + public T saveConfig(String configName, T newConfig) throws IOException + { + return saveConfigInternal(findFileName(configName, newConfig.getClass()), newConfig); + } + + private T saveConfigInternal(String configFileName, T newConfig) throws IOException + { + for (ConfigRepository repo : repos) + { + if(repo.canSave()) + { + return saveConfigToRepo(configFileName, newConfig, repo); + } + } + return newConfig; + } + + private T findConfigInternal(String configFileName, Class configClass) throws IOException + { + for (ConfigRepository repo : repos) + { + T result = findConfigFromRepo(configFileName, configClass, repo); + if(result != null) + { + return result; + } + } + return null; + } + + private T findOrCreateConfigInternal(String configFileName, Class configClass, T defaultConfig) throws IOException + { + T result = findConfigInternal(configFileName, configClass); + if(result == null) + { + result = saveConfigInternal(configFileName, defaultConfig); + } + return result; + } + + private String findFileName(Class cls) + { + return findAdapter(cls).findDefaultFileName(cls); + } + + private String findFileName(String configName, Class cls) + { + return findAdapter(cls).findFileName(configName, cls); + } + + private T saveConfigToRepo(String configName, T newConfig, ConfigRepository repo) throws IOException + { + try (Writer writer = repo.saveConfig(configName)) + { + if(writer != null) + { + writeConfig(writer, newConfig); + writer.flush(); + } + } + return newConfig; + } + + private T findConfigFromRepo(String configName, Class configClass, ConfigRepository repo) throws IOException + { + T configInstance = null; + try (Reader reader = repo.findConfig(configName)) + { + if(reader != null) + { + configInstance = readConfig(reader, configClass); + } + } + return configInstance; + } + + private void writeConfig(Writer writer, T newConfig) throws IOException + { + findAdapter(newConfig.getClass()).write(newConfig, writer); + } + + private T readConfig(Reader reader, Class configClass) throws IOException + { + return (T)findAdapter(configClass).read(configClass, reader); + } + + private ConfigurationAdapter findAdapter(Class cfgClass) + { + Configuration cfgAnnot = cfgClass.getAnnotation(Configuration.class); + Class configAdapter = null; + if(cfgAnnot != null) + { + configAdapter = cfgAnnot.value(); + } + if(configAdapter == null) + { + configAdapter = XmlConfigAdapter.class; + } + return Ioc.context().find(configAdapter); + } +} diff --git a/bridje-cfg/src/test/java/org/bridje/cfg/ConfigServiceTest.java b/bridje-cfg/src/test/java/org/bridje/cfg/ConfigServiceTest.java index d1abf72a8..9ac83ce9d 100644 --- a/bridje-cfg/src/test/java/org/bridje/cfg/ConfigServiceTest.java +++ b/bridje-cfg/src/test/java/org/bridje/cfg/ConfigServiceTest.java @@ -1,79 +1,79 @@ -/* - * Copyright 2016 Bridje Framework. - * - * Licensed 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.bridje.cfg; - -import org.bridje.ioc.Ioc; -import org.junit.After; -import org.junit.AfterClass; -import static org.junit.Assert.*; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class ConfigServiceTest -{ - - public ConfigServiceTest() - { - } - - @BeforeClass - public static void setUpClass() - { - } - - @AfterClass - public static void tearDownClass() - { - } - - @Before - public void setUp() - { - } - - @After - public void tearDown() - { - } - - @Test - public void testFindConfig_Class() throws Exception - { - ConfigService instance = Ioc.context().find(ConfigService.class); - MyConfig myCfg = instance.findConfig(MyConfig.class); - assertNotNull(myCfg); - assertNotNull(myCfg.getName()); - assertNotNull(myCfg.getPort()); - assertEquals("someServer", myCfg.getName()); - assertEquals(8080, myCfg.getPort()); - - MyConfig myCfg1 = instance.findConfig("my-config", MyConfig.class); - assertNotNull(myCfg1); - assertNotNull(myCfg1.getName()); - assertNotNull(myCfg1.getPort()); - assertEquals("someServer1", myCfg1.getName()); - assertEquals(8081, myCfg1.getPort()); - - MyConfig myCfg2 = instance.findConfig("system/server", MyConfig.class); - assertNotNull(myCfg2); - assertNotNull(myCfg2.getName()); - assertNotNull(myCfg2.getPort()); - assertEquals("localhost", myCfg2.getName()); - assertEquals(8082, myCfg2.getPort()); - } -} +/* + * Copyright 2016 Bridje Framework. + * + * Licensed 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.bridje.cfg; + +import org.bridje.ioc.Ioc; +import org.junit.After; +import org.junit.AfterClass; +import static org.junit.Assert.*; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +public class ConfigServiceTest +{ + + public ConfigServiceTest() + { + } + + @BeforeClass + public static void setUpClass() + { + } + + @AfterClass + public static void tearDownClass() + { + } + + @Before + public void setUp() + { + } + + @After + public void tearDown() + { + } + + @Test + public void testFindConfig_Class() throws Exception + { + ConfigService instance = Ioc.context().find(ConfigService.class); + MyConfig myCfg = instance.findConfig(MyConfig.class); + assertNotNull(myCfg); + assertNotNull(myCfg.getName()); + assertNotNull(myCfg.getPort()); + assertEquals("someServer", myCfg.getName()); + assertEquals(8080, myCfg.getPort()); + + MyConfig myCfg1 = instance.findConfig("my-config", MyConfig.class); + assertNotNull(myCfg1); + assertNotNull(myCfg1.getName()); + assertNotNull(myCfg1.getPort()); + assertEquals("someServer1", myCfg1.getName()); + assertEquals(8081, myCfg1.getPort()); + + MyConfig myCfg2 = instance.findConfig("system/server", MyConfig.class); + assertNotNull(myCfg2); + assertNotNull(myCfg2.getName()); + assertNotNull(myCfg2.getPort()); + assertEquals("localhost", myCfg2.getName()); + assertEquals(8082, myCfg2.getPort()); + } +} diff --git a/bridje-cfg/src/test/java/org/bridje/cfg/MyConfig.java b/bridje-cfg/src/test/java/org/bridje/cfg/MyConfig.java index f04d9d824..cee9681f2 100644 --- a/bridje-cfg/src/test/java/org/bridje/cfg/MyConfig.java +++ b/bridje-cfg/src/test/java/org/bridje/cfg/MyConfig.java @@ -1,48 +1,48 @@ -/* - * Copyright 2016 Bridje Framework. - * - * Licensed 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.bridje.cfg; - -import javax.xml.bind.annotation.XmlRootElement; - -@Configuration(XmlConfigAdapter.class) -@XmlRootElement -public class MyConfig -{ - private String name; - - private int port; - - public String getName() - { - return name; - } - - public void setName(String name) - { - this.name = name; - } - - public int getPort() - { - return port; - } - - public void setPort(int port) - { - this.port = port; - } -} +/* + * Copyright 2016 Bridje Framework. + * + * Licensed 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.bridje.cfg; + +import javax.xml.bind.annotation.XmlRootElement; + +@Configuration(XmlConfigAdapter.class) +@XmlRootElement +public class MyConfig +{ + private String name; + + private int port; + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public int getPort() + { + return port; + } + + public void setPort(int port) + { + this.port = port; + } +} diff --git a/bridje-http/pom.xml b/bridje-http/pom.xml index 88583a213..40d7a4b34 100644 --- a/bridje-http/pom.xml +++ b/bridje-http/pom.xml @@ -1,29 +1,29 @@ - - - 4.0.0 - - - org.bridje - bridje-parent - 0.1.3-SNAPSHOT - - - bridje-http - - Bridje HTTP - Bridje HTTP Server and Client - http://www.bridje.org - - - - junit - junit - test - - - io.netty - netty-all - 4.0.34.Final - - - + + + 4.0.0 + + + org.bridje + bridje-parent + 0.1.3-SNAPSHOT + + + bridje-http + + Bridje HTTP + Bridje HTTP Server and Client + http://www.bridje.org + + + + junit + junit + test + + + io.netty + netty-all + 4.0.34.Final + + + diff --git a/bridje-http/src/main/java/org/bridje/http/HttpClient.java b/bridje-http/src/main/java/org/bridje/http/HttpClient.java index cb8312ecf..4879f79f4 100644 --- a/bridje-http/src/main/java/org/bridje/http/HttpClient.java +++ b/bridje-http/src/main/java/org/bridje/http/HttpClient.java @@ -1,68 +1,68 @@ -/* - * Copyright 2016 Bridje Framework. - * - * Licensed 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.bridje.http; - -import io.netty.bootstrap.Bootstrap; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelInitializer; -import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; -import io.netty.channel.socket.SocketChannel; -import io.netty.channel.socket.nio.NioSocketChannel; -import java.net.InetSocketAddress; - -/** - * - */ -public class HttpClient -{ - private final String host; - - private final int port; - - public HttpClient(String host, int port) - { - this.host = host; - this.port = port; - } - - public void start() throws Exception - { - EventLoopGroup group = new NioEventLoopGroup(); - try - { - Bootstrap b = new Bootstrap(); - b.group(group) - .channel(NioSocketChannel.class) - .remoteAddress(new InetSocketAddress(host, port)) - .handler(new ChannelInitializer() - { - @Override - public void initChannel(SocketChannel ch) throws Exception - { - ch.pipeline().addLast(new HttpClientHandler()); - } - }); - ChannelFuture f = b.connect().sync(); - f.channel().closeFuture().sync(); - } - finally - { - group.shutdownGracefully().sync(); - } - } -} +/* + * Copyright 2016 Bridje Framework. + * + * Licensed 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.bridje.http; + +import io.netty.bootstrap.Bootstrap; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelInitializer; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.socket.SocketChannel; +import io.netty.channel.socket.nio.NioSocketChannel; +import java.net.InetSocketAddress; + +/** + * + */ +public class HttpClient +{ + private final String host; + + private final int port; + + public HttpClient(String host, int port) + { + this.host = host; + this.port = port; + } + + public void start() throws Exception + { + EventLoopGroup group = new NioEventLoopGroup(); + try + { + Bootstrap b = new Bootstrap(); + b.group(group) + .channel(NioSocketChannel.class) + .remoteAddress(new InetSocketAddress(host, port)) + .handler(new ChannelInitializer() + { + @Override + public void initChannel(SocketChannel ch) throws Exception + { + ch.pipeline().addLast(new HttpClientHandler()); + } + }); + ChannelFuture f = b.connect().sync(); + f.channel().closeFuture().sync(); + } + finally + { + group.shutdownGracefully().sync(); + } + } +} diff --git a/bridje-http/src/main/java/org/bridje/http/HttpClientHandler.java b/bridje-http/src/main/java/org/bridje/http/HttpClientHandler.java index fa764dcfd..c0bd4e169 100644 --- a/bridje-http/src/main/java/org/bridje/http/HttpClientHandler.java +++ b/bridje-http/src/main/java/org/bridje/http/HttpClientHandler.java @@ -1,54 +1,54 @@ -/* - * Copyright 2016 Bridje Framework. - * - * Licensed 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.bridje.http; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; -import io.netty.channel.ChannelHandler.Sharable; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.SimpleChannelInboundHandler; -import io.netty.util.CharsetUtil; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * - */ -@Sharable -public class HttpClientHandler extends SimpleChannelInboundHandler -{ - private static final Logger LOG = Logger.getLogger(HttpClientHandler.class.getName()); - - @Override - public void channelActive(ChannelHandlerContext ctx) - { - ctx.writeAndFlush(Unpooled.copiedBuffer("Netty rocks!", CharsetUtil.UTF_8)); - } - - @Override - public void channelRead0(ChannelHandlerContext ctx, ByteBuf in) - { - LOG.log(Level.INFO, "Client received: {0}", in.toString(CharsetUtil.UTF_8)); - } - - @Override - public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) - { - LOG.log(Level.SEVERE, cause.getMessage(), cause); - ctx.close(); - } -} +/* + * Copyright 2016 Bridje Framework. + * + * Licensed 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.bridje.http; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import io.netty.channel.ChannelHandler.Sharable; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.SimpleChannelInboundHandler; +import io.netty.util.CharsetUtil; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + */ +@Sharable +public class HttpClientHandler extends SimpleChannelInboundHandler +{ + private static final Logger LOG = Logger.getLogger(HttpClientHandler.class.getName()); + + @Override + public void channelActive(ChannelHandlerContext ctx) + { + ctx.writeAndFlush(Unpooled.copiedBuffer("Netty rocks!", CharsetUtil.UTF_8)); + } + + @Override + public void channelRead0(ChannelHandlerContext ctx, ByteBuf in) + { + LOG.log(Level.INFO, "Client received: {0}", in.toString(CharsetUtil.UTF_8)); + } + + @Override + public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) + { + LOG.log(Level.SEVERE, cause.getMessage(), cause); + ctx.close(); + } +} diff --git a/bridje-http/src/main/java/org/bridje/http/HttpServer.java b/bridje-http/src/main/java/org/bridje/http/HttpServer.java index d773b85f3..72546250a 100644 --- a/bridje-http/src/main/java/org/bridje/http/HttpServer.java +++ b/bridje-http/src/main/java/org/bridje/http/HttpServer.java @@ -1,66 +1,66 @@ -/* - * Copyright 2016 Bridje Framework. - * - * Licensed 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.bridje.http; - -import io.netty.bootstrap.ServerBootstrap; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelInitializer; -import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; -import io.netty.channel.socket.SocketChannel; -import io.netty.channel.socket.nio.NioServerSocketChannel; -import java.net.InetSocketAddress; -/** - * - */ -public class HttpServer -{ - private final int port; - - public HttpServer(int port) - { - this.port = port; - } - - public void start() throws Exception - { - final HttpServerHandler serverHandler = new HttpServerHandler(); - EventLoopGroup group = new NioEventLoopGroup(); - try - { - ServerBootstrap b = new ServerBootstrap(); - b.group(group) - .channel(NioServerSocketChannel.class) - .localAddress(new InetSocketAddress(port)) - .childHandler(new ChannelInitializer() - { - @Override - public void initChannel(SocketChannel ch) - throws Exception - { - ch.pipeline().addLast(serverHandler); - } - }); - ChannelFuture f = b.bind(port).sync(); - f.channel().closeFuture().sync(); - } - finally - { - group.shutdownGracefully().sync(); - } - } -} +/* + * Copyright 2016 Bridje Framework. + * + * Licensed 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.bridje.http; + +import io.netty.bootstrap.ServerBootstrap; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelInitializer; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.socket.SocketChannel; +import io.netty.channel.socket.nio.NioServerSocketChannel; +import java.net.InetSocketAddress; +/** + * + */ +public class HttpServer +{ + private final int port; + + public HttpServer(int port) + { + this.port = port; + } + + public void start() throws Exception + { + final HttpServerHandler serverHandler = new HttpServerHandler(); + EventLoopGroup group = new NioEventLoopGroup(); + try + { + ServerBootstrap b = new ServerBootstrap(); + b.group(group) + .channel(NioServerSocketChannel.class) + .localAddress(new InetSocketAddress(port)) + .childHandler(new ChannelInitializer() + { + @Override + public void initChannel(SocketChannel ch) + throws Exception + { + ch.pipeline().addLast(serverHandler); + } + }); + ChannelFuture f = b.bind(port).sync(); + f.channel().closeFuture().sync(); + } + finally + { + group.shutdownGracefully().sync(); + } + } +} diff --git a/bridje-http/src/main/java/org/bridje/http/HttpServerHandler.java b/bridje-http/src/main/java/org/bridje/http/HttpServerHandler.java index ed092ae56..e6eedc76c 100644 --- a/bridje-http/src/main/java/org/bridje/http/HttpServerHandler.java +++ b/bridje-http/src/main/java/org/bridje/http/HttpServerHandler.java @@ -1,58 +1,58 @@ -/* - * Copyright 2016 Bridje Framework. - * - * Licensed 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.bridje.http; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; -import io.netty.channel.ChannelFutureListener; -import io.netty.channel.ChannelHandler.Sharable; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelInboundHandlerAdapter; -import io.netty.util.CharsetUtil; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * - */ -@Sharable -public class HttpServerHandler extends ChannelInboundHandlerAdapter -{ - private static final Logger LOG = Logger.getLogger(HttpServerHandler.class.getName()); - - @Override - public void channelRead(ChannelHandlerContext ctx, Object msg) - { - ByteBuf in = (ByteBuf) msg; - LOG.log(Level.INFO, "Server received: {0}", in.toString(CharsetUtil.UTF_8)); - ctx.write(in); - } - - @Override - public void channelReadComplete(ChannelHandlerContext ctx) - { - ctx.writeAndFlush(Unpooled.EMPTY_BUFFER) - .addListener(ChannelFutureListener.CLOSE); - } - - @Override - public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) - { - LOG.log(Level.SEVERE, cause.getMessage(), cause); - ctx.close(); - } -} +/* + * Copyright 2016 Bridje Framework. + * + * Licensed 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.bridje.http; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import io.netty.channel.ChannelFutureListener; +import io.netty.channel.ChannelHandler.Sharable; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelInboundHandlerAdapter; +import io.netty.util.CharsetUtil; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + */ +@Sharable +public class HttpServerHandler extends ChannelInboundHandlerAdapter +{ + private static final Logger LOG = Logger.getLogger(HttpServerHandler.class.getName()); + + @Override + public void channelRead(ChannelHandlerContext ctx, Object msg) + { + ByteBuf in = (ByteBuf) msg; + LOG.log(Level.INFO, "Server received: {0}", in.toString(CharsetUtil.UTF_8)); + ctx.write(in); + } + + @Override + public void channelReadComplete(ChannelHandlerContext ctx) + { + ctx.writeAndFlush(Unpooled.EMPTY_BUFFER) + .addListener(ChannelFutureListener.CLOSE); + } + + @Override + public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) + { + LOG.log(Level.SEVERE, cause.getMessage(), cause); + ctx.close(); + } +} diff --git a/bridje-http/src/main/java/org/bridje/http/Main.java b/bridje-http/src/main/java/org/bridje/http/Main.java index 0b34a8e9c..6426f36e1 100644 --- a/bridje-http/src/main/java/org/bridje/http/Main.java +++ b/bridje-http/src/main/java/org/bridje/http/Main.java @@ -1,59 +1,59 @@ -/* - * Copyright 2016 Bridje Framework. - * - * Licensed 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.bridje.http; - -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * - */ -public class Main -{ - private static final Logger LOG = Logger.getLogger(Main.class.getName()); - - /** - * @param args the command line arguments - */ - public static void main(String[] args) - { - new Thread(() -> - { - try - { - new HttpServer(8080).start(); - } - catch (Exception e) - { - LOG.log(Level.SEVERE, e.getMessage(), e); - } - }).start(); - - new Thread(() -> - { - try - { - Thread.sleep(1000); - new HttpClient("localhost", 8080).start(); - } - catch (Exception e) - { - LOG.log(Level.SEVERE, e.getMessage(), e); - } - }).start(); - } -} +/* + * Copyright 2016 Bridje Framework. + * + * Licensed 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.bridje.http; + +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + */ +public class Main +{ + private static final Logger LOG = Logger.getLogger(Main.class.getName()); + + /** + * @param args the command line arguments + */ + public static void main(String[] args) + { + new Thread(() -> + { + try + { + new HttpServer(8080).start(); + } + catch (Exception e) + { + LOG.log(Level.SEVERE, e.getMessage(), e); + } + }).start(); + + new Thread(() -> + { + try + { + Thread.sleep(1000); + new HttpClient("localhost", 8080).start(); + } + catch (Exception e) + { + LOG.log(Level.SEVERE, e.getMessage(), e); + } + }).start(); + } +} diff --git a/bridje-ioc/pom.xml b/bridje-ioc/pom.xml index 813012224..beb60fcb8 100644 --- a/bridje-ioc/pom.xml +++ b/bridje-ioc/pom.xml @@ -1,61 +1,61 @@ - - - 4.0.0 - - - org.bridje - bridje-parent - 0.1.3-SNAPSHOT - - - bridje-ioc - - Bridje IoC - Bridje Inversion of Control API - http://www.bridje.org - - - - - org.apache.maven.plugins - maven-compiler-plugin - - -proc:none - - - - org.bsc.maven - maven-processor-plugin - - - org.bridje.ioc.impl.ComponentProcessor - - - - - process - - process - - compile - - - process-test - - process-test - - test-compile - - - - - - - - - junit - junit - test - - - + + + 4.0.0 + + + org.bridje + bridje-parent + 0.1.3-SNAPSHOT + + + bridje-ioc + + Bridje IoC + Bridje Inversion of Control API + http://www.bridje.org + + + + + org.apache.maven.plugins + maven-compiler-plugin + + -proc:none + + + + org.bsc.maven + maven-processor-plugin + + + org.bridje.ioc.impl.ComponentProcessor + + + + + process + + process + + compile + + + process-test + + process-test + + test-compile + + + + + + + + + junit + junit + test + + + diff --git a/bridje-ioc/src/main/java/org/bridje/ioc/ClassNavigator.java b/bridje-ioc/src/main/java/org/bridje/ioc/ClassNavigator.java index 5910cc263..cf3d1f710 100644 --- a/bridje-ioc/src/main/java/org/bridje/ioc/ClassNavigator.java +++ b/bridje-ioc/src/main/java/org/bridje/ioc/ClassNavigator.java @@ -1,41 +1,41 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Alejandro Ferrandiz (acksecurity[at]hotmail.com) - * - * Licensed 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.bridje.ioc; - -import java.lang.annotation.Annotation; - -/** - * Functional interface used by {@link ClassRepository} for navigating annotated - * classes in the inversion of control context. - *

- * @param The annotation that classes must have in orther to be accept by - * the navigator. - */ -@FunctionalInterface -public interface ClassNavigator -{ - /** - * This method is call when ever a class if found to have the given - * annotation. - *

- * @param component The class of the component found. - * @param annotation The instance of the annotation of the component. - */ - void accept(Class component, A annotation); -} +/* + * Copyright 2015 Bridje Framework. + * + * Alejandro Ferrandiz (acksecurity[at]hotmail.com) + * + * Licensed 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.bridje.ioc; + +import java.lang.annotation.Annotation; + +/** + * Functional interface used by {@link ClassRepository} for navigating annotated + * classes in the inversion of control context. + *

+ * @param The annotation that classes must have in orther to be accept by + * the navigator. + */ +@FunctionalInterface +public interface ClassNavigator +{ + /** + * This method is call when ever a class if found to have the given + * annotation. + *

+ * @param component The class of the component found. + * @param annotation The instance of the annotation of the component. + */ + void accept(Class component, A annotation); +} diff --git a/bridje-ioc/src/main/java/org/bridje/ioc/ClassRepository.java b/bridje-ioc/src/main/java/org/bridje/ioc/ClassRepository.java index ae78ab231..6fa202867 100644 --- a/bridje-ioc/src/main/java/org/bridje/ioc/ClassRepository.java +++ b/bridje-ioc/src/main/java/org/bridje/ioc/ClassRepository.java @@ -1,69 +1,69 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.ioc; - -import java.lang.annotation.Annotation; - -/** - * Represents the collection of classes being used by {@link IocContext} to create - * and manage components. - */ -public interface ClassRepository -{ - /** - * Navigates through all methods of all component classes registred in this - * repository, that are annotated with the given annotation. This includes - * superclasses methods. - *

- * @param The type of the annotation methods must be annotated - * with. - * @param annotation The class of the annotation methods must be annotated - * with. - * @param navigator Callback functional interface that handles the - * annotated method. - */ - public void navigateAnnotMethods(Class annotation, MethodNavigator navigator); - - /** - * Navigates through all fields of all component classes registred in this - * repository, that are annotated with the given annotation. This includes - * superclasses fields. - *

- * @param The type of the annotation fields must be annotated - * with. - * @param annotation The class of the annotation fields must be annotated - * with. - * @param navigator Callback functional interface that handles the - * annotated field. - */ - public void navigateAnnotFileds(Class annotation, FieldNavigator navigator); - - /** - * Navigates through all component classes registred in this repository, - * that are annotated with the given annotation. This includes superclasses - * fields. - *

- * @param The type of the annotation classes must be annotated - * with. - * @param annotation The class of the annotation classes must be annotated - * with. - * @param navigator Callback functional interface that handles the - * annotated class. - */ - public void navigateAnnotClasses(Class annotation, ClassNavigator navigator); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.ioc; + +import java.lang.annotation.Annotation; + +/** + * Represents the collection of classes being used by {@link IocContext} to create + * and manage components. + */ +public interface ClassRepository +{ + /** + * Navigates through all methods of all component classes registred in this + * repository, that are annotated with the given annotation. This includes + * superclasses methods. + *

+ * @param The type of the annotation methods must be annotated + * with. + * @param annotation The class of the annotation methods must be annotated + * with. + * @param navigator Callback functional interface that handles the + * annotated method. + */ + public void navigateAnnotMethods(Class annotation, MethodNavigator navigator); + + /** + * Navigates through all fields of all component classes registred in this + * repository, that are annotated with the given annotation. This includes + * superclasses fields. + *

+ * @param The type of the annotation fields must be annotated + * with. + * @param annotation The class of the annotation fields must be annotated + * with. + * @param navigator Callback functional interface that handles the + * annotated field. + */ + public void navigateAnnotFileds(Class annotation, FieldNavigator navigator); + + /** + * Navigates through all component classes registred in this repository, + * that are annotated with the given annotation. This includes superclasses + * fields. + *

+ * @param The type of the annotation classes must be annotated + * with. + * @param annotation The class of the annotation classes must be annotated + * with. + * @param navigator Callback functional interface that handles the + * annotated class. + */ + public void navigateAnnotClasses(Class annotation, ClassNavigator navigator); +} diff --git a/bridje-ioc/src/main/java/org/bridje/ioc/Component.java b/bridje-ioc/src/main/java/org/bridje/ioc/Component.java index 7518ed55e..43b1982d1 100644 --- a/bridje-ioc/src/main/java/org/bridje/ioc/Component.java +++ b/bridje-ioc/src/main/java/org/bridje/ioc/Component.java @@ -1,49 +1,49 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.ioc; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Mark a class as a component so it can be managed by the API. - *

- * This annotation mark any class as an IoC component. if scope of the component - * is no specified it will be an application scoped component. - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -public @interface Component -{ - /** - * Defines the scope of component. - *

- * @return String that represents the scope of the component. - */ - String scope() default "APPLICATION"; - - /** - * If the component must be instantiate eager or lazy - *

- * @return true the component will be instantiated eager, the default is - * false witch means that the component will be instantiated lazy - * the first time some one request it. - */ - boolean instantiate() default false; -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.ioc; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Mark a class as a component so it can be managed by the API. + *

+ * This annotation mark any class as an IoC component. if scope of the component + * is no specified it will be an application scoped component. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface Component +{ + /** + * Defines the scope of component. + *

+ * @return String that represents the scope of the component. + */ + String scope() default "APPLICATION"; + + /** + * If the component must be instantiate eager or lazy + *

+ * @return true the component will be instantiated eager, the default is + * false witch means that the component will be instantiated lazy + * the first time some one request it. + */ + boolean instantiate() default false; +} diff --git a/bridje-ioc/src/main/java/org/bridje/ioc/ContextListener.java b/bridje-ioc/src/main/java/org/bridje/ioc/ContextListener.java index 58d9c90a4..a8f70a61a 100644 --- a/bridje-ioc/src/main/java/org/bridje/ioc/ContextListener.java +++ b/bridje-ioc/src/main/java/org/bridje/ioc/ContextListener.java @@ -1,103 +1,103 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Alejandro Ferrandiz (acksecurity[at]hotmail.com) - * - * Licensed 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.bridje.ioc; - -/** - * A listener for the {@link IocContext}. This interfaz is mean to be - * implemented in order for the container to call his methods upon the events - * that take place on the {@link IocContext} - *

- * The context listener will be any component that implements the interface - * ContextListener, the framework must search all ContextListener - * implementations via the standard way of components resolution and call the 3 - * methods of the interface in the propper place. - *

- * @param Component class that you want listen. - * - * EXAMPLES - *

- * @Component
- * class MyContextListener implement ContextListener<MyComponent>
- * {
- *      public void preCreateComponent(Class<MyComponent>; component)
- *      {
- *          //only is call when MyComponent is pre create
- *      }
- *
- *      public void preInitComponent(Class<MyComponent> component)
- *      {
- *          //only is call when MyComponent is pre init
- *      }
- *
- *      public void postInitComponent(Class<MyComponent> component)
- *      {
- *          //only is call when MyComponent is post init
- *      }
- * }
- * 
- * - * If you want to listen to all components use Object - * - *
- * @Component
- * class MyContextListener implement ContextListener<Object>
- * {
- *      public void preCreateComponent(Class<Object> component)
- *      {
- *          //is call for each component pre create
- *      }
- *
- *      public void preInitComponent(Class<Object> component)
- *      {
- *          //is call for each component pre init
- *      }
- *
- *      public void postInitComponent(Class<Object> component)
- *      {
- *          //is call for each component post init
- *      }
- * }
- * 
- */ -public interface ContextListener -{ - /** - * Will be called before a component is created - * - * @param clazz The component class - */ - void preCreateComponent(Class clazz); - - /** - * Will be called after the component has been instantiate and before - * injecting the components dependencies - * - * @param clazz The component class - * @param instance The component instance - */ - void preInitComponent(Class clazz, T instance); - - /** - * Will be called after the components dependencies injection. - * - * @param clazz The component class - * @param instance The component instance - */ - void postInitComponent(Class clazz, T instance); - -} +/* + * Copyright 2015 Bridje Framework. + * + * Alejandro Ferrandiz (acksecurity[at]hotmail.com) + * + * Licensed 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.bridje.ioc; + +/** + * A listener for the {@link IocContext}. This interfaz is mean to be + * implemented in order for the container to call his methods upon the events + * that take place on the {@link IocContext} + *

+ * The context listener will be any component that implements the interface + * ContextListener, the framework must search all ContextListener + * implementations via the standard way of components resolution and call the 3 + * methods of the interface in the propper place. + *

+ * @param Component class that you want listen. + * + * EXAMPLES + *

+ * @Component
+ * class MyContextListener implement ContextListener<MyComponent>
+ * {
+ *      public void preCreateComponent(Class<MyComponent>; component)
+ *      {
+ *          //only is call when MyComponent is pre create
+ *      }
+ *
+ *      public void preInitComponent(Class<MyComponent> component)
+ *      {
+ *          //only is call when MyComponent is pre init
+ *      }
+ *
+ *      public void postInitComponent(Class<MyComponent> component)
+ *      {
+ *          //only is call when MyComponent is post init
+ *      }
+ * }
+ * 
+ * + * If you want to listen to all components use Object + * + *
+ * @Component
+ * class MyContextListener implement ContextListener<Object>
+ * {
+ *      public void preCreateComponent(Class<Object> component)
+ *      {
+ *          //is call for each component pre create
+ *      }
+ *
+ *      public void preInitComponent(Class<Object> component)
+ *      {
+ *          //is call for each component pre init
+ *      }
+ *
+ *      public void postInitComponent(Class<Object> component)
+ *      {
+ *          //is call for each component post init
+ *      }
+ * }
+ * 
+ */ +public interface ContextListener +{ + /** + * Will be called before a component is created + * + * @param clazz The component class + */ + void preCreateComponent(Class clazz); + + /** + * Will be called after the component has been instantiate and before + * injecting the components dependencies + * + * @param clazz The component class + * @param instance The component instance + */ + void preInitComponent(Class clazz, T instance); + + /** + * Will be called after the components dependencies injection. + * + * @param clazz The component class + * @param instance The component instance + */ + void postInitComponent(Class clazz, T instance); + +} diff --git a/bridje-ioc/src/main/java/org/bridje/ioc/FieldNavigator.java b/bridje-ioc/src/main/java/org/bridje/ioc/FieldNavigator.java index fc5da668e..7d1ab02d1 100644 --- a/bridje-ioc/src/main/java/org/bridje/ioc/FieldNavigator.java +++ b/bridje-ioc/src/main/java/org/bridje/ioc/FieldNavigator.java @@ -1,44 +1,44 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Alejandro Ferrandiz (acksecurity[at]hotmail.com) - * - * Licensed 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.bridje.ioc; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Field; - -/** - * Functional interface used by {@link ClassRepository} for navigating annotated - * fields in the inversion of control context. - *

- * @param The annotation that the fields must have in orther to be accept by - * the navigator. - */ -@FunctionalInterface -public interface FieldNavigator -{ - /** - * This method is call when ever a field in a component if found to have the - * given annotation. - *

- * @param field The field been found. - * @param component The class of the component that contains the found - * field. - * @param annotation The instance of the annotation of the field. - */ - void accept(Field field, Class component, A annotation); -} +/* + * Copyright 2015 Bridje Framework. + * + * Alejandro Ferrandiz (acksecurity[at]hotmail.com) + * + * Licensed 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.bridje.ioc; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Field; + +/** + * Functional interface used by {@link ClassRepository} for navigating annotated + * fields in the inversion of control context. + *

+ * @param The annotation that the fields must have in orther to be accept by + * the navigator. + */ +@FunctionalInterface +public interface FieldNavigator +{ + /** + * This method is call when ever a field in a component if found to have the + * given annotation. + *

+ * @param field The field been found. + * @param component The class of the component that contains the found + * field. + * @param annotation The instance of the annotation of the field. + */ + void accept(Field field, Class component, A annotation); +} diff --git a/bridje-ioc/src/main/java/org/bridje/ioc/Inject.java b/bridje-ioc/src/main/java/org/bridje/ioc/Inject.java index 1d51e4839..e9ced2b6f 100644 --- a/bridje-ioc/src/main/java/org/bridje/ioc/Inject.java +++ b/bridje-ioc/src/main/java/org/bridje/ioc/Inject.java @@ -1,34 +1,34 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.ioc; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * This annotation specify that the field on witch is declared is a component - * dependency, the container will find (any/all) component that provides the - * service and inject the instance of it in this field. Cannot be use in static - * fields, but it may be use in parent classes of components. - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface Inject -{ -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.ioc; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * This annotation specify that the field on witch is declared is a component + * dependency, the container will find (any/all) component that provides the + * service and inject the instance of it in this field. Cannot be use in static + * fields, but it may be use in parent classes of components. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface Inject +{ +} diff --git a/bridje-ioc/src/main/java/org/bridje/ioc/InjectNext.java b/bridje-ioc/src/main/java/org/bridje/ioc/InjectNext.java index 95e1a5cfe..55c625648 100644 --- a/bridje-ioc/src/main/java/org/bridje/ioc/InjectNext.java +++ b/bridje-ioc/src/main/java/org/bridje/ioc/InjectNext.java @@ -1,33 +1,33 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.ioc; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * This annotation specify behaves in the same way as the {@link Inject} annotation - * except that it will look only for components that has a priority value bigger thant - * the current component. - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface InjectNext -{ -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.ioc; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * This annotation specify behaves in the same way as the {@link Inject} annotation + * except that it will look only for components that has a priority value bigger thant + * the current component. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface InjectNext +{ +} diff --git a/bridje-ioc/src/main/java/org/bridje/ioc/Ioc.java b/bridje-ioc/src/main/java/org/bridje/ioc/Ioc.java index 289f87459..a49ee7ef0 100644 --- a/bridje-ioc/src/main/java/org/bridje/ioc/Ioc.java +++ b/bridje-ioc/src/main/java/org/bridje/ioc/Ioc.java @@ -1,47 +1,47 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.ioc; - -import org.bridje.ioc.impl.ContextFactory; - -/** - * Facade for the Bridje IoC API. - *

- * This class provides the method context() which will deliver the IocContext - * for the application scope. - */ -public class Ioc -{ - /** - * Private constructor so this object cannot be instantiated. - */ - private Ioc() - { - } - - /** - * This method returns the {@link IocContext} for the APPLICATION scoped - * {@link IocContext}. - *

- * @return The APPLICATION scoped {@link IocContext} instance for this - * application. - */ - public static IocContext context() - { - return ContextFactory.context(); - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.ioc; + +import org.bridje.ioc.impl.ContextFactory; + +/** + * Facade for the Bridje IoC API. + *

+ * This class provides the method context() which will deliver the IocContext + * for the application scope. + */ +public class Ioc +{ + /** + * Private constructor so this object cannot be instantiated. + */ + private Ioc() + { + } + + /** + * This method returns the {@link IocContext} for the APPLICATION scoped + * {@link IocContext}. + *

+ * @return The APPLICATION scoped {@link IocContext} instance for this + * application. + */ + public static IocContext context() + { + return ContextFactory.context(); + } +} diff --git a/bridje-ioc/src/main/java/org/bridje/ioc/IocContext.java b/bridje-ioc/src/main/java/org/bridje/ioc/IocContext.java index 68a343070..a37d65da9 100644 --- a/bridje-ioc/src/main/java/org/bridje/ioc/IocContext.java +++ b/bridje-ioc/src/main/java/org/bridje/ioc/IocContext.java @@ -1,167 +1,167 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.ioc; - -import java.lang.reflect.Type; -import java.util.Collection; - -/** - * Represents a context in witch components are managed. This interface is mean - * to be use (not for implementation), it brings all the method necessaries for - * find components and services in the scope that it manages. - *

- * An implementation of this interface can be obtained via the Ioc interface or - * by injecting {@link org.bridje.ioc.Inject} it in any component - * you want. - */ -public interface IocContext -{ - /** - * Gets the scope of the current context. - * - * @return An string object representing the scope name used for this - * context. - */ - String getScope(); - - /** - * This method finds the highest priority component that provides the given - * service. - *

- * @param The generic type of the class of the service that this method - * should find. - * @param service The class that represents the service that this method - * must find. - *

- * @return An object that extends or implement the class of the service - * provided, or null if no component provides this services in the context. - */ - T find(Class service); - - /** - * This method finds the component that provides the given service with less - * priority than the priority parameter. - *

- * @param The generic type of the class of the service that this method - * should find. - * @param service The class that represents the service that this method - * must find. - *

- * @param priority The given component must have a priority value greater - * than this parameter. - *

- * @return An object that extends or implement the class of the service - * provided, or null if no component provides this services in the context. - */ - T findNext(Class service, int priority); - - /** - * This method finds all the components that provides the given service. - *

- * @param The generic type of the class of the service that this method - * should find. - * @param service The class that represents the service that this method - * must find. - *

- * @return An array of objects who extends or implement the class of the - * service provided, or an empty array if no component provides this - * services in the context. - */ - T[] findAll(Class service); - - /** - * This method finds the highest priority component that provides the given - * generic service. - *

- * @param service The {@link java.lang.reflect.Type} that represents the - * service that this method must find. - *

- * @return An object that extends or implement the service provided, or null - * if no component provides this services in the context. - */ - Object findGeneric(Type service); - - /** - * This method finds the component that provides the given generic service - * with less priority than the priority parameter. - *

- * @param service The {@link java.lang.reflect.Type} that represents the - * service that this method must find. - *

- * @param priority The given component must have a priority value greater - * than this parameter. - *

- * @return An object that extends or implement the service provided, or null - * if no component provides this services in the context. - */ - Object findNextGeneric(Type service, int priority); - - /** - * This method finds if a service is provided by a least one component in - * the context. - *

- * @param service The type of the service to look for. - *

- * @return {@literal true} If at least one component provides this service, - * {@literal false} otherwise. - */ - boolean exists(Type service); - - /** - * This method finds if the given class is a component of the context. - *

- * @param component The class of the component to look for. - *

- * @return {@literal true} If this class represents a component of the - * context, {@literal false} otherwise. - */ - boolean existsComponent(Class component); - - /** - * The parent of this context. - *

- * @return The IocContext instance representing the parent of this context, - * or null if this context has no parent. - */ - IocContext getParent(); - - /** - * Create a child IocContext of this context. - *

- * @param scope The scope of the new context. - * @return The new IocContext instance created as child of this context. - */ - IocContext createChild(String scope); - - /** - * Create a child IocContext of this context. - *

- * @param scope The scope of the new context. - * @param instances A collection of objects that will be components of the - * new context. - * @return The new IocContext instance created as child of this context. - */ - IocContext createChild(String scope, Collection instances); - - /** - * Obtains the class repository associated with this context. that allows to - * find classes, fields and methods of the components in this context. - *

- * @return A ClassRepository instance - */ - ClassRepository getClassRepository(); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.ioc; + +import java.lang.reflect.Type; +import java.util.Collection; + +/** + * Represents a context in witch components are managed. This interface is mean + * to be use (not for implementation), it brings all the method necessaries for + * find components and services in the scope that it manages. + *

+ * An implementation of this interface can be obtained via the Ioc interface or + * by injecting {@link org.bridje.ioc.Inject} it in any component + * you want. + */ +public interface IocContext +{ + /** + * Gets the scope of the current context. + * + * @return An string object representing the scope name used for this + * context. + */ + String getScope(); + + /** + * This method finds the highest priority component that provides the given + * service. + *

+ * @param The generic type of the class of the service that this method + * should find. + * @param service The class that represents the service that this method + * must find. + *

+ * @return An object that extends or implement the class of the service + * provided, or null if no component provides this services in the context. + */ + T find(Class service); + + /** + * This method finds the component that provides the given service with less + * priority than the priority parameter. + *

+ * @param The generic type of the class of the service that this method + * should find. + * @param service The class that represents the service that this method + * must find. + *

+ * @param priority The given component must have a priority value greater + * than this parameter. + *

+ * @return An object that extends or implement the class of the service + * provided, or null if no component provides this services in the context. + */ + T findNext(Class service, int priority); + + /** + * This method finds all the components that provides the given service. + *

+ * @param The generic type of the class of the service that this method + * should find. + * @param service The class that represents the service that this method + * must find. + *

+ * @return An array of objects who extends or implement the class of the + * service provided, or an empty array if no component provides this + * services in the context. + */ + T[] findAll(Class service); + + /** + * This method finds the highest priority component that provides the given + * generic service. + *

+ * @param service The {@link java.lang.reflect.Type} that represents the + * service that this method must find. + *

+ * @return An object that extends or implement the service provided, or null + * if no component provides this services in the context. + */ + Object findGeneric(Type service); + + /** + * This method finds the component that provides the given generic service + * with less priority than the priority parameter. + *

+ * @param service The {@link java.lang.reflect.Type} that represents the + * service that this method must find. + *

+ * @param priority The given component must have a priority value greater + * than this parameter. + *

+ * @return An object that extends or implement the service provided, or null + * if no component provides this services in the context. + */ + Object findNextGeneric(Type service, int priority); + + /** + * This method finds if a service is provided by a least one component in + * the context. + *

+ * @param service The type of the service to look for. + *

+ * @return {@literal true} If at least one component provides this service, + * {@literal false} otherwise. + */ + boolean exists(Type service); + + /** + * This method finds if the given class is a component of the context. + *

+ * @param component The class of the component to look for. + *

+ * @return {@literal true} If this class represents a component of the + * context, {@literal false} otherwise. + */ + boolean existsComponent(Class component); + + /** + * The parent of this context. + *

+ * @return The IocContext instance representing the parent of this context, + * or null if this context has no parent. + */ + IocContext getParent(); + + /** + * Create a child IocContext of this context. + *

+ * @param scope The scope of the new context. + * @return The new IocContext instance created as child of this context. + */ + IocContext createChild(String scope); + + /** + * Create a child IocContext of this context. + *

+ * @param scope The scope of the new context. + * @param instances A collection of objects that will be components of the + * new context. + * @return The new IocContext instance created as child of this context. + */ + IocContext createChild(String scope, Collection instances); + + /** + * Obtains the class repository associated with this context. that allows to + * find classes, fields and methods of the components in this context. + *

+ * @return A ClassRepository instance + */ + ClassRepository getClassRepository(); +} diff --git a/bridje-ioc/src/main/java/org/bridje/ioc/MethodNavigator.java b/bridje-ioc/src/main/java/org/bridje/ioc/MethodNavigator.java index dbf1c31f8..90d971159 100644 --- a/bridje-ioc/src/main/java/org/bridje/ioc/MethodNavigator.java +++ b/bridje-ioc/src/main/java/org/bridje/ioc/MethodNavigator.java @@ -1,42 +1,42 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.ioc; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Method; - -/** - * Functional interface used by {@link ClassRepository} for navigating annotated - * methods in the inversion of control context. - *

- * @param The annotation that the methods must have in orther to be accept by - * the navigator. - */ -@FunctionalInterface -public interface MethodNavigator -{ - /** - * This method is call when ever a method in a component if found to have the - * given annotation. - *

- * @param method The method been found. - * @param component The class of the component that contains the found - * method. - * @param annotation The instance of the annotation of the method. - */ - void accept(Method method, Class component, A annotation); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.ioc; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Method; + +/** + * Functional interface used by {@link ClassRepository} for navigating annotated + * methods in the inversion of control context. + *

+ * @param The annotation that the methods must have in orther to be accept by + * the navigator. + */ +@FunctionalInterface +public interface MethodNavigator +{ + /** + * This method is call when ever a method in a component if found to have the + * given annotation. + *

+ * @param method The method been found. + * @param component The class of the component that contains the found + * method. + * @param annotation The instance of the annotation of the method. + */ + void accept(Method method, Class component, A annotation); +} diff --git a/bridje-ioc/src/main/java/org/bridje/ioc/Priority.java b/bridje-ioc/src/main/java/org/bridje/ioc/Priority.java index a6bcfdd96..48beda1bf 100644 --- a/bridje-ioc/src/main/java/org/bridje/ioc/Priority.java +++ b/bridje-ioc/src/main/java/org/bridje/ioc/Priority.java @@ -1,40 +1,40 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.ioc; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Defines the priority of the component in a way that the small values are the - * highest priority component. The container will use this annotation to find - * out the default implementation (the one with highest priority) for the given - * service. - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -public @interface Priority -{ - /** - * The priority of the component. - *

- * @return An intenger witch represents the priority of the component. - */ - int value() default Integer.MAX_VALUE; -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.ioc; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Defines the priority of the component in a way that the small values are the + * highest priority component. The container will use this annotation to find + * out the default implementation (the one with highest priority) for the given + * service. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface Priority +{ + /** + * The priority of the component. + *

+ * @return An intenger witch represents the priority of the component. + */ + int value() default Integer.MAX_VALUE; +} diff --git a/bridje-ioc/src/main/java/org/bridje/ioc/impl/ClassSet.java b/bridje-ioc/src/main/java/org/bridje/ioc/impl/ClassSet.java index d41c2e6b3..ab414e8a9 100644 --- a/bridje-ioc/src/main/java/org/bridje/ioc/impl/ClassSet.java +++ b/bridje-ioc/src/main/java/org/bridje/ioc/impl/ClassSet.java @@ -1,328 +1,328 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.ioc.impl; - -import java.io.IOException; -import java.io.InputStream; -import java.lang.annotation.Annotation; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.net.URL; -import java.util.Arrays; -import java.util.Collection; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Properties; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.bridje.ioc.ClassRepository; -import org.bridje.ioc.ClassNavigator; -import org.bridje.ioc.MethodNavigator; -import org.bridje.ioc.FieldNavigator; - -/** - * This class represents a set of classes, his propouse is to serve as a - * container for all the class that are to be managed by an IocContext instance. - * - */ -class ClassSet implements Iterable>, ClassRepository -{ - /** - * Logger for this class - */ - private static final Logger LOG = Logger.getLogger(ComponentProcessor.class.getName()); - - /** - * All ClassSets availables by scope. - */ - private static Map classSetCache; - - /** - * Al the components declared in the components.properties files. - */ - private static Map propFilesCache; - - /** - * The set of classes for this intance. - */ - private final Set> clsSet; - - /** - * Default constructor for internal use of this class only. - */ - private ClassSet() - { - clsSet = new HashSet<>(); - } - - /** - * Constructor that receive an arbitrary collection of classes. - * - * @param classes The collection of classes to be present in this set of - * classes. - */ - public ClassSet(Collection> classes) - { - this(); - if (classes != null && !classes.isEmpty()) - { - clsSet.addAll(classes); - } - } - - /** - * Constructor that receive an array of classes. - * - * @param classes The array of classes to be present in this set of classes. - */ - public ClassSet(Class... classes) - { - this(asList(classes)); - } - - /** - * Constructor that receive an array of ClassSets. - * - * @param lsts The array of ClassSets to be present in this set of classes. - */ - public ClassSet(ClassSet... lsts) - { - this(); - if (lsts != null && lsts.length > 0) - { - for (ClassSet clst : lsts) - { - if (clst != null && !clst.isEmpty()) - { - clsSet.addAll(clst.clsSet); - } - } - } - } - - /** - * Determines whenever a class exist whiting the class set. - * - * @param cls The class to lookup. - * @return true the class exists, false otherwise. - */ - public boolean contains(Class cls) - { - return clsSet.contains(cls); - } - - /** - * Determines if this class set has any classes or not. - * - * @return true this CassSet does not have any classes, false otherwise. - */ - public boolean isEmpty() - { - return clsSet.isEmpty(); - } - - /** - * Gets the class iterator for this class set. - * - * @return An iterator of classes. - */ - @Override - public Iterator> iterator() - { - return clsSet.iterator(); - } - - /** - * Finds a ClassSet that contains all the classes in the especified scope. - * - * @param scope The scope of the classes to lookup. - * @return A ClassSet containing all the classes in the especified scope. - */ - public static ClassSet findByScope(String scope) - { - if (classSetCache == null) - { - classSetCache = new ConcurrentHashMap<>(); - } - if (classSetCache.containsKey(scope)) - { - return classSetCache.get(scope); - } - try - { - ClassSet result = loadFromClassPath(scope); - if (result != null) - { - classSetCache.put(scope, result); - return result; - } - } - catch (Exception ex) - { - LOG.log(Level.SEVERE, ex.getMessage(), ex); - } - return null; - } - - /** - * Load all classes of the especified scope from the class path. - * - * @param scope The scope to load. - * @return A ClassSet containing all the classes in the scope, that where - * found in the classpath. - * @throws IOException If something whent wrong. - */ - private static ClassSet loadFromClassPath(String scope) throws IOException - { - Set> clsList = new HashSet<>(); - //An instance of IocContextImpl is always a component in every scope. - clsList.add(ContextImpl.class); - if (propFilesCache == null) - { - propFilesCache = loadPropFilesCache(); - } - for (Map.Entry entrySet : propFilesCache.entrySet()) - { - String clsName = entrySet.getKey(); - String compScope = entrySet.getValue(); - if (null != compScope && compScope.equalsIgnoreCase(scope)) - { - try - { - clsList.add(Class.forName(clsName)); - } - catch (ClassNotFoundException ex) - { - LOG.log(Level.SEVERE, null, ex); - } - } - } - if (clsList.isEmpty()) - { - return null; - } - return new ClassSet(clsList); - } - - /** - * Loads all of the components.properties files in the class path. - * - * @return A map containing the combination of all the components.properties - * files present in the class path. - * @throws IOException If a file cannot be readed. - */ - private static Map loadPropFilesCache() throws IOException - { - Map result = new HashMap<>(); - Enumeration resources = Thread.currentThread().getContextClassLoader().getResources(ComponentProcessor.COMPONENTS_RESOURCE_FILE); - while (resources.hasMoreElements()) - { - URL nextElement = resources.nextElement(); - Properties prop = new Properties(); - try (InputStream is = nextElement.openStream()) - { - prop.load(is); - } - prop.forEach((key, value) - -> - { - String clsName = (String) key; - String compScope = (String) value; - result.put(clsName, compScope); - }); - } - return result; - } - - /** - * The size of this ClassSet. - * - * @return The amount of classes this ClassSet contains. - */ - public int size() - { - return clsSet.size(); - } - - /** - * Utility method to convert from array to Collection of classes. - * - * @param clss The array of clases to be converted. - * @return A collection containing the classes in the passed array. - */ - private static Collection> asList(Class... clss) - { - if (clss == null || clss.length == 0) - { - return null; - } - return Arrays.asList(clss); - } - - @Override - public void navigateAnnotMethods(Class annotation, MethodNavigator navigator) - { - for (Class cls : this) - { - Method[] methods = cls.getDeclaredMethods(); - for (Method method : methods) - { - A annInst = method.getAnnotation(annotation); - if (annInst != null) - { - navigator.accept(method, cls, annInst); - } - } - } - } - - @Override - public void navigateAnnotFileds(Class annotation, FieldNavigator navigator) - { - for (Class cls : this) - { - Field[] fields = cls.getDeclaredFields(); - for (Field field : fields) - { - A annInst = field.getAnnotation(annotation); - if (annInst != null) - { - navigator.accept(field, cls, annInst); - } - } - } - } - - @Override - public void navigateAnnotClasses(Class annotation, ClassNavigator navigator) - { - for (Class cls : this) - { - A annot = cls.getAnnotation(annotation); - if (annot != null) - { - navigator.accept(cls, annot); - break; - } - } - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.ioc.impl; + +import java.io.IOException; +import java.io.InputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.net.URL; +import java.util.Arrays; +import java.util.Collection; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.bridje.ioc.ClassRepository; +import org.bridje.ioc.ClassNavigator; +import org.bridje.ioc.MethodNavigator; +import org.bridje.ioc.FieldNavigator; + +/** + * This class represents a set of classes, his propouse is to serve as a + * container for all the class that are to be managed by an IocContext instance. + * + */ +class ClassSet implements Iterable>, ClassRepository +{ + /** + * Logger for this class + */ + private static final Logger LOG = Logger.getLogger(ComponentProcessor.class.getName()); + + /** + * All ClassSets availables by scope. + */ + private static Map classSetCache; + + /** + * Al the components declared in the components.properties files. + */ + private static Map propFilesCache; + + /** + * The set of classes for this intance. + */ + private final Set> clsSet; + + /** + * Default constructor for internal use of this class only. + */ + private ClassSet() + { + clsSet = new HashSet<>(); + } + + /** + * Constructor that receive an arbitrary collection of classes. + * + * @param classes The collection of classes to be present in this set of + * classes. + */ + public ClassSet(Collection> classes) + { + this(); + if (classes != null && !classes.isEmpty()) + { + clsSet.addAll(classes); + } + } + + /** + * Constructor that receive an array of classes. + * + * @param classes The array of classes to be present in this set of classes. + */ + public ClassSet(Class... classes) + { + this(asList(classes)); + } + + /** + * Constructor that receive an array of ClassSets. + * + * @param lsts The array of ClassSets to be present in this set of classes. + */ + public ClassSet(ClassSet... lsts) + { + this(); + if (lsts != null && lsts.length > 0) + { + for (ClassSet clst : lsts) + { + if (clst != null && !clst.isEmpty()) + { + clsSet.addAll(clst.clsSet); + } + } + } + } + + /** + * Determines whenever a class exist whiting the class set. + * + * @param cls The class to lookup. + * @return true the class exists, false otherwise. + */ + public boolean contains(Class cls) + { + return clsSet.contains(cls); + } + + /** + * Determines if this class set has any classes or not. + * + * @return true this CassSet does not have any classes, false otherwise. + */ + public boolean isEmpty() + { + return clsSet.isEmpty(); + } + + /** + * Gets the class iterator for this class set. + * + * @return An iterator of classes. + */ + @Override + public Iterator> iterator() + { + return clsSet.iterator(); + } + + /** + * Finds a ClassSet that contains all the classes in the especified scope. + * + * @param scope The scope of the classes to lookup. + * @return A ClassSet containing all the classes in the especified scope. + */ + public static ClassSet findByScope(String scope) + { + if (classSetCache == null) + { + classSetCache = new ConcurrentHashMap<>(); + } + if (classSetCache.containsKey(scope)) + { + return classSetCache.get(scope); + } + try + { + ClassSet result = loadFromClassPath(scope); + if (result != null) + { + classSetCache.put(scope, result); + return result; + } + } + catch (Exception ex) + { + LOG.log(Level.SEVERE, ex.getMessage(), ex); + } + return null; + } + + /** + * Load all classes of the especified scope from the class path. + * + * @param scope The scope to load. + * @return A ClassSet containing all the classes in the scope, that where + * found in the classpath. + * @throws IOException If something whent wrong. + */ + private static ClassSet loadFromClassPath(String scope) throws IOException + { + Set> clsList = new HashSet<>(); + //An instance of IocContextImpl is always a component in every scope. + clsList.add(ContextImpl.class); + if (propFilesCache == null) + { + propFilesCache = loadPropFilesCache(); + } + for (Map.Entry entrySet : propFilesCache.entrySet()) + { + String clsName = entrySet.getKey(); + String compScope = entrySet.getValue(); + if (null != compScope && compScope.equalsIgnoreCase(scope)) + { + try + { + clsList.add(Class.forName(clsName)); + } + catch (ClassNotFoundException ex) + { + LOG.log(Level.SEVERE, null, ex); + } + } + } + if (clsList.isEmpty()) + { + return null; + } + return new ClassSet(clsList); + } + + /** + * Loads all of the components.properties files in the class path. + * + * @return A map containing the combination of all the components.properties + * files present in the class path. + * @throws IOException If a file cannot be readed. + */ + private static Map loadPropFilesCache() throws IOException + { + Map result = new HashMap<>(); + Enumeration resources = Thread.currentThread().getContextClassLoader().getResources(ComponentProcessor.COMPONENTS_RESOURCE_FILE); + while (resources.hasMoreElements()) + { + URL nextElement = resources.nextElement(); + Properties prop = new Properties(); + try (InputStream is = nextElement.openStream()) + { + prop.load(is); + } + prop.forEach((key, value) + -> + { + String clsName = (String) key; + String compScope = (String) value; + result.put(clsName, compScope); + }); + } + return result; + } + + /** + * The size of this ClassSet. + * + * @return The amount of classes this ClassSet contains. + */ + public int size() + { + return clsSet.size(); + } + + /** + * Utility method to convert from array to Collection of classes. + * + * @param clss The array of clases to be converted. + * @return A collection containing the classes in the passed array. + */ + private static Collection> asList(Class... clss) + { + if (clss == null || clss.length == 0) + { + return null; + } + return Arrays.asList(clss); + } + + @Override + public void navigateAnnotMethods(Class annotation, MethodNavigator navigator) + { + for (Class cls : this) + { + Method[] methods = cls.getDeclaredMethods(); + for (Method method : methods) + { + A annInst = method.getAnnotation(annotation); + if (annInst != null) + { + navigator.accept(method, cls, annInst); + } + } + } + } + + @Override + public void navigateAnnotFileds(Class annotation, FieldNavigator navigator) + { + for (Class cls : this) + { + Field[] fields = cls.getDeclaredFields(); + for (Field field : fields) + { + A annInst = field.getAnnotation(annotation); + if (annInst != null) + { + navigator.accept(field, cls, annInst); + } + } + } + } + + @Override + public void navigateAnnotClasses(Class annotation, ClassNavigator navigator) + { + for (Class cls : this) + { + A annot = cls.getAnnotation(annotation); + if (annot != null) + { + navigator.accept(cls, annot); + break; + } + } + } +} diff --git a/bridje-ioc/src/main/java/org/bridje/ioc/impl/ClassUtils.java b/bridje-ioc/src/main/java/org/bridje/ioc/impl/ClassUtils.java index 97c870b7d..7c782f542 100644 --- a/bridje-ioc/src/main/java/org/bridje/ioc/impl/ClassUtils.java +++ b/bridje-ioc/src/main/java/org/bridje/ioc/impl/ClassUtils.java @@ -1,553 +1,553 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.ioc.impl; - -import java.lang.reflect.Constructor; -import java.lang.reflect.GenericArrayType; -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; -import java.lang.reflect.TypeVariable; -import java.lang.reflect.WildcardType; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.concurrent.PriorityBlockingQueue; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.bridje.ioc.Priority; - -/** - * Utility method for class and type handling. - */ -class ClassUtils -{ - /** - * Logger for this class - */ - private static final Logger LOG = Logger.getLogger(ClassUtils.class.getName()); - - /** - * Gets the upper bounds Type for a WildcarType. - * - *

-     * ? extends SomeService               = SomeService
-     * ? extends SomeService<String> = SomeService<String>
-     * 
- * - * @param service The wildcardType to inspect. - * @return The upper bounds Type of the WildcardType. - */ - public static Type typeOf(WildcardType service) - { - Type[] upperBounds = ((WildcardType) service).getUpperBounds(); - if (upperBounds.length == 1) - { - return (upperBounds[0]); - } - else if (upperBounds.length == 0) - { - return Object.class; - } - return null; - } - - /** - * Find the Type of an array, map or collection. - * - *
-     * SomeService[]                 = SomeService
-     * List<SomeService>       = SomeService
-     * Map<Class, SomeService> = SomeService
-     * 
- * - * @param service The inner type of the multiple type passed. - * @return A type representing the inner type for the collection, array or - * map passed. - */ - public static Type multipleType(Type service) - { - if (isArray(service)) - { - return arrayType(service); - } - else if (isCollection(service)) - { - return collectionType(service); - } - else if (isMap(service)) - { - return mapType(service); - } - return null; - } - - /** - * Find the Type of an array. - * - *
-     * SomeService[] = SomeService
-     * 
- * - * @param service The inner type of the array type passed. - * @return A type representing the inner type for the array type passed. - */ - public static Type arrayType(Type service) - { - if (service instanceof GenericArrayType) - { - Type rawType = ((GenericArrayType) service).getGenericComponentType(); - return rawType; - } - else if (service instanceof Class) - { - return ((Class) service).getComponentType(); - } - return null; - } - - /** - * Find the Type of collection. - * - *
-     * List<SomeService> = SomeService
-     * Set<SomeService>  = SomeService
-     * 
- * - * @param service The inner type of the array type passed. - * @return A type representing the inner type for the collection type - * passed. - */ - public static Type collectionType(Type service) - { - if (service instanceof ParameterizedType) - { - Type[] args = ((ParameterizedType) service).getActualTypeArguments(); - if (args.length == 1) - { - return args[0]; - } - } - return null; - } - - /** - * Find the Type of a map. - * - *
-     * Map<Class, SomeService>     = SomeService
-     * HashMap<Class, SomeService> = SomeService
-     * 
- * - * @param service The inner type of the array type passed. - * @return A type representing the inner type for the map type passed. - */ - public static Type mapType(Type service) - { - if (service instanceof ParameterizedType) - { - Type[] args = ((ParameterizedType) service).getActualTypeArguments(); - if (args.length == 2) - { - return args[1]; - } - } - return null; - } - - /** - * Determines whenever the passed type is an array, a java collection like - * List or Set, or a java Map. - *
-     * SomeService                      = false
-     * SomeService[]                    = true
-     * List<SomeService>          = true
-     * Map<Class, SomeService>    = true
-     * MyListImpl<SomeService>    = false
-     * HashMap<Class, SomeService> = true
-     * 
- * - * @param service The type to inspect. - * @return true if the especified type is an array, a collection or map from - * java languaje. - */ - public static boolean isMultiple(Type service) - { - return isArray(service) || isCollection(service) || isMap(service); - } - - /** - * Determines whenever the passed type is an array. - *
-     * SomeService                      = false
-     * SomeService[]                    = true
-     * List<SomeService>          = false
-     * List<SomeService>[]        = true
-     * Map<Class, SomeService>    = false
-     * MyListImpl<SomeService>    = false
-     * HashMap<Class, SomeService> = false
-     * 
- * - * @param service The type to inspect. - * @return true if the especified type is an array. - */ - public static boolean isArray(Type service) - { - if (service instanceof Class) - { - return ((Class) service).isArray(); - } - else - { - return service instanceof GenericArrayType; - } - } - - /** - * Determines whenever the passed type is a collection. - *
-     * SomeService                      = false
-     * SomeService[]                    = false
-     * List<SomeService>          = true
-     * List<SomeService>[]        = true
-     * Map<Class, SomeService>    = false
-     * MyListImpl<SomeService>    = false
-     * HashMap<Class, SomeService> = false
-     * 
- * - * @param service The type to inspect. - * @return true if the especified type is a List Set or other java - * collection except a map. - */ - public static boolean isCollection(Type service) - { - Class cls = rawClass(service); - if (cls == null || cls.isArray() || cls.getPackage() == null) - { - return false; - } - return cls.getPackage().getName().startsWith("java.") - && Collection.class.isAssignableFrom(cls) - && !Map.class.isAssignableFrom(cls); - } - - /** - * Determines whenever the passed type is a map. - *
-     * SomeService                      = false
-     * SomeService[]                    = false
-     * List<SomeService>          = false
-     * List<SomeService>[]        = false
-     * Map<Class, SomeService>    = true
-     * MyListImpl<SomeService>    = false
-     * HashMap<Class, SomeService> = true
-     * 
- * - * @param service The type to inspect. - * @return true if the especified type is a java Map. - */ - public static boolean isMap(Type service) - { - Class cls = rawClass(service); - if (cls == null || cls.isArray() || cls.getPackage() == null) - { - return false; - } - return cls.getPackage().getName().startsWith("java.") - && Map.class.isAssignableFrom(cls); - } - - /** - * Gets the raw class for the especified Type. - *
-     * SomeService                      = SomeService
-     * SomeService[]                    = SomeService[]
-     * List<SomeService>          = List
-     * List<SomeService>[]        = List[]
-     * Map<Class, SomeService>    = Map
-     * MyListImpl<SomeService>    = MyListImpl
-     * HashMap<Class, SomeService> = HashMap
-     * 
- * - * @param service - * @return - */ - public static Class rawClass(Type service) - { - if (service instanceof Class) - { - return ((Class) service); - } - else if (service instanceof ParameterizedType) - { - Type rawType = ((ParameterizedType) service).getRawType(); - if (rawType instanceof Class) - { - return ((Class) rawType); - } - } - else if (service instanceof WildcardType) - { - Type wildCardType = typeOf((WildcardType) service); - return rawClass(wildCardType); - } - return null; - } - - /** - * Gets a collection with all the classes of the objects from the especified - * collection. - * - * @param instances The objects to obtain it´s classes from. - * @return A Collection object with all the classes of the object´s in the - * collection passed. - */ - public static Collection> toClasses(Collection instances) - { - List> arrList = new ArrayList(); - for (Object instance : instances) - { - arrList.add(instance.getClass()); - } - return arrList; - } - - /** - * Finds te priority value for a class, from it´s @Priority annotation if it - * haveit. - * - * @param cls The class to find it´s priority. - * @return The int value of the priority, by default the priority will be - * Integer.MAX_VALUE if not especified directly in the component. - */ - public static int findPriority(Class cls) - { - Priority a1 = cls.getAnnotation(Priority.class); - int v1 = Integer.MAX_VALUE; - if (a1 != null) - { - v1 = a1.value(); - } - return v1; - } - - /** - * Given a multiple type, (array, collection, or map) this method will - * return the appropied instance for it. - *
-     * SomeService                      = null
-     * SomeService[]                    = SomeService[]
-     * List<SomeService>          = ArrayList
-     * List<SomeService>[]        = List[]
-     * Map<Class, SomeService>    = Map
-     * MyListImpl<SomeService>    = null
-     * HashMap<Class, SomeService> = HashMap
-     * 
- * - * @param service The type of the array, collection or map. - * @param data The data to put on the result listing. - * @return The proper object for the especified type. - */ - public static Object createMultiple(Type service, Object[] data) - { - try - { - if (data != null) - { - if (ClassUtils.isCollection(service)) - { - Class resultClass = rawClass(service); - return ClassUtils.createCollection(resultClass, data); - } - else if (ClassUtils.isMap(service)) - { - Class resultClass = rawClass(service); - return ClassUtils.createCollection(resultClass, data); - } - else if (ClassUtils.isArray(service)) - { - return data; - } - } - } - catch (Exception ex) - { - LOG.log(Level.SEVERE, ex.getMessage(), ex); - } - return null; - } - - /** - * Given a collection type this method will return the appropied instance - * for it. - *
-     * SomeService                      = null
-     * SomeService[]                    = null
-     * List<SomeService>          = ArrayList
-     * LinkedList<SomeService>    = LinkedList
-     * List<SomeService>[]        = null
-     * Map<Class, SomeService>    = null
-     * MyListImpl<SomeService>    = null
-     * HashMap<Class, SomeService> = null
-     * 
- * - * @param collectionCls - * @param data - * @return - * @throws InstantiationException - * @throws IllegalAccessException - */ - public static Collection createCollection(Class collectionCls, Object[] data) throws InstantiationException, IllegalAccessException - { - Collection res = null; - Constructor construct = findConstructor(collectionCls); - if (construct != null && construct.isAccessible()) - { - res = (Collection) collectionCls.newInstance(); - } - else if (collectionCls.isAssignableFrom(ArrayList.class)) - { - res = new ArrayList(data.length); - } - else if (collectionCls.isAssignableFrom(LinkedHashSet.class)) - { - res = new LinkedHashSet(data.length); - } - else if (collectionCls.isAssignableFrom(PriorityBlockingQueue.class)) - { - res = new PriorityBlockingQueue(data.length); - } - if (res != null) - { - res.addAll(Arrays.asList(data)); - } - return res; - } - - /** - * Given a map type this method will return the appropied instance for it. - *
-     * SomeService                      = null
-     * SomeService[]                    = null
-     * List<SomeService>          = null
-     * List<SomeService>[]        = null
-     * Map<Class, SomeService>    = Map
-     * MyListImpl<SomeService>    = null
-     * HashMap<Class, SomeService> = HashMapl
-     * 
- * - * @param mapCls - * @param data - * @return - * @throws InstantiationException - * @throws IllegalAccessException - */ - public static Map createMap(Class mapCls, Object[] data) throws InstantiationException, IllegalAccessException - { - Map map = null; - Constructor construct = findConstructor(mapCls); - if (construct != null && construct.isAccessible()) - { - map = (Map) mapCls.newInstance(); - } - else if (mapCls.isAssignableFrom(LinkedHashMap.class)) - { - map = new LinkedHashMap(data.length); - } - if (map != null) - { - for (Object cmp : data) - { - map.put(cmp.getClass(), cmp); - } - } - return map; - } - - /** - * Finds the default constructor for the especified class. - * - * @param cls The class to find the constructor for. - * @return The default constructor for the class of null if none can be - * found. - */ - private static Constructor findConstructor(Class cls) - { - Constructor[] constructors = cls.getConstructors(); - for (Constructor constructor : constructors) - { - if (constructor.getParameterCount() == 0) - { - return constructor; - } - } - return null; - } - - /** - * Sorts a list of components by priority. - * - * @param value The list of classes to sort. - */ - public static void sort(List> value) - { - Collections.sort(value, (Class c1, Class c2) - -> - { - int v1 = ClassUtils.findPriority(c1); - int v2 = ClassUtils.findPriority(c2); - return v1 - v2; - }); - } - - /** - * Determines whenever the especified type has a wildcard or TypeVariable - * declaration whiting. - *
-     * SomeService<T>      = true
-     * SomeService<?>      = true
-     * SomeService               = false
-     * SomeService<String> = false
-     * 
- * - * @param type The type to inspect. - * @return true the especified type has a generic declaration, false - * otherwise. - */ - public static boolean hasGenericDeclaration(Type type) - { - if (type instanceof ParameterizedType) - { - ParameterizedType pType = (ParameterizedType) type; - Type[] types = pType.getActualTypeArguments(); - for (Type t : types) - { - if (hasGenericDeclaration(t)) - { - return true; - } - } - } - return type instanceof TypeVariable || type instanceof WildcardType; - } - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.ioc.impl; + +import java.lang.reflect.Constructor; +import java.lang.reflect.GenericArrayType; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.lang.reflect.TypeVariable; +import java.lang.reflect.WildcardType; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.PriorityBlockingQueue; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.bridje.ioc.Priority; + +/** + * Utility method for class and type handling. + */ +class ClassUtils +{ + /** + * Logger for this class + */ + private static final Logger LOG = Logger.getLogger(ClassUtils.class.getName()); + + /** + * Gets the upper bounds Type for a WildcarType. + * + *
+     * ? extends SomeService               = SomeService
+     * ? extends SomeService<String> = SomeService<String>
+     * 
+ * + * @param service The wildcardType to inspect. + * @return The upper bounds Type of the WildcardType. + */ + public static Type typeOf(WildcardType service) + { + Type[] upperBounds = ((WildcardType) service).getUpperBounds(); + if (upperBounds.length == 1) + { + return (upperBounds[0]); + } + else if (upperBounds.length == 0) + { + return Object.class; + } + return null; + } + + /** + * Find the Type of an array, map or collection. + * + *
+     * SomeService[]                 = SomeService
+     * List<SomeService>       = SomeService
+     * Map<Class, SomeService> = SomeService
+     * 
+ * + * @param service The inner type of the multiple type passed. + * @return A type representing the inner type for the collection, array or + * map passed. + */ + public static Type multipleType(Type service) + { + if (isArray(service)) + { + return arrayType(service); + } + else if (isCollection(service)) + { + return collectionType(service); + } + else if (isMap(service)) + { + return mapType(service); + } + return null; + } + + /** + * Find the Type of an array. + * + *
+     * SomeService[] = SomeService
+     * 
+ * + * @param service The inner type of the array type passed. + * @return A type representing the inner type for the array type passed. + */ + public static Type arrayType(Type service) + { + if (service instanceof GenericArrayType) + { + Type rawType = ((GenericArrayType) service).getGenericComponentType(); + return rawType; + } + else if (service instanceof Class) + { + return ((Class) service).getComponentType(); + } + return null; + } + + /** + * Find the Type of collection. + * + *
+     * List<SomeService> = SomeService
+     * Set<SomeService>  = SomeService
+     * 
+ * + * @param service The inner type of the array type passed. + * @return A type representing the inner type for the collection type + * passed. + */ + public static Type collectionType(Type service) + { + if (service instanceof ParameterizedType) + { + Type[] args = ((ParameterizedType) service).getActualTypeArguments(); + if (args.length == 1) + { + return args[0]; + } + } + return null; + } + + /** + * Find the Type of a map. + * + *
+     * Map<Class, SomeService>     = SomeService
+     * HashMap<Class, SomeService> = SomeService
+     * 
+ * + * @param service The inner type of the array type passed. + * @return A type representing the inner type for the map type passed. + */ + public static Type mapType(Type service) + { + if (service instanceof ParameterizedType) + { + Type[] args = ((ParameterizedType) service).getActualTypeArguments(); + if (args.length == 2) + { + return args[1]; + } + } + return null; + } + + /** + * Determines whenever the passed type is an array, a java collection like + * List or Set, or a java Map. + *
+     * SomeService                      = false
+     * SomeService[]                    = true
+     * List<SomeService>          = true
+     * Map<Class, SomeService>    = true
+     * MyListImpl<SomeService>    = false
+     * HashMap<Class, SomeService> = true
+     * 
+ * + * @param service The type to inspect. + * @return true if the especified type is an array, a collection or map from + * java languaje. + */ + public static boolean isMultiple(Type service) + { + return isArray(service) || isCollection(service) || isMap(service); + } + + /** + * Determines whenever the passed type is an array. + *
+     * SomeService                      = false
+     * SomeService[]                    = true
+     * List<SomeService>          = false
+     * List<SomeService>[]        = true
+     * Map<Class, SomeService>    = false
+     * MyListImpl<SomeService>    = false
+     * HashMap<Class, SomeService> = false
+     * 
+ * + * @param service The type to inspect. + * @return true if the especified type is an array. + */ + public static boolean isArray(Type service) + { + if (service instanceof Class) + { + return ((Class) service).isArray(); + } + else + { + return service instanceof GenericArrayType; + } + } + + /** + * Determines whenever the passed type is a collection. + *
+     * SomeService                      = false
+     * SomeService[]                    = false
+     * List<SomeService>          = true
+     * List<SomeService>[]        = true
+     * Map<Class, SomeService>    = false
+     * MyListImpl<SomeService>    = false
+     * HashMap<Class, SomeService> = false
+     * 
+ * + * @param service The type to inspect. + * @return true if the especified type is a List Set or other java + * collection except a map. + */ + public static boolean isCollection(Type service) + { + Class cls = rawClass(service); + if (cls == null || cls.isArray() || cls.getPackage() == null) + { + return false; + } + return cls.getPackage().getName().startsWith("java.") + && Collection.class.isAssignableFrom(cls) + && !Map.class.isAssignableFrom(cls); + } + + /** + * Determines whenever the passed type is a map. + *
+     * SomeService                      = false
+     * SomeService[]                    = false
+     * List<SomeService>          = false
+     * List<SomeService>[]        = false
+     * Map<Class, SomeService>    = true
+     * MyListImpl<SomeService>    = false
+     * HashMap<Class, SomeService> = true
+     * 
+ * + * @param service The type to inspect. + * @return true if the especified type is a java Map. + */ + public static boolean isMap(Type service) + { + Class cls = rawClass(service); + if (cls == null || cls.isArray() || cls.getPackage() == null) + { + return false; + } + return cls.getPackage().getName().startsWith("java.") + && Map.class.isAssignableFrom(cls); + } + + /** + * Gets the raw class for the especified Type. + *
+     * SomeService                      = SomeService
+     * SomeService[]                    = SomeService[]
+     * List<SomeService>          = List
+     * List<SomeService>[]        = List[]
+     * Map<Class, SomeService>    = Map
+     * MyListImpl<SomeService>    = MyListImpl
+     * HashMap<Class, SomeService> = HashMap
+     * 
+ * + * @param service + * @return + */ + public static Class rawClass(Type service) + { + if (service instanceof Class) + { + return ((Class) service); + } + else if (service instanceof ParameterizedType) + { + Type rawType = ((ParameterizedType) service).getRawType(); + if (rawType instanceof Class) + { + return ((Class) rawType); + } + } + else if (service instanceof WildcardType) + { + Type wildCardType = typeOf((WildcardType) service); + return rawClass(wildCardType); + } + return null; + } + + /** + * Gets a collection with all the classes of the objects from the especified + * collection. + * + * @param instances The objects to obtain it´s classes from. + * @return A Collection object with all the classes of the object´s in the + * collection passed. + */ + public static Collection> toClasses(Collection instances) + { + List> arrList = new ArrayList(); + for (Object instance : instances) + { + arrList.add(instance.getClass()); + } + return arrList; + } + + /** + * Finds te priority value for a class, from it´s @Priority annotation if it + * haveit. + * + * @param cls The class to find it´s priority. + * @return The int value of the priority, by default the priority will be + * Integer.MAX_VALUE if not especified directly in the component. + */ + public static int findPriority(Class cls) + { + Priority a1 = cls.getAnnotation(Priority.class); + int v1 = Integer.MAX_VALUE; + if (a1 != null) + { + v1 = a1.value(); + } + return v1; + } + + /** + * Given a multiple type, (array, collection, or map) this method will + * return the appropied instance for it. + *
+     * SomeService                      = null
+     * SomeService[]                    = SomeService[]
+     * List<SomeService>          = ArrayList
+     * List<SomeService>[]        = List[]
+     * Map<Class, SomeService>    = Map
+     * MyListImpl<SomeService>    = null
+     * HashMap<Class, SomeService> = HashMap
+     * 
+ * + * @param service The type of the array, collection or map. + * @param data The data to put on the result listing. + * @return The proper object for the especified type. + */ + public static Object createMultiple(Type service, Object[] data) + { + try + { + if (data != null) + { + if (ClassUtils.isCollection(service)) + { + Class resultClass = rawClass(service); + return ClassUtils.createCollection(resultClass, data); + } + else if (ClassUtils.isMap(service)) + { + Class resultClass = rawClass(service); + return ClassUtils.createCollection(resultClass, data); + } + else if (ClassUtils.isArray(service)) + { + return data; + } + } + } + catch (Exception ex) + { + LOG.log(Level.SEVERE, ex.getMessage(), ex); + } + return null; + } + + /** + * Given a collection type this method will return the appropied instance + * for it. + *
+     * SomeService                      = null
+     * SomeService[]                    = null
+     * List<SomeService>          = ArrayList
+     * LinkedList<SomeService>    = LinkedList
+     * List<SomeService>[]        = null
+     * Map<Class, SomeService>    = null
+     * MyListImpl<SomeService>    = null
+     * HashMap<Class, SomeService> = null
+     * 
+ * + * @param collectionCls + * @param data + * @return + * @throws InstantiationException + * @throws IllegalAccessException + */ + public static Collection createCollection(Class collectionCls, Object[] data) throws InstantiationException, IllegalAccessException + { + Collection res = null; + Constructor construct = findConstructor(collectionCls); + if (construct != null && construct.isAccessible()) + { + res = (Collection) collectionCls.newInstance(); + } + else if (collectionCls.isAssignableFrom(ArrayList.class)) + { + res = new ArrayList(data.length); + } + else if (collectionCls.isAssignableFrom(LinkedHashSet.class)) + { + res = new LinkedHashSet(data.length); + } + else if (collectionCls.isAssignableFrom(PriorityBlockingQueue.class)) + { + res = new PriorityBlockingQueue(data.length); + } + if (res != null) + { + res.addAll(Arrays.asList(data)); + } + return res; + } + + /** + * Given a map type this method will return the appropied instance for it. + *
+     * SomeService                      = null
+     * SomeService[]                    = null
+     * List<SomeService>          = null
+     * List<SomeService>[]        = null
+     * Map<Class, SomeService>    = Map
+     * MyListImpl<SomeService>    = null
+     * HashMap<Class, SomeService> = HashMapl
+     * 
+ * + * @param mapCls + * @param data + * @return + * @throws InstantiationException + * @throws IllegalAccessException + */ + public static Map createMap(Class mapCls, Object[] data) throws InstantiationException, IllegalAccessException + { + Map map = null; + Constructor construct = findConstructor(mapCls); + if (construct != null && construct.isAccessible()) + { + map = (Map) mapCls.newInstance(); + } + else if (mapCls.isAssignableFrom(LinkedHashMap.class)) + { + map = new LinkedHashMap(data.length); + } + if (map != null) + { + for (Object cmp : data) + { + map.put(cmp.getClass(), cmp); + } + } + return map; + } + + /** + * Finds the default constructor for the especified class. + * + * @param cls The class to find the constructor for. + * @return The default constructor for the class of null if none can be + * found. + */ + private static Constructor findConstructor(Class cls) + { + Constructor[] constructors = cls.getConstructors(); + for (Constructor constructor : constructors) + { + if (constructor.getParameterCount() == 0) + { + return constructor; + } + } + return null; + } + + /** + * Sorts a list of components by priority. + * + * @param value The list of classes to sort. + */ + public static void sort(List> value) + { + Collections.sort(value, (Class c1, Class c2) + -> + { + int v1 = ClassUtils.findPriority(c1); + int v2 = ClassUtils.findPriority(c2); + return v1 - v2; + }); + } + + /** + * Determines whenever the especified type has a wildcard or TypeVariable + * declaration whiting. + *
+     * SomeService<T>      = true
+     * SomeService<?>      = true
+     * SomeService               = false
+     * SomeService<String> = false
+     * 
+ * + * @param type The type to inspect. + * @return true the especified type has a generic declaration, false + * otherwise. + */ + public static boolean hasGenericDeclaration(Type type) + { + if (type instanceof ParameterizedType) + { + ParameterizedType pType = (ParameterizedType) type; + Type[] types = pType.getActualTypeArguments(); + for (Type t : types) + { + if (hasGenericDeclaration(t)) + { + return true; + } + } + } + return type instanceof TypeVariable || type instanceof WildcardType; + } + +} diff --git a/bridje-ioc/src/main/java/org/bridje/ioc/impl/ComponentProcessor.java b/bridje-ioc/src/main/java/org/bridje/ioc/impl/ComponentProcessor.java index d296b3e7e..86978e2c4 100644 --- a/bridje-ioc/src/main/java/org/bridje/ioc/impl/ComponentProcessor.java +++ b/bridje-ioc/src/main/java/org/bridje/ioc/impl/ComponentProcessor.java @@ -1,123 +1,123 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.ioc.impl; - -import java.io.IOException; -import java.io.Writer; -import java.util.Set; -import java.util.logging.Logger; -import javax.annotation.processing.AbstractProcessor; -import javax.annotation.processing.Filer; -import javax.annotation.processing.Messager; -import javax.annotation.processing.ProcessingEnvironment; -import javax.annotation.processing.RoundEnvironment; -import javax.annotation.processing.SupportedAnnotationTypes; -import javax.annotation.processing.SupportedSourceVersion; -import javax.lang.model.SourceVersion; -import javax.lang.model.element.Element; -import javax.lang.model.element.ElementKind; -import javax.lang.model.element.TypeElement; -import javax.tools.Diagnostic; -import javax.tools.FileObject; -import javax.tools.StandardLocation; -import org.bridje.ioc.Component; - -/** - * Annotations processor for the {@link Component} annotation. - */ -@SupportedAnnotationTypes("org.bridje.ioc.Component") -@SupportedSourceVersion(SourceVersion.RELEASE_8) -public class ComponentProcessor extends AbstractProcessor -{ - private Filer filer; - - private FileObject fobj; - - private Writer writer; - - private static final Logger LOG = Logger.getLogger(ComponentProcessor.class.getName()); - - public static final String COMPONENTS_RESOURCE_FILE = "BRIDJE-INF/ioc/components.properties"; - - @Override - public synchronized void init(ProcessingEnvironment processingEnv) - { - //Creating necesary objects for annotations procesing. - super.init(processingEnv); - Messager messager = processingEnv.getMessager(); - try - { - filer = processingEnv.getFiler(); - //Creating output file - fobj = filer.createResource(StandardLocation.CLASS_OUTPUT, "", COMPONENTS_RESOURCE_FILE); - writer = fobj.openWriter(); - } - catch (IOException e) - { - messager.printMessage(Diagnostic.Kind.ERROR, e.getMessage()); - LOG.severe(e.getMessage()); - } - } - - @Override - public boolean process(Set annotations, RoundEnvironment roundEnv) - { - Messager messager = processingEnv.getMessager(); - try - { - for (TypeElement typeElement : annotations) - { - //Find all @Component marked classes - Set ann = roundEnv.getElementsAnnotatedWith(typeElement); - for (Element element : ann) - { - if (element.getKind() == ElementKind.CLASS) - { - //Get the @Component annotation for the current element. - Component annot = element.getAnnotation(Component.class); - String clsName = element.toString(); - String scope = annot.scope(); - appendClass(clsName, scope); - } - } - } - } - catch (IOException ex) - { - messager.printMessage(Diagnostic.Kind.ERROR, ex.getMessage()); - LOG.severe(ex.getMessage()); - } - return false; - } - - /** - * This method appends class=scope to the output file. - *

- * @param clsName The full class name of the component to append - * @param scope The scope of the component - *

- * @throws IOException If any IO error prevents the writing. - */ - private void appendClass(String clsName, String scope) throws IOException - { - writer.append(clsName); - writer.append("="); - writer.append(scope); - writer.append("\n"); - writer.flush(); - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.ioc.impl; + +import java.io.IOException; +import java.io.Writer; +import java.util.Set; +import java.util.logging.Logger; +import javax.annotation.processing.AbstractProcessor; +import javax.annotation.processing.Filer; +import javax.annotation.processing.Messager; +import javax.annotation.processing.ProcessingEnvironment; +import javax.annotation.processing.RoundEnvironment; +import javax.annotation.processing.SupportedAnnotationTypes; +import javax.annotation.processing.SupportedSourceVersion; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; +import javax.lang.model.element.TypeElement; +import javax.tools.Diagnostic; +import javax.tools.FileObject; +import javax.tools.StandardLocation; +import org.bridje.ioc.Component; + +/** + * Annotations processor for the {@link Component} annotation. + */ +@SupportedAnnotationTypes("org.bridje.ioc.Component") +@SupportedSourceVersion(SourceVersion.RELEASE_8) +public class ComponentProcessor extends AbstractProcessor +{ + private Filer filer; + + private FileObject fobj; + + private Writer writer; + + private static final Logger LOG = Logger.getLogger(ComponentProcessor.class.getName()); + + public static final String COMPONENTS_RESOURCE_FILE = "BRIDJE-INF/ioc/components.properties"; + + @Override + public synchronized void init(ProcessingEnvironment processingEnv) + { + //Creating necesary objects for annotations procesing. + super.init(processingEnv); + Messager messager = processingEnv.getMessager(); + try + { + filer = processingEnv.getFiler(); + //Creating output file + fobj = filer.createResource(StandardLocation.CLASS_OUTPUT, "", COMPONENTS_RESOURCE_FILE); + writer = fobj.openWriter(); + } + catch (IOException e) + { + messager.printMessage(Diagnostic.Kind.ERROR, e.getMessage()); + LOG.severe(e.getMessage()); + } + } + + @Override + public boolean process(Set annotations, RoundEnvironment roundEnv) + { + Messager messager = processingEnv.getMessager(); + try + { + for (TypeElement typeElement : annotations) + { + //Find all @Component marked classes + Set ann = roundEnv.getElementsAnnotatedWith(typeElement); + for (Element element : ann) + { + if (element.getKind() == ElementKind.CLASS) + { + //Get the @Component annotation for the current element. + Component annot = element.getAnnotation(Component.class); + String clsName = element.toString(); + String scope = annot.scope(); + appendClass(clsName, scope); + } + } + } + } + catch (IOException ex) + { + messager.printMessage(Diagnostic.Kind.ERROR, ex.getMessage()); + LOG.severe(ex.getMessage()); + } + return false; + } + + /** + * This method appends class=scope to the output file. + *

+ * @param clsName The full class name of the component to append + * @param scope The scope of the component + *

+ * @throws IOException If any IO error prevents the writing. + */ + private void appendClass(String clsName, String scope) throws IOException + { + writer.append(clsName); + writer.append("="); + writer.append(scope); + writer.append("\n"); + writer.flush(); + } +} diff --git a/bridje-ioc/src/main/java/org/bridje/ioc/impl/Container.java b/bridje-ioc/src/main/java/org/bridje/ioc/impl/Container.java index 527b20bee..a6b578576 100644 --- a/bridje-ioc/src/main/java/org/bridje/ioc/impl/Container.java +++ b/bridje-ioc/src/main/java/org/bridje/ioc/impl/Container.java @@ -1,114 +1,114 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.ioc.impl; - -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -/** - * This class is resposable for holding references to the instanciated - * components in a ioc context. - */ -class Container -{ - /** - * A map containing the class of the component and it´s instance for all - * instantiated components in the context. - */ - private final Map components; - - /** - * The guy responsable for instantiate a component. - */ - private final Instanciator instanciator; - - /** - * The constuctor for this container. - * - * @param creator The instance of the object whos resposability will be to - * create the components. - * @param instances The components that are already instantiated. - */ - public Container(Instanciator creator, List instances) - { - this.components = new ConcurrentHashMap<>(); - this.instanciator = creator; - for (Object instance : instances) - { - components.put(instance.getClass(), instance); - instanciator.injectDependencies(instance.getClass(), instance); - } - } - - /** - * Determines if a omponent is alrready instantiated in this container. - * - * @param cls The class of the component. - * @return true the component is alrready instantiated, false othewise. - */ - public boolean contains(Class cls) - { - return components.containsKey(cls); - } - - /** - * Gets a component´s instance by it´s class. - * - * @param The type of the component. - * @param cls The class of the component. - * @return The component´s instance, or null if it does not exists. - */ - public T get(Class cls) - { - return (T) components.get(cls); - } - - /** - * Creates a component using the internar instanciator, and put it in the - * internal map for future use. - * - * @param The type of the component. - * @param cls The class of the component. - * @return The new create component of null if the component cannot be - * created. - */ - public T create(Class cls) - { - if (components.containsKey(cls)) - { - return (T) components.get(cls); - } - else - { - instanciator.invokePreCreateListener(cls); - T obj = instanciator.instantiate(cls); - if (obj == null) - { - return null; - } - components.put(cls, obj); - - instanciator.invokePreInitListener(cls, obj); - instanciator.injectDependencies(cls, obj); - - instanciator.invokePostInitListener(cls, obj); - instanciator.callPostConstruct(cls, obj); - return obj; - } - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.ioc.impl; + +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * This class is resposable for holding references to the instanciated + * components in a ioc context. + */ +class Container +{ + /** + * A map containing the class of the component and it´s instance for all + * instantiated components in the context. + */ + private final Map components; + + /** + * The guy responsable for instantiate a component. + */ + private final Instanciator instanciator; + + /** + * The constuctor for this container. + * + * @param creator The instance of the object whos resposability will be to + * create the components. + * @param instances The components that are already instantiated. + */ + public Container(Instanciator creator, List instances) + { + this.components = new ConcurrentHashMap<>(); + this.instanciator = creator; + for (Object instance : instances) + { + components.put(instance.getClass(), instance); + instanciator.injectDependencies(instance.getClass(), instance); + } + } + + /** + * Determines if a omponent is alrready instantiated in this container. + * + * @param cls The class of the component. + * @return true the component is alrready instantiated, false othewise. + */ + public boolean contains(Class cls) + { + return components.containsKey(cls); + } + + /** + * Gets a component´s instance by it´s class. + * + * @param The type of the component. + * @param cls The class of the component. + * @return The component´s instance, or null if it does not exists. + */ + public T get(Class cls) + { + return (T) components.get(cls); + } + + /** + * Creates a component using the internar instanciator, and put it in the + * internal map for future use. + * + * @param The type of the component. + * @param cls The class of the component. + * @return The new create component of null if the component cannot be + * created. + */ + public T create(Class cls) + { + if (components.containsKey(cls)) + { + return (T) components.get(cls); + } + else + { + instanciator.invokePreCreateListener(cls); + T obj = instanciator.instantiate(cls); + if (obj == null) + { + return null; + } + components.put(cls, obj); + + instanciator.invokePreInitListener(cls, obj); + instanciator.injectDependencies(cls, obj); + + instanciator.invokePostInitListener(cls, obj); + instanciator.callPostConstruct(cls, obj); + return obj; + } + } +} diff --git a/bridje-ioc/src/main/java/org/bridje/ioc/impl/ContextFactory.java b/bridje-ioc/src/main/java/org/bridje/ioc/impl/ContextFactory.java index 9bca1cb0c..165ee9b62 100644 --- a/bridje-ioc/src/main/java/org/bridje/ioc/impl/ContextFactory.java +++ b/bridje-ioc/src/main/java/org/bridje/ioc/impl/ContextFactory.java @@ -1,67 +1,67 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.ioc.impl; - -import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.bridje.ioc.IocContext; - -public class ContextFactory -{ - private static final Logger LOG = Logger.getLogger(ContextFactory.class.getName()); - - /** - * Internal holder for the single APPLICATION scoped IocContext instance. - */ - private static IocContext context; - - /** - * Private constructor so this object cannot be instantiated. - */ - private ContextFactory() - { - - } - - /** - * This method returns the IocContext for the application scope. - * - * @return An object providing de IocContext for the application scope. - */ - public static IocContext context() - { - if (context == null) - { - context = createApplicationContext(); - } - return context; - } - - private static IocContext createApplicationContext() - { - try - { - return new ContextImpl(); - } - catch (IOException ex) - { - LOG.log(Level.SEVERE, ex.getMessage(), ex); - } - return null; - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.ioc.impl; + +import java.io.IOException; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.bridje.ioc.IocContext; + +public class ContextFactory +{ + private static final Logger LOG = Logger.getLogger(ContextFactory.class.getName()); + + /** + * Internal holder for the single APPLICATION scoped IocContext instance. + */ + private static IocContext context; + + /** + * Private constructor so this object cannot be instantiated. + */ + private ContextFactory() + { + + } + + /** + * This method returns the IocContext for the application scope. + * + * @return An object providing de IocContext for the application scope. + */ + public static IocContext context() + { + if (context == null) + { + context = createApplicationContext(); + } + return context; + } + + private static IocContext createApplicationContext() + { + try + { + return new ContextImpl(); + } + catch (IOException ex) + { + LOG.log(Level.SEVERE, ex.getMessage(), ex); + } + return null; + } +} diff --git a/bridje-ioc/src/main/java/org/bridje/ioc/impl/ContextImpl.java b/bridje-ioc/src/main/java/org/bridje/ioc/impl/ContextImpl.java index bacaac0f1..3b420ee25 100644 --- a/bridje-ioc/src/main/java/org/bridje/ioc/impl/ContextImpl.java +++ b/bridje-ioc/src/main/java/org/bridje/ioc/impl/ContextImpl.java @@ -1,336 +1,336 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.ioc.impl; - -import java.io.IOException; -import java.lang.reflect.Array; -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.bridje.ioc.ClassRepository; -import org.bridje.ioc.IocContext; -import static org.bridje.ioc.impl.ClassUtils.*; - -class ContextImpl implements IocContext -{ - private static final Logger LOG = Logger.getLogger(ContextImpl.class.getName()); - - private final String scope; - - private final ClassSet classSet; - - private final Instanciator creator; - - private final ServiceMap serviceMap; - - private final Container container; - - private final IocContext parent; - - public ContextImpl() throws IOException - { - this("APPLICATION"); - } - - private ContextImpl(String scope) throws IOException - { - this(scope, null, null); - } - - private ContextImpl(String scope, Collection instances) throws IOException - { - this(scope, instances, null); - } - - @SuppressWarnings("LeakingThisInConstructor") - private ContextImpl(String scope, Collection instances, IocContext parent) throws IOException - { - this.scope = scope; - this.parent = parent; - if(instances != null && !instances.isEmpty()) - { - ClassSet cs = new ClassSet(toClasses(instances)); - classSet = new ClassSet(ClassSet.findByScope(scope), cs); - serviceMap = new ServiceMap(ServiceMap.findByScope(scope), cs); - } - else - { - classSet = ClassSet.findByScope(scope); - serviceMap = ServiceMap.findByScope(scope); - } - creator = new Instanciator(this, serviceMap); - List allInstances = new ArrayList(instances != null ? instances.size() + 1 : 1); - allInstances.add(this); - if(instances != null) - { - allInstances.addAll(instances); - } - container = new Container(creator, allInstances); - } - - @Override - public T find(Class service) - { - T result = findInternal(service); - if(result != null) - { - return result; - } - if(parent != null) - { - return parent.find(service); - } - return null; - } - - @Override - public T findNext(Class service, int priority) - { - return (T)findNextGeneric(service, priority); - } - - @Override - public Object findGeneric(Type service) - { - Object result = findGenericInternal(service); - if(result != null) - { - return result; - } - if(parent != null) - { - return parent.findGeneric(service); - } - return null; - } - - @Override - public Object findNextGeneric(Type service, int priority) - { - Object result = findGenericInternal(service, priority); - if(result != null) - { - return result; - } - if(parent != null) - { - return parent.findNextGeneric(service, priority); - } - return null; - } - - @Override - public T[] findAll(Class service) - { - T[] result = findAllInternal(service); - if(result != null && result.length > 0) - { - return result; - } - if(parent != null) - { - return parent.findAll(service); - } - return result; - } - - @Override - public boolean existsComponent(Class cls) - { - if(classSet.contains(cls)) - { - return true; - } - if(parent != null) - { - return parent.existsComponent(cls); - } - return false; - } - - @Override - public boolean exists(Type service) - { - if(isMultiple(service)) - { - Type type = multipleType(service); - if(serviceMap.exists(type)) - { - return true; - } - } - else - { - if(serviceMap.exists(service)) - { - return true; - } - } - if(parent != null) - { - return parent.exists(service); - } - return false; - } - - @Override - public IocContext getParent() - { - return parent; - } - - @Override - public IocContext createChild(String scope) - { - return createChild(scope, null); - } - - @Override - public IocContext createChild(String scope, Collection instances) - { - try - { - return new ContextImpl(scope, instances, this); - } - catch(Exception ex) - { - LOG.log(Level.SEVERE, ex.getMessage(), ex); - } - return null; - } - - private T findInternal(Class service) - { - if(service.isArray()) - { - return (T)findGenericInternal(service); - } - else - { - Class component = serviceMap.findOne(service); - if(component != null) - { - return (T)container.create(component); - } - } - return null; - } - - private T[] findAllInternal(Class service) - { - List> components = serviceMap.findAll(service); - if(components != null) - { - ArrayList resultList = new ArrayList(components.size()); - for (Class component : components) - { - Object compInstance = container.create(component); - if(compInstance != null) - { - resultList.add(compInstance); - } - } - T[] result = (T[])Array.newInstance(service, components.size()); - return (T[])resultList.toArray(result); - } - return (T[])Array.newInstance(service, 0); - } - - private Object findGenericInternal(Type service) - { - return findGenericInternal(service, null); - } - - private Object findGenericInternal(Type service, Integer priority) - { - if(isMultiple(service)) - { - Type type = multipleType(service); - Object[] data = findAllGenericInternal(type); - return createMultiple(service, data); - } - else - { - return findOneGenericInternal(service, priority); - } - } - - private Object findOneGenericInternal(Type service, Integer priority) - { - Class component = serviceMap.findOne(service, priority); - if(component != null) - { - return container.create(component); - } - return null; - } - - private Object[] findAllGenericInternal(Type service) - { - if(isMultiple(service)) - { - return null; - } - Class resultClass = rawClass(service); - if(resultClass == null) - { - return null; - } - Object[] result = null; - List> components = serviceMap.findAll(service); - if(components != null) - { - List resultList = new ArrayList(components.size()); - for (Class component : components) - { - Object compInstance = container.create(component); - if(compInstance != null) - { - resultList.add(compInstance); - } - } - result = (Object[])Array.newInstance(resultClass, components.size()); - result = resultList.toArray(result); - } - else - { - result = (Object[])Array.newInstance(resultClass, 0); - } - return result; - } - - @Override - public ClassRepository getClassRepository() - { - return classSet; - } - - @Override - public String getScope() - { - return scope; - } - - @Override - public String toString() - { - return "IocContext: " + scope; - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.ioc.impl; + +import java.io.IOException; +import java.lang.reflect.Array; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.bridje.ioc.ClassRepository; +import org.bridje.ioc.IocContext; +import static org.bridje.ioc.impl.ClassUtils.*; + +class ContextImpl implements IocContext +{ + private static final Logger LOG = Logger.getLogger(ContextImpl.class.getName()); + + private final String scope; + + private final ClassSet classSet; + + private final Instanciator creator; + + private final ServiceMap serviceMap; + + private final Container container; + + private final IocContext parent; + + public ContextImpl() throws IOException + { + this("APPLICATION"); + } + + private ContextImpl(String scope) throws IOException + { + this(scope, null, null); + } + + private ContextImpl(String scope, Collection instances) throws IOException + { + this(scope, instances, null); + } + + @SuppressWarnings("LeakingThisInConstructor") + private ContextImpl(String scope, Collection instances, IocContext parent) throws IOException + { + this.scope = scope; + this.parent = parent; + if(instances != null && !instances.isEmpty()) + { + ClassSet cs = new ClassSet(toClasses(instances)); + classSet = new ClassSet(ClassSet.findByScope(scope), cs); + serviceMap = new ServiceMap(ServiceMap.findByScope(scope), cs); + } + else + { + classSet = ClassSet.findByScope(scope); + serviceMap = ServiceMap.findByScope(scope); + } + creator = new Instanciator(this, serviceMap); + List allInstances = new ArrayList(instances != null ? instances.size() + 1 : 1); + allInstances.add(this); + if(instances != null) + { + allInstances.addAll(instances); + } + container = new Container(creator, allInstances); + } + + @Override + public T find(Class service) + { + T result = findInternal(service); + if(result != null) + { + return result; + } + if(parent != null) + { + return parent.find(service); + } + return null; + } + + @Override + public T findNext(Class service, int priority) + { + return (T)findNextGeneric(service, priority); + } + + @Override + public Object findGeneric(Type service) + { + Object result = findGenericInternal(service); + if(result != null) + { + return result; + } + if(parent != null) + { + return parent.findGeneric(service); + } + return null; + } + + @Override + public Object findNextGeneric(Type service, int priority) + { + Object result = findGenericInternal(service, priority); + if(result != null) + { + return result; + } + if(parent != null) + { + return parent.findNextGeneric(service, priority); + } + return null; + } + + @Override + public T[] findAll(Class service) + { + T[] result = findAllInternal(service); + if(result != null && result.length > 0) + { + return result; + } + if(parent != null) + { + return parent.findAll(service); + } + return result; + } + + @Override + public boolean existsComponent(Class cls) + { + if(classSet.contains(cls)) + { + return true; + } + if(parent != null) + { + return parent.existsComponent(cls); + } + return false; + } + + @Override + public boolean exists(Type service) + { + if(isMultiple(service)) + { + Type type = multipleType(service); + if(serviceMap.exists(type)) + { + return true; + } + } + else + { + if(serviceMap.exists(service)) + { + return true; + } + } + if(parent != null) + { + return parent.exists(service); + } + return false; + } + + @Override + public IocContext getParent() + { + return parent; + } + + @Override + public IocContext createChild(String scope) + { + return createChild(scope, null); + } + + @Override + public IocContext createChild(String scope, Collection instances) + { + try + { + return new ContextImpl(scope, instances, this); + } + catch(Exception ex) + { + LOG.log(Level.SEVERE, ex.getMessage(), ex); + } + return null; + } + + private T findInternal(Class service) + { + if(service.isArray()) + { + return (T)findGenericInternal(service); + } + else + { + Class component = serviceMap.findOne(service); + if(component != null) + { + return (T)container.create(component); + } + } + return null; + } + + private T[] findAllInternal(Class service) + { + List> components = serviceMap.findAll(service); + if(components != null) + { + ArrayList resultList = new ArrayList(components.size()); + for (Class component : components) + { + Object compInstance = container.create(component); + if(compInstance != null) + { + resultList.add(compInstance); + } + } + T[] result = (T[])Array.newInstance(service, components.size()); + return (T[])resultList.toArray(result); + } + return (T[])Array.newInstance(service, 0); + } + + private Object findGenericInternal(Type service) + { + return findGenericInternal(service, null); + } + + private Object findGenericInternal(Type service, Integer priority) + { + if(isMultiple(service)) + { + Type type = multipleType(service); + Object[] data = findAllGenericInternal(type); + return createMultiple(service, data); + } + else + { + return findOneGenericInternal(service, priority); + } + } + + private Object findOneGenericInternal(Type service, Integer priority) + { + Class component = serviceMap.findOne(service, priority); + if(component != null) + { + return container.create(component); + } + return null; + } + + private Object[] findAllGenericInternal(Type service) + { + if(isMultiple(service)) + { + return null; + } + Class resultClass = rawClass(service); + if(resultClass == null) + { + return null; + } + Object[] result = null; + List> components = serviceMap.findAll(service); + if(components != null) + { + List resultList = new ArrayList(components.size()); + for (Class component : components) + { + Object compInstance = container.create(component); + if(compInstance != null) + { + resultList.add(compInstance); + } + } + result = (Object[])Array.newInstance(resultClass, components.size()); + result = resultList.toArray(result); + } + else + { + result = (Object[])Array.newInstance(resultClass, 0); + } + return result; + } + + @Override + public ClassRepository getClassRepository() + { + return classSet; + } + + @Override + public String getScope() + { + return scope; + } + + @Override + public String toString() + { + return "IocContext: " + scope; + } +} diff --git a/bridje-ioc/src/main/java/org/bridje/ioc/impl/Instanciator.java b/bridje-ioc/src/main/java/org/bridje/ioc/impl/Instanciator.java index 99ae7fff1..16f4be233 100644 --- a/bridje-ioc/src/main/java/org/bridje/ioc/impl/Instanciator.java +++ b/bridje-ioc/src/main/java/org/bridje/ioc/impl/Instanciator.java @@ -1,280 +1,280 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.ioc.impl; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.annotation.PostConstruct; -import org.bridje.ioc.ContextListener; -import org.bridje.ioc.Inject; -import org.bridje.ioc.IocContext; -import org.bridje.ioc.InjectNext; - -class Instanciator -{ - private static final Logger LOG = Logger.getLogger(Instanciator.class.getName()); - - private final IocContext context; - - private final ServiceMap serviceMap; - - private ContextListener[] contextListeners; - - public Instanciator(IocContext context, ServiceMap serviceMap) - { - this.context = context; - this.serviceMap = serviceMap; - } - - @SuppressWarnings("UseSpecificCatch") - public T instantiate(Class cls) - { - try - { - Constructor constructor = findDefaultConstructor(cls); - if(constructor == null) - { - return null; - } - constructor.setAccessible(true); - return (T)constructor.newInstance(); - } - catch (InstantiationException | IllegalArgumentException | InvocationTargetException | IllegalAccessException ex) - { - LOG.warning(ex.getMessage()); - } - return null; - } - - public void callPostConstruct(Class cls, Object obj) - { - Method[] declaredMethods = cls.getDeclaredMethods(); - for (Method declaredMethod : declaredMethods) - { - PostConstruct annotation = declaredMethod.getAnnotation(PostConstruct.class); - if(annotation != null) - { - try - { - declaredMethod.setAccessible(true); - declaredMethod.invoke(obj); - } - catch(SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) - { - LOG.log(Level.SEVERE, ex.getMessage(), ex); - } - } - } - } - - public void injectDependencies(Class cls, Object obj) - { - Field[] declaredFields = cls.getDeclaredFields(); - for (Field declaredField : declaredFields) - { - Inject annotation = declaredField.getAnnotation(Inject.class); - if(annotation != null) - { - injectDependency(cls, obj, declaredField, null); - } - InjectNext annotationNext = declaredField.getAnnotation(InjectNext.class); - if(annotationNext != null) - { - injectDependency(cls, obj, declaredField, ClassUtils.findPriority(cls)); - } - } - - Class supClass = cls.getSuperclass(); - if(supClass != null && supClass != Object.class) - { - injectDependencies(supClass, obj); - } - } - - public void injectDependency(Class cls, Object obj, Field field, Integer priority) - { - try - { - Type service = field.getGenericType(); - Object componentObj; - if(priority == null) - { - componentObj = context.findGeneric(service); - } - else - { - componentObj = context.findNextGeneric(service, priority); - } - - field.setAccessible(true); - field.set(obj, componentObj); - } - catch(IllegalArgumentException | IllegalAccessException ex) - { - LOG.log(Level.SEVERE, ex.getMessage(), ex); - } - } - - private Constructor findDefaultConstructor(Class cls) - { - for (Constructor constructor : cls.getDeclaredConstructors()) - { - if (constructor.getParameterTypes().length == 0) - { - return constructor; - } - } - return null; - } - - private void initContextListeners() - { - if(null == contextListeners) - { - contextListeners = context.findAll(ContextListener.class); - } - } - - protected void invokePreCreateListener(Class cls) - { - if(ContextListener.class.isAssignableFrom(cls)) - { - return; - } - - initContextListeners(); - if(null != contextListeners) - { - for (ContextListener contextListener : contextListeners) - { - //find the generic parameter type of ContextListener, - //example ContexListener -> type = java.lang.Integer - Type type = findGenericType(contextListener.getClass()); - if(type.equals(Object.class)) - { - contextListener.preCreateComponent(cls); - } - else - { - List services = serviceMap.getServices(cls); - if(services != null) - { - for (Type service : services) - { - if(type.equals(service)) - { - contextListener.preCreateComponent(cls); - break; - } - } - } - } - } - } - } - - public void invokePreInitListener(Class cls, Object instance) - { - if(ContextListener.class.isAssignableFrom(cls)) - { - return; - } - - initContextListeners(); - if(null != contextListeners) - { - for (ContextListener contextListener : contextListeners) - { - //find the generic parameter type of ContextListener, - //example ContexListener -> type = java.lang.Integer - Type type = findGenericType(contextListener.getClass()); - if(type.equals(Object.class)) - { - contextListener.preInitComponent(cls, instance); - } - else - { - List services = serviceMap.getServices(cls); - if(services != null) - { - for (Type service : services) - { - if(type.equals(service)) - { - contextListener.preInitComponent(cls, instance); - break; - } - } - } - } - } - } - } - - public void invokePostInitListener(Class cls, Object instance) - { - if(ContextListener.class.isAssignableFrom(cls)) - { - return; - } - - initContextListeners(); - if(null != contextListeners) - { - for (ContextListener contextListener : contextListeners) - { - //find the generic parameter type of ContextListener, - //example ContexListener -> type = java.lang.Integer - Type type = findGenericType(contextListener.getClass()); - if(type.equals(Object.class)) - { - contextListener.postInitComponent(cls, instance); - } - else - { - List services = serviceMap.getServices(cls); - if(services != null) - { - for (Type service : services) - { - if(type.equals(service)) - { - contextListener.postInitComponent(cls, instance); - break; - } - } - } - } - } - } - } - - private Type findGenericType(Class clazz) - { - Type type = (((ParameterizedType)(clazz - .getGenericInterfaces())[0]) - .getActualTypeArguments())[0]; - return type; - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.ioc.impl; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.annotation.PostConstruct; +import org.bridje.ioc.ContextListener; +import org.bridje.ioc.Inject; +import org.bridje.ioc.IocContext; +import org.bridje.ioc.InjectNext; + +class Instanciator +{ + private static final Logger LOG = Logger.getLogger(Instanciator.class.getName()); + + private final IocContext context; + + private final ServiceMap serviceMap; + + private ContextListener[] contextListeners; + + public Instanciator(IocContext context, ServiceMap serviceMap) + { + this.context = context; + this.serviceMap = serviceMap; + } + + @SuppressWarnings("UseSpecificCatch") + public T instantiate(Class cls) + { + try + { + Constructor constructor = findDefaultConstructor(cls); + if(constructor == null) + { + return null; + } + constructor.setAccessible(true); + return (T)constructor.newInstance(); + } + catch (InstantiationException | IllegalArgumentException | InvocationTargetException | IllegalAccessException ex) + { + LOG.warning(ex.getMessage()); + } + return null; + } + + public void callPostConstruct(Class cls, Object obj) + { + Method[] declaredMethods = cls.getDeclaredMethods(); + for (Method declaredMethod : declaredMethods) + { + PostConstruct annotation = declaredMethod.getAnnotation(PostConstruct.class); + if(annotation != null) + { + try + { + declaredMethod.setAccessible(true); + declaredMethod.invoke(obj); + } + catch(SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) + { + LOG.log(Level.SEVERE, ex.getMessage(), ex); + } + } + } + } + + public void injectDependencies(Class cls, Object obj) + { + Field[] declaredFields = cls.getDeclaredFields(); + for (Field declaredField : declaredFields) + { + Inject annotation = declaredField.getAnnotation(Inject.class); + if(annotation != null) + { + injectDependency(cls, obj, declaredField, null); + } + InjectNext annotationNext = declaredField.getAnnotation(InjectNext.class); + if(annotationNext != null) + { + injectDependency(cls, obj, declaredField, ClassUtils.findPriority(cls)); + } + } + + Class supClass = cls.getSuperclass(); + if(supClass != null && supClass != Object.class) + { + injectDependencies(supClass, obj); + } + } + + public void injectDependency(Class cls, Object obj, Field field, Integer priority) + { + try + { + Type service = field.getGenericType(); + Object componentObj; + if(priority == null) + { + componentObj = context.findGeneric(service); + } + else + { + componentObj = context.findNextGeneric(service, priority); + } + + field.setAccessible(true); + field.set(obj, componentObj); + } + catch(IllegalArgumentException | IllegalAccessException ex) + { + LOG.log(Level.SEVERE, ex.getMessage(), ex); + } + } + + private Constructor findDefaultConstructor(Class cls) + { + for (Constructor constructor : cls.getDeclaredConstructors()) + { + if (constructor.getParameterTypes().length == 0) + { + return constructor; + } + } + return null; + } + + private void initContextListeners() + { + if(null == contextListeners) + { + contextListeners = context.findAll(ContextListener.class); + } + } + + protected void invokePreCreateListener(Class cls) + { + if(ContextListener.class.isAssignableFrom(cls)) + { + return; + } + + initContextListeners(); + if(null != contextListeners) + { + for (ContextListener contextListener : contextListeners) + { + //find the generic parameter type of ContextListener, + //example ContexListener -> type = java.lang.Integer + Type type = findGenericType(contextListener.getClass()); + if(type.equals(Object.class)) + { + contextListener.preCreateComponent(cls); + } + else + { + List services = serviceMap.getServices(cls); + if(services != null) + { + for (Type service : services) + { + if(type.equals(service)) + { + contextListener.preCreateComponent(cls); + break; + } + } + } + } + } + } + } + + public void invokePreInitListener(Class cls, Object instance) + { + if(ContextListener.class.isAssignableFrom(cls)) + { + return; + } + + initContextListeners(); + if(null != contextListeners) + { + for (ContextListener contextListener : contextListeners) + { + //find the generic parameter type of ContextListener, + //example ContexListener -> type = java.lang.Integer + Type type = findGenericType(contextListener.getClass()); + if(type.equals(Object.class)) + { + contextListener.preInitComponent(cls, instance); + } + else + { + List services = serviceMap.getServices(cls); + if(services != null) + { + for (Type service : services) + { + if(type.equals(service)) + { + contextListener.preInitComponent(cls, instance); + break; + } + } + } + } + } + } + } + + public void invokePostInitListener(Class cls, Object instance) + { + if(ContextListener.class.isAssignableFrom(cls)) + { + return; + } + + initContextListeners(); + if(null != contextListeners) + { + for (ContextListener contextListener : contextListeners) + { + //find the generic parameter type of ContextListener, + //example ContexListener -> type = java.lang.Integer + Type type = findGenericType(contextListener.getClass()); + if(type.equals(Object.class)) + { + contextListener.postInitComponent(cls, instance); + } + else + { + List services = serviceMap.getServices(cls); + if(services != null) + { + for (Type service : services) + { + if(type.equals(service)) + { + contextListener.postInitComponent(cls, instance); + break; + } + } + } + } + } + } + } + + private Type findGenericType(Class clazz) + { + Type type = (((ParameterizedType)(clazz + .getGenericInterfaces())[0]) + .getActualTypeArguments())[0]; + return type; + } +} diff --git a/bridje-ioc/src/main/java/org/bridje/ioc/impl/ServiceMap.java b/bridje-ioc/src/main/java/org/bridje/ioc/impl/ServiceMap.java index 552b1ba15..439d9bd9b 100644 --- a/bridje-ioc/src/main/java/org/bridje/ioc/impl/ServiceMap.java +++ b/bridje-ioc/src/main/java/org/bridje/ioc/impl/ServiceMap.java @@ -1,293 +1,293 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.ioc.impl; - -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; -import java.lang.reflect.TypeVariable; -import java.lang.reflect.WildcardType; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -/** - * An object to keep track of the services of the components. - */ -class ServiceMap -{ - /** - * A cache for the ServiceMap of all scopes. - */ - private static Map serviceMapCache; - - /** - * The service map, who links a services to a list of components. - */ - private final Map>> map; - - /** - * A map who links the components to a list of all it´s services. - */ - private final Map, List> compMap; - - /** - * Constructor for this class. - * - * @param baseMap A service map to base this service map from. - * @param list The components to create this services map for. - */ - public ServiceMap(ServiceMap baseMap, ClassSet list) - { - map = new HashMap<>(); - compMap = new HashMap<>(); - if (baseMap != null) - { - map.putAll(baseMap.map); - compMap.putAll(baseMap.compMap); - } - if (list != null) - { - for (Class component : list) - { - List services = findServices(component); - compMap.put(component, services); - for (Type service : services) - { - addComponentToService(service, component); - } - } - } - for (List> value : map.values()) - { - ClassUtils.sort(value); - } - } - - /** - * Finds the first component class by the given service type. - * - * @param service The type of the service. - * @return The component class or null if none can be found. - */ - public Class findOne(Type service) - { - return findOne(service, null); - } - - /** - * Finds the first component class by the given service type. - * - * @param service The type of the service. - * @param priority The priority - * @return The component class or null if none can be found. - */ - public Class findOne(Type service, Integer priority) - { - List> lst = map.get(service); - if (lst == null || lst.isEmpty()) - { - return null; - } - if (priority == null) - { - return (Class) lst.get(0); - } - else - { - for (Class cls : lst) - { - int v1 = ClassUtils.findPriority(cls); - if (v1 > priority || v1 == Integer.MAX_VALUE) - { - return (Class) cls; - } - } - } - return null; - } - - /** - * Determines whenever a service is provided by a least one component. - * - * @param service The serivce to look for. - * @return true at least one component provides the given service. - */ - public boolean exists(Type service) - { - return map.containsKey(service); - } - - /** - * Finds all components classes by the given service type. - * - * @param service The service to lookup - * @return The list of components that provides the given service if any. - */ - public List> findAll(Type service) - { - if (service instanceof WildcardType) - { - service = ClassUtils.typeOf((WildcardType) service); - } - if (service != null) - { - List> result = map.get(service); - if (result == null) - { - return null; - } - return Collections.unmodifiableList(result); - } - return Collections.EMPTY_LIST; - } - - /** - * Gets the service map by the given scope. - * - * @param scope The scope to look for. - * @return A service map with all the service in the given scope or null if - * the given scope has no components. - */ - public static ServiceMap findByScope(String scope) - { - if (serviceMapCache == null) - { - serviceMapCache = new ConcurrentHashMap<>(); - } - if (!serviceMapCache.containsKey(scope)) - { - ClassSet classSet = ClassSet.findByScope(scope); - if (classSet != null) - { - ServiceMap result = new ServiceMap(null, classSet); - serviceMapCache.put(scope, result); - return result; - } - return null; - } - return serviceMapCache.get(scope); - } - - /** - * Gets all the services provided by a component. - * - * @param component The component to look for. - * @return The list of service the especified component provides. - */ - public List getServices(Class component) - { - return compMap.get(component); - } - - /** - * Creates a list of all services the especified component provides. - * - * @param component The component to search. - * @return The list of all services the especified component provides. - */ - private static List findServices(Class component) - { - List result = new ArrayList<>(); - result.add(Object.class); - result.add(component); - fillServicesSuperClasses(component, result); - fillServicesIntefaces(component, result); - return result; - } - - /** - * Fills all the services provided by all supper classes of the component. - * - * @param component The component to look for it´s services for. - * @param servicesList The list to put all finded services. - */ - private static void fillServicesSuperClasses(Class component, List servicesList) - { - Type supClass = component.getGenericSuperclass(); - while (supClass != null && supClass != Object.class) - { - if (!ClassUtils.hasGenericDeclaration(supClass)) - { - if (!servicesList.contains(supClass)) - { - servicesList.add(supClass); - } - } - Class cls = ClassUtils.rawClass(supClass); - servicesList.add(cls); - if (cls != null) - { - supClass = cls.getGenericSuperclass(); - } - else - { - supClass = null; - } - } - } - - /** - * Fills all the services provided by all supper interfaces of the - * component. - * - * @param component The component to look for it´s services for. - * @param servicesList The list to put all finded services. - */ - private static void fillServicesIntefaces(Class cls, List servicesList) - { - Type[] interfaces = cls.getGenericInterfaces(); - for (Type ifc : interfaces) - { - if (!ClassUtils.hasGenericDeclaration(ifc)) - { - if (!servicesList.contains(ifc)) - { - servicesList.add(ifc); - } - } - Class icfCls = ClassUtils.rawClass(ifc); - servicesList.add(icfCls); - if (icfCls != null) - { - fillServicesIntefaces(icfCls, servicesList); - } - } - } - - /** - * Adds a component to a list of components that provides the given service. - * - * @param service The service provided - * @param component The component who provides the given services. - */ - private void addComponentToService(Type service, Class component) - { - List> components = map.get(service); - if (components == null) - { - components = new ArrayList<>(); - map.put(service, components); - } - if (!components.contains(component)) - { - components.add(component); - } - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.ioc.impl; + +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.lang.reflect.TypeVariable; +import java.lang.reflect.WildcardType; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * An object to keep track of the services of the components. + */ +class ServiceMap +{ + /** + * A cache for the ServiceMap of all scopes. + */ + private static Map serviceMapCache; + + /** + * The service map, who links a services to a list of components. + */ + private final Map>> map; + + /** + * A map who links the components to a list of all it´s services. + */ + private final Map, List> compMap; + + /** + * Constructor for this class. + * + * @param baseMap A service map to base this service map from. + * @param list The components to create this services map for. + */ + public ServiceMap(ServiceMap baseMap, ClassSet list) + { + map = new HashMap<>(); + compMap = new HashMap<>(); + if (baseMap != null) + { + map.putAll(baseMap.map); + compMap.putAll(baseMap.compMap); + } + if (list != null) + { + for (Class component : list) + { + List services = findServices(component); + compMap.put(component, services); + for (Type service : services) + { + addComponentToService(service, component); + } + } + } + for (List> value : map.values()) + { + ClassUtils.sort(value); + } + } + + /** + * Finds the first component class by the given service type. + * + * @param service The type of the service. + * @return The component class or null if none can be found. + */ + public Class findOne(Type service) + { + return findOne(service, null); + } + + /** + * Finds the first component class by the given service type. + * + * @param service The type of the service. + * @param priority The priority + * @return The component class or null if none can be found. + */ + public Class findOne(Type service, Integer priority) + { + List> lst = map.get(service); + if (lst == null || lst.isEmpty()) + { + return null; + } + if (priority == null) + { + return (Class) lst.get(0); + } + else + { + for (Class cls : lst) + { + int v1 = ClassUtils.findPriority(cls); + if (v1 > priority || v1 == Integer.MAX_VALUE) + { + return (Class) cls; + } + } + } + return null; + } + + /** + * Determines whenever a service is provided by a least one component. + * + * @param service The serivce to look for. + * @return true at least one component provides the given service. + */ + public boolean exists(Type service) + { + return map.containsKey(service); + } + + /** + * Finds all components classes by the given service type. + * + * @param service The service to lookup + * @return The list of components that provides the given service if any. + */ + public List> findAll(Type service) + { + if (service instanceof WildcardType) + { + service = ClassUtils.typeOf((WildcardType) service); + } + if (service != null) + { + List> result = map.get(service); + if (result == null) + { + return null; + } + return Collections.unmodifiableList(result); + } + return Collections.EMPTY_LIST; + } + + /** + * Gets the service map by the given scope. + * + * @param scope The scope to look for. + * @return A service map with all the service in the given scope or null if + * the given scope has no components. + */ + public static ServiceMap findByScope(String scope) + { + if (serviceMapCache == null) + { + serviceMapCache = new ConcurrentHashMap<>(); + } + if (!serviceMapCache.containsKey(scope)) + { + ClassSet classSet = ClassSet.findByScope(scope); + if (classSet != null) + { + ServiceMap result = new ServiceMap(null, classSet); + serviceMapCache.put(scope, result); + return result; + } + return null; + } + return serviceMapCache.get(scope); + } + + /** + * Gets all the services provided by a component. + * + * @param component The component to look for. + * @return The list of service the especified component provides. + */ + public List getServices(Class component) + { + return compMap.get(component); + } + + /** + * Creates a list of all services the especified component provides. + * + * @param component The component to search. + * @return The list of all services the especified component provides. + */ + private static List findServices(Class component) + { + List result = new ArrayList<>(); + result.add(Object.class); + result.add(component); + fillServicesSuperClasses(component, result); + fillServicesIntefaces(component, result); + return result; + } + + /** + * Fills all the services provided by all supper classes of the component. + * + * @param component The component to look for it´s services for. + * @param servicesList The list to put all finded services. + */ + private static void fillServicesSuperClasses(Class component, List servicesList) + { + Type supClass = component.getGenericSuperclass(); + while (supClass != null && supClass != Object.class) + { + if (!ClassUtils.hasGenericDeclaration(supClass)) + { + if (!servicesList.contains(supClass)) + { + servicesList.add(supClass); + } + } + Class cls = ClassUtils.rawClass(supClass); + servicesList.add(cls); + if (cls != null) + { + supClass = cls.getGenericSuperclass(); + } + else + { + supClass = null; + } + } + } + + /** + * Fills all the services provided by all supper interfaces of the + * component. + * + * @param component The component to look for it´s services for. + * @param servicesList The list to put all finded services. + */ + private static void fillServicesIntefaces(Class cls, List servicesList) + { + Type[] interfaces = cls.getGenericInterfaces(); + for (Type ifc : interfaces) + { + if (!ClassUtils.hasGenericDeclaration(ifc)) + { + if (!servicesList.contains(ifc)) + { + servicesList.add(ifc); + } + } + Class icfCls = ClassUtils.rawClass(ifc); + servicesList.add(icfCls); + if (icfCls != null) + { + fillServicesIntefaces(icfCls, servicesList); + } + } + } + + /** + * Adds a component to a list of components that provides the given service. + * + * @param service The service provided + * @param component The component who provides the given services. + */ + private void addComponentToService(Type service, Class component) + { + List> components = map.get(service); + if (components == null) + { + components = new ArrayList<>(); + map.put(service, components); + } + if (!components.contains(component)) + { + components.add(component); + } + } +} diff --git a/bridje-ioc/src/test/java/org/bridje/ioc/IocContextImplTest.java b/bridje-ioc/src/test/java/org/bridje/ioc/IocContextImplTest.java index 298d0539e..eb9c8a1a6 100644 --- a/bridje-ioc/src/test/java/org/bridje/ioc/IocContextImplTest.java +++ b/bridje-ioc/src/test/java/org/bridje/ioc/IocContextImplTest.java @@ -1,149 +1,149 @@ - -package org.bridje.ioc; - -import java.io.IOException; -import org.bridje.ioc.test.ComplexInjectComponent; -import org.bridje.ioc.test.ConcreteComponent; -import org.bridje.ioc.test.DummyComponent; -import org.bridje.ioc.test.DummyServiceProvider; -import org.bridje.ioc.test.DummyServiceProvider2; -import org.bridje.ioc.test.GenericComponent; -import org.bridje.ioc.test.GenericInjectComponent; -import org.bridje.ioc.test.SomeService; -import org.bridje.ioc.test.chain.ChainTest; -import org.bridje.ioc.test.priority.PriorityComp1; -import org.bridje.ioc.test.priority.PriorityComp2; -import org.bridje.ioc.test.priority.PriorityComp3; -import org.bridje.ioc.test.priority.PriorityComp4; -import org.bridje.ioc.test.priority.PriorityService; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import static org.junit.Assert.*; - -public class IocContextImplTest -{ - - public IocContextImplTest() - { - } - - @BeforeClass - public static void setUpClass() - { - /* - TODO: This initialization causes - java.lang.IllegalStateException: The APPLICATION Context is already created. - becouse the test order is not defined, a work arround is needed. - */ - /* - Ioc.init(Service. - forThis(DefaultService.class). - implementBy(DefaultComponent2.class)); - */ - } - - @AfterClass - public static void tearDownClass() - { - } - - @Before - public void setUp() - { - } - - @After - public void tearDown() - { - } - - @Test - public void testFind() throws IOException - { - IocContext instance = Ioc.context(); - DummyComponent result = instance.find(DummyComponent.class); - assertNotNull(result); - } - - @Test - public void testFindByService() throws IOException - { - IocContext instance = Ioc.context(); - SomeService result = instance.find(SomeService.class); - assertNotNull(result); - assertTrue(result instanceof DummyServiceProvider); - - SomeService[] resultArr = instance.findAll(SomeService.class); - assertNotNull(resultArr); - assertEquals(2, resultArr.length); - assertTrue(resultArr[0] instanceof DummyServiceProvider); - assertTrue(resultArr[1] instanceof DummyServiceProvider2); - } - - @Test - public void testInjectAndHerarchy() throws IOException - { - IocContext instance = Ioc.context(); - ConcreteComponent conComp = instance.find(ConcreteComponent.class); - assertNotNull(conComp.getDummyComponent()); - assertNotNull(conComp.getServices()); - assertTrue(conComp.getServices()[0] instanceof DummyServiceProvider); - assertTrue(conComp.getServices()[1] instanceof DummyServiceProvider2); - } - - @Test - public void testInjectGeneric() throws IOException - { - IocContext instance = Ioc.context(); - GenericInjectComponent giComp = instance.find(GenericInjectComponent.class); - assertNotNull(giComp); - assertNotNull(giComp.getGsOfStr()); - assertNull(giComp.getGsOfObject()); - assertTrue(giComp.getGsOfStr() instanceof GenericComponent); - assertNotNull(giComp.getComplexInject()); - assertTrue(giComp.getComplexInject() instanceof ComplexInjectComponent); - } - - @Test - public void testPriority() throws IOException - { - IocContext instance = Ioc.context(); - PriorityService[] prorityArr = instance.findAll(PriorityService.class); - assertTrue(prorityArr[0] instanceof PriorityComp3); - assertTrue(prorityArr[1] instanceof PriorityComp1); - assertTrue(prorityArr[2] instanceof PriorityComp4); - assertTrue(prorityArr[3] instanceof PriorityComp2); - - assertTrue(instance.find(PriorityService.class) instanceof PriorityComp3); - - } - - @Test - public void testDefineService() throws IOException - { - /* - TODO: This test needs the initialization that i commented becouse of the - java.lang.IllegalStateException: The APPLICATION Context is already created. - */ - /* - IocContext instance = Ioc.context(); - - DefaultService service = instance.find(DefaultService.class); - - assertTrue(service instanceof DefaultComponent2); - */ - } - - @Test - public void testChain() throws IOException - { - IocContext instance = Ioc.context(); - - ChainTest chainTest = instance.find(ChainTest.class); - - assertEquals("Wrong Chain", "1 2 3", chainTest.execute()); - } -} + +package org.bridje.ioc; + +import java.io.IOException; +import org.bridje.ioc.test.ComplexInjectComponent; +import org.bridje.ioc.test.ConcreteComponent; +import org.bridje.ioc.test.DummyComponent; +import org.bridje.ioc.test.DummyServiceProvider; +import org.bridje.ioc.test.DummyServiceProvider2; +import org.bridje.ioc.test.GenericComponent; +import org.bridje.ioc.test.GenericInjectComponent; +import org.bridje.ioc.test.SomeService; +import org.bridje.ioc.test.chain.ChainTest; +import org.bridje.ioc.test.priority.PriorityComp1; +import org.bridje.ioc.test.priority.PriorityComp2; +import org.bridje.ioc.test.priority.PriorityComp3; +import org.bridje.ioc.test.priority.PriorityComp4; +import org.bridje.ioc.test.priority.PriorityService; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; + +public class IocContextImplTest +{ + + public IocContextImplTest() + { + } + + @BeforeClass + public static void setUpClass() + { + /* + TODO: This initialization causes + java.lang.IllegalStateException: The APPLICATION Context is already created. + becouse the test order is not defined, a work arround is needed. + */ + /* + Ioc.init(Service. + forThis(DefaultService.class). + implementBy(DefaultComponent2.class)); + */ + } + + @AfterClass + public static void tearDownClass() + { + } + + @Before + public void setUp() + { + } + + @After + public void tearDown() + { + } + + @Test + public void testFind() throws IOException + { + IocContext instance = Ioc.context(); + DummyComponent result = instance.find(DummyComponent.class); + assertNotNull(result); + } + + @Test + public void testFindByService() throws IOException + { + IocContext instance = Ioc.context(); + SomeService result = instance.find(SomeService.class); + assertNotNull(result); + assertTrue(result instanceof DummyServiceProvider); + + SomeService[] resultArr = instance.findAll(SomeService.class); + assertNotNull(resultArr); + assertEquals(2, resultArr.length); + assertTrue(resultArr[0] instanceof DummyServiceProvider); + assertTrue(resultArr[1] instanceof DummyServiceProvider2); + } + + @Test + public void testInjectAndHerarchy() throws IOException + { + IocContext instance = Ioc.context(); + ConcreteComponent conComp = instance.find(ConcreteComponent.class); + assertNotNull(conComp.getDummyComponent()); + assertNotNull(conComp.getServices()); + assertTrue(conComp.getServices()[0] instanceof DummyServiceProvider); + assertTrue(conComp.getServices()[1] instanceof DummyServiceProvider2); + } + + @Test + public void testInjectGeneric() throws IOException + { + IocContext instance = Ioc.context(); + GenericInjectComponent giComp = instance.find(GenericInjectComponent.class); + assertNotNull(giComp); + assertNotNull(giComp.getGsOfStr()); + assertNull(giComp.getGsOfObject()); + assertTrue(giComp.getGsOfStr() instanceof GenericComponent); + assertNotNull(giComp.getComplexInject()); + assertTrue(giComp.getComplexInject() instanceof ComplexInjectComponent); + } + + @Test + public void testPriority() throws IOException + { + IocContext instance = Ioc.context(); + PriorityService[] prorityArr = instance.findAll(PriorityService.class); + assertTrue(prorityArr[0] instanceof PriorityComp3); + assertTrue(prorityArr[1] instanceof PriorityComp1); + assertTrue(prorityArr[2] instanceof PriorityComp4); + assertTrue(prorityArr[3] instanceof PriorityComp2); + + assertTrue(instance.find(PriorityService.class) instanceof PriorityComp3); + + } + + @Test + public void testDefineService() throws IOException + { + /* + TODO: This test needs the initialization that i commented becouse of the + java.lang.IllegalStateException: The APPLICATION Context is already created. + */ + /* + IocContext instance = Ioc.context(); + + DefaultService service = instance.find(DefaultService.class); + + assertTrue(service instanceof DefaultComponent2); + */ + } + + @Test + public void testChain() throws IOException + { + IocContext instance = Ioc.context(); + + ChainTest chainTest = instance.find(ChainTest.class); + + assertEquals("Wrong Chain", "1 2 3", chainTest.execute()); + } +} diff --git a/bridje-ioc/src/test/java/org/bridje/ioc/test/AbstractComponent.java b/bridje-ioc/src/test/java/org/bridje/ioc/test/AbstractComponent.java index 09d481af5..41b2f6522 100644 --- a/bridje-ioc/src/test/java/org/bridje/ioc/test/AbstractComponent.java +++ b/bridje-ioc/src/test/java/org/bridje/ioc/test/AbstractComponent.java @@ -1,30 +1,30 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.ioc.test; - -import org.bridje.ioc.Inject; - -public abstract class AbstractComponent -{ - @Inject - private DummyComponent dummyComponent; - - public DummyComponent getDummyComponent() - { - return dummyComponent; - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.ioc.test; + +import org.bridje.ioc.Inject; + +public abstract class AbstractComponent +{ + @Inject + private DummyComponent dummyComponent; + + public DummyComponent getDummyComponent() + { + return dummyComponent; + } +} diff --git a/bridje-ioc/src/test/java/org/bridje/ioc/test/ComplexInjectComponent.java b/bridje-ioc/src/test/java/org/bridje/ioc/test/ComplexInjectComponent.java index 3a98e6152..be7fd0cb1 100644 --- a/bridje-ioc/src/test/java/org/bridje/ioc/test/ComplexInjectComponent.java +++ b/bridje-ioc/src/test/java/org/bridje/ioc/test/ComplexInjectComponent.java @@ -1,31 +1,31 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.ioc.test; - -import java.util.List; -import java.util.Map; -import org.bridje.ioc.Component; - -/** - * - * @author Gilberto - */ -@Component -public class ComplexInjectComponent implements GenericService>> -{ - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.ioc.test; + +import java.util.List; +import java.util.Map; +import org.bridje.ioc.Component; + +/** + * + * @author Gilberto + */ +@Component +public class ComplexInjectComponent implements GenericService>> +{ + +} diff --git a/bridje-ioc/src/test/java/org/bridje/ioc/test/ConcreteComponent.java b/bridje-ioc/src/test/java/org/bridje/ioc/test/ConcreteComponent.java index 2f4e767e1..1a319199e 100644 --- a/bridje-ioc/src/test/java/org/bridje/ioc/test/ConcreteComponent.java +++ b/bridje-ioc/src/test/java/org/bridje/ioc/test/ConcreteComponent.java @@ -1,32 +1,32 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.ioc.test; - -import org.bridje.ioc.Component; -import org.bridje.ioc.Inject; - -@Component -public class ConcreteComponent extends AbstractComponent -{ - @Inject - private SomeService[] services; - - public SomeService[] getServices() - { - return services; - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.ioc.test; + +import org.bridje.ioc.Component; +import org.bridje.ioc.Inject; + +@Component +public class ConcreteComponent extends AbstractComponent +{ + @Inject + private SomeService[] services; + + public SomeService[] getServices() + { + return services; + } +} diff --git a/bridje-ioc/src/test/java/org/bridje/ioc/test/ContextListenerDummy.java b/bridje-ioc/src/test/java/org/bridje/ioc/test/ContextListenerDummy.java index a6d7cfdea..955f7b362 100644 --- a/bridje-ioc/src/test/java/org/bridje/ioc/test/ContextListenerDummy.java +++ b/bridje-ioc/src/test/java/org/bridje/ioc/test/ContextListenerDummy.java @@ -1,41 +1,41 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.ioc.test; - -import org.bridje.ioc.ContextListener; -import org.bridje.ioc.Component; - -@Component -public class ContextListenerDummy implements ContextListener -{ - @Override - public void preCreateComponent(Class clazz) - { - System.out.println("This method is called only when DummyComponent is preCreate"); - } - - @Override - public void preInitComponent(Class clazz, DummyComponent instance) - { - System.out.println("This method is called only when DummyComponent is preInit"); - } - - @Override - public void postInitComponent(Class clazz, DummyComponent instance) - { - System.out.println("This method is called only when DummyComponent is postInit"); - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.ioc.test; + +import org.bridje.ioc.ContextListener; +import org.bridje.ioc.Component; + +@Component +public class ContextListenerDummy implements ContextListener +{ + @Override + public void preCreateComponent(Class clazz) + { + System.out.println("This method is called only when DummyComponent is preCreate"); + } + + @Override + public void preInitComponent(Class clazz, DummyComponent instance) + { + System.out.println("This method is called only when DummyComponent is preInit"); + } + + @Override + public void postInitComponent(Class clazz, DummyComponent instance) + { + System.out.println("This method is called only when DummyComponent is postInit"); + } +} diff --git a/bridje-ioc/src/test/java/org/bridje/ioc/test/ContextListenerGeneric.java b/bridje-ioc/src/test/java/org/bridje/ioc/test/ContextListenerGeneric.java index e18aaca75..2e0359bb5 100644 --- a/bridje-ioc/src/test/java/org/bridje/ioc/test/ContextListenerGeneric.java +++ b/bridje-ioc/src/test/java/org/bridje/ioc/test/ContextListenerGeneric.java @@ -1,41 +1,41 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.ioc.test; - -import org.bridje.ioc.ContextListener; -import org.bridje.ioc.Component; - -@Component -public class ContextListenerGeneric implements ContextListener -{ - @Override - public void preCreateComponent(Class clazz) - { - System.out.println("General method called for all the components preCreate: " + clazz.getName()); - } - - @Override - public void preInitComponent(Class clazz, Object object) - { - System.out.println("General method called for all the components preInit: " + clazz.getName()); - } - - @Override - public void postInitComponent(Class clazz, Object object) - { - System.out.println("General method called for all the components postInit: " + clazz.getName()); - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.ioc.test; + +import org.bridje.ioc.ContextListener; +import org.bridje.ioc.Component; + +@Component +public class ContextListenerGeneric implements ContextListener +{ + @Override + public void preCreateComponent(Class clazz) + { + System.out.println("General method called for all the components preCreate: " + clazz.getName()); + } + + @Override + public void preInitComponent(Class clazz, Object object) + { + System.out.println("General method called for all the components preInit: " + clazz.getName()); + } + + @Override + public void postInitComponent(Class clazz, Object object) + { + System.out.println("General method called for all the components postInit: " + clazz.getName()); + } +} diff --git a/bridje-ioc/src/test/java/org/bridje/ioc/test/DefaultComponent.java b/bridje-ioc/src/test/java/org/bridje/ioc/test/DefaultComponent.java index 4b6deca71..6d5df11c7 100644 --- a/bridje-ioc/src/test/java/org/bridje/ioc/test/DefaultComponent.java +++ b/bridje-ioc/src/test/java/org/bridje/ioc/test/DefaultComponent.java @@ -1,27 +1,27 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.ioc.test; - -import org.bridje.ioc.Component; -import org.bridje.ioc.Priority; - -@Component -@Priority(1) -public class DefaultComponent implements DefaultService -{ - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.ioc.test; + +import org.bridje.ioc.Component; +import org.bridje.ioc.Priority; + +@Component +@Priority(1) +public class DefaultComponent implements DefaultService +{ + +} diff --git a/bridje-ioc/src/test/java/org/bridje/ioc/test/DefaultComponent2.java b/bridje-ioc/src/test/java/org/bridje/ioc/test/DefaultComponent2.java index 35b1f98fa..aafe847d1 100644 --- a/bridje-ioc/src/test/java/org/bridje/ioc/test/DefaultComponent2.java +++ b/bridje-ioc/src/test/java/org/bridje/ioc/test/DefaultComponent2.java @@ -1,27 +1,27 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.ioc.test; - -import org.bridje.ioc.Component; -import org.bridje.ioc.Priority; - -@Component -@Priority(2) -public class DefaultComponent2 implements DefaultService -{ - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.ioc.test; + +import org.bridje.ioc.Component; +import org.bridje.ioc.Priority; + +@Component +@Priority(2) +public class DefaultComponent2 implements DefaultService +{ + +} diff --git a/bridje-ioc/src/test/java/org/bridje/ioc/test/DefaultService.java b/bridje-ioc/src/test/java/org/bridje/ioc/test/DefaultService.java index 59e7f2dc9..6255959c0 100644 --- a/bridje-ioc/src/test/java/org/bridje/ioc/test/DefaultService.java +++ b/bridje-ioc/src/test/java/org/bridje/ioc/test/DefaultService.java @@ -1,22 +1,22 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.ioc.test; - -public interface DefaultService -{ - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.ioc.test; + +public interface DefaultService +{ + +} diff --git a/bridje-ioc/src/test/java/org/bridje/ioc/test/DummyComponent.java b/bridje-ioc/src/test/java/org/bridje/ioc/test/DummyComponent.java index 6e32c824b..45c88db15 100644 --- a/bridje-ioc/src/test/java/org/bridje/ioc/test/DummyComponent.java +++ b/bridje-ioc/src/test/java/org/bridje/ioc/test/DummyComponent.java @@ -1,10 +1,10 @@ - -package org.bridje.ioc.test; - -import org.bridje.ioc.Component; - -@Component -public class DummyComponent -{ - -} + +package org.bridje.ioc.test; + +import org.bridje.ioc.Component; + +@Component +public class DummyComponent +{ + +} diff --git a/bridje-ioc/src/test/java/org/bridje/ioc/test/DummyServiceProvider.java b/bridje-ioc/src/test/java/org/bridje/ioc/test/DummyServiceProvider.java index 95f68f711..5fee25470 100644 --- a/bridje-ioc/src/test/java/org/bridje/ioc/test/DummyServiceProvider.java +++ b/bridje-ioc/src/test/java/org/bridje/ioc/test/DummyServiceProvider.java @@ -1,27 +1,27 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.ioc.test; - -import org.bridje.ioc.Component; -import org.bridje.ioc.Priority; - -@Component -@Priority(value = 1) -public class DummyServiceProvider implements SomeService -{ - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.ioc.test; + +import org.bridje.ioc.Component; +import org.bridje.ioc.Priority; + +@Component +@Priority(value = 1) +public class DummyServiceProvider implements SomeService +{ + +} diff --git a/bridje-ioc/src/test/java/org/bridje/ioc/test/DummyServiceProvider2.java b/bridje-ioc/src/test/java/org/bridje/ioc/test/DummyServiceProvider2.java index d2424efd6..eef196d29 100644 --- a/bridje-ioc/src/test/java/org/bridje/ioc/test/DummyServiceProvider2.java +++ b/bridje-ioc/src/test/java/org/bridje/ioc/test/DummyServiceProvider2.java @@ -1,27 +1,27 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.ioc.test; - -import org.bridje.ioc.Component; -import org.bridje.ioc.Priority; - -@Component -@Priority(value = 2) -public class DummyServiceProvider2 implements SomeService -{ - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.ioc.test; + +import org.bridje.ioc.Component; +import org.bridje.ioc.Priority; + +@Component +@Priority(value = 2) +public class DummyServiceProvider2 implements SomeService +{ + +} diff --git a/bridje-ioc/src/test/java/org/bridje/ioc/test/GenericComponent.java b/bridje-ioc/src/test/java/org/bridje/ioc/test/GenericComponent.java index 9c1096e9e..f3356e654 100644 --- a/bridje-ioc/src/test/java/org/bridje/ioc/test/GenericComponent.java +++ b/bridje-ioc/src/test/java/org/bridje/ioc/test/GenericComponent.java @@ -1,25 +1,25 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.ioc.test; - -import org.bridje.ioc.Component; - -@Component -public class GenericComponent implements GenericService -{ - +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.ioc.test; + +import org.bridje.ioc.Component; + +@Component +public class GenericComponent implements GenericService +{ + } \ No newline at end of file diff --git a/bridje-ioc/src/test/java/org/bridje/ioc/test/GenericInjectComponent.java b/bridje-ioc/src/test/java/org/bridje/ioc/test/GenericInjectComponent.java index 3e2a233a6..35fb4557a 100644 --- a/bridje-ioc/src/test/java/org/bridje/ioc/test/GenericInjectComponent.java +++ b/bridje-ioc/src/test/java/org/bridje/ioc/test/GenericInjectComponent.java @@ -1,53 +1,53 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.ioc.test; - -import java.util.List; -import java.util.Map; -import org.bridje.ioc.Component; -import org.bridje.ioc.Inject; - -@Component -public class GenericInjectComponent -{ - //TODO test for array injection of generic services. - private GenericService[] gsOfStrArr; - - @Inject - private GenericService gsOfStr; - - @Inject - private GenericService gsOfObject; - - @Inject - private GenericService>> complexInject; - - public GenericService getGsOfStr() - { - return gsOfStr; - } - - public GenericService getGsOfObject() - { - return gsOfObject; - } - - public GenericService>> getComplexInject() - { - return complexInject; - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.ioc.test; + +import java.util.List; +import java.util.Map; +import org.bridje.ioc.Component; +import org.bridje.ioc.Inject; + +@Component +public class GenericInjectComponent +{ + //TODO test for array injection of generic services. + private GenericService[] gsOfStrArr; + + @Inject + private GenericService gsOfStr; + + @Inject + private GenericService gsOfObject; + + @Inject + private GenericService>> complexInject; + + public GenericService getGsOfStr() + { + return gsOfStr; + } + + public GenericService getGsOfObject() + { + return gsOfObject; + } + + public GenericService>> getComplexInject() + { + return complexInject; + } +} diff --git a/bridje-ioc/src/test/java/org/bridje/ioc/test/GenericService.java b/bridje-ioc/src/test/java/org/bridje/ioc/test/GenericService.java index c574279a1..586b01dac 100644 --- a/bridje-ioc/src/test/java/org/bridje/ioc/test/GenericService.java +++ b/bridje-ioc/src/test/java/org/bridje/ioc/test/GenericService.java @@ -1,22 +1,22 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.ioc.test; - -public interface GenericService -{ - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.ioc.test; + +public interface GenericService +{ + +} diff --git a/bridje-ioc/src/test/java/org/bridje/ioc/test/SomeService.java b/bridje-ioc/src/test/java/org/bridje/ioc/test/SomeService.java index dc8b59da5..da2f1052e 100644 --- a/bridje-ioc/src/test/java/org/bridje/ioc/test/SomeService.java +++ b/bridje-ioc/src/test/java/org/bridje/ioc/test/SomeService.java @@ -1,22 +1,22 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.ioc.test; - -public interface SomeService -{ - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.ioc.test; + +public interface SomeService +{ + +} diff --git a/bridje-ioc/src/test/java/org/bridje/ioc/test/chain/ChainHandlerFirst.java b/bridje-ioc/src/test/java/org/bridje/ioc/test/chain/ChainHandlerFirst.java index 366ec8cf2..41c5266f2 100644 --- a/bridje-ioc/src/test/java/org/bridje/ioc/test/chain/ChainHandlerFirst.java +++ b/bridje-ioc/src/test/java/org/bridje/ioc/test/chain/ChainHandlerFirst.java @@ -1,50 +1,50 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.ioc.test.chain; - -import org.bridje.ioc.Component; -import org.bridje.ioc.Inject; -import org.bridje.ioc.InjectNext; -import org.bridje.ioc.Priority; - -/** - * - * @author Gilberto - */ -@Component -@Priority(1) -public class ChainHandlerFirst implements MyChainHandler -{ - @InjectNext - private MyChainHandler next; - - @Override - public String execute(String prev) - { - String c = "1"; - if(prev != null) - { - c = prev + " " + c; - } - if(next != null) - { - return next.execute(c); - } - return c; - } - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.ioc.test.chain; + +import org.bridje.ioc.Component; +import org.bridje.ioc.Inject; +import org.bridje.ioc.InjectNext; +import org.bridje.ioc.Priority; + +/** + * + * @author Gilberto + */ +@Component +@Priority(1) +public class ChainHandlerFirst implements MyChainHandler +{ + @InjectNext + private MyChainHandler next; + + @Override + public String execute(String prev) + { + String c = "1"; + if(prev != null) + { + c = prev + " " + c; + } + if(next != null) + { + return next.execute(c); + } + return c; + } + +} diff --git a/bridje-ioc/src/test/java/org/bridje/ioc/test/chain/ChainHandlerSecond.java b/bridje-ioc/src/test/java/org/bridje/ioc/test/chain/ChainHandlerSecond.java index e030f6fd5..24831d56a 100644 --- a/bridje-ioc/src/test/java/org/bridje/ioc/test/chain/ChainHandlerSecond.java +++ b/bridje-ioc/src/test/java/org/bridje/ioc/test/chain/ChainHandlerSecond.java @@ -1,49 +1,49 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.ioc.test.chain; - -import org.bridje.ioc.Component; -import org.bridje.ioc.InjectNext; -import org.bridje.ioc.Priority; - -/** - * - * @author Gilberto - */ -@Component -@Priority(2) -public class ChainHandlerSecond implements MyChainHandler -{ - @InjectNext - private MyChainHandler next; - - @Override - public String execute(String prev) - { - String c = "2"; - if(prev != null) - { - c = prev + " " + c; - } - if(next != null) - { - return next.execute(c); - } - return c; - } - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.ioc.test.chain; + +import org.bridje.ioc.Component; +import org.bridje.ioc.InjectNext; +import org.bridje.ioc.Priority; + +/** + * + * @author Gilberto + */ +@Component +@Priority(2) +public class ChainHandlerSecond implements MyChainHandler +{ + @InjectNext + private MyChainHandler next; + + @Override + public String execute(String prev) + { + String c = "2"; + if(prev != null) + { + c = prev + " " + c; + } + if(next != null) + { + return next.execute(c); + } + return c; + } + +} diff --git a/bridje-ioc/src/test/java/org/bridje/ioc/test/chain/ChainHandlerThird.java b/bridje-ioc/src/test/java/org/bridje/ioc/test/chain/ChainHandlerThird.java index 0f98733de..11f6d06bf 100644 --- a/bridje-ioc/src/test/java/org/bridje/ioc/test/chain/ChainHandlerThird.java +++ b/bridje-ioc/src/test/java/org/bridje/ioc/test/chain/ChainHandlerThird.java @@ -1,48 +1,48 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.ioc.test.chain; - -import org.bridje.ioc.Component; -import org.bridje.ioc.InjectNext; -import org.bridje.ioc.Priority; - -/** - * - * @author Gilberto - */ -@Component -@Priority(3) -public class ChainHandlerThird implements MyChainHandler -{ - @InjectNext - private MyChainHandler next; - - @Override - public String execute(String prev) - { - String c = "3"; - if(prev != null) - { - c = prev + " " + c; - } - if(next != null) - { - return next.execute(c); - } - return c; - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.ioc.test.chain; + +import org.bridje.ioc.Component; +import org.bridje.ioc.InjectNext; +import org.bridje.ioc.Priority; + +/** + * + * @author Gilberto + */ +@Component +@Priority(3) +public class ChainHandlerThird implements MyChainHandler +{ + @InjectNext + private MyChainHandler next; + + @Override + public String execute(String prev) + { + String c = "3"; + if(prev != null) + { + c = prev + " " + c; + } + if(next != null) + { + return next.execute(c); + } + return c; + } +} diff --git a/bridje-ioc/src/test/java/org/bridje/ioc/test/chain/ChainTest.java b/bridje-ioc/src/test/java/org/bridje/ioc/test/chain/ChainTest.java index ca7616979..193f7182e 100644 --- a/bridje-ioc/src/test/java/org/bridje/ioc/test/chain/ChainTest.java +++ b/bridje-ioc/src/test/java/org/bridje/ioc/test/chain/ChainTest.java @@ -1,36 +1,36 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.ioc.test.chain; - -import org.bridje.ioc.Component; -import org.bridje.ioc.Inject; - -/** - * - * @author Gilberto - */ -@Component -public class ChainTest -{ - @Inject - private MyChainHandler first; - - public String execute() - { - return first.execute(null); - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.ioc.test.chain; + +import org.bridje.ioc.Component; +import org.bridje.ioc.Inject; + +/** + * + * @author Gilberto + */ +@Component +public class ChainTest +{ + @Inject + private MyChainHandler first; + + public String execute() + { + return first.execute(null); + } +} diff --git a/bridje-ioc/src/test/java/org/bridje/ioc/test/chain/MyChainHandler.java b/bridje-ioc/src/test/java/org/bridje/ioc/test/chain/MyChainHandler.java index fc850084f..6ebedd228 100644 --- a/bridje-ioc/src/test/java/org/bridje/ioc/test/chain/MyChainHandler.java +++ b/bridje-ioc/src/test/java/org/bridje/ioc/test/chain/MyChainHandler.java @@ -1,22 +1,22 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.ioc.test.chain; - -public interface MyChainHandler -{ - public T execute(T prev); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.ioc.test.chain; + +public interface MyChainHandler +{ + public T execute(T prev); +} diff --git a/bridje-ioc/src/test/java/org/bridje/ioc/test/priority/PriorityComp1.java b/bridje-ioc/src/test/java/org/bridje/ioc/test/priority/PriorityComp1.java index e9a25611b..210ec0e19 100644 --- a/bridje-ioc/src/test/java/org/bridje/ioc/test/priority/PriorityComp1.java +++ b/bridje-ioc/src/test/java/org/bridje/ioc/test/priority/PriorityComp1.java @@ -1,30 +1,30 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.ioc.test.priority; - -import org.bridje.ioc.Component; -import org.bridje.ioc.Priority; -/** - * - * @author Gilberto - */ -@Component -@Priority(1) -public class PriorityComp1 implements PriorityService -{ - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.ioc.test.priority; + +import org.bridje.ioc.Component; +import org.bridje.ioc.Priority; +/** + * + * @author Gilberto + */ +@Component +@Priority(1) +public class PriorityComp1 implements PriorityService +{ + +} diff --git a/bridje-ioc/src/test/java/org/bridje/ioc/test/priority/PriorityComp2.java b/bridje-ioc/src/test/java/org/bridje/ioc/test/priority/PriorityComp2.java index c2c84e08e..d37e2caff 100644 --- a/bridje-ioc/src/test/java/org/bridje/ioc/test/priority/PriorityComp2.java +++ b/bridje-ioc/src/test/java/org/bridje/ioc/test/priority/PriorityComp2.java @@ -1,28 +1,28 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.ioc.test.priority; - -import org.bridje.ioc.Component; -/** - * - * @author Gilberto - */ -@Component -public class PriorityComp2 implements PriorityService -{ - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.ioc.test.priority; + +import org.bridje.ioc.Component; +/** + * + * @author Gilberto + */ +@Component +public class PriorityComp2 implements PriorityService +{ + +} diff --git a/bridje-ioc/src/test/java/org/bridje/ioc/test/priority/PriorityComp3.java b/bridje-ioc/src/test/java/org/bridje/ioc/test/priority/PriorityComp3.java index e52a88976..e0b985fd6 100644 --- a/bridje-ioc/src/test/java/org/bridje/ioc/test/priority/PriorityComp3.java +++ b/bridje-ioc/src/test/java/org/bridje/ioc/test/priority/PriorityComp3.java @@ -1,30 +1,30 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.ioc.test.priority; - -import org.bridje.ioc.Component; -import org.bridje.ioc.Priority; -/** - * - * @author Gilberto - */ -@Component -@Priority(0) -public class PriorityComp3 implements PriorityService -{ - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.ioc.test.priority; + +import org.bridje.ioc.Component; +import org.bridje.ioc.Priority; +/** + * + * @author Gilberto + */ +@Component +@Priority(0) +public class PriorityComp3 implements PriorityService +{ + +} diff --git a/bridje-ioc/src/test/java/org/bridje/ioc/test/priority/PriorityComp4.java b/bridje-ioc/src/test/java/org/bridje/ioc/test/priority/PriorityComp4.java index fe4d36522..66360e5a8 100644 --- a/bridje-ioc/src/test/java/org/bridje/ioc/test/priority/PriorityComp4.java +++ b/bridje-ioc/src/test/java/org/bridje/ioc/test/priority/PriorityComp4.java @@ -1,30 +1,30 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.ioc.test.priority; - -import org.bridje.ioc.Component; -import org.bridje.ioc.Priority; -/** - * - * @author Gilberto - */ -@Component -@Priority(3) -public class PriorityComp4 implements PriorityService -{ - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.ioc.test.priority; + +import org.bridje.ioc.Component; +import org.bridje.ioc.Priority; +/** + * + * @author Gilberto + */ +@Component +@Priority(3) +public class PriorityComp4 implements PriorityService +{ + +} diff --git a/bridje-ioc/src/test/java/org/bridje/ioc/test/priority/PriorityService.java b/bridje-ioc/src/test/java/org/bridje/ioc/test/priority/PriorityService.java index e2a1d5163..458fb79f5 100644 --- a/bridje-ioc/src/test/java/org/bridje/ioc/test/priority/PriorityService.java +++ b/bridje-ioc/src/test/java/org/bridje/ioc/test/priority/PriorityService.java @@ -1,26 +1,26 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.ioc.test.priority; - -/** - * - * @author Gilberto - */ -public interface PriorityService -{ - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.ioc.test.priority; + +/** + * + * @author Gilberto + */ +public interface PriorityService +{ + +} diff --git a/bridje-xsd-maven-plugin/pom.xml b/bridje-xsd-maven-plugin/pom.xml index 7b1e6751b..19fb310a8 100644 --- a/bridje-xsd-maven-plugin/pom.xml +++ b/bridje-xsd-maven-plugin/pom.xml @@ -1,73 +1,73 @@ - - - 4.0.0 - - - org.bridje - bridje-parent - 0.1.3-SNAPSHOT - - - org.bridje - bridje-xsd-maven-plugin - 0.1.3-SNAPSHOT - maven-plugin - - Bridje XSD Maven Plugin - Maven plugin for XSD generation from JAXB classes - - - - - org.apache.maven.plugins - maven-plugin-plugin - 3.4 - - true - - - - default-descriptor - - descriptor - - process-classes - - - - - org.apache.maven.plugins - maven-compiler-plugin - - - - - - - org.apache.maven - maven-plugin-api - 3.3.3 - - - org.apache.maven - maven-artifact - 2.2.1 - - - org.apache.maven.plugin-tools - maven-plugin-annotations - 3.4 - provided - - - org.apache.maven - maven-project - 2.2.1 - - - com.github.lookfirst - sardine - 5.4 - - - + + + 4.0.0 + + + org.bridje + bridje-parent + 0.1.3-SNAPSHOT + + + org.bridje + bridje-xsd-maven-plugin + 0.1.3-SNAPSHOT + maven-plugin + + Bridje XSD Maven Plugin + Maven plugin for XSD generation from JAXB classes + + + + + org.apache.maven.plugins + maven-plugin-plugin + 3.4 + + true + + + + default-descriptor + + descriptor + + process-classes + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + + + + org.apache.maven + maven-plugin-api + 3.3.3 + + + org.apache.maven + maven-artifact + 2.2.1 + + + org.apache.maven.plugin-tools + maven-plugin-annotations + 3.4 + provided + + + org.apache.maven + maven-project + 2.2.1 + + + com.github.lookfirst + sardine + 5.4 + + + diff --git a/bridje-xsd-maven-plugin/src/main/java/org/bridje/xsd/maven/plugin/GenerateMojo.java b/bridje-xsd-maven-plugin/src/main/java/org/bridje/xsd/maven/plugin/GenerateMojo.java index 48b866c55..38c1a50d0 100644 --- a/bridje-xsd-maven-plugin/src/main/java/org/bridje/xsd/maven/plugin/GenerateMojo.java +++ b/bridje-xsd-maven-plugin/src/main/java/org/bridje/xsd/maven/plugin/GenerateMojo.java @@ -1,119 +1,119 @@ - -package org.bridje.xsd.maven.plugin; - -import java.io.File; -import java.io.IOException; -import java.net.MalformedURLException; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.DependencyResolutionRequiredException; -import org.apache.maven.plugin.AbstractMojo; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; -import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.classworlds.ClassWorld; -import org.codehaus.plexus.classworlds.realm.ClassRealm; -import org.codehaus.plexus.classworlds.realm.DuplicateRealmException; - -/** - * Mojo for xsd schema generation form project classes - */ -@Mojo(name = "generate-xsd") -public class GenerateMojo extends AbstractMojo -{ - @Parameter(property = "project") - private MavenProject project; - - @Parameter(property = "generateXsd.classes") - @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") - private List classes; - - @Parameter(property = "generateXsd.modelName") - private String modelName; - - @Override - public void execute() throws MojoExecutionException, MojoFailureException - { - if(modelName == null) - { - getLog().warn("XSD Schema cannot be generated. You must specify the model name."); - return; - } - - OutputResolver outputResolver = new OutputResolver(project.getBuild().getDirectory()); - try - { - ClassRealm newRealm = createClassRealm(); - processModel(newRealm, outputResolver); - } - catch (DependencyResolutionRequiredException | IOException | DuplicateRealmException ex) - { - getLog().error(ex.getMessage()); - throw new MojoExecutionException(ex.getMessage(), ex); - } - } - - private void processModel(ClassLoader classLoader, OutputResolver outputResolver) - { - List> lstClass = new LinkedList<>(); - - for (String cls : classes) - { - if (cls.endsWith(".java")) - { - cls = cls.substring(cls.length() - 5); - } - - try - { - Class modelCls = Class.forName(cls, true, classLoader); - lstClass.add(modelCls); - } - catch (ClassNotFoundException ex) - { - getLog().error(ex.getMessage()); - } - } - - try - { - Class[] arr = new Class[lstClass.size()]; - arr = lstClass.toArray(arr); - JAXBContext context = JAXBContext.newInstance(arr); - outputResolver.setSchemaName(modelName); - getLog().info("Generating XSD: " + modelName + " ..."); - context.generateSchema(outputResolver); - getLog().info("File " + modelName + ".xsd generated."); - } - catch (JAXBException | IOException ex) - { - getLog().error(ex.getMessage()); - } - } - - private ClassRealm createClassRealm() throws DependencyResolutionRequiredException, DuplicateRealmException, MalformedURLException - { - List elements = project.getCompileClasspathElements(); - Set artifacts = project.getDependencyArtifacts(); - - ClassWorld world = new ClassWorld(); - ClassRealm newRealm = world.newRealm("projCp", null); - for (Artifact artifact : artifacts) - { - File file = artifact.getFile(); - newRealm.addURL(file.toURI().toURL()); - } - - for(String element : elements) - { - newRealm.addURL(new File(element).toURI().toURL()); - } - return newRealm; - } -} + +package org.bridje.xsd.maven.plugin; + +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.DependencyResolutionRequiredException; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.classworlds.ClassWorld; +import org.codehaus.plexus.classworlds.realm.ClassRealm; +import org.codehaus.plexus.classworlds.realm.DuplicateRealmException; + +/** + * Mojo for xsd schema generation form project classes + */ +@Mojo(name = "generate-xsd") +public class GenerateMojo extends AbstractMojo +{ + @Parameter(property = "project") + private MavenProject project; + + @Parameter(property = "generateXsd.classes") + @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") + private List classes; + + @Parameter(property = "generateXsd.modelName") + private String modelName; + + @Override + public void execute() throws MojoExecutionException, MojoFailureException + { + if(modelName == null) + { + getLog().warn("XSD Schema cannot be generated. You must specify the model name."); + return; + } + + OutputResolver outputResolver = new OutputResolver(project.getBuild().getDirectory()); + try + { + ClassRealm newRealm = createClassRealm(); + processModel(newRealm, outputResolver); + } + catch (DependencyResolutionRequiredException | IOException | DuplicateRealmException ex) + { + getLog().error(ex.getMessage()); + throw new MojoExecutionException(ex.getMessage(), ex); + } + } + + private void processModel(ClassLoader classLoader, OutputResolver outputResolver) + { + List> lstClass = new LinkedList<>(); + + for (String cls : classes) + { + if (cls.endsWith(".java")) + { + cls = cls.substring(cls.length() - 5); + } + + try + { + Class modelCls = Class.forName(cls, true, classLoader); + lstClass.add(modelCls); + } + catch (ClassNotFoundException ex) + { + getLog().error(ex.getMessage()); + } + } + + try + { + Class[] arr = new Class[lstClass.size()]; + arr = lstClass.toArray(arr); + JAXBContext context = JAXBContext.newInstance(arr); + outputResolver.setSchemaName(modelName); + getLog().info("Generating XSD: " + modelName + " ..."); + context.generateSchema(outputResolver); + getLog().info("File " + modelName + ".xsd generated."); + } + catch (JAXBException | IOException ex) + { + getLog().error(ex.getMessage()); + } + } + + private ClassRealm createClassRealm() throws DependencyResolutionRequiredException, DuplicateRealmException, MalformedURLException + { + List elements = project.getCompileClasspathElements(); + Set artifacts = project.getDependencyArtifacts(); + + ClassWorld world = new ClassWorld(); + ClassRealm newRealm = world.newRealm("projCp", null); + for (Artifact artifact : artifacts) + { + File file = artifact.getFile(); + newRealm.addURL(file.toURI().toURL()); + } + + for(String element : elements) + { + newRealm.addURL(new File(element).toURI().toURL()); + } + return newRealm; + } +} diff --git a/bridje-xsd-maven-plugin/src/main/java/org/bridje/xsd/maven/plugin/OutputResolver.java b/bridje-xsd-maven-plugin/src/main/java/org/bridje/xsd/maven/plugin/OutputResolver.java index 06e620fbe..c329179c1 100644 --- a/bridje-xsd-maven-plugin/src/main/java/org/bridje/xsd/maven/plugin/OutputResolver.java +++ b/bridje-xsd-maven-plugin/src/main/java/org/bridje/xsd/maven/plugin/OutputResolver.java @@ -1,65 +1,65 @@ -package org.bridje.xsd.maven.plugin; - -import java.io.File; -import java.io.IOException; -import javax.xml.bind.SchemaOutputResolver; -import javax.xml.transform.Result; -import javax.xml.transform.stream.StreamResult; - -/** - * xsd schema output resolver fo the result xsd file. - */ -public class OutputResolver extends SchemaOutputResolver -{ - private final String baseDir; - - private String schemaName; - - public OutputResolver(String baseDir) - { - if (baseDir.endsWith(File.separator)) - { - baseDir = baseDir.substring(0, baseDir.length() - File.separator.length()); - } - - this.baseDir = baseDir; - } - - @Override - public Result createOutput(String nsUri, String fileName) throws IOException - { - if(schemaName == null || schemaName.isEmpty()) - { - setSchemaName(fileName); - } - String path = baseDir + File.separator + schemaName; - File file = new File(path); - if (file.exists()) - { - file.delete(); - } - - file.createNewFile(); - - return new StreamResult(file); - } - - public String getSchemaName() - { - return schemaName; - } - - public void setSchemaName(String schemaName) - { - if (schemaName == null || schemaName.isEmpty()) - { - return; - } - if (!schemaName.endsWith(".xsd")) - { - schemaName += ".xsd"; - } - - this.schemaName = schemaName.substring(0, 1).toLowerCase() + schemaName.substring(1); - } -} +package org.bridje.xsd.maven.plugin; + +import java.io.File; +import java.io.IOException; +import javax.xml.bind.SchemaOutputResolver; +import javax.xml.transform.Result; +import javax.xml.transform.stream.StreamResult; + +/** + * xsd schema output resolver fo the result xsd file. + */ +public class OutputResolver extends SchemaOutputResolver +{ + private final String baseDir; + + private String schemaName; + + public OutputResolver(String baseDir) + { + if (baseDir.endsWith(File.separator)) + { + baseDir = baseDir.substring(0, baseDir.length() - File.separator.length()); + } + + this.baseDir = baseDir; + } + + @Override + public Result createOutput(String nsUri, String fileName) throws IOException + { + if(schemaName == null || schemaName.isEmpty()) + { + setSchemaName(fileName); + } + String path = baseDir + File.separator + schemaName; + File file = new File(path); + if (file.exists()) + { + file.delete(); + } + + file.createNewFile(); + + return new StreamResult(file); + } + + public String getSchemaName() + { + return schemaName; + } + + public void setSchemaName(String schemaName) + { + if (schemaName == null || schemaName.isEmpty()) + { + return; + } + if (!schemaName.endsWith(".xsd")) + { + schemaName += ".xsd"; + } + + this.schemaName = schemaName.substring(0, 1).toLowerCase() + schemaName.substring(1); + } +} diff --git a/old/bridje-core/pom.xml b/old/bridje-core/pom.xml index e3fcf56ac..06536cdae 100644 --- a/old/bridje-core/pom.xml +++ b/old/bridje-core/pom.xml @@ -1,132 +1,132 @@ - - - 4.0.0 - - - org.bridje - bridje-parent - 0.0.6-SNAPSHOT - - - bridje-core - - Bridje Core - Bridje Core API - http://www.bridje.org - - - - javax.servlet-api - javax.servlet - 3.1.0 - - - org.eclipse.jetty - jetty-server - 9.3.6.v20151106 - - - jetty-http - org.eclipse.jetty - 9.3.6.v20151106 - - - jetty-util - org.eclipse.jetty - 9.3.6.v20151106 - - - jetty-io - org.eclipse.jetty - 9.3.6.v20151106 - - - jetty-continuation - org.eclipse.jetty - 9.3.6.v20151106 - - - org.eclipse.jetty - jetty-servlet - 9.3.6.v20151106 - - - jetty-security - org.eclipse.jetty - 9.3.6.v20151106 - - - org.eclipse.jetty - jetty-xml - 9.3.6.v20151106 - - - org.freemarker - freemarker - 2.3.23 - - - - de.odysseus.juel - juel-api - 2.2.7 - - - de.odysseus.juel - juel-impl - 2.2.7 - - - de.odysseus.juel - juel-spi - 2.2.7 - - - - commons-dbcp - commons-dbcp - 1.4 - - - - junit - junit - test - - - commons-io - commons-io - 2.4 - - - commons-codec - commons-codec - 1.10 - - - ${project.groupId} - bridje-ioc - ${project.version} - - - ${project.groupId} - bridje-vfs - ${project.version} - - - ${project.groupId} - bridje-cfg - ${project.version} - - - ${project.groupId} - bridje-el - ${project.version} - - - ${project.groupId} - bridje-tpl - ${project.version} - - - + + + 4.0.0 + + + org.bridje + bridje-parent + 0.0.6-SNAPSHOT + + + bridje-core + + Bridje Core + Bridje Core API + http://www.bridje.org + + + + javax.servlet-api + javax.servlet + 3.1.0 + + + org.eclipse.jetty + jetty-server + 9.3.6.v20151106 + + + jetty-http + org.eclipse.jetty + 9.3.6.v20151106 + + + jetty-util + org.eclipse.jetty + 9.3.6.v20151106 + + + jetty-io + org.eclipse.jetty + 9.3.6.v20151106 + + + jetty-continuation + org.eclipse.jetty + 9.3.6.v20151106 + + + org.eclipse.jetty + jetty-servlet + 9.3.6.v20151106 + + + jetty-security + org.eclipse.jetty + 9.3.6.v20151106 + + + org.eclipse.jetty + jetty-xml + 9.3.6.v20151106 + + + org.freemarker + freemarker + 2.3.23 + + + + de.odysseus.juel + juel-api + 2.2.7 + + + de.odysseus.juel + juel-impl + 2.2.7 + + + de.odysseus.juel + juel-spi + 2.2.7 + + + + commons-dbcp + commons-dbcp + 1.4 + + + + junit + junit + test + + + commons-io + commons-io + 2.4 + + + commons-codec + commons-codec + 1.10 + + + ${project.groupId} + bridje-ioc + ${project.version} + + + ${project.groupId} + bridje-vfs + ${project.version} + + + ${project.groupId} + bridje-cfg + ${project.version} + + + ${project.groupId} + bridje-el + ${project.version} + + + ${project.groupId} + bridje-tpl + ${project.version} + + + diff --git a/old/bridje-core/src/main/java/org/bridje/core/aas/AasService.java b/old/bridje-core/src/main/java/org/bridje/core/aas/AasService.java index 95f77879d..60c426d7e 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/aas/AasService.java +++ b/old/bridje-core/src/main/java/org/bridje/core/aas/AasService.java @@ -1,32 +1,32 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.aas; - -import java.security.PrivilegedExceptionAction; -import javax.security.auth.Subject; - -/** - * - */ -public interface AasService -{ - Subject authenticate(String user, String pass); - - T doAs(Subject subject, PrivilegedExceptionAction action) throws Exception; - - T getPrincipal(Class cls); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.aas; + +import java.security.PrivilegedExceptionAction; +import javax.security.auth.Subject; + +/** + * + */ +public interface AasService +{ + Subject authenticate(String user, String pass); + + T doAs(Subject subject, PrivilegedExceptionAction action) throws Exception; + + T getPrincipal(Class cls); +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/cast/CastProvider.java b/old/bridje-core/src/main/java/org/bridje/core/cast/CastProvider.java index 2bad50720..59c667bc5 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/cast/CastProvider.java +++ b/old/bridje-core/src/main/java/org/bridje/core/cast/CastProvider.java @@ -1,48 +1,48 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.cast; - -/** - * Provider to cast any object to a specific class. - * - * @param The handled type by the provider. - */ -public interface CastProvider -{ - /** - * Obtains the input types that can handle. - * - * @return The array of allowed input types. - */ - Class[] getSrcClasses(); - - /** - * Obtains the destiny class of casting. - * - * @return The destiny class of casting. - */ - Class getDestClass(); - - /** - * Cast an object. - * - * @param object The object to be converted. - * @return The converted value or {@literal null} if not conversion can be made or - * cannot be handled. - */ - T cast(Object object); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.cast; + +/** + * Provider to cast any object to a specific class. + * + * @param The handled type by the provider. + */ +public interface CastProvider +{ + /** + * Obtains the input types that can handle. + * + * @return The array of allowed input types. + */ + Class[] getSrcClasses(); + + /** + * Obtains the destiny class of casting. + * + * @return The destiny class of casting. + */ + Class getDestClass(); + + /** + * Cast an object. + * + * @param object The object to be converted. + * @return The converted value or {@literal null} if not conversion can be made or + * cannot be handled. + */ + T cast(Object object); +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/cast/CastService.java b/old/bridje-core/src/main/java/org/bridje/core/cast/CastService.java index 34ebf3d52..49ae372e4 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/cast/CastService.java +++ b/old/bridje-core/src/main/java/org/bridje/core/cast/CastService.java @@ -1,33 +1,33 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.cast; - -/** - * A cast service for converting values to specific classes. - */ -public interface CastService -{ - /** - * Cast a value to the specified class. - *

- * @param The type of the target class. - * @param object The object to be converted. - * @param cls The target class. - * @return The converted value or {@literal null} if not conversion can be made. - */ - T cast(Object object, Class cls); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.cast; + +/** + * A cast service for converting values to specific classes. + */ +public interface CastService +{ + /** + * Cast a value to the specified class. + *

+ * @param The type of the target class. + * @param object The object to be converted. + * @param cls The target class. + * @return The converted value or {@literal null} if not conversion can be made. + */ + T cast(Object object, Class cls); +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/cli/Argument.java b/old/bridje-core/src/main/java/org/bridje/core/cli/Argument.java index 8ffbbfb31..05b263f2c 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/cli/Argument.java +++ b/old/bridje-core/src/main/java/org/bridje/core/cli/Argument.java @@ -1,31 +1,31 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.cli; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.PARAMETER) -public @interface Argument -{ -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.cli; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.PARAMETER) +public @interface Argument +{ +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/cli/CliService.java b/old/bridje-core/src/main/java/org/bridje/core/cli/CliService.java index 8797c3864..4f258a46b 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/cli/CliService.java +++ b/old/bridje-core/src/main/java/org/bridje/core/cli/CliService.java @@ -1,25 +1,25 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.cli; - -/** - * - */ -public interface CliService -{ - void execute(String command, CliSession session) throws NoCliParserException, InvalidCliCommandException, NoSuchCommandException; -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.cli; + +/** + * + */ +public interface CliService +{ + void execute(String command, CliSession session) throws NoCliParserException, InvalidCliCommandException, NoSuchCommandException; +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/cli/CliSession.java b/old/bridje-core/src/main/java/org/bridje/core/cli/CliSession.java index 138356ce4..9afea00b3 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/cli/CliSession.java +++ b/old/bridje-core/src/main/java/org/bridje/core/cli/CliSession.java @@ -1,32 +1,32 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.cli; - -import java.io.InputStream; -import java.io.PrintStream; - -/** - * - */ -public interface CliSession -{ - InputStream getIn(); - - PrintStream getOut(); - - PrintStream getErr(); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.cli; + +import java.io.InputStream; +import java.io.PrintStream; + +/** + * + */ +public interface CliSession +{ + InputStream getIn(); + + PrintStream getOut(); + + PrintStream getErr(); +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/cli/Command.java b/old/bridje-core/src/main/java/org/bridje/core/cli/Command.java index a10418fcd..5ebee563b 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/cli/Command.java +++ b/old/bridje-core/src/main/java/org/bridje/core/cli/Command.java @@ -1,32 +1,32 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.cli; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) -public @interface Command -{ - String value(); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.cli; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface Command +{ + String value(); +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/cli/CommandInfo.java b/old/bridje-core/src/main/java/org/bridje/core/cli/CommandInfo.java index 321d6aff2..7e2e1cdd8 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/cli/CommandInfo.java +++ b/old/bridje-core/src/main/java/org/bridje/core/cli/CommandInfo.java @@ -1,63 +1,63 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.cli; - -/** - * - */ -public class CommandInfo -{ - private final String name; - - private final String[] options; - - private final String[] arguments; - - public CommandInfo(String name, String[] options, String[] arguments) - { - this.name = name; - this.options = options; - this.arguments = arguments; - } - - public String getName() - { - return name; - } - - public String[] getOptions() - { - return options; - } - - public String[] getArguments() - { - return arguments; - } - - public boolean hasOption(String value) - { - for (String option : options) - { - if(option.equalsIgnoreCase(value)) - { - return true; - } - } - return false; - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.cli; + +/** + * + */ +public class CommandInfo +{ + private final String name; + + private final String[] options; + + private final String[] arguments; + + public CommandInfo(String name, String[] options, String[] arguments) + { + this.name = name; + this.options = options; + this.arguments = arguments; + } + + public String getName() + { + return name; + } + + public String[] getOptions() + { + return options; + } + + public String[] getArguments() + { + return arguments; + } + + public boolean hasOption(String value) + { + for (String option : options) + { + if(option.equalsIgnoreCase(value)) + { + return true; + } + } + return false; + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/cli/CommandParser.java b/old/bridje-core/src/main/java/org/bridje/core/cli/CommandParser.java index 2f7358bf6..972f802b0 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/cli/CommandParser.java +++ b/old/bridje-core/src/main/java/org/bridje/core/cli/CommandParser.java @@ -1,25 +1,25 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.cli; - -/** - * - */ -public interface CommandParser -{ - CommandInfo parse(String command, CliSession session) throws InvalidCliCommandException; -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.cli; + +/** + * + */ +public interface CommandParser +{ + CommandInfo parse(String command, CliSession session) throws InvalidCliCommandException; +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/cli/InvalidCliCommandException.java b/old/bridje-core/src/main/java/org/bridje/core/cli/InvalidCliCommandException.java index e40bdcff5..593817805 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/cli/InvalidCliCommandException.java +++ b/old/bridje-core/src/main/java/org/bridje/core/cli/InvalidCliCommandException.java @@ -1,36 +1,36 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.cli; - -/** - * - */ -public class InvalidCliCommandException extends Exception -{ - private final String command; - - public InvalidCliCommandException(String command) - { - super("The cli command " + command + " cannot be parsed."); - this.command = command; - } - - public String getCommand() - { - return command; - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.cli; + +/** + * + */ +public class InvalidCliCommandException extends Exception +{ + private final String command; + + public InvalidCliCommandException(String command) + { + super("The cli command " + command + " cannot be parsed."); + this.command = command; + } + + public String getCommand() + { + return command; + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/cli/NoCliParserException.java b/old/bridje-core/src/main/java/org/bridje/core/cli/NoCliParserException.java index e9c7a1cb4..236c7f145 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/cli/NoCliParserException.java +++ b/old/bridje-core/src/main/java/org/bridje/core/cli/NoCliParserException.java @@ -1,28 +1,28 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.cli; - -/** - * - */ -public class NoCliParserException extends Exception -{ - public NoCliParserException() - { - super("No command line parser is available."); - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.cli; + +/** + * + */ +public class NoCliParserException extends Exception +{ + public NoCliParserException() + { + super("No command line parser is available."); + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/cli/NoSuchCommandException.java b/old/bridje-core/src/main/java/org/bridje/core/cli/NoSuchCommandException.java index 6ba10e3a2..786b9b653 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/cli/NoSuchCommandException.java +++ b/old/bridje-core/src/main/java/org/bridje/core/cli/NoSuchCommandException.java @@ -1,36 +1,36 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.cli; - -/** - * - */ -public class NoSuchCommandException extends Exception -{ - private final String command; - - public NoSuchCommandException(String command) - { - super("The command " + command + " is not recognized."); - this.command = command; - } - - public String getCommand() - { - return command; - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.cli; + +/** + * + */ +public class NoSuchCommandException extends Exception +{ + private final String command; + + public NoSuchCommandException(String command) + { + super("The command " + command + " is not recognized."); + this.command = command; + } + + public String getCommand() + { + return command; + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/cli/Option.java b/old/bridje-core/src/main/java/org/bridje/core/cli/Option.java index bba397072..03c42055b 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/cli/Option.java +++ b/old/bridje-core/src/main/java/org/bridje/core/cli/Option.java @@ -1,32 +1,32 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.cli; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.PARAMETER) -public @interface Option -{ - String value(); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.cli; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.PARAMETER) +public @interface Option +{ + String value(); +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/cli/StdSystemSession.java b/old/bridje-core/src/main/java/org/bridje/core/cli/StdSystemSession.java index 309fa6372..72b50417c 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/cli/StdSystemSession.java +++ b/old/bridje-core/src/main/java/org/bridje/core/cli/StdSystemSession.java @@ -1,46 +1,46 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.cli; - -import java.io.InputStream; -import java.io.PrintStream; - -/** - * - */ -public class StdSystemSession implements CliSession -{ - - @Override - public InputStream getIn() - { - return System.in; - } - - @Override - public PrintStream getOut() - { - return System.out; - } - - @Override - public PrintStream getErr() - { - return System.err; - } - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.cli; + +import java.io.InputStream; +import java.io.PrintStream; + +/** + * + */ +public class StdSystemSession implements CliSession +{ + + @Override + public InputStream getIn() + { + return System.in; + } + + @Override + public PrintStream getOut() + { + return System.out; + } + + @Override + public PrintStream getErr() + { + return System.err; + } + +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/dbc/DataSourceConfig.java b/old/bridje-core/src/main/java/org/bridje/core/dbc/DataSourceConfig.java index 7b5470288..478ce0f5c 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/dbc/DataSourceConfig.java +++ b/old/bridje-core/src/main/java/org/bridje/core/dbc/DataSourceConfig.java @@ -1,227 +1,227 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.dbc; - -/** - * - */ -public class DataSourceConfig -{ - private String driver; - - private String host; - - private int port; - - private String user; - - private String pass; - - private boolean logAbandoned; - - private boolean removeAbandoned; - - private int removeAbandonedTimeout; - - private int maxActive; - - private long maxWait; - - private long minEvictableIdleTimeMillis; - - private int numTestsPerEvictionRun; - - private long timeBetweenEvictionRunsMillis; - - private boolean testOnBorrow; - - private boolean testOnReturn; - - private boolean testWhileIdle; - - private long softMinEvictableIdleTimeMillis; - - public String getDriver() - { - return driver; - } - - public void setDriver(String driver) - { - this.driver = driver; - } - - public String getHost() - { - return host; - } - - public void setHost(String host) - { - this.host = host; - } - - public int getPort() - { - return port; - } - - public void setPort(int port) - { - this.port = port; - } - - public String getUser() - { - return user; - } - - public void setUser(String user) - { - this.user = user; - } - - public String getPass() - { - return pass; - } - - public void setPass(String pass) - { - this.pass = pass; - } - - public boolean isLogAbandoned() - { - return logAbandoned; - } - - public void setLogAbandoned(boolean logAbandoned) - { - this.logAbandoned = logAbandoned; - } - - public boolean isRemoveAbandoned() - { - return removeAbandoned; - } - - public void setRemoveAbandoned(boolean removeAbandoned) - { - this.removeAbandoned = removeAbandoned; - } - - public int getRemoveAbandonedTimeout() - { - return removeAbandonedTimeout; - } - - public void setRemoveAbandonedTimeout(int removeAbandonedTimeout) - { - this.removeAbandonedTimeout = removeAbandonedTimeout; - } - - public int getMaxActive() - { - return maxActive; - } - - public void setMaxActive(int maxActive) - { - this.maxActive = maxActive; - } - - public long getMaxWait() - { - return maxWait; - } - - public void setMaxWait(long maxWait) - { - this.maxWait = maxWait; - } - - public long getMinEvictableIdleTimeMillis() - { - return minEvictableIdleTimeMillis; - } - - public void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis) - { - this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis; - } - - public int getNumTestsPerEvictionRun() - { - return numTestsPerEvictionRun; - } - - public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) - { - this.numTestsPerEvictionRun = numTestsPerEvictionRun; - } - - public long getTimeBetweenEvictionRunsMillis() - { - return timeBetweenEvictionRunsMillis; - } - - public void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis) - { - this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis; - } - - public boolean isTestOnBorrow() - { - return testOnBorrow; - } - - public void setTestOnBorrow(boolean testOnBorrow) - { - this.testOnBorrow = testOnBorrow; - } - - public boolean isTestOnReturn() - { - return testOnReturn; - } - - public void setTestOnReturn(boolean testOnReturn) - { - this.testOnReturn = testOnReturn; - } - - public boolean isTestWhileIdle() - { - return testWhileIdle; - } - - public void setTestWhileIdle(boolean testWhileIdle) - { - this.testWhileIdle = testWhileIdle; - } - - public long getSoftMinEvictableIdleTimeMillis() - { - return softMinEvictableIdleTimeMillis; - } - - public void setSoftMinEvictableIdleTimeMillis(long softMinEvictableIdleTimeMillis) - { - this.softMinEvictableIdleTimeMillis = softMinEvictableIdleTimeMillis; - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.dbc; + +/** + * + */ +public class DataSourceConfig +{ + private String driver; + + private String host; + + private int port; + + private String user; + + private String pass; + + private boolean logAbandoned; + + private boolean removeAbandoned; + + private int removeAbandonedTimeout; + + private int maxActive; + + private long maxWait; + + private long minEvictableIdleTimeMillis; + + private int numTestsPerEvictionRun; + + private long timeBetweenEvictionRunsMillis; + + private boolean testOnBorrow; + + private boolean testOnReturn; + + private boolean testWhileIdle; + + private long softMinEvictableIdleTimeMillis; + + public String getDriver() + { + return driver; + } + + public void setDriver(String driver) + { + this.driver = driver; + } + + public String getHost() + { + return host; + } + + public void setHost(String host) + { + this.host = host; + } + + public int getPort() + { + return port; + } + + public void setPort(int port) + { + this.port = port; + } + + public String getUser() + { + return user; + } + + public void setUser(String user) + { + this.user = user; + } + + public String getPass() + { + return pass; + } + + public void setPass(String pass) + { + this.pass = pass; + } + + public boolean isLogAbandoned() + { + return logAbandoned; + } + + public void setLogAbandoned(boolean logAbandoned) + { + this.logAbandoned = logAbandoned; + } + + public boolean isRemoveAbandoned() + { + return removeAbandoned; + } + + public void setRemoveAbandoned(boolean removeAbandoned) + { + this.removeAbandoned = removeAbandoned; + } + + public int getRemoveAbandonedTimeout() + { + return removeAbandonedTimeout; + } + + public void setRemoveAbandonedTimeout(int removeAbandonedTimeout) + { + this.removeAbandonedTimeout = removeAbandonedTimeout; + } + + public int getMaxActive() + { + return maxActive; + } + + public void setMaxActive(int maxActive) + { + this.maxActive = maxActive; + } + + public long getMaxWait() + { + return maxWait; + } + + public void setMaxWait(long maxWait) + { + this.maxWait = maxWait; + } + + public long getMinEvictableIdleTimeMillis() + { + return minEvictableIdleTimeMillis; + } + + public void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis) + { + this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis; + } + + public int getNumTestsPerEvictionRun() + { + return numTestsPerEvictionRun; + } + + public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) + { + this.numTestsPerEvictionRun = numTestsPerEvictionRun; + } + + public long getTimeBetweenEvictionRunsMillis() + { + return timeBetweenEvictionRunsMillis; + } + + public void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis) + { + this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis; + } + + public boolean isTestOnBorrow() + { + return testOnBorrow; + } + + public void setTestOnBorrow(boolean testOnBorrow) + { + this.testOnBorrow = testOnBorrow; + } + + public boolean isTestOnReturn() + { + return testOnReturn; + } + + public void setTestOnReturn(boolean testOnReturn) + { + this.testOnReturn = testOnReturn; + } + + public boolean isTestWhileIdle() + { + return testWhileIdle; + } + + public void setTestWhileIdle(boolean testWhileIdle) + { + this.testWhileIdle = testWhileIdle; + } + + public long getSoftMinEvictableIdleTimeMillis() + { + return softMinEvictableIdleTimeMillis; + } + + public void setSoftMinEvictableIdleTimeMillis(long softMinEvictableIdleTimeMillis) + { + this.softMinEvictableIdleTimeMillis = softMinEvictableIdleTimeMillis; + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/dbc/DbcConfigProvider.java b/old/bridje-core/src/main/java/org/bridje/core/dbc/DbcConfigProvider.java index 8aa082bd7..ec1100491 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/dbc/DbcConfigProvider.java +++ b/old/bridje-core/src/main/java/org/bridje/core/dbc/DbcConfigProvider.java @@ -1,25 +1,25 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.dbc; - -/** - * - */ -public interface DbcConfigProvider -{ - DataSourceConfig findDataSourceConfig(String dsName); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.dbc; + +/** + * + */ +public interface DbcConfigProvider +{ + DataSourceConfig findDataSourceConfig(String dsName); +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/dbc/DbcDataSourceFactory.java b/old/bridje-core/src/main/java/org/bridje/core/dbc/DbcDataSourceFactory.java index c0e576053..67f2c05e7 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/dbc/DbcDataSourceFactory.java +++ b/old/bridje-core/src/main/java/org/bridje/core/dbc/DbcDataSourceFactory.java @@ -1,27 +1,27 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.dbc; - -import javax.sql.DataSource; - -/** - * - */ -public interface DbcDataSourceFactory -{ - DataSource createDataSource(DataSourceConfig config); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.dbc; + +import javax.sql.DataSource; + +/** + * + */ +public interface DbcDataSourceFactory +{ + DataSource createDataSource(DataSourceConfig config); +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/dbc/DbcService.java b/old/bridje-core/src/main/java/org/bridje/core/dbc/DbcService.java index 727eef962..66148cc90 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/dbc/DbcService.java +++ b/old/bridje-core/src/main/java/org/bridje/core/dbc/DbcService.java @@ -1,31 +1,31 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.dbc; - -import javax.sql.DataSource; - -/** - * - */ -public interface DbcService -{ - DataSource getDataSource(String dsName); - - DataSourceConfig findDataSourceConfig(String dsName); - - DataSource createDataSource(DataSourceConfig config); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.dbc; + +import javax.sql.DataSource; + +/** + * + */ +public interface DbcService +{ + DataSource getDataSource(String dsName); + + DataSourceConfig findDataSourceConfig(String dsName); + + DataSource createDataSource(DataSourceConfig config); +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/http/HttpServer.java b/old/bridje-core/src/main/java/org/bridje/core/http/HttpServer.java index 68f0a2dd0..6d48b35c2 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/http/HttpServer.java +++ b/old/bridje-core/src/main/java/org/bridje/core/http/HttpServer.java @@ -1,35 +1,35 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.http; - -/** - * - */ -public interface HttpServer -{ - /** - * - * @throws HttpServerException - */ - public void start() throws HttpServerException; - - /** - * - * @throws HttpServerException - */ - public void stop() throws HttpServerException; -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.http; + +/** + * + */ +public interface HttpServer +{ + /** + * + * @throws HttpServerException + */ + public void start() throws HttpServerException; + + /** + * + * @throws HttpServerException + */ + public void stop() throws HttpServerException; +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/http/HttpServerException.java b/old/bridje-core/src/main/java/org/bridje/core/http/HttpServerException.java index 720813139..be56efb2d 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/http/HttpServerException.java +++ b/old/bridje-core/src/main/java/org/bridje/core/http/HttpServerException.java @@ -1,39 +1,39 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.http; - -public class HttpServerException extends Exception -{ - public HttpServerException() - { - } - - public HttpServerException(String message) - { - super(message); - } - - public HttpServerException(String message, Throwable cause) - { - super(message, cause); - } - - public HttpServerException(Throwable cause) - { - super(cause); - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.http; + +public class HttpServerException extends Exception +{ + public HttpServerException() + { + } + + public HttpServerException(String message) + { + super(message); + } + + public HttpServerException(String message, Throwable cause) + { + super(message, cause); + } + + public HttpServerException(Throwable cause) + { + super(cause); + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/impl/cast/CastServiceImpl.java b/old/bridje-core/src/main/java/org/bridje/core/impl/cast/CastServiceImpl.java index e7d675a88..1d2c01b70 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/impl/cast/CastServiceImpl.java +++ b/old/bridje-core/src/main/java/org/bridje/core/impl/cast/CastServiceImpl.java @@ -1,112 +1,112 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.impl.cast; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import javax.annotation.PostConstruct; -import org.bridje.core.cast.CastProvider; -import org.bridje.core.cast.CastService; -import org.bridje.ioc.Component; -import org.bridje.ioc.Inject; - -/** - * - */ -@Component -class CastServiceImpl implements CastService -{ - private Map,List>> destClsProvidersMap; - - @Inject - private CastProvider[] providers; - - @PostConstruct - public void init() - { - destClsProvidersMap = new HashMap<>(); - for (CastProvider provider : providers) - { - Class toClass = provider.getDestClass(); - List> lst = destClsProvidersMap.get(toClass); - if(lst == null) - { - lst = new ArrayList<>(); - destClsProvidersMap.put(toClass, lst); - } - lst.add(provider); - } - } - - @Override - public T cast(Object object, Class cls) - { - if(object == null) - { - return null; - } - if(cls.isAssignableFrom(object.getClass())) - { - return (T)object; - } - List> providerLst = findProvidersByDestClass(cls); - if(providerLst == null || providerLst.isEmpty()) - { - return null; - } - CastProvider provider = findProviderBySrcClass(object.getClass(), providerLst); - if(provider != null) - { - return provider.cast(object); - } - return null; - } - - private List> findProvidersByDestClass(Class destClass) - { - List> lst = destClsProvidersMap.get(destClass); - if(lst == null) - { - return null; - } - List> result = new ArrayList<>(lst.size()); - for (CastProvider cp : lst) - { - result.add((CastProvider)cp); - } - return result; - } - - private CastProvider findProviderBySrcClass(Class srcClass, List> providerLst) - { - for (CastProvider provider : providerLst) - { - Class[] srcClss = provider.getSrcClasses(); - for (Class srcCls : srcClss) - { - if(srcCls.equals(srcClass)) - { - return provider; - } - } - } - return null; - } - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.impl.cast; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.annotation.PostConstruct; +import org.bridje.core.cast.CastProvider; +import org.bridje.core.cast.CastService; +import org.bridje.ioc.Component; +import org.bridje.ioc.Inject; + +/** + * + */ +@Component +class CastServiceImpl implements CastService +{ + private Map,List>> destClsProvidersMap; + + @Inject + private CastProvider[] providers; + + @PostConstruct + public void init() + { + destClsProvidersMap = new HashMap<>(); + for (CastProvider provider : providers) + { + Class toClass = provider.getDestClass(); + List> lst = destClsProvidersMap.get(toClass); + if(lst == null) + { + lst = new ArrayList<>(); + destClsProvidersMap.put(toClass, lst); + } + lst.add(provider); + } + } + + @Override + public T cast(Object object, Class cls) + { + if(object == null) + { + return null; + } + if(cls.isAssignableFrom(object.getClass())) + { + return (T)object; + } + List> providerLst = findProvidersByDestClass(cls); + if(providerLst == null || providerLst.isEmpty()) + { + return null; + } + CastProvider provider = findProviderBySrcClass(object.getClass(), providerLst); + if(provider != null) + { + return provider.cast(object); + } + return null; + } + + private List> findProvidersByDestClass(Class destClass) + { + List> lst = destClsProvidersMap.get(destClass); + if(lst == null) + { + return null; + } + List> result = new ArrayList<>(lst.size()); + for (CastProvider cp : lst) + { + result.add((CastProvider)cp); + } + return result; + } + + private CastProvider findProviderBySrcClass(Class srcClass, List> providerLst) + { + for (CastProvider provider : providerLst) + { + Class[] srcClss = provider.getSrcClasses(); + for (Class srcCls : srcClss) + { + if(srcCls.equals(srcClass)) + { + return provider; + } + } + } + return null; + } + +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/impl/cli/CliServiceImpl.java b/old/bridje-core/src/main/java/org/bridje/core/impl/cli/CliServiceImpl.java index b655d9ff6..505d1f439 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/impl/cli/CliServiceImpl.java +++ b/old/bridje-core/src/main/java/org/bridje/core/impl/cli/CliServiceImpl.java @@ -1,142 +1,142 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.impl.cli; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Parameter; -import java.util.Arrays; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.annotation.PostConstruct; -import org.bridje.core.cli.Argument; -import org.bridje.core.cli.CliService; -import org.bridje.core.cli.CliSession; -import org.bridje.core.cli.Command; -import org.bridje.core.cli.CommandInfo; -import org.bridje.core.cli.CommandParser; -import org.bridje.core.cli.Option; -import org.bridje.core.cli.StdSystemSession; -import org.bridje.core.cli.InvalidCliCommandException; -import org.bridje.core.cli.NoCliParserException; -import org.bridje.core.cli.NoSuchCommandException; -import org.bridje.ioc.Ioc; -import org.bridje.ioc.IocContext; -import org.bridje.ioc.Component; -import org.bridje.ioc.Inject; - -/** - * - */ -@Component -class CliServiceImpl implements CliService -{ - private static final Logger LOG = Logger.getLogger(CliServiceImpl.class.getName()); - - @Inject - private CommandParser parser; - - @Inject - private IocContext context; - - private Map commands; - - @PostConstruct - public void init() - { - commands = new HashMap<>(); - context.getClassRepository() - .navigateAnnotMethods(Command.class, - (Method method, Class component, Command annotation) -> - { - Object componentObj = Ioc.context().find(component); - CommandMethodInfo inf = new CommandMethodInfo(annotation.value(), method, componentObj); - commands.put(annotation.value(), inf); - }); - } - - @Override - public void execute(String command, CliSession session) throws NoCliParserException, InvalidCliCommandException, NoSuchCommandException - { - if(session == null) - { - session = new StdSystemSession(); - } - if(parser == null) - { - throw new NoCliParserException(); - } - CommandInfo cmd = parser.parse(command, session); - CommandMethodInfo inf = commands == null ? null : commands.get(cmd.getName()); - if(inf != null) - { - Method method = inf.getMethod(); - Object[] parameters = findParameters(method, cmd, session); - try - { - method.invoke(inf.getComponent(), parameters); - } - catch(IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) - { - LOG.log(Level.SEVERE, ex.getMessage(), ex); - } - } - else - { - throw new NoSuchCommandException(cmd.getName()); - } - } - - private Object[] findParameters(Method method, CommandInfo cmd, CliSession session) - { - Object[] result = new Object[method.getParameterCount()]; - Parameter[] parameters = method.getParameters(); - List argumentsValues = new LinkedList<>(Arrays.asList(cmd.getArguments())); - for (int i = 0; i < parameters.length; i++) - { - Parameter parameter = parameters[i]; - result[i] = findParameter(parameter, cmd, argumentsValues, session); - } - return result; - } - - private Object findParameter(Parameter parameter, CommandInfo cmd, List argumentsValues, CliSession session) - { - if(parameter.getType() == CliSession.class) - { - return session; - } - Option option = parameter.getAnnotation(Option.class); - Argument argument = parameter.getAnnotation(Argument.class); - if(option != null) - { - return cmd.hasOption(option.value()); - } - else if(argument != null && argumentsValues.size() > 0) - { - String arg = argumentsValues.get(0); - argumentsValues.remove(0); - return arg; - } - return null; - } - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.impl.cli; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; +import java.util.Arrays; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.annotation.PostConstruct; +import org.bridje.core.cli.Argument; +import org.bridje.core.cli.CliService; +import org.bridje.core.cli.CliSession; +import org.bridje.core.cli.Command; +import org.bridje.core.cli.CommandInfo; +import org.bridje.core.cli.CommandParser; +import org.bridje.core.cli.Option; +import org.bridje.core.cli.StdSystemSession; +import org.bridje.core.cli.InvalidCliCommandException; +import org.bridje.core.cli.NoCliParserException; +import org.bridje.core.cli.NoSuchCommandException; +import org.bridje.ioc.Ioc; +import org.bridje.ioc.IocContext; +import org.bridje.ioc.Component; +import org.bridje.ioc.Inject; + +/** + * + */ +@Component +class CliServiceImpl implements CliService +{ + private static final Logger LOG = Logger.getLogger(CliServiceImpl.class.getName()); + + @Inject + private CommandParser parser; + + @Inject + private IocContext context; + + private Map commands; + + @PostConstruct + public void init() + { + commands = new HashMap<>(); + context.getClassRepository() + .navigateAnnotMethods(Command.class, + (Method method, Class component, Command annotation) -> + { + Object componentObj = Ioc.context().find(component); + CommandMethodInfo inf = new CommandMethodInfo(annotation.value(), method, componentObj); + commands.put(annotation.value(), inf); + }); + } + + @Override + public void execute(String command, CliSession session) throws NoCliParserException, InvalidCliCommandException, NoSuchCommandException + { + if(session == null) + { + session = new StdSystemSession(); + } + if(parser == null) + { + throw new NoCliParserException(); + } + CommandInfo cmd = parser.parse(command, session); + CommandMethodInfo inf = commands == null ? null : commands.get(cmd.getName()); + if(inf != null) + { + Method method = inf.getMethod(); + Object[] parameters = findParameters(method, cmd, session); + try + { + method.invoke(inf.getComponent(), parameters); + } + catch(IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) + { + LOG.log(Level.SEVERE, ex.getMessage(), ex); + } + } + else + { + throw new NoSuchCommandException(cmd.getName()); + } + } + + private Object[] findParameters(Method method, CommandInfo cmd, CliSession session) + { + Object[] result = new Object[method.getParameterCount()]; + Parameter[] parameters = method.getParameters(); + List argumentsValues = new LinkedList<>(Arrays.asList(cmd.getArguments())); + for (int i = 0; i < parameters.length; i++) + { + Parameter parameter = parameters[i]; + result[i] = findParameter(parameter, cmd, argumentsValues, session); + } + return result; + } + + private Object findParameter(Parameter parameter, CommandInfo cmd, List argumentsValues, CliSession session) + { + if(parameter.getType() == CliSession.class) + { + return session; + } + Option option = parameter.getAnnotation(Option.class); + Argument argument = parameter.getAnnotation(Argument.class); + if(option != null) + { + return cmd.hasOption(option.value()); + } + else if(argument != null && argumentsValues.size() > 0) + { + String arg = argumentsValues.get(0); + argumentsValues.remove(0); + return arg; + } + return null; + } + +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/impl/cli/CommandMethodInfo.java b/old/bridje-core/src/main/java/org/bridje/core/impl/cli/CommandMethodInfo.java index 105267137..1daa1169b 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/impl/cli/CommandMethodInfo.java +++ b/old/bridje-core/src/main/java/org/bridje/core/impl/cli/CommandMethodInfo.java @@ -1,53 +1,53 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.impl.cli; - -import java.lang.reflect.Method; - -/** - * - */ -class CommandMethodInfo -{ - private final String name; - - private final Method method; - - private final Object component; - - public CommandMethodInfo(String name, Method method, Object component) - { - this.name = name; - this.method = method; - this.component = component; - } - - public String getName() - { - return name; - } - - public Method getMethod() - { - return method; - } - - public Object getComponent() - { - return component; - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.impl.cli; + +import java.lang.reflect.Method; + +/** + * + */ +class CommandMethodInfo +{ + private final String name; + + private final Method method; + + private final Object component; + + public CommandMethodInfo(String name, Method method, Object component) + { + this.name = name; + this.method = method; + this.component = component; + } + + public String getName() + { + return name; + } + + public Method getMethod() + { + return method; + } + + public Object getComponent() + { + return component; + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/impl/dbc/DbcServiceImpl.java b/old/bridje-core/src/main/java/org/bridje/core/impl/dbc/DbcServiceImpl.java index ca7ed0459..ac882fe9c 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/impl/dbc/DbcServiceImpl.java +++ b/old/bridje-core/src/main/java/org/bridje/core/impl/dbc/DbcServiceImpl.java @@ -1,82 +1,82 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.impl.dbc; - -import java.util.HashMap; -import java.util.Map; -import javax.sql.DataSource; -import org.bridje.core.dbc.DataSourceConfig; -import org.bridje.core.dbc.DbcConfigProvider; -import org.bridje.core.dbc.DbcDataSourceFactory; -import org.bridje.core.dbc.DbcService; -import org.bridje.ioc.Component; -import org.bridje.ioc.Inject; - -/** - * - */ -@Component -class DbcServiceImpl implements DbcService -{ - @Inject - private DbcConfigProvider configProv; - - @Inject - private DbcDataSourceFactory fact; - - private Map dataSourcesMap; - - @Override - public DataSource getDataSource(String dsName) - { - DataSource ds = getDataSourcesMap().get(dsName); - if(ds == null) - { - DataSourceConfig dsCfg = findDataSourceConfig(dsName); - if(dsCfg != null) - { - ds = createDataSource(dsCfg); - if(ds != null) - { - dataSourcesMap.put(dsName, ds); - } - } - } - return ds; - } - - @Override - public DataSourceConfig findDataSourceConfig(String dsName) - { - return configProv.findDataSourceConfig(dsName); - } - - @Override - public DataSource createDataSource(DataSourceConfig config) - { - return fact.createDataSource(config); - } - - public Map getDataSourcesMap() - { - if(dataSourcesMap == null) - { - dataSourcesMap = new HashMap<>(); - } - return dataSourcesMap; - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.impl.dbc; + +import java.util.HashMap; +import java.util.Map; +import javax.sql.DataSource; +import org.bridje.core.dbc.DataSourceConfig; +import org.bridje.core.dbc.DbcConfigProvider; +import org.bridje.core.dbc.DbcDataSourceFactory; +import org.bridje.core.dbc.DbcService; +import org.bridje.ioc.Component; +import org.bridje.ioc.Inject; + +/** + * + */ +@Component +class DbcServiceImpl implements DbcService +{ + @Inject + private DbcConfigProvider configProv; + + @Inject + private DbcDataSourceFactory fact; + + private Map dataSourcesMap; + + @Override + public DataSource getDataSource(String dsName) + { + DataSource ds = getDataSourcesMap().get(dsName); + if(ds == null) + { + DataSourceConfig dsCfg = findDataSourceConfig(dsName); + if(dsCfg != null) + { + ds = createDataSource(dsCfg); + if(ds != null) + { + dataSourcesMap.put(dsName, ds); + } + } + } + return ds; + } + + @Override + public DataSourceConfig findDataSourceConfig(String dsName) + { + return configProv.findDataSourceConfig(dsName); + } + + @Override + public DataSource createDataSource(DataSourceConfig config) + { + return fact.createDataSource(config); + } + + public Map getDataSourcesMap() + { + if(dataSourcesMap == null) + { + dataSourcesMap = new HashMap<>(); + } + return dataSourcesMap; + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/impl/dbc/fact/DataSourceImpl.java b/old/bridje-core/src/main/java/org/bridje/core/impl/dbc/fact/DataSourceImpl.java index 584a7203d..3eff6714d 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/impl/dbc/fact/DataSourceImpl.java +++ b/old/bridje-core/src/main/java/org/bridje/core/impl/dbc/fact/DataSourceImpl.java @@ -1,170 +1,170 @@ - -package org.bridje.core.impl.dbc.fact; - -import java.io.PrintWriter; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; -import java.sql.SQLFeatureNotSupportedException; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.sql.DataSource; -import org.apache.commons.dbcp.AbandonedConfig; -import org.apache.commons.dbcp.AbandonedObjectPool; -import org.apache.commons.dbcp.ConnectionFactory; -import org.apache.commons.dbcp.PoolableConnectionFactory; -import org.apache.commons.dbcp.PoolingDataSource; -import org.apache.commons.pool.KeyedObjectPoolFactory; -import org.apache.commons.pool.impl.GenericKeyedObjectPoolFactory; -import org.bridje.core.dbc.DataSourceConfig; - -public class DataSourceImpl implements DataSource, ConnectionFactory -{ - private static final Logger LOG = Logger.getLogger(DataSourceImpl.class.getName()); - - private final DataSource ds; - - private final DataSourceConfig config; - - private AbandonedObjectPool connectionPool; - - public DataSourceImpl(DataSourceConfig config) - { - this.config = config; - ds = createDataSource(); - } - - @Override - public Connection getConnection() throws SQLException - { - Connection cn = ds.getConnection(); - try - { - cn.setAutoCommit(true); - cn.setReadOnly(false); - } catch (Exception e) - { - LOG.log(Level.SEVERE, e.getMessage(), e); - } - return cn; - } - - @Override - public Connection getConnection(String username, String password) throws SQLException - { - Connection cn = ds.getConnection(username, password); - try - { - cn.setAutoCommit(true); - cn.setReadOnly(false); - } - catch (Exception e) - { - LOG.log(Level.SEVERE, e.getMessage(), e); - } - return cn; - } - - @Override - public PrintWriter getLogWriter() throws SQLException - { - return ds.getLogWriter(); - } - - @Override - public void setLogWriter(PrintWriter out) throws SQLException - { - ds.setLogWriter(out); - } - - @Override - public void setLoginTimeout(int seconds) throws SQLException - { - ds.setLoginTimeout(seconds); - } - - @Override - public int getLoginTimeout() throws SQLException - { - return ds.getLoginTimeout(); - } - - @Override - public java.util.logging.Logger getParentLogger() throws SQLFeatureNotSupportedException - { - if (ds == null) - { - throw new SQLFeatureNotSupportedException(); - } - return ds.getParentLogger(); - } - - @Override - public T unwrap(Class iface) throws SQLException - { - return ds.unwrap(iface); - } - - @Override - public boolean isWrapperFor(Class iface) throws SQLException - { - return ds.isWrapperFor(iface); - } - - @Override - public Connection createConnection() throws SQLException - { - return DriverManager.getConnection(config.getHost(), config.getUser(), config.getPass()); - } - - public Connection createRawConnection() throws SQLException - { - return DriverManager.getConnection(config.getHost(), config.getUser(), config.getPass()); - } - - private DataSource createDataSource() - { - AbandonedConfig abandonedConfig = new AbandonedConfig(); - abandonedConfig.setLogAbandoned(config.isLogAbandoned()); - abandonedConfig.setRemoveAbandoned(config.isRemoveAbandoned()); - abandonedConfig.setRemoveAbandonedTimeout(config.getRemoveAbandonedTimeout()); - - connectionPool = new AbandonedObjectPool(null, abandonedConfig); - - // Numero max de conexiones del pool (default 8) - connectionPool.setMaxActive(config.getMaxActive()); - // Tiempo max de espera para obtener una conexion (default ilimitado) - connectionPool.setMaxWait(config.getMaxWait()); - // Tiempo min antes de eliminar una conexion inactiva - connectionPool.setMinEvictableIdleTimeMillis(config.getMinEvictableIdleTimeMillis()); - // No de pruebas para eliminar conexiones por corridas - connectionPool.setNumTestsPerEvictionRun(config.getNumTestsPerEvictionRun()); - // Tiempo entre corridas - connectionPool.setTimeBetweenEvictionRunsMillis(config.getTimeBetweenEvictionRunsMillis()); - // Probar al obtener una conexion - connectionPool.setTestOnBorrow(config.isTestOnBorrow()); - // Probar al devolver una conexion - connectionPool.setTestOnReturn(config.isTestOnReturn()); - // Probar durante que una conexion este inactiva - connectionPool.setTestWhileIdle(config.isTestWhileIdle()); - // Tiempo min antes de eliminar una conexion inactiva - connectionPool.setSoftMinEvictableIdleTimeMillis(config.getSoftMinEvictableIdleTimeMillis()); - - KeyedObjectPoolFactory keyedObjectPoolFactory = new GenericKeyedObjectPoolFactory(null); - - PoolableConnectionFactory poolableConnectionFactory - = new PoolableConnectionFactory(this, connectionPool, - keyedObjectPoolFactory, null, false, true, abandonedConfig); - - connectionPool.setFactory(poolableConnectionFactory); - - PoolingDataSource dataSource = new PoolingDataSource(connectionPool); - - return dataSource; - } - - public DataSourceConfig getConfig() - { - return config; - } -} + +package org.bridje.core.impl.dbc.fact; + +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.sql.SQLFeatureNotSupportedException; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.sql.DataSource; +import org.apache.commons.dbcp.AbandonedConfig; +import org.apache.commons.dbcp.AbandonedObjectPool; +import org.apache.commons.dbcp.ConnectionFactory; +import org.apache.commons.dbcp.PoolableConnectionFactory; +import org.apache.commons.dbcp.PoolingDataSource; +import org.apache.commons.pool.KeyedObjectPoolFactory; +import org.apache.commons.pool.impl.GenericKeyedObjectPoolFactory; +import org.bridje.core.dbc.DataSourceConfig; + +public class DataSourceImpl implements DataSource, ConnectionFactory +{ + private static final Logger LOG = Logger.getLogger(DataSourceImpl.class.getName()); + + private final DataSource ds; + + private final DataSourceConfig config; + + private AbandonedObjectPool connectionPool; + + public DataSourceImpl(DataSourceConfig config) + { + this.config = config; + ds = createDataSource(); + } + + @Override + public Connection getConnection() throws SQLException + { + Connection cn = ds.getConnection(); + try + { + cn.setAutoCommit(true); + cn.setReadOnly(false); + } catch (Exception e) + { + LOG.log(Level.SEVERE, e.getMessage(), e); + } + return cn; + } + + @Override + public Connection getConnection(String username, String password) throws SQLException + { + Connection cn = ds.getConnection(username, password); + try + { + cn.setAutoCommit(true); + cn.setReadOnly(false); + } + catch (Exception e) + { + LOG.log(Level.SEVERE, e.getMessage(), e); + } + return cn; + } + + @Override + public PrintWriter getLogWriter() throws SQLException + { + return ds.getLogWriter(); + } + + @Override + public void setLogWriter(PrintWriter out) throws SQLException + { + ds.setLogWriter(out); + } + + @Override + public void setLoginTimeout(int seconds) throws SQLException + { + ds.setLoginTimeout(seconds); + } + + @Override + public int getLoginTimeout() throws SQLException + { + return ds.getLoginTimeout(); + } + + @Override + public java.util.logging.Logger getParentLogger() throws SQLFeatureNotSupportedException + { + if (ds == null) + { + throw new SQLFeatureNotSupportedException(); + } + return ds.getParentLogger(); + } + + @Override + public T unwrap(Class iface) throws SQLException + { + return ds.unwrap(iface); + } + + @Override + public boolean isWrapperFor(Class iface) throws SQLException + { + return ds.isWrapperFor(iface); + } + + @Override + public Connection createConnection() throws SQLException + { + return DriverManager.getConnection(config.getHost(), config.getUser(), config.getPass()); + } + + public Connection createRawConnection() throws SQLException + { + return DriverManager.getConnection(config.getHost(), config.getUser(), config.getPass()); + } + + private DataSource createDataSource() + { + AbandonedConfig abandonedConfig = new AbandonedConfig(); + abandonedConfig.setLogAbandoned(config.isLogAbandoned()); + abandonedConfig.setRemoveAbandoned(config.isRemoveAbandoned()); + abandonedConfig.setRemoveAbandonedTimeout(config.getRemoveAbandonedTimeout()); + + connectionPool = new AbandonedObjectPool(null, abandonedConfig); + + // Numero max de conexiones del pool (default 8) + connectionPool.setMaxActive(config.getMaxActive()); + // Tiempo max de espera para obtener una conexion (default ilimitado) + connectionPool.setMaxWait(config.getMaxWait()); + // Tiempo min antes de eliminar una conexion inactiva + connectionPool.setMinEvictableIdleTimeMillis(config.getMinEvictableIdleTimeMillis()); + // No de pruebas para eliminar conexiones por corridas + connectionPool.setNumTestsPerEvictionRun(config.getNumTestsPerEvictionRun()); + // Tiempo entre corridas + connectionPool.setTimeBetweenEvictionRunsMillis(config.getTimeBetweenEvictionRunsMillis()); + // Probar al obtener una conexion + connectionPool.setTestOnBorrow(config.isTestOnBorrow()); + // Probar al devolver una conexion + connectionPool.setTestOnReturn(config.isTestOnReturn()); + // Probar durante que una conexion este inactiva + connectionPool.setTestWhileIdle(config.isTestWhileIdle()); + // Tiempo min antes de eliminar una conexion inactiva + connectionPool.setSoftMinEvictableIdleTimeMillis(config.getSoftMinEvictableIdleTimeMillis()); + + KeyedObjectPoolFactory keyedObjectPoolFactory = new GenericKeyedObjectPoolFactory(null); + + PoolableConnectionFactory poolableConnectionFactory + = new PoolableConnectionFactory(this, connectionPool, + keyedObjectPoolFactory, null, false, true, abandonedConfig); + + connectionPool.setFactory(poolableConnectionFactory); + + PoolingDataSource dataSource = new PoolingDataSource(connectionPool); + + return dataSource; + } + + public DataSourceConfig getConfig() + { + return config; + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/impl/dbc/fact/DbcDataSourceFactoryImpl.java b/old/bridje-core/src/main/java/org/bridje/core/impl/dbc/fact/DbcDataSourceFactoryImpl.java index 728cf459f..bc78a99e5 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/impl/dbc/fact/DbcDataSourceFactoryImpl.java +++ b/old/bridje-core/src/main/java/org/bridje/core/impl/dbc/fact/DbcDataSourceFactoryImpl.java @@ -1,32 +1,32 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.impl.dbc.fact; - -import javax.sql.DataSource; -import org.bridje.core.dbc.DataSourceConfig; -import org.bridje.core.dbc.DbcDataSourceFactory; -import org.bridje.ioc.Component; - -@Component -public class DbcDataSourceFactoryImpl implements DbcDataSourceFactory -{ - @Override - public DataSource createDataSource(DataSourceConfig config) - { - return new DataSourceImpl(config); - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.impl.dbc.fact; + +import javax.sql.DataSource; +import org.bridje.core.dbc.DataSourceConfig; +import org.bridje.core.dbc.DbcDataSourceFactory; +import org.bridje.ioc.Component; + +@Component +public class DbcDataSourceFactoryImpl implements DbcDataSourceFactory +{ + @Override + public DataSource createDataSource(DataSourceConfig config) + { + return new DataSourceImpl(config); + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/impl/http/jetty/HttpConfig.java b/old/bridje-core/src/main/java/org/bridje/core/impl/http/jetty/HttpConfig.java index 6e0a42a99..b0399d837 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/impl/http/jetty/HttpConfig.java +++ b/old/bridje-core/src/main/java/org/bridje/core/impl/http/jetty/HttpConfig.java @@ -1,136 +1,136 @@ - -package org.bridje.core.impl.http.jetty; - -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlElementWrapper; -import javax.xml.bind.annotation.XmlElements; -import javax.xml.bind.annotation.XmlRootElement; - -@XmlRootElement(name = "http") -public class HttpConfig -{ - private List connectorConfigs; - - private List servletConfigs; - - private Integer sessionExp; - - @XmlElementWrapper(name = "connectors") - @XmlElements( - { - @XmlElement(name = "connector", type = HttpConnectorConfig.class) - }) - public List getConnectorConfigs() - { - if(connectorConfigs == null) - { - connectorConfigs = new ArrayList<>(); - } - - if (connectorConfigs.isEmpty()) - { - HttpConnectorConfig connectorConfig = new HttpConnectorConfig(); - connectorConfig.setPort(8080); - connectorConfig.setProtocol("http"); - connectorConfigs.add(connectorConfig); - } - - return connectorConfigs; - } - - /** - * Establece el listado de conectores http - * - * @param connectorConfigs Listado de {@link HttpConnectorConfig} o - * null - */ - public void setConnectorConfigs(List connectorConfigs) - { - this.connectorConfigs = connectorConfigs; - } - - /** - * Devuelve las configuraciones de - * {@link javax.servlet.annotation.WebServlet} que se desean sobreescribir - * - * @return Configuraciones a sobreescribir, no null - */ - @XmlElementWrapper(name = "servlets") - @XmlElements( - { - @XmlElement(name = "servlet", type = WebServletConfig.class) - }) - public List getServletConfigs() - { - if (servletConfigs == null) - { - servletConfigs = new LinkedList<>(); - } - return servletConfigs; - } - - /** - * Establece las configuraciones de - * {@link javax.servlet.annotation.WebServlet} que se desean sobreescribir - * en los servlets - * - * @param servletConfigs Listado de {@link WebServletConfig} con las - * configuraciones de {@link javax.servlet.annotation.WebServlet} deseadas - */ - public void setServletConfigs(List servletConfigs) - { - this.servletConfigs = servletConfigs; - } - - /** - * Deuelve la cantidad de segundos limite que puede durar la sesion antes de - * expirar - * - * @return cantidad de segundos o null - */ - @XmlElement(name = "sessionExp") - public Integer getSessionExp() - { - if(sessionExp == null) - { - sessionExp = 30; - } - return sessionExp; - } - - /** - * Establece la cantidad de segundos limite que podra durar la sesionn antes - * de expirar - * - * @param sessionExp cantidad de segundos - */ - public void setSessionExp(Integer sessionExp) - { - this.sessionExp = sessionExp; - } - - /** - * Busca una configuracion que sobreescribe la del - * {@link javax.servlet.annotation.WebServlet} en un servlet - * - * @param name Propiedad especificada en el - * {@link javax.servlet.annotation.WebServlet#name} por la cual se buscara - * el servlet - * @return Devuelve la configuracion {@link WebServletConfig} encontrada, o - * null - */ - public WebServletConfig findWebServletByName(String name) - { - for (WebServletConfig webServletConfig : getServletConfigs()) - { - if (name.equals(webServletConfig.getName())) - { - return webServletConfig; - } - } - return null; - } -} + +package org.bridje.core.impl.http.jetty; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; +import javax.xml.bind.annotation.XmlElements; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name = "http") +public class HttpConfig +{ + private List connectorConfigs; + + private List servletConfigs; + + private Integer sessionExp; + + @XmlElementWrapper(name = "connectors") + @XmlElements( + { + @XmlElement(name = "connector", type = HttpConnectorConfig.class) + }) + public List getConnectorConfigs() + { + if(connectorConfigs == null) + { + connectorConfigs = new ArrayList<>(); + } + + if (connectorConfigs.isEmpty()) + { + HttpConnectorConfig connectorConfig = new HttpConnectorConfig(); + connectorConfig.setPort(8080); + connectorConfig.setProtocol("http"); + connectorConfigs.add(connectorConfig); + } + + return connectorConfigs; + } + + /** + * Establece el listado de conectores http + * + * @param connectorConfigs Listado de {@link HttpConnectorConfig} o + * null + */ + public void setConnectorConfigs(List connectorConfigs) + { + this.connectorConfigs = connectorConfigs; + } + + /** + * Devuelve las configuraciones de + * {@link javax.servlet.annotation.WebServlet} que se desean sobreescribir + * + * @return Configuraciones a sobreescribir, no null + */ + @XmlElementWrapper(name = "servlets") + @XmlElements( + { + @XmlElement(name = "servlet", type = WebServletConfig.class) + }) + public List getServletConfigs() + { + if (servletConfigs == null) + { + servletConfigs = new LinkedList<>(); + } + return servletConfigs; + } + + /** + * Establece las configuraciones de + * {@link javax.servlet.annotation.WebServlet} que se desean sobreescribir + * en los servlets + * + * @param servletConfigs Listado de {@link WebServletConfig} con las + * configuraciones de {@link javax.servlet.annotation.WebServlet} deseadas + */ + public void setServletConfigs(List servletConfigs) + { + this.servletConfigs = servletConfigs; + } + + /** + * Deuelve la cantidad de segundos limite que puede durar la sesion antes de + * expirar + * + * @return cantidad de segundos o null + */ + @XmlElement(name = "sessionExp") + public Integer getSessionExp() + { + if(sessionExp == null) + { + sessionExp = 30; + } + return sessionExp; + } + + /** + * Establece la cantidad de segundos limite que podra durar la sesionn antes + * de expirar + * + * @param sessionExp cantidad de segundos + */ + public void setSessionExp(Integer sessionExp) + { + this.sessionExp = sessionExp; + } + + /** + * Busca una configuracion que sobreescribe la del + * {@link javax.servlet.annotation.WebServlet} en un servlet + * + * @param name Propiedad especificada en el + * {@link javax.servlet.annotation.WebServlet#name} por la cual se buscara + * el servlet + * @return Devuelve la configuracion {@link WebServletConfig} encontrada, o + * null + */ + public WebServletConfig findWebServletByName(String name) + { + for (WebServletConfig webServletConfig : getServletConfigs()) + { + if (name.equals(webServletConfig.getName())) + { + return webServletConfig; + } + } + return null; + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/impl/http/jetty/HttpConnectorConfig.java b/old/bridje-core/src/main/java/org/bridje/core/impl/http/jetty/HttpConnectorConfig.java index 860a1eb3c..c6b810419 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/impl/http/jetty/HttpConnectorConfig.java +++ b/old/bridje-core/src/main/java/org/bridje/core/impl/http/jetty/HttpConnectorConfig.java @@ -1,89 +1,89 @@ - -package org.bridje.core.impl.http.jetty; - -public class HttpConnectorConfig -{ - private String protocol; - - private Integer port; - - private String keyStorePath; - - private String keyStorePassword; - - private String keyManagerPassword; - - private String trustStorePath; - - private String trustStorePassword; - - public String getProtocol() - { - return protocol; - } - - public void setProtocol(String protocol) - { - this.protocol = protocol; - } - - public Integer getPort() - { - return port; - } - - public void setPort(Integer port) - { - this.port = port; - } - - public String getKeyStorePath() - { - return keyStorePath; - } - - public void setKeyStorePath(String keyStorePath) - { - this.keyStorePath = keyStorePath; - } - - public String getKeyStorePassword() - { - return keyStorePassword; - } - - public void setKeyStorePassword(String keyStorePassword) - { - this.keyStorePassword = keyStorePassword; - } - - public String getKeyManagerPassword() - { - return keyManagerPassword; - } - - public void setKeyManagerPassword(String keyManagerPassword) - { - this.keyManagerPassword = keyManagerPassword; - } - - public String getTrustStorePath() - { - return trustStorePath; - } - - public void setTrustStorePath(String trustStorePath) - { - this.trustStorePath = trustStorePath; - } - - public String getTrustStorePassword() - { - return trustStorePassword; - } - - public void setTrustStorePassword(String trustStorePassword) - { - this.trustStorePassword = trustStorePassword; - } -} + +package org.bridje.core.impl.http.jetty; + +public class HttpConnectorConfig +{ + private String protocol; + + private Integer port; + + private String keyStorePath; + + private String keyStorePassword; + + private String keyManagerPassword; + + private String trustStorePath; + + private String trustStorePassword; + + public String getProtocol() + { + return protocol; + } + + public void setProtocol(String protocol) + { + this.protocol = protocol; + } + + public Integer getPort() + { + return port; + } + + public void setPort(Integer port) + { + this.port = port; + } + + public String getKeyStorePath() + { + return keyStorePath; + } + + public void setKeyStorePath(String keyStorePath) + { + this.keyStorePath = keyStorePath; + } + + public String getKeyStorePassword() + { + return keyStorePassword; + } + + public void setKeyStorePassword(String keyStorePassword) + { + this.keyStorePassword = keyStorePassword; + } + + public String getKeyManagerPassword() + { + return keyManagerPassword; + } + + public void setKeyManagerPassword(String keyManagerPassword) + { + this.keyManagerPassword = keyManagerPassword; + } + + public String getTrustStorePath() + { + return trustStorePath; + } + + public void setTrustStorePath(String trustStorePath) + { + this.trustStorePath = trustStorePath; + } + + public String getTrustStorePassword() + { + return trustStorePassword; + } + + public void setTrustStorePassword(String trustStorePassword) + { + this.trustStorePassword = trustStorePassword; + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/impl/http/jetty/HttpServerImpl.java b/old/bridje-core/src/main/java/org/bridje/core/impl/http/jetty/HttpServerImpl.java index f8e4bdcc1..762b22a4c 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/impl/http/jetty/HttpServerImpl.java +++ b/old/bridje-core/src/main/java/org/bridje/core/impl/http/jetty/HttpServerImpl.java @@ -1,41 +1,41 @@ - -package org.bridje.core.impl.http.jetty; - -import org.bridje.core.http.HttpServer; -import org.bridje.core.http.HttpServerException; -import org.bridje.ioc.Component; -import org.bridje.ioc.Inject; - -@Component -class HttpServerImpl implements HttpServer -{ - @Inject - private JettyServer server; - - @Override - public void start() throws HttpServerException - { - try - { - server.start(); - } - catch(Exception ex) - { - throw new HttpServerException(ex.getMessage(), ex); - } - } - - @Override - public void stop() throws HttpServerException - { - try - { - server.stop(); - } - catch(Exception ex) - { - throw new HttpServerException(ex.getMessage(), ex); - } - } - -} + +package org.bridje.core.impl.http.jetty; + +import org.bridje.core.http.HttpServer; +import org.bridje.core.http.HttpServerException; +import org.bridje.ioc.Component; +import org.bridje.ioc.Inject; + +@Component +class HttpServerImpl implements HttpServer +{ + @Inject + private JettyServer server; + + @Override + public void start() throws HttpServerException + { + try + { + server.start(); + } + catch(Exception ex) + { + throw new HttpServerException(ex.getMessage(), ex); + } + } + + @Override + public void stop() throws HttpServerException + { + try + { + server.stop(); + } + catch(Exception ex) + { + throw new HttpServerException(ex.getMessage(), ex); + } + } + +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/impl/http/jetty/JettyServer.java b/old/bridje-core/src/main/java/org/bridje/core/impl/http/jetty/JettyServer.java index 5cfd31b3c..a019782b3 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/impl/http/jetty/JettyServer.java +++ b/old/bridje-core/src/main/java/org/bridje/core/impl/http/jetty/JettyServer.java @@ -1,211 +1,211 @@ - -package org.bridje.core.impl.http.jetty; - -import java.util.Arrays; -import java.util.EnumSet; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.annotation.PostConstruct; -import javax.servlet.DispatcherType; -import javax.servlet.Filter; -import javax.servlet.MultipartConfigElement; -import javax.servlet.Servlet; -import javax.servlet.annotation.MultipartConfig; -import javax.servlet.annotation.WebFilter; -import javax.servlet.annotation.WebInitParam; -import javax.servlet.annotation.WebServlet; -import org.bridje.core.cfg.ConfigService; -import org.bridje.ioc.IocContext; -import org.bridje.ioc.Component; -import org.bridje.ioc.Inject; -import org.eclipse.jetty.server.Connector; -import org.eclipse.jetty.server.Handler; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.server.ServerConnector; -import org.eclipse.jetty.server.session.SessionHandler; -import org.eclipse.jetty.servlet.FilterHolder; -import org.eclipse.jetty.servlet.ServletContextHandler; -import org.eclipse.jetty.servlet.ServletHolder; -import org.eclipse.jetty.util.ssl.SslContextFactory; - -@Component -class JettyServer extends Server -{ - public static final int STOP_TIMEOUT = 30000; - - private static final Logger LOG = Logger.getLogger(JettyServer.class.getName()); - - @Inject - private IocContext context; - - @Inject - private ConfigService configServ; - - private HttpConfig httpConfig; - - @PostConstruct - public void init() - { - LOG.info("Configurando servidor de Jetty..."); - try - { - setStopAtShutdown(true); - setStopTimeout(STOP_TIMEOUT); - httpConfig = configServ.findOrCreateConfig(HttpConfig.class, new HttpConfig()); - for (HttpConnectorConfig connectorCfg : httpConfig.getConnectorConfigs()) - { - addConnector(createConector(connectorCfg)); - } - setHandler(createSessionHandler()); - } - catch (Exception e) - { - LOG.log(Level.SEVERE, e.getMessage(), e); - } - } - - private Handler createSessionHandler() - { - SessionHandler sessionHandler = new SessionHandler(); - sessionHandler.getSessionManager().setMaxInactiveInterval(httpConfig.getSessionExp()); - sessionHandler.setHandler(createServletsHandler()); - return sessionHandler; - } - - private Handler createServletsHandler() - { - ServletContextHandler sch = new ServletContextHandler(); - sch.setContextPath("/"); - - context.getClassRepository().navigateAnnotClasses(WebServlet.class, (Class servletCls, WebServlet annotation) -> - { - if(Servlet.class.isAssignableFrom(servletCls)) - { - WebServletConfig servletConfig = httpConfig.findWebServletByName(annotation.name()); - if (servletConfig == null) - { - servletConfig = new WebServletConfig(annotation); - } - Servlet servlet = (Servlet)context.find(servletCls); - ServletHolder servletHolder = new ServletHolder(servlet); - servletHolder.setName(servletConfig.getName()); - servletHolder.setDisplayName(servletConfig.getDisplayName()); - servletHolder.setServletHandler(sch.getServletHandler()); - servletHolder.getRegistration().addMapping(servletConfig.getUrlPatterns()); - servletHolder.getRegistration().setLoadOnStartup(servletConfig.getLoadOnStartup()); - servletHolder.getRegistration().setAsyncSupported(servletConfig.isAsyncSupported()); - servletHolder.getRegistration().setInitParameters(createInitParameters(servletConfig.getInitParamsAnnotations())); - MultipartConfig mpConfig = servlet.getClass().getAnnotation(MultipartConfig.class); - if (mpConfig != null) - { - servletHolder.getRegistration().setMultipartConfig(new MultipartConfigElement(mpConfig)); - } - sch.getServletHandler().addServlet(servletHolder); - } - }); - - context.getClassRepository().navigateAnnotClasses(WebFilter.class, (Class filterCls, WebFilter annotation) -> - { - if(Filter.class.isAssignableFrom(filterCls)) - { - Filter filter = (Filter)context.find(filterCls); - FilterHolder filterHolder = new FilterHolder(filter); - filterHolder.setName(annotation.filterName()); - filterHolder.setDisplayName(annotation.displayName()); - filterHolder.setServletHandler(sch.getServletHandler()); - EnumSet dispacheTypes = createDispatcherType(annotation); - filterHolder.getRegistration().addMappingForServletNames(dispacheTypes, true, annotation.servletNames()); - filterHolder.getRegistration().addMappingForUrlPatterns(dispacheTypes, true, annotation.urlPatterns()); - filterHolder.getRegistration().setAsyncSupported(annotation.asyncSupported()); - filterHolder.getRegistration().setInitParameters(createInitParameters(annotation.initParams())); - sch.getServletHandler().addFilter(filterHolder); - } - }); - - return sch; - } - - private Connector createConector(HttpConnectorConfig connectorConfig) - { - if (connectorConfig == null) - { - connectorConfig = new HttpConnectorConfig(); - } - - if (!"http".equalsIgnoreCase(connectorConfig.getProtocol()) && !"https".equalsIgnoreCase(connectorConfig.getProtocol())) - { - connectorConfig.setProtocol("http"); - } - - if (connectorConfig.getPort() == null || connectorConfig.getPort() == 0) - { - connectorConfig.setPort(8080); - } - - ServerConnector connector = createServerConnector(connectorConfig); - - connector.setPort(connectorConfig.getPort()); - return connector; - } - - private ServerConnector createServerConnector(HttpConnectorConfig config) - { - ServerConnector connector; - if ("https".equalsIgnoreCase(config.getProtocol())) - { - SslContextFactory sslFact = new SslContextFactory(); - if (!isBlank(config.getKeyStorePath())) - { - sslFact.setKeyStorePath(config.getKeyStorePath()); - } - if (!isBlank(config.getKeyStorePassword())) - { - sslFact.setKeyStorePassword(config.getKeyStorePassword()); - } - if (!isBlank(config.getKeyManagerPassword())) - { - sslFact.setKeyManagerPassword(config.getKeyManagerPassword()); - } - if (!isBlank(config.getTrustStorePath())) - { - sslFact.setTrustStorePath(config.getTrustStorePath()); - } - if (isBlank(config.getTrustStorePassword())) - { - sslFact.setTrustStorePassword(config.getTrustStorePassword()); - } - connector = new ServerConnector(this, sslFact); - } - else - { - connector = new ServerConnector(this); - } - return connector; - } - - private boolean isBlank(String value) - { - return value == null || value.trim().isEmpty(); - } - - private Map createInitParameters(WebInitParam[] initParams) - { - Map result = new LinkedHashMap<>(); - - for (WebInitParam webInitParam : initParams) - { - result.put(webInitParam.name(), webInitParam.value()); - } - - return result; - } - - private EnumSet createDispatcherType(WebFilter annot) - { - EnumSet result = EnumSet.allOf(DispatcherType.class); - result.addAll(Arrays.asList(annot.dispatcherTypes())); - return result; - } -} + +package org.bridje.core.impl.http.jetty; + +import java.util.Arrays; +import java.util.EnumSet; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.annotation.PostConstruct; +import javax.servlet.DispatcherType; +import javax.servlet.Filter; +import javax.servlet.MultipartConfigElement; +import javax.servlet.Servlet; +import javax.servlet.annotation.MultipartConfig; +import javax.servlet.annotation.WebFilter; +import javax.servlet.annotation.WebInitParam; +import javax.servlet.annotation.WebServlet; +import org.bridje.core.cfg.ConfigService; +import org.bridje.ioc.IocContext; +import org.bridje.ioc.Component; +import org.bridje.ioc.Inject; +import org.eclipse.jetty.server.Connector; +import org.eclipse.jetty.server.Handler; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.ServerConnector; +import org.eclipse.jetty.server.session.SessionHandler; +import org.eclipse.jetty.servlet.FilterHolder; +import org.eclipse.jetty.servlet.ServletContextHandler; +import org.eclipse.jetty.servlet.ServletHolder; +import org.eclipse.jetty.util.ssl.SslContextFactory; + +@Component +class JettyServer extends Server +{ + public static final int STOP_TIMEOUT = 30000; + + private static final Logger LOG = Logger.getLogger(JettyServer.class.getName()); + + @Inject + private IocContext context; + + @Inject + private ConfigService configServ; + + private HttpConfig httpConfig; + + @PostConstruct + public void init() + { + LOG.info("Configurando servidor de Jetty..."); + try + { + setStopAtShutdown(true); + setStopTimeout(STOP_TIMEOUT); + httpConfig = configServ.findOrCreateConfig(HttpConfig.class, new HttpConfig()); + for (HttpConnectorConfig connectorCfg : httpConfig.getConnectorConfigs()) + { + addConnector(createConector(connectorCfg)); + } + setHandler(createSessionHandler()); + } + catch (Exception e) + { + LOG.log(Level.SEVERE, e.getMessage(), e); + } + } + + private Handler createSessionHandler() + { + SessionHandler sessionHandler = new SessionHandler(); + sessionHandler.getSessionManager().setMaxInactiveInterval(httpConfig.getSessionExp()); + sessionHandler.setHandler(createServletsHandler()); + return sessionHandler; + } + + private Handler createServletsHandler() + { + ServletContextHandler sch = new ServletContextHandler(); + sch.setContextPath("/"); + + context.getClassRepository().navigateAnnotClasses(WebServlet.class, (Class servletCls, WebServlet annotation) -> + { + if(Servlet.class.isAssignableFrom(servletCls)) + { + WebServletConfig servletConfig = httpConfig.findWebServletByName(annotation.name()); + if (servletConfig == null) + { + servletConfig = new WebServletConfig(annotation); + } + Servlet servlet = (Servlet)context.find(servletCls); + ServletHolder servletHolder = new ServletHolder(servlet); + servletHolder.setName(servletConfig.getName()); + servletHolder.setDisplayName(servletConfig.getDisplayName()); + servletHolder.setServletHandler(sch.getServletHandler()); + servletHolder.getRegistration().addMapping(servletConfig.getUrlPatterns()); + servletHolder.getRegistration().setLoadOnStartup(servletConfig.getLoadOnStartup()); + servletHolder.getRegistration().setAsyncSupported(servletConfig.isAsyncSupported()); + servletHolder.getRegistration().setInitParameters(createInitParameters(servletConfig.getInitParamsAnnotations())); + MultipartConfig mpConfig = servlet.getClass().getAnnotation(MultipartConfig.class); + if (mpConfig != null) + { + servletHolder.getRegistration().setMultipartConfig(new MultipartConfigElement(mpConfig)); + } + sch.getServletHandler().addServlet(servletHolder); + } + }); + + context.getClassRepository().navigateAnnotClasses(WebFilter.class, (Class filterCls, WebFilter annotation) -> + { + if(Filter.class.isAssignableFrom(filterCls)) + { + Filter filter = (Filter)context.find(filterCls); + FilterHolder filterHolder = new FilterHolder(filter); + filterHolder.setName(annotation.filterName()); + filterHolder.setDisplayName(annotation.displayName()); + filterHolder.setServletHandler(sch.getServletHandler()); + EnumSet dispacheTypes = createDispatcherType(annotation); + filterHolder.getRegistration().addMappingForServletNames(dispacheTypes, true, annotation.servletNames()); + filterHolder.getRegistration().addMappingForUrlPatterns(dispacheTypes, true, annotation.urlPatterns()); + filterHolder.getRegistration().setAsyncSupported(annotation.asyncSupported()); + filterHolder.getRegistration().setInitParameters(createInitParameters(annotation.initParams())); + sch.getServletHandler().addFilter(filterHolder); + } + }); + + return sch; + } + + private Connector createConector(HttpConnectorConfig connectorConfig) + { + if (connectorConfig == null) + { + connectorConfig = new HttpConnectorConfig(); + } + + if (!"http".equalsIgnoreCase(connectorConfig.getProtocol()) && !"https".equalsIgnoreCase(connectorConfig.getProtocol())) + { + connectorConfig.setProtocol("http"); + } + + if (connectorConfig.getPort() == null || connectorConfig.getPort() == 0) + { + connectorConfig.setPort(8080); + } + + ServerConnector connector = createServerConnector(connectorConfig); + + connector.setPort(connectorConfig.getPort()); + return connector; + } + + private ServerConnector createServerConnector(HttpConnectorConfig config) + { + ServerConnector connector; + if ("https".equalsIgnoreCase(config.getProtocol())) + { + SslContextFactory sslFact = new SslContextFactory(); + if (!isBlank(config.getKeyStorePath())) + { + sslFact.setKeyStorePath(config.getKeyStorePath()); + } + if (!isBlank(config.getKeyStorePassword())) + { + sslFact.setKeyStorePassword(config.getKeyStorePassword()); + } + if (!isBlank(config.getKeyManagerPassword())) + { + sslFact.setKeyManagerPassword(config.getKeyManagerPassword()); + } + if (!isBlank(config.getTrustStorePath())) + { + sslFact.setTrustStorePath(config.getTrustStorePath()); + } + if (isBlank(config.getTrustStorePassword())) + { + sslFact.setTrustStorePassword(config.getTrustStorePassword()); + } + connector = new ServerConnector(this, sslFact); + } + else + { + connector = new ServerConnector(this); + } + return connector; + } + + private boolean isBlank(String value) + { + return value == null || value.trim().isEmpty(); + } + + private Map createInitParameters(WebInitParam[] initParams) + { + Map result = new LinkedHashMap<>(); + + for (WebInitParam webInitParam : initParams) + { + result.put(webInitParam.name(), webInitParam.value()); + } + + return result; + } + + private EnumSet createDispatcherType(WebFilter annot) + { + EnumSet result = EnumSet.allOf(DispatcherType.class); + result.addAll(Arrays.asList(annot.dispatcherTypes())); + return result; + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/impl/procs/ProcessInstanceImpl.java b/old/bridje-core/src/main/java/org/bridje/core/impl/procs/ProcessInstanceImpl.java index a17d0155d..15f4a3c31 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/impl/procs/ProcessInstanceImpl.java +++ b/old/bridje-core/src/main/java/org/bridje/core/impl/procs/ProcessInstanceImpl.java @@ -1,82 +1,82 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.impl.procs; - -import org.bridje.core.procs.ApplicationProcess; -import org.bridje.core.procs.ProcessInstance; - -/** - * - */ -class ProcessInstanceImpl implements ProcessInstance -{ - private Thread procThread; - - private final ApplicationProcess target; - - public ProcessInstanceImpl(ApplicationProcess target) - { - this.target = target; - } - - @Override - public String getName() - { - return target.getName(); - } - - @Override - public boolean isRunning() - { - return procThread != null && procThread.isAlive(); - } - - @Override - public void start() - { - if(!isRunning()) - { - if(procThread == null) - { - procThread = new Thread(target); - } - procThread.start(); - } - } - - @Override - public void stop() - { - if(isRunning()) - { - target.stop(); - } - if(!isRunning() && procThread == null) - { - procThread = null; - } - } - - @Override - public void join() throws InterruptedException - { - if(isRunning()) - { - procThread.join(); - } - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.impl.procs; + +import org.bridje.core.procs.ApplicationProcess; +import org.bridje.core.procs.ProcessInstance; + +/** + * + */ +class ProcessInstanceImpl implements ProcessInstance +{ + private Thread procThread; + + private final ApplicationProcess target; + + public ProcessInstanceImpl(ApplicationProcess target) + { + this.target = target; + } + + @Override + public String getName() + { + return target.getName(); + } + + @Override + public boolean isRunning() + { + return procThread != null && procThread.isAlive(); + } + + @Override + public void start() + { + if(!isRunning()) + { + if(procThread == null) + { + procThread = new Thread(target); + } + procThread.start(); + } + } + + @Override + public void stop() + { + if(isRunning()) + { + target.stop(); + } + if(!isRunning() && procThread == null) + { + procThread = null; + } + } + + @Override + public void join() throws InterruptedException + { + if(isRunning()) + { + procThread.join(); + } + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/impl/procs/ProcessServiceImpl.java b/old/bridje-core/src/main/java/org/bridje/core/impl/procs/ProcessServiceImpl.java index d6861dc8c..0743c203e 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/impl/procs/ProcessServiceImpl.java +++ b/old/bridje-core/src/main/java/org/bridje/core/impl/procs/ProcessServiceImpl.java @@ -1,105 +1,105 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.impl.procs; - -import java.util.HashMap; -import java.util.Map; -import javax.annotation.PostConstruct; -import org.bridje.ioc.Component; -import org.bridje.ioc.Inject; -import org.bridje.core.procs.ApplicationProcess; -import org.bridje.core.procs.ProcessInstance; -import org.bridje.core.procs.ProcessService; - -/** - * - */ -@Component -class ProcessServiceImpl implements ProcessService -{ - @Inject - private ApplicationProcess[] appProcess; - - private ProcessInstance[] allProcess; - - private Map procMap; - - @PostConstruct - public void init() - { - procMap = new HashMap<>(); - if (appProcess == null) - { - appProcess = new ApplicationProcess[]{}; - } - allProcess = new ProcessInstance[appProcess.length]; - for (int i = 0; i < appProcess.length; i++) - { - allProcess[i] = new ProcessInstanceImpl(appProcess[i]); - procMap.put(allProcess[i].getName(), allProcess[i]); - } - } - - @Override - public ProcessInstance[] getAllProcess() - { - return allProcess; - } - - @Override - public ProcessInstance findProcess(String name) - { - return procMap.get(name); - } - - @Override - public void startAll() - { - for (ProcessInstance process : allProcess) - { - if (!process.isRunning()) - { - process.start(); - } - } - } - - @Override - public void shutdown() - { - for (ProcessInstance process : allProcess) - { - if (process.isRunning()) - { - process.stop(); - } - } - } - - @Override - public void join() throws InterruptedException - { - for (ProcessInstance process : allProcess) - { - if (process.isRunning()) - { - process.join(); - } - } - } - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.impl.procs; + +import java.util.HashMap; +import java.util.Map; +import javax.annotation.PostConstruct; +import org.bridje.ioc.Component; +import org.bridje.ioc.Inject; +import org.bridje.core.procs.ApplicationProcess; +import org.bridje.core.procs.ProcessInstance; +import org.bridje.core.procs.ProcessService; + +/** + * + */ +@Component +class ProcessServiceImpl implements ProcessService +{ + @Inject + private ApplicationProcess[] appProcess; + + private ProcessInstance[] allProcess; + + private Map procMap; + + @PostConstruct + public void init() + { + procMap = new HashMap<>(); + if (appProcess == null) + { + appProcess = new ApplicationProcess[]{}; + } + allProcess = new ProcessInstance[appProcess.length]; + for (int i = 0; i < appProcess.length; i++) + { + allProcess[i] = new ProcessInstanceImpl(appProcess[i]); + procMap.put(allProcess[i].getName(), allProcess[i]); + } + } + + @Override + public ProcessInstance[] getAllProcess() + { + return allProcess; + } + + @Override + public ProcessInstance findProcess(String name) + { + return procMap.get(name); + } + + @Override + public void startAll() + { + for (ProcessInstance process : allProcess) + { + if (!process.isRunning()) + { + process.start(); + } + } + } + + @Override + public void shutdown() + { + for (ProcessInstance process : allProcess) + { + if (process.isRunning()) + { + process.stop(); + } + } + } + + @Override + public void join() throws InterruptedException + { + for (ProcessInstance process : allProcess) + { + if (process.isRunning()) + { + process.join(); + } + } + } + +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/impl/sql/DeleteSQLQueryImpl.java b/old/bridje-core/src/main/java/org/bridje/core/impl/sql/DeleteSQLQueryImpl.java index b28927cca..d91d4e79c 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/impl/sql/DeleteSQLQueryImpl.java +++ b/old/bridje-core/src/main/java/org/bridje/core/impl/sql/DeleteSQLQueryImpl.java @@ -1,82 +1,82 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.impl.sql; - -import java.io.StringWriter; -import java.util.Arrays; -import org.bridje.core.sql.Condition; -import org.bridje.core.sql.DeleteFromStep; -import org.bridje.core.sql.SQLQuery; -import org.bridje.core.sql.Table; -import org.bridje.core.sql.TableExpression; -import org.bridje.core.sql.UpdateWhereStep; - -class DeleteSQLQueryImpl implements DeleteFromStep, UpdateWhereStep, SQLQuery -{ - private final Table[] tables; - - private TableExpression from; - - private Condition where; - - public DeleteSQLQueryImpl(Table... tables) - { - this.tables = tables; - } - - @Override - public String getSQL() - { - StringWriter sw = new StringWriter(); - writeDelete(sw); - writeFrom(sw); - writeWhere(sw); - return sw.toString(); - } - - @Override - public SQLQuery where(Condition condition) - { - this.where = condition; - return this; - } - - private void writeWhere(StringWriter sw) - { - sw.append("\nWHERE "); - where.writeSQL(sw); - } - - @Override - public UpdateWhereStep from(TableExpression from) - { - this.from = from; - return this; - } - - private void writeDelete(StringWriter sw) - { - sw.append("DELETE "); - Utils.joinExpressions(sw, Arrays.asList(tables)); - } - - private void writeFrom(StringWriter sw) - { - sw.append("FROM "); - from.writeSQL(sw); - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.impl.sql; + +import java.io.StringWriter; +import java.util.Arrays; +import org.bridje.core.sql.Condition; +import org.bridje.core.sql.DeleteFromStep; +import org.bridje.core.sql.SQLQuery; +import org.bridje.core.sql.Table; +import org.bridje.core.sql.TableExpression; +import org.bridje.core.sql.UpdateWhereStep; + +class DeleteSQLQueryImpl implements DeleteFromStep, UpdateWhereStep, SQLQuery +{ + private final Table[] tables; + + private TableExpression from; + + private Condition where; + + public DeleteSQLQueryImpl(Table... tables) + { + this.tables = tables; + } + + @Override + public String getSQL() + { + StringWriter sw = new StringWriter(); + writeDelete(sw); + writeFrom(sw); + writeWhere(sw); + return sw.toString(); + } + + @Override + public SQLQuery where(Condition condition) + { + this.where = condition; + return this; + } + + private void writeWhere(StringWriter sw) + { + sw.append("\nWHERE "); + where.writeSQL(sw); + } + + @Override + public UpdateWhereStep from(TableExpression from) + { + this.from = from; + return this; + } + + private void writeDelete(StringWriter sw) + { + sw.append("DELETE "); + Utils.joinExpressions(sw, Arrays.asList(tables)); + } + + private void writeFrom(StringWriter sw) + { + sw.append("FROM "); + from.writeSQL(sw); + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/impl/sql/InsertSQLQueryImpl.java b/old/bridje-core/src/main/java/org/bridje/core/impl/sql/InsertSQLQueryImpl.java index 76a4c16f9..e6989e09d 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/impl/sql/InsertSQLQueryImpl.java +++ b/old/bridje-core/src/main/java/org/bridje/core/impl/sql/InsertSQLQueryImpl.java @@ -1,85 +1,85 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.impl.sql; - -import java.io.StringWriter; -import java.util.ArrayList; -import java.util.List; -import org.bridje.core.sql.Column; -import org.bridje.core.sql.InsertSetStep; -import org.bridje.core.sql.Literal; -import org.bridje.core.sql.SQLQuery; -import org.bridje.core.sql.Table; -import org.bridje.core.sql.TableExpression; - -class InsertSQLQueryImpl implements InsertSetStep, SQLQuery -{ - private final List columns; - - private final TableExpression into; - - private final List values; - - public InsertSQLQueryImpl(Table into) - { - this.into = into; - this.columns = new ArrayList<>(); - this.values = new ArrayList<>(); - } - - @Override - public String getSQL() - { - if(into != null) - { - StringWriter sw = new StringWriter(); - writeInsertInto(sw); - writeColumns(sw); - writeValues(sw); - return sw.toString(); - } - return null; - } - - @Override - public InsertSetStep set(Column column, Literal value) - { - columns.add(column); - values.add(value); - return this; - } - - private void writeInsertInto(StringWriter sw) - { - sw.append("INSERT INTO "); - into.writeSQL(sw); - } - - private void writeColumns(StringWriter sw) - { - sw.append("\n ("); - Utils.joinExpressions(sw, columns); - sw.append(")"); - } - - private void writeValues(StringWriter sw) - { - sw.append("\nVALUES ("); - Utils.joinExpressions(sw, values); - sw.append(")"); - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.impl.sql; + +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.List; +import org.bridje.core.sql.Column; +import org.bridje.core.sql.InsertSetStep; +import org.bridje.core.sql.Literal; +import org.bridje.core.sql.SQLQuery; +import org.bridje.core.sql.Table; +import org.bridje.core.sql.TableExpression; + +class InsertSQLQueryImpl implements InsertSetStep, SQLQuery +{ + private final List columns; + + private final TableExpression into; + + private final List values; + + public InsertSQLQueryImpl(Table into) + { + this.into = into; + this.columns = new ArrayList<>(); + this.values = new ArrayList<>(); + } + + @Override + public String getSQL() + { + if(into != null) + { + StringWriter sw = new StringWriter(); + writeInsertInto(sw); + writeColumns(sw); + writeValues(sw); + return sw.toString(); + } + return null; + } + + @Override + public InsertSetStep set(Column column, Literal value) + { + columns.add(column); + values.add(value); + return this; + } + + private void writeInsertInto(StringWriter sw) + { + sw.append("INSERT INTO "); + into.writeSQL(sw); + } + + private void writeColumns(StringWriter sw) + { + sw.append("\n ("); + Utils.joinExpressions(sw, columns); + sw.append(")"); + } + + private void writeValues(StringWriter sw) + { + sw.append("\nVALUES ("); + Utils.joinExpressions(sw, values); + sw.append(")"); + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/impl/sql/SQLServiceImpl.java b/old/bridje-core/src/main/java/org/bridje/core/impl/sql/SQLServiceImpl.java index f1c8070ff..6d8ad2df3 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/impl/sql/SQLServiceImpl.java +++ b/old/bridje-core/src/main/java/org/bridje/core/impl/sql/SQLServiceImpl.java @@ -1,61 +1,61 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.impl.sql; - -import org.bridje.ioc.Component; -import org.bridje.core.sql.ColumnExpresion; -import org.bridje.core.sql.DeleteFromStep; -import org.bridje.core.sql.FromStep; -import org.bridje.core.sql.InsertSetStep; -import org.bridje.core.sql.SQLService; -import org.bridje.core.sql.Table; -import org.bridje.core.sql.TableExpression; -import org.bridje.core.sql.UpdateSetStep; - -@Component -class SQLServiceImpl implements SQLService -{ - @Override - public FromStep select(ColumnExpresion... selectExp) - { - return new SelectSQLQueryImpl(selectExp); - } - - @Override - public InsertSetStep insertInto(Table table) - { - return new InsertSQLQueryImpl(table); - } - - @Override - public UpdateSetStep update(TableExpression from) - { - return new UpdateSQLQueryImpl(from); - } - - @Override - public DeleteFromStep delete(Table table) - { - return new DeleteSQLQueryImpl(table); - } - - @Override - public DeleteFromStep delete() - { - return new DeleteSQLQueryImpl(); - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.impl.sql; + +import org.bridje.ioc.Component; +import org.bridje.core.sql.ColumnExpresion; +import org.bridje.core.sql.DeleteFromStep; +import org.bridje.core.sql.FromStep; +import org.bridje.core.sql.InsertSetStep; +import org.bridje.core.sql.SQLService; +import org.bridje.core.sql.Table; +import org.bridje.core.sql.TableExpression; +import org.bridje.core.sql.UpdateSetStep; + +@Component +class SQLServiceImpl implements SQLService +{ + @Override + public FromStep select(ColumnExpresion... selectExp) + { + return new SelectSQLQueryImpl(selectExp); + } + + @Override + public InsertSetStep insertInto(Table table) + { + return new InsertSQLQueryImpl(table); + } + + @Override + public UpdateSetStep update(TableExpression from) + { + return new UpdateSQLQueryImpl(from); + } + + @Override + public DeleteFromStep delete(Table table) + { + return new DeleteSQLQueryImpl(table); + } + + @Override + public DeleteFromStep delete() + { + return new DeleteSQLQueryImpl(); + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/impl/sql/SelectSQLQueryImpl.java b/old/bridje-core/src/main/java/org/bridje/core/impl/sql/SelectSQLQueryImpl.java index 5dd2489a6..ac0f4ae49 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/impl/sql/SelectSQLQueryImpl.java +++ b/old/bridje-core/src/main/java/org/bridje/core/impl/sql/SelectSQLQueryImpl.java @@ -1,153 +1,153 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.impl.sql; - -import java.io.StringWriter; -import java.util.Arrays; -import org.bridje.core.sql.ColumnExpresion; -import org.bridje.core.sql.Condition; -import org.bridje.core.sql.FromStep; -import org.bridje.core.sql.GroupByStep; -import org.bridje.core.sql.HavingStep; -import org.bridje.core.sql.OrderExpression; -import org.bridje.core.sql.OrderStep; -import org.bridje.core.sql.SQLQuery; -import org.bridje.core.sql.TableExpression; -import org.bridje.core.sql.SelectWhereStep; - -class SelectSQLQueryImpl implements FromStep, SelectWhereStep, GroupByStep, HavingStep, SQLQuery -{ - private ColumnExpresion[] select; - - private TableExpression from; - - private Condition where; - - private OrderExpression[] groupBy; - - private Condition having; - - private OrderExpression[] orderBy; - - public SelectSQLQueryImpl(ColumnExpresion[] select) - { - this.select = select; - } - - @Override - public String getSQL() - { - if(select != null) - { - StringWriter sw = new StringWriter(); - writeSelect(sw); - if(from != null) - { - writeFrom(sw); - if(where != null) - { - writeWhere(sw); - } - if(groupBy != null) - { - writeGroupBy(sw); - if(having != null) - { - writeHaving(sw); - } - } - if(orderBy != null) - { - writeOrderBy(sw); - } - } - return sw.toString(); - } - return null; - } - - @Override - public SelectWhereStep from(TableExpression table) - { - this.from = table; - return this; - } - - @Override - public GroupByStep where(Condition condition) - { - this.where = condition; - return this; - } - - @Override - public HavingStep groupBy(OrderExpression... groupByExp) - { - this.groupBy = groupByExp; - return this; - } - - @Override - public SQLQuery orderBy(OrderExpression... orderExp) - { - this.orderBy = orderExp; - return this; - } - - @Override - public OrderStep having(Condition condition) - { - this.having = condition; - return this; - } - - private void writeSelect(StringWriter sw) - { - sw.append("SELECT "); - Utils.joinExpressions(sw, Arrays.asList(select)); - } - - private void writeFrom(StringWriter sw) - { - sw.append("\nFROM "); - from.writeSQL(sw); - } - - private void writeWhere(StringWriter sw) - { - sw.append("\nWHERE "); - where.writeSQL(sw); - } - - private void writeGroupBy(StringWriter sw) - { - sw.append("\nGROUP BY "); - Utils.joinExpressions(sw, Arrays.asList(groupBy)); - } - - private void writeHaving(StringWriter sw) - { - sw.append("\nHAVING "); - having.writeSQL(sw); - } - - private void writeOrderBy(StringWriter sw) - { - sw.append("\nORDER BY "); - Utils.joinExpressions(sw, Arrays.asList(orderBy)); - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.impl.sql; + +import java.io.StringWriter; +import java.util.Arrays; +import org.bridje.core.sql.ColumnExpresion; +import org.bridje.core.sql.Condition; +import org.bridje.core.sql.FromStep; +import org.bridje.core.sql.GroupByStep; +import org.bridje.core.sql.HavingStep; +import org.bridje.core.sql.OrderExpression; +import org.bridje.core.sql.OrderStep; +import org.bridje.core.sql.SQLQuery; +import org.bridje.core.sql.TableExpression; +import org.bridje.core.sql.SelectWhereStep; + +class SelectSQLQueryImpl implements FromStep, SelectWhereStep, GroupByStep, HavingStep, SQLQuery +{ + private ColumnExpresion[] select; + + private TableExpression from; + + private Condition where; + + private OrderExpression[] groupBy; + + private Condition having; + + private OrderExpression[] orderBy; + + public SelectSQLQueryImpl(ColumnExpresion[] select) + { + this.select = select; + } + + @Override + public String getSQL() + { + if(select != null) + { + StringWriter sw = new StringWriter(); + writeSelect(sw); + if(from != null) + { + writeFrom(sw); + if(where != null) + { + writeWhere(sw); + } + if(groupBy != null) + { + writeGroupBy(sw); + if(having != null) + { + writeHaving(sw); + } + } + if(orderBy != null) + { + writeOrderBy(sw); + } + } + return sw.toString(); + } + return null; + } + + @Override + public SelectWhereStep from(TableExpression table) + { + this.from = table; + return this; + } + + @Override + public GroupByStep where(Condition condition) + { + this.where = condition; + return this; + } + + @Override + public HavingStep groupBy(OrderExpression... groupByExp) + { + this.groupBy = groupByExp; + return this; + } + + @Override + public SQLQuery orderBy(OrderExpression... orderExp) + { + this.orderBy = orderExp; + return this; + } + + @Override + public OrderStep having(Condition condition) + { + this.having = condition; + return this; + } + + private void writeSelect(StringWriter sw) + { + sw.append("SELECT "); + Utils.joinExpressions(sw, Arrays.asList(select)); + } + + private void writeFrom(StringWriter sw) + { + sw.append("\nFROM "); + from.writeSQL(sw); + } + + private void writeWhere(StringWriter sw) + { + sw.append("\nWHERE "); + where.writeSQL(sw); + } + + private void writeGroupBy(StringWriter sw) + { + sw.append("\nGROUP BY "); + Utils.joinExpressions(sw, Arrays.asList(groupBy)); + } + + private void writeHaving(StringWriter sw) + { + sw.append("\nHAVING "); + having.writeSQL(sw); + } + + private void writeOrderBy(StringWriter sw) + { + sw.append("\nORDER BY "); + Utils.joinExpressions(sw, Arrays.asList(orderBy)); + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/impl/sql/UpdateSQLQueryImpl.java b/old/bridje-core/src/main/java/org/bridje/core/impl/sql/UpdateSQLQueryImpl.java index 75e4b58c8..7fdf6bdef 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/impl/sql/UpdateSQLQueryImpl.java +++ b/old/bridje-core/src/main/java/org/bridje/core/impl/sql/UpdateSQLQueryImpl.java @@ -1,90 +1,90 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.impl.sql; - -import java.io.StringWriter; -import java.util.ArrayList; -import java.util.List; -import org.bridje.core.sql.Column; -import org.bridje.core.sql.ColumnExpresion; -import org.bridje.core.sql.Condition; -import org.bridje.core.sql.SQLQuery; -import org.bridje.core.sql.Table; -import org.bridje.core.sql.TableExpression; -import org.bridje.core.sql.UpdateSetStep; -import static org.bridje.core.impl.sql.Utils.joinExpressions; - -class UpdateSQLQueryImpl implements UpdateSetStep, SQLQuery -{ - private final List values; - - private final TableExpression table; - - private Condition where; - - public UpdateSQLQueryImpl(TableExpression table) - { - this.table = table; - this.values = new ArrayList<>(); - } - - @Override - public String getSQL() - { - if(table != null) - { - StringWriter sw = new StringWriter(); - writeUpdate(sw); - writeSets(sw); - writeWhere(sw); - return sw.toString(); - } - return null; - } - - @Override - public UpdateSetStep set(Column column, ColumnExpresion value) - { - values.add(new UpdateSetExpression(column, value)); - return this; - } - - private void writeUpdate(StringWriter sw) - { - sw.append("UPDATE "); - table.writeSQL(sw); - } - - private void writeSets(StringWriter sw) - { - sw.append("\nSET "); - joinExpressions(sw, values); - } - - @Override - public SQLQuery where(Condition condition) - { - this.where = condition; - return this; - } - - private void writeWhere(StringWriter sw) - { - sw.append("\nWHERE "); - where.writeSQL(sw); - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.impl.sql; + +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.List; +import org.bridje.core.sql.Column; +import org.bridje.core.sql.ColumnExpresion; +import org.bridje.core.sql.Condition; +import org.bridje.core.sql.SQLQuery; +import org.bridje.core.sql.Table; +import org.bridje.core.sql.TableExpression; +import org.bridje.core.sql.UpdateSetStep; +import static org.bridje.core.impl.sql.Utils.joinExpressions; + +class UpdateSQLQueryImpl implements UpdateSetStep, SQLQuery +{ + private final List values; + + private final TableExpression table; + + private Condition where; + + public UpdateSQLQueryImpl(TableExpression table) + { + this.table = table; + this.values = new ArrayList<>(); + } + + @Override + public String getSQL() + { + if(table != null) + { + StringWriter sw = new StringWriter(); + writeUpdate(sw); + writeSets(sw); + writeWhere(sw); + return sw.toString(); + } + return null; + } + + @Override + public UpdateSetStep set(Column column, ColumnExpresion value) + { + values.add(new UpdateSetExpression(column, value)); + return this; + } + + private void writeUpdate(StringWriter sw) + { + sw.append("UPDATE "); + table.writeSQL(sw); + } + + private void writeSets(StringWriter sw) + { + sw.append("\nSET "); + joinExpressions(sw, values); + } + + @Override + public SQLQuery where(Condition condition) + { + this.where = condition; + return this; + } + + private void writeWhere(StringWriter sw) + { + sw.append("\nWHERE "); + where.writeSQL(sw); + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/impl/sql/UpdateSetExpression.java b/old/bridje-core/src/main/java/org/bridje/core/impl/sql/UpdateSetExpression.java index de9423048..1c4200682 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/impl/sql/UpdateSetExpression.java +++ b/old/bridje-core/src/main/java/org/bridje/core/impl/sql/UpdateSetExpression.java @@ -1,49 +1,49 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.impl.sql; - -import java.io.StringWriter; -import org.bridje.core.sql.Column; -import org.bridje.core.sql.ColumnExpresion; -import org.bridje.core.sql.SQLExpression; -import org.bridje.core.sql.SQLOperator; - -/** - * - */ -public class UpdateSetExpression implements SQLExpression -{ - private Column column; - - private ColumnExpresion value; - - public UpdateSetExpression(Column column, ColumnExpresion value) - { - this.column = column; - this.value = value; - } - - @Override - public void writeSQL(StringWriter sw) - { - column.writeSQL(sw); - sw.append(" "); - sw.append(SQLOperator.EQ.toString()); - sw.append(" "); - value.writeSQL(sw); - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.impl.sql; + +import java.io.StringWriter; +import org.bridje.core.sql.Column; +import org.bridje.core.sql.ColumnExpresion; +import org.bridje.core.sql.SQLExpression; +import org.bridje.core.sql.SQLOperator; + +/** + * + */ +public class UpdateSetExpression implements SQLExpression +{ + private Column column; + + private ColumnExpresion value; + + public UpdateSetExpression(Column column, ColumnExpresion value) + { + this.column = column; + this.value = value; + } + + @Override + public void writeSQL(StringWriter sw) + { + column.writeSQL(sw); + sw.append(" "); + sw.append(SQLOperator.EQ.toString()); + sw.append(" "); + value.writeSQL(sw); + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/impl/sql/Utils.java b/old/bridje-core/src/main/java/org/bridje/core/impl/sql/Utils.java index 77c07ba29..282618656 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/impl/sql/Utils.java +++ b/old/bridje-core/src/main/java/org/bridje/core/impl/sql/Utils.java @@ -1,41 +1,41 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.impl.sql; - -import java.io.StringWriter; -import java.util.List; -import org.bridje.core.sql.SQLExpression; - -/** - * - */ -public class Utils -{ - public static void joinExpressions(StringWriter sw, List expressions) - { - boolean isFirst = true; - for (SQLExpression literal : expressions) - { - if (!isFirst) - { - sw.append(", "); - } - literal.writeSQL(sw); - isFirst = false; - } - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.impl.sql; + +import java.io.StringWriter; +import java.util.List; +import org.bridje.core.sql.SQLExpression; + +/** + * + */ +public class Utils +{ + public static void joinExpressions(StringWriter sw, List expressions) + { + boolean isFirst = true; + for (SQLExpression literal : expressions) + { + if (!isFirst) + { + sw.append(", "); + } + literal.writeSQL(sw); + isFirst = false; + } + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/impl/web/ResourceRendererHandler.java b/old/bridje-core/src/main/java/org/bridje/core/impl/web/ResourceRendererHandler.java index 86e66f85c..83ea95d60 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/impl/web/ResourceRendererHandler.java +++ b/old/bridje-core/src/main/java/org/bridje/core/impl/web/ResourceRendererHandler.java @@ -1,100 +1,100 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.impl.web; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import org.apache.commons.io.IOUtils; -import org.bridje.ioc.Component; -import org.bridje.ioc.Inject; -import org.bridje.ioc.Priority; -import org.bridje.core.web.HttpException; -import org.bridje.core.web.WebRequestChain; -import org.bridje.core.web.WebRequestHandler; -import org.bridje.vfs.Path; -import org.bridje.vfs.VfsService; -import org.bridje.vfs.VirtualFile; - -@Component -@Priority(1100) -public class ResourceRendererHandler implements WebRequestHandler -{ - @Inject - private VfsService vfsServ; - - @Override - public Object proccess(WebRequestChain chain) throws HttpException - { - String path = chain.getRequest().getRequestedPath(); - Object result = chain.procced(); - if(chain.getResponse().isProcessed()) - { - return result; - } - - if(result != null) - { - if( result instanceof String ) - { - renderVirtualFile((String)result, chain); - } - else if( result instanceof File ) - { - renderFile((File)result, chain); - } - } - else - { - renderVirtualFile(path, chain); - } - - return result; - } - - private void renderVirtualFile(String path, WebRequestChain chain) throws HttpException - { - VirtualFile file = vfsServ.findFile(new Path("/web/public").join(path)); - if(file != null) - { - try(InputStream is = file.open()) - { - IOUtils.copy(is, chain.getResponse().getOutputStream()); - chain.getResponse().processed(); - } - catch (IOException ex) - { - throw new HttpException(500, "Internal Server Error"); - } - } - } - - private void renderFile(File file, WebRequestChain chain) throws HttpException - { - try(InputStream is = new FileInputStream(file)) - { - IOUtils.copy(is, chain.getResponse().getOutputStream()); - chain.getResponse().processed(); - } - catch (IOException ex) - { - throw new HttpException(500, "Internal Server Error"); - } - } - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.impl.web; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import org.apache.commons.io.IOUtils; +import org.bridje.ioc.Component; +import org.bridje.ioc.Inject; +import org.bridje.ioc.Priority; +import org.bridje.core.web.HttpException; +import org.bridje.core.web.WebRequestChain; +import org.bridje.core.web.WebRequestHandler; +import org.bridje.vfs.Path; +import org.bridje.vfs.VfsService; +import org.bridje.vfs.VirtualFile; + +@Component +@Priority(1100) +public class ResourceRendererHandler implements WebRequestHandler +{ + @Inject + private VfsService vfsServ; + + @Override + public Object proccess(WebRequestChain chain) throws HttpException + { + String path = chain.getRequest().getRequestedPath(); + Object result = chain.procced(); + if(chain.getResponse().isProcessed()) + { + return result; + } + + if(result != null) + { + if( result instanceof String ) + { + renderVirtualFile((String)result, chain); + } + else if( result instanceof File ) + { + renderFile((File)result, chain); + } + } + else + { + renderVirtualFile(path, chain); + } + + return result; + } + + private void renderVirtualFile(String path, WebRequestChain chain) throws HttpException + { + VirtualFile file = vfsServ.findFile(new Path("/web/public").join(path)); + if(file != null) + { + try(InputStream is = file.open()) + { + IOUtils.copy(is, chain.getResponse().getOutputStream()); + chain.getResponse().processed(); + } + catch (IOException ex) + { + throw new HttpException(500, "Internal Server Error"); + } + } + } + + private void renderFile(File file, WebRequestChain chain) throws HttpException + { + try(InputStream is = new FileInputStream(file)) + { + IOUtils.copy(is, chain.getResponse().getOutputStream()); + chain.getResponse().processed(); + } + catch (IOException ex) + { + throw new HttpException(500, "Internal Server Error"); + } + } + +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/impl/web/TemplateRendererHandler.java b/old/bridje-core/src/main/java/org/bridje/core/impl/web/TemplateRendererHandler.java index 1999d691c..b79c53f0a 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/impl/web/TemplateRendererHandler.java +++ b/old/bridje-core/src/main/java/org/bridje/core/impl/web/TemplateRendererHandler.java @@ -1,92 +1,92 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.impl.web; - -import java.io.IOException; -import java.util.HashMap; -import javax.annotation.PostConstruct; -import org.bridje.ioc.Component; -import org.bridje.ioc.Inject; -import org.bridje.ioc.Priority; -import org.bridje.tpl.TplContext; -import org.bridje.tpl.TplNotFoundException; -import org.bridje.tpl.TplService; -import org.bridje.core.web.HttpException; -import org.bridje.core.web.WebRequestChain; -import org.bridje.core.web.WebRequestHandler; -import org.bridje.vfs.Path; - -@Component -@Priority(1050) -public class TemplateRendererHandler implements WebRequestHandler -{ - @Inject - private TplService tplServ; - - private TplContext tplWebContext; - - @PostConstruct - public void init() - { - tplWebContext = tplServ.createTplContext("/web"); - } - - @Override - public Object proccess(WebRequestChain chain) throws HttpException - { - String path = chain.getRequest().getRequestedPath(); - Object result = chain.procced(); - if(chain.getResponse().isProcessed()) - { - return result; - } - - if(result != null) - { - if( result instanceof String ) - { - path = (String)result; - } - else - { - return result; - } - } - - if(path != null) - { - try - { - String template = new Path("public/").join(path + ".ftl").toString(); - if(tplWebContext.exists(template)) - { - tplWebContext.render(template, new HashMap(), chain.getResponse().getOutputStream()); - chain.getResponse().processed(); - } - } - catch (TplNotFoundException ex) - { - return result; - } - catch (IOException ex) - { - throw new HttpException(500, "Internal Server Error"); - } - } - return result; - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.impl.web; + +import java.io.IOException; +import java.util.HashMap; +import javax.annotation.PostConstruct; +import org.bridje.ioc.Component; +import org.bridje.ioc.Inject; +import org.bridje.ioc.Priority; +import org.bridje.tpl.TplContext; +import org.bridje.tpl.TplNotFoundException; +import org.bridje.tpl.TplService; +import org.bridje.core.web.HttpException; +import org.bridje.core.web.WebRequestChain; +import org.bridje.core.web.WebRequestHandler; +import org.bridje.vfs.Path; + +@Component +@Priority(1050) +public class TemplateRendererHandler implements WebRequestHandler +{ + @Inject + private TplService tplServ; + + private TplContext tplWebContext; + + @PostConstruct + public void init() + { + tplWebContext = tplServ.createTplContext("/web"); + } + + @Override + public Object proccess(WebRequestChain chain) throws HttpException + { + String path = chain.getRequest().getRequestedPath(); + Object result = chain.procced(); + if(chain.getResponse().isProcessed()) + { + return result; + } + + if(result != null) + { + if( result instanceof String ) + { + path = (String)result; + } + else + { + return result; + } + } + + if(path != null) + { + try + { + String template = new Path("public/").join(path + ".ftl").toString(); + if(tplWebContext.exists(template)) + { + tplWebContext.render(template, new HashMap(), chain.getResponse().getOutputStream()); + chain.getResponse().processed(); + } + } + catch (TplNotFoundException ex) + { + return result; + } + catch (IOException ex) + { + throw new HttpException(500, "Internal Server Error"); + } + } + return result; + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/impl/web/ViewRendererHandler.java b/old/bridje-core/src/main/java/org/bridje/core/impl/web/ViewRendererHandler.java index c51f0c057..49a061f05 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/impl/web/ViewRendererHandler.java +++ b/old/bridje-core/src/main/java/org/bridje/core/impl/web/ViewRendererHandler.java @@ -1,108 +1,108 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.impl.web; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import javax.annotation.PostConstruct; -import org.bridje.ioc.Component; -import org.bridje.ioc.Inject; -import org.bridje.ioc.Priority; -import org.bridje.tpl.TplContext; -import org.bridje.tpl.TplNotFoundException; -import org.bridje.tpl.TplService; -import org.bridje.core.web.HttpException; -import org.bridje.core.web.WebRequestChain; -import org.bridje.core.web.WebRequestHandler; -import org.bridje.core.web.view.Page; -import org.bridje.core.web.view.UIContext; -import org.bridje.vfs.VfsService; - -@Component -@Priority(1000) -public class ViewRendererHandler implements WebRequestHandler -{ - @Inject - private TplService tplServ; - - @Inject - private VfsService vfsServ; - - private TplContext tplThemesContext; - - private UIContext uiContext; - - @PostConstruct - public void init() - { - tplThemesContext = tplServ.createTplContext("/web/themes"); - uiContext = new UIContext(vfsServ.findFolder("/web/public")); - } - - @Override - public Object proccess(WebRequestChain chain) throws HttpException - { - String path = chain.getRequest().getRequestedPath(); - Object result = chain.procced(); - if(chain.getResponse().isProcessed()) - { - return result; - } - - if(result != null) - { - if( result instanceof String ) - { - path = (String)result; - } - else - { - return result; - } - } - - if(path != null) - { - try - { - Page page = uiContext.findPage(path); - if(page != null) - { - String template = "default.ftl"; - if(tplThemesContext.exists(template)) - { - Map map = new HashMap(); - map.put("renderType", "full"); - map.put("view", page); - tplThemesContext.render(template, map, chain.getResponse().getOutputStream()); - chain.getResponse().processed(); - } - } - } - catch (TplNotFoundException ex) - { - return result; - } - catch (IOException ex) - { - throw new HttpException(500, "Internal Server Error"); - } - } - return result; - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.impl.web; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import javax.annotation.PostConstruct; +import org.bridje.ioc.Component; +import org.bridje.ioc.Inject; +import org.bridje.ioc.Priority; +import org.bridje.tpl.TplContext; +import org.bridje.tpl.TplNotFoundException; +import org.bridje.tpl.TplService; +import org.bridje.core.web.HttpException; +import org.bridje.core.web.WebRequestChain; +import org.bridje.core.web.WebRequestHandler; +import org.bridje.core.web.view.Page; +import org.bridje.core.web.view.UIContext; +import org.bridje.vfs.VfsService; + +@Component +@Priority(1000) +public class ViewRendererHandler implements WebRequestHandler +{ + @Inject + private TplService tplServ; + + @Inject + private VfsService vfsServ; + + private TplContext tplThemesContext; + + private UIContext uiContext; + + @PostConstruct + public void init() + { + tplThemesContext = tplServ.createTplContext("/web/themes"); + uiContext = new UIContext(vfsServ.findFolder("/web/public")); + } + + @Override + public Object proccess(WebRequestChain chain) throws HttpException + { + String path = chain.getRequest().getRequestedPath(); + Object result = chain.procced(); + if(chain.getResponse().isProcessed()) + { + return result; + } + + if(result != null) + { + if( result instanceof String ) + { + path = (String)result; + } + else + { + return result; + } + } + + if(path != null) + { + try + { + Page page = uiContext.findPage(path); + if(page != null) + { + String template = "default.ftl"; + if(tplThemesContext.exists(template)) + { + Map map = new HashMap(); + map.put("renderType", "full"); + map.put("view", page); + tplThemesContext.render(template, map, chain.getResponse().getOutputStream()); + chain.getResponse().processed(); + } + } + } + catch (TplNotFoundException ex) + { + return result; + } + catch (IOException ex) + { + throw new HttpException(500, "Internal Server Error"); + } + } + return result; + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/impl/web/WebManagerImpl.java b/old/bridje-core/src/main/java/org/bridje/core/impl/web/WebManagerImpl.java index 998646287..abc1ed761 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/impl/web/WebManagerImpl.java +++ b/old/bridje-core/src/main/java/org/bridje/core/impl/web/WebManagerImpl.java @@ -1,89 +1,89 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.impl.web; - -import java.io.PrintWriter; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.bridje.ioc.IocContext; -import org.bridje.ioc.Component; -import org.bridje.ioc.Inject; -import org.bridje.core.web.HttpException; -import org.bridje.core.web.WebManager; -import org.bridje.core.web.WebRequest; -import org.bridje.core.web.WebRequestChain; -import org.bridje.core.web.WebRequestHandler; -import org.bridje.core.web.WebResponse; - -@Component -class WebManagerImpl implements WebManager -{ - private static final Logger LOG = Logger.getLogger(WebManagerImpl.class.getName()); - - @Inject - private WebRequestHandler[] handlersList; - - @Inject - private IocContext context; - - @Override - public void proccess(WebRequest req, WebResponse resp) - { - try - { - IocContext reqContext = context.createChild("WEBREQUEST"); - WebRequestChain chain = new WebRequestChainImpl(req, resp, reqContext, handlersList); - chain.procced(); - if(!resp.isProcessed()) - { - writeError(404, "Not Found", resp); - } - } - catch(HttpException ex) - { - if(!resp.isProcessed()) - { - writeError(ex.getCode(), ex.getMessage(), resp); - } - } - catch(Exception ex) - { - LOG.log(Level.SEVERE, ex.getMessage(), ex); - if(!resp.isProcessed()) - { - writeError(500, ex.getMessage(), resp); - } - } - } - - private void writeError(int code, String message, WebResponse resp) - { - resp.setStatusCode(code); - try (PrintWriter w = new PrintWriter(resp.getOutputStream())) - { - w.print(code); - w.print(" - "); - w.print(message); - w.flush(); - } - catch(Exception e) - { - LOG.log(Level.SEVERE, e.getMessage(), e); - } - } - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.impl.web; + +import java.io.PrintWriter; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.bridje.ioc.IocContext; +import org.bridje.ioc.Component; +import org.bridje.ioc.Inject; +import org.bridje.core.web.HttpException; +import org.bridje.core.web.WebManager; +import org.bridje.core.web.WebRequest; +import org.bridje.core.web.WebRequestChain; +import org.bridje.core.web.WebRequestHandler; +import org.bridje.core.web.WebResponse; + +@Component +class WebManagerImpl implements WebManager +{ + private static final Logger LOG = Logger.getLogger(WebManagerImpl.class.getName()); + + @Inject + private WebRequestHandler[] handlersList; + + @Inject + private IocContext context; + + @Override + public void proccess(WebRequest req, WebResponse resp) + { + try + { + IocContext reqContext = context.createChild("WEBREQUEST"); + WebRequestChain chain = new WebRequestChainImpl(req, resp, reqContext, handlersList); + chain.procced(); + if(!resp.isProcessed()) + { + writeError(404, "Not Found", resp); + } + } + catch(HttpException ex) + { + if(!resp.isProcessed()) + { + writeError(ex.getCode(), ex.getMessage(), resp); + } + } + catch(Exception ex) + { + LOG.log(Level.SEVERE, ex.getMessage(), ex); + if(!resp.isProcessed()) + { + writeError(500, ex.getMessage(), resp); + } + } + } + + private void writeError(int code, String message, WebResponse resp) + { + resp.setStatusCode(code); + try (PrintWriter w = new PrintWriter(resp.getOutputStream())) + { + w.print(code); + w.print(" - "); + w.print(message); + w.flush(); + } + catch(Exception e) + { + LOG.log(Level.SEVERE, e.getMessage(), e); + } + } + +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/impl/web/WebMethodHandler.java b/old/bridje-core/src/main/java/org/bridje/core/impl/web/WebMethodHandler.java index c5dc33c9f..c9378d731 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/impl/web/WebMethodHandler.java +++ b/old/bridje-core/src/main/java/org/bridje/core/impl/web/WebMethodHandler.java @@ -1,74 +1,74 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.impl.web; - -import java.lang.reflect.InvocationTargetException; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.bridje.ioc.Component; -import org.bridje.ioc.Priority; -import org.bridje.core.web.HttpException; -import org.bridje.core.web.WebRequestChain; -import org.bridje.core.web.WebRequestHandler; - -@Component -@Priority(950) -class WebMethodHandler implements WebRequestHandler -{ - private static final Logger LOG = Logger.getLogger(WebMethodHandler.class.getName()); - - private WebMethodNode rootNode; - - @Override - public Object proccess(WebRequestChain chain) throws HttpException - { - if(rootNode == null) - { - rootNode = WebMethodNode.createWebMethodsTree(chain.getRequestContext()); - } - String requestedPath = chain.getRequest().getRequestedPath(); - requestedPath = WebMethodNode.removeSlashes(requestedPath); - String[] splitPath = requestedPath.split("//"); - WebMethodNode currNode = rootNode; - for (int i = 0; i < splitPath.length-1; i++) - { - String currPath = splitPath[i]; - currNode = rootNode.getNodes().get(currPath); - if(currNode == null) - { - return false; - } - } - String lastPathMember = splitPath[splitPath.length-1]; - WebMethodInf webMethodInf = currNode.getWebMethods().get(lastPathMember); - if(webMethodInf == null) - { - return chain.procced(); - } - Object compObj = chain.getRequestContext().find(webMethodInf.getCompClass()); - try - { - webMethodInf.getMethod().setAccessible(true); - return webMethodInf.getMethod().invoke(compObj); - } - catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) - { - LOG.log(Level.SEVERE, e.getMessage(), e); - } - return null; - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.impl.web; + +import java.lang.reflect.InvocationTargetException; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.bridje.ioc.Component; +import org.bridje.ioc.Priority; +import org.bridje.core.web.HttpException; +import org.bridje.core.web.WebRequestChain; +import org.bridje.core.web.WebRequestHandler; + +@Component +@Priority(950) +class WebMethodHandler implements WebRequestHandler +{ + private static final Logger LOG = Logger.getLogger(WebMethodHandler.class.getName()); + + private WebMethodNode rootNode; + + @Override + public Object proccess(WebRequestChain chain) throws HttpException + { + if(rootNode == null) + { + rootNode = WebMethodNode.createWebMethodsTree(chain.getRequestContext()); + } + String requestedPath = chain.getRequest().getRequestedPath(); + requestedPath = WebMethodNode.removeSlashes(requestedPath); + String[] splitPath = requestedPath.split("//"); + WebMethodNode currNode = rootNode; + for (int i = 0; i < splitPath.length-1; i++) + { + String currPath = splitPath[i]; + currNode = rootNode.getNodes().get(currPath); + if(currNode == null) + { + return false; + } + } + String lastPathMember = splitPath[splitPath.length-1]; + WebMethodInf webMethodInf = currNode.getWebMethods().get(lastPathMember); + if(webMethodInf == null) + { + return chain.procced(); + } + Object compObj = chain.getRequestContext().find(webMethodInf.getCompClass()); + try + { + webMethodInf.getMethod().setAccessible(true); + return webMethodInf.getMethod().invoke(compObj); + } + catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) + { + LOG.log(Level.SEVERE, e.getMessage(), e); + } + return null; + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/impl/web/WebMethodInf.java b/old/bridje-core/src/main/java/org/bridje/core/impl/web/WebMethodInf.java index ac0b36829..d2d1d7417 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/impl/web/WebMethodInf.java +++ b/old/bridje-core/src/main/java/org/bridje/core/impl/web/WebMethodInf.java @@ -1,65 +1,65 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.impl.web; - -import java.lang.reflect.Method; - -class WebMethodInf -{ - private Class compClass; - - private Method method; - - private String url; - - public WebMethodInf(Class compClass, Method method, String url) - { - this.compClass = compClass; - this.method = method; - this.url = url; - } - - public Class getCompClass() - { - return compClass; - } - - public void setCompClass(Class compClass) - { - this.compClass = compClass; - } - - public Method getMethod() - { - return method; - } - - public void setMethod(Method method) - { - this.method = method; - } - - public String getUrl() - { - return url; - } - - public void setUrl(String url) - { - this.url = url; - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.impl.web; + +import java.lang.reflect.Method; + +class WebMethodInf +{ + private Class compClass; + + private Method method; + + private String url; + + public WebMethodInf(Class compClass, Method method, String url) + { + this.compClass = compClass; + this.method = method; + this.url = url; + } + + public Class getCompClass() + { + return compClass; + } + + public void setCompClass(Class compClass) + { + this.compClass = compClass; + } + + public Method getMethod() + { + return method; + } + + public void setMethod(Method method) + { + this.method = method; + } + + public String getUrl() + { + return url; + } + + public void setUrl(String url) + { + this.url = url; + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/impl/web/WebMethodNode.java b/old/bridje-core/src/main/java/org/bridje/core/impl/web/WebMethodNode.java index c4b726908..ef6f34376 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/impl/web/WebMethodNode.java +++ b/old/bridje-core/src/main/java/org/bridje/core/impl/web/WebMethodNode.java @@ -1,87 +1,87 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.impl.web; - -import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.Map; -import org.bridje.ioc.IocContext; -import org.bridje.core.web.WebMethod; - -class WebMethodNode -{ - private final Map nodes; - - private final Map webMethods; - - public WebMethodNode() - { - nodes = new HashMap<>(); - webMethods = new HashMap<>(); - } - - public Map getNodes() - { - return nodes; - } - - public Map getWebMethods() - { - return webMethods; - } - - public static WebMethodNode createWebMethodsTree(IocContext context) - { - final WebMethodNode rootNode = new WebMethodNode(); - context.getClassRepository().navigateAnnotMethods(WebMethod.class, - (Method method, Class component, WebMethod annotation) -> - { - String path = annotation.value(); - path = removeSlashes(path); - WebMethodInf inf = new WebMethodInf(component, method, path); - String[] splitPath = path.split("//"); - WebMethodNode currNode = rootNode; - for (int i = 0; i < splitPath.length - 1; i++) - { - String currPath = splitPath[i]; - WebMethodNode childNode = currNode.getNodes().get(currPath); - if(childNode == null) - { - childNode = new WebMethodNode(); - currNode.getNodes().put(currPath, childNode); - currNode = childNode; - } - } - String lastPathName = splitPath[splitPath.length-1]; - currNode.getWebMethods().put(lastPathName, inf); - }); - return rootNode; - } - - public static String removeSlashes(String str) - { - if(str.startsWith("/")) - { - str = str.substring(1); - } - if(str.endsWith("/")) - { - str = str.substring(0, str.length()-1); - } - return str; - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.impl.web; + +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; +import org.bridje.ioc.IocContext; +import org.bridje.core.web.WebMethod; + +class WebMethodNode +{ + private final Map nodes; + + private final Map webMethods; + + public WebMethodNode() + { + nodes = new HashMap<>(); + webMethods = new HashMap<>(); + } + + public Map getNodes() + { + return nodes; + } + + public Map getWebMethods() + { + return webMethods; + } + + public static WebMethodNode createWebMethodsTree(IocContext context) + { + final WebMethodNode rootNode = new WebMethodNode(); + context.getClassRepository().navigateAnnotMethods(WebMethod.class, + (Method method, Class component, WebMethod annotation) -> + { + String path = annotation.value(); + path = removeSlashes(path); + WebMethodInf inf = new WebMethodInf(component, method, path); + String[] splitPath = path.split("//"); + WebMethodNode currNode = rootNode; + for (int i = 0; i < splitPath.length - 1; i++) + { + String currPath = splitPath[i]; + WebMethodNode childNode = currNode.getNodes().get(currPath); + if(childNode == null) + { + childNode = new WebMethodNode(); + currNode.getNodes().put(currPath, childNode); + currNode = childNode; + } + } + String lastPathName = splitPath[splitPath.length-1]; + currNode.getWebMethods().put(lastPathName, inf); + }); + return rootNode; + } + + public static String removeSlashes(String str) + { + if(str.startsWith("/")) + { + str = str.substring(1); + } + if(str.endsWith("/")) + { + str = str.substring(0, str.length()-1); + } + return str; + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/impl/web/WebRequestChainImpl.java b/old/bridje-core/src/main/java/org/bridje/core/impl/web/WebRequestChainImpl.java index e356a7a17..c9b7eec20 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/impl/web/WebRequestChainImpl.java +++ b/old/bridje-core/src/main/java/org/bridje/core/impl/web/WebRequestChainImpl.java @@ -1,78 +1,78 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.impl.web; - -import org.bridje.ioc.IocContext; -import org.bridje.core.web.HttpException; -import org.bridje.core.web.WebRequest; -import org.bridje.core.web.WebRequestChain; -import org.bridje.core.web.WebRequestHandler; -import org.bridje.core.web.WebResponse; - -class WebRequestChainImpl implements WebRequestChain -{ - private final WebRequest request; - - private final WebResponse response; - - private final IocContext context; - - private final WebRequestHandler[] handlers; - - private int current; - - public WebRequestChainImpl(WebRequest request, WebResponse response, IocContext context, WebRequestHandler[] handlers) - { - this.request = request; - this.response = response; - this.context = context; - this.handlers = handlers; - this.current = this.handlers.length; - } - - @Override - public WebRequest getRequest() - { - return request; - } - - @Override - public WebResponse getResponse() - { - return response; - } - - @Override - public IocContext getRequestContext() - { - return context; - } - - @Override - public Object procced() throws HttpException - { - this.current--; - if(this.current >= 0) - { - return this.handlers[this.current].proccess(this); - } - else - { - return null; - } - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.impl.web; + +import org.bridje.ioc.IocContext; +import org.bridje.core.web.HttpException; +import org.bridje.core.web.WebRequest; +import org.bridje.core.web.WebRequestChain; +import org.bridje.core.web.WebRequestHandler; +import org.bridje.core.web.WebResponse; + +class WebRequestChainImpl implements WebRequestChain +{ + private final WebRequest request; + + private final WebResponse response; + + private final IocContext context; + + private final WebRequestHandler[] handlers; + + private int current; + + public WebRequestChainImpl(WebRequest request, WebResponse response, IocContext context, WebRequestHandler[] handlers) + { + this.request = request; + this.response = response; + this.context = context; + this.handlers = handlers; + this.current = this.handlers.length; + } + + @Override + public WebRequest getRequest() + { + return request; + } + + @Override + public WebResponse getResponse() + { + return response; + } + + @Override + public IocContext getRequestContext() + { + return context; + } + + @Override + public Object procced() throws HttpException + { + this.current--; + if(this.current >= 0) + { + return this.handlers[this.current].proccess(this); + } + else + { + return null; + } + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/impl/web/servlet/BridjeWebServlet.java b/old/bridje-core/src/main/java/org/bridje/core/impl/web/servlet/BridjeWebServlet.java index 5ad8bcf33..5f916cc50 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/impl/web/servlet/BridjeWebServlet.java +++ b/old/bridje-core/src/main/java/org/bridje/core/impl/web/servlet/BridjeWebServlet.java @@ -1,34 +1,34 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - -package org.bridje.core.impl.web.servlet; - -import java.io.IOException; -import java.util.logging.Logger; -import javax.servlet.ServletException; -import javax.servlet.annotation.WebServlet; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import org.bridje.ioc.Component; -import org.bridje.ioc.Inject; -import org.bridje.core.web.WebManager; - -@Component -@WebServlet(name = "bridje-web-servlet", urlPatterns = "/*") -public class BridjeWebServlet extends HttpServlet -{ - private static final Logger LOG = Logger.getLogger(BridjeWebServlet.class.getName()); - - @Inject - private WebManager webMang; - - @Override - protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException - { - webMang.proccess(new WebRequestImpl(req), new WebResponseImpl(resp)); - } -} +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +package org.bridje.core.impl.web.servlet; + +import java.io.IOException; +import java.util.logging.Logger; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.bridje.ioc.Component; +import org.bridje.ioc.Inject; +import org.bridje.core.web.WebManager; + +@Component +@WebServlet(name = "bridje-web-servlet", urlPatterns = "/*") +public class BridjeWebServlet extends HttpServlet +{ + private static final Logger LOG = Logger.getLogger(BridjeWebServlet.class.getName()); + + @Inject + private WebManager webMang; + + @Override + protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException + { + webMang.proccess(new WebRequestImpl(req), new WebResponseImpl(resp)); + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/impl/web/servlet/WebRequestImpl.java b/old/bridje-core/src/main/java/org/bridje/core/impl/web/servlet/WebRequestImpl.java index e9f081ba4..c7bd58f88 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/impl/web/servlet/WebRequestImpl.java +++ b/old/bridje-core/src/main/java/org/bridje/core/impl/web/servlet/WebRequestImpl.java @@ -1,36 +1,36 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.impl.web.servlet; - -import javax.servlet.http.HttpServletRequest; -import org.bridje.core.web.WebRequest; - -public class WebRequestImpl implements WebRequest -{ - private final HttpServletRequest request; - - public WebRequestImpl(HttpServletRequest request) - { - this.request = request; - } - - @Override - public String getRequestedPath() - { - return this.request.getPathInfo(); - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.impl.web.servlet; + +import javax.servlet.http.HttpServletRequest; +import org.bridje.core.web.WebRequest; + +public class WebRequestImpl implements WebRequest +{ + private final HttpServletRequest request; + + public WebRequestImpl(HttpServletRequest request) + { + this.request = request; + } + + @Override + public String getRequestedPath() + { + return this.request.getPathInfo(); + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/impl/web/servlet/WebResponseImpl.java b/old/bridje-core/src/main/java/org/bridje/core/impl/web/servlet/WebResponseImpl.java index 2f44e0ff3..2b37acf48 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/impl/web/servlet/WebResponseImpl.java +++ b/old/bridje-core/src/main/java/org/bridje/core/impl/web/servlet/WebResponseImpl.java @@ -1,74 +1,74 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.impl.web.servlet; - -import java.io.IOException; -import java.io.OutputStream; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.servlet.http.HttpServletResponse; -import org.bridje.core.web.WebResponse; - -public class WebResponseImpl implements WebResponse -{ - private static final Logger LOG = Logger.getLogger(WebResponseImpl.class.getName()); - - private final HttpServletResponse resp; - - private boolean processed; - - public WebResponseImpl(HttpServletResponse resp) - { - this.resp = resp; - } - - @Override - public OutputStream getOutputStream() - { - try - { - return resp.getOutputStream(); - } - catch (IOException ex) - { - LOG.log(Level.SEVERE, ex.getMessage(), ex); - } - return null; - } - - @Override - public void processed() - { - if(processed) - { - throw new IllegalStateException("The request is allready procesed."); - } - processed = true; - } - - @Override - public boolean isProcessed() - { - return processed; - } - - @Override - public void setStatusCode(int code) - { - resp.setStatus(code); - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.impl.web.servlet; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.servlet.http.HttpServletResponse; +import org.bridje.core.web.WebResponse; + +public class WebResponseImpl implements WebResponse +{ + private static final Logger LOG = Logger.getLogger(WebResponseImpl.class.getName()); + + private final HttpServletResponse resp; + + private boolean processed; + + public WebResponseImpl(HttpServletResponse resp) + { + this.resp = resp; + } + + @Override + public OutputStream getOutputStream() + { + try + { + return resp.getOutputStream(); + } + catch (IOException ex) + { + LOG.log(Level.SEVERE, ex.getMessage(), ex); + } + return null; + } + + @Override + public void processed() + { + if(processed) + { + throw new IllegalStateException("The request is allready procesed."); + } + processed = true; + } + + @Override + public boolean isProcessed() + { + return processed; + } + + @Override + public void setStatusCode(int code) + { + resp.setStatus(code); + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/procs/ApplicationProcess.java b/old/bridje-core/src/main/java/org/bridje/core/procs/ApplicationProcess.java index c441c5bce..640c9016f 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/procs/ApplicationProcess.java +++ b/old/bridje-core/src/main/java/org/bridje/core/procs/ApplicationProcess.java @@ -1,27 +1,27 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.procs; - -/** - * - */ -public interface ApplicationProcess extends Runnable -{ - String getName(); - - void stop(); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.procs; + +/** + * + */ +public interface ApplicationProcess extends Runnable +{ + String getName(); + + void stop(); +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/procs/ProcessInstance.java b/old/bridje-core/src/main/java/org/bridje/core/procs/ProcessInstance.java index 9677e49f2..eb57624aa 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/procs/ProcessInstance.java +++ b/old/bridje-core/src/main/java/org/bridje/core/procs/ProcessInstance.java @@ -1,33 +1,33 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.procs; - -/** - * - */ -public interface ProcessInstance -{ - String getName(); - - boolean isRunning(); - - void start(); - - void stop(); - - void join() throws InterruptedException; -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.procs; + +/** + * + */ +public interface ProcessInstance +{ + String getName(); + + boolean isRunning(); + + void start(); + + void stop(); + + void join() throws InterruptedException; +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/procs/ProcessService.java b/old/bridje-core/src/main/java/org/bridje/core/procs/ProcessService.java index 36c507282..3023b12cf 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/procs/ProcessService.java +++ b/old/bridje-core/src/main/java/org/bridje/core/procs/ProcessService.java @@ -1,33 +1,33 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.procs; - -/** - * - */ -public interface ProcessService -{ - ProcessInstance[] getAllProcess(); - - ProcessInstance findProcess(String name); - - void startAll(); - - void shutdown(); - - void join() throws InterruptedException; -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.procs; + +/** + * + */ +public interface ProcessService +{ + ProcessInstance[] getAllProcess(); + + ProcessInstance findProcess(String name); + + void startAll(); + + void shutdown(); + + void join() throws InterruptedException; +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/sql/BinaryCondition.java b/old/bridje-core/src/main/java/org/bridje/core/sql/BinaryCondition.java index 1413dae25..e055a2ec9 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/sql/BinaryCondition.java +++ b/old/bridje-core/src/main/java/org/bridje/core/sql/BinaryCondition.java @@ -1,108 +1,108 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.sql; - -import java.io.StringWriter; - -class BinaryCondition implements Condition -{ - private Operand rightOperand; - - private SQLOperator operator; - - private Operand leftOperand; - - public BinaryCondition(Operand leftOperand, SQLOperator operator, Operand rightOperand) - { - this.rightOperand = rightOperand; - this.operator = operator; - this.leftOperand = leftOperand; - } - - public Operand getRightOperand() - { - return rightOperand; - } - - public void setRightOperand(Operand rightOperand) - { - this.rightOperand = rightOperand; - } - - public SQLOperator getOperator() - { - return operator; - } - - public void setOperator(SQLOperator operator) - { - this.operator = operator; - } - - public Operand getLeftOperand() - { - return leftOperand; - } - - public void setLeftOperand(Operand leftOperand) - { - this.leftOperand = leftOperand; - } - - @Override - public Condition and(Condition condition) - { - return new BinaryCondition(this, SQLOperator.AND, condition); - } - - @Override - public Condition or(Condition condition) - { - return new BinaryCondition(this, SQLOperator.OR, condition); - } - - @Override - public Condition not() - { - return new UnaryCondition(SQLOperator.NOT, this); - } - - @Override - public void writeSQL(StringWriter sw) - { - sw.append("("); - writeOperand(sw, leftOperand); - sw.append(" "); - sw.append(operator.toString()); - sw.append(" "); - writeOperand(sw, rightOperand); - sw.append(")"); - } - - private void writeOperand(StringWriter sw, Operand operand) - { - if(operand != null) - { - operand.writeSQL(sw); - } - else - { - sw.append("NULL"); - } - } - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.sql; + +import java.io.StringWriter; + +class BinaryCondition implements Condition +{ + private Operand rightOperand; + + private SQLOperator operator; + + private Operand leftOperand; + + public BinaryCondition(Operand leftOperand, SQLOperator operator, Operand rightOperand) + { + this.rightOperand = rightOperand; + this.operator = operator; + this.leftOperand = leftOperand; + } + + public Operand getRightOperand() + { + return rightOperand; + } + + public void setRightOperand(Operand rightOperand) + { + this.rightOperand = rightOperand; + } + + public SQLOperator getOperator() + { + return operator; + } + + public void setOperator(SQLOperator operator) + { + this.operator = operator; + } + + public Operand getLeftOperand() + { + return leftOperand; + } + + public void setLeftOperand(Operand leftOperand) + { + this.leftOperand = leftOperand; + } + + @Override + public Condition and(Condition condition) + { + return new BinaryCondition(this, SQLOperator.AND, condition); + } + + @Override + public Condition or(Condition condition) + { + return new BinaryCondition(this, SQLOperator.OR, condition); + } + + @Override + public Condition not() + { + return new UnaryCondition(SQLOperator.NOT, this); + } + + @Override + public void writeSQL(StringWriter sw) + { + sw.append("("); + writeOperand(sw, leftOperand); + sw.append(" "); + sw.append(operator.toString()); + sw.append(" "); + writeOperand(sw, rightOperand); + sw.append(")"); + } + + private void writeOperand(StringWriter sw, Operand operand) + { + if(operand != null) + { + operand.writeSQL(sw); + } + else + { + sw.append("NULL"); + } + } + +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/sql/Column.java b/old/bridje-core/src/main/java/org/bridje/core/sql/Column.java index c7a2bf32b..580b45bea 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/sql/Column.java +++ b/old/bridje-core/src/main/java/org/bridje/core/sql/Column.java @@ -1,100 +1,100 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.sql; - -import java.io.StringWriter; - -public class Column implements ColumnExpresion -{ - private final Table table; - - private final String name; - - public Column(Table table, String name) - { - this.table = table; - this.name = name; - } - - public Table getTable() - { - return table; - } - - public String getName() - { - return name; - } - - public Condition isNull() - { - return new BinaryCondition(this, SQLOperator.IS, null); - } - - public Condition isNotNull() - { - return new BinaryCondition(this, SQLOperator.IS, null).not(); - } - - public OrderExpression asc() - { - return new OrderExpression(this, "ASC"); - } - - public OrderExpression desc() - { - return new OrderExpression(this, "DESC"); - } - - @Override - public Condition eq(ColumnExpresion exp) - { - return new BinaryCondition(this, SQLOperator.EQ, exp); - } - - @Override - public Condition gt(ColumnExpresion exp) - { - return new BinaryCondition(this, SQLOperator.GT, exp); - } - - @Override - public Condition ge(ColumnExpresion exp) - { - return new BinaryCondition(this, SQLOperator.GE, exp); - } - - @Override - public Condition lt(ColumnExpresion exp) - { - return new BinaryCondition(this, SQLOperator.LT, exp); - } - - @Override - public Condition le(ColumnExpresion exp) - { - return new BinaryCondition(this, SQLOperator.LE, exp); - } - - @Override - public void writeSQL(StringWriter sw) - { - table.writeSQL(sw); - sw.append("."); - sw.append(name); - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.sql; + +import java.io.StringWriter; + +public class Column implements ColumnExpresion +{ + private final Table table; + + private final String name; + + public Column(Table table, String name) + { + this.table = table; + this.name = name; + } + + public Table getTable() + { + return table; + } + + public String getName() + { + return name; + } + + public Condition isNull() + { + return new BinaryCondition(this, SQLOperator.IS, null); + } + + public Condition isNotNull() + { + return new BinaryCondition(this, SQLOperator.IS, null).not(); + } + + public OrderExpression asc() + { + return new OrderExpression(this, "ASC"); + } + + public OrderExpression desc() + { + return new OrderExpression(this, "DESC"); + } + + @Override + public Condition eq(ColumnExpresion exp) + { + return new BinaryCondition(this, SQLOperator.EQ, exp); + } + + @Override + public Condition gt(ColumnExpresion exp) + { + return new BinaryCondition(this, SQLOperator.GT, exp); + } + + @Override + public Condition ge(ColumnExpresion exp) + { + return new BinaryCondition(this, SQLOperator.GE, exp); + } + + @Override + public Condition lt(ColumnExpresion exp) + { + return new BinaryCondition(this, SQLOperator.LT, exp); + } + + @Override + public Condition le(ColumnExpresion exp) + { + return new BinaryCondition(this, SQLOperator.LE, exp); + } + + @Override + public void writeSQL(StringWriter sw) + { + table.writeSQL(sw); + sw.append("."); + sw.append(name); + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/sql/ColumnExpresion.java b/old/bridje-core/src/main/java/org/bridje/core/sql/ColumnExpresion.java index 620a2ad8c..3820b2ed3 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/sql/ColumnExpresion.java +++ b/old/bridje-core/src/main/java/org/bridje/core/sql/ColumnExpresion.java @@ -1,30 +1,30 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.sql; - -public interface ColumnExpresion extends Operand -{ - Condition eq(ColumnExpresion exp); - - Condition gt(ColumnExpresion exp); - - Condition ge(ColumnExpresion exp); - - Condition lt(ColumnExpresion exp); - - Condition le(ColumnExpresion exp); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.sql; + +public interface ColumnExpresion extends Operand +{ + Condition eq(ColumnExpresion exp); + + Condition gt(ColumnExpresion exp); + + Condition ge(ColumnExpresion exp); + + Condition lt(ColumnExpresion exp); + + Condition le(ColumnExpresion exp); +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/sql/Condition.java b/old/bridje-core/src/main/java/org/bridje/core/sql/Condition.java index 1126da956..42b861aca 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/sql/Condition.java +++ b/old/bridje-core/src/main/java/org/bridje/core/sql/Condition.java @@ -1,29 +1,29 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.sql; - -/** - * - */ -public interface Condition extends Operand -{ - Condition and(Condition condition); - - Condition or(Condition condition); - - Condition not(); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.sql; + +/** + * + */ +public interface Condition extends Operand +{ + Condition and(Condition condition); + + Condition or(Condition condition); + + Condition not(); +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/sql/DeleteFromStep.java b/old/bridje-core/src/main/java/org/bridje/core/sql/DeleteFromStep.java index 0a5a7aadb..a12357d70 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/sql/DeleteFromStep.java +++ b/old/bridje-core/src/main/java/org/bridje/core/sql/DeleteFromStep.java @@ -1,25 +1,25 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.sql; - -/** - * - */ -public interface DeleteFromStep -{ - UpdateWhereStep from(TableExpression from); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.sql; + +/** + * + */ +public interface DeleteFromStep +{ + UpdateWhereStep from(TableExpression from); +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/sql/FromStep.java b/old/bridje-core/src/main/java/org/bridje/core/sql/FromStep.java index 63db3c392..05fb8273a 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/sql/FromStep.java +++ b/old/bridje-core/src/main/java/org/bridje/core/sql/FromStep.java @@ -1,22 +1,22 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.sql; - -public interface FromStep extends SQLQuery -{ - SelectWhereStep from(TableExpression table); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.sql; + +public interface FromStep extends SQLQuery +{ + SelectWhereStep from(TableExpression table); +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/sql/GroupByStep.java b/old/bridje-core/src/main/java/org/bridje/core/sql/GroupByStep.java index 597b76a79..78a592814 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/sql/GroupByStep.java +++ b/old/bridje-core/src/main/java/org/bridje/core/sql/GroupByStep.java @@ -1,22 +1,22 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.sql; - -public interface GroupByStep extends OrderStep -{ - HavingStep groupBy(OrderExpression... groupByExp); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.sql; + +public interface GroupByStep extends OrderStep +{ + HavingStep groupBy(OrderExpression... groupByExp); +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/sql/HavingStep.java b/old/bridje-core/src/main/java/org/bridje/core/sql/HavingStep.java index 22124a0cd..96c82cc43 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/sql/HavingStep.java +++ b/old/bridje-core/src/main/java/org/bridje/core/sql/HavingStep.java @@ -1,25 +1,25 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.sql; - -/** - * - */ -public interface HavingStep extends OrderStep -{ - OrderStep having(Condition condition); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.sql; + +/** + * + */ +public interface HavingStep extends OrderStep +{ + OrderStep having(Condition condition); +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/sql/InsertSetStep.java b/old/bridje-core/src/main/java/org/bridje/core/sql/InsertSetStep.java index 7c2d3724e..3f4f95703 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/sql/InsertSetStep.java +++ b/old/bridje-core/src/main/java/org/bridje/core/sql/InsertSetStep.java @@ -1,25 +1,25 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.sql; - -/** - * - */ -public interface InsertSetStep extends SQLQuery -{ - InsertSetStep set(Column column, Literal value); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.sql; + +/** + * + */ +public interface InsertSetStep extends SQLQuery +{ + InsertSetStep set(Column column, Literal value); +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/sql/Join.java b/old/bridje-core/src/main/java/org/bridje/core/sql/Join.java index 9861e439b..9c572f0eb 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/sql/Join.java +++ b/old/bridje-core/src/main/java/org/bridje/core/sql/Join.java @@ -1,25 +1,25 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.sql; - -/** - * - */ -public interface Join extends TableExpression -{ - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.sql; + +/** + * + */ +public interface Join extends TableExpression +{ + +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/sql/JoinImpl.java b/old/bridje-core/src/main/java/org/bridje/core/sql/JoinImpl.java index 4eba1a233..9d9814892 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/sql/JoinImpl.java +++ b/old/bridje-core/src/main/java/org/bridje/core/sql/JoinImpl.java @@ -1,103 +1,103 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.sql; - -import java.io.StringWriter; - -class JoinImpl implements Join, OnStep -{ - private TableExpression leftTable; - - private String joinType; - - private TableExpression rightTable; - - private Condition on; - - public JoinImpl(TableExpression leftTable, String joinType, TableExpression rightTable) - { - this.leftTable = leftTable; - this.joinType = joinType; - this.rightTable = rightTable; - } - - public TableExpression getLeftTable() - { - return leftTable; - } - - public void setLeftTable(TableExpression leftTable) - { - this.leftTable = leftTable; - } - - public String getJoinType() - { - return joinType; - } - - public void setJoinType(String joinType) - { - this.joinType = joinType; - } - - public TableExpression getRightTable() - { - return rightTable; - } - - public void setRightTable(TableExpression rightTable) - { - this.rightTable = rightTable; - } - - public Condition getOn() - { - return on; - } - - public void setOn(Condition on) - { - this.on = on; - } - - @Override - public OnStep innerJoin(TableExpression exp) - { - return new JoinImpl(this, "INNER", exp); - } - - @Override - public void writeSQL(StringWriter sw) - { - leftTable.writeSQL(sw); - sw.write(" "); - sw.write(joinType); - sw.write(" JOIN "); - rightTable.writeSQL(sw); - sw.write(" ON "); - on.writeSQL(sw); - } - - @Override - public Join on(Condition condition) - { - on = condition; - return this; - } - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.sql; + +import java.io.StringWriter; + +class JoinImpl implements Join, OnStep +{ + private TableExpression leftTable; + + private String joinType; + + private TableExpression rightTable; + + private Condition on; + + public JoinImpl(TableExpression leftTable, String joinType, TableExpression rightTable) + { + this.leftTable = leftTable; + this.joinType = joinType; + this.rightTable = rightTable; + } + + public TableExpression getLeftTable() + { + return leftTable; + } + + public void setLeftTable(TableExpression leftTable) + { + this.leftTable = leftTable; + } + + public String getJoinType() + { + return joinType; + } + + public void setJoinType(String joinType) + { + this.joinType = joinType; + } + + public TableExpression getRightTable() + { + return rightTable; + } + + public void setRightTable(TableExpression rightTable) + { + this.rightTable = rightTable; + } + + public Condition getOn() + { + return on; + } + + public void setOn(Condition on) + { + this.on = on; + } + + @Override + public OnStep innerJoin(TableExpression exp) + { + return new JoinImpl(this, "INNER", exp); + } + + @Override + public void writeSQL(StringWriter sw) + { + leftTable.writeSQL(sw); + sw.write(" "); + sw.write(joinType); + sw.write(" JOIN "); + rightTable.writeSQL(sw); + sw.write(" ON "); + on.writeSQL(sw); + } + + @Override + public Join on(Condition condition) + { + on = condition; + return this; + } + +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/sql/Literal.java b/old/bridje-core/src/main/java/org/bridje/core/sql/Literal.java index c45a9e9cd..b6c13378c 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/sql/Literal.java +++ b/old/bridje-core/src/main/java/org/bridje/core/sql/Literal.java @@ -1,75 +1,75 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.sql; - -import java.io.StringWriter; - -/** - * - */ -public class Literal implements ColumnExpresion -{ - private final Object literal; - - public Literal(Object literal) - { - this.literal = literal; - } - - @Override - public Condition eq(ColumnExpresion exp) - { - return new BinaryCondition(this, SQLOperator.EQ, exp); - } - - @Override - public Condition gt(ColumnExpresion exp) - { - return new BinaryCondition(this, SQLOperator.GT, exp); - } - - @Override - public Condition ge(ColumnExpresion exp) - { - return new BinaryCondition(this, SQLOperator.GE, exp); - } - - @Override - public Condition lt(ColumnExpresion exp) - { - return new BinaryCondition(this, SQLOperator.LT, exp); - } - - @Override - public Condition le(ColumnExpresion exp) - { - return new BinaryCondition(this, SQLOperator.LE, exp); - } - - @Override - public void writeSQL(StringWriter sw) - { - if(literal == null) - { - sw.append("NULL"); - } - else - { - sw.append(literal.toString()); - } - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.sql; + +import java.io.StringWriter; + +/** + * + */ +public class Literal implements ColumnExpresion +{ + private final Object literal; + + public Literal(Object literal) + { + this.literal = literal; + } + + @Override + public Condition eq(ColumnExpresion exp) + { + return new BinaryCondition(this, SQLOperator.EQ, exp); + } + + @Override + public Condition gt(ColumnExpresion exp) + { + return new BinaryCondition(this, SQLOperator.GT, exp); + } + + @Override + public Condition ge(ColumnExpresion exp) + { + return new BinaryCondition(this, SQLOperator.GE, exp); + } + + @Override + public Condition lt(ColumnExpresion exp) + { + return new BinaryCondition(this, SQLOperator.LT, exp); + } + + @Override + public Condition le(ColumnExpresion exp) + { + return new BinaryCondition(this, SQLOperator.LE, exp); + } + + @Override + public void writeSQL(StringWriter sw) + { + if(literal == null) + { + sw.append("NULL"); + } + else + { + sw.append(literal.toString()); + } + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/sql/OnStep.java b/old/bridje-core/src/main/java/org/bridje/core/sql/OnStep.java index 367ff9127..d5ad410b0 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/sql/OnStep.java +++ b/old/bridje-core/src/main/java/org/bridje/core/sql/OnStep.java @@ -1,25 +1,25 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.sql; - -/** - * - */ -public interface OnStep -{ - Join on(Condition condition); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.sql; + +/** + * + */ +public interface OnStep +{ + Join on(Condition condition); +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/sql/Operand.java b/old/bridje-core/src/main/java/org/bridje/core/sql/Operand.java index f2b7f56b1..ae6324d80 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/sql/Operand.java +++ b/old/bridje-core/src/main/java/org/bridje/core/sql/Operand.java @@ -1,25 +1,25 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.sql; - -/** - * - */ -public interface Operand extends SQLExpression -{ - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.sql; + +/** + * + */ +public interface Operand extends SQLExpression +{ + +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/sql/OrderExpression.java b/old/bridje-core/src/main/java/org/bridje/core/sql/OrderExpression.java index 6525637ba..c4cd89ab5 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/sql/OrderExpression.java +++ b/old/bridje-core/src/main/java/org/bridje/core/sql/OrderExpression.java @@ -1,51 +1,51 @@ - -package org.bridje.core.sql; - -import java.io.StringWriter; - -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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. - */ - -public class OrderExpression implements SQLExpression -{ - private final Column column; - - private final String orderType; - - public OrderExpression(Column column, String orderType) - { - this.column = column; - this.orderType = orderType; - } - - @Override - public void writeSQL(StringWriter sw) - { - column.writeSQL(sw); - sw.write(" "); - sw.write(orderType); - } - - public Column getColumn() - { - return column; - } - - public String getOrderType() - { - return orderType; - } -} + +package org.bridje.core.sql; + +import java.io.StringWriter; + +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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. + */ + +public class OrderExpression implements SQLExpression +{ + private final Column column; + + private final String orderType; + + public OrderExpression(Column column, String orderType) + { + this.column = column; + this.orderType = orderType; + } + + @Override + public void writeSQL(StringWriter sw) + { + column.writeSQL(sw); + sw.write(" "); + sw.write(orderType); + } + + public Column getColumn() + { + return column; + } + + public String getOrderType() + { + return orderType; + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/sql/OrderStep.java b/old/bridje-core/src/main/java/org/bridje/core/sql/OrderStep.java index 05f696122..7cceb88ea 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/sql/OrderStep.java +++ b/old/bridje-core/src/main/java/org/bridje/core/sql/OrderStep.java @@ -1,22 +1,22 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.sql; - -public interface OrderStep extends SQLQuery -{ - SQLQuery orderBy(OrderExpression... orderExp); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.sql; + +public interface OrderStep extends SQLQuery +{ + SQLQuery orderBy(OrderExpression... orderExp); +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/sql/SQLExpression.java b/old/bridje-core/src/main/java/org/bridje/core/sql/SQLExpression.java index 91c2b263c..1a79c063f 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/sql/SQLExpression.java +++ b/old/bridje-core/src/main/java/org/bridje/core/sql/SQLExpression.java @@ -1,24 +1,24 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.sql; - -import java.io.StringWriter; - -public interface SQLExpression -{ - void writeSQL(StringWriter sw); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.sql; + +import java.io.StringWriter; + +public interface SQLExpression +{ + void writeSQL(StringWriter sw); +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/sql/SQLOperator.java b/old/bridje-core/src/main/java/org/bridje/core/sql/SQLOperator.java index 781d2db79..2360c732f 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/sql/SQLOperator.java +++ b/old/bridje-core/src/main/java/org/bridje/core/sql/SQLOperator.java @@ -1,46 +1,46 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.sql; - -/** - * - */ -public enum SQLOperator -{ - IS("IS"), - EQ("="), - GT(">"), - GE(">="), - LT("<"), - LE("<="), - AND("AND"), - OR("OR"), - NOT("NOT"); - - private String value; - - private SQLOperator(String value) - { - this.value = value; - } - - @Override - public String toString() - { - return value; - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.sql; + +/** + * + */ +public enum SQLOperator +{ + IS("IS"), + EQ("="), + GT(">"), + GE(">="), + LT("<"), + LE("<="), + AND("AND"), + OR("OR"), + NOT("NOT"); + + private String value; + + private SQLOperator(String value) + { + this.value = value; + } + + @Override + public String toString() + { + return value; + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/sql/SQLQuery.java b/old/bridje-core/src/main/java/org/bridje/core/sql/SQLQuery.java index 314a8d277..f8618cfb4 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/sql/SQLQuery.java +++ b/old/bridje-core/src/main/java/org/bridje/core/sql/SQLQuery.java @@ -1,26 +1,26 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.sql; - -public interface SQLQuery -{ - /** - * Returns the string representing the SQL query of this object. - * @return A String representing the SQL query of this object. - */ - String getSQL(); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.sql; + +public interface SQLQuery +{ + /** + * Returns the string representing the SQL query of this object. + * @return A String representing the SQL query of this object. + */ + String getSQL(); +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/sql/SQLService.java b/old/bridje-core/src/main/java/org/bridje/core/sql/SQLService.java index d5a393415..1e1e9afa5 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/sql/SQLService.java +++ b/old/bridje-core/src/main/java/org/bridje/core/sql/SQLService.java @@ -1,30 +1,30 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.sql; - -public interface SQLService -{ - FromStep select(ColumnExpresion... selectExp); - - InsertSetStep insertInto(Table table); - - UpdateSetStep update(TableExpression from); - - DeleteFromStep delete(Table table); - - DeleteFromStep delete(); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.sql; + +public interface SQLService +{ + FromStep select(ColumnExpresion... selectExp); + + InsertSetStep insertInto(Table table); + + UpdateSetStep update(TableExpression from); + + DeleteFromStep delete(Table table); + + DeleteFromStep delete(); +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/sql/SelectWhereStep.java b/old/bridje-core/src/main/java/org/bridje/core/sql/SelectWhereStep.java index c9787e588..bbc516114 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/sql/SelectWhereStep.java +++ b/old/bridje-core/src/main/java/org/bridje/core/sql/SelectWhereStep.java @@ -1,22 +1,22 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.sql; - -public interface SelectWhereStep extends GroupByStep -{ - GroupByStep where(Condition condition); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.sql; + +public interface SelectWhereStep extends GroupByStep +{ + GroupByStep where(Condition condition); +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/sql/Table.java b/old/bridje-core/src/main/java/org/bridje/core/sql/Table.java index bf735b252..1e095e0be 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/sql/Table.java +++ b/old/bridje-core/src/main/java/org/bridje/core/sql/Table.java @@ -1,49 +1,49 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.sql; - -import java.io.StringWriter; - -/** - * - */ -public class Table implements TableExpression -{ - private final String name; - - public Table(String name) - { - this.name = name; - } - - public String getName() - { - return name; - } - - @Override - public OnStep innerJoin(TableExpression exp) - { - return new JoinImpl(this, "INNER", exp); - } - - @Override - public void writeSQL(StringWriter sw) - { - sw.append(name); - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.sql; + +import java.io.StringWriter; + +/** + * + */ +public class Table implements TableExpression +{ + private final String name; + + public Table(String name) + { + this.name = name; + } + + public String getName() + { + return name; + } + + @Override + public OnStep innerJoin(TableExpression exp) + { + return new JoinImpl(this, "INNER", exp); + } + + @Override + public void writeSQL(StringWriter sw) + { + sw.append(name); + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/sql/TableExpression.java b/old/bridje-core/src/main/java/org/bridje/core/sql/TableExpression.java index 10c082a4e..3f6c4a135 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/sql/TableExpression.java +++ b/old/bridje-core/src/main/java/org/bridje/core/sql/TableExpression.java @@ -1,22 +1,22 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.sql; - -public interface TableExpression extends SQLExpression -{ - OnStep innerJoin(TableExpression exp); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.sql; + +public interface TableExpression extends SQLExpression +{ + OnStep innerJoin(TableExpression exp); +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/sql/UnaryCondition.java b/old/bridje-core/src/main/java/org/bridje/core/sql/UnaryCondition.java index ff4c9c292..34bc2ec1b 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/sql/UnaryCondition.java +++ b/old/bridje-core/src/main/java/org/bridje/core/sql/UnaryCondition.java @@ -1,87 +1,87 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.sql; - -import java.io.StringWriter; - -class UnaryCondition implements Condition -{ - private final SQLOperator operator; - - private final Operand operand; - - public UnaryCondition(SQLOperator operator, Operand operand) - { - this.operator = operator; - this.operand = operand; - } - - public SQLOperator getOperator() - { - return operator; - } - - public Operand getOperand() - { - return operand; - } - - @Override - public Condition and(Condition condition) - { - return new BinaryCondition(this, SQLOperator.AND, condition); - } - - @Override - public Condition or(Condition condition) - { - return new BinaryCondition(this, SQLOperator.OR, condition); - } - - @Override - public Condition not() - { - return new UnaryCondition(SQLOperator.NOT, this); - } - - @Override - public void writeSQL(StringWriter sw) - { - sw.append("("); - if(operator == SQLOperator.NOT) - { - sw.append(" "); - sw.append(operator.toString()); - sw.append(" "); - writeOperand(sw, operand); - } - sw.append(")"); - } - - private void writeOperand(StringWriter sw, Operand operand) - { - if(operand != null) - { - operand.writeSQL(sw); - } - else - { - sw.append("NULL"); - } - } - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.sql; + +import java.io.StringWriter; + +class UnaryCondition implements Condition +{ + private final SQLOperator operator; + + private final Operand operand; + + public UnaryCondition(SQLOperator operator, Operand operand) + { + this.operator = operator; + this.operand = operand; + } + + public SQLOperator getOperator() + { + return operator; + } + + public Operand getOperand() + { + return operand; + } + + @Override + public Condition and(Condition condition) + { + return new BinaryCondition(this, SQLOperator.AND, condition); + } + + @Override + public Condition or(Condition condition) + { + return new BinaryCondition(this, SQLOperator.OR, condition); + } + + @Override + public Condition not() + { + return new UnaryCondition(SQLOperator.NOT, this); + } + + @Override + public void writeSQL(StringWriter sw) + { + sw.append("("); + if(operator == SQLOperator.NOT) + { + sw.append(" "); + sw.append(operator.toString()); + sw.append(" "); + writeOperand(sw, operand); + } + sw.append(")"); + } + + private void writeOperand(StringWriter sw, Operand operand) + { + if(operand != null) + { + operand.writeSQL(sw); + } + else + { + sw.append("NULL"); + } + } + +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/sql/UpdateSetStep.java b/old/bridje-core/src/main/java/org/bridje/core/sql/UpdateSetStep.java index 802c5a69d..f760b9b0e 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/sql/UpdateSetStep.java +++ b/old/bridje-core/src/main/java/org/bridje/core/sql/UpdateSetStep.java @@ -1,25 +1,25 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.sql; - -/** - * - */ -public interface UpdateSetStep extends UpdateWhereStep -{ - UpdateSetStep set(Column column, ColumnExpresion value); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.sql; + +/** + * + */ +public interface UpdateSetStep extends UpdateWhereStep +{ + UpdateSetStep set(Column column, ColumnExpresion value); +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/sql/UpdateWhereStep.java b/old/bridje-core/src/main/java/org/bridje/core/sql/UpdateWhereStep.java index 8b7f1294a..ac3769a59 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/sql/UpdateWhereStep.java +++ b/old/bridje-core/src/main/java/org/bridje/core/sql/UpdateWhereStep.java @@ -1,22 +1,22 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.sql; - -public interface UpdateWhereStep -{ - SQLQuery where(Condition condition); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.sql; + +public interface UpdateWhereStep +{ + SQLQuery where(Condition condition); +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/HttpException.java b/old/bridje-core/src/main/java/org/bridje/core/web/HttpException.java index 850bce981..f01fbf746 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/HttpException.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/HttpException.java @@ -1,52 +1,52 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web; - -public class HttpException extends Exception -{ - private int code; - - public HttpException(int code) - { - this.code = code; - } - - public int getCode() - { - return code; - } - - public HttpException(int code, String message) - { - super(message); - this.code = code; - } - - public HttpException(int code, String message, Throwable cause) - { - super(message, cause); - this.code = code; - } - - public HttpException(int code, Throwable cause) - { - super(cause); - this.code = code; - } - - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web; + +public class HttpException extends Exception +{ + private int code; + + public HttpException(int code) + { + this.code = code; + } + + public int getCode() + { + return code; + } + + public HttpException(int code, String message) + { + super(message); + this.code = code; + } + + public HttpException(int code, String message, Throwable cause) + { + super(message, cause); + this.code = code; + } + + public HttpException(int code, Throwable cause) + { + super(cause); + this.code = code; + } + + +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/WebManager.java b/old/bridje-core/src/main/java/org/bridje/core/web/WebManager.java index dcd3d3283..f463889a7 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/WebManager.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/WebManager.java @@ -1,35 +1,35 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web; - -/** - * A manager services that can proccess web request. - * - * This service is the starting point of every web request passed to this api. - * Usually this service will be used in a HttpServlet service method. - */ -public interface WebManager -{ - /** - * Proccess a web request, this method will create the WEBREQUEST context an - * will invoke a WebRequestChain for handling the request. - * - * @param req The WebRequest object for this request. - * @param resp The WebResponse object for this request. - */ - void proccess(WebRequest req, WebResponse resp); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web; + +/** + * A manager services that can proccess web request. + * + * This service is the starting point of every web request passed to this api. + * Usually this service will be used in a HttpServlet service method. + */ +public interface WebManager +{ + /** + * Proccess a web request, this method will create the WEBREQUEST context an + * will invoke a WebRequestChain for handling the request. + * + * @param req The WebRequest object for this request. + * @param resp The WebResponse object for this request. + */ + void proccess(WebRequest req, WebResponse resp); +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/WebMethod.java b/old/bridje-core/src/main/java/org/bridje/core/web/WebMethod.java index 385ab3af6..df030a1b7 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/WebMethod.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/WebMethod.java @@ -1,41 +1,41 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * This annotations defines a web method, that can be mapped to the especified - * path. - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) -public @interface WebMethod -{ - /** - * The web path for this method, it must be unique for the entire - * application otherwise the result of a call to this method is not - * garantied to call this especific method. - * - * @return String value witch represents the path to this method. - * (Eg: "/my-path/my-method") the starting slash is optional. - */ - String value(); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * This annotations defines a web method, that can be mapped to the especified + * path. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface WebMethod +{ + /** + * The web path for this method, it must be unique for the entire + * application otherwise the result of a call to this method is not + * garantied to call this especific method. + * + * @return String value witch represents the path to this method. + * (Eg: "/my-path/my-method") the starting slash is optional. + */ + String value(); +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/WebRequest.java b/old/bridje-core/src/main/java/org/bridje/core/web/WebRequest.java index 3f293a668..39bc6e63c 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/WebRequest.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/WebRequest.java @@ -1,32 +1,32 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web; - -/** - * An interface that especifies the information that a web request need to - * provides. - */ -public interface WebRequest -{ - /** - * The path of the http request. - * - * @return An string object witch represents the called path for this - * request. - */ - public String getRequestedPath(); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web; + +/** + * An interface that especifies the information that a web request need to + * provides. + */ +public interface WebRequest +{ + /** + * The path of the http request. + * + * @return An string object witch represents the called path for this + * request. + */ + public String getRequestedPath(); +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/WebRequestChain.java b/old/bridje-core/src/main/java/org/bridje/core/web/WebRequestChain.java index 78695b43f..c30c39b4c 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/WebRequestChain.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/WebRequestChain.java @@ -1,58 +1,58 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web; - -import org.bridje.ioc.IocContext; - -/** - * A chain controller object for the current web request being processed by the - * api. - */ -public interface WebRequestChain -{ - /** - * The web request object for the current request. - * - * @return A WebRequest object witch holds the data of the current request. - */ - public WebRequest getRequest(); - - /** - * The web response object for the current request. - * - * @return A WebResponse object witch holds the data of the current request's - * response. - */ - public WebResponse getResponse(); - - /** - * The inversion of control context for the current request. - * - * @return The IocContext of the "WEBREQUEST" scope created for the current - * request. - */ - IocContext getRequestContext(); - - /** - * Continues the chain by calling the next available handler. If no next - * handler can be found this method will return null. - * - * @return The result of the chain, may be null. - * @throws org.bridje.core.web.HttpException - */ - public Object procced() throws HttpException; -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web; + +import org.bridje.ioc.IocContext; + +/** + * A chain controller object for the current web request being processed by the + * api. + */ +public interface WebRequestChain +{ + /** + * The web request object for the current request. + * + * @return A WebRequest object witch holds the data of the current request. + */ + public WebRequest getRequest(); + + /** + * The web response object for the current request. + * + * @return A WebResponse object witch holds the data of the current request's + * response. + */ + public WebResponse getResponse(); + + /** + * The inversion of control context for the current request. + * + * @return The IocContext of the "WEBREQUEST" scope created for the current + * request. + */ + IocContext getRequestContext(); + + /** + * Continues the chain by calling the next available handler. If no next + * handler can be found this method will return null. + * + * @return The result of the chain, may be null. + * @throws org.bridje.core.web.HttpException + */ + public Object procced() throws HttpException; +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/WebRequestHandler.java b/old/bridje-core/src/main/java/org/bridje/core/web/WebRequestHandler.java index 1e32ba0f5..0d4b2e564 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/WebRequestHandler.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/WebRequestHandler.java @@ -1,35 +1,35 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web; - -/** - * A handler for the web request chain of the framework. - */ -public interface WebRequestHandler -{ - /** - * This methods will procced with the execution of the chain, if the - * implementation of this method needs to continue the chain it will need to - * call the procced method of the chain parameter passed to it. otherwise - * this method may return the result of the chain ignoring the rest of it. - * - * @param chain The current chain being proccessed. - * @return The result of the execution. - * @throws org.bridje.core.web.HttpException - */ - Object proccess(WebRequestChain chain) throws HttpException; -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web; + +/** + * A handler for the web request chain of the framework. + */ +public interface WebRequestHandler +{ + /** + * This methods will procced with the execution of the chain, if the + * implementation of this method needs to continue the chain it will need to + * call the procced method of the chain parameter passed to it. otherwise + * this method may return the result of the chain ignoring the rest of it. + * + * @param chain The current chain being proccessed. + * @return The result of the execution. + * @throws org.bridje.core.web.HttpException + */ + Object proccess(WebRequestChain chain) throws HttpException; +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/WebResponse.java b/old/bridje-core/src/main/java/org/bridje/core/web/WebResponse.java index 056ffeae7..c3ea799cd 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/WebResponse.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/WebResponse.java @@ -1,52 +1,52 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web; - -import java.io.OutputStream; - -/** - * An object witch holds the data of the current request's response. - */ -public interface WebResponse -{ - /** - * The output stream for the current request. - * - * @return An OutputStream object to outputs the result of the current - * request. - */ - public OutputStream getOutputStream(); - - /** - * Mark the response as processed, this method should be called only onece - * per request, if no handler calls this method the web api will return a - * 404 not found to the client. - */ - public void processed(); - - /** - * - * @return - */ - public boolean isProcessed(); - - /** - * - * @param code - */ - public void setStatusCode(int code); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web; + +import java.io.OutputStream; + +/** + * An object witch holds the data of the current request's response. + */ +public interface WebResponse +{ + /** + * The output stream for the current request. + * + * @return An OutputStream object to outputs the result of the current + * request. + */ + public OutputStream getOutputStream(); + + /** + * Mark the response as processed, this method should be called only onece + * per request, if no handler calls this method the web api will return a + * 404 not found to the client. + */ + public void processed(); + + /** + * + * @return + */ + public boolean isProcessed(); + + /** + * + * @param code + */ + public void setStatusCode(int code); +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/view/AbstractView.java b/old/bridje-core/src/main/java/org/bridje/core/web/view/AbstractView.java index bff88a616..02615f09f 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/view/AbstractView.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/view/AbstractView.java @@ -1,200 +1,200 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web.view; - -import java.io.InputStream; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.Unmarshaller; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlElements; -import org.bridje.vfs.VirtualFile; - -@XmlAccessorType(XmlAccessType.FIELD) -public abstract class AbstractView -{ - private static final Logger LOG = Logger.getLogger(AbstractView.class.getName()); - - @XmlElements( - { - @XmlElement(name = "extends", type = Extends.class), - @XmlElement(name = "accordion", type = Accordion.class), - @XmlElement(name = "border", type = BorderLayout.class), - @XmlElement(name = "horizontal", type = HorizontalLayout.class), - @XmlElement(name = "menubar", type = MenuBar.class), - @XmlElement(name = "section", type = Section.class), - @XmlElement(name = "tabsheet", type = TabSheet.class), - @XmlElement(name = "toolbar", type = ToolBar.class), - @XmlElement(name = "vertical", type = VerticalLayout.class) - }) - private Component content; - - public Component getContent() - { - return content; - } - - boolean isAbstract() - { - if(content instanceof Container) - { - return ((Container)content).isAbstract(); - } - return false; - } - - static Page loadPage(VirtualFile file) - { - Object obj = loadFile(file); - if(obj != null && obj instanceof Page) - { - return (Page)obj; - } - return null; - } - - static Fragment loadFragment(VirtualFile file) - { - Object obj = loadFile(file); - if(obj != null && obj instanceof Fragment) - { - return (Fragment)obj; - } - return null; - } - - private static Object loadFile(VirtualFile file) - { - InputStream is = null; - try - { - is = file.open(); - JAXBContext jaxbCtx = JAXBContext.newInstance(Page.class, Fragment.class); - Unmarshaller unm = jaxbCtx.createUnmarshaller(); - Object obj = unm.unmarshal(is); - if(obj instanceof Page || obj instanceof Fragment) - { - return obj; - } - } - catch (Exception e) - { - LOG.log(Level.SEVERE, e.getMessage(), e); - } - finally - { - if(is != null) - { - try - { - is.close(); - } - catch (Exception e) - { - LOG.log(Level.SEVERE, e.getMessage(), e); - } - } - } - return null; - } - - public void travel(ComponentVisitor visitor) - { - travel(visitor, getContent()); - } - - private void travel(ComponentVisitor visitor, Component component) - { - if(component instanceof Container) - { - travel(visitor, (Container)component); - } - if(component instanceof Widget) - { - travel(visitor, (Widget)component); - } - } - - private void travel(ComponentVisitor visitor, Container container) - { - visitor.visit(container); - for(Component comp : container.getChilds()) - { - travel(visitor, comp); - } - } - - private void travel(ComponentVisitor visitor, Widget widget) - { - visitor.visit(widget); - } - - public void travel(ContainerVisitor visitor) - { - travel(visitor, getContent()); - } - - private void travel(ContainerVisitor visitor, Component component) - { - if(component instanceof Container) - { - travel(visitor, (Container)component); - } - } - - private void travel(ContainerVisitor visitor, Container container) - { - visitor.visit(container); - for(Component comp : container.getChilds()) - { - travel(visitor, comp); - } - } - - public void travel(WidgetVisitor visitor) - { - travel(visitor, getContent()); - } - - private void travel(WidgetVisitor visitor, Component component) - { - if(component instanceof Container) - { - travel(visitor, (Container)component); - } - if(component instanceof Widget) - { - travel(visitor, (Widget)component); - } - } - - private void travel(WidgetVisitor visitor, Container container) - { - for(Component comp : container.getChilds()) - { - travel(visitor, comp); - } - } - - private void travel(WidgetVisitor visitor, Widget widget) - { - visitor.visit(widget); - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web.view; + +import java.io.InputStream; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Unmarshaller; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElements; +import org.bridje.vfs.VirtualFile; + +@XmlAccessorType(XmlAccessType.FIELD) +public abstract class AbstractView +{ + private static final Logger LOG = Logger.getLogger(AbstractView.class.getName()); + + @XmlElements( + { + @XmlElement(name = "extends", type = Extends.class), + @XmlElement(name = "accordion", type = Accordion.class), + @XmlElement(name = "border", type = BorderLayout.class), + @XmlElement(name = "horizontal", type = HorizontalLayout.class), + @XmlElement(name = "menubar", type = MenuBar.class), + @XmlElement(name = "section", type = Section.class), + @XmlElement(name = "tabsheet", type = TabSheet.class), + @XmlElement(name = "toolbar", type = ToolBar.class), + @XmlElement(name = "vertical", type = VerticalLayout.class) + }) + private Component content; + + public Component getContent() + { + return content; + } + + boolean isAbstract() + { + if(content instanceof Container) + { + return ((Container)content).isAbstract(); + } + return false; + } + + static Page loadPage(VirtualFile file) + { + Object obj = loadFile(file); + if(obj != null && obj instanceof Page) + { + return (Page)obj; + } + return null; + } + + static Fragment loadFragment(VirtualFile file) + { + Object obj = loadFile(file); + if(obj != null && obj instanceof Fragment) + { + return (Fragment)obj; + } + return null; + } + + private static Object loadFile(VirtualFile file) + { + InputStream is = null; + try + { + is = file.open(); + JAXBContext jaxbCtx = JAXBContext.newInstance(Page.class, Fragment.class); + Unmarshaller unm = jaxbCtx.createUnmarshaller(); + Object obj = unm.unmarshal(is); + if(obj instanceof Page || obj instanceof Fragment) + { + return obj; + } + } + catch (Exception e) + { + LOG.log(Level.SEVERE, e.getMessage(), e); + } + finally + { + if(is != null) + { + try + { + is.close(); + } + catch (Exception e) + { + LOG.log(Level.SEVERE, e.getMessage(), e); + } + } + } + return null; + } + + public void travel(ComponentVisitor visitor) + { + travel(visitor, getContent()); + } + + private void travel(ComponentVisitor visitor, Component component) + { + if(component instanceof Container) + { + travel(visitor, (Container)component); + } + if(component instanceof Widget) + { + travel(visitor, (Widget)component); + } + } + + private void travel(ComponentVisitor visitor, Container container) + { + visitor.visit(container); + for(Component comp : container.getChilds()) + { + travel(visitor, comp); + } + } + + private void travel(ComponentVisitor visitor, Widget widget) + { + visitor.visit(widget); + } + + public void travel(ContainerVisitor visitor) + { + travel(visitor, getContent()); + } + + private void travel(ContainerVisitor visitor, Component component) + { + if(component instanceof Container) + { + travel(visitor, (Container)component); + } + } + + private void travel(ContainerVisitor visitor, Container container) + { + visitor.visit(container); + for(Component comp : container.getChilds()) + { + travel(visitor, comp); + } + } + + public void travel(WidgetVisitor visitor) + { + travel(visitor, getContent()); + } + + private void travel(WidgetVisitor visitor, Component component) + { + if(component instanceof Container) + { + travel(visitor, (Container)component); + } + if(component instanceof Widget) + { + travel(visitor, (Widget)component); + } + } + + private void travel(WidgetVisitor visitor, Container container) + { + for(Component comp : container.getChilds()) + { + travel(visitor, comp); + } + } + + private void travel(WidgetVisitor visitor, Widget widget) + { + visitor.visit(widget); + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/view/Accordion.java b/old/bridje-core/src/main/java/org/bridje/core/web/view/Accordion.java index 8c36203cf..0e63fdc9d 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/view/Accordion.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/view/Accordion.java @@ -1,26 +1,26 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web.view; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; - -@XmlAccessorType(XmlAccessType.FIELD) -public class Accordion extends BasicContainer -{ - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web.view; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; + +@XmlAccessorType(XmlAccessType.FIELD) +public class Accordion extends BasicContainer +{ + +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/view/BasicComponent.java b/old/bridje-core/src/main/java/org/bridje/core/web/view/BasicComponent.java index 58f61a8d9..283903516 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/view/BasicComponent.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/view/BasicComponent.java @@ -1,75 +1,75 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web.view; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlTransient; - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlTransient -public abstract class BasicComponent extends Component -{ - @XmlAttribute - private String id; - - @XmlAttribute(name = "class") - private UIExpression classExpression; - - @XmlAttribute(name = "visible") - private UIExpression visibleExpression; - - public String getId() - { - return id; - } - - public String getStyleClass() - { - return classExpression.get(String.class, ""); - } - - public UIExpression getClassExpression() - { - return classExpression; - } - - public boolean getVisible() - { - return visibleExpression.get(Boolean.class, true); - } - - public UIExpression getVisibleExpression() - { - return visibleExpression; - } - - public boolean hasStyleClass(String clsName) - { - String styleClass = getStyleClass(); - String[] split = styleClass.split(" "); - for (String split1 : split) - { - if(split1.equals(clsName)) - { - return true; - } - } - return false; - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web.view; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlTransient; + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlTransient +public abstract class BasicComponent extends Component +{ + @XmlAttribute + private String id; + + @XmlAttribute(name = "class") + private UIExpression classExpression; + + @XmlAttribute(name = "visible") + private UIExpression visibleExpression; + + public String getId() + { + return id; + } + + public String getStyleClass() + { + return classExpression.get(String.class, ""); + } + + public UIExpression getClassExpression() + { + return classExpression; + } + + public boolean getVisible() + { + return visibleExpression.get(Boolean.class, true); + } + + public UIExpression getVisibleExpression() + { + return visibleExpression; + } + + public boolean hasStyleClass(String clsName) + { + String styleClass = getStyleClass(); + String[] split = styleClass.split(" "); + for (String split1 : split) + { + if(split1.equals(clsName)) + { + return true; + } + } + return false; + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/view/BasicContainer.java b/old/bridje-core/src/main/java/org/bridje/core/web/view/BasicContainer.java index 069ec23d4..729ce86da 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/view/BasicContainer.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/view/BasicContainer.java @@ -1,117 +1,117 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web.view; - -import java.util.ArrayList; -import java.util.List; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlElements; -import javax.xml.bind.annotation.XmlTransient; - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlTransient -public abstract class BasicContainer extends Container -{ - @XmlElements( - { - @XmlElement(name = "define", type = Define.class), - @XmlElement(name = "inject", type = Inject.class), - - @XmlElement(name = "vertical", type = VerticalLayout.class), - @XmlElement(name = "horizontal", type = HorizontalLayout.class), - @XmlElement(name = "border", type = BorderLayout.class), - @XmlElement(name = "menubar", type = MenuBar.class), - @XmlElement(name = "toolbar", type = ToolBar.class), - @XmlElement(name = "section", type = Section.class), - @XmlElement(name = "tabsheet", type = TabSheet.class), - @XmlElement(name = "accordion", type = Accordion.class), - - @XmlElement(name = "combobox", type = ComboBox.class), - @XmlElement(name = "datalist", type = DataList.class), - @XmlElement(name = "datatable", type = DataTable.class), - @XmlElement(name = "header", type = Header.class), - @XmlElement(name = "image", type = Image.class), - @XmlElement(name = "link", type = Link.class), - @XmlElement(name = "parag", type = Paragraph.class), - @XmlElement(name = "html", type = RawHtml.class), - @XmlElement(name = "text", type = Text.class), - @XmlElement(name = "textbox", type = TextBox.class), - @XmlElement(name = "password", type = Password.class), - @XmlElement(name = "number", type = Number.class), - @XmlElement(name = "button", type = Button.class) - }) - private List childs; - - @Override - public List getChilds() - { - return childs; - } - - @Override - void assamble(Extends ext) - { - List newChilds = new ArrayList<>(); - for (Component child : childs) - { - if(child instanceof Define) - { - Define def = (Define)child; - List overrides = ext.getOverrides(); - for (Overrides override : overrides) - { - if(override.getName().equalsIgnoreCase(def.getName())) - { - newChilds.addAll(override.getChilds()); - } - } - } - else - { - newChilds.add(child); - } - } - childs = newChilds; - super.assamble(ext); - } - - @Override - void injectFragments(UIContext context) - { - List newChilds = new ArrayList<>(); - for (Component child : childs) - { - if(child instanceof Inject) - { - Inject inj = (Inject)child; - List fragments = context.findFragments(inj.getCategory()); - for (Fragment fragment : fragments) - { - newChilds.add(fragment.getContent()); - } - } - else - { - newChilds.add(child); - } - } - childs = newChilds; - super.injectFragments(context); - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web.view; + +import java.util.ArrayList; +import java.util.List; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElements; +import javax.xml.bind.annotation.XmlTransient; + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlTransient +public abstract class BasicContainer extends Container +{ + @XmlElements( + { + @XmlElement(name = "define", type = Define.class), + @XmlElement(name = "inject", type = Inject.class), + + @XmlElement(name = "vertical", type = VerticalLayout.class), + @XmlElement(name = "horizontal", type = HorizontalLayout.class), + @XmlElement(name = "border", type = BorderLayout.class), + @XmlElement(name = "menubar", type = MenuBar.class), + @XmlElement(name = "toolbar", type = ToolBar.class), + @XmlElement(name = "section", type = Section.class), + @XmlElement(name = "tabsheet", type = TabSheet.class), + @XmlElement(name = "accordion", type = Accordion.class), + + @XmlElement(name = "combobox", type = ComboBox.class), + @XmlElement(name = "datalist", type = DataList.class), + @XmlElement(name = "datatable", type = DataTable.class), + @XmlElement(name = "header", type = Header.class), + @XmlElement(name = "image", type = Image.class), + @XmlElement(name = "link", type = Link.class), + @XmlElement(name = "parag", type = Paragraph.class), + @XmlElement(name = "html", type = RawHtml.class), + @XmlElement(name = "text", type = Text.class), + @XmlElement(name = "textbox", type = TextBox.class), + @XmlElement(name = "password", type = Password.class), + @XmlElement(name = "number", type = Number.class), + @XmlElement(name = "button", type = Button.class) + }) + private List childs; + + @Override + public List getChilds() + { + return childs; + } + + @Override + void assamble(Extends ext) + { + List newChilds = new ArrayList<>(); + for (Component child : childs) + { + if(child instanceof Define) + { + Define def = (Define)child; + List overrides = ext.getOverrides(); + for (Overrides override : overrides) + { + if(override.getName().equalsIgnoreCase(def.getName())) + { + newChilds.addAll(override.getChilds()); + } + } + } + else + { + newChilds.add(child); + } + } + childs = newChilds; + super.assamble(ext); + } + + @Override + void injectFragments(UIContext context) + { + List newChilds = new ArrayList<>(); + for (Component child : childs) + { + if(child instanceof Inject) + { + Inject inj = (Inject)child; + List fragments = context.findFragments(inj.getCategory()); + for (Fragment fragment : fragments) + { + newChilds.add(fragment.getContent()); + } + } + else + { + newChilds.add(child); + } + } + childs = newChilds; + super.injectFragments(context); + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/view/BasicWidget.java b/old/bridje-core/src/main/java/org/bridje/core/web/view/BasicWidget.java index 82870e7c8..851ce830e 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/view/BasicWidget.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/view/BasicWidget.java @@ -1,40 +1,40 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web.view; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlTransient; -import javax.xml.bind.annotation.XmlValue; - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlTransient -public class BasicWidget extends Widget -{ - @XmlValue - private UIExpression captionExpression; - - public String getCaption() - { - return captionExpression.get(String.class, ""); - } - - public UIExpression getCaptionExpression() - { - return captionExpression; - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web.view; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlTransient; +import javax.xml.bind.annotation.XmlValue; + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlTransient +public class BasicWidget extends Widget +{ + @XmlValue + private UIExpression captionExpression; + + public String getCaption() + { + return captionExpression.get(String.class, ""); + } + + public UIExpression getCaptionExpression() + { + return captionExpression; + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/view/BorderLayout.java b/old/bridje-core/src/main/java/org/bridje/core/web/view/BorderLayout.java index 0184dfc9a..da5fd109b 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/view/BorderLayout.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/view/BorderLayout.java @@ -1,96 +1,96 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web.view; - -import java.util.LinkedList; -import java.util.List; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; - -@XmlAccessorType(XmlAccessType.FIELD) -public class BorderLayout extends Container -{ - private HorizontalLayout top; - - private VerticalLayout right; - - private VerticalLayout left; - - private HorizontalLayout bottom; - - private VerticalLayout center; - - public BasicContainer getTop() - { - return top; - } - - public BasicContainer getRight() - { - return right; - } - - public BasicContainer getLeft() - { - return left; - } - - public BasicContainer getBottom() - { - return bottom; - } - - @Override - public List getChilds() - { - List childs = new LinkedList<>(); - if(top != null) - { - childs.addAll(top.getChilds()); - } - if(left != null) - { - childs.addAll(left.getChilds()); - } - if(right != null) - { - childs.addAll(right.getChilds()); - } - if(bottom != null) - { - childs.addAll(bottom.getChilds()); - } - if(center != null) - { - childs.addAll(bottom.getChilds()); - } - return childs; - } - - @Override - void assamble(Extends ext) - { - List childs = getChilds(); - for (Component child : childs) - { - if(child instanceof Container) - { - ((Container)child).assamble(ext); - } - } - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web.view; + +import java.util.LinkedList; +import java.util.List; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; + +@XmlAccessorType(XmlAccessType.FIELD) +public class BorderLayout extends Container +{ + private HorizontalLayout top; + + private VerticalLayout right; + + private VerticalLayout left; + + private HorizontalLayout bottom; + + private VerticalLayout center; + + public BasicContainer getTop() + { + return top; + } + + public BasicContainer getRight() + { + return right; + } + + public BasicContainer getLeft() + { + return left; + } + + public BasicContainer getBottom() + { + return bottom; + } + + @Override + public List getChilds() + { + List childs = new LinkedList<>(); + if(top != null) + { + childs.addAll(top.getChilds()); + } + if(left != null) + { + childs.addAll(left.getChilds()); + } + if(right != null) + { + childs.addAll(right.getChilds()); + } + if(bottom != null) + { + childs.addAll(bottom.getChilds()); + } + if(center != null) + { + childs.addAll(bottom.getChilds()); + } + return childs; + } + + @Override + void assamble(Extends ext) + { + List childs = getChilds(); + for (Component child : childs) + { + if(child instanceof Container) + { + ((Container)child).assamble(ext); + } + } + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/view/Button.java b/old/bridje-core/src/main/java/org/bridje/core/web/view/Button.java index 6471de12b..a2f81d5c7 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/view/Button.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/view/Button.java @@ -1,41 +1,41 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web.view; - -import java.util.Arrays; -import java.util.List; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; - -@XmlAccessorType(XmlAccessType.FIELD) -public class Button extends BasicWidget -{ - @XmlAttribute(name = "action") - private UIEvent action; - - public UIEvent getActionEvent() - { - return action; - } - - @Override - public List getEvents() - { - return Arrays.asList(new UIEvent[] { action }); - } +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web.view; + +import java.util.Arrays; +import java.util.List; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; + +@XmlAccessorType(XmlAccessType.FIELD) +public class Button extends BasicWidget +{ + @XmlAttribute(name = "action") + private UIEvent action; + + public UIEvent getActionEvent() + { + return action; + } + + @Override + public List getEvents() + { + return Arrays.asList(new UIEvent[] { action }); + } } \ No newline at end of file diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/view/ComboBox.java b/old/bridje-core/src/main/java/org/bridje/core/web/view/ComboBox.java index 19e62e492..1c93cdfd9 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/view/ComboBox.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/view/ComboBox.java @@ -1,40 +1,40 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web.view; - -import java.util.List; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlElements; - -@XmlAccessorType(XmlAccessType.FIELD) -public class ComboBox extends FormWidget -{ - @XmlElements( - { - @XmlElement(name = "option", type = ListItem.class), - @XmlElement(name = "options", type = ListItems.class), - @XmlElement(name = "group", type = ComboBoxGroup.class) - }) - private List options; - - public List getOptions() - { - return options; - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web.view; + +import java.util.List; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElements; + +@XmlAccessorType(XmlAccessType.FIELD) +public class ComboBox extends FormWidget +{ + @XmlElements( + { + @XmlElement(name = "option", type = ListItem.class), + @XmlElement(name = "options", type = ListItems.class), + @XmlElement(name = "group", type = ComboBoxGroup.class) + }) + private List options; + + public List getOptions() + { + return options; + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/view/ComboBoxGroup.java b/old/bridje-core/src/main/java/org/bridje/core/web/view/ComboBoxGroup.java index 8535355f0..62dec58b8 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/view/ComboBoxGroup.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/view/ComboBoxGroup.java @@ -1,56 +1,56 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web.view; - -import java.util.List; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlElements; - -@XmlAccessorType(XmlAccessType.FIELD) -public class ComboBoxGroup -{ - @XmlAttribute(name = "icon") - private UIExpression iconExpression; - - @XmlAttribute(name = "name") - private UIExpression nameExpression; - - @XmlElements( - { - @XmlElement(name = "option", type = ListItem.class), - @XmlElement(name = "options", type = ListItems.class) - }) - private List options; - - public UIExpression getIconExpression() - { - return iconExpression; - } - - public UIExpression getNameExpression() - { - return nameExpression; - } - - public List getOptions() - { - return options; - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web.view; + +import java.util.List; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElements; + +@XmlAccessorType(XmlAccessType.FIELD) +public class ComboBoxGroup +{ + @XmlAttribute(name = "icon") + private UIExpression iconExpression; + + @XmlAttribute(name = "name") + private UIExpression nameExpression; + + @XmlElements( + { + @XmlElement(name = "option", type = ListItem.class), + @XmlElement(name = "options", type = ListItems.class) + }) + private List options; + + public UIExpression getIconExpression() + { + return iconExpression; + } + + public UIExpression getNameExpression() + { + return nameExpression; + } + + public List getOptions() + { + return options; + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/view/Component.java b/old/bridje-core/src/main/java/org/bridje/core/web/view/Component.java index 179bf9264..9e7c29b1c 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/view/Component.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/view/Component.java @@ -1,39 +1,39 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web.view; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlTransient; - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlTransient -public abstract class Component -{ - @XmlTransient - private UIContext uiContext; - - UIContext getUiContext() - { - return uiContext; - } - - void setUiContext(UIContext uiContext) - { - this.uiContext = uiContext; - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web.view; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlTransient; + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlTransient +public abstract class Component +{ + @XmlTransient + private UIContext uiContext; + + UIContext getUiContext() + { + return uiContext; + } + + void setUiContext(UIContext uiContext) + { + this.uiContext = uiContext; + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/view/Container.java b/old/bridje-core/src/main/java/org/bridje/core/web/view/Container.java index 146291f5d..178dc80e6 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/view/Container.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/view/Container.java @@ -1,73 +1,73 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web.view; - -import java.util.List; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlTransient; - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlTransient -public abstract class Container extends BasicComponent -{ - public abstract List getChilds(); - - boolean isAbstract() - { - List childs = getChilds(); - for (Component child : childs) - { - if(child instanceof Define) - { - return true; - } - else if(child instanceof Container) - { - if( ((Container)child).isAbstract() ) - { - return true; - } - } - } - return false; - } - - void assamble(Extends ext) - { - List childs = getChilds(); - for (Component child : childs) - { - if(child instanceof Container) - { - ((Container)child).assamble(ext); - } - } - } - - void injectFragments(UIContext context) - { - List childs = getChilds(); - for (Component child : childs) - { - if(child instanceof Container) - { - ((Container)child).injectFragments(context); - } - } - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web.view; + +import java.util.List; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlTransient; + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlTransient +public abstract class Container extends BasicComponent +{ + public abstract List getChilds(); + + boolean isAbstract() + { + List childs = getChilds(); + for (Component child : childs) + { + if(child instanceof Define) + { + return true; + } + else if(child instanceof Container) + { + if( ((Container)child).isAbstract() ) + { + return true; + } + } + } + return false; + } + + void assamble(Extends ext) + { + List childs = getChilds(); + for (Component child : childs) + { + if(child instanceof Container) + { + ((Container)child).assamble(ext); + } + } + } + + void injectFragments(UIContext context) + { + List childs = getChilds(); + for (Component child : childs) + { + if(child instanceof Container) + { + ((Container)child).injectFragments(context); + } + } + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/view/DataList.java b/old/bridje-core/src/main/java/org/bridje/core/web/view/DataList.java index 709c8e056..ade059d4e 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/view/DataList.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/view/DataList.java @@ -1,62 +1,62 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web.view; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; - -@XmlAccessorType(XmlAccessType.FIELD) -public class DataList extends DataWidget -{ - @XmlAttribute(name = "items") - private UIExpression items; - - @XmlAttribute(name = "as") - private String as; - - private HorizontalLayout header; - - private HorizontalLayout content; - - private HorizontalLayout footer; - - public UIExpression getItems() - { - return items; - } - - public String getAs() - { - return as; - } - - public HorizontalLayout getHeader() - { - return header; - } - - public HorizontalLayout getContent() - { - return content; - } - - public HorizontalLayout getFooter() - { - return footer; - } +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web.view; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; + +@XmlAccessorType(XmlAccessType.FIELD) +public class DataList extends DataWidget +{ + @XmlAttribute(name = "items") + private UIExpression items; + + @XmlAttribute(name = "as") + private String as; + + private HorizontalLayout header; + + private HorizontalLayout content; + + private HorizontalLayout footer; + + public UIExpression getItems() + { + return items; + } + + public String getAs() + { + return as; + } + + public HorizontalLayout getHeader() + { + return header; + } + + public HorizontalLayout getContent() + { + return content; + } + + public HorizontalLayout getFooter() + { + return footer; + } } \ No newline at end of file diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/view/DataTable.java b/old/bridje-core/src/main/java/org/bridje/core/web/view/DataTable.java index 0c25d46ed..b52d86f0b 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/view/DataTable.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/view/DataTable.java @@ -1,55 +1,55 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web.view; - -import java.util.List; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlElements; - -@XmlAccessorType(XmlAccessType.FIELD) -public class DataTable extends DataWidget -{ - @XmlAttribute(name = "items") - private UIExpression items; - - @XmlAttribute(name = "as") - private String as; - - @XmlElements( - { - @XmlElement(name = "column", type = DataTableColumn.class) - }) - private List columns; - - public UIExpression getItems() - { - return items; - } - - public String getAs() - { - return as; - } - - public List getColumns() - { - return columns; - } +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web.view; + +import java.util.List; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElements; + +@XmlAccessorType(XmlAccessType.FIELD) +public class DataTable extends DataWidget +{ + @XmlAttribute(name = "items") + private UIExpression items; + + @XmlAttribute(name = "as") + private String as; + + @XmlElements( + { + @XmlElement(name = "column", type = DataTableColumn.class) + }) + private List columns; + + public UIExpression getItems() + { + return items; + } + + public String getAs() + { + return as; + } + + public List getColumns() + { + return columns; + } } \ No newline at end of file diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/view/DataTableColumn.java b/old/bridje-core/src/main/java/org/bridje/core/web/view/DataTableColumn.java index dfd1b0ece..3d378c29b 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/view/DataTableColumn.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/view/DataTableColumn.java @@ -1,50 +1,50 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web.view; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlValue; - -@XmlAccessorType(XmlAccessType.FIELD) -public class DataTableColumn -{ - @XmlAttribute(name = "header") - private UIExpression headerExpression; - - @XmlValue - private UIExpression valueExpression; - - @XmlAttribute(name = "footer") - private UIExpression footerExpression; - - public UIExpression getHeaderExpression() - { - return headerExpression; - } - - public UIExpression getValueExpression() - { - return valueExpression; - } - - public UIExpression getFooterExpression() - { - return footerExpression; - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web.view; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlValue; + +@XmlAccessorType(XmlAccessType.FIELD) +public class DataTableColumn +{ + @XmlAttribute(name = "header") + private UIExpression headerExpression; + + @XmlValue + private UIExpression valueExpression; + + @XmlAttribute(name = "footer") + private UIExpression footerExpression; + + public UIExpression getHeaderExpression() + { + return headerExpression; + } + + public UIExpression getValueExpression() + { + return valueExpression; + } + + public UIExpression getFooterExpression() + { + return footerExpression; + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/view/DataWidget.java b/old/bridje-core/src/main/java/org/bridje/core/web/view/DataWidget.java index a00fe59d7..66b871682 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/view/DataWidget.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/view/DataWidget.java @@ -1,28 +1,28 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web.view; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlTransient; - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlTransient -public class DataWidget extends Widget -{ - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web.view; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlTransient; + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlTransient +public class DataWidget extends Widget +{ + +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/view/Define.java b/old/bridje-core/src/main/java/org/bridje/core/web/view/Define.java index 59ecf2714..08848a551 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/view/Define.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/view/Define.java @@ -1,33 +1,33 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web.view; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; - -@XmlAccessorType(XmlAccessType.FIELD) -public class Define extends Component -{ - @XmlAttribute(name = "name") - private String name; - - public String getName() - { - return name; - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web.view; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; + +@XmlAccessorType(XmlAccessType.FIELD) +public class Define extends Component +{ + @XmlAttribute(name = "name") + private String name; + + public String getName() + { + return name; + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/view/Extends.java b/old/bridje-core/src/main/java/org/bridje/core/web/view/Extends.java index 4670dde7a..6f1c19de6 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/view/Extends.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/view/Extends.java @@ -1,47 +1,47 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web.view; - -import java.util.List; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlElements; - -@XmlAccessorType(XmlAccessType.FIELD) -public class Extends extends Component -{ - @XmlAttribute(name = "from") - private String from; - - @XmlElements( - { - @XmlElement(name = "override", type = Overrides.class) - }) - private List overrides; - - public String getFrom() - { - return from; - } - - public List getOverrides() - { - return overrides; - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web.view; + +import java.util.List; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElements; + +@XmlAccessorType(XmlAccessType.FIELD) +public class Extends extends Component +{ + @XmlAttribute(name = "from") + private String from; + + @XmlElements( + { + @XmlElement(name = "override", type = Overrides.class) + }) + private List overrides; + + public String getFrom() + { + return from; + } + + public List getOverrides() + { + return overrides; + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/view/FormWidget.java b/old/bridje-core/src/main/java/org/bridje/core/web/view/FormWidget.java index d654e4039..f4354b88f 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/view/FormWidget.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/view/FormWidget.java @@ -1,70 +1,70 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web.view; - -import java.util.Arrays; -import java.util.List; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlTransient; - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlTransient -public abstract class FormWidget extends Widget -{ - @XmlAttribute(name = "value") - private UIExpression valueExpression; - - @XmlAttribute(name = "placeholder") - private String placeholder; - - public String getValue() - { - return valueExpression.get(String.class, ""); - } - - public UIExpression getValueExpression() - { - return valueExpression; - } - - @Override - public List getInputs() - { - if(!valueExpression.isInputExpression()) - { - return null; - } - return Arrays.asList(new UIExpression[]{valueExpression}); - } - - public void set(Object value) - { - valueExpression.set(value); - } - - public String getPlaceholder() - { - return placeholder; - } - - public String getFieldName() - { - return valueExpression.getFieldName(); - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web.view; + +import java.util.Arrays; +import java.util.List; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlTransient; + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlTransient +public abstract class FormWidget extends Widget +{ + @XmlAttribute(name = "value") + private UIExpression valueExpression; + + @XmlAttribute(name = "placeholder") + private String placeholder; + + public String getValue() + { + return valueExpression.get(String.class, ""); + } + + public UIExpression getValueExpression() + { + return valueExpression; + } + + @Override + public List getInputs() + { + if(!valueExpression.isInputExpression()) + { + return null; + } + return Arrays.asList(new UIExpression[]{valueExpression}); + } + + public void set(Object value) + { + valueExpression.set(value); + } + + public String getPlaceholder() + { + return placeholder; + } + + public String getFieldName() + { + return valueExpression.getFieldName(); + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/view/Fragment.java b/old/bridje-core/src/main/java/org/bridje/core/web/view/Fragment.java index ce3675653..21bf27957 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/view/Fragment.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/view/Fragment.java @@ -1,48 +1,48 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web.view; - -import java.util.logging.Logger; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; - -@XmlRootElement(name = "fragment") -@XmlAccessorType(XmlAccessType.FIELD) -public class Fragment extends AbstractView -{ - private static final Logger LOG = Logger.getLogger(Fragment.class.getName()); - - @XmlAttribute(name = "category") - @XmlJavaTypeAdapter(StringArrayAdapter.class) - private String[] category; - - @XmlAttribute(name = "priority") - private Integer priority; - - public String[] getCategory() - { - return category; - } - - public Integer getPriority() - { - return priority; - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web.view; + +import java.util.logging.Logger; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; + +@XmlRootElement(name = "fragment") +@XmlAccessorType(XmlAccessType.FIELD) +public class Fragment extends AbstractView +{ + private static final Logger LOG = Logger.getLogger(Fragment.class.getName()); + + @XmlAttribute(name = "category") + @XmlJavaTypeAdapter(StringArrayAdapter.class) + private String[] category; + + @XmlAttribute(name = "priority") + private Integer priority; + + public String[] getCategory() + { + return category; + } + + public Integer getPriority() + { + return priority; + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/view/Header.java b/old/bridje-core/src/main/java/org/bridje/core/web/view/Header.java index 7206af760..f84977c9c 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/view/Header.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/view/Header.java @@ -1,25 +1,25 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web.view; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; - -@XmlAccessorType(XmlAccessType.FIELD) -public class Header extends BasicWidget -{ -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web.view; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; + +@XmlAccessorType(XmlAccessType.FIELD) +public class Header extends BasicWidget +{ +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/view/HorizontalLayout.java b/old/bridje-core/src/main/java/org/bridje/core/web/view/HorizontalLayout.java index d159dcf8e..723066954 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/view/HorizontalLayout.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/view/HorizontalLayout.java @@ -1,26 +1,26 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web.view; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; - -@XmlAccessorType(XmlAccessType.FIELD) -public class HorizontalLayout extends BasicContainer -{ - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web.view; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; + +@XmlAccessorType(XmlAccessType.FIELD) +public class HorizontalLayout extends BasicContainer +{ + +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/view/Image.java b/old/bridje-core/src/main/java/org/bridje/core/web/view/Image.java index 5026b44da..9f4d4775e 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/view/Image.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/view/Image.java @@ -1,25 +1,25 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web.view; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; - -@XmlAccessorType(XmlAccessType.FIELD) -public class Image extends BasicWidget -{ +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web.view; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; + +@XmlAccessorType(XmlAccessType.FIELD) +public class Image extends BasicWidget +{ } \ No newline at end of file diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/view/Inject.java b/old/bridje-core/src/main/java/org/bridje/core/web/view/Inject.java index 40e252122..b8124a363 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/view/Inject.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/view/Inject.java @@ -1,33 +1,33 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web.view; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; - -@XmlAccessorType(XmlAccessType.FIELD) -public class Inject extends Component -{ - @XmlAttribute(name = "category") - private String category; - - public String getCategory() - { - return category; - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web.view; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; + +@XmlAccessorType(XmlAccessType.FIELD) +public class Inject extends Component +{ + @XmlAttribute(name = "category") + private String category; + + public String getCategory() + { + return category; + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/view/Link.java b/old/bridje-core/src/main/java/org/bridje/core/web/view/Link.java index 7cfcba336..18a0242c4 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/view/Link.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/view/Link.java @@ -1,33 +1,33 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web.view; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; - -@XmlAccessorType(XmlAccessType.FIELD) -public class Link extends BasicWidget -{ - @XmlAttribute(name = "href") - private String href; - - public String getHref() - { - return href; - } +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web.view; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; + +@XmlAccessorType(XmlAccessType.FIELD) +public class Link extends BasicWidget +{ + @XmlAttribute(name = "href") + private String href; + + public String getHref() + { + return href; + } } \ No newline at end of file diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/view/ListItem.java b/old/bridje-core/src/main/java/org/bridje/core/web/view/ListItem.java index bbee6ec37..463fb9b05 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/view/ListItem.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/view/ListItem.java @@ -1,50 +1,50 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web.view; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlValue; - -@XmlAccessorType(XmlAccessType.FIELD) -public class ListItem -{ - @XmlAttribute(name = "icon") - private UIExpression iconExpression; - - @XmlAttribute(name = "value") - private UIExpression valueExpression; - - @XmlValue - private UIExpression titleExpression; - - public UIExpression getIconExpression() - { - return iconExpression; - } - - public UIExpression getValueExpression() - { - return valueExpression; - } - - public UIExpression getTitleExpression() - { - return titleExpression; - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web.view; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlValue; + +@XmlAccessorType(XmlAccessType.FIELD) +public class ListItem +{ + @XmlAttribute(name = "icon") + private UIExpression iconExpression; + + @XmlAttribute(name = "value") + private UIExpression valueExpression; + + @XmlValue + private UIExpression titleExpression; + + public UIExpression getIconExpression() + { + return iconExpression; + } + + public UIExpression getValueExpression() + { + return valueExpression; + } + + public UIExpression getTitleExpression() + { + return titleExpression; + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/view/ListItems.java b/old/bridje-core/src/main/java/org/bridje/core/web/view/ListItems.java index f183fd865..dfa8c09f7 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/view/ListItems.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/view/ListItems.java @@ -1,66 +1,66 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web.view; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlValue; - -@XmlAccessorType(XmlAccessType.FIELD) -public class ListItems -{ - @XmlAttribute(name = "list") - private UIExpression listExpression; - - @XmlAttribute(name = "as") - private String as; - - @XmlAttribute(name = "value") - private UIExpression valueExpression; - - @XmlAttribute(name = "icon") - private UIExpression iconExpression; - - @XmlValue - private UIExpression titleExpression; - - public UIExpression getListExpression() - { - return listExpression; - } - - public String getAs() - { - return as; - } - - public UIExpression getValueExpression() - { - return valueExpression; - } - - public UIExpression getIconExpression() - { - return iconExpression; - } - - public UIExpression getTitleExpression() - { - return titleExpression; - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web.view; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlValue; + +@XmlAccessorType(XmlAccessType.FIELD) +public class ListItems +{ + @XmlAttribute(name = "list") + private UIExpression listExpression; + + @XmlAttribute(name = "as") + private String as; + + @XmlAttribute(name = "value") + private UIExpression valueExpression; + + @XmlAttribute(name = "icon") + private UIExpression iconExpression; + + @XmlValue + private UIExpression titleExpression; + + public UIExpression getListExpression() + { + return listExpression; + } + + public String getAs() + { + return as; + } + + public UIExpression getValueExpression() + { + return valueExpression; + } + + public UIExpression getIconExpression() + { + return iconExpression; + } + + public UIExpression getTitleExpression() + { + return titleExpression; + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/view/MenuBar.java b/old/bridje-core/src/main/java/org/bridje/core/web/view/MenuBar.java index 1f57b9793..906877605 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/view/MenuBar.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/view/MenuBar.java @@ -1,26 +1,26 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web.view; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; - -@XmlAccessorType(XmlAccessType.FIELD) -public class MenuBar extends BasicContainer -{ - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web.view; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; + +@XmlAccessorType(XmlAccessType.FIELD) +public class MenuBar extends BasicContainer +{ + +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/view/Number.java b/old/bridje-core/src/main/java/org/bridje/core/web/view/Number.java index dd4d24c0e..d64783be1 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/view/Number.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/view/Number.java @@ -1,33 +1,33 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web.view; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; - -@XmlAccessorType(XmlAccessType.FIELD) -public class Number extends FormWidget -{ - @XmlAttribute(name = "label") - private String label; - - public String getLabel() - { - return label; - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web.view; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; + +@XmlAccessorType(XmlAccessType.FIELD) +public class Number extends FormWidget +{ + @XmlAttribute(name = "label") + private String label; + + public String getLabel() + { + return label; + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/view/Overrides.java b/old/bridje-core/src/main/java/org/bridje/core/web/view/Overrides.java index a2c3aa921..9bafa8c67 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/view/Overrides.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/view/Overrides.java @@ -1,70 +1,70 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web.view; - -import java.util.List; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlElements; - -@XmlAccessorType(XmlAccessType.FIELD) -public class Overrides extends Component -{ - @XmlElements( - { - @XmlElement(name = "define", type = Define.class), - - @XmlElement(name = "vertical", type = VerticalLayout.class), - @XmlElement(name = "horizontal", type = HorizontalLayout.class), - @XmlElement(name = "border", type = BorderLayout.class), - @XmlElement(name = "menubar", type = MenuBar.class), - @XmlElement(name = "toolbar", type = ToolBar.class), - @XmlElement(name = "section", type = Section.class), - @XmlElement(name = "tabsheet", type = TabSheet.class), - @XmlElement(name = "accordion", type = Accordion.class), - - @XmlElement(name = "combobox", type = ComboBox.class), - @XmlElement(name = "datalist", type = DataList.class), - @XmlElement(name = "datatable", type = DataTable.class), - @XmlElement(name = "header", type = Header.class), - @XmlElement(name = "image", type = Image.class), - @XmlElement(name = "link", type = Link.class), - @XmlElement(name = "parag", type = Paragraph.class), - @XmlElement(name = "html", type = RawHtml.class), - @XmlElement(name = "text", type = Text.class), - @XmlElement(name = "textbox", type = TextBox.class), - @XmlElement(name = "password", type = Password.class), - @XmlElement(name = "number", type = Number.class), - @XmlElement(name = "button", type = Button.class), - }) - private List childs; - - @XmlAttribute(name = "name") - private String name; - - public String getName() - { - return name; - } - - public List getChilds() - { - return childs; - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web.view; + +import java.util.List; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElements; + +@XmlAccessorType(XmlAccessType.FIELD) +public class Overrides extends Component +{ + @XmlElements( + { + @XmlElement(name = "define", type = Define.class), + + @XmlElement(name = "vertical", type = VerticalLayout.class), + @XmlElement(name = "horizontal", type = HorizontalLayout.class), + @XmlElement(name = "border", type = BorderLayout.class), + @XmlElement(name = "menubar", type = MenuBar.class), + @XmlElement(name = "toolbar", type = ToolBar.class), + @XmlElement(name = "section", type = Section.class), + @XmlElement(name = "tabsheet", type = TabSheet.class), + @XmlElement(name = "accordion", type = Accordion.class), + + @XmlElement(name = "combobox", type = ComboBox.class), + @XmlElement(name = "datalist", type = DataList.class), + @XmlElement(name = "datatable", type = DataTable.class), + @XmlElement(name = "header", type = Header.class), + @XmlElement(name = "image", type = Image.class), + @XmlElement(name = "link", type = Link.class), + @XmlElement(name = "parag", type = Paragraph.class), + @XmlElement(name = "html", type = RawHtml.class), + @XmlElement(name = "text", type = Text.class), + @XmlElement(name = "textbox", type = TextBox.class), + @XmlElement(name = "password", type = Password.class), + @XmlElement(name = "number", type = Number.class), + @XmlElement(name = "button", type = Button.class), + }) + private List childs; + + @XmlAttribute(name = "name") + private String name; + + public String getName() + { + return name; + } + + public List getChilds() + { + return childs; + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/view/Page.java b/old/bridje-core/src/main/java/org/bridje/core/web/view/Page.java index 93b4eb421..b187eb5d4 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/view/Page.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/view/Page.java @@ -1,106 +1,106 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web.view; - -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.logging.Logger; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; - -@XmlRootElement(name = "page") -@XmlAccessorType(XmlAccessType.FIELD) -public class Page extends AbstractView -{ - private static final Logger LOG = Logger.getLogger(Page.class.getName()); - - @XmlTransient - private final Map inputExpressions = new LinkedHashMap<>(); - - @XmlTransient - private final Map eventExpressions = new LinkedHashMap<>(); - - public boolean existsInputExpression(String encParam) - { - if(inputExpressions == null) - { - fillInputExpressionMap(); - } - return inputExpressions.containsKey(encParam); - } - - public UIExpression findInputExpression(String encParam) - { - if(inputExpressions == null) - { - fillInputExpressionMap(); - } - return inputExpressions.get(encParam); - } - - private synchronized void fillInputExpressionMap() - { - if(inputExpressions == null) - { - travel((Widget widget) -> { - if(widget.getInputs() != null) - { - for(UIExpression uiExp : widget.getInputs()) - { - inputExpressions.put(uiExp.getEncodecExpression(), uiExp); - } - } - }); - } - } - - public boolean existsEvent(String viewAction) - { - if(eventExpressions == null) - { - fillEventExpressionMap(); - } - return eventExpressions.containsKey(viewAction); - } - - public UIEvent findEvent(String encParam) - { - if(eventExpressions == null) - { - fillEventExpressionMap(); - } - return eventExpressions.get(encParam); - } - - private synchronized void fillEventExpressionMap() - { - if(eventExpressions == null) - { - travel((Widget widget) -> { - if(widget.getEvents() != null) - { - for(UIEvent uiEvent : widget.getEvents()) - { - eventExpressions.put(uiEvent.getEncodecExpression(), uiEvent); - } - } - }); - } - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web.view; + +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.logging.Logger; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; + +@XmlRootElement(name = "page") +@XmlAccessorType(XmlAccessType.FIELD) +public class Page extends AbstractView +{ + private static final Logger LOG = Logger.getLogger(Page.class.getName()); + + @XmlTransient + private final Map inputExpressions = new LinkedHashMap<>(); + + @XmlTransient + private final Map eventExpressions = new LinkedHashMap<>(); + + public boolean existsInputExpression(String encParam) + { + if(inputExpressions == null) + { + fillInputExpressionMap(); + } + return inputExpressions.containsKey(encParam); + } + + public UIExpression findInputExpression(String encParam) + { + if(inputExpressions == null) + { + fillInputExpressionMap(); + } + return inputExpressions.get(encParam); + } + + private synchronized void fillInputExpressionMap() + { + if(inputExpressions == null) + { + travel((Widget widget) -> { + if(widget.getInputs() != null) + { + for(UIExpression uiExp : widget.getInputs()) + { + inputExpressions.put(uiExp.getEncodecExpression(), uiExp); + } + } + }); + } + } + + public boolean existsEvent(String viewAction) + { + if(eventExpressions == null) + { + fillEventExpressionMap(); + } + return eventExpressions.containsKey(viewAction); + } + + public UIEvent findEvent(String encParam) + { + if(eventExpressions == null) + { + fillEventExpressionMap(); + } + return eventExpressions.get(encParam); + } + + private synchronized void fillEventExpressionMap() + { + if(eventExpressions == null) + { + travel((Widget widget) -> { + if(widget.getEvents() != null) + { + for(UIEvent uiEvent : widget.getEvents()) + { + eventExpressions.put(uiEvent.getEncodecExpression(), uiEvent); + } + } + }); + } + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/view/Paragraph.java b/old/bridje-core/src/main/java/org/bridje/core/web/view/Paragraph.java index 71fc54036..7484b5ee1 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/view/Paragraph.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/view/Paragraph.java @@ -1,26 +1,26 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web.view; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; - -@XmlAccessorType(XmlAccessType.FIELD) -public class Paragraph extends BasicWidget -{ -} - +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web.view; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; + +@XmlAccessorType(XmlAccessType.FIELD) +public class Paragraph extends BasicWidget +{ +} + diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/view/Password.java b/old/bridje-core/src/main/java/org/bridje/core/web/view/Password.java index 2c5db65f7..9c4f2af13 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/view/Password.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/view/Password.java @@ -1,33 +1,33 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web.view; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; - -@XmlAccessorType(XmlAccessType.FIELD) -public class Password extends FormWidget -{ - @XmlAttribute(name = "label") - private String label; - - public String getLabel() - { - return label; - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web.view; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; + +@XmlAccessorType(XmlAccessType.FIELD) +public class Password extends FormWidget +{ + @XmlAttribute(name = "label") + private String label; + + public String getLabel() + { + return label; + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/view/RawHtml.java b/old/bridje-core/src/main/java/org/bridje/core/web/view/RawHtml.java index 0aef58568..2ddd16bbe 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/view/RawHtml.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/view/RawHtml.java @@ -1,25 +1,25 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web.view; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; - -@XmlAccessorType(XmlAccessType.FIELD) -public class RawHtml extends BasicWidget -{ -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web.view; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; + +@XmlAccessorType(XmlAccessType.FIELD) +public class RawHtml extends BasicWidget +{ +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/view/Section.java b/old/bridje-core/src/main/java/org/bridje/core/web/view/Section.java index f66d65bd1..202b79d1e 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/view/Section.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/view/Section.java @@ -1,26 +1,26 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web.view; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; - -@XmlAccessorType(XmlAccessType.FIELD) -public class Section extends BasicContainer -{ - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web.view; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; + +@XmlAccessorType(XmlAccessType.FIELD) +public class Section extends BasicContainer +{ + +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/view/StringArrayAdapter.java b/old/bridje-core/src/main/java/org/bridje/core/web/view/StringArrayAdapter.java index a9bd3d720..6b1cabd0d 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/view/StringArrayAdapter.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/view/StringArrayAdapter.java @@ -1,38 +1,38 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web.view; - -import javax.xml.bind.annotation.adapters.XmlAdapter; - -public class StringArrayAdapter extends XmlAdapter -{ - @Override - public String marshal(String[] v) throws Exception - { - if(v == null) - { - return null; - } - return String.join(" ", v); - } - - @Override - public String[] unmarshal(String v) throws Exception - { - return v.split(" "); - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web.view; + +import javax.xml.bind.annotation.adapters.XmlAdapter; + +public class StringArrayAdapter extends XmlAdapter +{ + @Override + public String marshal(String[] v) throws Exception + { + if(v == null) + { + return null; + } + return String.join(" ", v); + } + + @Override + public String[] unmarshal(String v) throws Exception + { + return v.split(" "); + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/view/TabSheet.java b/old/bridje-core/src/main/java/org/bridje/core/web/view/TabSheet.java index 6443a3850..7feadc31b 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/view/TabSheet.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/view/TabSheet.java @@ -1,26 +1,26 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web.view; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; - -@XmlAccessorType(XmlAccessType.FIELD) -public class TabSheet extends BasicContainer -{ - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web.view; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; + +@XmlAccessorType(XmlAccessType.FIELD) +public class TabSheet extends BasicContainer +{ + +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/view/Text.java b/old/bridje-core/src/main/java/org/bridje/core/web/view/Text.java index f4a5a3f97..ff936d3f2 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/view/Text.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/view/Text.java @@ -1,25 +1,25 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web.view; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; - -@XmlAccessorType(XmlAccessType.FIELD) -public class Text extends BasicWidget -{ +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web.view; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; + +@XmlAccessorType(XmlAccessType.FIELD) +public class Text extends BasicWidget +{ } \ No newline at end of file diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/view/TextBox.java b/old/bridje-core/src/main/java/org/bridje/core/web/view/TextBox.java index 469a5fc62..3dc2af0e9 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/view/TextBox.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/view/TextBox.java @@ -1,33 +1,33 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web.view; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; - -@XmlAccessorType(XmlAccessType.FIELD) -public class TextBox extends FormWidget -{ - @XmlAttribute(name = "label") - private String label; - - public String getLabel() - { - return label; - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web.view; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; + +@XmlAccessorType(XmlAccessType.FIELD) +public class TextBox extends FormWidget +{ + @XmlAttribute(name = "label") + private String label; + + public String getLabel() + { + return label; + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/view/ToolBar.java b/old/bridje-core/src/main/java/org/bridje/core/web/view/ToolBar.java index 5b72ac9ce..e0549e286 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/view/ToolBar.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/view/ToolBar.java @@ -1,26 +1,26 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web.view; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; - -@XmlAccessorType(XmlAccessType.FIELD) -public class ToolBar extends BasicContainer -{ - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web.view; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; + +@XmlAccessorType(XmlAccessType.FIELD) +public class ToolBar extends BasicContainer +{ + +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/view/UIContext.java b/old/bridje-core/src/main/java/org/bridje/core/web/view/UIContext.java index 34c626ac6..6a503b75f 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/view/UIContext.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/view/UIContext.java @@ -1,121 +1,121 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web.view; - -import java.util.LinkedList; -import java.util.List; -import java.util.logging.Logger; -import org.bridje.vfs.VirtualFile; -import org.bridje.vfs.VirtualFolder; - -public class UIContext -{ - private static final Logger LOG = Logger.getLogger(UIContext.class.getName()); - - private final VirtualFolder rootFolder; - - public UIContext(VirtualFolder rootFolder) - { - this.rootFolder = rootFolder; - } - - public List findFragments(String category) - { - List fragments = new LinkedList<>(); - loadFragments(category, rootFolder, fragments); - return fragments; - } - - public void loadFragments(String category, VirtualFolder folder, List fragments) - { - folder.travel((VirtualFile file) -> { - if(file.getName().endsWith(".fragment.xml")) - { - Fragment fragment = AbstractView.loadFragment(file); - if(fragment != null) - { - String[] categs = fragment.getCategory(); - for (String categ : categs) - { - if(categ.equalsIgnoreCase(category)) - { - fragments.add(fragment); - } - } - } - } - }); - } - - public Page findPage(String pagePath) - { - Page page = loadPage(pagePath); - if(page != null && !page.isAbstract()) - { - Page injPage = injectFragments(page); - Page assPage = assamblePage(injPage); - - return assPage; - } - return null; - } - - private Page loadPage(String pagePath) - { - VirtualFile file = rootFolder.findFile(pagePath + ".page.xml"); - if(file == null) - { - return null; - } - return AbstractView.loadPage(file); - } - - private Page assamblePage(Page page) - { - if(page.getContent() instanceof Extends) - { - Extends ext = (Extends)page.getContent(); - String from = ext.getFrom(); - Page loadPage = loadPage(from); - if(loadPage != null) - { - Page injPage = injectFragments(loadPage); - Page assPage = assamblePage(injPage); - if(assPage != null) - { - Component content = assPage.getContent(); - if(content instanceof Container) - { - ((Container)content).assamble(ext); - } - return assPage; - } - } - return null; - } - return page; - } - - private Page injectFragments(Page page) - { - if(page.getContent() instanceof Container) - { - ((Container)page.getContent()).injectFragments(this); - } - return page; - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web.view; + +import java.util.LinkedList; +import java.util.List; +import java.util.logging.Logger; +import org.bridje.vfs.VirtualFile; +import org.bridje.vfs.VirtualFolder; + +public class UIContext +{ + private static final Logger LOG = Logger.getLogger(UIContext.class.getName()); + + private final VirtualFolder rootFolder; + + public UIContext(VirtualFolder rootFolder) + { + this.rootFolder = rootFolder; + } + + public List findFragments(String category) + { + List fragments = new LinkedList<>(); + loadFragments(category, rootFolder, fragments); + return fragments; + } + + public void loadFragments(String category, VirtualFolder folder, List fragments) + { + folder.travel((VirtualFile file) -> { + if(file.getName().endsWith(".fragment.xml")) + { + Fragment fragment = AbstractView.loadFragment(file); + if(fragment != null) + { + String[] categs = fragment.getCategory(); + for (String categ : categs) + { + if(categ.equalsIgnoreCase(category)) + { + fragments.add(fragment); + } + } + } + } + }); + } + + public Page findPage(String pagePath) + { + Page page = loadPage(pagePath); + if(page != null && !page.isAbstract()) + { + Page injPage = injectFragments(page); + Page assPage = assamblePage(injPage); + + return assPage; + } + return null; + } + + private Page loadPage(String pagePath) + { + VirtualFile file = rootFolder.findFile(pagePath + ".page.xml"); + if(file == null) + { + return null; + } + return AbstractView.loadPage(file); + } + + private Page assamblePage(Page page) + { + if(page.getContent() instanceof Extends) + { + Extends ext = (Extends)page.getContent(); + String from = ext.getFrom(); + Page loadPage = loadPage(from); + if(loadPage != null) + { + Page injPage = injectFragments(loadPage); + Page assPage = assamblePage(injPage); + if(assPage != null) + { + Component content = assPage.getContent(); + if(content instanceof Container) + { + ((Container)content).assamble(ext); + } + return assPage; + } + } + return null; + } + return page; + } + + private Page injectFragments(Page page) + { + if(page.getContent() instanceof Container) + { + ((Container)page.getContent()).injectFragments(this); + } + return page; + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/view/UIEvent.java b/old/bridje-core/src/main/java/org/bridje/core/web/view/UIEvent.java index fa33eaacd..b3149dca6 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/view/UIEvent.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/view/UIEvent.java @@ -1,107 +1,107 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web.view; - -import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; -import org.apache.commons.codec.digest.DigestUtils; - -@XmlJavaTypeAdapter(UIEventAdapter.class) -public class UIEvent -{ - private final String expression; - - private final String[] objPath; - - private final String methodName; - - private final String[] params; - - private UIEvent(String expression, String[] objPath, String methodName, String[] params) - { - this.expression = expression; - this.objPath = objPath; - this.methodName = methodName; - this.params = params; - } - - public String[] getObjPath() - { - return objPath; - } - - public String getMethodName() - { - return methodName; - } - - public String[] getParams() - { - return params; - } - - public String getExpression() - { - return expression; - } - - public String getEncodecExpression() - { - if(expression != null && !expression.trim().isEmpty()) - { - return encode(expression); - } - return null; - } - - public static UIEvent parse(String eventExpression) - { - if(eventExpression == null || eventExpression.trim().isEmpty()) - { - return null; - } - - if(!(eventExpression.lastIndexOf("${") == 0 && eventExpression.indexOf("}") == (eventExpression.length() - 1))) - { - return null; - } - - if(!eventExpression.endsWith(")")) - { - return null; - } - - String[] split = eventExpression.split("\\("); - if(split.length != 2) - { - return null; - } - - String pathObjAndMethod = split[0]; - String params = split[1]; - params = params.substring(0, params.length() - 1); - String[] pathSplit = pathObjAndMethod.split("[.]"); - String[] objPath = new String[pathSplit.length - 1]; - System.arraycopy(pathSplit, 0, objPath, 0, pathSplit.length - 1); - String methodName = pathSplit[pathSplit.length - 1]; - return new UIEvent(eventExpression, objPath, methodName, params.split(",")); - } - - private static String encode(String expression) - { - return DigestUtils.md5Hex(expression); - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web.view; + +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import org.apache.commons.codec.digest.DigestUtils; + +@XmlJavaTypeAdapter(UIEventAdapter.class) +public class UIEvent +{ + private final String expression; + + private final String[] objPath; + + private final String methodName; + + private final String[] params; + + private UIEvent(String expression, String[] objPath, String methodName, String[] params) + { + this.expression = expression; + this.objPath = objPath; + this.methodName = methodName; + this.params = params; + } + + public String[] getObjPath() + { + return objPath; + } + + public String getMethodName() + { + return methodName; + } + + public String[] getParams() + { + return params; + } + + public String getExpression() + { + return expression; + } + + public String getEncodecExpression() + { + if(expression != null && !expression.trim().isEmpty()) + { + return encode(expression); + } + return null; + } + + public static UIEvent parse(String eventExpression) + { + if(eventExpression == null || eventExpression.trim().isEmpty()) + { + return null; + } + + if(!(eventExpression.lastIndexOf("${") == 0 && eventExpression.indexOf("}") == (eventExpression.length() - 1))) + { + return null; + } + + if(!eventExpression.endsWith(")")) + { + return null; + } + + String[] split = eventExpression.split("\\("); + if(split.length != 2) + { + return null; + } + + String pathObjAndMethod = split[0]; + String params = split[1]; + params = params.substring(0, params.length() - 1); + String[] pathSplit = pathObjAndMethod.split("[.]"); + String[] objPath = new String[pathSplit.length - 1]; + System.arraycopy(pathSplit, 0, objPath, 0, pathSplit.length - 1); + String methodName = pathSplit[pathSplit.length - 1]; + return new UIEvent(eventExpression, objPath, methodName, params.split(",")); + } + + private static String encode(String expression) + { + return DigestUtils.md5Hex(expression); + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/view/UIEventAdapter.java b/old/bridje-core/src/main/java/org/bridje/core/web/view/UIEventAdapter.java index 2a932d399..1cf4ff272 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/view/UIEventAdapter.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/view/UIEventAdapter.java @@ -1,38 +1,38 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web.view; - -import javax.xml.bind.annotation.adapters.XmlAdapter; - -public class UIEventAdapter extends XmlAdapter -{ - @Override - public String marshal(UIEvent v) throws Exception - { - if(v == null) - { - return null; - } - return v.getExpression(); - } - - @Override - public UIEvent unmarshal(String v) throws Exception - { - return UIEvent.parse(v); - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web.view; + +import javax.xml.bind.annotation.adapters.XmlAdapter; + +public class UIEventAdapter extends XmlAdapter +{ + @Override + public String marshal(UIEvent v) throws Exception + { + if(v == null) + { + return null; + } + return v.getExpression(); + } + + @Override + public UIEvent unmarshal(String v) throws Exception + { + return UIEvent.parse(v); + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/view/UIExpression.java b/old/bridje-core/src/main/java/org/bridje/core/web/view/UIExpression.java index 51591d441..7c8d8ca94 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/view/UIExpression.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/view/UIExpression.java @@ -1,138 +1,138 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web.view; - -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; -import org.apache.commons.codec.digest.DigestUtils; -import org.bridje.el.ElEnviroment; -import org.bridje.tls.Tls; - -@XmlJavaTypeAdapter(UIExpressionAdapter.class) -public class UIExpression -{ - private static final Logger LOG = Logger.getLogger(UIExpression.class.getName()); - - private final String expression; - - private UIExpression(String expression) - { - this.expression = expression; - } - - public String getExpression() - { - return expression; - } - - public String getEncodecExpression() - { - if(expression != null && !expression.trim().isEmpty()) - { - return encode(expression); - } - return null; - } - - public String getFieldName() - { - String ie = expression; - if(ie != null && ie.trim().length() > 3) - { - ie = ie.substring(2, ie.length() - 1); - String[] str = ie.split("[.]"); - if(str.length > 0) - { - return str[str.length - 1]; - } - } - return null; - } - - public boolean isInputExpression() - { - if (expression != null && !expression.trim().isEmpty()) - { - return (expression.lastIndexOf("${") == 0 && expression.indexOf("}") == (expression.length() - 1)); - } - return false; - } - - public T get(Class resultCls, T ifNull) - { - try - { - if(expression == null) - { - return ifNull; - } - - T result = env().get(expression, resultCls); - if(result == null) - { - return ifNull; - } - return result; - } - catch(Exception ex) - { - LOG.log(Level.SEVERE, ex.getMessage(), ex); - } - return ifNull; - } - - public void set(Object value) - { - env().set(expression, value); - } - - public static T getVar(String varName, Class resultCls, T ifNull) - { - if(varName == null) - { - return ifNull; - } - - T result = env().getVar(varName, resultCls); - if(result == null) - { - return ifNull; - } - return result; - } - - public static void setVar(String varName, Object value) - { - env().setVar(varName, value); - } - - public static ElEnviroment env() - { - return Tls.get(ElEnviroment.class); - } - - public static UIExpression parse(String expression) - { - return new UIExpression(expression); - } - - private static String encode(String expression) - { - return DigestUtils.md5Hex(expression); - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web.view; + +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import org.apache.commons.codec.digest.DigestUtils; +import org.bridje.el.ElEnviroment; +import org.bridje.tls.Tls; + +@XmlJavaTypeAdapter(UIExpressionAdapter.class) +public class UIExpression +{ + private static final Logger LOG = Logger.getLogger(UIExpression.class.getName()); + + private final String expression; + + private UIExpression(String expression) + { + this.expression = expression; + } + + public String getExpression() + { + return expression; + } + + public String getEncodecExpression() + { + if(expression != null && !expression.trim().isEmpty()) + { + return encode(expression); + } + return null; + } + + public String getFieldName() + { + String ie = expression; + if(ie != null && ie.trim().length() > 3) + { + ie = ie.substring(2, ie.length() - 1); + String[] str = ie.split("[.]"); + if(str.length > 0) + { + return str[str.length - 1]; + } + } + return null; + } + + public boolean isInputExpression() + { + if (expression != null && !expression.trim().isEmpty()) + { + return (expression.lastIndexOf("${") == 0 && expression.indexOf("}") == (expression.length() - 1)); + } + return false; + } + + public T get(Class resultCls, T ifNull) + { + try + { + if(expression == null) + { + return ifNull; + } + + T result = env().get(expression, resultCls); + if(result == null) + { + return ifNull; + } + return result; + } + catch(Exception ex) + { + LOG.log(Level.SEVERE, ex.getMessage(), ex); + } + return ifNull; + } + + public void set(Object value) + { + env().set(expression, value); + } + + public static T getVar(String varName, Class resultCls, T ifNull) + { + if(varName == null) + { + return ifNull; + } + + T result = env().getVar(varName, resultCls); + if(result == null) + { + return ifNull; + } + return result; + } + + public static void setVar(String varName, Object value) + { + env().setVar(varName, value); + } + + public static ElEnviroment env() + { + return Tls.get(ElEnviroment.class); + } + + public static UIExpression parse(String expression) + { + return new UIExpression(expression); + } + + private static String encode(String expression) + { + return DigestUtils.md5Hex(expression); + } +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/view/UIExpressionAdapter.java b/old/bridje-core/src/main/java/org/bridje/core/web/view/UIExpressionAdapter.java index daca62999..91798c611 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/view/UIExpressionAdapter.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/view/UIExpressionAdapter.java @@ -1,39 +1,39 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web.view; - -import javax.xml.bind.annotation.adapters.XmlAdapter; - -public class UIExpressionAdapter extends XmlAdapter -{ - @Override - public String marshal(UIExpression v) throws Exception - { - if(v == null) - { - return null; - } - return v.getExpression(); - } - - @Override - public UIExpression unmarshal(String v) throws Exception - { - return UIExpression.parse(v); - } - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web.view; + +import javax.xml.bind.annotation.adapters.XmlAdapter; + +public class UIExpressionAdapter extends XmlAdapter +{ + @Override + public String marshal(UIExpression v) throws Exception + { + if(v == null) + { + return null; + } + return v.getExpression(); + } + + @Override + public UIExpression unmarshal(String v) throws Exception + { + return UIExpression.parse(v); + } + +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/view/VerticalLayout.java b/old/bridje-core/src/main/java/org/bridje/core/web/view/VerticalLayout.java index 1e9eb56d5..7ffb6e99e 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/view/VerticalLayout.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/view/VerticalLayout.java @@ -1,26 +1,26 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web.view; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; - -@XmlAccessorType(XmlAccessType.FIELD) -public class VerticalLayout extends BasicContainer -{ - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web.view; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; + +@XmlAccessorType(XmlAccessType.FIELD) +public class VerticalLayout extends BasicContainer +{ + +} diff --git a/old/bridje-core/src/main/java/org/bridje/core/web/view/Widget.java b/old/bridje-core/src/main/java/org/bridje/core/web/view/Widget.java index ff9502f65..d5a8852a6 100644 --- a/old/bridje-core/src/main/java/org/bridje/core/web/view/Widget.java +++ b/old/bridje-core/src/main/java/org/bridje/core/web/view/Widget.java @@ -1,37 +1,37 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.web.view; - -import java.util.List; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlTransient; - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlTransient -public abstract class Widget extends BasicComponent -{ - public List getEvents() - { - return null; - } - - public List getInputs() - { - return null; - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.web.view; + +import java.util.List; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlTransient; + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlTransient +public abstract class Widget extends BasicComponent +{ + public List getEvents() + { + return null; + } + + public List getInputs() + { + return null; + } +} diff --git a/old/bridje-core/src/test/java/org/bridje/core/cast/CastServiceTest.java b/old/bridje-core/src/test/java/org/bridje/core/cast/CastServiceTest.java index f58598900..f330b37f4 100644 --- a/old/bridje-core/src/test/java/org/bridje/core/cast/CastServiceTest.java +++ b/old/bridje-core/src/test/java/org/bridje/core/cast/CastServiceTest.java @@ -1,71 +1,71 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.cast; - -import org.bridje.ioc.Ioc; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * - * @author Gilberto - */ -public class CastServiceTest -{ - - public CastServiceTest() - { - } - - @BeforeClass - public static void setUpClass() - { - } - - @AfterClass - public static void tearDownClass() - { - } - - @Before - public void setUp() - { - } - - @After - public void tearDown() - { - } - - /** - * Test of cast method, of class CastService. - */ - @Test - public void testCast() - { - String str = "123"; - Integer integ = 123; - CastService castServ = Ioc.context().find(CastService.class); - Integer cast = castServ.cast(str, Integer.class); - Assert.assertEquals(integ, cast); - } - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.cast; + +import org.bridje.ioc.Ioc; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * + * @author Gilberto + */ +public class CastServiceTest +{ + + public CastServiceTest() + { + } + + @BeforeClass + public static void setUpClass() + { + } + + @AfterClass + public static void tearDownClass() + { + } + + @Before + public void setUp() + { + } + + @After + public void tearDown() + { + } + + /** + * Test of cast method, of class CastService. + */ + @Test + public void testCast() + { + String str = "123"; + Integer integ = 123; + CastService castServ = Ioc.context().find(CastService.class); + Integer cast = castServ.cast(str, Integer.class); + Assert.assertEquals(integ, cast); + } + +} diff --git a/old/bridje-core/src/test/java/org/bridje/core/cast/StringToIntCastProvider.java b/old/bridje-core/src/test/java/org/bridje/core/cast/StringToIntCastProvider.java index a1e885d4c..a2fd9f200 100644 --- a/old/bridje-core/src/test/java/org/bridje/core/cast/StringToIntCastProvider.java +++ b/old/bridje-core/src/test/java/org/bridje/core/cast/StringToIntCastProvider.java @@ -1,48 +1,48 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.core.cast; - -import org.bridje.ioc.Component; - -/** - * - * @author Gilberto - */ -@Component -public class StringToIntCastProvider implements CastProvider -{ - - @Override - public Class[] getSrcClasses() - { - return new Class[] { String.class }; - } - - @Override - public Class getDestClass() - { - return Integer.class; - } - - @Override - public Integer cast(Object object) - { - String str = (String)object; - return Integer.valueOf(str); - } - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.core.cast; + +import org.bridje.ioc.Component; + +/** + * + * @author Gilberto + */ +@Component +public class StringToIntCastProvider implements CastProvider +{ + + @Override + public Class[] getSrcClasses() + { + return new Class[] { String.class }; + } + + @Override + public Class getDestClass() + { + return Integer.class; + } + + @Override + public Integer cast(Object object) + { + String str = (String)object; + return Integer.valueOf(str); + } + +} diff --git a/old/bridje-el/pom.xml b/old/bridje-el/pom.xml index 36e1cac3f..e32aa8fde 100644 --- a/old/bridje-el/pom.xml +++ b/old/bridje-el/pom.xml @@ -1,45 +1,45 @@ - - - 4.0.0 - - - org.bridje - bridje-parent - 0.0.6-SNAPSHOT - - - bridje-el - - Bridje EL - Bridje EL API - http://www.bridje.org - - - - de.odysseus.juel - juel-api - 2.2.7 - - - de.odysseus.juel - juel-impl - 2.2.7 - - - de.odysseus.juel - juel-spi - 2.2.7 - - - - junit - junit - test - - - ${project.groupId} - bridje-ioc - ${project.version} - - - + + + 4.0.0 + + + org.bridje + bridje-parent + 0.0.6-SNAPSHOT + + + bridje-el + + Bridje EL + Bridje EL API + http://www.bridje.org + + + + de.odysseus.juel + juel-api + 2.2.7 + + + de.odysseus.juel + juel-impl + 2.2.7 + + + de.odysseus.juel + juel-spi + 2.2.7 + + + + junit + junit + test + + + ${project.groupId} + bridje-ioc + ${project.version} + + + diff --git a/old/bridje-el/src/main/java/org/bridje/el/El.java b/old/bridje-el/src/main/java/org/bridje/el/El.java index 846aad46f..b93dcb8bf 100644 --- a/old/bridje-el/src/main/java/org/bridje/el/El.java +++ b/old/bridje-el/src/main/java/org/bridje/el/El.java @@ -1,28 +1,28 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.el; - -import org.bridje.el.impl.ElFactory; -import org.bridje.ioc.IocContext; - -public class El -{ - public static ElEnviroment createElEnviroment(IocContext context) - { - return ElFactory.createElEnviroment(context); - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.el; + +import org.bridje.el.impl.ElFactory; +import org.bridje.ioc.IocContext; + +public class El +{ + public static ElEnviroment createElEnviroment(IocContext context) + { + return ElFactory.createElEnviroment(context); + } +} diff --git a/old/bridje-el/src/main/java/org/bridje/el/ElEnviroment.java b/old/bridje-el/src/main/java/org/bridje/el/ElEnviroment.java index 1b4a83cbe..87987614c 100644 --- a/old/bridje-el/src/main/java/org/bridje/el/ElEnviroment.java +++ b/old/bridje-el/src/main/java/org/bridje/el/ElEnviroment.java @@ -1,28 +1,28 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.el; - -public interface ElEnviroment -{ - T get(String expression, Class resultCls); - - void set(String expression, T value); - - T getVar(String name, Class resultCls); - - void setVar(String name, T value); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.el; + +public interface ElEnviroment +{ + T get(String expression, Class resultCls); + + void set(String expression, T value); + + T getVar(String name, Class resultCls); + + void setVar(String name, T value); +} diff --git a/old/bridje-el/src/main/java/org/bridje/el/ElTypeConverter.java b/old/bridje-el/src/main/java/org/bridje/el/ElTypeConverter.java index c0ce70a67..7b2264235 100644 --- a/old/bridje-el/src/main/java/org/bridje/el/ElTypeConverter.java +++ b/old/bridje-el/src/main/java/org/bridje/el/ElTypeConverter.java @@ -1,11 +1,11 @@ - -package org.bridje.el; - -public interface ElTypeConverter -{ - public Class[] getFromClasses(); - - public Class[] getToClasses(); - - public T convert(Object value, Class type); -} + +package org.bridje.el; + +public interface ElTypeConverter +{ + public Class[] getFromClasses(); + + public Class[] getToClasses(); + + public T convert(Object value, Class type); +} diff --git a/old/bridje-el/src/main/java/org/bridje/el/impl/ElFactory.java b/old/bridje-el/src/main/java/org/bridje/el/impl/ElFactory.java index 789787b51..8e75b54ce 100644 --- a/old/bridje-el/src/main/java/org/bridje/el/impl/ElFactory.java +++ b/old/bridje-el/src/main/java/org/bridje/el/impl/ElFactory.java @@ -1,28 +1,28 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.el.impl; - -import org.bridje.el.ElEnviroment; -import org.bridje.ioc.IocContext; - -public class ElFactory -{ - public static ElEnviroment createElEnviroment(IocContext context) - { - return new IocEnviromentImpl(context); - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.el.impl; + +import org.bridje.el.ElEnviroment; +import org.bridje.ioc.IocContext; + +public class ElFactory +{ + public static ElEnviroment createElEnviroment(IocContext context) + { + return new IocEnviromentImpl(context); + } +} diff --git a/old/bridje-el/src/main/java/org/bridje/el/impl/ExpressionFactoryImpl.java b/old/bridje-el/src/main/java/org/bridje/el/impl/ExpressionFactoryImpl.java index f9861a746..675282691 100644 --- a/old/bridje-el/src/main/java/org/bridje/el/impl/ExpressionFactoryImpl.java +++ b/old/bridje-el/src/main/java/org/bridje/el/impl/ExpressionFactoryImpl.java @@ -1,67 +1,67 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.el.impl; - -import de.odysseus.el.misc.TypeConverter; -import java.util.Properties; -import javax.annotation.PostConstruct; -import javax.el.ELContext; -import javax.el.ExpressionFactory; -import javax.el.MethodExpression; -import javax.el.ValueExpression; -import org.bridje.ioc.Component; -import org.bridje.ioc.Inject; - -@Component -class ExpressionFactoryImpl extends ExpressionFactory -{ - @Inject - private TypeConverter typeConverter; - - private ExpressionFactory factory; - - @PostConstruct - public void init() - { - factory = new de.odysseus.el.ExpressionFactoryImpl(de.odysseus.el.ExpressionFactoryImpl.Profile.JEE5, new Properties(), typeConverter); - } - - @Override - public Object coerceToType(Object obj, Class targetType) - { - return factory.coerceToType(obj, targetType); - } - - @Override - public MethodExpression createMethodExpression(ELContext context, String expression, Class expectedReturnType, Class[] expectedParamTypes) - { - return factory.createMethodExpression(context, expression, expectedReturnType, expectedParamTypes); - } - - @Override - public ValueExpression createValueExpression(ELContext context, String expression, Class expectedType) - { - return factory.createValueExpression(context, expression, expectedType); - } - - @Override - public ValueExpression createValueExpression(Object instance, Class expectedType) - { - return factory.createValueExpression(instance, expectedType); - } - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.el.impl; + +import de.odysseus.el.misc.TypeConverter; +import java.util.Properties; +import javax.annotation.PostConstruct; +import javax.el.ELContext; +import javax.el.ExpressionFactory; +import javax.el.MethodExpression; +import javax.el.ValueExpression; +import org.bridje.ioc.Component; +import org.bridje.ioc.Inject; + +@Component +class ExpressionFactoryImpl extends ExpressionFactory +{ + @Inject + private TypeConverter typeConverter; + + private ExpressionFactory factory; + + @PostConstruct + public void init() + { + factory = new de.odysseus.el.ExpressionFactoryImpl(de.odysseus.el.ExpressionFactoryImpl.Profile.JEE5, new Properties(), typeConverter); + } + + @Override + public Object coerceToType(Object obj, Class targetType) + { + return factory.coerceToType(obj, targetType); + } + + @Override + public MethodExpression createMethodExpression(ELContext context, String expression, Class expectedReturnType, Class[] expectedParamTypes) + { + return factory.createMethodExpression(context, expression, expectedReturnType, expectedParamTypes); + } + + @Override + public ValueExpression createValueExpression(ELContext context, String expression, Class expectedType) + { + return factory.createValueExpression(context, expression, expectedType); + } + + @Override + public ValueExpression createValueExpression(Object instance, Class expectedType) + { + return factory.createValueExpression(instance, expectedType); + } + +} diff --git a/old/bridje-el/src/main/java/org/bridje/el/impl/IocElContext.java b/old/bridje-el/src/main/java/org/bridje/el/impl/IocElContext.java index 11040132b..cd479c905 100644 --- a/old/bridje-el/src/main/java/org/bridje/el/impl/IocElContext.java +++ b/old/bridje-el/src/main/java/org/bridje/el/impl/IocElContext.java @@ -1,170 +1,170 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.el.impl; - -import de.odysseus.el.util.SimpleResolver; -import java.lang.reflect.Method; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import javax.el.ELContext; -import javax.el.ELResolver; -import javax.el.ExpressionFactory; -import javax.el.FunctionMapper; -import javax.el.ValueExpression; -import javax.el.VariableMapper; -import org.bridje.ioc.IocContext; - -class IocElContext extends ELContext -{ - private final ExpressionFactory factory; - - static class Functions extends FunctionMapper - { - private final ExpressionFactory factory; - - private Map map = Collections.emptyMap(); - - public Functions(ExpressionFactory factory) - { - this.factory = factory; - } - - @Override - public Method resolveFunction(String prefix, String localName) - { - return map.get(prefix + ":" + localName); - } - - public void setFunction(String prefix, String localName, Method method) - { - if (map.isEmpty()) - { - map = new HashMap<>(); - } - map.put(prefix + ":" + localName, method); - } - } - - static class Variables extends VariableMapper - { - private final ExpressionFactory factory; - - private final Map map = new HashMap<>(); - - private final IocContext context; - - public Variables(IocContext context, ExpressionFactory factory) - { - this.context = context; - this.factory = factory; - } - - @Override - public ValueExpression resolveVariable(String variable) - { - if(!map.containsKey(variable)) - { - /* - if(context.getNamedComponents().containsKey(variable)) - { - map.put(variable, factory.createValueExpression(context.getNamedComponents().get(variable), context.getNamedComponents().get(variable).getClass())); - } - */ - } - return map.get(variable); - } - - @Override - public ValueExpression setVariable(String variable, ValueExpression expression) - { - if(expression == null) - { - map.remove(variable); - return null; - } - return map.put(variable, expression); - } - } - - private Functions functions; - - private Variables variables; - - private ELResolver resolver; - - private final IocContext context; - - public IocElContext(IocContext context, ExpressionFactory factory) - { - this.context = context; - this.factory = factory; - } - - public void setFunction(String prefix, String localName, Method method) - { - if (functions == null) - { - functions = new Functions(factory); - } - functions.setFunction(prefix, localName, method); - } - - public ValueExpression setVariable(String name, ValueExpression expression) - { - if (variables == null) - { - variables = new Variables(context, factory); - } - return variables.setVariable(name, expression); - } - - @Override - public FunctionMapper getFunctionMapper() - { - if (functions == null) - { - functions = new Functions(factory); - } - return functions; - } - - @Override - public VariableMapper getVariableMapper() - { - if (variables == null) - { - variables = new Variables(context, factory); - } - return variables; - } - - @Override - public ELResolver getELResolver() - { - if (resolver == null) - { - resolver = new SimpleResolver(); - } - return resolver; - } - - public void setELResolver(ELResolver resolver) - { - this.resolver = resolver; - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.el.impl; + +import de.odysseus.el.util.SimpleResolver; +import java.lang.reflect.Method; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import javax.el.ELContext; +import javax.el.ELResolver; +import javax.el.ExpressionFactory; +import javax.el.FunctionMapper; +import javax.el.ValueExpression; +import javax.el.VariableMapper; +import org.bridje.ioc.IocContext; + +class IocElContext extends ELContext +{ + private final ExpressionFactory factory; + + static class Functions extends FunctionMapper + { + private final ExpressionFactory factory; + + private Map map = Collections.emptyMap(); + + public Functions(ExpressionFactory factory) + { + this.factory = factory; + } + + @Override + public Method resolveFunction(String prefix, String localName) + { + return map.get(prefix + ":" + localName); + } + + public void setFunction(String prefix, String localName, Method method) + { + if (map.isEmpty()) + { + map = new HashMap<>(); + } + map.put(prefix + ":" + localName, method); + } + } + + static class Variables extends VariableMapper + { + private final ExpressionFactory factory; + + private final Map map = new HashMap<>(); + + private final IocContext context; + + public Variables(IocContext context, ExpressionFactory factory) + { + this.context = context; + this.factory = factory; + } + + @Override + public ValueExpression resolveVariable(String variable) + { + if(!map.containsKey(variable)) + { + /* + if(context.getNamedComponents().containsKey(variable)) + { + map.put(variable, factory.createValueExpression(context.getNamedComponents().get(variable), context.getNamedComponents().get(variable).getClass())); + } + */ + } + return map.get(variable); + } + + @Override + public ValueExpression setVariable(String variable, ValueExpression expression) + { + if(expression == null) + { + map.remove(variable); + return null; + } + return map.put(variable, expression); + } + } + + private Functions functions; + + private Variables variables; + + private ELResolver resolver; + + private final IocContext context; + + public IocElContext(IocContext context, ExpressionFactory factory) + { + this.context = context; + this.factory = factory; + } + + public void setFunction(String prefix, String localName, Method method) + { + if (functions == null) + { + functions = new Functions(factory); + } + functions.setFunction(prefix, localName, method); + } + + public ValueExpression setVariable(String name, ValueExpression expression) + { + if (variables == null) + { + variables = new Variables(context, factory); + } + return variables.setVariable(name, expression); + } + + @Override + public FunctionMapper getFunctionMapper() + { + if (functions == null) + { + functions = new Functions(factory); + } + return functions; + } + + @Override + public VariableMapper getVariableMapper() + { + if (variables == null) + { + variables = new Variables(context, factory); + } + return variables; + } + + @Override + public ELResolver getELResolver() + { + if (resolver == null) + { + resolver = new SimpleResolver(); + } + return resolver; + } + + public void setELResolver(ELResolver resolver) + { + this.resolver = resolver; + } +} diff --git a/old/bridje-el/src/main/java/org/bridje/el/impl/IocEnviromentImpl.java b/old/bridje-el/src/main/java/org/bridje/el/impl/IocEnviromentImpl.java index 8f93af305..f4430b1b8 100644 --- a/old/bridje-el/src/main/java/org/bridje/el/impl/IocEnviromentImpl.java +++ b/old/bridje-el/src/main/java/org/bridje/el/impl/IocEnviromentImpl.java @@ -1,69 +1,69 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.el.impl; - -import org.bridje.el.ElEnviroment; -import javax.el.ExpressionFactory; -import javax.el.ValueExpression; -import org.bridje.ioc.Ioc; -import org.bridje.ioc.IocContext; - -class IocEnviromentImpl implements ElEnviroment -{ - private final IocElContext context; - - private final ExpressionFactory factory; - - public IocEnviromentImpl(IocContext context) - { - this.factory = Ioc.context().find(ExpressionFactoryImpl.class); - this.context = new IocElContext(context, factory); - } - - @Override - public T get(String expresion, Class resultCls) - { - ValueExpression valueExp = factory.createValueExpression(context, expresion, resultCls); - return (T)valueExp.getValue(context); - } - - @Override - public void set(String expresion, T value) - { - ValueExpression valueExp = factory.createValueExpression(context, expresion, value.getClass()); - valueExp.setValue(context, value); - } - - @Override - public void setVar(String name, T value) - { - if(value == null) - { - context.setVariable(name, null); - } - else - { - context.setVariable(name, factory.createValueExpression(value, value.getClass())); - } - } - - @Override - public T getVar(String name, Class resultCls) - { - return get("${" + name + "}", resultCls); - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.el.impl; + +import org.bridje.el.ElEnviroment; +import javax.el.ExpressionFactory; +import javax.el.ValueExpression; +import org.bridje.ioc.Ioc; +import org.bridje.ioc.IocContext; + +class IocEnviromentImpl implements ElEnviroment +{ + private final IocElContext context; + + private final ExpressionFactory factory; + + public IocEnviromentImpl(IocContext context) + { + this.factory = Ioc.context().find(ExpressionFactoryImpl.class); + this.context = new IocElContext(context, factory); + } + + @Override + public T get(String expresion, Class resultCls) + { + ValueExpression valueExp = factory.createValueExpression(context, expresion, resultCls); + return (T)valueExp.getValue(context); + } + + @Override + public void set(String expresion, T value) + { + ValueExpression valueExp = factory.createValueExpression(context, expresion, value.getClass()); + valueExp.setValue(context, value); + } + + @Override + public void setVar(String name, T value) + { + if(value == null) + { + context.setVariable(name, null); + } + else + { + context.setVariable(name, factory.createValueExpression(value, value.getClass())); + } + } + + @Override + public T getVar(String name, Class resultCls) + { + return get("${" + name + "}", resultCls); + } +} diff --git a/old/bridje-el/src/main/java/org/bridje/el/impl/TypeConverterImpl.java b/old/bridje-el/src/main/java/org/bridje/el/impl/TypeConverterImpl.java index fd710dc87..1a4a2cda2 100644 --- a/old/bridje-el/src/main/java/org/bridje/el/impl/TypeConverterImpl.java +++ b/old/bridje-el/src/main/java/org/bridje/el/impl/TypeConverterImpl.java @@ -1,91 +1,91 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.el.impl; - -import org.bridje.el.ElTypeConverter; -import de.odysseus.el.misc.TypeConverter; -import java.util.HashMap; -import java.util.Map; -import javax.annotation.PostConstruct; -import javax.el.ELException; -import org.bridje.ioc.Component; -import org.bridje.ioc.Inject; - -@Component -class TypeConverterImpl implements TypeConverter -{ - @Inject - private ElTypeConverter[] typeConverter; - - private Map> convertMap; - - @PostConstruct - public void init() - { - convertMap = new HashMap<>(); - for (ElTypeConverter converter : typeConverter) - { - Class[] toClasses = converter.getToClasses(); - Class[] fromClasses = converter.getFromClasses(); - for (Class fromClasse : fromClasses) - { - Map map = convertMap.get(fromClasse); - if(map == null) - { - map = new HashMap<>(); - convertMap.put(fromClasse, map); - } - for (Class toClazz : toClasses) - { - map.put(toClazz, converter); - } - } - } - } - - @Override - public T convert(Object value, Class type) throws ELException - { - if(value == null) - { - return null; - } - - if(type.getClass() == value.getClass()) - { - return (T)value; - } - - if(type.getClass().isAssignableFrom(value.getClass())) - { - return (T)value; - } - - Map map = convertMap.get(value.getClass()); - if(map != null) - { - ElTypeConverter converter = map.get(type); - if(converter != null) - { - return converter.convert(value, type); - } - } - - return TypeConverter.DEFAULT.convert(value, type); - } - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.el.impl; + +import org.bridje.el.ElTypeConverter; +import de.odysseus.el.misc.TypeConverter; +import java.util.HashMap; +import java.util.Map; +import javax.annotation.PostConstruct; +import javax.el.ELException; +import org.bridje.ioc.Component; +import org.bridje.ioc.Inject; + +@Component +class TypeConverterImpl implements TypeConverter +{ + @Inject + private ElTypeConverter[] typeConverter; + + private Map> convertMap; + + @PostConstruct + public void init() + { + convertMap = new HashMap<>(); + for (ElTypeConverter converter : typeConverter) + { + Class[] toClasses = converter.getToClasses(); + Class[] fromClasses = converter.getFromClasses(); + for (Class fromClasse : fromClasses) + { + Map map = convertMap.get(fromClasse); + if(map == null) + { + map = new HashMap<>(); + convertMap.put(fromClasse, map); + } + for (Class toClazz : toClasses) + { + map.put(toClazz, converter); + } + } + } + } + + @Override + public T convert(Object value, Class type) throws ELException + { + if(value == null) + { + return null; + } + + if(type.getClass() == value.getClass()) + { + return (T)value; + } + + if(type.getClass().isAssignableFrom(value.getClass())) + { + return (T)value; + } + + Map map = convertMap.get(value.getClass()); + if(map != null) + { + ElTypeConverter converter = map.get(type); + if(converter != null) + { + return converter.convert(value, type); + } + } + + return TypeConverter.DEFAULT.convert(value, type); + } + +} diff --git a/old/bridje-tls/pom.xml b/old/bridje-tls/pom.xml index b8efc8b00..ad07ad28b 100644 --- a/old/bridje-tls/pom.xml +++ b/old/bridje-tls/pom.xml @@ -1,29 +1,29 @@ - - - 4.0.0 - - - org.bridje - bridje-parent - 0.0.6-SNAPSHOT - - - bridje-tls - - Bridje Tls - Bridje Thread Local Storage API - http://www.bridje.org - - - - junit - junit - test - - - ${project.groupId} - bridje-ioc - ${project.version} - - - + + + 4.0.0 + + + org.bridje + bridje-parent + 0.0.6-SNAPSHOT + + + bridje-tls + + Bridje Tls + Bridje Thread Local Storage API + http://www.bridje.org + + + + junit + junit + test + + + ${project.groupId} + bridje-ioc + ${project.version} + + + diff --git a/old/bridje-tls/src/main/java/org/bridje/tls/Tls.java b/old/bridje-tls/src/main/java/org/bridje/tls/Tls.java index 65cc94283..8c3552dad 100644 --- a/old/bridje-tls/src/main/java/org/bridje/tls/Tls.java +++ b/old/bridje-tls/src/main/java/org/bridje/tls/Tls.java @@ -1,67 +1,67 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.tls; - -import org.bridje.ioc.Ioc; - -/** - * Facade to thread local storage (tls) service. {@link TlsService} - */ -public class Tls -{ - private static TlsService tlsServ; - - /** - * Get the last object of the cls Class that was put in the thread local - * storage. - *

- * @param The type of the object to look for. - * @param cls The class of the object to look for. - *

- * @return The last object of the specified class that was put in the thread - * local storage, or null if none can be found. - */ - public static T get(Class cls) - { - if (tlsServ == null) - { - tlsServ = Ioc.context().find(TlsService.class); - } - return tlsServ.get(cls); - } - - /** - * This method puts all the data objects on the internal thread - * local storage an executes the {@link TlsAction}. - *

- * @param The type of the resulting object for the action. - * @param action The action to be executed. - * @param data The data that must be available for the action. - *

- * @return The object returned by the {@link TlsAction#execute()} method. - *

- * @throws Exception If {@link TlsAction#execute()} throw an exception. - */ - public static T doAs(TlsAction action, Object... data) throws Exception - { - if (tlsServ == null) - { - tlsServ = Ioc.context().find(TlsService.class); - } - return tlsServ.doAs(action, data); - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.tls; + +import org.bridje.ioc.Ioc; + +/** + * Facade to thread local storage (tls) service. {@link TlsService} + */ +public class Tls +{ + private static TlsService tlsServ; + + /** + * Get the last object of the cls Class that was put in the thread local + * storage. + *

+ * @param The type of the object to look for. + * @param cls The class of the object to look for. + *

+ * @return The last object of the specified class that was put in the thread + * local storage, or null if none can be found. + */ + public static T get(Class cls) + { + if (tlsServ == null) + { + tlsServ = Ioc.context().find(TlsService.class); + } + return tlsServ.get(cls); + } + + /** + * This method puts all the data objects on the internal thread + * local storage an executes the {@link TlsAction}. + *

+ * @param The type of the resulting object for the action. + * @param action The action to be executed. + * @param data The data that must be available for the action. + *

+ * @return The object returned by the {@link TlsAction#execute()} method. + *

+ * @throws Exception If {@link TlsAction#execute()} throw an exception. + */ + public static T doAs(TlsAction action, Object... data) throws Exception + { + if (tlsServ == null) + { + tlsServ = Ioc.context().find(TlsService.class); + } + return tlsServ.doAs(action, data); + } +} diff --git a/old/bridje-tls/src/main/java/org/bridje/tls/TlsAction.java b/old/bridje-tls/src/main/java/org/bridje/tls/TlsAction.java index 0d09db49e..50baa01c2 100644 --- a/old/bridje-tls/src/main/java/org/bridje/tls/TlsAction.java +++ b/old/bridje-tls/src/main/java/org/bridje/tls/TlsAction.java @@ -1,39 +1,39 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.tls; - -/** - * Represents an action that can be executed and can access to the data of the - * current thread, that was made available on the - * {@link TlsService#doAs(org.bridje.core.tls.TlsAction, java.lang.Object...) doAs} - * method. - *

- * @param The type of the returning object for the action. - */ -@FunctionalInterface -public interface TlsAction -{ - /** - * Executes the action. this method is called on the - * {@link TlsService#doAs(org.bridje.core.tls.TlsAction, java.lang.Object...) doAs} - * method. - *

- * @return The action result. - * @throws java.lang.Exception Any exception throw by the action. - */ - T execute() throws Exception; -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.tls; + +/** + * Represents an action that can be executed and can access to the data of the + * current thread, that was made available on the + * {@link TlsService#doAs(org.bridje.core.tls.TlsAction, java.lang.Object...) doAs} + * method. + *

+ * @param The type of the returning object for the action. + */ +@FunctionalInterface +public interface TlsAction +{ + /** + * Executes the action. this method is called on the + * {@link TlsService#doAs(org.bridje.core.tls.TlsAction, java.lang.Object...) doAs} + * method. + *

+ * @return The action result. + * @throws java.lang.Exception Any exception throw by the action. + */ + T execute() throws Exception; +} diff --git a/old/bridje-tls/src/main/java/org/bridje/tls/TlsService.java b/old/bridje-tls/src/main/java/org/bridje/tls/TlsService.java index a601e8e36..d0c108c66 100644 --- a/old/bridje-tls/src/main/java/org/bridje/tls/TlsService.java +++ b/old/bridje-tls/src/main/java/org/bridje/tls/TlsService.java @@ -1,50 +1,50 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.tls; - -/** - * This service allows you to execute an action with a group of data objects - * that will be available in the thread. - */ -public interface TlsService -{ - /** - * This method puts all the data objects on the internal thread - * local storage an executes the {@link TlsAction}. - *

- * @param The type of the resulting object for the action. - * @param action The action to be executed. - * @param data The data that must be available for the action. - *

- * @return The object returned by the {@link TlsAction#execute()} method. - *

- * @throws Exception If {@link TlsAction#execute()} throw an exception. - */ - T doAs(TlsAction action, Object... data) throws Exception; - - /** - * Get the last object of the specified class that was put in the thread local - * storage. - *

- * @param The type of the object to look for. - * @param cls The class of the object to look for. - *

- * @return The last object of the specified class that was put in the thread local - * storage, or null if none can be found. - */ - T get(Class cls); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.tls; + +/** + * This service allows you to execute an action with a group of data objects + * that will be available in the thread. + */ +public interface TlsService +{ + /** + * This method puts all the data objects on the internal thread + * local storage an executes the {@link TlsAction}. + *

+ * @param The type of the resulting object for the action. + * @param action The action to be executed. + * @param data The data that must be available for the action. + *

+ * @return The object returned by the {@link TlsAction#execute()} method. + *

+ * @throws Exception If {@link TlsAction#execute()} throw an exception. + */ + T doAs(TlsAction action, Object... data) throws Exception; + + /** + * Get the last object of the specified class that was put in the thread local + * storage. + *

+ * @param The type of the object to look for. + * @param cls The class of the object to look for. + *

+ * @return The last object of the specified class that was put in the thread local + * storage, or null if none can be found. + */ + T get(Class cls); +} diff --git a/old/bridje-tls/src/main/java/org/bridje/tls/impl/ThreadLocalStorage.java b/old/bridje-tls/src/main/java/org/bridje/tls/impl/ThreadLocalStorage.java index 677a9a8de..aa64fccc7 100644 --- a/old/bridje-tls/src/main/java/org/bridje/tls/impl/ThreadLocalStorage.java +++ b/old/bridje-tls/src/main/java/org/bridje/tls/impl/ThreadLocalStorage.java @@ -1,77 +1,77 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.tls.impl; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -class ThreadLocalStorage -{ - private ThreadLocal>> threadLocalStorage; - - public ThreadLocalStorage() - { - threadLocalStorage = new ThreadLocal<>(); - } - - public T get(Class cls) - { - Map> map = threadLocalStorage.get(); - if(map != null) - { - List objects = map.get(cls); - if(objects != null && !objects.isEmpty()) - { - return (T)objects.get(objects.size()-1); - } - } - return null; - } - - public void pop(Class cls) - { - Map> map = threadLocalStorage.get(); - if(map != null) - { - List objects = map.get(cls); - if(objects != null && !objects.isEmpty()) - { - objects.remove(objects.size()-1); - } - } - } - - public void put(Object obj) - { - Class cls = obj.getClass(); - Map> map = threadLocalStorage.get(); - if(map == null) - { - map = new HashMap<>(); - threadLocalStorage.set(map); - } - List objects = map.get(cls); - if(objects == null) - { - objects = new ArrayList<>(); - map.put(cls, objects); - } - objects.add(obj); - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.tls.impl; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +class ThreadLocalStorage +{ + private ThreadLocal>> threadLocalStorage; + + public ThreadLocalStorage() + { + threadLocalStorage = new ThreadLocal<>(); + } + + public T get(Class cls) + { + Map> map = threadLocalStorage.get(); + if(map != null) + { + List objects = map.get(cls); + if(objects != null && !objects.isEmpty()) + { + return (T)objects.get(objects.size()-1); + } + } + return null; + } + + public void pop(Class cls) + { + Map> map = threadLocalStorage.get(); + if(map != null) + { + List objects = map.get(cls); + if(objects != null && !objects.isEmpty()) + { + objects.remove(objects.size()-1); + } + } + } + + public void put(Object obj) + { + Class cls = obj.getClass(); + Map> map = threadLocalStorage.get(); + if(map == null) + { + map = new HashMap<>(); + threadLocalStorage.set(map); + } + List objects = map.get(cls); + if(objects == null) + { + objects = new ArrayList<>(); + map.put(cls, objects); + } + objects.add(obj); + } +} diff --git a/old/bridje-tls/src/main/java/org/bridje/tls/impl/TlsServiceImpl.java b/old/bridje-tls/src/main/java/org/bridje/tls/impl/TlsServiceImpl.java index b2e176a9f..62e08755f 100644 --- a/old/bridje-tls/src/main/java/org/bridje/tls/impl/TlsServiceImpl.java +++ b/old/bridje-tls/src/main/java/org/bridje/tls/impl/TlsServiceImpl.java @@ -1,62 +1,62 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.tls.impl; - -import org.bridje.ioc.Component; -import org.bridje.tls.TlsAction; -import org.bridje.tls.TlsService; - -@Component -class TlsServiceImpl implements TlsService -{ - private final ThreadLocalStorage threadLocalStorage; - - public TlsServiceImpl() - { - threadLocalStorage = new ThreadLocalStorage(); - } - - @Override - public T doAs(TlsAction action, Object... data) throws Exception - { - for (Object obj : data) - { - threadLocalStorage.put(obj); - } - try - { - return action.execute(); - } - catch(Exception ex) - { - throw ex; - } - finally - { - for (Object obj : data) - { - threadLocalStorage.pop(obj.getClass()); - } - } - } - - @Override - public T get(Class cls) - { - return threadLocalStorage.get(cls); - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.tls.impl; + +import org.bridje.ioc.Component; +import org.bridje.tls.TlsAction; +import org.bridje.tls.TlsService; + +@Component +class TlsServiceImpl implements TlsService +{ + private final ThreadLocalStorage threadLocalStorage; + + public TlsServiceImpl() + { + threadLocalStorage = new ThreadLocalStorage(); + } + + @Override + public T doAs(TlsAction action, Object... data) throws Exception + { + for (Object obj : data) + { + threadLocalStorage.put(obj); + } + try + { + return action.execute(); + } + catch(Exception ex) + { + throw ex; + } + finally + { + for (Object obj : data) + { + threadLocalStorage.pop(obj.getClass()); + } + } + } + + @Override + public T get(Class cls) + { + return threadLocalStorage.get(cls); + } +} diff --git a/old/bridje-tls/src/test/java/org/bridje/tls/SomeData.java b/old/bridje-tls/src/test/java/org/bridje/tls/SomeData.java index bf8aba441..2dd926f95 100644 --- a/old/bridje-tls/src/test/java/org/bridje/tls/SomeData.java +++ b/old/bridje-tls/src/test/java/org/bridje/tls/SomeData.java @@ -1,36 +1,36 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.tls; - -/** - * - * @author Gilberto - */ -public class SomeData -{ - private String str; - - public String getStr() - { - return str; - } - - public void setStr(String str) - { - this.str = str; - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.tls; + +/** + * + * @author Gilberto + */ +public class SomeData +{ + private String str; + + public String getStr() + { + return str; + } + + public void setStr(String str) + { + this.str = str; + } +} diff --git a/old/bridje-tls/src/test/java/org/bridje/tls/TlsServiceTest.java b/old/bridje-tls/src/test/java/org/bridje/tls/TlsServiceTest.java index 67141e39a..9ae83f5bd 100644 --- a/old/bridje-tls/src/test/java/org/bridje/tls/TlsServiceTest.java +++ b/old/bridje-tls/src/test/java/org/bridje/tls/TlsServiceTest.java @@ -1,99 +1,99 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.tls; - -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import static org.junit.Assert.*; - -public class TlsServiceTest -{ - - public TlsServiceTest() - { - } - - @BeforeClass - public static void setUpClass() - { - } - - @AfterClass - public static void tearDownClass() - { - } - - @Before - public void setUp() - { - } - - @After - public void tearDown() - { - } - - @Test - public void testDoAs() throws Exception - { - //No data must be in the thread. - assertNull("Where did you get this data?", Tls.get(SomeData.class)); - //Create some data - SomeData d = new SomeData(); - d.setStr("Hi"); - //Execute an action an get the "Hi" value from withing the action. - String result = Tls.doAs(() -> - { - assertNotNull("SomeData must be here.",Tls.get(SomeData.class)); - assertEquals("SomeData must have the \"Hi\" value.", "Hi",Tls.get(SomeData.class).getStr()); - return Tls.get(SomeData.class).getStr(); - }, new Object[]{d}); - assertEquals("Wrong result.", "Hi", result); - //Again, No data must be in the thread. - assertNull("Where did you get this data?", Tls.get(SomeData.class)); - //Execute multiple nested actions with the same data. - result = Tls.doAs(() -> - { - assertNotNull("SomeData must be here.",Tls.get(SomeData.class)); - assertEquals("SomeData must have the \"Hi\" value.", "Hi",Tls.get(SomeData.class).getStr()); - - //Execute the nested action with the same class bu a diferento object with diferent data. - //Create some diferent data - SomeData d1 = new SomeData(); - d1.setStr("Hello"); - //Execute an action an get the "Hello" value from withing the action. - String result1 = Tls.doAs(() -> - { - assertNotNull("SomeData must be here.",Tls.get(SomeData.class)); - assertEquals("SomeData must have the \"Hello\" value.", "Hello",Tls.get(SomeData.class).getStr()); - return Tls.get(SomeData.class).getStr(); - }, new Object[]{d1}); - assertEquals("Wrong result.", "Hello", result1); - - //Test that everything is as it was berofe the nested action was executed. - assertNotNull("SomeData must be here.",Tls.get(SomeData.class)); - assertEquals("SomeData must have the \"Hi\" value.", "Hi",Tls.get(SomeData.class).getStr()); - return Tls.get(SomeData.class).getStr(); - }, new Object[]{d}); - assertEquals("Wrong result.", "Hi", result); - //No data must be in the thread. - assertNull("Where did you get this data?", Tls.get(SomeData.class)); - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.tls; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; + +public class TlsServiceTest +{ + + public TlsServiceTest() + { + } + + @BeforeClass + public static void setUpClass() + { + } + + @AfterClass + public static void tearDownClass() + { + } + + @Before + public void setUp() + { + } + + @After + public void tearDown() + { + } + + @Test + public void testDoAs() throws Exception + { + //No data must be in the thread. + assertNull("Where did you get this data?", Tls.get(SomeData.class)); + //Create some data + SomeData d = new SomeData(); + d.setStr("Hi"); + //Execute an action an get the "Hi" value from withing the action. + String result = Tls.doAs(() -> + { + assertNotNull("SomeData must be here.",Tls.get(SomeData.class)); + assertEquals("SomeData must have the \"Hi\" value.", "Hi",Tls.get(SomeData.class).getStr()); + return Tls.get(SomeData.class).getStr(); + }, new Object[]{d}); + assertEquals("Wrong result.", "Hi", result); + //Again, No data must be in the thread. + assertNull("Where did you get this data?", Tls.get(SomeData.class)); + //Execute multiple nested actions with the same data. + result = Tls.doAs(() -> + { + assertNotNull("SomeData must be here.",Tls.get(SomeData.class)); + assertEquals("SomeData must have the \"Hi\" value.", "Hi",Tls.get(SomeData.class).getStr()); + + //Execute the nested action with the same class bu a diferento object with diferent data. + //Create some diferent data + SomeData d1 = new SomeData(); + d1.setStr("Hello"); + //Execute an action an get the "Hello" value from withing the action. + String result1 = Tls.doAs(() -> + { + assertNotNull("SomeData must be here.",Tls.get(SomeData.class)); + assertEquals("SomeData must have the \"Hello\" value.", "Hello",Tls.get(SomeData.class).getStr()); + return Tls.get(SomeData.class).getStr(); + }, new Object[]{d1}); + assertEquals("Wrong result.", "Hello", result1); + + //Test that everything is as it was berofe the nested action was executed. + assertNotNull("SomeData must be here.",Tls.get(SomeData.class)); + assertEquals("SomeData must have the \"Hi\" value.", "Hi",Tls.get(SomeData.class).getStr()); + return Tls.get(SomeData.class).getStr(); + }, new Object[]{d}); + assertEquals("Wrong result.", "Hi", result); + //No data must be in the thread. + assertNull("Where did you get this data?", Tls.get(SomeData.class)); + } +} diff --git a/old/bridje-tpl/pom.xml b/old/bridje-tpl/pom.xml index 0c56708fe..435e3fa13 100644 --- a/old/bridje-tpl/pom.xml +++ b/old/bridje-tpl/pom.xml @@ -1,45 +1,45 @@ - - - 4.0.0 - - - org.bridje - bridje-parent - 0.0.6-SNAPSHOT - - - bridje-tpl - - Bridje Tpl - Bridje Tpl API - http://www.bridje.org - - - - org.freemarker - freemarker - 2.3.23 - - - - junit - junit - test - - - commons-io - commons-io - 2.4 - - - ${project.groupId} - bridje-ioc - ${project.version} - - - ${project.groupId} - bridje-vfs - ${project.version} - - - + + + 4.0.0 + + + org.bridje + bridje-parent + 0.0.6-SNAPSHOT + + + bridje-tpl + + Bridje Tpl + Bridje Tpl API + http://www.bridje.org + + + + org.freemarker + freemarker + 2.3.23 + + + + junit + junit + test + + + commons-io + commons-io + 2.4 + + + ${project.groupId} + bridje-ioc + ${project.version} + + + ${project.groupId} + bridje-vfs + ${project.version} + + + diff --git a/old/bridje-tpl/src/main/java/org/bridje/tpl/TemplateLoader.java b/old/bridje-tpl/src/main/java/org/bridje/tpl/TemplateLoader.java index 61a235ac8..2f3794942 100644 --- a/old/bridje-tpl/src/main/java/org/bridje/tpl/TemplateLoader.java +++ b/old/bridje-tpl/src/main/java/org/bridje/tpl/TemplateLoader.java @@ -1,46 +1,46 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.tpl; - -import java.io.IOException; -import java.io.InputStream; - -/** - * Defines a templates loader. - *

- * The objects implementing this interface are responsible for loading templates - * on {@link InputStream} objects from their storage and provides it to the tpl api. - */ -public interface TemplateLoader -{ - /** - * - * @param path - * @return - */ - Object findTemplate(String path); - - /** - * Gets an InputStream to the template specified by the path parameter. - *

- * @param template - * @return An InputStream witch allows the api to read the content of the - * template. - * @throws java.io.IOException - */ - InputStream loadTemplate(Object template) throws IOException; -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.tpl; + +import java.io.IOException; +import java.io.InputStream; + +/** + * Defines a templates loader. + *

+ * The objects implementing this interface are responsible for loading templates + * on {@link InputStream} objects from their storage and provides it to the tpl api. + */ +public interface TemplateLoader +{ + /** + * + * @param path + * @return + */ + Object findTemplate(String path); + + /** + * Gets an InputStream to the template specified by the path parameter. + *

+ * @param template + * @return An InputStream witch allows the api to read the content of the + * template. + * @throws java.io.IOException + */ + InputStream loadTemplate(Object template) throws IOException; +} diff --git a/old/bridje-tpl/src/main/java/org/bridje/tpl/TemplatesProvider.java b/old/bridje-tpl/src/main/java/org/bridje/tpl/TemplatesProvider.java index d271a2d23..1c1b9245c 100644 --- a/old/bridje-tpl/src/main/java/org/bridje/tpl/TemplatesProvider.java +++ b/old/bridje-tpl/src/main/java/org/bridje/tpl/TemplatesProvider.java @@ -1,43 +1,43 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.tpl; - -/** - * A service interface that can create template loaders that will be used in the - * tpl api. - *

- * The tpl api will use only one implementation of this interface. - */ -public interface TemplatesProvider -{ - /** - * Creates the TemplateLoader object for the default context of the tpl api. - *

- * @return The default TemplateLoader object to be use by the api. - */ - TemplateLoader createDefaultLoader(); - - /** - * Create a new template loader that will take the templates from the - * specified path. - *

- * @param path The root path for the new template loader. - * @return The TemplateLoader that will load templates that are in the - * specified path. - */ - TemplateLoader createLoader(String path); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.tpl; + +/** + * A service interface that can create template loaders that will be used in the + * tpl api. + *

+ * The tpl api will use only one implementation of this interface. + */ +public interface TemplatesProvider +{ + /** + * Creates the TemplateLoader object for the default context of the tpl api. + *

+ * @return The default TemplateLoader object to be use by the api. + */ + TemplateLoader createDefaultLoader(); + + /** + * Create a new template loader that will take the templates from the + * specified path. + *

+ * @param path The root path for the new template loader. + * @return The TemplateLoader that will load templates that are in the + * specified path. + */ + TemplateLoader createLoader(String path); +} diff --git a/old/bridje-tpl/src/main/java/org/bridje/tpl/TplContext.java b/old/bridje-tpl/src/main/java/org/bridje/tpl/TplContext.java index 8ac96e309..d9b78c9fe 100644 --- a/old/bridje-tpl/src/main/java/org/bridje/tpl/TplContext.java +++ b/old/bridje-tpl/src/main/java/org/bridje/tpl/TplContext.java @@ -1,89 +1,89 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.tpl; - -import java.io.File; -import java.io.IOException; -import java.io.OutputStream; -import java.io.Writer; -import java.util.Map; - -/** - * This interface represents a template rendering context. - *

- * The api allows you to create many different contexts for different purposes - * when rendering templates. - */ -public interface TplContext -{ - /** - * Renders the specified template with the data provided to the given - * {@link OutputStream}. - *

- * @param template The template path an name to be rendered. - * @param data The data to be use by the template. - * @param os The {@link OutputStream} to output the result of the rendering. - * @throws org.bridje.tpl.TplNotFoundException - * @throws java.io.IOException - */ - void render(String template, Map data, OutputStream os) throws TplNotFoundException, IOException; - - /** - * Renders the specified template with the data provided to the given - * {@link OutputStream}. - *

- * @param template The template path an name to be rendered. - * @param data The data to be use by the template. - * @param file The {@link File} to output the result of the rendering. - * @throws org.bridje.tpl.TplNotFoundException - * @throws java.io.IOException - */ - void render(String template, Map data, File file) throws TplNotFoundException, IOException; - - /** - * Renders the specified template with the data provided to the given - * {@link Writer}. - *

- * @param template The template path an name to be rendered. - * @param data The data to be use by the template. - * @param writer - * @throws org.bridje.tpl.TplNotFoundException - * @throws java.io.IOException - */ - void render(String template, Map data, Writer writer) throws TplNotFoundException, IOException; - - /** - * Renders the specified template with the data provided to and return the - * result. - *

- * @param template The template path an name to be rendered. - * @param data The data to be use by the template. - * @return The result of the rendered template. - * @throws org.bridje.tpl.TplNotFoundException - * @throws java.io.IOException - */ - String render(String template, Map data) throws TplNotFoundException, IOException; - - /** - * Finds out whether the specified template exists. - *

- * @param template The template path an name to be rendered. - * @return {@literal true} if the template exists in the context, - * {@literal false} otherwise. - */ - boolean exists(String template); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.tpl; + +import java.io.File; +import java.io.IOException; +import java.io.OutputStream; +import java.io.Writer; +import java.util.Map; + +/** + * This interface represents a template rendering context. + *

+ * The api allows you to create many different contexts for different purposes + * when rendering templates. + */ +public interface TplContext +{ + /** + * Renders the specified template with the data provided to the given + * {@link OutputStream}. + *

+ * @param template The template path an name to be rendered. + * @param data The data to be use by the template. + * @param os The {@link OutputStream} to output the result of the rendering. + * @throws org.bridje.tpl.TplNotFoundException + * @throws java.io.IOException + */ + void render(String template, Map data, OutputStream os) throws TplNotFoundException, IOException; + + /** + * Renders the specified template with the data provided to the given + * {@link OutputStream}. + *

+ * @param template The template path an name to be rendered. + * @param data The data to be use by the template. + * @param file The {@link File} to output the result of the rendering. + * @throws org.bridje.tpl.TplNotFoundException + * @throws java.io.IOException + */ + void render(String template, Map data, File file) throws TplNotFoundException, IOException; + + /** + * Renders the specified template with the data provided to the given + * {@link Writer}. + *

+ * @param template The template path an name to be rendered. + * @param data The data to be use by the template. + * @param writer + * @throws org.bridje.tpl.TplNotFoundException + * @throws java.io.IOException + */ + void render(String template, Map data, Writer writer) throws TplNotFoundException, IOException; + + /** + * Renders the specified template with the data provided to and return the + * result. + *

+ * @param template The template path an name to be rendered. + * @param data The data to be use by the template. + * @return The result of the rendered template. + * @throws org.bridje.tpl.TplNotFoundException + * @throws java.io.IOException + */ + String render(String template, Map data) throws TplNotFoundException, IOException; + + /** + * Finds out whether the specified template exists. + *

+ * @param template The template path an name to be rendered. + * @return {@literal true} if the template exists in the context, + * {@literal false} otherwise. + */ + boolean exists(String template); +} diff --git a/old/bridje-tpl/src/main/java/org/bridje/tpl/TplEngine.java b/old/bridje-tpl/src/main/java/org/bridje/tpl/TplEngine.java index b7d163bcc..82c73e350 100644 --- a/old/bridje-tpl/src/main/java/org/bridje/tpl/TplEngine.java +++ b/old/bridje-tpl/src/main/java/org/bridje/tpl/TplEngine.java @@ -1,46 +1,46 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.tpl; - -import java.io.IOException; -/** - * An interface that every template engine must implement to provide his - * functionality in the tpl api. - */ -public interface TplEngine -{ - /** - * The extensions used by the templates of this template engine. - *

- * @return A String representing the extension that the files that this - * engine can render must have. The name must not have the dot (".") - * character.(Eg: "tpl" NOT ".tpl") - */ - String getExtension(); - - /** - * Creates a template engine context for the specified loader. The tpl api - * will use this context to render templates that match the extension of - * this engine. - *

- * @param loader The loader from witch the result context may load the - * templates. - * @return An TplEngineContext object that can render templates of this - * engine. - */ - TplEngineContext createContext(TemplateLoader loader); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.tpl; + +import java.io.IOException; +/** + * An interface that every template engine must implement to provide his + * functionality in the tpl api. + */ +public interface TplEngine +{ + /** + * The extensions used by the templates of this template engine. + *

+ * @return A String representing the extension that the files that this + * engine can render must have. The name must not have the dot (".") + * character.(Eg: "tpl" NOT ".tpl") + */ + String getExtension(); + + /** + * Creates a template engine context for the specified loader. The tpl api + * will use this context to render templates that match the extension of + * this engine. + *

+ * @param loader The loader from witch the result context may load the + * templates. + * @return An TplEngineContext object that can render templates of this + * engine. + */ + TplEngineContext createContext(TemplateLoader loader); +} diff --git a/old/bridje-tpl/src/main/java/org/bridje/tpl/TplEngineContext.java b/old/bridje-tpl/src/main/java/org/bridje/tpl/TplEngineContext.java index 1ab032fee..ba09c5261 100644 --- a/old/bridje-tpl/src/main/java/org/bridje/tpl/TplEngineContext.java +++ b/old/bridje-tpl/src/main/java/org/bridje/tpl/TplEngineContext.java @@ -1,25 +1,25 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.tpl; - -/** - * A marker interface for all the context of the different templates engines. - */ -public interface TplEngineContext extends TplContext -{ - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.tpl; + +/** + * A marker interface for all the context of the different templates engines. + */ +public interface TplEngineContext extends TplContext +{ + +} diff --git a/old/bridje-tpl/src/main/java/org/bridje/tpl/TplNotFoundException.java b/old/bridje-tpl/src/main/java/org/bridje/tpl/TplNotFoundException.java index ca4dd6f73..a70262de5 100644 --- a/old/bridje-tpl/src/main/java/org/bridje/tpl/TplNotFoundException.java +++ b/old/bridje-tpl/src/main/java/org/bridje/tpl/TplNotFoundException.java @@ -1,39 +1,39 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.tpl; - -public class TplNotFoundException extends Exception -{ - public TplNotFoundException() - { - } - - public TplNotFoundException(String message) - { - super(message); - } - - public TplNotFoundException(String message, Throwable cause) - { - super(message, cause); - } - - public TplNotFoundException(Throwable cause) - { - super(cause); - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.tpl; + +public class TplNotFoundException extends Exception +{ + public TplNotFoundException() + { + } + + public TplNotFoundException(String message) + { + super(message); + } + + public TplNotFoundException(String message, Throwable cause) + { + super(message, cause); + } + + public TplNotFoundException(Throwable cause) + { + super(cause); + } +} diff --git a/old/bridje-tpl/src/main/java/org/bridje/tpl/TplParserException.java b/old/bridje-tpl/src/main/java/org/bridje/tpl/TplParserException.java index 09531d63b..888877b74 100644 --- a/old/bridje-tpl/src/main/java/org/bridje/tpl/TplParserException.java +++ b/old/bridje-tpl/src/main/java/org/bridje/tpl/TplParserException.java @@ -1,39 +1,39 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.tpl; - -public class TplParserException extends Exception -{ - public TplParserException() - { - } - - public TplParserException(String message) - { - super(message); - } - - public TplParserException(String message, Throwable cause) - { - super(message, cause); - } - - public TplParserException(Throwable cause) - { - super(cause); - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.tpl; + +public class TplParserException extends Exception +{ + public TplParserException() + { + } + + public TplParserException(String message) + { + super(message); + } + + public TplParserException(String message, Throwable cause) + { + super(message, cause); + } + + public TplParserException(Throwable cause) + { + super(cause); + } +} diff --git a/old/bridje-tpl/src/main/java/org/bridje/tpl/TplService.java b/old/bridje-tpl/src/main/java/org/bridje/tpl/TplService.java index 8bb3a8ee8..347452d8a 100644 --- a/old/bridje-tpl/src/main/java/org/bridje/tpl/TplService.java +++ b/old/bridje-tpl/src/main/java/org/bridje/tpl/TplService.java @@ -1,33 +1,33 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.tpl; - -/** - * The template service allow to obtain a template context. - *

- * @see TplContext - */ -public interface TplService extends TplContext -{ - /** - * Obtains a template contexts in the specified path. - *

- * @param path - * @return The context to access templates on the specified path. - */ - TplContext createTplContext(String path); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.tpl; + +/** + * The template service allow to obtain a template context. + *

+ * @see TplContext + */ +public interface TplService extends TplContext +{ + /** + * Obtains a template contexts in the specified path. + *

+ * @param path + * @return The context to access templates on the specified path. + */ + TplContext createTplContext(String path); +} diff --git a/old/bridje-tpl/src/main/java/org/bridje/tpl/impl/TplContextImpl.java b/old/bridje-tpl/src/main/java/org/bridje/tpl/impl/TplContextImpl.java index d5db528e8..432df8560 100644 --- a/old/bridje-tpl/src/main/java/org/bridje/tpl/impl/TplContextImpl.java +++ b/old/bridje-tpl/src/main/java/org/bridje/tpl/impl/TplContextImpl.java @@ -1,124 +1,124 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.tpl.impl; - -import java.io.File; -import java.io.IOException; -import java.io.OutputStream; -import java.io.Writer; -import java.util.HashMap; -import java.util.Map; -import org.bridje.tpl.TemplateLoader; -import org.bridje.tpl.TplContext; -import org.bridje.tpl.TplEngine; -import org.bridje.tpl.TplEngineContext; -import org.bridje.tpl.TplNotFoundException; - -public class TplContextImpl implements TplContext -{ - private final Map extContexts; - - public TplContextImpl(TemplateLoader loader, TplEngine[] engines) - { - extContexts = createEngineContexts(loader, engines); - } - - @Override - public void render(String template, Map data, File file) throws TplNotFoundException, IOException - { - TplEngineContext tplEngCtx = findTplEngineContext(template); - if(tplEngCtx != null) - { - tplEngCtx.render(template, data, file); - } - } - - @Override - public void render(String template, Map data, OutputStream os) throws TplNotFoundException, IOException - { - TplEngineContext tplEngCtx = findTplEngineContext(template); - if(tplEngCtx != null) - { - tplEngCtx.render(template, data, os); - } - } - - @Override - public void render(String template, Map data, Writer writer) throws TplNotFoundException, IOException - { - TplEngineContext tplEngCtx = findTplEngineContext(template); - if(tplEngCtx != null) - { - tplEngCtx.render(template, data, writer); - } - } - - @Override - public String render(String template, Map data) throws TplNotFoundException, IOException - { - TplEngineContext tplEngCtx = findTplEngineContext(template); - if(tplEngCtx != null) - { - return tplEngCtx.render(template, data); - } - return null; - } - - private String findExtension(String template) - { - int lastIndexOf = template.lastIndexOf("."); - if(lastIndexOf > 0 && lastIndexOf < template.length()) - { - return template.substring(lastIndexOf + 1); - } - return null; - } - - private TplEngineContext findTplEngineContext(String template) - { - String ext = findExtension(template); - if(ext != null && !ext.isEmpty()) - { - return extContexts.get(ext); - } - return null; - } - - private Map createEngineContexts(TemplateLoader loader,TplEngine[] engines) - { - Map result = new HashMap<>(); - for (TplEngine engine : engines) - { - if(engine.getExtension() != null && !engine.getExtension().isEmpty()) - { - result.put(engine.getExtension(), engine.createContext(loader)); - } - } - return result; - } - - @Override - public boolean exists(String template) - { - TplEngineContext tplEngCtx = findTplEngineContext(template); - if(tplEngCtx != null) - { - return tplEngCtx.exists(template); - } - return false; - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.tpl.impl; + +import java.io.File; +import java.io.IOException; +import java.io.OutputStream; +import java.io.Writer; +import java.util.HashMap; +import java.util.Map; +import org.bridje.tpl.TemplateLoader; +import org.bridje.tpl.TplContext; +import org.bridje.tpl.TplEngine; +import org.bridje.tpl.TplEngineContext; +import org.bridje.tpl.TplNotFoundException; + +public class TplContextImpl implements TplContext +{ + private final Map extContexts; + + public TplContextImpl(TemplateLoader loader, TplEngine[] engines) + { + extContexts = createEngineContexts(loader, engines); + } + + @Override + public void render(String template, Map data, File file) throws TplNotFoundException, IOException + { + TplEngineContext tplEngCtx = findTplEngineContext(template); + if(tplEngCtx != null) + { + tplEngCtx.render(template, data, file); + } + } + + @Override + public void render(String template, Map data, OutputStream os) throws TplNotFoundException, IOException + { + TplEngineContext tplEngCtx = findTplEngineContext(template); + if(tplEngCtx != null) + { + tplEngCtx.render(template, data, os); + } + } + + @Override + public void render(String template, Map data, Writer writer) throws TplNotFoundException, IOException + { + TplEngineContext tplEngCtx = findTplEngineContext(template); + if(tplEngCtx != null) + { + tplEngCtx.render(template, data, writer); + } + } + + @Override + public String render(String template, Map data) throws TplNotFoundException, IOException + { + TplEngineContext tplEngCtx = findTplEngineContext(template); + if(tplEngCtx != null) + { + return tplEngCtx.render(template, data); + } + return null; + } + + private String findExtension(String template) + { + int lastIndexOf = template.lastIndexOf("."); + if(lastIndexOf > 0 && lastIndexOf < template.length()) + { + return template.substring(lastIndexOf + 1); + } + return null; + } + + private TplEngineContext findTplEngineContext(String template) + { + String ext = findExtension(template); + if(ext != null && !ext.isEmpty()) + { + return extContexts.get(ext); + } + return null; + } + + private Map createEngineContexts(TemplateLoader loader,TplEngine[] engines) + { + Map result = new HashMap<>(); + for (TplEngine engine : engines) + { + if(engine.getExtension() != null && !engine.getExtension().isEmpty()) + { + result.put(engine.getExtension(), engine.createContext(loader)); + } + } + return result; + } + + @Override + public boolean exists(String template) + { + TplEngineContext tplEngCtx = findTplEngineContext(template); + if(tplEngCtx != null) + { + return tplEngCtx.exists(template); + } + return false; + } +} diff --git a/old/bridje-tpl/src/main/java/org/bridje/tpl/impl/TplServiceImpl.java b/old/bridje-tpl/src/main/java/org/bridje/tpl/impl/TplServiceImpl.java index 67fd9524d..38c5c775e 100644 --- a/old/bridje-tpl/src/main/java/org/bridje/tpl/impl/TplServiceImpl.java +++ b/old/bridje-tpl/src/main/java/org/bridje/tpl/impl/TplServiceImpl.java @@ -1,92 +1,92 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.tpl.impl; - -import java.io.File; -import java.io.IOException; -import java.io.OutputStream; -import java.io.Writer; -import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.annotation.PostConstruct; -import org.bridje.ioc.Component; -import org.bridje.ioc.Inject; -import org.bridje.tpl.TemplateLoader; -import org.bridje.tpl.TemplatesProvider; -import org.bridje.tpl.TplContext; -import org.bridje.tpl.TplEngine; -import org.bridje.tpl.TplNotFoundException; -import org.bridje.tpl.TplService; - -@Component -public class TplServiceImpl implements TplService -{ - private static final Logger LOG = Logger.getLogger(TplServiceImpl.class.getName()); - - @Inject - private TemplatesProvider provider; - - @Inject - private TplEngine[] engines; - - private TplContext rootContext; - - @PostConstruct - public void init() - { - TemplateLoader defTplLoader = provider.createDefaultLoader(); - rootContext = new TplContextImpl(defTplLoader, engines); - } - - @Override - public TplContext createTplContext(String path) - { - TemplateLoader loader = provider.createLoader(path); - return new TplContextImpl(loader, engines); - } - - @Override - public void render(String template, Map data, File file) throws TplNotFoundException, IOException - { - rootContext.render(template, data, file); - } - - @Override - public void render(String template, Map data, OutputStream os) throws TplNotFoundException, IOException - { - rootContext.render(template, data, os); - } - - @Override - public void render(String template, Map data, Writer writer) throws TplNotFoundException, IOException - { - rootContext.render(template, data, writer); - } - - @Override - public String render(String template, Map data) throws TplNotFoundException, IOException - { - return rootContext.render(template, data); - } - - @Override - public boolean exists(String template) - { - return rootContext.exists(template); - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.tpl.impl; + +import java.io.File; +import java.io.IOException; +import java.io.OutputStream; +import java.io.Writer; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.annotation.PostConstruct; +import org.bridje.ioc.Component; +import org.bridje.ioc.Inject; +import org.bridje.tpl.TemplateLoader; +import org.bridje.tpl.TemplatesProvider; +import org.bridje.tpl.TplContext; +import org.bridje.tpl.TplEngine; +import org.bridje.tpl.TplNotFoundException; +import org.bridje.tpl.TplService; + +@Component +public class TplServiceImpl implements TplService +{ + private static final Logger LOG = Logger.getLogger(TplServiceImpl.class.getName()); + + @Inject + private TemplatesProvider provider; + + @Inject + private TplEngine[] engines; + + private TplContext rootContext; + + @PostConstruct + public void init() + { + TemplateLoader defTplLoader = provider.createDefaultLoader(); + rootContext = new TplContextImpl(defTplLoader, engines); + } + + @Override + public TplContext createTplContext(String path) + { + TemplateLoader loader = provider.createLoader(path); + return new TplContextImpl(loader, engines); + } + + @Override + public void render(String template, Map data, File file) throws TplNotFoundException, IOException + { + rootContext.render(template, data, file); + } + + @Override + public void render(String template, Map data, OutputStream os) throws TplNotFoundException, IOException + { + rootContext.render(template, data, os); + } + + @Override + public void render(String template, Map data, Writer writer) throws TplNotFoundException, IOException + { + rootContext.render(template, data, writer); + } + + @Override + public String render(String template, Map data) throws TplNotFoundException, IOException + { + return rootContext.render(template, data); + } + + @Override + public boolean exists(String template) + { + return rootContext.exists(template); + } +} diff --git a/old/bridje-tpl/src/main/java/org/bridje/tpl/impl/VfsTemplateLoader.java b/old/bridje-tpl/src/main/java/org/bridje/tpl/impl/VfsTemplateLoader.java index a048c05d0..3b1fdbcab 100644 --- a/old/bridje-tpl/src/main/java/org/bridje/tpl/impl/VfsTemplateLoader.java +++ b/old/bridje-tpl/src/main/java/org/bridje/tpl/impl/VfsTemplateLoader.java @@ -1,53 +1,53 @@ -/* - * Copyright 2016 Bridje Framework. - * - * Licensed 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.bridje.tpl.impl; - -import java.io.IOException; -import java.io.InputStream; -import org.bridje.ioc.Ioc; -import org.bridje.tpl.TemplateLoader; -import org.bridje.vfs.Path; -import org.bridje.vfs.VfsService; -import org.bridje.vfs.VirtualFile; - -public class VfsTemplateLoader implements TemplateLoader -{ - private final Path basePath; - - public VfsTemplateLoader(String basePath) - { - this.basePath = new Path(basePath); - } - - @Override - public InputStream loadTemplate(Object template) throws IOException - { - VirtualFile file = (VirtualFile)template; - if(file != null) - { - return file.open(); - } - return null; - } - - @Override - public Object findTemplate(String path) - { - return Ioc.context().find(VfsService.class).findFile(basePath.join(path)); - } - -} +/* + * Copyright 2016 Bridje Framework. + * + * Licensed 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.bridje.tpl.impl; + +import java.io.IOException; +import java.io.InputStream; +import org.bridje.ioc.Ioc; +import org.bridje.tpl.TemplateLoader; +import org.bridje.vfs.Path; +import org.bridje.vfs.VfsService; +import org.bridje.vfs.VirtualFile; + +public class VfsTemplateLoader implements TemplateLoader +{ + private final Path basePath; + + public VfsTemplateLoader(String basePath) + { + this.basePath = new Path(basePath); + } + + @Override + public InputStream loadTemplate(Object template) throws IOException + { + VirtualFile file = (VirtualFile)template; + if(file != null) + { + return file.open(); + } + return null; + } + + @Override + public Object findTemplate(String path) + { + return Ioc.context().find(VfsService.class).findFile(basePath.join(path)); + } + +} diff --git a/old/bridje-tpl/src/main/java/org/bridje/tpl/impl/VfsTemplatesProvider.java b/old/bridje-tpl/src/main/java/org/bridje/tpl/impl/VfsTemplatesProvider.java index ea62311c3..62c574184 100644 --- a/old/bridje-tpl/src/main/java/org/bridje/tpl/impl/VfsTemplatesProvider.java +++ b/old/bridje-tpl/src/main/java/org/bridje/tpl/impl/VfsTemplatesProvider.java @@ -1,40 +1,40 @@ -/* - * Copyright 2016 Bridje Framework. - * - * Licensed 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.bridje.tpl.impl; - -import org.bridje.ioc.Component; -import org.bridje.ioc.Priority; -import org.bridje.tpl.TemplateLoader; -import org.bridje.tpl.TemplatesProvider; - -@Component -@Priority(100) -public class VfsTemplatesProvider implements TemplatesProvider -{ - @Override - public TemplateLoader createDefaultLoader() - { - return new VfsTemplateLoader("/tpls"); - } - - @Override - public TemplateLoader createLoader(String path) - { - return new VfsTemplateLoader(path); - } - -} +/* + * Copyright 2016 Bridje Framework. + * + * Licensed 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.bridje.tpl.impl; + +import org.bridje.ioc.Component; +import org.bridje.ioc.Priority; +import org.bridje.tpl.TemplateLoader; +import org.bridje.tpl.TemplatesProvider; + +@Component +@Priority(100) +public class VfsTemplatesProvider implements TemplatesProvider +{ + @Override + public TemplateLoader createDefaultLoader() + { + return new VfsTemplateLoader("/tpls"); + } + + @Override + public TemplateLoader createLoader(String path) + { + return new VfsTemplateLoader(path); + } + +} diff --git a/old/bridje-tpl/src/main/java/org/bridje/tpl/impl/ftl/FtlTplContextImpl.java b/old/bridje-tpl/src/main/java/org/bridje/tpl/impl/ftl/FtlTplContextImpl.java index 3254e12b6..5f546591f 100644 --- a/old/bridje-tpl/src/main/java/org/bridje/tpl/impl/ftl/FtlTplContextImpl.java +++ b/old/bridje-tpl/src/main/java/org/bridje/tpl/impl/ftl/FtlTplContextImpl.java @@ -1,179 +1,179 @@ - -package org.bridje.tpl.impl.ftl; - -import freemarker.cache.TemplateLoader; -import freemarker.core.Environment; -import freemarker.core.ParseException; -import freemarker.template.Configuration; -import freemarker.template.Template; -import freemarker.template.TemplateException; -import freemarker.template.TemplateExceptionHandler; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.StringWriter; -import java.io.Writer; -import java.util.Locale; -import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.bridje.tls.Tls; -import org.bridje.tpl.TplEngineContext; -import org.bridje.tpl.TplNotFoundException; -import org.bridje.tpl.TplParserException; - -final class FtlTplContextImpl implements TplEngineContext -{ - private static final Logger LOG = Logger.getLogger(FtlTplContextImpl.class.getName()); - - private final FtlCtxImplExceptionHandler exceptionHandler; - - private final Configuration cf; - - public FtlTplContextImpl(org.bridje.tpl.TemplateLoader loader) - { - TemplateLoader ftlLoader = new FtlVfsTemplateLoader(loader); - - exceptionHandler = new FtlCtxImplExceptionHandler(isErrorIgnored()); - cf = new Configuration(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS); - cf.setTemplateLoader(ftlLoader); - cf.setTemplateExceptionHandler(exceptionHandler); - - System.setProperty(freemarker.log.Logger.SYSTEM_PROPERTY_NAME_LOGGER_LIBRARY, freemarker.log.Logger.LIBRARY_NAME_JUL); - } - - @Override - public void render(String template, Map data, Writer writer) throws TplNotFoundException, IOException - { - try - { - Template tmpl = findTemplate(template); - tmpl.process(data, writer); - } - catch (TemplateException | TplParserException ex) - { - LOG.log(Level.SEVERE, ex.getMessage(), ex); - } - } - - @Override - public String render(String template, Map data) throws TplNotFoundException - { - StringWriter writer = null; - try - { - writer = new StringWriter(); - Template tmpl = findTemplate(template); - tmpl.process(data, writer); - return writer.toString(); - } - catch (IOException | TemplateException | TplParserException ex) - { - LOG.log(Level.SEVERE, ex.getMessage(), ex); - } - finally - { - if (writer != null) - { - try - { - writer.close(); - } - catch (IOException ex) - { - LOG.log(Level.SEVERE, ex.getMessage(), ex); - } - } - } - return ""; - } - - @Override - public void render(String template, Map data, File file) throws TplNotFoundException, IOException - { - try (FileWriter fw = new FileWriter(file)) - { - render(template, data, fw); - } - catch (IOException ex) - { - LOG.log(Level.SEVERE, ex.getMessage(), ex); - } - } - - @Override - public void render(String template, Map data, OutputStream os) throws TplNotFoundException, IOException - { - render(template, data, new OutputStreamWriter(os, "UTF-8")); - } - - @Override - public boolean exists(String template) - { - try - { - Template tmp = findTemplate(template); - return tmp != null; - } - catch (TplNotFoundException | TplParserException ex) - { - return false; - } - } - - protected Template findTemplate(String template) throws TplNotFoundException, TplParserException - { - try - { - Locale locale = Tls.get(Locale.class); - if (locale != null) - { - return cf.getTemplate(template, locale); - } - - return cf.getTemplate(template, Locale.getDefault()); - } - catch (ParseException ex) - { - LOG.log(Level.SEVERE, ex.getMessage(), ex); - throw new TplParserException(template, ex); - } - catch (IOException e) - { - throw new TplNotFoundException(template); - } - } - - protected boolean isErrorIgnored() - { - return true; - } - - private static class FtlCtxImplExceptionHandler implements TemplateExceptionHandler - { - private final boolean errIgnored; - - public FtlCtxImplExceptionHandler(boolean errIgnored) - { - this.errIgnored = errIgnored; - } - - @Override - public void handleTemplateException(TemplateException te, Environment env, java.io.Writer out) throws TemplateException - { - try - { - if (!errIgnored) - { - out.write("[ERROR: " + te.getMessage() + "]"); - } - } - catch (IOException e) - { - throw new TemplateException("Failed to print error message. Cause: " + e.getMessage(), env); - } - } - } -} + +package org.bridje.tpl.impl.ftl; + +import freemarker.cache.TemplateLoader; +import freemarker.core.Environment; +import freemarker.core.ParseException; +import freemarker.template.Configuration; +import freemarker.template.Template; +import freemarker.template.TemplateException; +import freemarker.template.TemplateExceptionHandler; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.StringWriter; +import java.io.Writer; +import java.util.Locale; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.bridje.tls.Tls; +import org.bridje.tpl.TplEngineContext; +import org.bridje.tpl.TplNotFoundException; +import org.bridje.tpl.TplParserException; + +final class FtlTplContextImpl implements TplEngineContext +{ + private static final Logger LOG = Logger.getLogger(FtlTplContextImpl.class.getName()); + + private final FtlCtxImplExceptionHandler exceptionHandler; + + private final Configuration cf; + + public FtlTplContextImpl(org.bridje.tpl.TemplateLoader loader) + { + TemplateLoader ftlLoader = new FtlVfsTemplateLoader(loader); + + exceptionHandler = new FtlCtxImplExceptionHandler(isErrorIgnored()); + cf = new Configuration(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS); + cf.setTemplateLoader(ftlLoader); + cf.setTemplateExceptionHandler(exceptionHandler); + + System.setProperty(freemarker.log.Logger.SYSTEM_PROPERTY_NAME_LOGGER_LIBRARY, freemarker.log.Logger.LIBRARY_NAME_JUL); + } + + @Override + public void render(String template, Map data, Writer writer) throws TplNotFoundException, IOException + { + try + { + Template tmpl = findTemplate(template); + tmpl.process(data, writer); + } + catch (TemplateException | TplParserException ex) + { + LOG.log(Level.SEVERE, ex.getMessage(), ex); + } + } + + @Override + public String render(String template, Map data) throws TplNotFoundException + { + StringWriter writer = null; + try + { + writer = new StringWriter(); + Template tmpl = findTemplate(template); + tmpl.process(data, writer); + return writer.toString(); + } + catch (IOException | TemplateException | TplParserException ex) + { + LOG.log(Level.SEVERE, ex.getMessage(), ex); + } + finally + { + if (writer != null) + { + try + { + writer.close(); + } + catch (IOException ex) + { + LOG.log(Level.SEVERE, ex.getMessage(), ex); + } + } + } + return ""; + } + + @Override + public void render(String template, Map data, File file) throws TplNotFoundException, IOException + { + try (FileWriter fw = new FileWriter(file)) + { + render(template, data, fw); + } + catch (IOException ex) + { + LOG.log(Level.SEVERE, ex.getMessage(), ex); + } + } + + @Override + public void render(String template, Map data, OutputStream os) throws TplNotFoundException, IOException + { + render(template, data, new OutputStreamWriter(os, "UTF-8")); + } + + @Override + public boolean exists(String template) + { + try + { + Template tmp = findTemplate(template); + return tmp != null; + } + catch (TplNotFoundException | TplParserException ex) + { + return false; + } + } + + protected Template findTemplate(String template) throws TplNotFoundException, TplParserException + { + try + { + Locale locale = Tls.get(Locale.class); + if (locale != null) + { + return cf.getTemplate(template, locale); + } + + return cf.getTemplate(template, Locale.getDefault()); + } + catch (ParseException ex) + { + LOG.log(Level.SEVERE, ex.getMessage(), ex); + throw new TplParserException(template, ex); + } + catch (IOException e) + { + throw new TplNotFoundException(template); + } + } + + protected boolean isErrorIgnored() + { + return true; + } + + private static class FtlCtxImplExceptionHandler implements TemplateExceptionHandler + { + private final boolean errIgnored; + + public FtlCtxImplExceptionHandler(boolean errIgnored) + { + this.errIgnored = errIgnored; + } + + @Override + public void handleTemplateException(TemplateException te, Environment env, java.io.Writer out) throws TemplateException + { + try + { + if (!errIgnored) + { + out.write("[ERROR: " + te.getMessage() + "]"); + } + } + catch (IOException e) + { + throw new TemplateException("Failed to print error message. Cause: " + e.getMessage(), env); + } + } + } +} diff --git a/old/bridje-tpl/src/main/java/org/bridje/tpl/impl/ftl/FtlTplEngine.java b/old/bridje-tpl/src/main/java/org/bridje/tpl/impl/ftl/FtlTplEngine.java index c968082d2..81c937922 100644 --- a/old/bridje-tpl/src/main/java/org/bridje/tpl/impl/ftl/FtlTplEngine.java +++ b/old/bridje-tpl/src/main/java/org/bridje/tpl/impl/ftl/FtlTplEngine.java @@ -1,41 +1,41 @@ -/* - * Copyright 2016 Bridje Framework. - * - * Licensed 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.bridje.tpl.impl.ftl; - -import org.bridje.ioc.Component; -import org.bridje.ioc.Priority; -import org.bridje.tpl.TemplateLoader; -import org.bridje.tpl.TplEngine; -import org.bridje.tpl.TplEngineContext; - -@Component -@Priority(100) -public class FtlTplEngine implements TplEngine -{ - @Override - public String getExtension() - { - return "ftl"; - } - - @Override - public TplEngineContext createContext(TemplateLoader loader) - { - return new FtlTplContextImpl(loader); - } - -} +/* + * Copyright 2016 Bridje Framework. + * + * Licensed 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.bridje.tpl.impl.ftl; + +import org.bridje.ioc.Component; +import org.bridje.ioc.Priority; +import org.bridje.tpl.TemplateLoader; +import org.bridje.tpl.TplEngine; +import org.bridje.tpl.TplEngineContext; + +@Component +@Priority(100) +public class FtlTplEngine implements TplEngine +{ + @Override + public String getExtension() + { + return "ftl"; + } + + @Override + public TplEngineContext createContext(TemplateLoader loader) + { + return new FtlTplContextImpl(loader); + } + +} diff --git a/old/bridje-tpl/src/main/java/org/bridje/tpl/impl/ftl/FtlVfsTemplateLoader.java b/old/bridje-tpl/src/main/java/org/bridje/tpl/impl/ftl/FtlVfsTemplateLoader.java index a7d5b1a2d..1e3dc3104 100644 --- a/old/bridje-tpl/src/main/java/org/bridje/tpl/impl/ftl/FtlVfsTemplateLoader.java +++ b/old/bridje-tpl/src/main/java/org/bridje/tpl/impl/ftl/FtlVfsTemplateLoader.java @@ -1,40 +1,40 @@ - -package org.bridje.tpl.impl.ftl; - -import freemarker.cache.TemplateLoader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.Reader; - -public class FtlVfsTemplateLoader implements TemplateLoader -{ - private final org.bridje.tpl.TemplateLoader tplLoader; - - public FtlVfsTemplateLoader(org.bridje.tpl.TemplateLoader tplLoader) - { - this.tplLoader = tplLoader; - } - - @Override - public Object findTemplateSource(String name) throws IOException - { - return tplLoader.findTemplate(name); - } - - @Override - public long getLastModified(Object templateSource) - { - return 0L; - } - - @Override - public Reader getReader(Object templateSource, String encoding) throws IOException - { - return new InputStreamReader(tplLoader.loadTemplate(templateSource)); - } - - @Override - public void closeTemplateSource(Object templateSource) throws IOException - { - } -} + +package org.bridje.tpl.impl.ftl; + +import freemarker.cache.TemplateLoader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; + +public class FtlVfsTemplateLoader implements TemplateLoader +{ + private final org.bridje.tpl.TemplateLoader tplLoader; + + public FtlVfsTemplateLoader(org.bridje.tpl.TemplateLoader tplLoader) + { + this.tplLoader = tplLoader; + } + + @Override + public Object findTemplateSource(String name) throws IOException + { + return tplLoader.findTemplate(name); + } + + @Override + public long getLastModified(Object templateSource) + { + return 0L; + } + + @Override + public Reader getReader(Object templateSource, String encoding) throws IOException + { + return new InputStreamReader(tplLoader.loadTemplate(templateSource)); + } + + @Override + public void closeTemplateSource(Object templateSource) throws IOException + { + } +} diff --git a/old/bridje-tpl/src/test/java/org/bridje/tpl/DummyTemplateLoader.java b/old/bridje-tpl/src/test/java/org/bridje/tpl/DummyTemplateLoader.java index 0009ecb49..395ea89c4 100644 --- a/old/bridje-tpl/src/test/java/org/bridje/tpl/DummyTemplateLoader.java +++ b/old/bridje-tpl/src/test/java/org/bridje/tpl/DummyTemplateLoader.java @@ -1,42 +1,42 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.tpl; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; - -/** - * - * @author Gilberto - */ -public class DummyTemplateLoader implements TemplateLoader -{ - @Override - public Object findTemplate(String path) - { - return path; - } - - @Override - public InputStream loadTemplate(Object template) throws IOException - { - String text = "Hello"; - return new ByteArrayInputStream(text.getBytes()); - } - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.tpl; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; + +/** + * + * @author Gilberto + */ +public class DummyTemplateLoader implements TemplateLoader +{ + @Override + public Object findTemplate(String path) + { + return path; + } + + @Override + public InputStream loadTemplate(Object template) throws IOException + { + String text = "Hello"; + return new ByteArrayInputStream(text.getBytes()); + } + +} diff --git a/old/bridje-tpl/src/test/java/org/bridje/tpl/DummyTemplatesProvider.java b/old/bridje-tpl/src/test/java/org/bridje/tpl/DummyTemplatesProvider.java index b014dc862..99d5597c3 100644 --- a/old/bridje-tpl/src/test/java/org/bridje/tpl/DummyTemplatesProvider.java +++ b/old/bridje-tpl/src/test/java/org/bridje/tpl/DummyTemplatesProvider.java @@ -1,43 +1,43 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.tpl; - -import org.bridje.ioc.Component; -import org.bridje.ioc.Priority; - -/** - * - * @author Gilberto - */ -@Component -@Priority(-10) -public class DummyTemplatesProvider implements TemplatesProvider -{ - - @Override - public TemplateLoader createDefaultLoader() - { - return new DummyTemplateLoader(); - } - - @Override - public TemplateLoader createLoader(String path) - { - return new DummyTemplateLoader(); - } - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.tpl; + +import org.bridje.ioc.Component; +import org.bridje.ioc.Priority; + +/** + * + * @author Gilberto + */ +@Component +@Priority(-10) +public class DummyTemplatesProvider implements TemplatesProvider +{ + + @Override + public TemplateLoader createDefaultLoader() + { + return new DummyTemplateLoader(); + } + + @Override + public TemplateLoader createLoader(String path) + { + return new DummyTemplateLoader(); + } + +} diff --git a/old/bridje-tpl/src/test/java/org/bridje/tpl/DummyTplEngine.java b/old/bridje-tpl/src/test/java/org/bridje/tpl/DummyTplEngine.java index 03d80f5e0..420bd87db 100644 --- a/old/bridje-tpl/src/test/java/org/bridje/tpl/DummyTplEngine.java +++ b/old/bridje-tpl/src/test/java/org/bridje/tpl/DummyTplEngine.java @@ -1,41 +1,41 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.tpl; - -import org.bridje.ioc.Component; - -/** - * - * @author Gilberto - */ -@Component -public class DummyTplEngine implements TplEngine -{ - - @Override - public String getExtension() - { - return "dummy"; - } - - @Override - public TplEngineContext createContext(TemplateLoader loader) - { - return new DummyTplEngineContext(loader); - } - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.tpl; + +import org.bridje.ioc.Component; + +/** + * + * @author Gilberto + */ +@Component +public class DummyTplEngine implements TplEngine +{ + + @Override + public String getExtension() + { + return "dummy"; + } + + @Override + public TplEngineContext createContext(TemplateLoader loader) + { + return new DummyTplEngineContext(loader); + } + +} diff --git a/old/bridje-tpl/src/test/java/org/bridje/tpl/DummyTplEngineContext.java b/old/bridje-tpl/src/test/java/org/bridje/tpl/DummyTplEngineContext.java index 7965dca97..0a77ce04c 100644 --- a/old/bridje-tpl/src/test/java/org/bridje/tpl/DummyTplEngineContext.java +++ b/old/bridje-tpl/src/test/java/org/bridje/tpl/DummyTplEngineContext.java @@ -1,102 +1,102 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.tpl; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.StringWriter; -import java.io.Writer; -import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.apache.commons.io.IOUtils; - -/** - * - * @author Gilberto - */ -public class DummyTplEngineContext implements TplEngineContext -{ - private static final Logger LOG = Logger.getLogger(DummyTplEngineContext.class.getName()); - - private TemplateLoader loader; - - public DummyTplEngineContext(TemplateLoader loader) - { - this.loader = loader; - } - - @Override - public void render(String template, Map data, OutputStream os) throws IOException - { - InputStream is = loader.loadTemplate(template); - try - { - IOUtils.copy(is, os); - } - catch(Exception ex) - { - LOG.log(Level.SEVERE, ex.getMessage(), ex); - } - } - - @Override - public void render(String template, Map data, Writer writer) throws IOException - { - InputStream is = loader.loadTemplate(template); - try - { - IOUtils.copy(is, writer); - } - catch(Exception ex) - { - LOG.log(Level.SEVERE, ex.getMessage(), ex); - } - } - - @Override - public String render(String template, Map data) throws IOException - { - StringWriter sw = new StringWriter(); - render(template, data, sw); - return sw.toString(); - } - - @Override - public void render(String template, Map data, File file) throws TplNotFoundException, IOException - { - InputStream is = loader.loadTemplate(template); - try(OutputStream os = new FileOutputStream(file)) - { - IOUtils.copy(is, os); - } - catch(Exception ex) - { - LOG.log(Level.SEVERE, ex.getMessage(), ex); - } - } - - @Override - public boolean exists(String template) - { - return true; - } - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.tpl; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.StringWriter; +import java.io.Writer; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.apache.commons.io.IOUtils; + +/** + * + * @author Gilberto + */ +public class DummyTplEngineContext implements TplEngineContext +{ + private static final Logger LOG = Logger.getLogger(DummyTplEngineContext.class.getName()); + + private TemplateLoader loader; + + public DummyTplEngineContext(TemplateLoader loader) + { + this.loader = loader; + } + + @Override + public void render(String template, Map data, OutputStream os) throws IOException + { + InputStream is = loader.loadTemplate(template); + try + { + IOUtils.copy(is, os); + } + catch(Exception ex) + { + LOG.log(Level.SEVERE, ex.getMessage(), ex); + } + } + + @Override + public void render(String template, Map data, Writer writer) throws IOException + { + InputStream is = loader.loadTemplate(template); + try + { + IOUtils.copy(is, writer); + } + catch(Exception ex) + { + LOG.log(Level.SEVERE, ex.getMessage(), ex); + } + } + + @Override + public String render(String template, Map data) throws IOException + { + StringWriter sw = new StringWriter(); + render(template, data, sw); + return sw.toString(); + } + + @Override + public void render(String template, Map data, File file) throws TplNotFoundException, IOException + { + InputStream is = loader.loadTemplate(template); + try(OutputStream os = new FileOutputStream(file)) + { + IOUtils.copy(is, os); + } + catch(Exception ex) + { + LOG.log(Level.SEVERE, ex.getMessage(), ex); + } + } + + @Override + public boolean exists(String template) + { + return true; + } + +} diff --git a/old/bridje-tpl/src/test/java/org/bridje/tpl/TplServiceTest.java b/old/bridje-tpl/src/test/java/org/bridje/tpl/TplServiceTest.java index 46f5ca8ff..fdd32db3f 100644 --- a/old/bridje-tpl/src/test/java/org/bridje/tpl/TplServiceTest.java +++ b/old/bridje-tpl/src/test/java/org/bridje/tpl/TplServiceTest.java @@ -1,73 +1,73 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.tpl; - -import java.io.IOException; -import java.util.HashMap; -import org.bridje.ioc.Ioc; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * - * @author Gilberto - */ -public class TplServiceTest -{ - - public TplServiceTest() - { - } - - @BeforeClass - public static void setUpClass() - { - } - - @AfterClass - public static void tearDownClass() - { - } - - @Before - public void setUp() - { - } - - @After - public void tearDown() - { - } - - /** - * Test of createTplContext method, of class TplService. - * @throws org.bridje.core.tpl.TplNotFoundException - * @throws java.io.IOException - */ - @Test - public void testAll() throws TplNotFoundException, IOException - { - TplService tplServ = Ioc.context().find(TplService.class); - String result = tplServ.render("/mytemplate.dummy", new HashMap()); - Assert.assertEquals("Hello", result); - } - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.tpl; + +import java.io.IOException; +import java.util.HashMap; +import org.bridje.ioc.Ioc; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * + * @author Gilberto + */ +public class TplServiceTest +{ + + public TplServiceTest() + { + } + + @BeforeClass + public static void setUpClass() + { + } + + @AfterClass + public static void tearDownClass() + { + } + + @Before + public void setUp() + { + } + + @After + public void tearDown() + { + } + + /** + * Test of createTplContext method, of class TplService. + * @throws org.bridje.core.tpl.TplNotFoundException + * @throws java.io.IOException + */ + @Test + public void testAll() throws TplNotFoundException, IOException + { + TplService tplServ = Ioc.context().find(TplService.class); + String result = tplServ.render("/mytemplate.dummy", new HashMap()); + Assert.assertEquals("Hello", result); + } + +} diff --git a/old/bridje-vfs/pom.xml b/old/bridje-vfs/pom.xml index e3b916c7b..81b90dee0 100644 --- a/old/bridje-vfs/pom.xml +++ b/old/bridje-vfs/pom.xml @@ -1,35 +1,35 @@ - - - 4.0.0 - - - org.bridje - bridje-parent - 0.0.6-SNAPSHOT - - - bridje-vfs - - Bridje VFS - Bridje VFS API - http://www.bridje.org - - - - junit - junit - test - - - commons-io - commons-io - 2.4 - test - - - ${project.groupId} - bridje-ioc - ${project.version} - - - + + + 4.0.0 + + + org.bridje + bridje-parent + 0.0.6-SNAPSHOT + + + bridje-vfs + + Bridje VFS + Bridje VFS API + http://www.bridje.org + + + + junit + junit + test + + + commons-io + commons-io + 2.4 + test + + + ${project.groupId} + bridje-ioc + ${project.version} + + + diff --git a/old/bridje-vfs/src/main/java/org/bridje/vfs/MultiVirtualFile.java b/old/bridje-vfs/src/main/java/org/bridje/vfs/MultiVirtualFile.java index 979c64b70..e7e9a134d 100644 --- a/old/bridje-vfs/src/main/java/org/bridje/vfs/MultiVirtualFile.java +++ b/old/bridje-vfs/src/main/java/org/bridje/vfs/MultiVirtualFile.java @@ -1,24 +1,24 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.vfs; - -import java.util.List; - -public interface MultiVirtualFile extends VirtualFile -{ - List getFiles(); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.vfs; + +import java.util.List; + +public interface MultiVirtualFile extends VirtualFile +{ + List getFiles(); +} diff --git a/old/bridje-vfs/src/main/java/org/bridje/vfs/Path.java b/old/bridje-vfs/src/main/java/org/bridje/vfs/Path.java index fc2ebc391..3336ef2eb 100644 --- a/old/bridje-vfs/src/main/java/org/bridje/vfs/Path.java +++ b/old/bridje-vfs/src/main/java/org/bridje/vfs/Path.java @@ -1,314 +1,314 @@ - -package org.bridje.vfs; - -import java.util.Arrays; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - -/** - * An utility class for virtual path management. - *

- * The path elements are separated by the {@literal "/"} character. - */ -public class Path implements Iterable -{ - private final String[] pathElements; - - /** - * Creates a Path object from String - *

- * @param path The String object representing the path - */ - public Path(String path) - { - this(createElements(path)); - } - - /** - * Internal constructor that creates a Path from it´s elements. - *

- * @param pathElements - */ - private Path(String[] pathElements) - { - this.pathElements = pathElements; - } - - /** - * Gets the first element of the path. - *

- * For example, if the path represented by this object equals to {@literal "usr/local"}, - * this method will return {@literal "usr"}. - *

- * @return An String object that represents the first element of the path. - */ - public String getFirstElement() - { - return pathElements[0]; - } - - /** - * Gets the first element of the path. - *

- * For example, if the path represented by this object equals to {@literal "usr/local/somefile"}, - * this method will return {@literal "somefile"}. - *

- * @return An String object that represents the first element of the path. - */ - public String getName() - { - return pathElements[pathElements.length - 1]; - } - - /** - * Creates a new Path object that represents the path to the parent object - * of the current path. - *

- * For example, if the path represented by this object equals to {@literal "usr/local/somefile"}, - * this method will return a path object representing {@literal "usr/local"}. - *

- * @return The Path object parent of this object, or {@literal null} if this - * is the last path. - */ - public Path getParent() - { - if (isLast()) - { - return null; - } - String[] copyOfRange = Arrays.copyOfRange(pathElements, 0, pathElements.length - 1); - return new Path(copyOfRange); - } - - /** - * Creates a new Path object that does not contains the first element of - * the current path. - *

- * For example, if the path represented by this object equals to {@literal "usr/local/somefile"}, - * this method will return a path object representing {@literal "/local/somefile"}. - *

- * @return The Path object without the first element of the current path, or - * {@literal null} if this is the las path. - */ - public Path getNext() - { - if (isLast()) - { - return null; - } - - String[] copyOfRange = Arrays.copyOfRange(pathElements, 1, pathElements.length); - return new Path(copyOfRange); - } - - /** - * Determines if this path has any element left. - *

- * For example, if the path represented by this object is a multiple element - * path like {@literal "usr/local"} the this method will return {@literal true}. - *

- * @return {@literal true} if this path is a multi element path, {@literal false} - * otherwise. - */ - public boolean hasNext() - { - return !isLast(); - } - - /** - * Determines if the first element of the path is the dot (.) character - * witch represents the current folder. - *

- * @return {@literal true} if the first element of the path is the dot (.) - * character, {@literal false} otherwise. - */ - public boolean isSelf() - { - if(pathElements.length < 0) - { - return false; - } - return ".".equalsIgnoreCase(pathElements[0]); - } - - /** - * Determines if the first element of the path is the (..) identifier witch - * represents the parent folder. - *

- * @return {@literal true} if the first element of the path is the (..) identifier, - * {@literal false} otherwise. - */ - public boolean isParent() - { - if(pathElements.length < 0) - { - return false; - } - return "..".equalsIgnoreCase(pathElements[0]); - } - - /** - * Determines if this path is the last element path. - *

- * If the path represented by this object is a single element path like - * {@literal "usr"} then this method will return {@literal true}. - *

- * @return {@literal true} if this path is a single element, {@literal false} - * otherwise. - */ - public boolean isLast() - { - return (pathElements.length <= 1); - } - - /** - * This method creates a new path object that does not contains the (.) and - * (..) identifiers. - *

- * For example, if the path represented by this element equals to {@literal "usr/./local/../etc"}, - * this method will return {@link "usr/etc"}. - *

- * @return A new Path object representing the canonical path of this object. - */ - public Path getCanonicalPath() - { - List str = new LinkedList<>(); - for (String pe : pathElements) - { - if (pe.equalsIgnoreCase("..")) - { - if (str.isEmpty()) - { - return null; - } - else - { - str.remove(str.size() - 1); - } - } - else if (!pe.equalsIgnoreCase(".")) - { - str.add(pe); - } - } - if (str.isEmpty()) - { - return null; - } - String[] els = new String[str.size()]; - return new Path(str.toArray(els)); - } - - /** - * Gets a string representation of the current path. - *

- * @return The String object representing the current path. - */ - @Override - public String toString() - { - return toString("/"); - } - - /** - * Gets a string representation of the current path, separated by the - * specified path separator. - *

- * @param pathSep The path separator to be used. - * @return The String object representing the current path. - */ - public String toString(String pathSep) - { - return String.join(pathSep, pathElements); - } - - public Path join(Path path) - { - String[] newElements = new String[pathElements.length + path.pathElements.length]; - System.arraycopy(pathElements, 0, newElements, 0, pathElements.length); - System.arraycopy(path.pathElements, 0, newElements, pathElements.length, path.pathElements.length); - return new Path(newElements); - } - - public Path join(String path) - { - return join(new Path(path)); - } - - @Override - public Iterator iterator() - { - return new Iterator() - { - private int currentIndex = 0; - - @Override - public boolean hasNext() - { - return (currentIndex < pathElements.length); - } - - @Override - public Path next() - { - String[] copyOfRange = Arrays.copyOfRange(pathElements, 0, currentIndex + 1); - currentIndex++; - return new Path(copyOfRange); - } - }; - } - - private static String[] createElements(String path) - { - if (path == null || path.trim().isEmpty()) - { - throw new IllegalArgumentException("The specified path is not valid."); - } - - String newPath = path; - String toReplace = "\\"; - while (newPath.contains(toReplace)) - { - newPath = newPath.replace(toReplace, "/"); - } - - if (path.startsWith("/")) - { - newPath = newPath.substring(1); - } - if (newPath.endsWith("/")) - { - newPath = newPath.substring(0, newPath.length() - 1); - } - - if (newPath.trim().isEmpty()) - { - return new String[]{}; - } - - String[] arr = newPath.trim().split("/"); - return arr; - } - - @Override - public int hashCode() - { - return toString().hashCode(); - } - - @Override - public boolean equals(Object obj) - { - if (obj == null) - { - return false; - } - if (getClass() != obj.getClass()) - { - return false; - } - final Path other = (Path) obj; - return toString().equals(other.toString()); - } -} + +package org.bridje.vfs; + +import java.util.Arrays; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; + +/** + * An utility class for virtual path management. + *

+ * The path elements are separated by the {@literal "/"} character. + */ +public class Path implements Iterable +{ + private final String[] pathElements; + + /** + * Creates a Path object from String + *

+ * @param path The String object representing the path + */ + public Path(String path) + { + this(createElements(path)); + } + + /** + * Internal constructor that creates a Path from it´s elements. + *

+ * @param pathElements + */ + private Path(String[] pathElements) + { + this.pathElements = pathElements; + } + + /** + * Gets the first element of the path. + *

+ * For example, if the path represented by this object equals to {@literal "usr/local"}, + * this method will return {@literal "usr"}. + *

+ * @return An String object that represents the first element of the path. + */ + public String getFirstElement() + { + return pathElements[0]; + } + + /** + * Gets the first element of the path. + *

+ * For example, if the path represented by this object equals to {@literal "usr/local/somefile"}, + * this method will return {@literal "somefile"}. + *

+ * @return An String object that represents the first element of the path. + */ + public String getName() + { + return pathElements[pathElements.length - 1]; + } + + /** + * Creates a new Path object that represents the path to the parent object + * of the current path. + *

+ * For example, if the path represented by this object equals to {@literal "usr/local/somefile"}, + * this method will return a path object representing {@literal "usr/local"}. + *

+ * @return The Path object parent of this object, or {@literal null} if this + * is the last path. + */ + public Path getParent() + { + if (isLast()) + { + return null; + } + String[] copyOfRange = Arrays.copyOfRange(pathElements, 0, pathElements.length - 1); + return new Path(copyOfRange); + } + + /** + * Creates a new Path object that does not contains the first element of + * the current path. + *

+ * For example, if the path represented by this object equals to {@literal "usr/local/somefile"}, + * this method will return a path object representing {@literal "/local/somefile"}. + *

+ * @return The Path object without the first element of the current path, or + * {@literal null} if this is the las path. + */ + public Path getNext() + { + if (isLast()) + { + return null; + } + + String[] copyOfRange = Arrays.copyOfRange(pathElements, 1, pathElements.length); + return new Path(copyOfRange); + } + + /** + * Determines if this path has any element left. + *

+ * For example, if the path represented by this object is a multiple element + * path like {@literal "usr/local"} the this method will return {@literal true}. + *

+ * @return {@literal true} if this path is a multi element path, {@literal false} + * otherwise. + */ + public boolean hasNext() + { + return !isLast(); + } + + /** + * Determines if the first element of the path is the dot (.) character + * witch represents the current folder. + *

+ * @return {@literal true} if the first element of the path is the dot (.) + * character, {@literal false} otherwise. + */ + public boolean isSelf() + { + if(pathElements.length < 0) + { + return false; + } + return ".".equalsIgnoreCase(pathElements[0]); + } + + /** + * Determines if the first element of the path is the (..) identifier witch + * represents the parent folder. + *

+ * @return {@literal true} if the first element of the path is the (..) identifier, + * {@literal false} otherwise. + */ + public boolean isParent() + { + if(pathElements.length < 0) + { + return false; + } + return "..".equalsIgnoreCase(pathElements[0]); + } + + /** + * Determines if this path is the last element path. + *

+ * If the path represented by this object is a single element path like + * {@literal "usr"} then this method will return {@literal true}. + *

+ * @return {@literal true} if this path is a single element, {@literal false} + * otherwise. + */ + public boolean isLast() + { + return (pathElements.length <= 1); + } + + /** + * This method creates a new path object that does not contains the (.) and + * (..) identifiers. + *

+ * For example, if the path represented by this element equals to {@literal "usr/./local/../etc"}, + * this method will return {@link "usr/etc"}. + *

+ * @return A new Path object representing the canonical path of this object. + */ + public Path getCanonicalPath() + { + List str = new LinkedList<>(); + for (String pe : pathElements) + { + if (pe.equalsIgnoreCase("..")) + { + if (str.isEmpty()) + { + return null; + } + else + { + str.remove(str.size() - 1); + } + } + else if (!pe.equalsIgnoreCase(".")) + { + str.add(pe); + } + } + if (str.isEmpty()) + { + return null; + } + String[] els = new String[str.size()]; + return new Path(str.toArray(els)); + } + + /** + * Gets a string representation of the current path. + *

+ * @return The String object representing the current path. + */ + @Override + public String toString() + { + return toString("/"); + } + + /** + * Gets a string representation of the current path, separated by the + * specified path separator. + *

+ * @param pathSep The path separator to be used. + * @return The String object representing the current path. + */ + public String toString(String pathSep) + { + return String.join(pathSep, pathElements); + } + + public Path join(Path path) + { + String[] newElements = new String[pathElements.length + path.pathElements.length]; + System.arraycopy(pathElements, 0, newElements, 0, pathElements.length); + System.arraycopy(path.pathElements, 0, newElements, pathElements.length, path.pathElements.length); + return new Path(newElements); + } + + public Path join(String path) + { + return join(new Path(path)); + } + + @Override + public Iterator iterator() + { + return new Iterator() + { + private int currentIndex = 0; + + @Override + public boolean hasNext() + { + return (currentIndex < pathElements.length); + } + + @Override + public Path next() + { + String[] copyOfRange = Arrays.copyOfRange(pathElements, 0, currentIndex + 1); + currentIndex++; + return new Path(copyOfRange); + } + }; + } + + private static String[] createElements(String path) + { + if (path == null || path.trim().isEmpty()) + { + throw new IllegalArgumentException("The specified path is not valid."); + } + + String newPath = path; + String toReplace = "\\"; + while (newPath.contains(toReplace)) + { + newPath = newPath.replace(toReplace, "/"); + } + + if (path.startsWith("/")) + { + newPath = newPath.substring(1); + } + if (newPath.endsWith("/")) + { + newPath = newPath.substring(0, newPath.length() - 1); + } + + if (newPath.trim().isEmpty()) + { + return new String[]{}; + } + + String[] arr = newPath.trim().split("/"); + return arr; + } + + @Override + public int hashCode() + { + return toString().hashCode(); + } + + @Override + public boolean equals(Object obj) + { + if (obj == null) + { + return false; + } + if (getClass() != obj.getClass()) + { + return false; + } + final Path other = (Path) obj; + return toString().equals(other.toString()); + } +} diff --git a/old/bridje-vfs/src/main/java/org/bridje/vfs/VfsMountConfig.java b/old/bridje-vfs/src/main/java/org/bridje/vfs/VfsMountConfig.java index 23a7eb2fc..4425b2b1a 100644 --- a/old/bridje-vfs/src/main/java/org/bridje/vfs/VfsMountConfig.java +++ b/old/bridje-vfs/src/main/java/org/bridje/vfs/VfsMountConfig.java @@ -1,24 +1,24 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.vfs; - -import java.util.List; - -public interface VfsMountConfig -{ - List getEntries(); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.vfs; + +import java.util.List; + +public interface VfsMountConfig +{ + List getEntries(); +} diff --git a/old/bridje-vfs/src/main/java/org/bridje/vfs/VfsMountEntry.java b/old/bridje-vfs/src/main/java/org/bridje/vfs/VfsMountEntry.java index 8d8a19ff4..1a1766027 100644 --- a/old/bridje-vfs/src/main/java/org/bridje/vfs/VfsMountEntry.java +++ b/old/bridje-vfs/src/main/java/org/bridje/vfs/VfsMountEntry.java @@ -1,75 +1,75 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.vfs; - -import java.util.Map; - -public class VfsMountEntry -{ - private String mountPath; - - private String fileSystem; - - private Map properties; - - public VfsMountEntry() - { - } - - public VfsMountEntry(String mountPath, String fileSystem) - { - this.mountPath = mountPath; - this.fileSystem = fileSystem; - } - - public VfsMountEntry(String mountPath, String fileSystem, Map properties) - { - this.mountPath = mountPath; - this.fileSystem = fileSystem; - this.properties = properties; - } - - public String getMountPath() - { - return mountPath; - } - - public void setMountPath(String mountPath) - { - this.mountPath = mountPath; - } - - public String getFileSystem() - { - return fileSystem; - } - - public void setFileSystem(String fileSystem) - { - this.fileSystem = fileSystem; - } - - public Map getProperties() - { - return properties; - } - - public void setProperties(Map properties) - { - this.properties = properties; - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.vfs; + +import java.util.Map; + +public class VfsMountEntry +{ + private String mountPath; + + private String fileSystem; + + private Map properties; + + public VfsMountEntry() + { + } + + public VfsMountEntry(String mountPath, String fileSystem) + { + this.mountPath = mountPath; + this.fileSystem = fileSystem; + } + + public VfsMountEntry(String mountPath, String fileSystem, Map properties) + { + this.mountPath = mountPath; + this.fileSystem = fileSystem; + this.properties = properties; + } + + public String getMountPath() + { + return mountPath; + } + + public void setMountPath(String mountPath) + { + this.mountPath = mountPath; + } + + public String getFileSystem() + { + return fileSystem; + } + + public void setFileSystem(String fileSystem) + { + this.fileSystem = fileSystem; + } + + public Map getProperties() + { + return properties; + } + + public void setProperties(Map properties) + { + this.properties = properties; + } +} diff --git a/old/bridje-vfs/src/main/java/org/bridje/vfs/VfsProvider.java b/old/bridje-vfs/src/main/java/org/bridje/vfs/VfsProvider.java index cd84b61dc..7795640f4 100644 --- a/old/bridje-vfs/src/main/java/org/bridje/vfs/VfsProvider.java +++ b/old/bridje-vfs/src/main/java/org/bridje/vfs/VfsProvider.java @@ -1,24 +1,24 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.vfs; - -public interface VfsProvider -{ - String getName(); - - VfsSource createVfsSource(VfsMountEntry entry); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.vfs; + +public interface VfsProvider +{ + String getName(); + + VfsSource createVfsSource(VfsMountEntry entry); +} diff --git a/old/bridje-vfs/src/main/java/org/bridje/vfs/VfsService.java b/old/bridje-vfs/src/main/java/org/bridje/vfs/VfsService.java index 6cafa1bcd..94ffabebc 100644 --- a/old/bridje-vfs/src/main/java/org/bridje/vfs/VfsService.java +++ b/old/bridje-vfs/src/main/java/org/bridje/vfs/VfsService.java @@ -1,40 +1,40 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.vfs; - -import java.util.List; - -public interface VfsService -{ - VirtualFolder findFolder(String path); - - VirtualFolder findFolder(Path path); - - VirtualFile findFile(String path); - - VirtualFile findFile(Path path); - - List listFolders(); - - List listFiles(); - - void mount(Path path, VfsSource source); - - void travel(VirtualFileVisitor visitor); - - void travel(VirtualFolderVisitor visitor); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.vfs; + +import java.util.List; + +public interface VfsService +{ + VirtualFolder findFolder(String path); + + VirtualFolder findFolder(Path path); + + VirtualFile findFile(String path); + + VirtualFile findFile(Path path); + + List listFolders(); + + List listFiles(); + + void mount(Path path, VfsSource source); + + void travel(VirtualFileVisitor visitor); + + void travel(VirtualFolderVisitor visitor); +} diff --git a/old/bridje-vfs/src/main/java/org/bridje/vfs/VfsSource.java b/old/bridje-vfs/src/main/java/org/bridje/vfs/VfsSource.java index 5c0764d50..40ebb0459 100644 --- a/old/bridje-vfs/src/main/java/org/bridje/vfs/VfsSource.java +++ b/old/bridje-vfs/src/main/java/org/bridje/vfs/VfsSource.java @@ -1,102 +1,102 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.vfs; - -import java.io.IOException; -import java.io.InputStream; -import java.util.List; - -/** - * Represents a file source for the VFS API. - *

- * All VfsProvider implementation must provides an object that implements this - * interface in order to put files in the vfs tree. - */ -public interface VfsSource -{ - /** - * Gets all objects identifying the files in the specified path, if the - * file represented by the path argument is a single file within the - * VfsSource this method will return a single file object array, but if - * multiple files within the VfsSource are map to the specified path then - * this method will return all objects files for the path. - *

- * @param path The path to look for. - * @return An array of object, each acts as identifier for a file mapped to - * the path argument. - * @throws IOException This method may access to physical device so this - * exception may be throw if any input output operation fails. - */ - Object[] getFiles(Path path) throws IOException; - - /** - * This method retrieve all names for the child folders within the - * specified path. - *

- * @param path The path to look for children folders. - * @return A list of string with the names of the child folders for the - * specified path. - * @throws IOException This method may access to physical device so this - * exception may be throw if any input output operation fails. - */ - List listFolders(Path path) throws IOException; - - /** - * This method retrieve all names for the child files within the specified - * path. - *

- * @param path The path to look for children files. - * @return A list of string with the names of the child file for the - * specified path. - * @throws IOException This method may access to physical device so this - * exception may be throw if any input output operation fails. - */ - List listFiles(Path path) throws IOException; - - /** - * Determines if the specified path is a file from this VfsSource. - *

- * @param path The path of the file. - * @return {@literal true} if a file mapped to the path argument exists within - * this VfsSource. - * @throws IOException This method may access to physical device so this - * exception may be throw if any input output operation fails. - */ - boolean fileExists(Path path) throws IOException; - - /** - * Determines if the specified path is a folder from this VfsSource. - *

- * @param path The path of the file. - * @return {@literal true} if a folder mapped to the path argument exists within - * this VfsSource. - * @throws IOException This method may access to physical device so this - * exception may be throw if any input output operation fails. - */ - boolean folderExists(Path path) throws IOException; - - /** - * Open a file's InputStream for reading it's content. - *

- * @param data The file identifier retrieve from this VfsSource by the - * {@link #getFiles(org.bridje.core.vfs.Path)} method. - * @return An InputStream to the file. - * @throws IOException This method may access to physical device so this - * exception may be throw if any input output operation fails. - */ - InputStream open(Object data) throws IOException; -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.vfs; + +import java.io.IOException; +import java.io.InputStream; +import java.util.List; + +/** + * Represents a file source for the VFS API. + *

+ * All VfsProvider implementation must provides an object that implements this + * interface in order to put files in the vfs tree. + */ +public interface VfsSource +{ + /** + * Gets all objects identifying the files in the specified path, if the + * file represented by the path argument is a single file within the + * VfsSource this method will return a single file object array, but if + * multiple files within the VfsSource are map to the specified path then + * this method will return all objects files for the path. + *

+ * @param path The path to look for. + * @return An array of object, each acts as identifier for a file mapped to + * the path argument. + * @throws IOException This method may access to physical device so this + * exception may be throw if any input output operation fails. + */ + Object[] getFiles(Path path) throws IOException; + + /** + * This method retrieve all names for the child folders within the + * specified path. + *

+ * @param path The path to look for children folders. + * @return A list of string with the names of the child folders for the + * specified path. + * @throws IOException This method may access to physical device so this + * exception may be throw if any input output operation fails. + */ + List listFolders(Path path) throws IOException; + + /** + * This method retrieve all names for the child files within the specified + * path. + *

+ * @param path The path to look for children files. + * @return A list of string with the names of the child file for the + * specified path. + * @throws IOException This method may access to physical device so this + * exception may be throw if any input output operation fails. + */ + List listFiles(Path path) throws IOException; + + /** + * Determines if the specified path is a file from this VfsSource. + *

+ * @param path The path of the file. + * @return {@literal true} if a file mapped to the path argument exists within + * this VfsSource. + * @throws IOException This method may access to physical device so this + * exception may be throw if any input output operation fails. + */ + boolean fileExists(Path path) throws IOException; + + /** + * Determines if the specified path is a folder from this VfsSource. + *

+ * @param path The path of the file. + * @return {@literal true} if a folder mapped to the path argument exists within + * this VfsSource. + * @throws IOException This method may access to physical device so this + * exception may be throw if any input output operation fails. + */ + boolean folderExists(Path path) throws IOException; + + /** + * Open a file's InputStream for reading it's content. + *

+ * @param data The file identifier retrieve from this VfsSource by the + * {@link #getFiles(org.bridje.core.vfs.Path)} method. + * @return An InputStream to the file. + * @throws IOException This method may access to physical device so this + * exception may be throw if any input output operation fails. + */ + InputStream open(Object data) throws IOException; +} diff --git a/old/bridje-vfs/src/main/java/org/bridje/vfs/VirtualFile.java b/old/bridje-vfs/src/main/java/org/bridje/vfs/VirtualFile.java index 01b1b617e..bcddc872e 100644 --- a/old/bridje-vfs/src/main/java/org/bridje/vfs/VirtualFile.java +++ b/old/bridje-vfs/src/main/java/org/bridje/vfs/VirtualFile.java @@ -1,35 +1,35 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.vfs; - -import java.io.IOException; -import java.io.InputStream; - -/** - * Represents a file of the VFS tree. - */ -public interface VirtualFile extends VirtualResource -{ - /** - * Open a file's InputStream for reading it's content. - *

- * @return An InputStream to the file. - * @throws IOException This method may access to physical device so this - * exception may be throw if any input output operation fails. - */ - InputStream open() throws IOException; -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.vfs; + +import java.io.IOException; +import java.io.InputStream; + +/** + * Represents a file of the VFS tree. + */ +public interface VirtualFile extends VirtualResource +{ + /** + * Open a file's InputStream for reading it's content. + *

+ * @return An InputStream to the file. + * @throws IOException This method may access to physical device so this + * exception may be throw if any input output operation fails. + */ + InputStream open() throws IOException; +} diff --git a/old/bridje-vfs/src/main/java/org/bridje/vfs/VirtualFileVisitor.java b/old/bridje-vfs/src/main/java/org/bridje/vfs/VirtualFileVisitor.java index 66e555202..a5ccc0822 100644 --- a/old/bridje-vfs/src/main/java/org/bridje/vfs/VirtualFileVisitor.java +++ b/old/bridje-vfs/src/main/java/org/bridje/vfs/VirtualFileVisitor.java @@ -1,31 +1,31 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.vfs; - -/** - * A functional interface to navigates files in the vfs tree. - */ -@FunctionalInterface -public interface VirtualFileVisitor -{ - /** - * Called when a match is hit in the navigation method. - *

- * @param file The file matched. - */ - public void visit(VirtualFile file); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.vfs; + +/** + * A functional interface to navigates files in the vfs tree. + */ +@FunctionalInterface +public interface VirtualFileVisitor +{ + /** + * Called when a match is hit in the navigation method. + *

+ * @param file The file matched. + */ + public void visit(VirtualFile file); +} diff --git a/old/bridje-vfs/src/main/java/org/bridje/vfs/VirtualFolder.java b/old/bridje-vfs/src/main/java/org/bridje/vfs/VirtualFolder.java index 4f04cc4a6..5602e0e0b 100644 --- a/old/bridje-vfs/src/main/java/org/bridje/vfs/VirtualFolder.java +++ b/old/bridje-vfs/src/main/java/org/bridje/vfs/VirtualFolder.java @@ -1,97 +1,97 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.vfs; - -import java.util.List; - -/** - * Represents a folder of the VFS tree. - */ -public interface VirtualFolder extends VirtualResource -{ - /** - * Finds a folder mapped to the specified path. - *

- * @param path The string representation of the path to the folder. - * @return A VirtualFolder object representing the folder mapped to the path - * argument or null if the specified path is not a valid folder in - * the vfs tree. - */ - VirtualFolder findFolder(String path); - - /** - * Finds a folder mapped to the specified path. - *

- * @param path The path to the folder. - * @return A VirtualFolder object representing the folder mapped to the path - * argument or {@literal null} if the specified path is not a valid - * folder in the vfs tree. - */ - VirtualFolder findFolder(Path path); - - /** - * Finds a file mapped to the specified path. - *

- * @param path The string representation of the path to the file. - * @return A VirtualFile object representing the file mapped to the path - * argument or null if the specified path is not a valid folder in - * the vfs tree. - */ - VirtualFile findFile(String path); - - /** - * Finds a file mapped to the specified path. - *

- * @param path The path to the file. - * @return A VirtualFile object representing the file mapped to the path - * argument or null if the specified path is not a valid folder in - * the vfs tree. - */ - VirtualFile findFile(Path path); - - /** - * Gets a list of all child folders of this folder. - *

- * @return A List of VirtualFolders representing the child folders of this - * folder. - */ - List listFolders(); - - /** - * Gets a list of all child files of this folder. - *

- * @return A List of VirtualFiles representing the child files of this - * folder. - */ - List listFiles(); - - /** - * Travels through all files recursively from this folder and its children - * folders. - *

- * @param visitor The visitor to be used. - */ - void travel(VirtualFileVisitor visitor); - - /** - * Travels through all folders recursively from this folder and its children - * folders. - *

- * @param visitor The visitor to be used. - */ - void travel(VirtualFolderVisitor visitor); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.vfs; + +import java.util.List; + +/** + * Represents a folder of the VFS tree. + */ +public interface VirtualFolder extends VirtualResource +{ + /** + * Finds a folder mapped to the specified path. + *

+ * @param path The string representation of the path to the folder. + * @return A VirtualFolder object representing the folder mapped to the path + * argument or null if the specified path is not a valid folder in + * the vfs tree. + */ + VirtualFolder findFolder(String path); + + /** + * Finds a folder mapped to the specified path. + *

+ * @param path The path to the folder. + * @return A VirtualFolder object representing the folder mapped to the path + * argument or {@literal null} if the specified path is not a valid + * folder in the vfs tree. + */ + VirtualFolder findFolder(Path path); + + /** + * Finds a file mapped to the specified path. + *

+ * @param path The string representation of the path to the file. + * @return A VirtualFile object representing the file mapped to the path + * argument or null if the specified path is not a valid folder in + * the vfs tree. + */ + VirtualFile findFile(String path); + + /** + * Finds a file mapped to the specified path. + *

+ * @param path The path to the file. + * @return A VirtualFile object representing the file mapped to the path + * argument or null if the specified path is not a valid folder in + * the vfs tree. + */ + VirtualFile findFile(Path path); + + /** + * Gets a list of all child folders of this folder. + *

+ * @return A List of VirtualFolders representing the child folders of this + * folder. + */ + List listFolders(); + + /** + * Gets a list of all child files of this folder. + *

+ * @return A List of VirtualFiles representing the child files of this + * folder. + */ + List listFiles(); + + /** + * Travels through all files recursively from this folder and its children + * folders. + *

+ * @param visitor The visitor to be used. + */ + void travel(VirtualFileVisitor visitor); + + /** + * Travels through all folders recursively from this folder and its children + * folders. + *

+ * @param visitor The visitor to be used. + */ + void travel(VirtualFolderVisitor visitor); +} diff --git a/old/bridje-vfs/src/main/java/org/bridje/vfs/VirtualFolderVisitor.java b/old/bridje-vfs/src/main/java/org/bridje/vfs/VirtualFolderVisitor.java index c542fad86..613bb47a7 100644 --- a/old/bridje-vfs/src/main/java/org/bridje/vfs/VirtualFolderVisitor.java +++ b/old/bridje-vfs/src/main/java/org/bridje/vfs/VirtualFolderVisitor.java @@ -1,31 +1,31 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.vfs; - -/** - * A functional interface to navigates folders in the vfs tree. - */ -@FunctionalInterface -public interface VirtualFolderVisitor -{ - /** - * Called when a match is hit in the navigation method. - *

- * @param folder The file matched. - */ - public void visit(VirtualFolder folder); +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.vfs; + +/** + * A functional interface to navigates folders in the vfs tree. + */ +@FunctionalInterface +public interface VirtualFolderVisitor +{ + /** + * Called when a match is hit in the navigation method. + *

+ * @param folder The file matched. + */ + public void visit(VirtualFolder folder); } \ No newline at end of file diff --git a/old/bridje-vfs/src/main/java/org/bridje/vfs/VirtualResource.java b/old/bridje-vfs/src/main/java/org/bridje/vfs/VirtualResource.java index 93074c863..baa799f06 100644 --- a/old/bridje-vfs/src/main/java/org/bridje/vfs/VirtualResource.java +++ b/old/bridje-vfs/src/main/java/org/bridje/vfs/VirtualResource.java @@ -1,38 +1,38 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.vfs; - -/** - * Base interface for all resource type in the VFS tree. - *

- * This interface represents a file or folder in the VFS tree. - */ -public interface VirtualResource -{ - /** - * The parent folder of this resource. - *

- * @return A VirtualFlder representing the parent folder of this resource. - */ - VirtualFolder getParent(); - - String getName(); - - Path getPath(); - - Path getParentPath(); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.vfs; + +/** + * Base interface for all resource type in the VFS tree. + *

+ * This interface represents a file or folder in the VFS tree. + */ +public interface VirtualResource +{ + /** + * The parent folder of this resource. + *

+ * @return A VirtualFlder representing the parent folder of this resource. + */ + VirtualFolder getParent(); + + String getName(); + + Path getPath(); + + Path getParentPath(); +} diff --git a/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/AbstractResource.java b/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/AbstractResource.java index 2099639eb..0b6c8f95e 100644 --- a/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/AbstractResource.java +++ b/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/AbstractResource.java @@ -1,125 +1,125 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.vfs.impl; - - -import java.util.List; -import org.bridje.ioc.Ioc; -import org.bridje.vfs.Path; -import org.bridje.vfs.VfsService; -import org.bridje.vfs.VirtualFile; -import org.bridje.vfs.VirtualFileVisitor; -import org.bridje.vfs.VirtualFolder; -import org.bridje.vfs.VirtualFolderVisitor; -import org.bridje.vfs.VirtualResource; - -abstract class AbstractResource implements VirtualResource -{ - private static VfsService VFS; - - private final Path path; - - AbstractResource(Path path) - { - this.path = path; - } - - @Override - public VirtualFolder getParent() - { - if (getPath() == null) - { - return null; - } - - return vfs().findFolder(getPath().getParent()); - } - - @Override - public String getName() - { - if(getPath() == null) - { - return null; - } - return getPath().getName(); - } - - @Override - public Path getPath() - { - return path; - } - - @Override - public Path getParentPath() - { - if(getPath() == null) - { - return null; - } - return getPath().getParent(); - } - - static VfsService vfs() - { - if(VFS == null) - { - VFS = Ioc.context().find(VfsService.class); - } - return VFS; - } - - @Override - public String toString() - { - return getPath().toString(); - } - - static void travel(VirtualFolder rootFolder, VirtualFileVisitor visitor) - { - List listFolders = rootFolder.listFolders(); - if(listFolders != null) - { - for (VirtualFolder folder : listFolders) - { - folder.travel(visitor); - } - } - List listFiles = rootFolder.listFiles(); - if(listFiles != null) - { - for (VirtualFile file : listFiles) - { - visitor.visit(file); - } - } - } - - static void travel(VirtualFolder rootFolder, VirtualFolderVisitor visitor) - { - List listFolders = rootFolder.listFolders(); - if(listFolders != null) - { - for (VirtualFolder folder : listFolders) - { - visitor.visit(folder); - folder.travel(visitor); - } - } - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.vfs.impl; + + +import java.util.List; +import org.bridje.ioc.Ioc; +import org.bridje.vfs.Path; +import org.bridje.vfs.VfsService; +import org.bridje.vfs.VirtualFile; +import org.bridje.vfs.VirtualFileVisitor; +import org.bridje.vfs.VirtualFolder; +import org.bridje.vfs.VirtualFolderVisitor; +import org.bridje.vfs.VirtualResource; + +abstract class AbstractResource implements VirtualResource +{ + private static VfsService VFS; + + private final Path path; + + AbstractResource(Path path) + { + this.path = path; + } + + @Override + public VirtualFolder getParent() + { + if (getPath() == null) + { + return null; + } + + return vfs().findFolder(getPath().getParent()); + } + + @Override + public String getName() + { + if(getPath() == null) + { + return null; + } + return getPath().getName(); + } + + @Override + public Path getPath() + { + return path; + } + + @Override + public Path getParentPath() + { + if(getPath() == null) + { + return null; + } + return getPath().getParent(); + } + + static VfsService vfs() + { + if(VFS == null) + { + VFS = Ioc.context().find(VfsService.class); + } + return VFS; + } + + @Override + public String toString() + { + return getPath().toString(); + } + + static void travel(VirtualFolder rootFolder, VirtualFileVisitor visitor) + { + List listFolders = rootFolder.listFolders(); + if(listFolders != null) + { + for (VirtualFolder folder : listFolders) + { + folder.travel(visitor); + } + } + List listFiles = rootFolder.listFiles(); + if(listFiles != null) + { + for (VirtualFile file : listFiles) + { + visitor.visit(file); + } + } + } + + static void travel(VirtualFolder rootFolder, VirtualFolderVisitor visitor) + { + List listFolders = rootFolder.listFolders(); + if(listFolders != null) + { + for (VirtualFolder folder : listFolders) + { + visitor.visit(folder); + folder.travel(visitor); + } + } + } +} diff --git a/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/ByteArrayFile.java b/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/ByteArrayFile.java index 69f08d268..b92bdb37d 100644 --- a/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/ByteArrayFile.java +++ b/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/ByteArrayFile.java @@ -1,39 +1,39 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.vfs.impl; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import org.bridje.vfs.Path; -import org.bridje.vfs.VirtualFile; - -class ByteArrayFile extends MemoryFile implements VirtualFile -{ - private final byte[] bytes; - - public ByteArrayFile(byte[] bytes, Path path) - { - super(path); - this.bytes = bytes; - } - - @Override - public InputStream open() - { - return new ByteArrayInputStream(bytes); - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.vfs.impl; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import org.bridje.vfs.Path; +import org.bridje.vfs.VirtualFile; + +class ByteArrayFile extends MemoryFile implements VirtualFile +{ + private final byte[] bytes; + + public ByteArrayFile(byte[] bytes, Path path) + { + super(path); + this.bytes = bytes; + } + + @Override + public InputStream open() + { + return new ByteArrayInputStream(bytes); + } +} diff --git a/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/MemoryFile.java b/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/MemoryFile.java index 33bda488a..9de18f87e 100644 --- a/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/MemoryFile.java +++ b/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/MemoryFile.java @@ -1,28 +1,28 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.vfs.impl; - -import org.bridje.vfs.Path; -import org.bridje.vfs.VirtualFile; - -abstract class MemoryFile extends AbstractResource implements VirtualFile -{ - public MemoryFile(Path path) - { - super(path); - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.vfs.impl; + +import org.bridje.vfs.Path; +import org.bridje.vfs.VirtualFile; + +abstract class MemoryFile extends AbstractResource implements VirtualFile +{ + public MemoryFile(Path path) + { + super(path); + } +} diff --git a/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/MemoryFolder.java b/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/MemoryFolder.java index 0a6a02a56..623d00225 100644 --- a/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/MemoryFolder.java +++ b/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/MemoryFolder.java @@ -1,253 +1,253 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.vfs.impl; - -import java.util.LinkedHashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import org.bridje.vfs.Path; -import org.bridje.vfs.VirtualFile; -import org.bridje.vfs.VirtualFileVisitor; -import org.bridje.vfs.VirtualFolder; -import org.bridje.vfs.VirtualFolderVisitor; - -class MemoryFolder extends AbstractResource implements VirtualFolder -{ - private Map folders; - - private Map files; - - MemoryFolder(Path path) - { - super(path); - } - - @Override - public VirtualFolder findFolder(Path path) - { - if(folders == null || path == null) - { - return null; - } - if(path.isLast()) - { - if(path.isSelf()) - { - return this; - } - else if(path.isParent()) - { - return getParent(); - } - return folders.get(path.getName()); - } - else - { - VirtualFolder folder; - if(path.isSelf()) - { - folder = this; - } - else if(path.isParent()) - { - folder = getParent(); - } - else - { - folder = folders.get(path.getFirstElement()); - } - if(folder == null) - { - return null; - } - return folder.findFolder(path.getNext()); - } - } - - @Override - public VirtualFile findFile(Path path) - { - if(path == null) - { - return null; - } - if(path.isLast()) - { - if(files == null || path.isSelf() || path.isParent()) - { - return null; - } - return files.get(path.getFirstElement()); - } - else - { - if(folders == null) - { - return null; - } - VirtualFolder nextFolder; - if(path.isSelf()) - { - nextFolder = this; - } - else - { - if(path.isParent()) - { - nextFolder = getParent(); - } - else - { - nextFolder = folders.get(path.getFirstElement()); - } - } - if(nextFolder == null) - { - return null; - } - return nextFolder.findFile(path.getNext()); - } - } - - @Override - public VirtualFolder findFolder(String path) - { - return findFolder(new Path(path)); - } - - @Override - public VirtualFile findFile(String path) - { - return findFile(new Path(path)); - } - - @Override - public List listFolders() - { - if(folders == null) - { - return null; - } - List result = new LinkedList<>(); - result.addAll(folders.values()); - return result; - } - - @Override - public List listFiles() - { - if(files == null) - { - return null; - } - List result = new LinkedList<>(); - result.addAll(files.values()); - return result; - } - - T addFolder(T virtualFolder) - { - if(virtualFolder == null || virtualFolder.getName() == null || virtualFolder.getName().trim().isEmpty()) - { - return null; - } - if(folders == null) - { - folders = new LinkedHashMap<>(); - } - VirtualFolder vf = folders.get(virtualFolder.getName()); - if(vf != null) - { - if(vf instanceof ProxyFolder) - { - ((ProxyFolder)vf).add(virtualFolder); - } - else - { - ProxyFolder pf = new ProxyFolder(); - pf.add(vf); - pf.add(virtualFolder); - } - } - else - { - folders.put(virtualFolder.getName(), virtualFolder); - } - return virtualFolder; - } - - void removeFolder(VirtualFolder virtualFolder) - { - if(folders != null) - { - folders.remove(virtualFolder.getName()); - } - } - - T addFile(T virtualFile) - { - if(virtualFile == null || virtualFile.getName() == null || virtualFile.getName().trim().isEmpty()) - { - return null; - } - if(files == null) - { - files = new LinkedHashMap<>(); - } - VirtualFile vf = files.get(virtualFile.getName()); - if(vf != null) - { - if(vf instanceof ProxyFile) - { - ((ProxyFile)vf).add(virtualFile); - } - else - { - ProxyFile pf = new ProxyFile(); - pf.add(vf); - pf.add(virtualFile); - } - } - else - { - files.put(virtualFile.getName(), virtualFile); - } - return virtualFile; - } - - void removeFile(VirtualFile virtualFile) - { - if(files == null) - { - files = new LinkedHashMap<>(); - } - files.remove(virtualFile.getName()); - } - - @Override - public void travel(VirtualFileVisitor visitor) - { - travel(this, visitor); - } - - @Override - public void travel(VirtualFolderVisitor visitor) - { - travel(this, visitor); - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.vfs.impl; + +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import org.bridje.vfs.Path; +import org.bridje.vfs.VirtualFile; +import org.bridje.vfs.VirtualFileVisitor; +import org.bridje.vfs.VirtualFolder; +import org.bridje.vfs.VirtualFolderVisitor; + +class MemoryFolder extends AbstractResource implements VirtualFolder +{ + private Map folders; + + private Map files; + + MemoryFolder(Path path) + { + super(path); + } + + @Override + public VirtualFolder findFolder(Path path) + { + if(folders == null || path == null) + { + return null; + } + if(path.isLast()) + { + if(path.isSelf()) + { + return this; + } + else if(path.isParent()) + { + return getParent(); + } + return folders.get(path.getName()); + } + else + { + VirtualFolder folder; + if(path.isSelf()) + { + folder = this; + } + else if(path.isParent()) + { + folder = getParent(); + } + else + { + folder = folders.get(path.getFirstElement()); + } + if(folder == null) + { + return null; + } + return folder.findFolder(path.getNext()); + } + } + + @Override + public VirtualFile findFile(Path path) + { + if(path == null) + { + return null; + } + if(path.isLast()) + { + if(files == null || path.isSelf() || path.isParent()) + { + return null; + } + return files.get(path.getFirstElement()); + } + else + { + if(folders == null) + { + return null; + } + VirtualFolder nextFolder; + if(path.isSelf()) + { + nextFolder = this; + } + else + { + if(path.isParent()) + { + nextFolder = getParent(); + } + else + { + nextFolder = folders.get(path.getFirstElement()); + } + } + if(nextFolder == null) + { + return null; + } + return nextFolder.findFile(path.getNext()); + } + } + + @Override + public VirtualFolder findFolder(String path) + { + return findFolder(new Path(path)); + } + + @Override + public VirtualFile findFile(String path) + { + return findFile(new Path(path)); + } + + @Override + public List listFolders() + { + if(folders == null) + { + return null; + } + List result = new LinkedList<>(); + result.addAll(folders.values()); + return result; + } + + @Override + public List listFiles() + { + if(files == null) + { + return null; + } + List result = new LinkedList<>(); + result.addAll(files.values()); + return result; + } + + T addFolder(T virtualFolder) + { + if(virtualFolder == null || virtualFolder.getName() == null || virtualFolder.getName().trim().isEmpty()) + { + return null; + } + if(folders == null) + { + folders = new LinkedHashMap<>(); + } + VirtualFolder vf = folders.get(virtualFolder.getName()); + if(vf != null) + { + if(vf instanceof ProxyFolder) + { + ((ProxyFolder)vf).add(virtualFolder); + } + else + { + ProxyFolder pf = new ProxyFolder(); + pf.add(vf); + pf.add(virtualFolder); + } + } + else + { + folders.put(virtualFolder.getName(), virtualFolder); + } + return virtualFolder; + } + + void removeFolder(VirtualFolder virtualFolder) + { + if(folders != null) + { + folders.remove(virtualFolder.getName()); + } + } + + T addFile(T virtualFile) + { + if(virtualFile == null || virtualFile.getName() == null || virtualFile.getName().trim().isEmpty()) + { + return null; + } + if(files == null) + { + files = new LinkedHashMap<>(); + } + VirtualFile vf = files.get(virtualFile.getName()); + if(vf != null) + { + if(vf instanceof ProxyFile) + { + ((ProxyFile)vf).add(virtualFile); + } + else + { + ProxyFile pf = new ProxyFile(); + pf.add(vf); + pf.add(virtualFile); + } + } + else + { + files.put(virtualFile.getName(), virtualFile); + } + return virtualFile; + } + + void removeFile(VirtualFile virtualFile) + { + if(files == null) + { + files = new LinkedHashMap<>(); + } + files.remove(virtualFile.getName()); + } + + @Override + public void travel(VirtualFileVisitor visitor) + { + travel(this, visitor); + } + + @Override + public void travel(VirtualFolderVisitor visitor) + { + travel(this, visitor); + } +} diff --git a/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/PhysicalFile.java b/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/PhysicalFile.java index cfc5b341c..6fd01a459 100644 --- a/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/PhysicalFile.java +++ b/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/PhysicalFile.java @@ -1,40 +1,40 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.vfs.impl; - -import java.io.IOException; -import java.io.InputStream; -import org.bridje.vfs.Path; -import org.bridje.vfs.VfsSource; -import org.bridje.vfs.VirtualFile; - -class PhysicalFile extends PhysicalResource implements VirtualFile -{ - private final Object data; - - public PhysicalFile(Object data, VfsSource source, Path mountPath, Path path) - { - super(source, mountPath, path); - this.data = data; - } - - @Override - public InputStream open() throws IOException - { - return getSource().open(data); - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.vfs.impl; + +import java.io.IOException; +import java.io.InputStream; +import org.bridje.vfs.Path; +import org.bridje.vfs.VfsSource; +import org.bridje.vfs.VirtualFile; + +class PhysicalFile extends PhysicalResource implements VirtualFile +{ + private final Object data; + + public PhysicalFile(Object data, VfsSource source, Path mountPath, Path path) + { + super(source, mountPath, path); + this.data = data; + } + + @Override + public InputStream open() throws IOException + { + return getSource().open(data); + } +} diff --git a/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/PhysicalFolder.java b/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/PhysicalFolder.java index 03cce3756..c3f5f90d7 100644 --- a/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/PhysicalFolder.java +++ b/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/PhysicalFolder.java @@ -1,189 +1,189 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.vfs.impl; - -import java.io.IOException; -import java.util.LinkedList; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.bridje.vfs.Path; -import org.bridje.vfs.VfsSource; -import org.bridje.vfs.VirtualFile; -import org.bridje.vfs.VirtualFileVisitor; -import org.bridje.vfs.VirtualFolder; -import org.bridje.vfs.VirtualFolderVisitor; - -class PhysicalFolder extends PhysicalResource implements VirtualFolder -{ - private static final Logger LOG = Logger.getLogger(PhysicalFolder.class.getName()); - - public PhysicalFolder(VfsSource source, Path mountPath, Path path) - { - super(source, mountPath, path); - } - - @Override - public VirtualFolder findFolder(String path) - { - return findFolder(new Path(path)); - } - - @Override - public VirtualFolder findFolder(Path path) - { - try - { - if(getSource().folderExists(getPhysicalPath(path))) - { - return createChildFolder(path); - } - } - catch (IOException e) - { - LOG.log(Level.SEVERE, e.getMessage(), e); - } - return null; - } - - @Override - public VirtualFile findFile(String path) - { - return findFile(new Path(path)); - } - - @Override - public VirtualFile findFile(Path path) - { - try - { - if(getSource().fileExists(getPhysicalPath(path))) - { - return createChildFile(path); - } - } - catch (IOException e) - { - LOG.log(Level.SEVERE, e.getMessage(), e); - } - return null; - } - - @Override - public List listFolders() - { - List result = new LinkedList<>(); - try - { - if(getSource().folderExists(getPhysicalPath())) - { - List folders = getSource().listFolders(getPhysicalPath()); - if(folders != null) - { - for (String folder : folders) - { - VirtualFolder vf = createChildFolder(new Path(folder)); - if(vf != null) - { - result.add(vf); - } - } - } - } - } - catch (Exception e) - { - LOG.log(Level.SEVERE, e.getMessage(), e); - } - return result; - } - - @Override - public List listFiles() - { - List result = new LinkedList<>(); - try - { - List files = getSource().listFiles(getPhysicalPath()); - if(files != null) - { - for (String file : files) - { - VirtualFile vf = createChildFile(new Path(file)); - if(vf != null) - { - result.add(vf); - } - } - } - } - catch (Exception e) - { - LOG.log(Level.SEVERE, e.getMessage(), e); - } - return result; - } - - private VirtualFolder createChildFolder(Path path) - { - return new PhysicalFolder(getSource(), getMountPath(), getRelativePath().join(path)); - } - - private VirtualFile createChildFile(Path path) - { - try - { - Object[] files = getSource().getFiles(getPhysicalPath(path)); - if(files != null) - { - if(files.length > 0) - { - if(files.length == 1) - { - return new PhysicalFile(files[0], getSource(), getMountPath(), getRelativePath().join(path)); - } - if(files.length > 1) - { - ProxyFile pf = new ProxyFile(); - for (Object file : files) - { - pf.add(new PhysicalFile(file, getSource(), getMountPath(), getRelativePath().join(path))); - } - return pf; - } - } - } - } - catch (Exception e) - { - LOG.log(Level.SEVERE, e.getMessage(), e); - } - return null; - } - - @Override - public void travel(VirtualFileVisitor visitor) - { - travel(this, visitor); - } - - @Override - public void travel(VirtualFolderVisitor visitor) - { - travel(this, visitor); - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.vfs.impl; + +import java.io.IOException; +import java.util.LinkedList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.bridje.vfs.Path; +import org.bridje.vfs.VfsSource; +import org.bridje.vfs.VirtualFile; +import org.bridje.vfs.VirtualFileVisitor; +import org.bridje.vfs.VirtualFolder; +import org.bridje.vfs.VirtualFolderVisitor; + +class PhysicalFolder extends PhysicalResource implements VirtualFolder +{ + private static final Logger LOG = Logger.getLogger(PhysicalFolder.class.getName()); + + public PhysicalFolder(VfsSource source, Path mountPath, Path path) + { + super(source, mountPath, path); + } + + @Override + public VirtualFolder findFolder(String path) + { + return findFolder(new Path(path)); + } + + @Override + public VirtualFolder findFolder(Path path) + { + try + { + if(getSource().folderExists(getPhysicalPath(path))) + { + return createChildFolder(path); + } + } + catch (IOException e) + { + LOG.log(Level.SEVERE, e.getMessage(), e); + } + return null; + } + + @Override + public VirtualFile findFile(String path) + { + return findFile(new Path(path)); + } + + @Override + public VirtualFile findFile(Path path) + { + try + { + if(getSource().fileExists(getPhysicalPath(path))) + { + return createChildFile(path); + } + } + catch (IOException e) + { + LOG.log(Level.SEVERE, e.getMessage(), e); + } + return null; + } + + @Override + public List listFolders() + { + List result = new LinkedList<>(); + try + { + if(getSource().folderExists(getPhysicalPath())) + { + List folders = getSource().listFolders(getPhysicalPath()); + if(folders != null) + { + for (String folder : folders) + { + VirtualFolder vf = createChildFolder(new Path(folder)); + if(vf != null) + { + result.add(vf); + } + } + } + } + } + catch (Exception e) + { + LOG.log(Level.SEVERE, e.getMessage(), e); + } + return result; + } + + @Override + public List listFiles() + { + List result = new LinkedList<>(); + try + { + List files = getSource().listFiles(getPhysicalPath()); + if(files != null) + { + for (String file : files) + { + VirtualFile vf = createChildFile(new Path(file)); + if(vf != null) + { + result.add(vf); + } + } + } + } + catch (Exception e) + { + LOG.log(Level.SEVERE, e.getMessage(), e); + } + return result; + } + + private VirtualFolder createChildFolder(Path path) + { + return new PhysicalFolder(getSource(), getMountPath(), getRelativePath().join(path)); + } + + private VirtualFile createChildFile(Path path) + { + try + { + Object[] files = getSource().getFiles(getPhysicalPath(path)); + if(files != null) + { + if(files.length > 0) + { + if(files.length == 1) + { + return new PhysicalFile(files[0], getSource(), getMountPath(), getRelativePath().join(path)); + } + if(files.length > 1) + { + ProxyFile pf = new ProxyFile(); + for (Object file : files) + { + pf.add(new PhysicalFile(file, getSource(), getMountPath(), getRelativePath().join(path))); + } + return pf; + } + } + } + } + catch (Exception e) + { + LOG.log(Level.SEVERE, e.getMessage(), e); + } + return null; + } + + @Override + public void travel(VirtualFileVisitor visitor) + { + travel(this, visitor); + } + + @Override + public void travel(VirtualFolderVisitor visitor) + { + travel(this, visitor); + } +} diff --git a/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/PhysicalResource.java b/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/PhysicalResource.java index 4fc210caa..e632523df 100644 --- a/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/PhysicalResource.java +++ b/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/PhysicalResource.java @@ -1,79 +1,79 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.vfs.impl; - -import org.bridje.vfs.Path; -import org.bridje.vfs.VfsSource; -import org.bridje.vfs.VirtualResource; - -class PhysicalResource extends AbstractResource implements VirtualResource -{ - private final VfsSource source; - - private final Path mountPath; - - public PhysicalResource(VfsSource source, Path mountPath, Path path) - { - super(path); - this.source = source; - this.mountPath = mountPath; - } - - public VfsSource getSource() - { - return source; - } - - @Override - public Path getPath() - { - Path p = super.getPath(); - if(p != null) - { - if(mountPath != null) - { - return mountPath.join(super.getPath()); - } - return p; - } - return mountPath; - } - - public Path getRelativePath() - { - return super.getPath(); - } - - public Path getPhysicalPath() - { - return getRelativePath().getNext(); - } - - public Path getPhysicalPath(Path path) - { - if(getRelativePath().isLast()) - { - return path; - } - return getPhysicalPath().join(path); - } - - public Path getMountPath() - { - return mountPath; - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.vfs.impl; + +import org.bridje.vfs.Path; +import org.bridje.vfs.VfsSource; +import org.bridje.vfs.VirtualResource; + +class PhysicalResource extends AbstractResource implements VirtualResource +{ + private final VfsSource source; + + private final Path mountPath; + + public PhysicalResource(VfsSource source, Path mountPath, Path path) + { + super(path); + this.source = source; + this.mountPath = mountPath; + } + + public VfsSource getSource() + { + return source; + } + + @Override + public Path getPath() + { + Path p = super.getPath(); + if(p != null) + { + if(mountPath != null) + { + return mountPath.join(super.getPath()); + } + return p; + } + return mountPath; + } + + public Path getRelativePath() + { + return super.getPath(); + } + + public Path getPhysicalPath() + { + return getRelativePath().getNext(); + } + + public Path getPhysicalPath(Path path) + { + if(getRelativePath().isLast()) + { + return path; + } + return getPhysicalPath().join(path); + } + + public Path getMountPath() + { + return mountPath; + } +} diff --git a/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/ProxyFile.java b/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/ProxyFile.java index fd1d25517..126baf4c7 100644 --- a/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/ProxyFile.java +++ b/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/ProxyFile.java @@ -1,87 +1,87 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.vfs.impl; - -import java.io.IOException; -import java.io.InputStream; -import java.util.LinkedList; -import java.util.List; -import org.bridje.vfs.MultiVirtualFile; -import org.bridje.vfs.Path; -import org.bridje.vfs.VirtualFile; -import org.bridje.vfs.VirtualFolder; - -public class ProxyFile implements MultiVirtualFile -{ - private final List files; - - public ProxyFile() - { - this.files = new LinkedList<>(); - } - - public ProxyFile(List files) - { - this.files = files; - } - - @Override - public List getFiles() - { - return files; - } - - @Override - public InputStream open() throws IOException - { - return getDefFile().open(); - } - - @Override - public VirtualFolder getParent() - { - return getDefFile().getParent(); - } - - @Override - public String getName() - { - return getDefFile().getName(); - } - - @Override - public Path getPath() - { - return getDefFile().getPath(); - } - - @Override - public Path getParentPath() - { - return getDefFile().getParentPath(); - } - - public void add(VirtualFile vf) - { - files.add(vf); - } - - private VirtualFile getDefFile() - { - return files.get(files.size()-1); - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.vfs.impl; + +import java.io.IOException; +import java.io.InputStream; +import java.util.LinkedList; +import java.util.List; +import org.bridje.vfs.MultiVirtualFile; +import org.bridje.vfs.Path; +import org.bridje.vfs.VirtualFile; +import org.bridje.vfs.VirtualFolder; + +public class ProxyFile implements MultiVirtualFile +{ + private final List files; + + public ProxyFile() + { + this.files = new LinkedList<>(); + } + + public ProxyFile(List files) + { + this.files = files; + } + + @Override + public List getFiles() + { + return files; + } + + @Override + public InputStream open() throws IOException + { + return getDefFile().open(); + } + + @Override + public VirtualFolder getParent() + { + return getDefFile().getParent(); + } + + @Override + public String getName() + { + return getDefFile().getName(); + } + + @Override + public Path getPath() + { + return getDefFile().getPath(); + } + + @Override + public Path getParentPath() + { + return getDefFile().getParentPath(); + } + + public void add(VirtualFile vf) + { + files.add(vf); + } + + private VirtualFile getDefFile() + { + return files.get(files.size()-1); + } +} diff --git a/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/ProxyFolder.java b/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/ProxyFolder.java index 2109eead7..5aea3cd08 100644 --- a/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/ProxyFolder.java +++ b/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/ProxyFolder.java @@ -1,247 +1,247 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.vfs.impl; - -import java.util.LinkedHashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import org.bridje.vfs.Path; -import org.bridje.vfs.VirtualFile; -import org.bridje.vfs.VirtualFileVisitor; -import org.bridje.vfs.VirtualFolder; -import org.bridje.vfs.VirtualFolderVisitor; - -class ProxyFolder implements VirtualFolder -{ - private final List folders; - - public ProxyFolder() - { - folders = new LinkedList<>(); - } - - public ProxyFolder(List folders) - { - this.folders = folders; - } - - @Override - public VirtualFolder findFolder(String path) - { - return findFolder(new Path(path)); - } - - @Override - public VirtualFolder findFolder(Path path) - { - List result = new LinkedList<>(); - if(folders != null) - { - for (VirtualFolder folder : folders) - { - VirtualFolder ff = folder.findFolder(path); - if(ff != null) - { - result.add(ff); - } - } - } - if(result.isEmpty()) - { - return null; - } - if(result.size() == 1) - { - return result.get(0); - } - return new ProxyFolder(result); - } - - @Override - public VirtualFile findFile(String path) - { - return findFile(new Path(path)); - } - - @Override - public VirtualFile findFile(Path path) - { - List result = new LinkedList<>(); - if(folders != null) - { - for (VirtualFolder folder : folders) - { - VirtualFile ff = folder.findFile(path); - if(ff != null) - { - result.add(ff); - } - } - } - if(result.isEmpty()) - { - return null; - } - if(result.size() == 1) - { - return result.get(0); - } - return new ProxyFile(result); - } - - @Override - public List listFolders() - { - if(folders != null) - { - List result = new LinkedList<>(); - Map> foldersMap = new LinkedHashMap<>(); - folders.stream().forEach((folder) -> - { - folder.listFolders().stream().forEach((chFolder) -> - { - List lst = foldersMap.get(chFolder.getName()); - if(lst == null) - { - lst = new LinkedList<>(); - } - lst.add(chFolder); - foldersMap.put(chFolder.getName(), lst); - }); - }); - - for (Map.Entry> entry : foldersMap.entrySet()) - { - List value = entry.getValue(); - if(value == null || value.isEmpty()) - { - continue; - } - if(value.size() == 1) - { - result.add(value.get(0)); - } - if(value.size() > 1) - { - result.add(new ProxyFolder(value)); - } - } - return result; - } - return null; - } - - @Override - public List listFiles() - { - if(folders != null) - { - List result = new LinkedList<>(); - Map> filesMap = new LinkedHashMap<>(); - folders.stream().forEach((folder) -> - { - folder.listFiles().stream().forEach((chFile) -> - { - List lst = filesMap.get(chFile.getName()); - if(lst == null) - { - lst = new LinkedList<>(); - } - lst.add(chFile); - filesMap.put(chFile.getName(), lst); - }); - }); - - for (Map.Entry> entry : filesMap.entrySet()) - { - List value = entry.getValue(); - if(value == null || value.isEmpty()) - { - continue; - } - if(value.size() == 1) - { - result.add(value.get(0)); - } - if(value.size() > 1) - { - result.add(new ProxyFile(value)); - } - } - return result; - } - return null; - } - - @Override - public VirtualFolder getParent() - { - if(folders == null || folders.isEmpty()) - { - return null; - } - return folders.get(0).getParent(); - } - - @Override - public String getName() - { - if(folders == null || folders.isEmpty()) - { - return null; - } - return folders.get(0).getName(); - } - - @Override - public Path getPath() - { - if(folders == null || folders.isEmpty()) - { - return null; - } - return folders.get(0).getPath(); - } - - @Override - public Path getParentPath() - { - if(folders == null || folders.isEmpty()) - { - return null; - } - return folders.get(0).getParentPath(); - } - - public void add(VirtualFolder vf) - { - folders.add(vf); - } - - @Override - public void travel(VirtualFileVisitor visitor) - { - AbstractResource.travel(this, visitor); - } - - @Override - public void travel(VirtualFolderVisitor visitor) - { - AbstractResource.travel(this, visitor); - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.vfs.impl; + +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import org.bridje.vfs.Path; +import org.bridje.vfs.VirtualFile; +import org.bridje.vfs.VirtualFileVisitor; +import org.bridje.vfs.VirtualFolder; +import org.bridje.vfs.VirtualFolderVisitor; + +class ProxyFolder implements VirtualFolder +{ + private final List folders; + + public ProxyFolder() + { + folders = new LinkedList<>(); + } + + public ProxyFolder(List folders) + { + this.folders = folders; + } + + @Override + public VirtualFolder findFolder(String path) + { + return findFolder(new Path(path)); + } + + @Override + public VirtualFolder findFolder(Path path) + { + List result = new LinkedList<>(); + if(folders != null) + { + for (VirtualFolder folder : folders) + { + VirtualFolder ff = folder.findFolder(path); + if(ff != null) + { + result.add(ff); + } + } + } + if(result.isEmpty()) + { + return null; + } + if(result.size() == 1) + { + return result.get(0); + } + return new ProxyFolder(result); + } + + @Override + public VirtualFile findFile(String path) + { + return findFile(new Path(path)); + } + + @Override + public VirtualFile findFile(Path path) + { + List result = new LinkedList<>(); + if(folders != null) + { + for (VirtualFolder folder : folders) + { + VirtualFile ff = folder.findFile(path); + if(ff != null) + { + result.add(ff); + } + } + } + if(result.isEmpty()) + { + return null; + } + if(result.size() == 1) + { + return result.get(0); + } + return new ProxyFile(result); + } + + @Override + public List listFolders() + { + if(folders != null) + { + List result = new LinkedList<>(); + Map> foldersMap = new LinkedHashMap<>(); + folders.stream().forEach((folder) -> + { + folder.listFolders().stream().forEach((chFolder) -> + { + List lst = foldersMap.get(chFolder.getName()); + if(lst == null) + { + lst = new LinkedList<>(); + } + lst.add(chFolder); + foldersMap.put(chFolder.getName(), lst); + }); + }); + + for (Map.Entry> entry : foldersMap.entrySet()) + { + List value = entry.getValue(); + if(value == null || value.isEmpty()) + { + continue; + } + if(value.size() == 1) + { + result.add(value.get(0)); + } + if(value.size() > 1) + { + result.add(new ProxyFolder(value)); + } + } + return result; + } + return null; + } + + @Override + public List listFiles() + { + if(folders != null) + { + List result = new LinkedList<>(); + Map> filesMap = new LinkedHashMap<>(); + folders.stream().forEach((folder) -> + { + folder.listFiles().stream().forEach((chFile) -> + { + List lst = filesMap.get(chFile.getName()); + if(lst == null) + { + lst = new LinkedList<>(); + } + lst.add(chFile); + filesMap.put(chFile.getName(), lst); + }); + }); + + for (Map.Entry> entry : filesMap.entrySet()) + { + List value = entry.getValue(); + if(value == null || value.isEmpty()) + { + continue; + } + if(value.size() == 1) + { + result.add(value.get(0)); + } + if(value.size() > 1) + { + result.add(new ProxyFile(value)); + } + } + return result; + } + return null; + } + + @Override + public VirtualFolder getParent() + { + if(folders == null || folders.isEmpty()) + { + return null; + } + return folders.get(0).getParent(); + } + + @Override + public String getName() + { + if(folders == null || folders.isEmpty()) + { + return null; + } + return folders.get(0).getName(); + } + + @Override + public Path getPath() + { + if(folders == null || folders.isEmpty()) + { + return null; + } + return folders.get(0).getPath(); + } + + @Override + public Path getParentPath() + { + if(folders == null || folders.isEmpty()) + { + return null; + } + return folders.get(0).getParentPath(); + } + + public void add(VirtualFolder vf) + { + folders.add(vf); + } + + @Override + public void travel(VirtualFileVisitor visitor) + { + AbstractResource.travel(this, visitor); + } + + @Override + public void travel(VirtualFolderVisitor visitor) + { + AbstractResource.travel(this, visitor); + } +} diff --git a/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/VfsServiceImpl.java b/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/VfsServiceImpl.java index 09fe08f96..6a9662f68 100644 --- a/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/VfsServiceImpl.java +++ b/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/VfsServiceImpl.java @@ -1,176 +1,176 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.vfs.impl; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.logging.Logger; -import org.bridje.ioc.Component; -import org.bridje.ioc.Inject; -import org.bridje.vfs.Path; -import org.bridje.vfs.VfsMountConfig; -import org.bridje.vfs.VfsMountEntry; -import org.bridje.vfs.VfsProvider; -import org.bridje.vfs.VfsService; -import org.bridje.vfs.VfsSource; -import org.bridje.vfs.VirtualFile; -import org.bridje.vfs.VirtualFileVisitor; -import org.bridje.vfs.VirtualFolder; -import org.bridje.vfs.VirtualFolderVisitor; - -@Component -class VfsServiceImpl implements VfsService -{ - private static final Logger LOG = Logger.getLogger(VfsServiceImpl.class.getName()); - - private MemoryFolder root; - - private Map providersMap; - - @Inject - private VfsProvider[] providers; - - @Inject - private VfsMountConfig[] mountConfig; - - @Override - public VirtualFolder findFolder(String path) - { - load(); - return root.findFolder(path); - } - - @Override - public VirtualFolder findFolder(Path path) - { - load(); - return root.findFolder(path); - } - - @Override - public VirtualFile findFile(String path) - { - load(); - return root.findFile(path); - } - - @Override - public VirtualFile findFile(Path path) - { - load(); - return root.findFile(path); - } - - @Override - public List listFolders() - { - load(); - return root.listFolders(); - } - - @Override - public List listFiles() - { - load(); - return root.listFiles(); - } - - @Override - public void mount(Path path, VfsSource source) - { - Path canPath = path.getCanonicalPath(); - if(canPath == null) - { - throw new IllegalArgumentException("The specified path " + path + " is not valid ."); - } - Path mountPath = canPath.getParent(); - String mountName = canPath.getName(); - MemoryFolder currentFolder = root; - if(mountPath != null) - { - for (Path currentPath : mountPath) - { - VirtualFolder currVFolder = root.findFolder(currentPath); - if(currVFolder != null && (currVFolder instanceof MemoryFolder)) - { - currentFolder = (MemoryFolder)currVFolder; - } - else - { - currentFolder = currentFolder.addFolder(new MemoryFolder(currentPath)); - } - } - } - - currentFolder.addFolder(new PhysicalFolder(source, mountPath, new Path(mountName))); - } - - @Override - public void travel(VirtualFileVisitor visitor) - { - root.travel(visitor); - } - - @Override - public void travel(VirtualFolderVisitor visitor) - { - root.travel(visitor); - } - - private void load() - { - if(root == null) - { - root = new MemoryFolder(null); - loadProviders(); - loadConfig(); - } - } - - private void loadProviders() - { - providersMap = new HashMap<>(); - for (VfsProvider provider : providers) - { - providersMap.put(provider.getName(), provider); - } - } - - private void loadConfig() - { - if(mountConfig != null) - { - for (VfsMountConfig cfg : mountConfig) - { - List entires = cfg.getEntries(); - if(entires != null) - { - for (VfsMountEntry entry : entires) - { - String fileSystem = entry.getFileSystem(); - VfsProvider fsProv = providersMap.get(fileSystem); - if(fsProv != null) - { - mount(new Path(entry.getMountPath()), fsProv.createVfsSource(entry)); - } - } - } - } - } - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.vfs.impl; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.logging.Logger; +import org.bridje.ioc.Component; +import org.bridje.ioc.Inject; +import org.bridje.vfs.Path; +import org.bridje.vfs.VfsMountConfig; +import org.bridje.vfs.VfsMountEntry; +import org.bridje.vfs.VfsProvider; +import org.bridje.vfs.VfsService; +import org.bridje.vfs.VfsSource; +import org.bridje.vfs.VirtualFile; +import org.bridje.vfs.VirtualFileVisitor; +import org.bridje.vfs.VirtualFolder; +import org.bridje.vfs.VirtualFolderVisitor; + +@Component +class VfsServiceImpl implements VfsService +{ + private static final Logger LOG = Logger.getLogger(VfsServiceImpl.class.getName()); + + private MemoryFolder root; + + private Map providersMap; + + @Inject + private VfsProvider[] providers; + + @Inject + private VfsMountConfig[] mountConfig; + + @Override + public VirtualFolder findFolder(String path) + { + load(); + return root.findFolder(path); + } + + @Override + public VirtualFolder findFolder(Path path) + { + load(); + return root.findFolder(path); + } + + @Override + public VirtualFile findFile(String path) + { + load(); + return root.findFile(path); + } + + @Override + public VirtualFile findFile(Path path) + { + load(); + return root.findFile(path); + } + + @Override + public List listFolders() + { + load(); + return root.listFolders(); + } + + @Override + public List listFiles() + { + load(); + return root.listFiles(); + } + + @Override + public void mount(Path path, VfsSource source) + { + Path canPath = path.getCanonicalPath(); + if(canPath == null) + { + throw new IllegalArgumentException("The specified path " + path + " is not valid ."); + } + Path mountPath = canPath.getParent(); + String mountName = canPath.getName(); + MemoryFolder currentFolder = root; + if(mountPath != null) + { + for (Path currentPath : mountPath) + { + VirtualFolder currVFolder = root.findFolder(currentPath); + if(currVFolder != null && (currVFolder instanceof MemoryFolder)) + { + currentFolder = (MemoryFolder)currVFolder; + } + else + { + currentFolder = currentFolder.addFolder(new MemoryFolder(currentPath)); + } + } + } + + currentFolder.addFolder(new PhysicalFolder(source, mountPath, new Path(mountName))); + } + + @Override + public void travel(VirtualFileVisitor visitor) + { + root.travel(visitor); + } + + @Override + public void travel(VirtualFolderVisitor visitor) + { + root.travel(visitor); + } + + private void load() + { + if(root == null) + { + root = new MemoryFolder(null); + loadProviders(); + loadConfig(); + } + } + + private void loadProviders() + { + providersMap = new HashMap<>(); + for (VfsProvider provider : providers) + { + providersMap.put(provider.getName(), provider); + } + } + + private void loadConfig() + { + if(mountConfig != null) + { + for (VfsMountConfig cfg : mountConfig) + { + List entires = cfg.getEntries(); + if(entires != null) + { + for (VfsMountEntry entry : entires) + { + String fileSystem = entry.getFileSystem(); + VfsProvider fsProv = providersMap.get(fileSystem); + if(fsProv != null) + { + mount(new Path(entry.getMountPath()), fsProv.createVfsSource(entry)); + } + } + } + } + } + } +} diff --git a/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/cfg/ClassPathConfig.java b/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/cfg/ClassPathConfig.java index bdbcaf01b..cd9dcec8e 100644 --- a/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/cfg/ClassPathConfig.java +++ b/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/cfg/ClassPathConfig.java @@ -1,56 +1,56 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.vfs.impl.cfg; - -import java.util.HashMap; -import java.util.Map; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; - -@XmlAccessorType(XmlAccessType.FIELD) -public class ClassPathConfig extends MountEntryFactory -{ - @XmlAttribute - private String path; - - public String getPath() - { - return path; - } - - public void setPath(String path) - { - this.path = path; - } - - @Override - public String getFileSystem() - { - return "CLASSPATH"; - } - - @Override - public Map getProperties() - { - Map result = new HashMap<>(); - result.put("classpath", path); - return result; - } - - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.vfs.impl.cfg; + +import java.util.HashMap; +import java.util.Map; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; + +@XmlAccessorType(XmlAccessType.FIELD) +public class ClassPathConfig extends MountEntryFactory +{ + @XmlAttribute + private String path; + + public String getPath() + { + return path; + } + + public void setPath(String path) + { + this.path = path; + } + + @Override + public String getFileSystem() + { + return "CLASSPATH"; + } + + @Override + public Map getProperties() + { + Map result = new HashMap<>(); + result.put("classpath", path); + return result; + } + + +} diff --git a/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/cfg/FileConfig.java b/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/cfg/FileConfig.java index 5896d1af5..90f832f9e 100644 --- a/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/cfg/FileConfig.java +++ b/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/cfg/FileConfig.java @@ -1,56 +1,56 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.vfs.impl.cfg; - -import java.util.HashMap; -import java.util.Map; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; - -@XmlAccessorType(XmlAccessType.FIELD) -public class FileConfig extends MountEntryFactory -{ - @XmlAttribute - private String file; - - public String getFile() - { - return file; - } - - public void setFile(String file) - { - this.file = file; - } - - @Override - public String getFileSystem() - { - return "SYSTEMFS"; - } - - @Override - public Map getProperties() - { - Map result = new HashMap<>(); - result.put("file", file); - return result; - } - - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.vfs.impl.cfg; + +import java.util.HashMap; +import java.util.Map; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; + +@XmlAccessorType(XmlAccessType.FIELD) +public class FileConfig extends MountEntryFactory +{ + @XmlAttribute + private String file; + + public String getFile() + { + return file; + } + + public void setFile(String file) + { + this.file = file; + } + + @Override + public String getFileSystem() + { + return "SYSTEMFS"; + } + + @Override + public Map getProperties() + { + Map result = new HashMap<>(); + result.put("file", file); + return result; + } + + +} diff --git a/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/cfg/MountEntryFactory.java b/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/cfg/MountEntryFactory.java index bafc026be..0dd4961eb 100644 --- a/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/cfg/MountEntryFactory.java +++ b/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/cfg/MountEntryFactory.java @@ -1,49 +1,49 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.vfs.impl.cfg; - -import java.util.Map; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import org.bridje.vfs.VfsMountEntry; - -@XmlAccessorType(XmlAccessType.FIELD) -public abstract class MountEntryFactory -{ - @XmlAttribute - private String on; - - public String getOn() - { - return on; - } - - public void setOn(String on) - { - this.on = on; - } - - public VfsMountEntry createMountEntry() - { - return new VfsMountEntry(on, getFileSystem(), getProperties()); - } - - public abstract String getFileSystem(); - - public abstract Map getProperties(); -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.vfs.impl.cfg; + +import java.util.Map; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import org.bridje.vfs.VfsMountEntry; + +@XmlAccessorType(XmlAccessType.FIELD) +public abstract class MountEntryFactory +{ + @XmlAttribute + private String on; + + public String getOn() + { + return on; + } + + public void setOn(String on) + { + this.on = on; + } + + public VfsMountEntry createMountEntry() + { + return new VfsMountEntry(on, getFileSystem(), getProperties()); + } + + public abstract String getFileSystem(); + + public abstract Map getProperties(); +} diff --git a/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/cfg/VfsConfig.java b/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/cfg/VfsConfig.java index fa439741d..d4bdca655 100644 --- a/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/cfg/VfsConfig.java +++ b/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/cfg/VfsConfig.java @@ -1,58 +1,58 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.vfs.impl.cfg; - -import java.util.LinkedList; -import java.util.List; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlElements; -import javax.xml.bind.annotation.XmlRootElement; -import org.bridje.vfs.VfsMountEntry; - -@XmlRootElement(name = "vfs") -@XmlAccessorType(XmlAccessType.FIELD) -public class VfsConfig -{ - @XmlElements( - { - @XmlElement(name = "file", type = FileConfig.class), - @XmlElement(name = "classpath", type = ClassPathConfig.class) - }) - private List entries; - - public List getEntries() - { - return entries; - } - - public void setEntries(List entries) - { - this.entries = entries; - } - - public List createEntries() - { - List result = new LinkedList<>(); - for (MountEntryFactory entry : entries) - { - result.add(entry.createMountEntry()); - } - return result; - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.vfs.impl.cfg; + +import java.util.LinkedList; +import java.util.List; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElements; +import javax.xml.bind.annotation.XmlRootElement; +import org.bridje.vfs.VfsMountEntry; + +@XmlRootElement(name = "vfs") +@XmlAccessorType(XmlAccessType.FIELD) +public class VfsConfig +{ + @XmlElements( + { + @XmlElement(name = "file", type = FileConfig.class), + @XmlElement(name = "classpath", type = ClassPathConfig.class) + }) + private List entries; + + public List getEntries() + { + return entries; + } + + public void setEntries(List entries) + { + this.entries = entries; + } + + public List createEntries() + { + List result = new LinkedList<>(); + for (MountEntryFactory entry : entries) + { + result.add(entry.createMountEntry()); + } + return result; + } +} diff --git a/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/src/ClassPathProvider.java b/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/src/ClassPathProvider.java index f69ac1c20..689681f2b 100644 --- a/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/src/ClassPathProvider.java +++ b/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/src/ClassPathProvider.java @@ -1,54 +1,54 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.vfs.impl.src; - -import java.io.File; -import java.io.IOException; -import java.net.URISyntaxException; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.bridje.ioc.Component; -import org.bridje.vfs.VfsMountEntry; -import org.bridje.vfs.VfsProvider; -import org.bridje.vfs.VfsSource; - -@Component -public class ClassPathProvider implements VfsProvider -{ - private static final Logger LOG = Logger.getLogger(ClassPathProvider.class.getName()); - - @Override - public String getName() - { - return "CLASSPATH"; - } - - @Override - public VfsSource createVfsSource(VfsMountEntry entry) - { - try - { - return new ClassPathVfsSource(entry.getProperties().get("classpath")); - } - catch (IOException | URISyntaxException ex) - { - LOG.log(Level.SEVERE, ex.getMessage(), ex); - } - return null; - } - -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.vfs.impl.src; + +import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.bridje.ioc.Component; +import org.bridje.vfs.VfsMountEntry; +import org.bridje.vfs.VfsProvider; +import org.bridje.vfs.VfsSource; + +@Component +public class ClassPathProvider implements VfsProvider +{ + private static final Logger LOG = Logger.getLogger(ClassPathProvider.class.getName()); + + @Override + public String getName() + { + return "CLASSPATH"; + } + + @Override + public VfsSource createVfsSource(VfsMountEntry entry) + { + try + { + return new ClassPathVfsSource(entry.getProperties().get("classpath")); + } + catch (IOException | URISyntaxException ex) + { + LOG.log(Level.SEVERE, ex.getMessage(), ex); + } + return null; + } + +} diff --git a/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/src/ClassPathVfsSource.java b/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/src/ClassPathVfsSource.java index 2432de6d9..b07f6e32c 100644 --- a/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/src/ClassPathVfsSource.java +++ b/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/src/ClassPathVfsSource.java @@ -1,254 +1,254 @@ - -package org.bridje.vfs.impl.src; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.net.URISyntaxException; -import java.net.URL; -import java.net.URLDecoder; -import java.util.Arrays; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.jar.JarEntry; -import java.util.jar.JarFile; -import org.bridje.vfs.Path; -import org.bridje.vfs.VfsSource; - -/** - * - */ -public class ClassPathVfsSource implements VfsSource -{ - private final String resource; - - private Map childs; - - public ClassPathVfsSource(String resource) throws IOException, URISyntaxException - { - this.resource = new Path(resource).toString(); - List resourceListing = getResourceListing(getClass(), resource); - if(resourceListing != null && !resourceListing.isEmpty()) - { - this.childs = new HashMap<>(); - for (String childName : resourceListing) - { - this.childs.put(childName, new ClassPathVfsSource(resource + "/" + childName)); - } - } - } - - @Override - public URL[] getFiles(Path path) throws IOException - { - List urls = new LinkedList<>(); - Enumeration resources; - if(path == null) - { - resources = getClass().getClassLoader().getResources(resource); - } - else - { - resources = getClass().getClassLoader().getResources(resource + "/" + path); - } - if(resources != null) - { - while (resources.hasMoreElements()) - { - URL nextElement = resources.nextElement(); - urls.add(nextElement); - } - } - URL[] result = new URL[urls.size()]; - return urls.toArray(result); - } - - @Override - public List listFolders(Path path) throws IOException - { - if(childs == null) - { - return null; - } - if(path == null) - { - List result = new LinkedList<>(); - for (Map.Entry entry : childs.entrySet()) - { - String key = entry.getKey(); - ClassPathVfsSource value = entry.getValue(); - if (value.isFolder()) - { - result.add(key); - } - } - return result; - } - else - { - ClassPathVfsSource src = childs.get(path.getFirstElement()); - if(src != null) - { - return src.listFolders(path.getNext()); - } - } - return null; - } - - @Override - public List listFiles(Path path) throws IOException - { - if(childs == null) - { - return null; - } - if(path == null) - { - List result = new LinkedList<>(); - childs.entrySet().stream().forEach((entry) -> - { - String key = entry.getKey(); - ClassPathVfsSource value = entry.getValue(); - if (!value.isFolder()) - { - result.add(key); - } - }); - return result; - } - else - { - ClassPathVfsSource src = childs.get(path.getFirstElement()); - if(src != null) - { - return src.listFiles(path.getNext()); - } - } - return null; - } - - @Override - public boolean fileExists(Path path) throws IOException - { - if(path == null) - { - return !isFolder(); - } - if(childs == null) - { - return false; - } - ClassPathVfsSource src = childs.get(path.getFirstElement()); - if(src != null) - { - return src.fileExists(path.getNext()); - } - return false; - } - - @Override - public boolean folderExists(Path path) throws IOException - { - if(path == null) - { - return isFolder(); - } - if(childs == null) - { - return false; - } - ClassPathVfsSource src = childs.get(path.getFirstElement()); - if(src != null) - { - return src.folderExists(path.getNext()); - } - return false; - } - - private List getResourceListing(Class clazz, String path) throws URISyntaxException, IOException - { - if(path.startsWith("/")) - { - path = path.substring(1); - } - Enumeration resources = clazz.getClassLoader().getResources(path); - Set result = new HashSet<>(); //avoid duplicates in case it is a subdirectory - while (resources.hasMoreElements()) - { - URL dirURL = resources.nextElement(); - if (dirURL != null && dirURL.getProtocol().equals("file")) - { - /* A file path: easy enough */ - String[] list = new File(dirURL.toURI()).list(); - if(list == null) - { - return null; - } - result.addAll(Arrays.asList(list)); - } - - if (dirURL == null) - { - /* - * In case of a jar file, we can't actually find a directory. - * Have to assume the same jar as clazz. - */ - String me = clazz.getName().replace(".", "/").concat(".class"); - dirURL = clazz.getClassLoader().getResource(me); - } - - if (dirURL.getProtocol().equals("jar")) - { - /* A JAR path */ - String jarPath = dirURL.getPath().substring(5, dirURL.getPath().indexOf("!")); //strip out only the JAR file - JarFile jar = new JarFile(URLDecoder.decode(jarPath, "UTF-8")); - Enumeration entries = jar.entries(); //gives ALL entries in jar - Set currentProjectResource = new HashSet<>(); //avoid duplicates in case it is a subdirectory - while (entries.hasMoreElements()) - { - String name = entries.nextElement().getName().trim(); - if (name.startsWith(path)) - { - //filter according to the path - String entry = name.trim().substring(path.length()); - int checkSubdir = entry.indexOf("/"); - if (checkSubdir >= 0) - { - // if it is a subdirectory, we just return the directory name - entry = entry.substring(0, checkSubdir); - } - if(!entry.isEmpty()) - { - currentProjectResource.add(entry); - } - } - } - result.addAll(currentProjectResource); - } - } - if (result.isEmpty()) - { - return null; - } - List res = new LinkedList<>(); - res.addAll(result); - return res; - } - - private boolean isFolder() - { - return childs != null; - } - - @Override - public InputStream open(Object data) throws IOException - { - URL url = (URL)data; - return url.openStream(); - } -} + +package org.bridje.vfs.impl.src; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URISyntaxException; +import java.net.URL; +import java.net.URLDecoder; +import java.util.Arrays; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; +import org.bridje.vfs.Path; +import org.bridje.vfs.VfsSource; + +/** + * + */ +public class ClassPathVfsSource implements VfsSource +{ + private final String resource; + + private Map childs; + + public ClassPathVfsSource(String resource) throws IOException, URISyntaxException + { + this.resource = new Path(resource).toString(); + List resourceListing = getResourceListing(getClass(), resource); + if(resourceListing != null && !resourceListing.isEmpty()) + { + this.childs = new HashMap<>(); + for (String childName : resourceListing) + { + this.childs.put(childName, new ClassPathVfsSource(resource + "/" + childName)); + } + } + } + + @Override + public URL[] getFiles(Path path) throws IOException + { + List urls = new LinkedList<>(); + Enumeration resources; + if(path == null) + { + resources = getClass().getClassLoader().getResources(resource); + } + else + { + resources = getClass().getClassLoader().getResources(resource + "/" + path); + } + if(resources != null) + { + while (resources.hasMoreElements()) + { + URL nextElement = resources.nextElement(); + urls.add(nextElement); + } + } + URL[] result = new URL[urls.size()]; + return urls.toArray(result); + } + + @Override + public List listFolders(Path path) throws IOException + { + if(childs == null) + { + return null; + } + if(path == null) + { + List result = new LinkedList<>(); + for (Map.Entry entry : childs.entrySet()) + { + String key = entry.getKey(); + ClassPathVfsSource value = entry.getValue(); + if (value.isFolder()) + { + result.add(key); + } + } + return result; + } + else + { + ClassPathVfsSource src = childs.get(path.getFirstElement()); + if(src != null) + { + return src.listFolders(path.getNext()); + } + } + return null; + } + + @Override + public List listFiles(Path path) throws IOException + { + if(childs == null) + { + return null; + } + if(path == null) + { + List result = new LinkedList<>(); + childs.entrySet().stream().forEach((entry) -> + { + String key = entry.getKey(); + ClassPathVfsSource value = entry.getValue(); + if (!value.isFolder()) + { + result.add(key); + } + }); + return result; + } + else + { + ClassPathVfsSource src = childs.get(path.getFirstElement()); + if(src != null) + { + return src.listFiles(path.getNext()); + } + } + return null; + } + + @Override + public boolean fileExists(Path path) throws IOException + { + if(path == null) + { + return !isFolder(); + } + if(childs == null) + { + return false; + } + ClassPathVfsSource src = childs.get(path.getFirstElement()); + if(src != null) + { + return src.fileExists(path.getNext()); + } + return false; + } + + @Override + public boolean folderExists(Path path) throws IOException + { + if(path == null) + { + return isFolder(); + } + if(childs == null) + { + return false; + } + ClassPathVfsSource src = childs.get(path.getFirstElement()); + if(src != null) + { + return src.folderExists(path.getNext()); + } + return false; + } + + private List getResourceListing(Class clazz, String path) throws URISyntaxException, IOException + { + if(path.startsWith("/")) + { + path = path.substring(1); + } + Enumeration resources = clazz.getClassLoader().getResources(path); + Set result = new HashSet<>(); //avoid duplicates in case it is a subdirectory + while (resources.hasMoreElements()) + { + URL dirURL = resources.nextElement(); + if (dirURL != null && dirURL.getProtocol().equals("file")) + { + /* A file path: easy enough */ + String[] list = new File(dirURL.toURI()).list(); + if(list == null) + { + return null; + } + result.addAll(Arrays.asList(list)); + } + + if (dirURL == null) + { + /* + * In case of a jar file, we can't actually find a directory. + * Have to assume the same jar as clazz. + */ + String me = clazz.getName().replace(".", "/").concat(".class"); + dirURL = clazz.getClassLoader().getResource(me); + } + + if (dirURL.getProtocol().equals("jar")) + { + /* A JAR path */ + String jarPath = dirURL.getPath().substring(5, dirURL.getPath().indexOf("!")); //strip out only the JAR file + JarFile jar = new JarFile(URLDecoder.decode(jarPath, "UTF-8")); + Enumeration entries = jar.entries(); //gives ALL entries in jar + Set currentProjectResource = new HashSet<>(); //avoid duplicates in case it is a subdirectory + while (entries.hasMoreElements()) + { + String name = entries.nextElement().getName().trim(); + if (name.startsWith(path)) + { + //filter according to the path + String entry = name.trim().substring(path.length()); + int checkSubdir = entry.indexOf("/"); + if (checkSubdir >= 0) + { + // if it is a subdirectory, we just return the directory name + entry = entry.substring(0, checkSubdir); + } + if(!entry.isEmpty()) + { + currentProjectResource.add(entry); + } + } + } + result.addAll(currentProjectResource); + } + } + if (result.isEmpty()) + { + return null; + } + List res = new LinkedList<>(); + res.addAll(result); + return res; + } + + private boolean isFolder() + { + return childs != null; + } + + @Override + public InputStream open(Object data) throws IOException + { + URL url = (URL)data; + return url.openStream(); + } +} diff --git a/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/src/FileVfsSource.java b/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/src/FileVfsSource.java index ca6b4d21a..dd4b92511 100644 --- a/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/src/FileVfsSource.java +++ b/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/src/FileVfsSource.java @@ -1,124 +1,124 @@ - -package org.bridje.vfs.impl.src; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.util.LinkedList; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.bridje.vfs.Path; -import org.bridje.vfs.VfsSource; - -public class FileVfsSource implements VfsSource -{ - private static final Logger LOG = Logger.getLogger(FileVfsSource.class.getName()); - - private final File file; - - public FileVfsSource(File file) - { - this.file = file; - } - - @Override - public Object[] getFiles(Path path) throws IOException - { - File f = new File(file.getCanonicalPath() + File.separator + path.toString(File.separator)); - if(f.exists() && f.isFile() && f.canRead()) - { - return new File[]{f}; - } - return null; - } - - @Override - public List listFolders(Path path) throws IOException - { - File f = findRealFile(path); - if(!f.exists()) - { - return null; - } - if(!f.isDirectory()) - { - throw new IOException("Can´t open " + f.getCanonicalPath() + ". is not a folder."); - } - List result = new LinkedList<>(); - File[] listFiles = f.listFiles(); - for (File listFile : listFiles) - { - if(listFile.isDirectory()) - { - result.add(listFile.getName()); - } - } - return result; - } - - @Override - public List listFiles(Path path) throws IOException - { - File f = findRealFile(path); - if(!f.exists()) - { - return null; - } - if(!f.isDirectory()) - { - throw new IOException("Can´t open " + f.getCanonicalPath() + ". is not a folder."); - } - List result = new LinkedList<>(); - File[] listFiles = f.listFiles(); - for (File listFile : listFiles) - { - if(listFile.isFile()) - { - result.add(listFile.getName()); - } - } - return result; - } - - @Override - public boolean fileExists(Path path) throws IOException - { - File f = findRealFile(path); - return (f.exists() && f.isFile()); - } - - @Override - public boolean folderExists(Path path) throws IOException - { - File f = findRealFile(path); - return (f.exists() && f.isDirectory()); - } - - private File findRealFile(Path path) throws IOException - { - File f = file; - if(path != null) - { - f = new File(file.getCanonicalPath() + File.separator + path.toString(File.separator)); - } - return f; - } - - @Override - public InputStream open(Object data) - { - try - { - File f = (File)data; - return new FileInputStream(f); - } - catch (FileNotFoundException ex) - { - LOG.log(Level.SEVERE, null, ex); - } - return null; - } -} + +package org.bridje.vfs.impl.src; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.util.LinkedList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.bridje.vfs.Path; +import org.bridje.vfs.VfsSource; + +public class FileVfsSource implements VfsSource +{ + private static final Logger LOG = Logger.getLogger(FileVfsSource.class.getName()); + + private final File file; + + public FileVfsSource(File file) + { + this.file = file; + } + + @Override + public Object[] getFiles(Path path) throws IOException + { + File f = new File(file.getCanonicalPath() + File.separator + path.toString(File.separator)); + if(f.exists() && f.isFile() && f.canRead()) + { + return new File[]{f}; + } + return null; + } + + @Override + public List listFolders(Path path) throws IOException + { + File f = findRealFile(path); + if(!f.exists()) + { + return null; + } + if(!f.isDirectory()) + { + throw new IOException("Can´t open " + f.getCanonicalPath() + ". is not a folder."); + } + List result = new LinkedList<>(); + File[] listFiles = f.listFiles(); + for (File listFile : listFiles) + { + if(listFile.isDirectory()) + { + result.add(listFile.getName()); + } + } + return result; + } + + @Override + public List listFiles(Path path) throws IOException + { + File f = findRealFile(path); + if(!f.exists()) + { + return null; + } + if(!f.isDirectory()) + { + throw new IOException("Can´t open " + f.getCanonicalPath() + ". is not a folder."); + } + List result = new LinkedList<>(); + File[] listFiles = f.listFiles(); + for (File listFile : listFiles) + { + if(listFile.isFile()) + { + result.add(listFile.getName()); + } + } + return result; + } + + @Override + public boolean fileExists(Path path) throws IOException + { + File f = findRealFile(path); + return (f.exists() && f.isFile()); + } + + @Override + public boolean folderExists(Path path) throws IOException + { + File f = findRealFile(path); + return (f.exists() && f.isDirectory()); + } + + private File findRealFile(Path path) throws IOException + { + File f = file; + if(path != null) + { + f = new File(file.getCanonicalPath() + File.separator + path.toString(File.separator)); + } + return f; + } + + @Override + public InputStream open(Object data) + { + try + { + File f = (File)data; + return new FileInputStream(f); + } + catch (FileNotFoundException ex) + { + LOG.log(Level.SEVERE, null, ex); + } + return null; + } +} diff --git a/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/src/SystemFsProvider.java b/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/src/SystemFsProvider.java index 2f9f25c82..f4b41f66e 100644 --- a/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/src/SystemFsProvider.java +++ b/old/bridje-vfs/src/main/java/org/bridje/vfs/impl/src/SystemFsProvider.java @@ -1,40 +1,40 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.vfs.impl.src; - -import java.io.File; -import org.bridje.ioc.Component; -import org.bridje.vfs.VfsMountEntry; -import org.bridje.vfs.VfsProvider; -import org.bridje.vfs.VfsSource; - -@Component -public class SystemFsProvider implements VfsProvider -{ - - @Override - public String getName() - { - return "SYSTEMFS"; - } - - @Override - public VfsSource createVfsSource(VfsMountEntry entry) - { - return new FileVfsSource(new File(entry.getProperties().get("file"))); - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.vfs.impl.src; + +import java.io.File; +import org.bridje.ioc.Component; +import org.bridje.vfs.VfsMountEntry; +import org.bridje.vfs.VfsProvider; +import org.bridje.vfs.VfsSource; + +@Component +public class SystemFsProvider implements VfsProvider +{ + + @Override + public String getName() + { + return "SYSTEMFS"; + } + + @Override + public VfsSource createVfsSource(VfsMountEntry entry) + { + return new FileVfsSource(new File(entry.getProperties().get("file"))); + } +} diff --git a/old/bridje-vfs/src/test/java/org/bridje/vfs/PathTest.java b/old/bridje-vfs/src/test/java/org/bridje/vfs/PathTest.java index fcd03d985..10128d385 100644 --- a/old/bridje-vfs/src/test/java/org/bridje/vfs/PathTest.java +++ b/old/bridje-vfs/src/test/java/org/bridje/vfs/PathTest.java @@ -1,214 +1,214 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.vfs; - -import org.bridje.vfs.Path; -import java.util.Iterator; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import static org.junit.Assert.*; - -public class PathTest -{ - - public PathTest() - { - } - - @BeforeClass - public static void setUpClass() - { - } - - @AfterClass - public static void tearDownClass() - { - } - - @Before - public void setUp() - { - } - - @After - public void tearDown() - { - } - - /** - * Test of getFirstElement method, of class Path. - */ - @Test - public void testGetFirstElement() - { - Path instance = new Path("/usr/local"); - String expResult = "usr"; - String result = instance.getFirstElement(); - assertEquals(expResult, result); - } - - /** - * Test of getName method, of class Path. - */ - @Test - public void testGetName() - { - Path instance = new Path("/usr/local/asd.txt"); - String expResult = "asd.txt"; - String result = instance.getName(); - assertEquals(expResult, result); - } - - /** - * Test of getParent method, of class Path. - */ - @Test - public void testGetParent() - { - Path instance = new Path("/var/etc/log/"); - Path expResult = new Path("/var/etc"); - Path result = instance.getParent(); - assertEquals(expResult, result); - } - - /** - * Test of getNext method, of class Path. - */ - @Test - public void testGetNext() - { - Path instance = new Path("/var/www/html"); - Path expResult = new Path("/www/html"); - Path result = instance.getNext(); - assertEquals(expResult, result); - } - - /** - * Test of hasNext method, of class Path. - */ - @Test - public void testHasNext() - { - Path instance = new Path("/www"); - boolean expResult = false; - boolean result = instance.hasNext(); - assertEquals(expResult, result); - } - - /** - * Test of isSelf method, of class Path. - */ - @Test - public void testIsSelf() - { - Path instance = new Path("/./asd"); - boolean expResult = true; - boolean result = instance.isSelf(); - assertEquals(expResult, result); - } - - /** - * Test of isParent method, of class Path. - */ - @Test - public void testIsParent() - { - Path instance = new Path("/../"); - boolean expResult = true; - boolean result = instance.isParent(); - assertEquals(expResult, result); - } - - /** - * Test of isLast method, of class Path. - */ - @Test - public void testIsLast() - { - Path instance = new Path("/www"); - boolean expResult = true; - boolean result = instance.isLast(); - assertEquals(expResult, result); - } - - /** - * Test of getCanonicalPath method, of class Path. - */ - @Test - public void testGetCanonicalPath() - { - Path instance = new Path("/usr/./../usr/local/../g.txt"); - Path expResult = new Path("/usr/g.txt"); - Path result = instance.getCanonicalPath(); - assertEquals(expResult, result); - } - - /** - * Test of toString method, of class Path. - */ - @Test - public void testToString_0args() - { - Path instance = new Path("/usr/local"); - String expResult = "usr/local"; - String result = instance.toString(); - assertEquals(expResult, result); - } - - /** - * Test of toString method, of class Path. - */ - @Test - public void testToString_String() - { - System.out.println("toString"); - String pathSep = "\\"; - Path instance = new Path("/usr/local/bin"); - String expResult = "usr\\local\\bin"; - String result = instance.toString(pathSep); - assertEquals(expResult, result); - } - - /** - * Test of join method, of class Path. - */ - @Test - public void testJoin_Path() - { - Path path = new Path("/html/public"); - Path instance = new Path("/var/www"); - Path expResult = new Path("/var/www/html/public"); - Path result = instance.join(path); - assertEquals(expResult, result); - } - - /** - * Test of join method, of class Path. - */ - @Test - public void testJoin_String() - { - String path = "/html/public"; - Path instance = new Path("/var/www");; - Path expResult = new Path("/var/www/html/public"); - Path result = instance.join(path); - assertEquals(expResult, result); - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.vfs; + +import org.bridje.vfs.Path; +import java.util.Iterator; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; + +public class PathTest +{ + + public PathTest() + { + } + + @BeforeClass + public static void setUpClass() + { + } + + @AfterClass + public static void tearDownClass() + { + } + + @Before + public void setUp() + { + } + + @After + public void tearDown() + { + } + + /** + * Test of getFirstElement method, of class Path. + */ + @Test + public void testGetFirstElement() + { + Path instance = new Path("/usr/local"); + String expResult = "usr"; + String result = instance.getFirstElement(); + assertEquals(expResult, result); + } + + /** + * Test of getName method, of class Path. + */ + @Test + public void testGetName() + { + Path instance = new Path("/usr/local/asd.txt"); + String expResult = "asd.txt"; + String result = instance.getName(); + assertEquals(expResult, result); + } + + /** + * Test of getParent method, of class Path. + */ + @Test + public void testGetParent() + { + Path instance = new Path("/var/etc/log/"); + Path expResult = new Path("/var/etc"); + Path result = instance.getParent(); + assertEquals(expResult, result); + } + + /** + * Test of getNext method, of class Path. + */ + @Test + public void testGetNext() + { + Path instance = new Path("/var/www/html"); + Path expResult = new Path("/www/html"); + Path result = instance.getNext(); + assertEquals(expResult, result); + } + + /** + * Test of hasNext method, of class Path. + */ + @Test + public void testHasNext() + { + Path instance = new Path("/www"); + boolean expResult = false; + boolean result = instance.hasNext(); + assertEquals(expResult, result); + } + + /** + * Test of isSelf method, of class Path. + */ + @Test + public void testIsSelf() + { + Path instance = new Path("/./asd"); + boolean expResult = true; + boolean result = instance.isSelf(); + assertEquals(expResult, result); + } + + /** + * Test of isParent method, of class Path. + */ + @Test + public void testIsParent() + { + Path instance = new Path("/../"); + boolean expResult = true; + boolean result = instance.isParent(); + assertEquals(expResult, result); + } + + /** + * Test of isLast method, of class Path. + */ + @Test + public void testIsLast() + { + Path instance = new Path("/www"); + boolean expResult = true; + boolean result = instance.isLast(); + assertEquals(expResult, result); + } + + /** + * Test of getCanonicalPath method, of class Path. + */ + @Test + public void testGetCanonicalPath() + { + Path instance = new Path("/usr/./../usr/local/../g.txt"); + Path expResult = new Path("/usr/g.txt"); + Path result = instance.getCanonicalPath(); + assertEquals(expResult, result); + } + + /** + * Test of toString method, of class Path. + */ + @Test + public void testToString_0args() + { + Path instance = new Path("/usr/local"); + String expResult = "usr/local"; + String result = instance.toString(); + assertEquals(expResult, result); + } + + /** + * Test of toString method, of class Path. + */ + @Test + public void testToString_String() + { + System.out.println("toString"); + String pathSep = "\\"; + Path instance = new Path("/usr/local/bin"); + String expResult = "usr\\local\\bin"; + String result = instance.toString(pathSep); + assertEquals(expResult, result); + } + + /** + * Test of join method, of class Path. + */ + @Test + public void testJoin_Path() + { + Path path = new Path("/html/public"); + Path instance = new Path("/var/www"); + Path expResult = new Path("/var/www/html/public"); + Path result = instance.join(path); + assertEquals(expResult, result); + } + + /** + * Test of join method, of class Path. + */ + @Test + public void testJoin_String() + { + String path = "/html/public"; + Path instance = new Path("/var/www");; + Path expResult = new Path("/var/www/html/public"); + Path result = instance.join(path); + assertEquals(expResult, result); + } +} diff --git a/old/bridje-vfs/src/test/java/org/bridje/vfs/TestVfsMountConfig.java b/old/bridje-vfs/src/test/java/org/bridje/vfs/TestVfsMountConfig.java index 2092a1bfd..92955bf6e 100644 --- a/old/bridje-vfs/src/test/java/org/bridje/vfs/TestVfsMountConfig.java +++ b/old/bridje-vfs/src/test/java/org/bridje/vfs/TestVfsMountConfig.java @@ -1,36 +1,36 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.vfs; - -import org.bridje.vfs.VfsMountConfig; -import org.bridje.vfs.VfsMountEntry; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import org.bridje.ioc.Component; - -@Component -public class TestVfsMountConfig implements VfsMountConfig -{ - @Override - public List getEntries() - { - VfsMountEntry entry = new VfsMountEntry("/src", "SYSTEMFS", new HashMap<>()); - entry.getProperties().put("file", "./src"); - return Arrays.asList(new VfsMountEntry[]{ entry }); - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.vfs; + +import org.bridje.vfs.VfsMountConfig; +import org.bridje.vfs.VfsMountEntry; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import org.bridje.ioc.Component; + +@Component +public class TestVfsMountConfig implements VfsMountConfig +{ + @Override + public List getEntries() + { + VfsMountEntry entry = new VfsMountEntry("/src", "SYSTEMFS", new HashMap<>()); + entry.getProperties().put("file", "./src"); + return Arrays.asList(new VfsMountEntry[]{ entry }); + } +} diff --git a/old/bridje-vfs/src/test/java/org/bridje/vfs/VfsServiceTest.java b/old/bridje-vfs/src/test/java/org/bridje/vfs/VfsServiceTest.java index e82ea44fb..7a2f76d28 100644 --- a/old/bridje-vfs/src/test/java/org/bridje/vfs/VfsServiceTest.java +++ b/old/bridje-vfs/src/test/java/org/bridje/vfs/VfsServiceTest.java @@ -1,72 +1,72 @@ -/* - * Copyright 2015 Bridje Framework. - * - * Licensed 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.bridje.vfs; - -import org.bridje.vfs.VirtualFolder; -import org.bridje.vfs.VfsService; -import org.bridje.vfs.VirtualFile; -import org.bridje.ioc.Ioc; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import static org.junit.Assert.*; - -public class VfsServiceTest -{ - - public VfsServiceTest() - { - } - - @BeforeClass - public static void setUpClass() - { - } - - @AfterClass - public static void tearDownClass() - { - } - - @Before - public void setUp() - { - } - - @After - public void tearDown() - { - } - - @Test - public void testFindFolder_String() - { - String path = "/src/main"; - VfsService instance = Ioc.context().find(VfsService.class); - String expResult = "main"; - VirtualFolder result = instance.findFolder(path); - assertNotNull(result); - assertEquals(expResult, result.getName()); - - instance.travel((VirtualFile f) -> - { - System.out.println(f.getPath()); - }); - } -} +/* + * Copyright 2015 Bridje Framework. + * + * Licensed 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.bridje.vfs; + +import org.bridje.vfs.VirtualFolder; +import org.bridje.vfs.VfsService; +import org.bridje.vfs.VirtualFile; +import org.bridje.ioc.Ioc; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; + +public class VfsServiceTest +{ + + public VfsServiceTest() + { + } + + @BeforeClass + public static void setUpClass() + { + } + + @AfterClass + public static void tearDownClass() + { + } + + @Before + public void setUp() + { + } + + @After + public void tearDown() + { + } + + @Test + public void testFindFolder_String() + { + String path = "/src/main"; + VfsService instance = Ioc.context().find(VfsService.class); + String expResult = "main"; + VirtualFolder result = instance.findFolder(path); + assertNotNull(result); + assertEquals(expResult, result.getName()); + + instance.travel((VirtualFile f) -> + { + System.out.println(f.getPath()); + }); + } +} diff --git a/pom.xml b/pom.xml index f29bdc3b4..360f5d3e2 100644 --- a/pom.xml +++ b/pom.xml @@ -1,260 +1,260 @@ - - - 4.0.0 - - org.bridje - bridje-parent - 0.1.3-SNAPSHOT - pom - - Bridje (Parent) - Parent Maven Project for Bridje Framework - http://www.bridje.org - - 2015 - - Bridje Framework - http://www.bridje.org - - - - UTF-8 - 1.8 - 1.8 - - - - bridje-ioc - bridje-cfg - bridje-xsd-maven-plugin - bridje-http - - - - https://github.com/bridje/bridje-framework - scm:git:https://github.com/bridje/bridje-framework.git - scm:git:https://github.com/bridje/bridje-framework.git - HEAD - - - - github - https://github.com/bridje/bridje-framework/issues - - - - - sonatype-releases - https://oss.sonatype.org/service/local/staging/deploy/maven2 - - - true - sonatype-snapshots - https://oss.sonatype.org/content/repositories/snapshots - - - - - - Gilberto Vento - gilbertovento - gilberto.vento@gmail.com - -5 - - - Alejandro Ferrandiz - gorums - gorumlabmatcom@gmail.com - -5 - - - - - - Apache License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt - repo - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.3 - - ${maven.compiler.source} - ${maven.compiler.target} - ${project.build.sourceEncoding} - - - - org.apache.maven.plugins - maven-release-plugin - 2.5.3 - - - org.apache.maven.plugins - maven-source-plugin - 2.4 - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.10.3 - - - org.apache.maven.plugins - maven-deploy-plugin - 2.8.2 - - - org.bsc.maven - maven-processor-plugin - 2.2.4 - - - org.apache.maven.plugins - maven-resources-plugin - 2.7 - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.3 - - - org.apache.maven.plugins - maven-source-plugin - 2.4 - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.10.3 - - - org.apache.maven.plugins - maven-deploy-plugin - 2.8.2 - - - org.apache.maven.plugins - maven-release-plugin - 2.5.3 - - v@{project.version} - true - forked-path - false - -Psonatype-oss-release - - - - - - - - - junit - junit - 4.12 - - - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.10.3 - - false - - - - org.apache.maven.plugins - maven-jxr-plugin - 2.5 - - - aggregate - - aggregate - test-aggregate - - - - - - org.apache.maven.plugins - maven-checkstyle-plugin - 2.15 - - - - - - - sonatype-public - https://oss.sonatype.org/content/groups/public - - - sonatype-staging - https://oss.sonatype.org/content/groups/staging - - - - - - release-profile - - - - - org.apache.maven.plugins - maven-gpg-plugin - 1.6 - - - sign-artifacts - verify - - sign - - - - - - - - - org.apache.maven.plugins - maven-gpg-plugin - 1.6 - - - --no-tty - - - - - sign-artifacts - verify - - sign - - - - - - - - + + + 4.0.0 + + org.bridje + bridje-parent + 0.1.3-SNAPSHOT + pom + + Bridje (Parent) + Parent Maven Project for Bridje Framework + http://www.bridje.org + + 2015 + + Bridje Framework + http://www.bridje.org + + + + UTF-8 + 1.8 + 1.8 + + + + bridje-ioc + bridje-cfg + bridje-xsd-maven-plugin + bridje-http + + + + https://github.com/bridje/bridje-framework + scm:git:https://github.com/bridje/bridje-framework.git + scm:git:https://github.com/bridje/bridje-framework.git + HEAD + + + + github + https://github.com/bridje/bridje-framework/issues + + + + + sonatype-releases + https://oss.sonatype.org/service/local/staging/deploy/maven2 + + + true + sonatype-snapshots + https://oss.sonatype.org/content/repositories/snapshots + + + + + + Gilberto Vento + gilbertovento + gilberto.vento@gmail.com + -5 + + + Alejandro Ferrandiz + gorums + gorumlabmatcom@gmail.com + -5 + + + + + + Apache License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.3 + + ${maven.compiler.source} + ${maven.compiler.target} + ${project.build.sourceEncoding} + + + + org.apache.maven.plugins + maven-release-plugin + 2.5.3 + + + org.apache.maven.plugins + maven-source-plugin + 2.4 + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.10.3 + + + org.apache.maven.plugins + maven-deploy-plugin + 2.8.2 + + + org.bsc.maven + maven-processor-plugin + 2.2.4 + + + org.apache.maven.plugins + maven-resources-plugin + 2.7 + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.3 + + + org.apache.maven.plugins + maven-source-plugin + 2.4 + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.10.3 + + + org.apache.maven.plugins + maven-deploy-plugin + 2.8.2 + + + org.apache.maven.plugins + maven-release-plugin + 2.5.3 + + v@{project.version} + true + forked-path + false + -Psonatype-oss-release + + + + + + + + + junit + junit + 4.12 + + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.10.3 + + false + + + + org.apache.maven.plugins + maven-jxr-plugin + 2.5 + + + aggregate + + aggregate + test-aggregate + + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + 2.15 + + + + + + + sonatype-public + https://oss.sonatype.org/content/groups/public + + + sonatype-staging + https://oss.sonatype.org/content/groups/staging + + + + + + release-profile + + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.6 + + + sign-artifacts + verify + + sign + + + + + + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.6 + + + --no-tty + + + + + sign-artifacts + verify + + sign + + + + + + + + \ No newline at end of file