Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 7ECB4200C2B for ; Wed, 15 Feb 2017 23:42:46 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 7D3DF160B87; Wed, 15 Feb 2017 22:42:46 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 56B7A160B76 for ; Wed, 15 Feb 2017 23:42:44 +0100 (CET) Received: (qmail 71707 invoked by uid 500); 15 Feb 2017 22:42:43 -0000 Mailing-List: contact commits-help@flex.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@flex.apache.org Delivered-To: mailing list commits@flex.apache.org Received: (qmail 71512 invoked by uid 99); 15 Feb 2017 22:42:42 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 15 Feb 2017 22:42:42 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id B538CDFC31; Wed, 15 Feb 2017 22:42:42 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: cdutz@apache.org To: commits@flex.apache.org Date: Wed, 15 Feb 2017 22:42:48 -0000 Message-Id: <9330f04f77d3439faf1fbcbe77b21bd4@git.apache.org> In-Reply-To: <299783f720494887a2a646a2035519f4@git.apache.org> References: <299783f720494887a2a646a2035519f4@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [07/51] [partial] flex-blazeds git commit: - Major code scrub archived-at: Wed, 15 Feb 2017 22:42:46 -0000 http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/services/messaging/adapters/MessagingSecurityConstraintManager.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/services/messaging/adapters/MessagingSecurityConstraintManager.java b/core/src/flex/messaging/services/messaging/adapters/MessagingSecurityConstraintManager.java deleted file mode 100644 index 644771a..0000000 --- a/core/src/flex/messaging/services/messaging/adapters/MessagingSecurityConstraintManager.java +++ /dev/null @@ -1,162 +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 flex.messaging.services.messaging.adapters; - -import flex.messaging.FlexContext; -import flex.messaging.MessageBroker; -import flex.messaging.config.ConfigurationConstants; -import flex.messaging.config.ConfigMap; -import flex.messaging.config.SecurityConstraint; -import flex.messaging.config.SecuritySettings; -import flex.messaging.security.LoginManager; -import flex.messaging.security.SecurityException; - -/** - * Messaging security constraint managers are used by messaging destinations - * to assert authorization of send and subscribe operations. - */ -public final class MessagingSecurityConstraintManager -{ - public static final String SEND_SECURITY_CONSTRAINT = "send-security-constraint"; - public static final String SUBSCRIBE_SECURITY_CONSTRAINT = "subscribe-security-constraint"; - - private static final int NO_SEC_CONSTRAINT = 10062; - - private LoginManager loginManager; - private SecuritySettings securitySettings; - - private SecurityConstraint sendConstraint; - private SecurityConstraint subscribeConstraint; - - /** - * Creates a new MessagingSecurityConstraintManager instance. - * - * @param broker Associated MessageBroker. - */ - public MessagingSecurityConstraintManager(MessageBroker broker) - { - this.loginManager = broker.getLoginManager(); - this.securitySettings = broker.getSecuritySettings(); - } - - /** - * Sets the send constraint which is used when to assert authorization when - * sending a message. - * - * @param ref The reference id of the constraint - */ - public void setSendConstraint(String ref) - { - validateConstraint(ref); - sendConstraint = securitySettings.getConstraint(ref); - } - - /** - * Sets the subscribe constraint which is used to assert authorization in - * subscribe, multi-subscribe, and unsubscribe operations. - * - * @param ref The reference id of the constraint - */ - public void setSubscribeConstraint(String ref) - { - validateConstraint(ref); - subscribeConstraint = securitySettings.getConstraint(ref); - } - - /** - * - * Asserts send authorizations. - */ - public void assertSendAuthorization() - { - checkConstraint(sendConstraint); - } - - /** - * - * Asserts subscribe authorizations. - */ - public void assertSubscribeAuthorization() - { - checkConstraint(subscribeConstraint); - } - - /** - * - * Creates security constraints from the given server settings. - * - * @param serverSettings The ConfigMap of server settings. - */ - public void createConstraints(ConfigMap serverSettings) - { - // Send constraint - ConfigMap send = serverSettings.getPropertyAsMap(SEND_SECURITY_CONSTRAINT, null); - if (send != null) - { - String ref = send.getPropertyAsString(ConfigurationConstants.REF_ATTR, null); - createSendConstraint(ref); - } - - // Subscribe constraint - ConfigMap subscribe = serverSettings.getPropertyAsMap(SUBSCRIBE_SECURITY_CONSTRAINT, null); - if (subscribe != null) - { - String ref = subscribe.getPropertyAsString(ConfigurationConstants.REF_ATTR, null); - createSubscribeConstraint(ref); - } - } - - void createSendConstraint(String ref) - { - if (ref != null) - sendConstraint = securitySettings.getConstraint(ref); - } - - void createSubscribeConstraint(String ref) - { - if (ref != null) - subscribeConstraint = securitySettings.getConstraint(ref); - } - - private void checkConstraint(SecurityConstraint constraint) - { - if (constraint != null && !FlexContext.isMessageFromPeer()) - { - try - { - loginManager.checkConstraint(constraint); - } - catch (SecurityException e) - { - throw e; - } - } - } - - private void validateConstraint(String ref) - { - // If an attempt is made to use a constraint that we do not know about, - // do not let the authorization succeed. - if (securitySettings.getConstraint(ref) == null) - { - // Security constraint {0} is not defined. - SecurityException se = new SecurityException(); - se.setMessage(NO_SEC_CONSTRAINT, new Object[] {ref}); - throw se; - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/services/messaging/adapters/SyncMessageReceiver.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/services/messaging/adapters/SyncMessageReceiver.java b/core/src/flex/messaging/services/messaging/adapters/SyncMessageReceiver.java deleted file mode 100644 index 46fed23..0000000 --- a/core/src/flex/messaging/services/messaging/adapters/SyncMessageReceiver.java +++ /dev/null @@ -1,201 +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 flex.messaging.services.messaging.adapters; - -import javax.jms.JMSException; -import javax.jms.Message; - -import flex.messaging.log.Log; - -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; - -/** - * A MessageReceiver that receives messages from JMS using - * synchronous javax.jms.MessageConsumer.receive call. - * - * - */ -class SyncMessageReceiver implements MessageReceiver -{ - private ScheduledExecutorService messageReceiverService; - private boolean isScheduled = false; - - private JMSConsumer jmsConsumer; - private int syncMaxReceiveThreads; - private long syncReceiveIntervalMillis; - private long syncReceiveWaitMillis; - - /** - * Constructs a new SyncMessageReceiver with default delivery settings. - * - * @param jmsConsumer JMSConsumer associated with the SynMessageReceiver. - */ - public SyncMessageReceiver(JMSConsumer jmsConsumer) - { - this.jmsConsumer = jmsConsumer; - syncReceiveIntervalMillis = JMSConfigConstants.defaultSyncReceiveIntervalMillis; - syncReceiveWaitMillis = JMSConfigConstants.defaultSyncReceiveWaitMillis; - syncMaxReceiveThreads = 1; // Always use one thread. - } - - /** - * Returns the interval of the sync receive message call. - * - * @return The interval of the sync receive message call. - */ - public long getSyncReceiveIntervalMillis() - { - return syncReceiveIntervalMillis; - } - - /** - * Sets the interval of the receive message call. This property - * is optional and defaults to 100. - * - * @param syncReceiveIntervalMillis A positive long that indicates - * the interval of the receive message call. - */ - public void setSyncReceiveIntervalMillis(long syncReceiveIntervalMillis) - { - if (syncReceiveIntervalMillis < 1) - syncReceiveIntervalMillis = JMSConfigConstants.defaultSyncReceiveIntervalMillis; - this.syncReceiveIntervalMillis = syncReceiveIntervalMillis; - } - - /** - * Returns how long a JMS proxy waits for a message before returning. - * - * @return How long a JMS proxy waits for a message before returning. - */ - public long getSyncReceiveWaitMillis() - { - return syncReceiveWaitMillis; - } - - /** - * Sets how long a JMS proxy waits for a message before returning. - * This property is optional and defaults to zero (no wait). - * - * @param syncReceiveWaitMillis A non-negative value that indicates how - * long a JMS proxy waits for a message before returning. Zero means no - * wait, negative one means wait until a message arrives. - */ - public void setSyncReceiveWaitMillis(long syncReceiveWaitMillis) - { - if (syncReceiveWaitMillis < -1) - syncReceiveWaitMillis = JMSConfigConstants.defaultSyncReceiveWaitMillis; - this.syncReceiveWaitMillis = syncReceiveWaitMillis; - } - - /** - * Implements MessageReceiver.startReceive. - */ - public void startReceive() - { - if (!isScheduled) - { - if (Log.isDebug()) - Log.getLogger(JMSAdapter.LOG_CATEGORY).debug(Thread.currentThread() - + " JMS consumer sync receive thread for JMS destination '" - + jmsConsumer.destinationJndiName + "' is starting to poll the JMS server for new messages."); - - ThreadFactory mrtf = new MessageReceiveThreadFactory(); - messageReceiverService = Executors.newScheduledThreadPool(syncMaxReceiveThreads, mrtf); - messageReceiverService.scheduleAtFixedRate(new MessageReceiveThread(), syncReceiveIntervalMillis, syncReceiveIntervalMillis, TimeUnit.MILLISECONDS); - isScheduled = true; - } - } - - /** - * Implements MessageReceivers.stopReceive. - */ - public void stopReceive() - { - if (messageReceiverService != null) - messageReceiverService.shutdown(); - } - - /** - * Used internally to receive messages as determined by syncReceiveWaitMillis. - */ - private Message receiveMessage() throws JMSException - { - if (syncReceiveWaitMillis == -1) - return jmsConsumer.receive(); - else if (syncReceiveWaitMillis == 0) - return jmsConsumer.receiveNoWait(); - else if (syncReceiveWaitMillis > 0) - return jmsConsumer.receive(syncReceiveWaitMillis); - return null; - } - - /** - * Thread Factory used to create message receive threads. - */ - class MessageReceiveThreadFactory implements ThreadFactory - { - - /** - * Used to uniquely identify each new message receive thread created. - */ - private int receiveThreadCount; - - /** - * Creates a new message receive thread. - * Synchronized to uniquely identify each receive thread at construct time safely. - * - * @param r The runnable to assign to the new thread. - */ - public synchronized Thread newThread(Runnable r) - { - Thread t = new Thread(r); - t.setName("MessageReceiveThread" + "-" + receiveThreadCount++); - t.setDaemon(true); - if (Log.isDebug()) - Log.getLogger(JMSAdapter.LOG_CATEGORY).debug("Created message receive thread: " + t.getName()); - return t; - } - - } - - /** - * Message receive threads that perform sync javax.jms.MessageConsumer.receive - * calls. - */ - class MessageReceiveThread implements Runnable - { - public void run() - { - try - { - while (true) - { - Message message = receiveMessage(); - if (message == null) break; - jmsConsumer.onMessage(message); - } - } - catch (JMSException jmsEx) - { - jmsConsumer.onException(jmsEx); - } - } - } -} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/services/messaging/adapters/package-info.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/services/messaging/adapters/package-info.java b/core/src/flex/messaging/services/messaging/adapters/package-info.java deleted file mode 100644 index d647df7..0000000 --- a/core/src/flex/messaging/services/messaging/adapters/package-info.java +++ /dev/null @@ -1,17 +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 flex.messaging.services.messaging.adapters; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/services/messaging/package-info.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/services/messaging/package-info.java b/core/src/flex/messaging/services/messaging/package-info.java deleted file mode 100644 index 53123a5..0000000 --- a/core/src/flex/messaging/services/messaging/package-info.java +++ /dev/null @@ -1,17 +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 flex.messaging.services.messaging; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/services/messaging/selector/JMSSelector.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/services/messaging/selector/JMSSelector.java b/core/src/flex/messaging/services/messaging/selector/JMSSelector.java deleted file mode 100644 index 3d680f9..0000000 --- a/core/src/flex/messaging/services/messaging/selector/JMSSelector.java +++ /dev/null @@ -1,120 +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 flex.messaging.services.messaging.selector; - -import javax.jms.InvalidSelectorException; -import javax.jms.JMSException; - -import org.apache.activemq.command.ActiveMQMessage; -import org.apache.activemq.filter.BooleanExpression; -import org.apache.activemq.filter.MessageEvaluationContext; -import org.apache.activemq.selector.SelectorParser; - -import flex.messaging.log.Log; -import flex.messaging.log.LogCategories; -import flex.messaging.messages.Message; - -/** - * The JMSSelector is used to determine whether a message matches a given - * SQL-92 selector expression. - * - * A prior implementation of this class borrowed heavily from Sun's - * proprietary code, that eventually found its way into Glassfish. The license - * was still CDDL (or CDDL+GPL) and therefore unfit for donation to Apache. - * - * The current implementation relies on Apache ActiveMQ to do the same. Since - * the selector is evaluated against the message headers (called properties in - * ActiveMQ parlance), and both ActiveMQ messages and Flex messages use a Map - * to store the header-value pair, it is easy to create a minimally sufficient - * ActiveMQMessage from a Flex message. - * - * Possible performance improvement: prevent creation of an ActiveMQMessage for each selector. - * This isn't exactly a lightweight object but there seem to be only two choices at the moment: - * a. Use a static field and synchronize access to it - * OR - * b. Instantiate a new ActiveMQMessage for each selector - * - * Re-using the same instance (approach a.) would entail calling clearProperties() followed - * by setProperties() and that too by one thread at a time, which is why approach b. has been - * chosen for now. - * - */ -public class JMSSelector -{ - public static final String LOG_CATEGORY = LogCategories.MESSAGE_SELECTOR; // Because we're not always JMS-specific. - - private String pattern = null; - - /** - * Class Constructor. - * - * @param pattern selector pattern - */ - public JMSSelector(String pattern) - { - if (pattern == null) - pattern = ""; - - this.pattern = pattern; - } - - /** - * Matches the message against the selector expression. - * - * @param msg The message to match against. - * @return true if the message headers match the selector; otherwise false. - * @exception JMSSelectorException - */ - public boolean match(Message msg) throws JMSSelectorException - { - if (pattern.equals("")) - return true; // No selector - - boolean matched = false; - - try - { - // Parse selector pattern - BooleanExpression expr = SelectorParser.parse(pattern); - - //Create a disposable ActiveMQMessage - ActiveMQMessage dummyMessage = new ActiveMQMessage(); - - // Populate dummyMessage from Flex message - dummyMessage.setProperties(msg.getHeaders()); - - // Set up an evaluation context - MessageEvaluationContext context = new MessageEvaluationContext(); - context.setMessageReference(dummyMessage); - - // Check whether message (headers) matches selector expression - matched = expr.matches(context); - - } - catch (InvalidSelectorException e) - { - throw new JMSSelectorException(e); - } - catch (JMSException e) - { - throw new JMSSelectorException(e); - } - Log.getLogger(LOG_CATEGORY).debug("Selector: " + pattern + (matched ? " matched " : " did not match ") + " message with id: " + msg.getMessageId()); - return matched; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/services/messaging/selector/JMSSelectorException.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/services/messaging/selector/JMSSelectorException.java b/core/src/flex/messaging/services/messaging/selector/JMSSelectorException.java deleted file mode 100644 index f69d32b..0000000 --- a/core/src/flex/messaging/services/messaging/selector/JMSSelectorException.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 flex.messaging.services.messaging.selector; - -import flex.messaging.MessageException; - -/** - * Exception type for JMSSelector errors. - * - * - */ -public class JMSSelectorException extends MessageException -{ - static final long serialVersionUID = -8886580147676036114L; - - public JMSSelectorException(Throwable t) - { - super(t) ; - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/services/messaging/selector/package-info.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/services/messaging/selector/package-info.java b/core/src/flex/messaging/services/messaging/selector/package-info.java deleted file mode 100644 index 266ff53..0000000 --- a/core/src/flex/messaging/services/messaging/selector/package-info.java +++ /dev/null @@ -1,17 +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 flex.messaging.services.messaging.selector; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/services/package-info.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/services/package-info.java b/core/src/flex/messaging/services/package-info.java deleted file mode 100644 index 7b724d3..0000000 --- a/core/src/flex/messaging/services/package-info.java +++ /dev/null @@ -1,17 +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 flex.messaging.services; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/util/Assert.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/util/Assert.java b/core/src/flex/messaging/util/Assert.java deleted file mode 100644 index a5f28a3..0000000 --- a/core/src/flex/messaging/util/Assert.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 flex.messaging.util; - -/** - * Simple assert class which provides functionality similar to the assert API - * of JDK 1.4. - * - * Enable as follows: - * java -Dassert - * - * - */ -public class Assert -{ - public static final boolean enableAssert = (System.getProperty("assert") != null); - - - /** - * If assertions are enabled and the passed in expression is false, throw an - * AssertionFailedError. - * - * @param expr expression whose truth value is tested - */ - public static void testAssertion(boolean expr) - { - if (enableAssert && !expr) - { - throw new AssertionFailedError(); - } - } - - /** - * If assertions are enabled and the passed in expression is false, throw an - * AssertionFailedError with the passed in message. - * - * @param expr expression whose truth value is tested - * @param message message contained in the AssertionFailedError when the expression - * is false and assertions are enabled. - */ - public static void testAssertion(boolean expr, String message) - { - if (enableAssert && !expr) - { - throw new AssertionFailedError(message); - } - } - -} - http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/util/AssertionFailedError.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/util/AssertionFailedError.java b/core/src/flex/messaging/util/AssertionFailedError.java deleted file mode 100644 index 5f9a154..0000000 --- a/core/src/flex/messaging/util/AssertionFailedError.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 flex.messaging.util; - -/** - * - * - */ -public class AssertionFailedError extends Error -{ - static final long serialVersionUID = 6315002781136046939L; - - public AssertionFailedError() - { - } - - public AssertionFailedError(String message) - { - super(message); - } -} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/util/Base64.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/util/Base64.java b/core/src/flex/messaging/util/Base64.java deleted file mode 100644 index 547b491..0000000 --- a/core/src/flex/messaging/util/Base64.java +++ /dev/null @@ -1,233 +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 flex.messaging.util; - -/** - * Code to read and write Base64-encoded text. - * Fairly special-purpose, not quite ready for - * general streaming as they don't let you - * drain less than everything that is currently - * available. - * - * - */ -public class Base64 -{ - private static final char alphabet[] = - { - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', - 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', - 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', - 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', - 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', - 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', - 'w', 'x', 'y', 'z', '0', '1', '2', '3', - '4', '5', '6', '7', '8', '9', '+', '/' - }; - - private static final int inverse[] = - { - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 64, 64, 63, - 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64, - 64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 64, - 64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, - 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 - }; - /** - * - */ - - public static class Decoder - { - private int filled = 0; - private byte data[]; - private int count = 0; - private int work[] = {0, 0, 0, 0}; - - - public Decoder() - { - data = new byte[256]; - } - - public void decode(String encoded) - { - int estimate = 1 + encoded.length() * 3 / 4; - - if (filled + estimate > data.length) - { - int length = data.length * 2; - while (length < filled + estimate) - { - length *= 2; - } - byte[] newdata = new byte[length]; - - System.arraycopy(data, 0, newdata, 0, filled); - data = newdata; - } - - for (int i = 0; i < encoded.length(); ++i) - { - char c = encoded.charAt(i); - - if (c == '=') - work[count++] = -1; - else if (inverse[c] != 64) - work[count++] = inverse[c]; - else - continue; - - if (count == 4) - { - count = 0; - data[filled++] = (byte)((work[0] << 2) | ((work[1] & 0xff) >> 4)); - - if (work[2] == -1) - break; - - data[filled++] = (byte)((work[1] << 4) | ((work[2] & 0xff) >> 2)); - - if (work[3] == -1) - break; - - data[filled++] = (byte)((work[2] << 6) | work[3]); - } - - } - } - - public byte[] drain() - { - byte[] r = new byte[filled]; - System.arraycopy(data, 0, r, 0, filled); - filled = 0; - return r; - } - - public byte[] flush() throws IllegalStateException - { - if (count > 0) - throw new IllegalStateException("a partial block (" + count + " of 4 bytes) was dropped, decoded data is probably truncated!"); - return drain(); - } - - public void reset() - { - count = 0; - filled = 0; - } - - } - - /** - * - */ - public static class Encoder - { - private int work[] = {0, 0, 0}; - private int count = 0; - private int line = 0; - private StringBuffer output; - - public Encoder(int size) - { - output = new StringBuffer(size); - } - - private void encodeBlock() - { - output.append(alphabet[(work[0] & 0xFF) >> 2]); - output.append(alphabet[((work[0] & 0x03) << 4) | ((work[1] & 0xF0) >> 4)]); - if (count > 1) - output.append(alphabet[((work[1] & 0x0F) << 2) | ((work[2] & 0xC0) >> 6)]); - else - output.append('='); - - if (count > 2) - output.append(alphabet[work[2] & 0x3F]); - else - output.append('='); - - if ((line += 4) == 76) - { - output.append('\n'); - line = 0; - } - } - - public void encode(byte[] data) - { - encode(data, 0, data.length); - } - - public void encode(byte[] data, int offset, int length) - { - int plainIndex = offset; - - while (plainIndex < (offset + length)) - { - work[count] = data[plainIndex]; - count++; - - if (count == work.length || ((offset + length) - plainIndex) == 1) - { - encodeBlock(); - count = 0; - work[0] = 0; - work[1] = 0; - work[2] = 0; - } - plainIndex++; - } - } - - public String drain() - { - String r = output.toString(); - output.setLength(0); - return r; - } - - public String flush() - { - if (count > 0) - encodeBlock(); - - String r = drain(); - count = 0; - line = 0; - work[0] = 0; - work[1] = 0; - work[2] = 0; - return r; - } - - - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/util/ClassUtil.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/util/ClassUtil.java b/core/src/flex/messaging/util/ClassUtil.java deleted file mode 100644 index f93080e..0000000 --- a/core/src/flex/messaging/util/ClassUtil.java +++ /dev/null @@ -1,359 +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 flex.messaging.util; - -import flex.messaging.MessageException; -import flex.messaging.io.SerializationContext; -import flex.messaging.io.SerializationException; -import flex.messaging.validators.DeserializationValidator; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Modifier; - -/** - * Utility class to create instances of Complex Types - * and handle error conditions consistently across the RemoteObject - * code base. - * - * - */ -public class ClassUtil -{ - private static final int TYPE_NOT_FOUND = 10008; - private static final int UNEXPECTED_TYPE = 10009; - private static final int CANNOT_CREATE_TYPE = 10010; - private static final int SECURITY_ERROR = 10011; - private static final int UNKNOWN_ERROR = 10012; - - private static final String NULL = "null"; - - private ClassUtil() - { - } - - /** - * Create a class of the specified type. - * Use {@link #createClass(String, ClassLoader)} and explicitly provide the MessageBroker class loader - * - * @param type fully qualified class name - * @return the class instance - */ - public static Class createClass(String type) - { - return createClass(type, null); - } - - /** - * Create a class of the specified type using the provided class loader. - * @param type fully qualified class name - * @param loader class loader, if null the class loader that loaded ClassUtil is used - * @return the class instance - */ - public static Class createClass(String type, ClassLoader loader) - { - try - { - if (type != null) - type = type.trim(); - - if (loader == null) // will use the loader for this class - return Class.forName(type); - return Class.forName(type, true, loader); - } - catch (ClassNotFoundException cnf) - { - // Cannot invoke type '{type}' - MessageException ex = new MessageException(); - ex.setMessage(TYPE_NOT_FOUND, new Object[] {type}); - ex.setDetails(TYPE_NOT_FOUND, "0", new Object[] {type}); - ex.setCode(MessageException.CODE_SERVER_RESOURCE_UNAVAILABLE); - throw ex; - } - } - - /** - * Creates the default instance of the class and verifies that it matches - * with the expected class type, if one passed in. - * - * @param cls The class to create. - * @param expectedInstance The expected class type. - * @return The default instance of the class. - */ - public static Object createDefaultInstance(Class cls, Class expectedInstance) - { - return ClassUtil.createDefaultInstance(cls, expectedInstance, false /*validate*/); - } - - /** - * Creates the default instance of the class and verifies that it matches - * with the expected class type, if one passed in. It also validates the creation - * of the instance with the deserialization validator, if one exists. - * - * @param cls The class to create. - * @param expectedInstance The expected class type. - * @param validate Controls whether the creation of the instance is validated - * with the deserialization validator. - * @return The default instance of the class. - */ - public static Object createDefaultInstance(Class cls, Class expectedInstance, boolean validate) - { - if (validate) - validateCreation(cls); - - String type = cls.getName(); - try - { - Object instance = cls.newInstance(); - - if (expectedInstance != null && !expectedInstance.isInstance(instance)) - { - // Given type '{name}' is not of expected type '{expectedName}'. - MessageException ex = new MessageException(); - ex.setMessage(UNEXPECTED_TYPE, new Object[] {instance.getClass().getName(), expectedInstance.getName()}); - ex.setCode(MessageException.CODE_SERVER_RESOURCE_UNAVAILABLE); - throw ex; - } - - return instance; - } - catch (IllegalAccessException ia) - { - boolean details = false; - StringBuffer message = new StringBuffer("Unable to create a new instance of type "); - message.append(type); - - //Look for a possible cause... - - // Class might not have a suitable constructor? - if (!hasValidDefaultConstructor(cls)) - { - details = true; - } - - // Unable to create a new instance of type '{type}'. - MessageException ex = new MessageException(); - ex.setMessage(CANNOT_CREATE_TYPE, new Object[] {type}); - if (details) - { - //Types must have a public, no arguments constructor - ex.setDetails(CANNOT_CREATE_TYPE, "0"); - } - ex.setCode(MessageException.CODE_SERVER_RESOURCE_UNAVAILABLE); - throw ex; - } - catch (InstantiationException ine) - { - String variant = null; - - //Look for a possible cause... - - if (cls.isInterface()) // Class is really an interface? - variant = "1"; // Interfaces cannot be instantiated - else if (isAbstract(cls)) - variant = "2"; //Abstract types cannot be instantiated. - else if (!hasValidDefaultConstructor(cls)) // Class might not have a suitable constructor? - variant = "3"; // Types cannot be instantiated without a public, no arguments constructor. - - MessageException ex = new MessageException(); - ex.setMessage(CANNOT_CREATE_TYPE, new Object[] {type}); - if (variant != null) - ex.setDetails(CANNOT_CREATE_TYPE, variant); - ex.setCode(MessageException.CODE_SERVER_RESOURCE_UNAVAILABLE); - throw ex; - } - catch (SecurityException se) - { - MessageException ex = new MessageException(); - ex.setMessage(SECURITY_ERROR, new Object[] {type}); - ex.setCode(MessageException.CODE_SERVER_RESOURCE_UNAVAILABLE); - ex.setRootCause(se); - throw ex; - } - catch (MessageException me) - { - throw me; - } - catch (Exception e) - { - MessageException ex = new MessageException(); - ex.setMessage(UNKNOWN_ERROR, new Object[] {type}); - ex.setCode(MessageException.CODE_SERVER_RESOURCE_UNAVAILABLE); - ex.setRootCause(e); - throw ex; - } - } - - public static boolean isAbstract(Class cls) - { - try - { - if (cls != null) - { - int mod = cls.getModifiers(); - return Modifier.isAbstract(mod); - } - } - catch (Throwable t) - { - return false; - } - - return false; - } - - public static boolean hasValidDefaultConstructor(Class cls) - { - try - { - if (cls != null) - { - Constructor c = cls.getConstructor(); - int mod = c.getModifiers(); - return Modifier.isPublic(mod); - } - } - catch (Throwable t) - { - return false; - } - - return false; - } - - public static String classLoaderToString(ClassLoader cl) - { - if (cl == null) - return NULL; - - if (cl == ClassLoader.getSystemClassLoader()) - return "system"; - - StringBuffer sb = new StringBuffer(); - sb.append("hashCode: " + System.identityHashCode(cl) + " (parent " + ClassUtil.classLoaderToString(cl.getParent()) + ")"); - return sb.toString(); - } - - /** - * Validates the assignment of a value to an index of an Array or List instance - * against the deserialization validator. If the assignment is not valid, - * SerializationException is thrown. - * - * @param obj The Array or List instance. - * @param index The index at which the value is being assigned. - * @param value The value that is assigned to the index. - */ - public static void validateAssignment(Object obj, int index, Object value) - { - SerializationContext context = SerializationContext.getSerializationContext(); - DeserializationValidator validator = context.getDeserializationValidator(); - if (validator == null) - return; - - boolean valid = true; - try - { - valid = validator.validateAssignment(obj, index, value); - } - catch (Exception e) - { - // Assignment validation of the object with type '{0}' for the index '{1}' failed. - SerializationException se = new SerializationException(); - se.setMessage(10313, new Object[]{obj == null? NULL : obj.getClass().getName(), index}); - se.setRootCause(e); - throw se; - } - if (!valid) - { - SerializationException se = new SerializationException(); - se.setMessage(10313, new Object[]{obj == null? NULL : obj.getClass().getName(), index}); - throw se; - } - } - - /** - * Validates the assignment of a property of an instance of a class to a value - * against the deserialization validator. If the assignment is not valid, - * SerializationException is thrown. - * - * @param obj The class instance whose property is being assigned to a value. - * @param propName The name of the property that is being assigned. - * @param value The value that the property is being assigned to. - */ - public static void validateAssignment(Object obj, String propName, Object value) - { - SerializationContext context = SerializationContext.getSerializationContext(); - DeserializationValidator validator = context.getDeserializationValidator(); - if (validator == null) - return; - - boolean valid = true; - try - { - valid = validator.validateAssignment(obj, propName, value); - } - catch (Exception e) - { - // Assignment validation of the object with type '{0}' for the property '{1}' failed. - SerializationException se = new SerializationException(); - se.setMessage(10312, new Object[]{obj == null? NULL : obj.getClass().getName(), propName}); - se.setRootCause(e); - throw se; - } - if (!valid) - { - SerializationException se = new SerializationException(); - se.setMessage(10312, new Object[]{obj == null? NULL : obj.getClass().getName(), propName}); - throw se; - } - } - - /** - * Validates the creation of the class instance against the deserialization - * validator, if one exists. If the class creation is not valid, - * SerializationException is thrown. - * - * @param cls The class to validate. - */ - public static void validateCreation(Class cls) - { - SerializationContext context = SerializationContext.getSerializationContext(); - DeserializationValidator validator = context.getDeserializationValidator(); - if (validator == null) - return; - - boolean valid = true; - try - { - valid = validator.validateCreation(cls); - } - catch (Exception e) - { - // Creation validation for class '{0}' failed. - SerializationException se = new SerializationException(); - se.setMessage(10311, new Object[]{cls == null? NULL : cls.getName()}); - se.setRootCause(e); - throw se; - } - if (!valid) - { - // Creation validation for class '{0}' failed. - SerializationException se = new SerializationException(); - se.setMessage(10311, new Object[]{cls == null? NULL : cls.getName()}); - throw se; - } - } -} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/util/Diag.jsl ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/util/Diag.jsl b/core/src/flex/messaging/util/Diag.jsl deleted file mode 100644 index f84c960..0000000 --- a/core/src/flex/messaging/util/Diag.jsl +++ /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 flex.messaging.util; - -import java.io.PrintWriter; -import java.io.StringWriter; - -public class Diag -{ - public static void TraceException(Throwable e, String txt) - { - System.Diagnostics.Trace.WriteLine("Exception: " + txt); - StringWriter sw = new StringWriter(); - PrintWriter pw = new PrintWriter(sw); - e.printStackTrace(pw); - System.Diagnostics.Trace.WriteLine(sw); - } -} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/util/DoubleUtil.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/util/DoubleUtil.java b/core/src/flex/messaging/util/DoubleUtil.java deleted file mode 100644 index 19dfbc8..0000000 --- a/core/src/flex/messaging/util/DoubleUtil.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 flex.messaging.util; - -/** - * - */ -public class DoubleUtil -{ - /** - * - */ - public static long doubleToRawLongBits(double d) - { - return Double.doubleToRawLongBits(d); - } -} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/util/DoubleUtil.jsl ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/util/DoubleUtil.jsl b/core/src/flex/messaging/util/DoubleUtil.jsl deleted file mode 100644 index 97b959c..0000000 --- a/core/src/flex/messaging/util/DoubleUtil.jsl +++ /dev/null @@ -1,27 +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 flex.messaging.util; - -public class DoubleUtil -{ - public static long doubleToRawLongBits(double d) - { - return System.BitConverter.DoubleToInt64Bits(d); - } -} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/util/Hex.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/util/Hex.java b/core/src/flex/messaging/util/Hex.java deleted file mode 100644 index a48fac8..0000000 --- a/core/src/flex/messaging/util/Hex.java +++ /dev/null @@ -1,143 +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 flex.messaging.util; - -/** - * Code to read and write Base64-encoded text. - * Fairly special-purpose, not quite ready for - * general streaming as they don't let you - * drain less than everything that is currently - * available. - * - * - */ -public class Hex -{ - private static final char digits[] = - { - '0', '1', '2', '3', '4', '5', '6', '7', - '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' - }; - /** - * - */ - public static class Decoder - { - private int filled = 0; - private byte data[]; - private int work[] = {0, 0}; - - - public Decoder() - { - data = new byte[256]; - } - - public void decode(String encoded) - { - - int estimate = 1 + encoded.length() / 2; - - if (filled + estimate > data.length) - { - int length = data.length * 2; - while (length < filled + estimate) - { - length *= 2; - } - byte[] newdata = new byte[length]; - - System.arraycopy(data, 0, newdata, 0, filled); - data = newdata; - } - - for (int i = 0; i < encoded.length(); ++i) - { - work[0] = Character.digit(encoded.charAt(i), 16); - i++; - work[1] = Character.digit(encoded.charAt(i), 16); - data[filled++] = (byte) (((work[0] << 4) | (work[1])) & 0xff); - } - } - - public byte[] drain() - { - byte[] r = new byte[filled]; - System.arraycopy(data, 0, r, 0, filled); - filled = 0; - return r; - } - - public byte[] flush() throws IllegalStateException - { - return drain(); - } - - public void reset() - { - filled = 0; - } - - } - - /** - * - */ - public static class Encoder - { - private StringBuffer output; - - public Encoder(int size) - { - output = new StringBuffer(size * 2); - } - - private void encodeBlock(byte work) - { - output.append(digits[(work & 0xF0) >>> 4]); - output.append(digits[(work & 0x0F)]); - } - - public void encode(byte[] data) - { - encode(data, 0, data.length); - } - - public void encode(byte[] data, int offset, int length) - { - int plainIndex = offset; - - while (plainIndex < (offset + length)) - { - encodeBlock(data[plainIndex]); - plainIndex++; - } - } - - public String drain() - { - String r = output.toString(); - output.setLength(0); - return r; - } - - public String flush() - { - return drain(); - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/util/MethodKey.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/util/MethodKey.java b/core/src/flex/messaging/util/MethodKey.java deleted file mode 100644 index d2eb7dc..0000000 --- a/core/src/flex/messaging/util/MethodKey.java +++ /dev/null @@ -1,80 +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 flex.messaging.util; - -import java.util.Arrays; - -/** - * Utility class used as a key into collections of Remote Object methods. The - * key consists of the Remote Object class containing this method, the method name, - * and the classes representing the parameters in the signature of this method. - * - * - */ -public class MethodKey -{ - private Class enclosingClass; - private String methodName; - private Class[] parameterTypes; - - /** - * Constructor. - * - * @param enclosingClass remote Ooject class containing this method - * @param methodName method name - * @param parameterTypes classes representing the parameters in the signature of this method - */ - public MethodKey(Class enclosingClass, String methodName, Class[] parameterTypes) - { - this.enclosingClass = enclosingClass; - this.methodName = methodName; - this.parameterTypes = parameterTypes; - } - - /** {@inheritDoc} */ - public boolean equals(Object object) - { - boolean result; - if (this == object) - { - result = true; - } - else if (object instanceof MethodKey) - { - MethodKey other = (MethodKey) object; - result = - other.methodName.equals(this.methodName) && - other.parameterTypes.length == this.parameterTypes.length && - other.enclosingClass == this.enclosingClass && - Arrays.equals(other.parameterTypes, this.parameterTypes); - } - else - { - result = false; - } - return result; - } - - /** {@inheritDoc} */ - public int hashCode() - { - // Don't consider parameter types in hashcode to speed up - // calculation. - return enclosingClass.hashCode() * 10003 + - methodName.hashCode(); - } -} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/util/MethodMatcher.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/util/MethodMatcher.java b/core/src/flex/messaging/util/MethodMatcher.java deleted file mode 100644 index 6430a30..0000000 --- a/core/src/flex/messaging/util/MethodMatcher.java +++ /dev/null @@ -1,515 +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 flex.messaging.util; - -import flex.messaging.io.TypeMarshaller; -import flex.messaging.io.TypeMarshallingContext; -import flex.messaging.MessageException; - -import java.util.Map; -import java.util.HashMap; -import java.util.List; -import java.lang.reflect.Method; - -/** - * A utility class used to find a suitable method based on matching - * signatures to the types of set of arguments. Since the arguments - * may be from more loosely typed environments such as ActionScript, - * a translator can be employed to handle type conversion. Note that - * there isn't a great guarantee for which method will be selected - * when several overloaded methods match very closely through the use - * of various combinations of generic types. - * - * - */ -public class MethodMatcher -{ - private final Map methodCache = new HashMap(); - private static final int ARGUMENT_CONVERSION_ERROR = 10006; - private static final int CANNOT_INVOKE_METHOD = 10007; - - /** - * Default constructor. - */ - public MethodMatcher() - { - } - - /** - * Utility method that searches a class for a given method, taking - * into account the supplied parameters when evaluating overloaded - * method signatures. - * - * @param c The class. - * @param methodName Desired method to search for - * @param parameters Required to distinguish between overloaded methods of the same name - * @return The best-match Method. - */ - public Method getMethod(Class c, String methodName, List parameters) - { - // Keep track of the best method match found - Match bestMatch = new Match(methodName); - - // Determine supplied parameter types. - Class[] suppliedParamTypes = paramTypes(parameters); - - // Create a key to search our method cache - MethodKey methodKey = new MethodKey(c, methodName, suppliedParamTypes); - - Method method = null; - if (methodCache.containsKey(methodKey)) - { - method = methodCache.get(methodKey); - - String thisMethodName = method.getName(); - bestMatch.matchedMethodName = thisMethodName; - } - else - { - try // First, try an exact match. - { - method = c.getMethod(methodName, suppliedParamTypes); - synchronized(methodCache) - { - Method method2 = methodCache.get(methodKey); - if (method2 == null) - methodCache.put(methodKey, method); - else - method = method2; - } - } - catch (SecurityException e) - { - // NOWARN - } - catch (NoSuchMethodException e) - { - // NOWARN - } - - if (method == null) // Otherwise, search the long way. - { - Method[] methods = c.getMethods(); - for (Method thisMethod : c.getMethods()) - { - String thisMethodName = thisMethod.getName(); - - // FIXME: Do we want to do this case-insensitively in Flex 2.0? - // First, search by name; for backwards compatibility - // we continue to check case-insensitively - if (!thisMethodName.equalsIgnoreCase(methodName)) - continue; - - // Next, search on params - Match currentMatch = new Match(methodName); - currentMatch.matchedMethodName = thisMethodName; - - // If we've not yet had a match, this is our best match so far. - if (bestMatch.matchedMethodName == null) - bestMatch = currentMatch; - - // Number of parameters must match. - Class[] desiredParamTypes = thisMethod.getParameterTypes(); - currentMatch.methodParamTypes = desiredParamTypes; - - if (desiredParamTypes.length != suppliedParamTypes.length) - continue; - - currentMatch.matchedByNumberOfParams = true; - - // If we've not yet matched any params, this is our best match so far. - if (!bestMatch.matchedByNumberOfParams && bestMatch.matchedParamCount == 0) - bestMatch = currentMatch; - - // Parameter types must also be compatible. Don't actually convert - // the parameter just yet, only count the matches and exact matches. - convertParams(parameters, desiredParamTypes, currentMatch, false); - - // If we've not yet had this many params match, this is our best match so far. - if (currentMatch.matchedParamCount >= bestMatch.matchedParamCount - && currentMatch.exactMatchedParamCount >= bestMatch.exactMatchedParamCount) - bestMatch = currentMatch; - - // If all types were compatible, we have a match. - if (currentMatch.matchedParamCount == desiredParamTypes.length - && bestMatch == currentMatch) - { - method = thisMethod; - synchronized(methodCache) - { - Method method2 = methodCache.get(methodKey); - if (method2 == null || method2 != method) - methodCache.put(methodKey, method); - else - method = method2; - } - // Don't break as there might be other methods with the - // same number of arguments but with better match count. - // break; - } - } - } - } - - if (method == null) - { - methodNotFound(methodName, suppliedParamTypes, bestMatch); - } - else if (bestMatch.paramTypeConversionFailure != null) - { - //Error occurred while attempting to convert an input argument's type. - MessageException me = new MessageException(); - me.setMessage(ARGUMENT_CONVERSION_ERROR); - me.setCode("Server.Processing"); - me.setRootCause(bestMatch.paramTypeConversionFailure); - throw me; - } - - // Call convertParams one last time before returning method. This ensures - // that parameters List is converted using bestMatch. - Class[] desiredParamTypes = method.getParameterTypes(); - bestMatch.methodParamTypes = desiredParamTypes; - convertParams(parameters, desiredParamTypes, bestMatch, true); - return method; - } - - - /** - * Utility method to convert a collection of parameters to desired types. We keep track - * of the progress of the conversion to allow callers to gauge the success of the conversion. - * This is important for ranking overloaded-methods and debugging purposes. - * - * @param parameters actual parameters for an invocation - * @param desiredParamTypes classes in the signature of a potential match for the invocation - * @param currentMatch the currently best known match - * @param convert determines whether the actual conversion should take place. - */ - public static void convertParams(List parameters, Class[] desiredParamTypes, Match currentMatch, boolean convert) - { - int matchCount = 0; - int exactMatchCount = 0; - - currentMatch.matchedParamCount = 0; - currentMatch.convertedSuppliedTypes = new Class[desiredParamTypes.length]; - - TypeMarshaller marshaller = TypeMarshallingContext.getTypeMarshaller(); - - for (int i = 0; i < desiredParamTypes.length; i++) - { - Object param = parameters.get(i); - - // Consider null param to match - if (param != null) - { - Object obj = null; - Class objClass = null; - - if (marshaller != null) - { - try - { - obj = marshaller.convert(param, desiredParamTypes[i]); - } - catch (MessageException ex) - { - currentMatch.paramTypeConversionFailure = ex; - break; - } - catch (ClassCastException ex) - { - currentMatch.paramTypeConversionFailure = ex; - break; - } - // We need to catch the exception here as the conversion of parameter types could fail - catch(Exception e) - { - currentMatch.paramTypeConversionFailure = e; - break; - } - } - else - { - obj = param; - } - - currentMatch.convertedSuppliedTypes[i] = (obj != null ? (objClass = obj.getClass()) : null); - - // Things match if we now have an object which is assignable from the - // method param class type or if we have an Object which corresponds to - // a primitive - if (objClass != null && isAssignableFrom(desiredParamTypes[i], objClass)) - { - // See if there's an exact match before parameter is converted. - if (isAssignableFrom(desiredParamTypes[i], param.getClass())) - exactMatchCount++; - - if (convert) // Convert the parameter. - parameters.set(i, obj); - - matchCount++; - } - else - { - break; - } - } - else - { - matchCount++; - } - } - - currentMatch.matchedParamCount = matchCount; - currentMatch.exactMatchedParamCount = exactMatchCount; - } - - private static boolean isAssignableFrom(Class first, Class second) - { - return (first.isAssignableFrom(second)) || - (first == Integer.TYPE && Integer.class.isAssignableFrom(second)) || - (first == Double.TYPE && Double.class.isAssignableFrom(second)) || - (first == Long.TYPE && Long.class.isAssignableFrom(second)) || - (first == Boolean.TYPE && Boolean.class.isAssignableFrom(second)) || - (first == Character.TYPE && Character.class.isAssignableFrom(second)) || - (first == Float.TYPE && Float.class.isAssignableFrom(second)) || - (first == Short.TYPE && Short.class.isAssignableFrom(second)) || - (first == Byte.TYPE && Byte.class.isAssignableFrom(second)); - } - - /** - * Utility method that iterates over a collection of input - * parameters to determine their types while logging - * the class names to create a unique identifier for a - * method signature. - * - * @param parameters - A list of supplied parameters. - * @return An array of Class instances indicating the class of each corresponding parameter. - * - */ - public static Class[] paramTypes(List parameters) - { - Class[] paramTypes = new Class[parameters.size()]; - for (int i = 0; i < paramTypes.length; i++) - { - Object p = parameters.get(i); - paramTypes[i] = p == null ? Object.class : p.getClass(); - } - return paramTypes; - } - - /** - * Utility method to provide more detailed information in the event that a search - * for a specific method failed for the service class. - * - * @param methodName the name of the missing method - * @param suppliedParamTypes the types of parameters supplied for the search - * @param bestMatch the best match found during the search - */ - public static void methodNotFound(String methodName, Class[] suppliedParamTypes, Match bestMatch) - { - // Set default error message... - // Cannot invoke method '{methodName}'. - int errorCode = CANNOT_INVOKE_METHOD; - Object[] errorParams = new Object[]{methodName}; - String errorDetailVariant = "0"; - // Method '{methodName}' not found. - Object[] errorDetailParams = new Object[]{methodName}; - - if (bestMatch.matchedMethodName != null) - { - // Cannot invoke method '{bestMatch.matchedMethodName}'. - errorCode = CANNOT_INVOKE_METHOD; - errorParams = new Object[]{bestMatch.matchedMethodName}; - - int suppliedParamCount = suppliedParamTypes.length; - int expectedParamCount = bestMatch.methodParamTypes != null ? bestMatch.methodParamTypes.length : 0; - - if (suppliedParamCount != expectedParamCount) - { - // {suppliedParamCount} arguments were sent but {expectedParamCount} were expected. - errorDetailVariant = "1"; - errorDetailParams = new Object[]{new Integer(suppliedParamCount), new Integer(expectedParamCount)}; - - } - else - { - String suppliedTypes = bestMatch.listTypes(suppliedParamTypes); - String convertedTypes = bestMatch.listConvertedTypes(); - String expectedTypes = bestMatch.listExpectedTypes(); - - if (expectedTypes != null) - { - if (suppliedTypes != null) - { - if (convertedTypes != null) - { - // The expected argument types are ({expectedTypes}) - // but the supplied types were ({suppliedTypes}) - // and converted to ({convertedTypes}). - errorDetailVariant = "2"; - errorDetailParams = new Object[]{expectedTypes, suppliedTypes, convertedTypes}; - } - else - { - // The expected argument types are ({expectedTypes}) - // but the supplied types were ({suppliedTypes}) - // with none successfully converted. - errorDetailVariant = "3"; - errorDetailParams = new Object[]{expectedTypes, suppliedTypes}; - } - } - else - { - // The expected argument types are ({expectedTypes}) - // but no arguments were provided. - errorDetailVariant = "4"; - errorDetailParams = new Object[]{expectedTypes}; - } - } - else - { - // No arguments were expected but the following types were supplied (suppliedTypes) - errorDetailVariant = "5"; - errorDetailParams = new Object[]{suppliedTypes}; - } - } - } - - MessageException ex = new MessageException(); - ex.setMessage(errorCode, errorParams); - ex.setCode(MessageException.CODE_SERVER_RESOURCE_UNAVAILABLE); - if (errorDetailVariant != null) - ex.setDetails(errorCode, errorDetailVariant, errorDetailParams); - - if (bestMatch.paramTypeConversionFailure != null) - ex.setRootCause(bestMatch.paramTypeConversionFailure); - - throw ex; - } - - /** - * A utility class to help rank methods in the search - * for a best match, given a name and collection of - * input parameters. - * - */ - public static class Match - { - /** - * Constructor. - * @param name the name of the method to match - */ - public Match(String name) - { - this.methodName = name; - } - - /** - * Returns true if desired and found method names match. - * @return true if desired and found method names match - */ - public boolean matchedExactlyByName() - { - return matchedMethodName != null? matchedMethodName.equals(methodName) : false; - } - - /** - * Returns true if desired and found method names match only when case is ignored. - * @return true if desired and found method names match only when case is ignored - */ - public boolean matchedLooselyByName() - { - return matchedMethodName != null? - (!matchedExactlyByName() && matchedMethodName.equalsIgnoreCase(methodName)) : false; - } - - - /** - * Lists the classes in the signature of the method matched. - * @return the classes in the signature of the method matched - */ - public String listExpectedTypes() - { - return listTypes(methodParamTypes); - } - - - /** - * Lists the classes corresponding to actual invocation parameters once they have been - * converted as best they could to match the classes in the invoked method's signature. - * - * @return the classes corresponding to actual invocation parameters once they have been - * converted as best they could to match the classes in the invoked method's signature - */ - public String listConvertedTypes() - { - return listTypes(convertedSuppliedTypes); - } - - /** - * Creates a string representation of the class names in the array of types passed into - * this method. - * - * @param types an array of types whose names are to be listed - * @return a string representation of the class names in the array of types - */ - public String listTypes(Class[] types) - { - if (types == null || types.length == 0) - return null; - - StringBuffer sb = new StringBuffer(); - - for (int i = 0; i < types.length; i++) - { - if (i > 0) - sb.append(", "); - - Class c = types[i]; - - if (c != null) - { - if (c.isArray()) - { - c = c.getComponentType(); - sb.append(c.getName()).append("[]"); - } - else - { - sb.append(c.getName()); - } - } - else - { - sb.append("null"); - } - } - - return sb.toString(); - } - - final String methodName; - String matchedMethodName; - - boolean matchedByNumberOfParams; - int matchedParamCount; - int exactMatchedParamCount; - Class[] methodParamTypes; - Class[] convertedSuppliedTypes; - Exception paramTypeConversionFailure; - } -}