http://git-wip-us.apache.org/repos/asf/zest-java/blob/e0e1d7d4/libraries/appbrowser/src/main/java/org/apache/polygene/library/appbrowser/json/ServiceModelFormatter.java ---------------------------------------------------------------------- diff --git a/libraries/appbrowser/src/main/java/org/apache/polygene/library/appbrowser/json/ServiceModelFormatter.java b/libraries/appbrowser/src/main/java/org/apache/polygene/library/appbrowser/json/ServiceModelFormatter.java new file mode 100644 index 0000000..97a14e9 --- /dev/null +++ b/libraries/appbrowser/src/main/java/org/apache/polygene/library/appbrowser/json/ServiceModelFormatter.java @@ -0,0 +1,61 @@ +/* + * 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.appbrowser.json; + +import org.json.JSONException; +import org.json.JSONWriter; +import org.apache.polygene.api.service.ServiceDescriptor; + +public class ServiceModelFormatter extends AbstractJsonFormatter<ServiceDescriptor, Void> +{ + public ServiceModelFormatter( JSONWriter writer ) + { + super( writer ); + } + + @Override + public void enter( ServiceDescriptor visited ) + throws JSONException + { + object(); + field( "identity", visited.identity() ); + field( "type", visited.primaryType().getName() ); + field( "visibility", visited.visibility().toString() ); + Class<Object> config = visited.configurationType(); + if( config != null ) + { + field( "configuration", config.getName() ); + } + field( "instantiateOnStartup", visited.isInstantiateOnStartup() ); + } + + @Override + public void leave( ServiceDescriptor visited ) + throws JSONException + { + endObject(); + } + + @Override + public void visit( Void visited ) + throws JSONException + { + + } +}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/e0e1d7d4/libraries/appbrowser/src/main/java/org/apache/polygene/library/appbrowser/json/ValueModelFormatter.java ---------------------------------------------------------------------- diff --git a/libraries/appbrowser/src/main/java/org/apache/polygene/library/appbrowser/json/ValueModelFormatter.java b/libraries/appbrowser/src/main/java/org/apache/polygene/library/appbrowser/json/ValueModelFormatter.java new file mode 100644 index 0000000..4d19f4f --- /dev/null +++ b/libraries/appbrowser/src/main/java/org/apache/polygene/library/appbrowser/json/ValueModelFormatter.java @@ -0,0 +1,55 @@ +/* + * 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.appbrowser.json; + +import org.json.JSONException; +import org.json.JSONWriter; +import org.apache.polygene.api.value.ValueDescriptor; +import org.apache.polygene.library.appbrowser.Formatter; + +public class ValueModelFormatter extends AbstractJsonFormatter<ValueDescriptor,Void> +{ + public ValueModelFormatter( JSONWriter writer ) + { + super(writer); + } + + @Override + public void enter( ValueDescriptor visited ) + throws JSONException + { + object(); + field( "type", visited.valueType().mainType().getName() ); + field( "visibility", visited.visibility().toString() ); + } + + @Override + public void leave( ValueDescriptor visited ) + throws JSONException + { + endObject(); + } + + @Override + public void visit( Void visited ) + throws JSONException + { + + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/e0e1d7d4/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/Browser.java ---------------------------------------------------------------------- diff --git a/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/Browser.java b/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/Browser.java deleted file mode 100644 index 29c3d0f..0000000 --- a/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/Browser.java +++ /dev/null @@ -1,109 +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.appbrowser; - -import java.util.Stack; -import org.json.JSONException; -import org.apache.polygene.api.structure.ApplicationDescriptor; -import org.apache.polygene.api.util.HierarchicalVisitor; - -public class Browser -{ - private final ApplicationDescriptor application; - private final FormatterFactory factory; - private final Stack<Formatter> stack = new Stack<>(); - - public Browser( ApplicationDescriptor application, FormatterFactory factory ) - { - this.application = application; - this.factory = factory; - } - - public void toJson() - throws BrowserException - { - application.accept( new HierarchicalVisitor<Object, Object, BrowserException>() - { - @Override - public boolean visitEnter( Object visited ) - throws BrowserException - { - String simpleName = visited.getClass().getSimpleName(); - Formatter formatter = factory.create( simpleName ); - stack.push(formatter); - if( formatter == null ) - { - System.err.println( "Unknown application component: " + visited.getClass() ); - return false; - } - try - { - formatter.enter( visited ); - } - catch( JSONException e ) - { - throw new BrowserException( "Formatting failed.", e ); - } - return true; - } - - @Override - public boolean visitLeave( Object visited ) - throws BrowserException - { - Formatter formatter = stack.pop(); - if( formatter == null ) - { - System.err.println( "Unknown application component: " + visited.getClass() ); - return false; - } - try - { - formatter.leave( visited ); - } - catch( JSONException e ) - { - throw new BrowserException( "Formatting failed.", e ); - } - return true; - } - - @Override - public boolean visit( Object visited ) - throws BrowserException - { - Formatter formatter = stack.peek(); - if( formatter == null ) - { - System.err.println( "Unknown application component: " + visited.getClass() ); - return false; - } - try - { - formatter.visit( visited ); - } - catch( JSONException e ) - { - throw new BrowserException( "Formatting failed.", e ); - } - return true; - } - } ); - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/e0e1d7d4/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/BrowserException.java ---------------------------------------------------------------------- diff --git a/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/BrowserException.java b/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/BrowserException.java deleted file mode 100644 index 126c198..0000000 --- a/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/BrowserException.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.appbrowser; - -import org.json.JSONException; - -public class BrowserException extends RuntimeException -{ - public BrowserException( String message, JSONException exception ) - { - super( message, exception); - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/e0e1d7d4/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/Formatter.java ---------------------------------------------------------------------- diff --git a/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/Formatter.java b/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/Formatter.java deleted file mode 100644 index 19355a7..0000000 --- a/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/Formatter.java +++ /dev/null @@ -1,34 +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.appbrowser; - -import org.json.JSONException; - -public interface Formatter<NODE, LEAF> -{ - - void enter( NODE visited ) - throws JSONException; - - void leave( NODE visited ) - throws JSONException; - - void visit( LEAF visited ) - throws JSONException; -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/e0e1d7d4/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/FormatterFactory.java ---------------------------------------------------------------------- diff --git a/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/FormatterFactory.java b/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/FormatterFactory.java deleted file mode 100644 index d996e2a..0000000 --- a/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/FormatterFactory.java +++ /dev/null @@ -1,25 +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.appbrowser; - -public interface FormatterFactory -{ - - Formatter create( String componentType ); -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/e0e1d7d4/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/AbstractJsonFormatter.java ---------------------------------------------------------------------- diff --git a/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/AbstractJsonFormatter.java b/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/AbstractJsonFormatter.java deleted file mode 100644 index 7682097..0000000 --- a/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/AbstractJsonFormatter.java +++ /dev/null @@ -1,85 +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.appbrowser.json; - -import org.json.JSONException; -import org.json.JSONWriter; -import org.apache.polygene.library.appbrowser.Formatter; - -public abstract class AbstractJsonFormatter<NODE,LEAF> - implements Formatter<NODE, LEAF> -{ - private final JSONWriter writer; - - public AbstractJsonFormatter( JSONWriter writer ) - { - this.writer = writer; - } - - protected void field( String name, String value ) - throws JSONException - { - writer.key( name ).value(value); - } - - protected void field( String name, boolean value ) - throws JSONException - { - writer.key( name ).value(value); - } - - protected void array( String name ) - throws JSONException - { - writer.key(name); - writer.array(); - } - - protected void endArray() - throws JSONException - { - writer.endArray(); - } - - protected void object() - throws JSONException - { - writer.object(); - } - - protected void object(String name) - throws JSONException - { - writer.key(name); - writer.object(); - } - - protected void endObject() - throws JSONException - { - writer.endObject(); - } - - protected void value( Object value ) - throws JSONException - { - writer.value( value ); - } - -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/e0e1d7d4/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/ApplicationModelFormatter.java ---------------------------------------------------------------------- diff --git a/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/ApplicationModelFormatter.java b/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/ApplicationModelFormatter.java deleted file mode 100644 index c862021..0000000 --- a/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/ApplicationModelFormatter.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.appbrowser.json; - -import org.json.JSONException; -import org.json.JSONWriter; -import org.apache.polygene.api.structure.ApplicationDescriptor; -import org.apache.polygene.library.appbrowser.Formatter; - -public class ApplicationModelFormatter extends AbstractJsonFormatter<ApplicationDescriptor, Void> -{ - - public ApplicationModelFormatter( JSONWriter writer ) - { - super( writer ); - } - - @Override - public void enter( ApplicationDescriptor visited ) - throws JSONException - { - object(); - field( "name", visited.name() ); - array("layers"); - } - - @Override - public void leave( ApplicationDescriptor visited ) - throws JSONException - { - endArray(); - endObject(); - } - - @Override - public void visit( Void visited ) - throws JSONException - { - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/e0e1d7d4/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/ArrayFormatter.java ---------------------------------------------------------------------- diff --git a/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/ArrayFormatter.java b/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/ArrayFormatter.java deleted file mode 100644 index 6c315d0..0000000 --- a/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/ArrayFormatter.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.appbrowser.json; - -import org.json.JSONException; -import org.json.JSONWriter; -import org.apache.polygene.library.appbrowser.Formatter; - -public class ArrayFormatter extends AbstractJsonFormatter - implements Formatter -{ - private final String name; - - public ArrayFormatter( JSONWriter writer, String name ) - { - super(writer); - this.name = name; - } - - @Override - public void enter( Object visited ) - throws JSONException - { - array(name); - } - - @Override - public void leave( Object visited ) - throws JSONException - { - endArray(); - } - - @Override - public void visit( Object visited ) - throws JSONException - { - - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/e0e1d7d4/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/CompositeMethodModelFormatter.java ---------------------------------------------------------------------- diff --git a/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/CompositeMethodModelFormatter.java b/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/CompositeMethodModelFormatter.java deleted file mode 100644 index e4328ea..0000000 --- a/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/CompositeMethodModelFormatter.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.polygene.library.appbrowser.json; - -import org.json.JSONException; -import org.json.JSONWriter; -import org.apache.polygene.api.composite.MethodDescriptor; -import org.apache.polygene.library.appbrowser.Formatter; - -public class CompositeMethodModelFormatter extends AbstractJsonFormatter<MethodDescriptor, Void> -{ - public CompositeMethodModelFormatter( JSONWriter writer ) - { - super(writer); - } - - @Override - public void enter( MethodDescriptor visited ) - throws JSONException - { - object(); - field("method", visited.method().getName() ); - } - - @Override - public void leave( MethodDescriptor visited ) - throws JSONException - { - endObject(); - } - - @Override - public void visit( Void visited ) - throws JSONException - { - - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/e0e1d7d4/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/ConstructorModelFormatter.java ---------------------------------------------------------------------- diff --git a/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/ConstructorModelFormatter.java b/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/ConstructorModelFormatter.java deleted file mode 100644 index 8f864dd..0000000 --- a/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/ConstructorModelFormatter.java +++ /dev/null @@ -1,53 +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.appbrowser.json; - -import org.json.JSONException; -import org.json.JSONWriter; -import org.apache.polygene.api.composite.ConstructorDescriptor; - -public class ConstructorModelFormatter extends AbstractJsonFormatter<ConstructorDescriptor,Void> -{ - public ConstructorModelFormatter( JSONWriter writer ) - { - super( writer ); - } - - @Override - public void enter( ConstructorDescriptor visited ) - throws JSONException - { - object(); - field( "name", visited.constructor().getName() ); - } - - @Override - public void leave( ConstructorDescriptor visited ) - throws JSONException - { - endObject(); - } - - @Override - public void visit( Void visited ) - throws JSONException - { - - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/e0e1d7d4/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/EntityModelFormatter.java ---------------------------------------------------------------------- diff --git a/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/EntityModelFormatter.java b/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/EntityModelFormatter.java deleted file mode 100644 index 70d0d9e..0000000 --- a/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/EntityModelFormatter.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.appbrowser.json; - -import org.json.JSONException; -import org.json.JSONWriter; -import org.apache.polygene.api.entity.EntityDescriptor; - -public class EntityModelFormatter extends AbstractJsonFormatter<EntityDescriptor, Void> -{ - - public EntityModelFormatter( JSONWriter writer ) - { - super( writer ); - } - - @Override - public void enter( EntityDescriptor visited ) - throws JSONException - { - object(); - field( "type", visited.primaryType().getName() ); - field( "visibility", visited.visibility().toString() ); - field( "queryable", visited.queryable() ); - } - - @Override - public void leave( EntityDescriptor visited ) - throws JSONException - { - endObject(); - } - - @Override - public void visit( Void visited ) - throws JSONException - { - - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/e0e1d7d4/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/InjectedFieldModelFormatter.java ---------------------------------------------------------------------- diff --git a/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/InjectedFieldModelFormatter.java b/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/InjectedFieldModelFormatter.java deleted file mode 100644 index 75a216e..0000000 --- a/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/InjectedFieldModelFormatter.java +++ /dev/null @@ -1,60 +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.appbrowser.json; - -import org.json.JSONException; -import org.json.JSONWriter; -import org.apache.polygene.api.composite.DependencyDescriptor; -import org.apache.polygene.api.composite.InjectedFieldDescriptor; -import org.apache.polygene.library.appbrowser.Formatter; - -public class InjectedFieldModelFormatter extends AbstractJsonFormatter<InjectedFieldDescriptor, DependencyDescriptor> -{ - public InjectedFieldModelFormatter( JSONWriter writer ) - { - super(writer); - } - - @Override - public void enter( InjectedFieldDescriptor visited ) - throws JSONException - { - object(); - field("name", visited.field().getName() ); -// field( "optional", visited.optional() ); -// field( "injectedclass", visited.injectedClass().getName() ); -// field( "injectedannotation", visited.injectionAnnotation().toString() ); -// field( "injectedtype", visited.injectionType().toString() ); -// field( "rawinjectectiontype", visited.rawInjectionType().getName() ); - } - - @Override - public void leave( InjectedFieldDescriptor visited ) - throws JSONException - { - endObject(); - } - - @Override - public void visit( DependencyDescriptor visited ) - throws JSONException - { - - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/e0e1d7d4/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/JsonFormatterFactory.java ---------------------------------------------------------------------- diff --git a/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/JsonFormatterFactory.java b/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/JsonFormatterFactory.java deleted file mode 100644 index 5c7748a..0000000 --- a/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/JsonFormatterFactory.java +++ /dev/null @@ -1,107 +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.appbrowser.json; - -import java.io.Writer; -import org.json.JSONWriter; -import org.apache.polygene.library.appbrowser.Formatter; -import org.apache.polygene.library.appbrowser.FormatterFactory; - -public class JsonFormatterFactory - implements FormatterFactory -{ - private static final NullFormatter NULL_FORMATTER = new NullFormatter(); - private final JSONWriter writer; - - public JsonFormatterFactory(Writer destination) - { - writer = new JSONWriter( destination ); - } - - @Override - public Formatter create( String componentType ) - { - if( componentType.equalsIgnoreCase( "ApplicationModel" )) - return new ApplicationModelFormatter( writer ); - if( componentType.equalsIgnoreCase( "LayerModel" )) - return new LayerModelFormatter( writer ); - if( componentType.equalsIgnoreCase( "ModuleModel" )) - return new ModuleModelFormatter( writer ); - if( componentType.equalsIgnoreCase( "TransientsModel" )) - return new ArrayFormatter(writer, "transients"); - if( componentType.equalsIgnoreCase( "EntitiesModel" )) - return new ArrayFormatter(writer, "entities"); - if( componentType.equalsIgnoreCase( "ServicesModel" )) - return new ArrayFormatter(writer, "services"); - if( componentType.equalsIgnoreCase( "ServiceModel" )) - return new ServiceModelFormatter - (writer); - if( componentType.equalsIgnoreCase( "ValuesModel" )) - return new ArrayFormatter(writer, "values"); - if( componentType.equalsIgnoreCase( "ValueModel" )) - return new ValueModelFormatter(writer); - if( componentType.equalsIgnoreCase( "ValueStateModel" )) - return NULL_FORMATTER; - if( componentType.equalsIgnoreCase( "EntityModel" )) - return new EntityModelFormatter( writer ); - if( componentType.equalsIgnoreCase( "CompositeMethodsModel" )) - return new ArrayFormatter( writer, "methods" ); - if( componentType.equalsIgnoreCase( "CompositeMethodModel" )) - return new CompositeMethodModelFormatter(writer); - if( componentType.equalsIgnoreCase( "ObjectsModel" )) - return new ArrayFormatter( writer, "objects" ); - if( componentType.equalsIgnoreCase( "ConstraintsModel" )) - return new ArrayFormatter( writer, "constraints" ); - if( componentType.equalsIgnoreCase( "SideEffectsModel" )) - return new ArrayFormatter( writer, "sideeffects" ); - if( componentType.equalsIgnoreCase( "ConcernsModel" )) - return new ArrayFormatter( writer, "concerns" ); - if( componentType.equalsIgnoreCase( "PropertiesModel" )) - return new ArrayFormatter( writer, "properties" ); - if( componentType.equalsIgnoreCase( "ConstructorsModel" )) - return new ArrayFormatter( writer, "constructors" ); - if( componentType.equalsIgnoreCase( "ConstructorModel" )) - return new ConstructorModelFormatter( writer ); - if( componentType.equalsIgnoreCase( "EntityMixinsModel" )) - return new ArrayFormatter( writer, "mixins" ); - if( componentType.equalsIgnoreCase( "MixinsModel" )) - return new ArrayFormatter( writer, "mixins" ); - if( componentType.equalsIgnoreCase( "MixinModel" )) - return new MixinModelFormatter( writer ); - if( componentType.equalsIgnoreCase( "AssociationsModel" )) - return new ArrayFormatter( writer, "associations" ); - if( componentType.equalsIgnoreCase( "ManyAssociationsModel" )) - return new ArrayFormatter( writer, "manyassociations" ); - if( componentType.equalsIgnoreCase( "InjectedFieldsModel" )) - return new ArrayFormatter( writer, "injectedfields" ); - if( componentType.equalsIgnoreCase( "InjectedFieldModel" )) - return new InjectedFieldModelFormatter(writer); - if( componentType.equalsIgnoreCase( "InjectedMethodsModel" )) - return new ArrayFormatter( writer, "injectedmethods" ); - if( componentType.equalsIgnoreCase( "InjectedParametersModel" )) - return new ArrayFormatter( writer, "injectedparameters" ); - if( componentType.equalsIgnoreCase( "EntityStateModel" )) - return NULL_FORMATTER; - if( componentType.equalsIgnoreCase( "ObjectModel" )) - return new ObjectModelFormatter(writer); - if( componentType.equalsIgnoreCase( "ImportedServicesModel" )) - return NULL_FORMATTER; - return null; - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/e0e1d7d4/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/LayerModelFormatter.java ---------------------------------------------------------------------- diff --git a/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/LayerModelFormatter.java b/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/LayerModelFormatter.java deleted file mode 100644 index f55c475..0000000 --- a/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/LayerModelFormatter.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.appbrowser.json; - -import org.json.JSONException; -import org.json.JSONWriter; -import org.apache.polygene.api.structure.LayerDescriptor; -import org.apache.polygene.api.structure.UsedLayersDescriptor; - -public class LayerModelFormatter extends AbstractJsonFormatter<LayerDescriptor, Void> -{ - public LayerModelFormatter( JSONWriter writer ) - { - super( writer ); - } - - @Override - public void enter( LayerDescriptor visited ) - throws JSONException - { - object(); - field( "name", visited.name() ); - array( "uses" ); - UsedLayersDescriptor usedLayersDescriptor = visited.usedLayers(); - for( LayerDescriptor used : usedLayersDescriptor.layers() ) - { - value( used.name() ); - } - endArray(); - array( "modules" ); - } - - @Override - public void leave( LayerDescriptor visited ) - throws JSONException - { - endArray(); - endObject(); - } - - @Override - public void visit( Void visited ) - throws JSONException - { - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/e0e1d7d4/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/MixinModelFormatter.java ---------------------------------------------------------------------- diff --git a/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/MixinModelFormatter.java b/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/MixinModelFormatter.java deleted file mode 100644 index 3254e58..0000000 --- a/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/MixinModelFormatter.java +++ /dev/null @@ -1,53 +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.appbrowser.json; - -import org.json.JSONException; -import org.json.JSONWriter; -import org.apache.polygene.api.mixin.MixinDescriptor; - -public class MixinModelFormatter extends AbstractJsonFormatter<MixinDescriptor, Void> -{ - public MixinModelFormatter( JSONWriter writer ) - { - super( writer ); - } - - @Override - public void enter( MixinDescriptor visited ) - throws JSONException - { - object(); - field( "mixin", visited.mixinClass().getName() ); - } - - @Override - public void leave( MixinDescriptor visited ) - throws JSONException - { - endObject(); - } - - @Override - public void visit( Void visited ) - throws JSONException - { - - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/e0e1d7d4/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/ModuleModelFormatter.java ---------------------------------------------------------------------- diff --git a/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/ModuleModelFormatter.java b/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/ModuleModelFormatter.java deleted file mode 100644 index 1ea5c34..0000000 --- a/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/ModuleModelFormatter.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.polygene.library.appbrowser.json; - -import org.json.JSONException; -import org.json.JSONWriter; -import org.apache.polygene.api.structure.ModuleDescriptor; -import org.apache.polygene.library.appbrowser.Formatter; - -public class ModuleModelFormatter extends AbstractJsonFormatter<ModuleDescriptor, Void> -{ - - public ModuleModelFormatter( JSONWriter writer ) - { - super( writer ); - } - - @Override - public void enter( ModuleDescriptor visited ) - throws JSONException - { - object(); - field( "name", visited.name() ); - } - - @Override - public void leave( ModuleDescriptor visited ) - throws JSONException - { - endObject(); - } - - @Override - public void visit( Void visited ) - throws JSONException - { - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/e0e1d7d4/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/NullFormatter.java ---------------------------------------------------------------------- diff --git a/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/NullFormatter.java b/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/NullFormatter.java deleted file mode 100644 index 6cb3e59..0000000 --- a/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/NullFormatter.java +++ /dev/null @@ -1,48 +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.appbrowser.json; - -import org.json.JSONException; -import org.json.JSONWriter; -import org.apache.polygene.library.appbrowser.Formatter; - -public class NullFormatter - implements Formatter<Object, Object> -{ - @Override - public void enter( Object visited ) - throws JSONException - { - - } - - @Override - public void leave( Object visited ) - throws JSONException - { - - } - - @Override - public void visit( Object visited ) - throws JSONException - { - - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/e0e1d7d4/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/ObjectModelFormatter.java ---------------------------------------------------------------------- diff --git a/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/ObjectModelFormatter.java b/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/ObjectModelFormatter.java deleted file mode 100644 index 959edad..0000000 --- a/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/ObjectModelFormatter.java +++ /dev/null @@ -1,53 +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.appbrowser.json; - -import org.json.JSONException; -import org.json.JSONWriter; -import org.apache.polygene.api.object.ObjectDescriptor; - -public class ObjectModelFormatter extends AbstractJsonFormatter<ObjectDescriptor, Void> -{ - public ObjectModelFormatter( JSONWriter writer ) - { - super(writer); - } - - @Override - public void enter( ObjectDescriptor visited ) - throws JSONException - { - object(); - field( "visibility", visited.visibility().toString()); - } - - @Override - public void leave( ObjectDescriptor visited ) - throws JSONException - { - endObject(); - } - - @Override - public void visit( Void visited ) - throws JSONException - { - - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/e0e1d7d4/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/ServiceModelFormatter.java ---------------------------------------------------------------------- diff --git a/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/ServiceModelFormatter.java b/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/ServiceModelFormatter.java deleted file mode 100644 index 97a14e9..0000000 --- a/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/ServiceModelFormatter.java +++ /dev/null @@ -1,61 +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.appbrowser.json; - -import org.json.JSONException; -import org.json.JSONWriter; -import org.apache.polygene.api.service.ServiceDescriptor; - -public class ServiceModelFormatter extends AbstractJsonFormatter<ServiceDescriptor, Void> -{ - public ServiceModelFormatter( JSONWriter writer ) - { - super( writer ); - } - - @Override - public void enter( ServiceDescriptor visited ) - throws JSONException - { - object(); - field( "identity", visited.identity() ); - field( "type", visited.primaryType().getName() ); - field( "visibility", visited.visibility().toString() ); - Class<Object> config = visited.configurationType(); - if( config != null ) - { - field( "configuration", config.getName() ); - } - field( "instantiateOnStartup", visited.isInstantiateOnStartup() ); - } - - @Override - public void leave( ServiceDescriptor visited ) - throws JSONException - { - endObject(); - } - - @Override - public void visit( Void visited ) - throws JSONException - { - - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/e0e1d7d4/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/ValueModelFormatter.java ---------------------------------------------------------------------- diff --git a/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/ValueModelFormatter.java b/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/ValueModelFormatter.java deleted file mode 100644 index 4d19f4f..0000000 --- a/libraries/appbrowser/src/main/java/org/apache/zest/library/appbrowser/json/ValueModelFormatter.java +++ /dev/null @@ -1,55 +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.appbrowser.json; - -import org.json.JSONException; -import org.json.JSONWriter; -import org.apache.polygene.api.value.ValueDescriptor; -import org.apache.polygene.library.appbrowser.Formatter; - -public class ValueModelFormatter extends AbstractJsonFormatter<ValueDescriptor,Void> -{ - public ValueModelFormatter( JSONWriter writer ) - { - super(writer); - } - - @Override - public void enter( ValueDescriptor visited ) - throws JSONException - { - object(); - field( "type", visited.valueType().mainType().getName() ); - field( "visibility", visited.visibility().toString() ); - } - - @Override - public void leave( ValueDescriptor visited ) - throws JSONException - { - endObject(); - } - - @Override - public void visit( Void visited ) - throws JSONException - { - - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/e0e1d7d4/libraries/appbrowser/src/test/java/org/apache/polygene/library/appbrowser/AppBrowserTest.java ---------------------------------------------------------------------- diff --git a/libraries/appbrowser/src/test/java/org/apache/polygene/library/appbrowser/AppBrowserTest.java b/libraries/appbrowser/src/test/java/org/apache/polygene/library/appbrowser/AppBrowserTest.java new file mode 100644 index 0000000..4a4ffc2 --- /dev/null +++ b/libraries/appbrowser/src/test/java/org/apache/polygene/library/appbrowser/AppBrowserTest.java @@ -0,0 +1,167 @@ +/* + * 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.appbrowser; + +import java.io.StringWriter; +import java.io.Writer; +import org.junit.Test; +import org.apache.polygene.api.association.Association; +import org.apache.polygene.api.association.ManyAssociation; +import org.apache.polygene.api.common.Optional; +import org.apache.polygene.api.concern.ConcernOf; +import org.apache.polygene.api.concern.Concerns; +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; +import org.apache.polygene.api.property.Property; +import org.apache.polygene.api.value.ValueSerialization; +import org.apache.polygene.bootstrap.AssemblyException; +import org.apache.polygene.bootstrap.ModuleAssembly; +import org.apache.polygene.entitystore.memory.MemoryEntityStoreService; +import org.apache.polygene.library.appbrowser.json.JsonFormatterFactory; +import org.apache.polygene.test.AbstractPolygeneTest; + +public class AppBrowserTest extends AbstractPolygeneTest +{ + @Override + public void assemble( ModuleAssembly module ) + throws AssemblyException + { + module.entities( Person.class ); + module.values( Age.class ); + module.services( MemoryEntityStoreService.class ); + module.importedServices( ValueSerialization.class ); + } + + @Test + public void testBrowser() + throws Exception + { + Writer output = new StringWriter(); + FormatterFactory jsonFactory = new JsonFormatterFactory( output ); + Browser browser = new Browser( applicationModel, jsonFactory ); + browser.toJson(); + } + + @Mixins( Person.Mixin.class ) + @Concerns( Person.AgeLimitConcern.class ) + public interface Person extends HasIdentity + { + String name(); + + int yearsOld(); + + interface State + { + Property<String> name(); + + Property<Age> age(); + + @Optional + Association<Person> spouse(); + + ManyAssociation<Person> children(); + } + + abstract class Mixin + implements Person + { + + @This + private State state; + + @Override + public String name() + { + return state.name().get(); + } + + @Override + public int yearsOld() + { + return state.age().get().numberOfYearsOld(); + } + } + + abstract class AgeLimitConcern extends ConcernOf<Person> + implements Person + { + @This + private Person me; + @Service + private AgeCheckService ageCheck; + + @Override + public int yearsOld() + { + int years = next.yearsOld(); + if( ageCheck.checkAge( identity(), years )) + throw new DeathException( "Person is dead."); + return 0; + } + } + } + + @Mixins( Age.AgeMixin.class ) + public interface Age + { + Property<Integer> birthYear(); + + int numberOfYearsOld(); + + abstract class AgeMixin + implements Age + { + + @Override + public int numberOfYearsOld() + { + return DateTime.now().getYearOfEra() - birthYear().get(); + } + } + } + + public static class DeathException extends RuntimeException + { + public DeathException( String message ) + { + super( message ); + } + } + + @Mixins(AgeCheckService.AgeCheckerMixin.class) + public interface AgeCheckService + { + + boolean checkAge( Property<Identity> identity, int years ); + + class AgeCheckerMixin + implements AgeCheckService + { + + @Override + public boolean checkAge( Property<Identity> identity, int years ) + { + double probabiility = years/(Math.random()*120+1); + return probabiility < 0.9; + } + } + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/e0e1d7d4/libraries/appbrowser/src/test/java/org/apache/zest/library/appbrowser/AppBrowserTest.java ---------------------------------------------------------------------- diff --git a/libraries/appbrowser/src/test/java/org/apache/zest/library/appbrowser/AppBrowserTest.java b/libraries/appbrowser/src/test/java/org/apache/zest/library/appbrowser/AppBrowserTest.java deleted file mode 100644 index 4a4ffc2..0000000 --- a/libraries/appbrowser/src/test/java/org/apache/zest/library/appbrowser/AppBrowserTest.java +++ /dev/null @@ -1,167 +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.appbrowser; - -import java.io.StringWriter; -import java.io.Writer; -import org.junit.Test; -import org.apache.polygene.api.association.Association; -import org.apache.polygene.api.association.ManyAssociation; -import org.apache.polygene.api.common.Optional; -import org.apache.polygene.api.concern.ConcernOf; -import org.apache.polygene.api.concern.Concerns; -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; -import org.apache.polygene.api.property.Property; -import org.apache.polygene.api.value.ValueSerialization; -import org.apache.polygene.bootstrap.AssemblyException; -import org.apache.polygene.bootstrap.ModuleAssembly; -import org.apache.polygene.entitystore.memory.MemoryEntityStoreService; -import org.apache.polygene.library.appbrowser.json.JsonFormatterFactory; -import org.apache.polygene.test.AbstractPolygeneTest; - -public class AppBrowserTest extends AbstractPolygeneTest -{ - @Override - public void assemble( ModuleAssembly module ) - throws AssemblyException - { - module.entities( Person.class ); - module.values( Age.class ); - module.services( MemoryEntityStoreService.class ); - module.importedServices( ValueSerialization.class ); - } - - @Test - public void testBrowser() - throws Exception - { - Writer output = new StringWriter(); - FormatterFactory jsonFactory = new JsonFormatterFactory( output ); - Browser browser = new Browser( applicationModel, jsonFactory ); - browser.toJson(); - } - - @Mixins( Person.Mixin.class ) - @Concerns( Person.AgeLimitConcern.class ) - public interface Person extends HasIdentity - { - String name(); - - int yearsOld(); - - interface State - { - Property<String> name(); - - Property<Age> age(); - - @Optional - Association<Person> spouse(); - - ManyAssociation<Person> children(); - } - - abstract class Mixin - implements Person - { - - @This - private State state; - - @Override - public String name() - { - return state.name().get(); - } - - @Override - public int yearsOld() - { - return state.age().get().numberOfYearsOld(); - } - } - - abstract class AgeLimitConcern extends ConcernOf<Person> - implements Person - { - @This - private Person me; - @Service - private AgeCheckService ageCheck; - - @Override - public int yearsOld() - { - int years = next.yearsOld(); - if( ageCheck.checkAge( identity(), years )) - throw new DeathException( "Person is dead."); - return 0; - } - } - } - - @Mixins( Age.AgeMixin.class ) - public interface Age - { - Property<Integer> birthYear(); - - int numberOfYearsOld(); - - abstract class AgeMixin - implements Age - { - - @Override - public int numberOfYearsOld() - { - return DateTime.now().getYearOfEra() - birthYear().get(); - } - } - } - - public static class DeathException extends RuntimeException - { - public DeathException( String message ) - { - super( message ); - } - } - - @Mixins(AgeCheckService.AgeCheckerMixin.class) - public interface AgeCheckService - { - - boolean checkAge( Property<Identity> identity, int years ); - - class AgeCheckerMixin - implements AgeCheckService - { - - @Override - public boolean checkAge( Property<Identity> identity, int years ) - { - double probabiility = years/(Math.random()*120+1); - return probabiility < 0.9; - } - } - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/e0e1d7d4/libraries/http/src/vhost-test/java/org/apache/polygene/library/http/VirtualHostJettyServiceTest.java ---------------------------------------------------------------------- diff --git a/libraries/http/src/vhost-test/java/org/apache/polygene/library/http/VirtualHostJettyServiceTest.java b/libraries/http/src/vhost-test/java/org/apache/polygene/library/http/VirtualHostJettyServiceTest.java new file mode 100644 index 0000000..88afe0e --- /dev/null +++ b/libraries/http/src/vhost-test/java/org/apache/polygene/library/http/VirtualHostJettyServiceTest.java @@ -0,0 +1,91 @@ +/* + * 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.http; + +import java.io.IOException; +import org.apache.http.client.methods.HttpGet; +import org.apache.polygene.api.common.Visibility; +import org.apache.polygene.bootstrap.AssemblyException; +import org.apache.polygene.bootstrap.ModuleAssembly; +import org.apache.polygene.library.http.dns.LocalManagedDns; +import org.apache.polygene.test.EntityTestAssembler; +import org.apache.polygene.test.util.FreePortFinder; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import static org.apache.polygene.library.http.Servlets.addServlets; +import static org.apache.polygene.library.http.Servlets.serve; +import static org.apache.polygene.test.util.Assume.assumeNoIbmJdk; +import static org.junit.Assert.assertEquals; + +public class VirtualHostJettyServiceTest + extends AbstractJettyTest +{ + private static final String HOST1 = "host1.http.library.polygene"; + private static final String HOST2 = "host2.http.library.polygene"; + + private final int httpPort = FreePortFinder.findFreePortOnLoopback(); + + @BeforeClass + public static void beforeVirtualHostsClass() + { + assumeNoIbmJdk(); + LocalManagedDns.putName( HOST1, "127.0.0.1" ); + LocalManagedDns.putName( HOST2, "127.0.0.1" ); + } + + @AfterClass + public static void afterVirtualHostsClass() + { + LocalManagedDns.removeName( HOST1 ); + LocalManagedDns.removeName( HOST2 ); + } + + @Override + public void assemble( ModuleAssembly module ) + throws AssemblyException + { + ModuleAssembly configModule = module; + new EntityTestAssembler().assemble( configModule ); + new JettyServiceAssembler().withConfig( configModule, Visibility.layer ).assemble( module ); + + SecureJettyConfiguration config = configModule.forMixin( SecureJettyConfiguration.class ).declareDefaults(); + config.hostName().set( "127.0.0.1" ); + config.port().set( httpPort ); + config.virtualHosts().set( HOST1 + "," + HOST2 ); + + addServlets( serve( "/hello" ).with( HelloWorldServletService.class ) ).to( module ); + } + + @Test + public void test() + throws IOException + { + // Available on HOST1 and HOST2 + String output = defaultHttpClient.execute( new HttpGet( "http://" + HOST1 + ":" + httpPort + "/hello" ), + stringResponseHandler ); + assertEquals( "Hello World", output ); + + output = defaultHttpClient.execute( new HttpGet( "http://" + HOST2 + ":" + httpPort + "/hello" ), + stringResponseHandler ); + assertEquals( "Hello World", output ); + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/e0e1d7d4/libraries/http/src/vhost-test/java/org/apache/polygene/library/http/dns/LocalManagedDns.java ---------------------------------------------------------------------- diff --git a/libraries/http/src/vhost-test/java/org/apache/polygene/library/http/dns/LocalManagedDns.java b/libraries/http/src/vhost-test/java/org/apache/polygene/library/http/dns/LocalManagedDns.java new file mode 100644 index 0000000..065c35a --- /dev/null +++ b/libraries/http/src/vhost-test/java/org/apache/polygene/library/http/dns/LocalManagedDns.java @@ -0,0 +1,125 @@ +/* + * 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.http.dns; + +import java.net.Inet4Address; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import org.xbill.DNS.spi.DNSJavaNameServiceDescriptor; +import sun.net.spi.nameservice.NameService; + +public class LocalManagedDns + implements NameService +{ + + private static final NameService DEFAULT_DNS = new DNSJavaNameServiceDescriptor().createNameService(); + private static final Map<String, String> NAMES = new ConcurrentHashMap<String, String>(); + + public static void clearNames() + { + NAMES.clear(); + } + + public static String putName( String name, String ip ) + { + return NAMES.put( name, ip ); + } + + public static String removeName( String name ) + { + return NAMES.remove( name ); + } + + public String getHostByAddr( byte[] bytes ) + throws UnknownHostException + { + return DEFAULT_DNS.getHostByAddr( bytes ); + } + + public InetAddress[] lookupAllHostAddr( String name ) + throws UnknownHostException + { + String log = "[CDNS] Lookup request"; + String ip = NAMES.get( name ); + InetAddress[] result = new InetAddress[ 0 ]; + if ( ip != null && ip.length() > 0 ) { + log += " on managed name (" + name + ")"; + byte[] ipBytes = ipStringToBytes( ip ); + result = new InetAddress[]{ Inet4Address.getByAddress( ipBytes ) }; + } else { + log += " on non-managed name (" + name + ")"; + result = DEFAULT_DNS.lookupAllHostAddr( name ); + } + return result; + } + + private static byte[] ipStringToBytes( String ipString ) + { + if ( ipString == null || ipString.length() == 0 ) { + return null; + } + + int inetAddrSize = 4; + int octets; + char ch; + byte[] dst = new byte[ inetAddrSize ]; + char[] srcb = ipString.toCharArray(); + boolean saw_digit = false; + + octets = 0; + int i = 0; + int cur = 0; + while ( i < srcb.length ) { + ch = srcb[i++]; + if ( Character.isDigit( ch ) ) { + int sum = dst[cur] * 10 + ( Character.digit( ch, 10 ) & 0xff ); + + if ( sum > 255 ) { + return null; + } + + dst[cur] = ( byte ) ( sum & 0xff ); + if ( !saw_digit ) { + if ( ++octets > inetAddrSize ) { + return null; + } + saw_digit = true; + } + } else if ( ch == '.' && saw_digit ) { + if ( octets == inetAddrSize ) { + return null; + } + cur++; + dst[cur] = 0; + saw_digit = false; + } else { + return null; + } + } + + if ( octets < inetAddrSize ) { + return null; + } + return dst; + } + +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/e0e1d7d4/libraries/http/src/vhost-test/java/org/apache/polygene/library/http/dns/LocalManagedDnsDescriptor.java ---------------------------------------------------------------------- diff --git a/libraries/http/src/vhost-test/java/org/apache/polygene/library/http/dns/LocalManagedDnsDescriptor.java b/libraries/http/src/vhost-test/java/org/apache/polygene/library/http/dns/LocalManagedDnsDescriptor.java new file mode 100644 index 0000000..91af739 --- /dev/null +++ b/libraries/http/src/vhost-test/java/org/apache/polygene/library/http/dns/LocalManagedDnsDescriptor.java @@ -0,0 +1,48 @@ +/* + * 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.http.dns; + +import sun.net.spi.nameservice.NameService; +import sun.net.spi.nameservice.NameServiceDescriptor; + +public class LocalManagedDnsDescriptor + implements NameServiceDescriptor +{ + + public static final String PROVIDER_NAME = "LocalManagedDns"; + private static final NameService nameService = new LocalManagedDns(); + + public NameService createNameService() + throws Exception + { + return nameService; + } + + public String getProviderName() + { + return PROVIDER_NAME; + } + + public String getType() + { + return "dns"; + } + +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/e0e1d7d4/libraries/http/src/vhost-test/java/org/apache/zest/library/http/VirtualHostJettyServiceTest.java ---------------------------------------------------------------------- diff --git a/libraries/http/src/vhost-test/java/org/apache/zest/library/http/VirtualHostJettyServiceTest.java b/libraries/http/src/vhost-test/java/org/apache/zest/library/http/VirtualHostJettyServiceTest.java deleted file mode 100644 index 88afe0e..0000000 --- a/libraries/http/src/vhost-test/java/org/apache/zest/library/http/VirtualHostJettyServiceTest.java +++ /dev/null @@ -1,91 +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.http; - -import java.io.IOException; -import org.apache.http.client.methods.HttpGet; -import org.apache.polygene.api.common.Visibility; -import org.apache.polygene.bootstrap.AssemblyException; -import org.apache.polygene.bootstrap.ModuleAssembly; -import org.apache.polygene.library.http.dns.LocalManagedDns; -import org.apache.polygene.test.EntityTestAssembler; -import org.apache.polygene.test.util.FreePortFinder; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; - -import static org.apache.polygene.library.http.Servlets.addServlets; -import static org.apache.polygene.library.http.Servlets.serve; -import static org.apache.polygene.test.util.Assume.assumeNoIbmJdk; -import static org.junit.Assert.assertEquals; - -public class VirtualHostJettyServiceTest - extends AbstractJettyTest -{ - private static final String HOST1 = "host1.http.library.polygene"; - private static final String HOST2 = "host2.http.library.polygene"; - - private final int httpPort = FreePortFinder.findFreePortOnLoopback(); - - @BeforeClass - public static void beforeVirtualHostsClass() - { - assumeNoIbmJdk(); - LocalManagedDns.putName( HOST1, "127.0.0.1" ); - LocalManagedDns.putName( HOST2, "127.0.0.1" ); - } - - @AfterClass - public static void afterVirtualHostsClass() - { - LocalManagedDns.removeName( HOST1 ); - LocalManagedDns.removeName( HOST2 ); - } - - @Override - public void assemble( ModuleAssembly module ) - throws AssemblyException - { - ModuleAssembly configModule = module; - new EntityTestAssembler().assemble( configModule ); - new JettyServiceAssembler().withConfig( configModule, Visibility.layer ).assemble( module ); - - SecureJettyConfiguration config = configModule.forMixin( SecureJettyConfiguration.class ).declareDefaults(); - config.hostName().set( "127.0.0.1" ); - config.port().set( httpPort ); - config.virtualHosts().set( HOST1 + "," + HOST2 ); - - addServlets( serve( "/hello" ).with( HelloWorldServletService.class ) ).to( module ); - } - - @Test - public void test() - throws IOException - { - // Available on HOST1 and HOST2 - String output = defaultHttpClient.execute( new HttpGet( "http://" + HOST1 + ":" + httpPort + "/hello" ), - stringResponseHandler ); - assertEquals( "Hello World", output ); - - output = defaultHttpClient.execute( new HttpGet( "http://" + HOST2 + ":" + httpPort + "/hello" ), - stringResponseHandler ); - assertEquals( "Hello World", output ); - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/e0e1d7d4/libraries/http/src/vhost-test/java/org/apache/zest/library/http/dns/LocalManagedDns.java ---------------------------------------------------------------------- diff --git a/libraries/http/src/vhost-test/java/org/apache/zest/library/http/dns/LocalManagedDns.java b/libraries/http/src/vhost-test/java/org/apache/zest/library/http/dns/LocalManagedDns.java deleted file mode 100644 index 065c35a..0000000 --- a/libraries/http/src/vhost-test/java/org/apache/zest/library/http/dns/LocalManagedDns.java +++ /dev/null @@ -1,125 +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.http.dns; - -import java.net.Inet4Address; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import org.xbill.DNS.spi.DNSJavaNameServiceDescriptor; -import sun.net.spi.nameservice.NameService; - -public class LocalManagedDns - implements NameService -{ - - private static final NameService DEFAULT_DNS = new DNSJavaNameServiceDescriptor().createNameService(); - private static final Map<String, String> NAMES = new ConcurrentHashMap<String, String>(); - - public static void clearNames() - { - NAMES.clear(); - } - - public static String putName( String name, String ip ) - { - return NAMES.put( name, ip ); - } - - public static String removeName( String name ) - { - return NAMES.remove( name ); - } - - public String getHostByAddr( byte[] bytes ) - throws UnknownHostException - { - return DEFAULT_DNS.getHostByAddr( bytes ); - } - - public InetAddress[] lookupAllHostAddr( String name ) - throws UnknownHostException - { - String log = "[CDNS] Lookup request"; - String ip = NAMES.get( name ); - InetAddress[] result = new InetAddress[ 0 ]; - if ( ip != null && ip.length() > 0 ) { - log += " on managed name (" + name + ")"; - byte[] ipBytes = ipStringToBytes( ip ); - result = new InetAddress[]{ Inet4Address.getByAddress( ipBytes ) }; - } else { - log += " on non-managed name (" + name + ")"; - result = DEFAULT_DNS.lookupAllHostAddr( name ); - } - return result; - } - - private static byte[] ipStringToBytes( String ipString ) - { - if ( ipString == null || ipString.length() == 0 ) { - return null; - } - - int inetAddrSize = 4; - int octets; - char ch; - byte[] dst = new byte[ inetAddrSize ]; - char[] srcb = ipString.toCharArray(); - boolean saw_digit = false; - - octets = 0; - int i = 0; - int cur = 0; - while ( i < srcb.length ) { - ch = srcb[i++]; - if ( Character.isDigit( ch ) ) { - int sum = dst[cur] * 10 + ( Character.digit( ch, 10 ) & 0xff ); - - if ( sum > 255 ) { - return null; - } - - dst[cur] = ( byte ) ( sum & 0xff ); - if ( !saw_digit ) { - if ( ++octets > inetAddrSize ) { - return null; - } - saw_digit = true; - } - } else if ( ch == '.' && saw_digit ) { - if ( octets == inetAddrSize ) { - return null; - } - cur++; - dst[cur] = 0; - saw_digit = false; - } else { - return null; - } - } - - if ( octets < inetAddrSize ) { - return null; - } - return dst; - } - -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/e0e1d7d4/libraries/http/src/vhost-test/java/org/apache/zest/library/http/dns/LocalManagedDnsDescriptor.java ---------------------------------------------------------------------- diff --git a/libraries/http/src/vhost-test/java/org/apache/zest/library/http/dns/LocalManagedDnsDescriptor.java b/libraries/http/src/vhost-test/java/org/apache/zest/library/http/dns/LocalManagedDnsDescriptor.java deleted file mode 100644 index 91af739..0000000 --- a/libraries/http/src/vhost-test/java/org/apache/zest/library/http/dns/LocalManagedDnsDescriptor.java +++ /dev/null @@ -1,48 +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.http.dns; - -import sun.net.spi.nameservice.NameService; -import sun.net.spi.nameservice.NameServiceDescriptor; - -public class LocalManagedDnsDescriptor - implements NameServiceDescriptor -{ - - public static final String PROVIDER_NAME = "LocalManagedDns"; - private static final NameService nameService = new LocalManagedDns(); - - public NameService createNameService() - throws Exception - { - return nameService; - } - - public String getProviderName() - { - return PROVIDER_NAME; - } - - public String getType() - { - return "dns"; - } - -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/e0e1d7d4/libraries/http/src/vhost-test/resources/META-INF/services/sun.net.spi.nameservice.NameServiceDescriptor ---------------------------------------------------------------------- diff --git a/libraries/http/src/vhost-test/resources/META-INF/services/sun.net.spi.nameservice.NameServiceDescriptor b/libraries/http/src/vhost-test/resources/META-INF/services/sun.net.spi.nameservice.NameServiceDescriptor index 97d19d9..093db66 100644 --- a/libraries/http/src/vhost-test/resources/META-INF/services/sun.net.spi.nameservice.NameServiceDescriptor +++ b/libraries/http/src/vhost-test/resources/META-INF/services/sun.net.spi.nameservice.NameServiceDescriptor @@ -14,4 +14,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -polygene.library.http.dns.LocalManagedDnsDescriptor +org.apache.polygene.library.http.dns.LocalManagedDnsDescriptor
