POLYGENE-298 - Removed library-restlet. Formatting in the other rest libraries
Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/3a26d21d Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/3a26d21d Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/3a26d21d Branch: refs/heads/develop Commit: 3a26d21dd999b9b8ec8cfca0092219b1b793085e Parents: 8d0d8dc Author: niclas <nic...@hedhman.org> Authored: Tue Apr 3 18:52:34 2018 +0800 Committer: niclas <nic...@hedhman.org> Committed: Tue Apr 3 18:52:34 2018 +0800 ---------------------------------------------------------------------- .../ContextResourceClientFactoryTest.java | 89 +++---- .../responsewriter/TableResponseWriter.java | 2 +- .../ValueCompositeResponseWriter.java | 2 +- .../server/restlet/responsewriter/resource.htm | 2 +- .../server/restlet/responsewriter/table.htm | 2 +- .../server/restlet/responsewriter/value.htm | 3 +- libraries/restlet/build.gradle | 50 ---- libraries/restlet/dev-status.xml | 38 --- libraries/restlet/src/docs/restlet.txt | 63 ----- .../polygene/library/restlet/Command.java | 29 -- .../library/restlet/ConversionException.java | 29 -- .../library/restlet/HasDescription.java | 31 --- .../polygene/library/restlet/HasName.java | 28 -- .../PolygeneRestApplicationLauncher.java | 104 -------- .../library/restlet/PolygeneServerServlet.java | 46 ---- .../polygene/library/restlet/RestLink.java | 30 --- .../restlet/assembly/CrudServiceAssembler.java | 39 --- .../RestletCrudConnectivityAssembler.java | 69 ----- .../assembly/RestletCrudModuleAssembler.java | 74 ------ .../library/restlet/crud/EntityList.java | 33 --- .../library/restlet/crud/EntityRef.java | 35 --- .../restlet/crud/HasIdentitySpecification.java | 44 ---- .../crud/RepositoryNotFoundException.java | 29 -- .../library/restlet/filters/NameFilter.java | 40 --- .../library/restlet/identity/CanonicalName.java | 56 ---- .../restlet/identity/IdentityManager.java | 156 ----------- .../identity/IdentityMappingConfiguration.java | 33 --- .../InvalidIdentityFormatException.java | 29 -- .../library/restlet/metainfo/UserIdentity.java | 66 ----- .../library/restlet/repository/EntityName.java | 64 ----- .../repository/EntityTypeDescriptor.java | 42 --- .../repository/MissingRepositoryException.java | 29 -- .../restlet/repository/RepositoryLocator.java | 62 ----- .../resource/DefaultResourceFactoryImpl.java | 101 ------- .../library/restlet/resource/EntryPoint.java | 31 --- .../restlet/resource/NotPresentException.java | 25 -- .../library/restlet/resource/Parameterizer.java | 25 -- .../restlet/resource/ResourceFactory.java | 31 --- .../restlet/resource/ServerResource.java | 109 -------- .../serialization/FormRepresentation.java | 150 ----------- .../serialization/JsonRepresentation.java | 135 ---------- .../serialization/PolygeneConverter.java | 263 ------------------- ...org.restlet.engine.converter.ConverterHelper | 16 -- .../polygene/library/restlet/Customer.java | 27 -- .../apache/polygene/library/restlet/Order.java | 27 -- .../polygene/library/restlet/Product.java | 27 -- .../library/restlet/TestApplication.java | 83 ------ .../assembly/RestApplicationAssembler.java | 81 ------ .../configuration/ConfigurationLayer.java | 45 ---- .../configuration/ConfigurationModule.java | 40 --- .../connectivity/ConnectivityLayer.java | 39 --- .../assembly/connectivity/RestModule.java | 40 --- .../assembly/connectivity/SecurityModule.java | 35 --- .../restlet/assembly/domain/CrudModule.java | 39 --- .../restlet/assembly/domain/DomainLayer.java | 38 --- .../restlet/assembly/domain/OrdersModule.java | 44 ---- .../infrastructue/FileStorageModule.java | 51 ---- .../assembly/infrastructue/IndexingModule.java | 49 ---- .../infrastructue/InfrastructureLayer.java | 55 ---- .../infrastructue/SerializationModule.java | 37 --- .../assembly/resource/ResourceLayer.java | 37 --- settings.gradle | 1 - 62 files changed, 50 insertions(+), 3079 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/polygene-java/blob/3a26d21d/libraries/rest-client/src/test/java/org/apache/polygene/library/rest/client/ContextResourceClientFactoryTest.java ---------------------------------------------------------------------- diff --git a/libraries/rest-client/src/test/java/org/apache/polygene/library/rest/client/ContextResourceClientFactoryTest.java b/libraries/rest-client/src/test/java/org/apache/polygene/library/rest/client/ContextResourceClientFactoryTest.java index 80db1bf..b6854f5 100644 --- a/libraries/rest-client/src/test/java/org/apache/polygene/library/rest/client/ContextResourceClientFactoryTest.java +++ b/libraries/rest-client/src/test/java/org/apache/polygene/library/rest/client/ContextResourceClientFactoryTest.java @@ -125,7 +125,6 @@ public class ContextResourceClientFactoryTest module.objects( RootRestlet.class, RootResource.class, RootContext.class, SubResource1.class, PagesResource.class ); - module.objects( DescribableContext.class ); module.transients( TestComposite.class ); @@ -146,18 +145,18 @@ public class ContextResourceClientFactoryTest server = new Server( Protocol.HTTP, port ); ContextRestlet restlet = objectFactory.newObject( ContextRestlet.class, new org.restlet.Context() ); - ChallengeAuthenticator guard = new ChallengeAuthenticator(null, ChallengeScheme.HTTP_BASIC, "testRealm"); + ChallengeAuthenticator guard = new ChallengeAuthenticator( null, ChallengeScheme.HTTP_BASIC, "testRealm" ); MapVerifier mapVerifier = new MapVerifier(); - mapVerifier.getLocalSecrets().put("rickard", "secret".toCharArray()); - guard.setVerifier(mapVerifier); + mapVerifier.getLocalSecrets().put( "rickard", "secret".toCharArray() ); + guard.setVerifier( mapVerifier ); - guard.setNext(restlet); + guard.setNext( restlet ); server.setNext( guard ); server.start(); //START SNIPPET: client-create1 - Client client = new Client( Protocol.HTTP ); + Client client = new Client( Protocol.HTTP ); ContextResourceClientFactory contextResourceClientFactory = objectFactory.newObject( ContextResourceClientFactory.class, client ); contextResourceClientFactory.setAcceptedMediaTypes( MediaType.APPLICATION_JSON ); @@ -171,14 +170,16 @@ public class ContextResourceClientFactoryTest @Override public HandlerCommand handleResponse( Response response, ContextResourceClient client ) { - if (tried) - throw new ResourceException( response.getStatus() ); + if( tried ) + { + throw new ResourceException( response.getStatus() ); + } - tried = true; - client.getContextResourceClientFactory().getInfo().setUser( new User("rickard", "secret") ); + tried = true; + client.getContextResourceClientFactory().getInfo().setUser( new User( "rickard", "secret" ) ); - // Try again - return refresh(); + // Try again + return refresh(); } } ).onError( ErrorHandler.RECOVERABLE_ERROR, new ResponseHandler() { @@ -222,15 +223,15 @@ public class ContextResourceClientFactoryTest return query( "querywithoutvalue" ); } } ). - onQuery( "querywithoutvalue", new ResultHandler<TestResult>() - { - @Override - public HandlerCommand handleResult( TestResult result, ContextResourceClient client ) - { - Assert.assertThat( result.xyz().get(), CoreMatchers.equalTo( "bar" ) ); - return null; - } - } ); + onQuery( "querywithoutvalue", new ResultHandler<TestResult>() + { + @Override + public HandlerCommand handleResult( TestResult result, ContextResourceClient client ) + { + Assert.assertThat( result.xyz().get(), CoreMatchers.equalTo( "bar" ) ); + return null; + } + } ); crc.start(); //END SNIPPET: query-without-value @@ -351,7 +352,7 @@ public class ContextResourceClientFactoryTest @Test public void testIndexedResource() { - crc.newClient("subcontext/pages/").onResource( new ResultHandler<Resource>() + crc.newClient( "subcontext/pages/" ).onResource( new ResultHandler<Resource>() { @Override public HandlerCommand handleResult( Resource result, ContextResourceClient client ) @@ -359,16 +360,15 @@ public class ContextResourceClientFactoryTest return query( "index" ); } } ).onQuery( "index", new ResultHandler<Links>() - { - @Override - public HandlerCommand handleResult( Links result, ContextResourceClient client ) - { - Assert.assertEquals( result.links().get().size(), 3 ); - return null; - } - } ) - .start(); - + { + @Override + public HandlerCommand handleResult( Links result, ContextResourceClient client ) + { + Assert.assertEquals( result.links().get().size(), 3 ); + return null; + } + } ) + .start(); } public interface TestQuery @@ -441,10 +441,10 @@ public class ContextResourceClientFactoryTest public Links commandwithvalue() { - return new LinksBuilder(module). - command( "commandwithvalue" ). - addLink( "Command ABC","right" ). - addLink( "Command XYZ", "wrong" ).newLinks(); + return new LinksBuilder( module ). + command( "commandwithvalue" ). + addLink( "Command ABC", "right" ). + addLink( "Command XYZ", "wrong" ).newLinks(); } @Override @@ -519,7 +519,7 @@ public class ContextResourceClientFactoryTest } @Requires( File.class ) - public TestResult queryWithRoleRequirement(TestQuery query) + public TestResult queryWithRoleRequirement( TestQuery query ) { return context( SubContext.class ).queryWithRoleRequirement( query ); } @@ -549,7 +549,8 @@ public class ContextResourceClientFactoryTest } @SubResource - public void pages() { + public void pages() + { subResource( PagesResource.class ); } } @@ -566,7 +567,7 @@ public class ContextResourceClientFactoryTest public TestResult queryWithValue( TestQuery query ) { - return vbf.newValueFromSerializedState( TestResult.class, "{\"xyz\":\""+query.abc().get()+"\"}" ); + return vbf.newValueFromSerializedState( TestResult.class, "{\"xyz\":\"" + query.abc().get() + "\"}" ); } public TestResult queryWithoutValue() @@ -705,11 +706,11 @@ public class ContextResourceClientFactoryTest @Override public Links index() { - return new LinksBuilder(module) - .addLink( "Page1", "page1") - .addLink( "Page2", "page2") - .addLink( "Page3", "page3") - .newLinks(); + return new LinksBuilder( module ) + .addLink( "Page1", "page1" ) + .addLink( "Page2", "page2" ) + .addLink( "Page3", "page3" ) + .newLinks(); } } http://git-wip-us.apache.org/repos/asf/polygene-java/blob/3a26d21d/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/restlet/responsewriter/TableResponseWriter.java ---------------------------------------------------------------------- diff --git a/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/restlet/responsewriter/TableResponseWriter.java b/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/restlet/responsewriter/TableResponseWriter.java index 55ebe77..68bc264 100644 --- a/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/restlet/responsewriter/TableResponseWriter.java +++ b/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/restlet/responsewriter/TableResponseWriter.java @@ -152,7 +152,7 @@ public class TableResponseWriter extends AbstractResponseWriter JsonObjectBuilder cellBuilder = jsonBuilderFactory.createObjectBuilder(); if( value != null ) { - cellBuilder.add( "v", jsonSerializer.toJson( Serializer.Options.ALL_TYPE_INFO, value ) ); + cellBuilder.add( "v", jsonSerializer.toJson( Serializer.Options.NO_TYPE_INFO, value ) ); } if( cellValue.f().get() != null ) { http://git-wip-us.apache.org/repos/asf/polygene-java/blob/3a26d21d/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/restlet/responsewriter/ValueCompositeResponseWriter.java ---------------------------------------------------------------------- diff --git a/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/restlet/responsewriter/ValueCompositeResponseWriter.java b/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/restlet/responsewriter/ValueCompositeResponseWriter.java index 845b256..5e32b39 100644 --- a/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/restlet/responsewriter/ValueCompositeResponseWriter.java +++ b/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/restlet/responsewriter/ValueCompositeResponseWriter.java @@ -63,7 +63,7 @@ public class ValueCompositeResponseWriter extends AbstractResponseWriter MediaType type = getVariant( response.getRequest(), ENGLISH, supportedMediaTypes ).getMediaType(); if( MediaType.APPLICATION_JSON.equals( type ) ) { - StringRepresentation representation = new StringRepresentation( serializer.serialize( Serializer.Options.ALL_TYPE_INFO, result ), + StringRepresentation representation = new StringRepresentation( serializer.serialize( Serializer.Options.NO_TYPE_INFO, result ), MediaType.APPLICATION_JSON ); response.setEntity( representation ); return true; http://git-wip-us.apache.org/repos/asf/polygene-java/blob/3a26d21d/libraries/rest-server/src/main/resources/org/apache/polygene/library/rest/server/restlet/responsewriter/resource.htm ---------------------------------------------------------------------- diff --git a/libraries/rest-server/src/main/resources/org/apache/polygene/library/rest/server/restlet/responsewriter/resource.htm b/libraries/rest-server/src/main/resources/org/apache/polygene/library/rest/server/restlet/responsewriter/resource.htm index 4c00354..fbff49b 100644 --- a/libraries/rest-server/src/main/resources/org/apache/polygene/library/rest/server/restlet/responsewriter/resource.htm +++ b/libraries/rest-server/src/main/resources/org/apache/polygene/library/rest/server/restlet/responsewriter/resource.htm @@ -19,7 +19,7 @@ --> <!-- Default resource template --> -<html> +<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>${request.resourceRef.remainingPart}</title> </head> http://git-wip-us.apache.org/repos/asf/polygene-java/blob/3a26d21d/libraries/rest-server/src/main/resources/org/apache/polygene/library/rest/server/restlet/responsewriter/table.htm ---------------------------------------------------------------------- diff --git a/libraries/rest-server/src/main/resources/org/apache/polygene/library/rest/server/restlet/responsewriter/table.htm b/libraries/rest-server/src/main/resources/org/apache/polygene/library/rest/server/restlet/responsewriter/table.htm index e9ce307..63b9eec 100644 --- a/libraries/rest-server/src/main/resources/org/apache/polygene/library/rest/server/restlet/responsewriter/table.htm +++ b/libraries/rest-server/src/main/resources/org/apache/polygene/library/rest/server/restlet/responsewriter/table.htm @@ -18,7 +18,7 @@ ~ --> -<html> +<html xmlns="http://www.w3.org/1999/xhtml"> <body> <table border="1"> http://git-wip-us.apache.org/repos/asf/polygene-java/blob/3a26d21d/libraries/rest-server/src/main/resources/org/apache/polygene/library/rest/server/restlet/responsewriter/value.htm ---------------------------------------------------------------------- diff --git a/libraries/rest-server/src/main/resources/org/apache/polygene/library/rest/server/restlet/responsewriter/value.htm b/libraries/rest-server/src/main/resources/org/apache/polygene/library/rest/server/restlet/responsewriter/value.htm index 971fd24..0796e4c 100644 --- a/libraries/rest-server/src/main/resources/org/apache/polygene/library/rest/server/restlet/responsewriter/value.htm +++ b/libraries/rest-server/src/main/resources/org/apache/polygene/library/rest/server/restlet/responsewriter/value.htm @@ -17,8 +17,7 @@ ~ ~ --> - -<html> +<html xmlns="http://www.w3.org/1999/xhtml"> <body> <ul> http://git-wip-us.apache.org/repos/asf/polygene-java/blob/3a26d21d/libraries/restlet/build.gradle ---------------------------------------------------------------------- diff --git a/libraries/restlet/build.gradle b/libraries/restlet/build.gradle deleted file mode 100644 index 7a8705c..0000000 --- a/libraries/restlet/build.gradle +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ -import org.apache.polygene.gradle.TaskGroups - -apply plugin: 'polygene-library' - -description = "Apache Polygene⢠Restlet Library provides automatic CRUD resources as well as custom resources integrated to Polygene." - -jar { manifest { name = "Apache Polygene⢠Library - Restlet" } } - -dependencies { - compileOnly libraries.servlet_api - - api polygene.core.bootstrap - - implementation libraries.restlet - - runtimeOnly polygene.core.runtime - - testImplementation polygene.core.testsupport - testImplementation polygene.library( 'http' ) - testImplementation libraries.http_client - testImplementation polygene.extension( 'entitystore-file' ) - testImplementation polygene.extension( 'indexing-rdf' ) - testRuntimeOnly libraries.logback -} - -task runRestletSample( type: JavaExec, dependsOn: 'testClasses' ) { - group = TaskGroups.SAMPLES - description = "Runs $project.name sample." - classpath = sourceSets.test.runtimeClasspath - main = 'org.apache.polygene.library.restlet.TestApplication' -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/3a26d21d/libraries/restlet/dev-status.xml ---------------------------------------------------------------------- diff --git a/libraries/restlet/dev-status.xml b/libraries/restlet/dev-status.xml deleted file mode 100644 index 97fd7ff..0000000 --- a/libraries/restlet/dev-status.xml +++ /dev/null @@ -1,38 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<!-- - ~ Licensed to the Apache Software Foundation (ASF) under one - ~ or more contributor license agreements. See the NOTICE file - ~ distributed with this work for additional information - ~ regarding copyright ownership. The ASF licenses this file - ~ to you under the Apache License, Version 2.0 (the - ~ "License"); you may not use this file except in compliance - ~ with the License. You may obtain a copy of the License at - ~ - ~ http://www.apache.org/licenses/LICENSE-2.0 - ~ - ~ Unless required by applicable law or agreed to in writing, software - ~ distributed under the License is distributed on an "AS IS" BASIS, - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - ~ See the License for the specific language governing permissions and - ~ limitations under the License. - ~ - ~ - --> -<module xmlns="http://polygene.apache.org/schemas/2008/dev-status/1" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://polygene.apache.org/schemas/2008/dev-status/1 - http://polygene.apache.org/schemas/2008/dev-status/1/dev-status.xsd"> - <status> - <!--none,early,beta,stable,mature--> - <codebase>stable</codebase> - - <!-- none, brief, good, complete --> - <documentation>brief</documentation> - - <!-- none, some, good, complete --> - <unittests>some</unittests> - </status> - <licenses> - <license>ALv2</license> - </licenses> -</module> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/polygene-java/blob/3a26d21d/libraries/restlet/src/docs/restlet.txt ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/docs/restlet.txt b/libraries/restlet/src/docs/restlet.txt deleted file mode 100644 index 69cd82a..0000000 --- a/libraries/restlet/src/docs/restlet.txt +++ /dev/null @@ -1,63 +0,0 @@ -/////////////////////////////////////////////////////////////// - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. -/////////////////////////////////////////////////////////////// - -[[library-restlet, Restlet Library]] -= Restlet Support = - -[devstatus] --------------- -source=libraries/restlet/dev-status.xml --------------- - -The Restlet Support Library has support to expose CRUD operations directly -as well as regular Rest resources. - -include::../../build/docs/buildinfo/artifact.txt[] - -This library leverages +restlet.org+ which has a very neat way to map resources -to URIs, and flexible ways to be served the requests. This library defines -all the plumbing needed to set up Restlet, map resources to URIs, convert -Polygene ValueComposites to resource representations (such as JSON) and -create a fully HATEOAS environment, with single bookmarkable URI. - -To set up the Restlet Connectivity Module, it is recommended to use the provided -+Assembler+ for it; - - -[[library-restlet-resource-binding, Restlet Resource Binding]] -== Resource Binding == -REST defines that all URLs are *resources* and that a known, small set of -operations can be done on those resources. - - - -== CRUD Repository == -This library provides a +CrudRepository+ which simplifies accessing entities -directly from the Rest module. This is implemented by using the -<<library-restlet-resource-binding, Resource Binding>> above. - -It also requires that one or more Crud Modules are defined. These are typically -either in the domain layer directly, or in the layer above (some call that the -service layer). There is a RestletCrudModuleAssembler that helps set up such -module. Typical setup is like this; - - - - - http://git-wip-us.apache.org/repos/asf/polygene-java/blob/3a26d21d/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/Command.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/Command.java b/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/Command.java deleted file mode 100644 index cd739fe..0000000 --- a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/Command.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ -package org.apache.polygene.library.restlet; - -import org.apache.polygene.api.property.Property; - -public interface Command -{ - Property<String> name(); - - Property<RestForm> form(); -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/3a26d21d/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/ConversionException.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/ConversionException.java b/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/ConversionException.java deleted file mode 100644 index 5e11e3c..0000000 --- a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/ConversionException.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ - -package org.apache.polygene.library.restlet; - -public class ConversionException extends RuntimeException -{ - public ConversionException( String entityAsText ) - { - super( "Unable to convert REST entity: " + entityAsText ); - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/3a26d21d/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/HasDescription.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/HasDescription.java b/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/HasDescription.java deleted file mode 100644 index d4a8f85..0000000 --- a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/HasDescription.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ - -package org.apache.polygene.library.restlet; - -import org.apache.polygene.api.common.Optional; -import org.apache.polygene.api.common.UseDefaults; -import org.apache.polygene.api.property.Property; - -public interface HasDescription -{ - @Optional @UseDefaults - Property<String> description(); -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/3a26d21d/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/HasName.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/HasName.java b/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/HasName.java deleted file mode 100644 index a8f6517..0000000 --- a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/HasName.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ - -package org.apache.polygene.library.restlet; - -import org.apache.polygene.api.property.Property; - -public interface HasName -{ - Property<String> name(); -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/3a26d21d/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/PolygeneRestApplicationLauncher.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/PolygeneRestApplicationLauncher.java b/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/PolygeneRestApplicationLauncher.java deleted file mode 100644 index 956e1e7..0000000 --- a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/PolygeneRestApplicationLauncher.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ -package org.apache.polygene.library.restlet; - -import org.apache.polygene.api.activation.ActivationException; -import org.apache.polygene.api.activation.PassivationException; -import org.apache.polygene.api.composite.TransientBuilderFactory; -import org.apache.polygene.api.object.ObjectFactory; -import org.apache.polygene.api.service.ServiceFinder; -import org.apache.polygene.api.structure.Application; -import org.apache.polygene.api.structure.Module; -import org.apache.polygene.api.unitofwork.UnitOfWorkFactory; -import org.apache.polygene.api.value.ValueBuilderFactory; -import org.apache.polygene.bootstrap.AssemblyException; -import org.apache.polygene.bootstrap.layered.LayeredApplicationAssembler; - -@SuppressWarnings( "WeakerAccess" ) -public abstract class PolygeneRestApplicationLauncher -{ - protected org.apache.polygene.api.structure.Application polygeneApplication; - protected ServiceFinder serviceFinder; - protected ObjectFactory objectFactory; - protected TransientBuilderFactory transientBuilderFactory; - protected UnitOfWorkFactory unitOfWorkFactory; - protected ValueBuilderFactory valueBuilderFactory; - protected Module entryModule; - - public void initialize() - throws ActivationException - { - polygeneApplication = createApplication(); - activateApplication(); - entryModule = polygeneApplication.findModule( entryLayer(), entryModule() ); - serviceFinder = entryModule; - objectFactory = entryModule; - transientBuilderFactory = entryModule; - unitOfWorkFactory = entryModule.unitOfWorkFactory(); - valueBuilderFactory = entryModule; - } - - protected abstract String entryLayer(); - - protected abstract String entryModule(); - - protected void activateApplication() - throws ActivationException - { - polygeneApplication.activate(); - } - - protected Application createApplication() - { - try - { - LayeredApplicationAssembler assembler = createApplicationAssembler(); - assembler.initialize(); - return assembler.application(); - } - catch( Throwable e ) - { - throw new RuntimeException( "Unable to start Polygene application.", e ); - } - } - - protected abstract LayeredApplicationAssembler createApplicationAssembler() - throws AssemblyException; - - protected void installShutdownHook() - { - Runtime.getRuntime().addShutdownHook( new Thread( this::shutdown ) ); - } - - protected void shutdown() - { - try - { - if( polygeneApplication != null ) - { - polygeneApplication.passivate(); - } - } - catch( PassivationException e ) - { - throw new RuntimeException( "Unable to shut down cleanly.", e ); - } - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/3a26d21d/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/PolygeneServerServlet.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/PolygeneServerServlet.java b/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/PolygeneServerServlet.java deleted file mode 100644 index 834dd33..0000000 --- a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/PolygeneServerServlet.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ -package org.apache.polygene.library.restlet; - -import javax.servlet.Servlet; -import org.apache.polygene.api.injection.scope.Structure; -import org.apache.polygene.api.mixin.Mixins; -import org.apache.polygene.api.object.ObjectFactory; -import org.restlet.Context; -import org.restlet.ext.servlet.ServerServlet; - -/** - * Restlet ServerServlet backed by a org.restlet.Application object. - */ -@Mixins( PolygeneServerServlet.Mixin.class ) -public interface PolygeneServerServlet extends Servlet -{ - class Mixin extends ServerServlet - { - @Structure - private ObjectFactory objectFactory; - - @Override - protected org.restlet.Application createApplication( Context parentContext ) - { - return objectFactory.newObject( PolygeneRestApplication.class, parentContext.createChildContext() ); - } - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/3a26d21d/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/RestLink.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/RestLink.java b/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/RestLink.java deleted file mode 100644 index c2b4371..0000000 --- a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/RestLink.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ - -package org.apache.polygene.library.restlet; - -import org.apache.polygene.api.property.Property; - -public interface RestLink extends HasDescription -{ - Property<String> method(); - - Property<String> path(); -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/polygene-java/blob/3a26d21d/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/assembly/CrudServiceAssembler.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/assembly/CrudServiceAssembler.java b/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/assembly/CrudServiceAssembler.java deleted file mode 100644 index 7e55a75..0000000 --- a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/assembly/CrudServiceAssembler.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ -package org.apache.polygene.library.restlet.assembly; - -import org.apache.polygene.api.common.Visibility; -import org.apache.polygene.bootstrap.Assembler; -import org.apache.polygene.bootstrap.ModuleAssembly; -import org.apache.polygene.library.restlet.identity.IdentityManager; -import org.apache.polygene.library.restlet.identity.IdentityMappingConfiguration; -import org.apache.polygene.library.restlet.repository.RepositoryLocator; - -public class CrudServiceAssembler - implements Assembler -{ - @Override - public void assemble( ModuleAssembly module ) - { - module.entities( IdentityMappingConfiguration.class ); - module.services( IdentityManager.class ).visibleIn( Visibility.application ).instantiateOnStartup(); - module.services( RepositoryLocator.class ).visibleIn( Visibility.application ); - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/3a26d21d/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/assembly/RestletCrudConnectivityAssembler.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/assembly/RestletCrudConnectivityAssembler.java b/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/assembly/RestletCrudConnectivityAssembler.java deleted file mode 100644 index 0eb1d5e..0000000 --- a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/assembly/RestletCrudConnectivityAssembler.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ -package org.apache.polygene.library.restlet.assembly; - -import org.apache.polygene.api.common.Visibility; -import org.apache.polygene.bootstrap.Assembler; -import org.apache.polygene.bootstrap.ModuleAssembly; -import org.apache.polygene.library.restlet.Command; -import org.apache.polygene.library.restlet.FormField; -import org.apache.polygene.library.restlet.PolygeneEntityRestlet; -import org.apache.polygene.library.restlet.RestForm; -import org.apache.polygene.library.restlet.RestLink; -import org.apache.polygene.library.restlet.crud.EntityList; -import org.apache.polygene.library.restlet.crud.EntityListResource; -import org.apache.polygene.library.restlet.crud.EntityRef; -import org.apache.polygene.library.restlet.crud.EntityResource; -import org.apache.polygene.library.restlet.resource.CreationResource; -import org.apache.polygene.library.restlet.resource.DefaultResourceFactoryImpl; -import org.apache.polygene.library.restlet.resource.EntryPointResource; -import org.apache.polygene.library.restlet.resource.ResourceBuilder; -import org.apache.polygene.library.restlet.serialization.FormRepresentation; -import org.apache.polygene.library.restlet.serialization.JsonRepresentation; - -/** This assembler should go to a module in the layer of the {@link RestletCrudModuleAssembler}. - * - */ -public class RestletCrudConnectivityAssembler - implements Assembler -{ - @Override - public void assemble( ModuleAssembly module ) - { - module.values( EntryPointResource.class, - EntityListResource.class, - EntityResource.class, - CreationResource.class ) - .visibleIn( Visibility.layer ); - module.values( Command.class, - FormField.class, - RestForm.class, - RestLink.class, - EntityList.class, - EntityRef.class ) - .visibleIn( Visibility.layer ); - module.objects( DefaultResourceFactoryImpl.class, - JsonRepresentation.class, - FormRepresentation.class, - PolygeneEntityRestlet.class ) - .visibleIn( Visibility.layer ); - module.services( ResourceBuilder.class ).visibleIn( Visibility.layer ); - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/3a26d21d/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/assembly/RestletCrudModuleAssembler.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/assembly/RestletCrudModuleAssembler.java b/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/assembly/RestletCrudModuleAssembler.java deleted file mode 100644 index f6c07e0..0000000 --- a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/assembly/RestletCrudModuleAssembler.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ - -package org.apache.polygene.library.restlet.assembly; - -import org.apache.polygene.api.common.Visibility; -import org.apache.polygene.api.unitofwork.concern.UnitOfWorkConcern; -import org.apache.polygene.bootstrap.Assemblers; -import org.apache.polygene.bootstrap.ModuleAssembly; -import org.apache.polygene.bootstrap.ServiceDeclaration; -import org.apache.polygene.library.restlet.repository.CrudRepository; -import org.apache.polygene.library.restlet.repository.EntityTypeDescriptor; -import org.apache.polygene.library.restlet.repository.SmallCrudRepositoryMixin; - -/** - * This assembler should be used for each module that has CRUD types, reachable by the REST API. - */ -public class RestletCrudModuleAssembler extends Assemblers.VisibilityIdentity<RestletCrudModuleAssembler> -{ - private final Class type; - private final Class repositoryType; - - public RestletCrudModuleAssembler( Class type, Class repositoryType ) - { - this.type = type; - this.repositoryType = repositoryType; - } - - public RestletCrudModuleAssembler( Class type ) - { - this.type = type; - repositoryType = CrudRepository.class; - } - - @Override - public void assemble( ModuleAssembly module ) - { - super.assemble( module ); - ServiceDeclaration declaration = module - .addServices( repositoryType ) - .visibleIn( Visibility.application ) - .withMixins( SmallCrudRepositoryMixin.class ) - .withConcerns( UnitOfWorkConcern.class ) - .taggedWith( type.getSimpleName() ) - .setMetaInfo( new EntityTypeDescriptor( type ) ); - if( hasIdentity() ) - { - declaration.identifiedBy( identity() ); - } - else - { - declaration.identifiedBy( "repository_" + type.getSimpleName() ); - } - module.entities( type ).visibleIn( Visibility.layer ); - module.values( type ).visibleIn( Visibility.layer ); - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/3a26d21d/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/crud/EntityList.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/crud/EntityList.java b/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/crud/EntityList.java deleted file mode 100644 index 7eebdce..0000000 --- a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/crud/EntityList.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ - -package org.apache.polygene.library.restlet.crud; - -import java.util.List; -import org.apache.polygene.api.identity.HasIdentity; -import org.apache.polygene.api.property.Property; -import org.apache.polygene.library.restlet.Command; - -public interface EntityList extends HasIdentity -{ - Property<List<EntityRef>> entities(); - - Property<List<Command>> commands(); -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/3a26d21d/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/crud/EntityRef.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/crud/EntityRef.java b/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/crud/EntityRef.java deleted file mode 100644 index d077a17..0000000 --- a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/crud/EntityRef.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ - -package org.apache.polygene.library.restlet.crud; - -import org.apache.polygene.api.property.Property; -import org.apache.polygene.library.restlet.RestLink; - -public interface EntityRef -{ - Property<String> name(); - - Property<RestLink> get(); - - Property<RestLink> put(); - - Property<RestLink> delete(); -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/3a26d21d/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/crud/HasIdentitySpecification.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/crud/HasIdentitySpecification.java b/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/crud/HasIdentitySpecification.java deleted file mode 100644 index ce359ca..0000000 --- a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/crud/HasIdentitySpecification.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ - -package org.apache.polygene.library.restlet.crud; - -import java.util.Objects; -import java.util.function.Predicate; -import org.apache.polygene.api.identity.HasIdentity; -import org.apache.polygene.api.identity.Identity; - -public class HasIdentitySpecification - implements Predicate<HasIdentity> -{ - private final Identity id; - - public HasIdentitySpecification(Identity identity ) - { - Objects.requireNonNull( identity, "reference" ); - this.id = identity; - } - - @Override - public boolean test( HasIdentity item ) - { - return id.equals( item.identity().get() ); - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/3a26d21d/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/crud/RepositoryNotFoundException.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/crud/RepositoryNotFoundException.java b/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/crud/RepositoryNotFoundException.java deleted file mode 100644 index b330aa1..0000000 --- a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/crud/RepositoryNotFoundException.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ - -package org.apache.polygene.library.restlet.crud; - -public class RepositoryNotFoundException extends RuntimeException -{ - public RepositoryNotFoundException( Class entityType ) - { - super( "No repository found for " + entityType.getName() ); - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/3a26d21d/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/filters/NameFilter.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/filters/NameFilter.java b/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/filters/NameFilter.java deleted file mode 100644 index d23a3aa..0000000 --- a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/filters/NameFilter.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ - -package org.apache.polygene.library.restlet.filters; - -import java.util.function.Predicate; -import org.apache.polygene.library.restlet.HasName; - -public class NameFilter implements Predicate<HasName> -{ - private final String name; - - public NameFilter( String name ) - { - this.name = name; - } - - @Override - public boolean test( HasName hasName ) - { - return hasName.name().get().equals(name); - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/3a26d21d/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/identity/CanonicalName.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/identity/CanonicalName.java b/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/identity/CanonicalName.java deleted file mode 100644 index 3e8ee8b..0000000 --- a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/identity/CanonicalName.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ - -package org.apache.polygene.library.restlet.identity; - -import org.apache.polygene.api.identity.HasIdentity; -import org.apache.polygene.api.injection.scope.Service; -import org.apache.polygene.api.injection.scope.This; -import org.apache.polygene.api.mixin.Mixins; - -@Mixins( CanonicalName.Mixin.class ) -public interface CanonicalName -{ - String name(); - - Class type(); - - class Mixin - implements CanonicalName - { - @This - private HasIdentity me; - - @Service - private IdentityManager manager; - - @Override - public String name() - { - return manager.extractName( me.identity().get() ); - } - - @Override - public Class type() - { - return manager.extractType( me.identity().get() ); - } - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/3a26d21d/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/identity/IdentityManager.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/identity/IdentityManager.java b/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/identity/IdentityManager.java deleted file mode 100644 index e7b66fa..0000000 --- a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/identity/IdentityManager.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ - -package org.apache.polygene.library.restlet.identity; - -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.function.Predicate; -import org.apache.polygene.api.common.Optional; -import org.apache.polygene.api.concern.Concerns; -import org.apache.polygene.api.configuration.Configuration; -import org.apache.polygene.api.identity.Identity; -import org.apache.polygene.api.identity.IdentityGenerator; -import org.apache.polygene.api.identity.StringIdentity; -import org.apache.polygene.api.injection.scope.Service; -import org.apache.polygene.api.injection.scope.This; -import org.apache.polygene.api.mixin.Mixins; -import org.apache.polygene.api.unitofwork.concern.UnitOfWorkConcern; -import org.apache.polygene.api.unitofwork.concern.UnitOfWorkPropagation; - -@Mixins( IdentityManager.Mixin.class ) -@Concerns( { UnitOfWorkConcern.class } ) -public interface IdentityManager -{ - String SEPARATOR = "~"; - String IDENTITY_SIGNATURE = "[0-9][0-9]*~.*"; - - boolean isIdentity( String candidate ); - - Identity generate( Class type, @Optional String canonicalName ); - - String extractName( Identity identity ); - - Class extractType( Identity identity ); - - @UnitOfWorkPropagation - String findPrefix( Class type ); - - class Mixin - implements IdentityManager - { - @Service - private IdentityGenerator uuidService; - - @This - private Configuration<IdentityMappingConfiguration> config; - - private ConcurrentHashMap<String, Class> actualClasses = new ConcurrentHashMap<>(); - - @Override - public boolean isIdentity( String candidate ) - { - return candidate.matches( IDENTITY_SIGNATURE ); - } - - @Override - public Identity generate( Class type, String canonicalName ) - { - if( canonicalName == null ) - { - canonicalName = uuidService.generate( type ).toString(); - } - if( isIdentity( canonicalName ) ) - { - // This is already an ID, and we simply return it. - return StringIdentity.identityOf( canonicalName ); - } - String prefix = findPrefix( type ); - return StringIdentity.identityOf( prefix + SEPARATOR + canonicalName ); - } - - @Override - public String findPrefix( Class type ) - { - Map<String, String> mapping = config.get().mapping().get(); - String prefix = mapping.get( type.getName() ); - if( prefix == null ) - { - config.refresh(); - mapping = config.get().mapping().get(); - prefix = Integer.toString( mapping.size() + 1 ); - mapping.put( type.getName(), prefix ); - config.get().mapping().set( mapping ); - config.save(); - } - actualClasses.put( type.getName(), type ); - return prefix; - } - - @Override - public String extractName( Identity identity ) - { - String idString = identity.toString(); - int pos = idString.indexOf( SEPARATOR ); - if( pos < 1 ) - { - throw new InvalidIdentityFormatException( idString ); - } - return idString.substring( pos + 1 ); - } - - @Override - public Class extractType( Identity identity ) - { - String idString = identity.toString(); - if( !isIdentity( idString ) ) - { - throw new IllegalArgumentException( "Given argument '" + idString + "' is not an Identity" ); - } - int pos = idString.indexOf( SEPARATOR ); - if( pos < 1 ) - { - throw new InvalidIdentityFormatException( idString ); - } - String prefix = idString.substring( 0, pos ); - Map.Entry<String, String> found = config.get().mapping().get().entrySet().stream() - .filter( new FindClassSpecification( prefix ) ) - .findFirst().orElse( null ); - return found == null ? null : actualClasses.get( found.getKey() ); - } - - private static class FindClassSpecification - implements Predicate<Map.Entry<String, String>> - { - private String prefix; - - private FindClassSpecification( String prefix ) - { - this.prefix = prefix; - } - - @Override - public boolean test( Map.Entry<String, String> item ) - { - return item.getValue().equals( prefix ); - } - } - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/3a26d21d/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/identity/IdentityMappingConfiguration.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/identity/IdentityMappingConfiguration.java b/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/identity/IdentityMappingConfiguration.java deleted file mode 100644 index e30d0ed..0000000 --- a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/identity/IdentityMappingConfiguration.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ - -package org.apache.polygene.library.restlet.identity; - -import java.util.Map; -import org.apache.polygene.api.common.Optional; -import org.apache.polygene.api.common.UseDefaults; -import org.apache.polygene.api.property.Property; - -public interface IdentityMappingConfiguration -{ - @Optional - @UseDefaults - Property<Map<String, String>> mapping(); -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/3a26d21d/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/identity/InvalidIdentityFormatException.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/identity/InvalidIdentityFormatException.java b/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/identity/InvalidIdentityFormatException.java deleted file mode 100644 index 7514304..0000000 --- a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/identity/InvalidIdentityFormatException.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ - -package org.apache.polygene.library.restlet.identity; - -public class InvalidIdentityFormatException extends RuntimeException -{ - public InvalidIdentityFormatException( String identity ) - { - super( "The given reference wasn't generated by the UrlIdentityManager: " + identity ); - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/3a26d21d/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/metainfo/UserIdentity.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/metainfo/UserIdentity.java b/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/metainfo/UserIdentity.java deleted file mode 100644 index 58bcdbc..0000000 --- a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/metainfo/UserIdentity.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ - -package org.apache.polygene.library.restlet.metainfo; - -public class UserIdentity -{ - private final String identifier; - private final String name; - private final String email; - private final String firstName; - private final String lastName; - - public UserIdentity( String identifier, String name, String email, String firstName, String lastName ) - { - this.identifier = identifier; - this.name = name; - this.email = email; - this.firstName = firstName; - this.lastName = lastName; - } - - public String identifier() - { - return identifier; - } - - public String name() - { - return name; - } - - public String email() - { - return email; - } - - public String firstName() - { - return firstName; - } - - public String lastName() - { - return lastName; - } - - -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/3a26d21d/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/repository/EntityName.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/repository/EntityName.java b/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/repository/EntityName.java deleted file mode 100644 index 64dd5db..0000000 --- a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/repository/EntityName.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ - -package org.apache.polygene.library.restlet.repository; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import org.apache.polygene.api.constraint.ConstraintDeclaration; -import org.apache.polygene.api.constraint.Constraints; -import org.apache.polygene.library.restlet.identity.IdentityManager; - -@ConstraintDeclaration -@Retention( RetentionPolicy.RUNTIME ) -@Constraints( EntityName.Constraint.class ) -public @interface EntityName -{ - - class Constraint - implements org.apache.polygene.api.constraint.Constraint<EntityName, String> - { - - @Override - public boolean isValid( EntityName annotation, String value ) - { - int pos = value.indexOf( IdentityManager.SEPARATOR ); - if( pos > 0 ) - { - value = value.substring( pos+1 ); - } - for( int i = 0; i < value.length(); i++ ) - { - char ch = value.charAt( i ); - if( ( ch < 'A' || ch > 'Z' ) && - ( ch < 'a' || ch > 'z' ) && - ( ch < '0' || ch > '9' ) && - ( ch != '.' ) && - ( ch != '_' ) && - ( ch != '-' ) - ) - { - return false; - } - } - return true; - } - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/3a26d21d/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/repository/EntityTypeDescriptor.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/repository/EntityTypeDescriptor.java b/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/repository/EntityTypeDescriptor.java deleted file mode 100644 index 2779b56..0000000 --- a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/repository/EntityTypeDescriptor.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ - -package org.apache.polygene.library.restlet.repository; - -public class EntityTypeDescriptor -{ - private Class entityType; - - public EntityTypeDescriptor( Class entityType ) - { - this.entityType = entityType; - } - - public Class entityType() - { - return entityType; - } - - @Override - public String toString() - { - return "EntityTypeDescriptor{" + entityType + '}'; - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/3a26d21d/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/repository/MissingRepositoryException.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/repository/MissingRepositoryException.java b/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/repository/MissingRepositoryException.java deleted file mode 100644 index 3836ec0..0000000 --- a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/repository/MissingRepositoryException.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ - -package org.apache.polygene.library.restlet.repository; - -public class MissingRepositoryException extends RuntimeException -{ - public MissingRepositoryException( Class typeName ) - { - super( "There is no Entity Repository @Tagged with the name '" + typeName + "'" ); - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/3a26d21d/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/repository/RepositoryLocator.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/repository/RepositoryLocator.java b/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/repository/RepositoryLocator.java deleted file mode 100644 index 09d6b04..0000000 --- a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/repository/RepositoryLocator.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ - -package org.apache.polygene.library.restlet.repository; - -import java.util.HashMap; -import java.util.Map; -import java.util.stream.StreamSupport; -import org.apache.polygene.api.identity.HasIdentity; -import org.apache.polygene.api.injection.scope.Service; -import org.apache.polygene.api.mixin.Mixins; -import org.apache.polygene.api.service.ServiceReference; - -@Mixins( RepositoryLocator.Mixin.class ) -public interface RepositoryLocator -{ - <T extends HasIdentity> CrudRepository<T> find(Class<T> entityType ); - - class Mixin - implements RepositoryLocator - { - - private Map<Class, CrudRepository> repositories = new HashMap<>(); - - public Mixin( @Service Iterable<ServiceReference<CrudRepository>> repositories ) - { - StreamSupport.stream( repositories.spliterator(), true ).forEach( ref -> { - Class type = ref.metaInfo( EntityTypeDescriptor.class ).entityType(); - this.repositories.put( type, ref.get() ); - } ); - } - - @Override - public <T extends HasIdentity> CrudRepository<T> find(Class<T> entityType ) - { - @SuppressWarnings( "unchecked" ) - CrudRepository<T> repository = repositories.get( entityType ); - if( repository == null ) - { - throw new MissingRepositoryException( entityType ); - } - return repository; - } - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/3a26d21d/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/resource/DefaultResourceFactoryImpl.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/resource/DefaultResourceFactoryImpl.java b/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/resource/DefaultResourceFactoryImpl.java deleted file mode 100644 index d1508d3..0000000 --- a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/resource/DefaultResourceFactoryImpl.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ - -package org.apache.polygene.library.restlet.resource; - -import java.util.Map; -import org.apache.polygene.api.identity.HasIdentity; -import org.apache.polygene.api.injection.scope.Structure; -import org.apache.polygene.api.injection.scope.Uses; -import org.apache.polygene.api.property.PropertyDescriptor; -import org.apache.polygene.api.value.ValueBuilder; -import org.apache.polygene.api.value.ValueBuilderFactory; -import org.apache.polygene.spi.PolygeneSPI; -import org.restlet.Context; -import org.restlet.Request; -import org.restlet.Response; -import org.restlet.routing.Router; - -public class DefaultResourceFactoryImpl<K extends HasIdentity, T extends ServerResource<K>> - implements ResourceFactory<K, T> -{ - @Uses - private Class<T> resourceType; - - @Uses - private Context context; - - @Uses - private Router router; - - @Uses - private Request request; - - @Structure - private ValueBuilderFactory vbf; - - @Structure - private PolygeneSPI spi; - - @Override - public T create( Class<T> entityType, Request request, Response response, Context context ) - { - final Map<String, Object> attributes = request.getAttributes(); - String id = (String) attributes.get( "id" ); - - ValueBuilder<T> builder = vbf.newValueBuilderWithState( - resourceType, - descriptor -> findValue( attributes, descriptor ), - descriptor -> null, - descriptor -> null, - descriptor -> null - ); - //noinspection unchecked - ServerResource.Parameters<T> params = builder.prototypeFor( ServerResource.Parameters.class ); - params.id().set( id ); - params.entityType().set( entityType ); - params.context().set( this.context ); - params.request().set( request ); - params.router().set( router ); - params.response().set( response ); - return builder.newInstance(); - } - - private Object findValue( Map<String, Object> attributes, PropertyDescriptor descriptor ) - { - String name = descriptor.qualifiedName().name(); - if( name.equals( "reference" ) ) - { - Object id = attributes.get( "id" ); - if( id == null ) - { - throw new IllegalArgumentException( resourceType.getName() + " implements Identity and must have an {id} attribute in the path template." ); - } - return id; - } - return attributes.get( name ); - } - - @Override - public String toString() - { - return "factory[" + ( resourceType == null ? "<null>" : resourceType.getSimpleName()) + "]"; - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/3a26d21d/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/resource/EntryPoint.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/resource/EntryPoint.java b/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/resource/EntryPoint.java deleted file mode 100644 index 3a74b63..0000000 --- a/libraries/restlet/src/main/java/org/apache/polygene/library/restlet/resource/EntryPoint.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ - -package org.apache.polygene.library.restlet.resource; - -import java.util.Map; -import org.apache.polygene.api.identity.HasIdentity; -import org.apache.polygene.api.property.Property; -import org.apache.polygene.library.restlet.RestLink; - -public interface EntryPoint extends HasIdentity -{ - Property<Map<String,RestLink>> api(); -}